FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
wireguard_peer.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Doc.ai and/or its affiliates.
3  * Copyright (c) 2020 Cisco 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 __included_wg_peer_h__
18 #define __included_wg_peer_h__
19 
20 #include <vnet/ip/ip.h>
21 
26 #include <wireguard/wireguard_if.h>
27 
28 typedef struct ip4_udp_header_t_
29 {
32 } __clib_packed ip4_udp_header_t;
33 
34 u8 *format_ip4_udp_header (u8 * s, va_list * va);
35 
36 typedef struct wg_peer_allowed_ip_t_
37 {
41 
42 typedef struct wg_peer_endpoint_t_
43 {
44  ip46_address_t addr;
47 
48 typedef struct wg_peer
49 {
52 
55 
56  /* Peer addresses */
61 
62  /* rewrite built from address information */
64 
65  /* Vector of allowed-ips */
67 
68  /* The WG interface this peer is attached to */
70 
71  /* Timers */
72  tw_timer_wheel_16t_2w_512sl_t *timer_wheel;
77 
78  /* Timestamps */
84 
85  /* Variable intervals */
88 
90 
91  bool is_dead;
92 } wg_peer_t;
93 
95 {
100 
101 int wg_peer_add (u32 tun_sw_if_index,
102  const u8 public_key_64[NOISE_PUBLIC_KEY_LEN],
103  u32 table_id,
104  const ip46_address_t * endpoint,
105  const fib_prefix_t * allowed_ips,
106  u16 port, u16 persistent_keepalive, index_t * peer_index);
107 int wg_peer_remove (u32 peer_index);
108 
109 typedef walk_rc_t (*wg_peer_walk_cb_t) (index_t peeri, void *arg);
111 
112 u8 *format_wg_peer (u8 * s, va_list * va);
113 
115  void *data);
117 
118 /*
119  * Expoed for the data-plane
120  */
122 extern wg_peer_t *wg_peer_pool;
123 
124 static inline wg_peer_t *
126 {
127  return (pool_elt_at_index (wg_peer_pool, peeri));
128 }
129 
130 static inline index_t
132 {
133  return (wg_peer_by_adj_index[ai]);
134 }
135 
136 /*
137  * Makes choice for thread_id should be assigned.
138 */
139 static inline u32
141 {
142  return ((thread_id) ? thread_id
143  : (vlib_num_workers ()?
145  1) : thread_id));
146 }
147 
148 #endif // __included_wg_peer_h__
149 
150 /*
151  * fd.io coding-style-patch-verification: ON
152  *
153  * Local Variables:
154  * eval: (c-set-style "gnu")
155  * End:
156  */
ip4_udp_header_t
struct ip4_udp_header_t_ ip4_udp_header_t
format_wg_peer
u8 * format_wg_peer(u8 *s, va_list *va)
Definition: wireguard_peer.c:384
vlib_num_workers
static u32 vlib_num_workers()
Definition: threads.h:333
format_ip4_udp_header
u8 * format_ip4_udp_header(u8 *s, va_list *va)
Definition: wireguard_output_tun.c:59
wireguard_key.h
wg_peer::allowed_ips
wg_peer_allowed_ip_t * allowed_ips
Definition: wireguard_peer.h:66
wg_peer_if_table_change
walk_rc_t wg_peer_if_table_change(wg_if_t *wgi, index_t peeri, void *data)
Definition: wireguard_peer.c:194
wg_peer_allowed_ip_t_::fib_entry_index
fib_node_index_t fib_entry_index
Definition: wireguard_peer.h:39
wg_peer::input_thread_index
u32 input_thread_index
Definition: wireguard_peer.h:53
wg_peer::rewrite
u8 * rewrite
Definition: wireguard_peer.h:63
wg_peer_walk
index_t wg_peer_walk(wg_peer_walk_cb_t fn, void *data)
Definition: wireguard_peer.c:358
wg_peer_table_bind_ctx_t_::new_fib_index
u32 new_fib_index
Definition: wireguard_peer.h:97
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:549
wg_peer::timers_dispatched
u8 timers_dispatched[WG_N_TIMERS]
Definition: wireguard_peer.h:74
wg_peer_assign_thread
static u32 wg_peer_assign_thread(u32 thread_id)
Definition: wireguard_peer.h:140
wg_peer_get_by_adj_index
static index_t wg_peer_get_by_adj_index(index_t ai)
Definition: wireguard_peer.h:131
persistent_keepalive
u16 persistent_keepalive
Definition: wireguard.api:101
u16
unsigned short u16
Definition: types.h:57
wg_peer_table_bind_ctx_t_
Definition: wireguard_peer.h:94
wg_peer::last_received_packet
f64 last_received_packet
Definition: wireguard_peer.h:81
wg_peer::output_thread_index
u32 output_thread_index
Definition: wireguard_peer.h:54
wg_peer_if_admin_state_change
walk_rc_t wg_peer_if_admin_state_change(wg_if_t *wgi, index_t peeri, void *data)
Definition: wireguard_peer.c:186
wg_peer_remove
int wg_peer_remove(u32 peer_index)
Definition: wireguard_peer.c:336
port
u16 port
Definition: lb_types.api:73
wg_peer_walk_cb_t
walk_rc_t(* wg_peer_walk_cb_t)(index_t peeri, void *arg)
Definition: wireguard_peer.h:109
WG_N_TIMERS
@ WG_N_TIMERS
Definition: wireguard_timer.h:36
udp_header_t
Definition: udp_packet.h:45
ip4_header_t
Definition: ip4_packet.h:87
wg_peer_allowed_ip_t
struct wg_peer_allowed_ip_t_ wg_peer_allowed_ip_t
wg_peer::timer_handshake_attempts
u32 timer_handshake_attempts
Definition: wireguard_peer.h:75
wg_peer_endpoint_t_::addr
ip46_address_t addr
Definition: wireguard_peer.h:44
ip4_udp_header_t_::ip4
ip4_header_t ip4
Definition: wireguard_peer.h:30
wg_peer_add
int wg_peer_add(u32 tun_sw_if_index, const u8 public_key_64[NOISE_PUBLIC_KEY_LEN], u32 table_id, const ip46_address_t *endpoint, const fib_prefix_t *allowed_ips, u16 port, u16 persistent_keepalive, index_t *peer_index)
Definition: wireguard_peer.c:273
wg_peer::wg_sw_if_index
u32 wg_sw_if_index
Definition: wireguard_peer.h:69
wg_peer_t
struct wg_peer wg_peer_t
wg_peer::timers
u32 timers[WG_N_TIMERS]
Definition: wireguard_peer.h:73
wg_peer::session_derived
f64 session_derived
Definition: wireguard_peer.h:82
wg_peer::rehandshake_interval_tick
u32 rehandshake_interval_tick
Definition: wireguard_peer.h:87
wg_peer_endpoint_t
struct wg_peer_endpoint_t_ wg_peer_endpoint_t
index_t
u32 index_t
A Data-Path Object is an object that represents actions that are applied to packets are they are swit...
Definition: dpo.h:43
cookie_maker
Definition: wireguard_cookie.h:62
ip4_udp_header_t_
Definition: wireguard_peer.h:28
fib_node_index_t
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:29
unix_time_now_nsec
static u64 unix_time_now_nsec(void)
Definition: time.h:270
wg_peer::rehandshake_started
f64 rehandshake_started
Definition: wireguard_peer.h:83
noise_remote
Definition: wireguard_noise.h:99
wg_peer
Definition: wireguard_peer.h:48
wg_peer_by_adj_index
index_t * wg_peer_by_adj_index
Definition: wireguard_peer.c:29
wg_peer::last_sent_packet
f64 last_sent_packet
Definition: wireguard_peer.h:80
f64
double f64
Definition: types.h:142
wg_peer::last_sent_handshake
f64 last_sent_handshake
Definition: wireguard_peer.h:79
wg_if_t_
Definition: wireguard_if.h:23
wg_peer::src
wg_peer_endpoint_t src
Definition: wireguard_peer.h:58
wireguard_messages.h
data
u8 data[128]
Definition: ipsec_types.api:95
wg_peer_endpoint_t_::port
u16 port
Definition: wireguard_peer.h:45
wg_peer::is_dead
bool is_dead
Definition: wireguard_peer.h:91
wg_peer::adj_index
adj_index_t adj_index
Definition: wireguard_peer.h:60
allowed_ips
vl_api_prefix_t allowed_ips[n_allowed_ips]
Definition: wireguard.api:107
wg_peer_table_bind_ctx_t
struct wg_peer_table_bind_ctx_t_ wg_peer_table_bind_ctx_t
endpoint
vl_api_address_t endpoint
Definition: wireguard.api:103
NOISE_PUBLIC_KEY_LEN
#define NOISE_PUBLIC_KEY_LEN
Definition: wireguard_noise.h:26
ip.h
u32
unsigned int u32
Definition: types.h:88
wg_peer::remote
noise_remote_t remote
Definition: wireguard_peer.h:50
table_id
u32 table_id
Definition: wireguard.api:102
wg_peer_endpoint_t_
Definition: wireguard_peer.h:42
wg_peer::new_handshake_interval_tick
u32 new_handshake_interval_tick
Definition: wireguard_peer.h:86
wg_peer_table_bind_ctx_t_::af
ip_address_family_t af
Definition: wireguard_peer.h:96
adj_index_t
u32 adj_index_t
An index for adjacencies.
Definition: adj_types.h:30
wg_peer::dst
wg_peer_endpoint_t dst
Definition: wireguard_peer.h:57
wg_peer::table_id
u32 table_id
Definition: wireguard_peer.h:59
u8
unsigned char u8
Definition: types.h:56
wg_peer_get
static wg_peer_t * wg_peer_get(index_t peeri)
Definition: wireguard_peer.h:125
wg_peer_pool
wg_peer_t * wg_peer_pool
Definition: wireguard_peer.c:27
wireguard_if.h
wg_peer::persistent_keepalive_interval
u16 persistent_keepalive_interval
Definition: wireguard_peer.h:76
wg_peer_table_bind_ctx_t_::old_fib_index
u32 old_fib_index
Definition: wireguard_peer.h:98
wireguard_timer.h
ip4_udp_header_t_::udp
udp_header_t udp
Definition: wireguard_peer.h:31
wg_peer_allowed_ip_t_::prefix
fib_prefix_t prefix
Definition: wireguard_peer.h:38
wg_peer::timer_wheel
tw_timer_wheel_16t_2w_512sl_t * timer_wheel
Definition: wireguard_peer.h:72
wg_peer_allowed_ip_t_
Definition: wireguard_peer.h:36
walk_rc_t
enum walk_rc_t_ walk_rc_t
Walk return code.
wg_peer::timer_need_another_keepalive
bool timer_need_another_keepalive
Definition: wireguard_peer.h:89
fib_prefix_t_
Aggregate type for a prefix.
Definition: fib_types.h:202
wg_peer::cookie_maker
cookie_maker_t cookie_maker
Definition: wireguard_peer.h:51
ip_address_family_t
enum ip_address_family_t_ ip_address_family_t