wireguard: add ipv6 support
[vpp.git] / src / plugins / wireguard / wireguard_if.h
1 /*
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:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #ifndef __WG_ITF_H__
18 #define __WG_ITF_H__
19
20 #include <wireguard/wireguard_index_table.h>
21 #include <wireguard/wireguard_messages.h>
22
23 typedef struct wg_if_t_
24 {
25   int user_instance;
26   u32 sw_if_index;
27
28   // Interface params
29   /* noise_local_pool elt index */
30   u32 local_idx;
31   cookie_checker_t cookie_checker;
32   u16 port;
33
34   /* Source IP address for originated packets */
35   ip_address_t src_ip;
36
37   /* hash table of peers on this link */
38   uword *peers;
39 } wg_if_t;
40
41
42 int wg_if_create (u32 user_instance,
43                   const u8 private_key_64[NOISE_PUBLIC_KEY_LEN],
44                   u16 port, const ip_address_t * src_ip, u32 * sw_if_indexp);
45 int wg_if_delete (u32 sw_if_index);
46 index_t wg_if_find_by_sw_if_index (u32 sw_if_index);
47
48 u8 *format_wg_if (u8 * s, va_list * va);
49
50 typedef walk_rc_t (*wg_if_walk_cb_t) (index_t wgi, void *data);
51 void wg_if_walk (wg_if_walk_cb_t fn, void *data);
52
53 typedef walk_rc_t (*wg_if_peer_walk_cb_t) (index_t peeri, void *data);
54 index_t wg_if_peer_walk (wg_if_t * wgi, wg_if_peer_walk_cb_t fn, void *data);
55
56 void wg_if_peer_add (wg_if_t * wgi, index_t peeri);
57 void wg_if_peer_remove (wg_if_t * wgi, index_t peeri);
58
59 /**
60  * Data-plane exposed functions
61  */
62 extern wg_if_t *wg_if_pool;
63
64 static_always_inline wg_if_t *
65 wg_if_get (index_t wgii)
66 {
67   if (INDEX_INVALID == wgii)
68     return (NULL);
69   return (pool_elt_at_index (wg_if_pool, wgii));
70 }
71
72 extern index_t **wg_if_indexes_by_port;
73
74 static_always_inline index_t *
75 wg_if_indexes_get_by_port (u16 port)
76 {
77   if (vec_len (wg_if_indexes_by_port) == 0)
78     return (NULL);
79   if (vec_len (wg_if_indexes_by_port[port]) == 0)
80     return (NULL);
81   return (wg_if_indexes_by_port[port]);
82 }
83
84
85 #endif
86
87 /*
88  * fd.io coding-style-patch-verification: ON
89  *
90  * Local Variables:
91  * eval: (c-set-style "gnu")
92  * End:
93  */