2 * Copyright (c) 2020 Cisco and/or its affiliates.
3 * Copyright (c) 2020 Doc.ai and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <wireguard/wireguard_index_table.h>
21 #include <wireguard/wireguard_messages.h>
23 typedef struct wg_if_t_
29 /* noise_local_pool elt index */
31 cookie_checker_t cookie_checker;
34 wg_index_table_t index_table;
36 /* Source IP address for originated packets */
39 /* hash table of peers on this link */
44 int wg_if_create (u32 user_instance,
45 const u8 private_key_64[NOISE_PUBLIC_KEY_LEN],
46 u16 port, const ip_address_t * src_ip, u32 * sw_if_indexp);
47 int wg_if_delete (u32 sw_if_index);
48 index_t wg_if_find_by_sw_if_index (u32 sw_if_index);
50 u8 *format_wg_if (u8 * s, va_list * va);
52 typedef walk_rc_t (*wg_if_walk_cb_t) (index_t wgi, void *data);
53 void wg_if_walk (wg_if_walk_cb_t fn, void *data);
55 typedef walk_rc_t (*wg_if_peer_walk_cb_t) (wg_if_t * wgi, index_t peeri,
57 index_t wg_if_peer_walk (wg_if_t * wgi, wg_if_peer_walk_cb_t fn, void *data);
59 void wg_if_peer_add (wg_if_t * wgi, index_t peeri);
60 void wg_if_peer_remove (wg_if_t * wgi, index_t peeri);
63 * Data-plane exposed functions
65 extern wg_if_t *wg_if_pool;
67 static_always_inline wg_if_t *
68 wg_if_get (index_t wgii)
70 if (INDEX_INVALID == wgii)
72 return (pool_elt_at_index (wg_if_pool, wgii));
75 extern index_t *wg_if_index_by_port;
77 static_always_inline wg_if_t *
78 wg_if_get_by_port (u16 port)
80 if (vec_len (wg_if_index_by_port) < port)
82 if (INDEX_INVALID == wg_if_index_by_port[port])
84 return (wg_if_get (wg_if_index_by_port[port]));
91 * fd.io coding-style-patch-verification: ON
94 * eval: (c-set-style "gnu")