FD.io VPP  v21.01.1
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;
73  u32 timers[WG_N_TIMERS];
76 
77  /* Timestamps */
83 
84  /* Variable intervals */
87 
89 
90  bool is_dead;
91 } wg_peer_t;
92 
94 {
99 
100 int wg_peer_add (u32 tun_sw_if_index,
101  const u8 public_key_64[NOISE_PUBLIC_KEY_LEN],
102  u32 table_id,
103  const ip46_address_t * endpoint,
104  const fib_prefix_t * allowed_ips,
105  u16 port, u16 persistent_keepalive, index_t * peer_index);
106 int wg_peer_remove (u32 peer_index);
107 
108 typedef walk_rc_t (*wg_peer_walk_cb_t) (index_t peeri, void *arg);
110 
111 u8 *format_wg_peer (u8 * s, va_list * va);
112 
114  void *data);
116 
117 /*
118  * Expoed for the data-plane
119  */
121 extern wg_peer_t *wg_peer_pool;
122 
123 static inline wg_peer_t *
125 {
126  return (pool_elt_at_index (wg_peer_pool, peeri));
127 }
128 
129 static inline index_t
131 {
132  return (wg_peer_by_adj_index[ai]);
133 }
134 
135 /*
136  * Makes choice for thread_id should be assigned.
137 */
138 static inline u32
140 {
141  return ((thread_id) ? thread_id
142  : (vlib_num_workers ()?
144  1) : thread_id));
145 }
146 
147 #endif // __included_wg_peer_h__
148 
149 /*
150  * fd.io coding-style-patch-verification: ON
151  *
152  * Local Variables:
153  * eval: (c-set-style "gnu")
154  * End:
155  */
wg_peer_allowed_ip_t * allowed_ips
index_t wg_peer_walk(wg_peer_walk_cb_t fn, void *data)
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)
u16 persistent_keepalive_interval
f64 rehandshake_started
u8 * format_ip4_udp_header(u8 *s, va_list *va)
ip_address_family_t af
int wg_peer_remove(u32 peer_index)
tw_timer_wheel_16t_2w_512sl_t * timer_wheel
walk_rc_t(* wg_peer_walk_cb_t)(index_t peeri, void *arg)
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:41
walk_rc_t wg_peer_if_table_change(wg_if_t *wgi, index_t peeri, void *data)
struct wg_peer_allowed_ip_t_ wg_peer_allowed_ip_t
struct wg_peer_endpoint_t_ wg_peer_endpoint_t
f64 session_derived
unsigned char u8
Definition: types.h:56
u8 data[128]
Definition: ipsec_types.api:90
double f64
Definition: types.h:142
f64 last_sent_packet
enum walk_rc_t_ walk_rc_t
Walk return code.
ip4_header_t ip4
walk_rc_t wg_peer_if_admin_state_change(wg_if_t *wgi, index_t peeri, void *data)
noise_remote_t remote
static index_t wg_peer_get_by_adj_index(index_t ai)
vl_api_prefix_t allowed_ips[n_allowed_ips]
Definition: wireguard.api:107
Aggregate type for a prefix.
Definition: fib_types.h:202
unsigned int u32
Definition: types.h:88
index_t * wg_peer_by_adj_index
#define NOISE_PUBLIC_KEY_LEN
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:546
unsigned short u16
Definition: types.h:57
vl_api_address_t endpoint
Definition: wireguard.api:103
wg_peer_endpoint_t dst
u32 new_handshake_interval_tick
struct wg_peer_table_bind_ctx_t_ wg_peer_table_bind_ctx_t
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:29
static u64 unix_time_now_nsec(void)
Definition: time.h:270
cookie_maker_t cookie_maker
u32 adj_index_t
An index for adjacencies.
Definition: adj_types.h:30
fib_node_index_t fib_entry_index
bool is_dead
adj_index_t adj_index
struct wg_peer wg_peer_t
u8 * rewrite
u16 persistent_keepalive
Definition: wireguard.api:101
u8 * format_wg_peer(u8 *s, va_list *va)
bool timer_need_another_keepalive
f64 last_sent_handshake
wg_peer_t * wg_peer_pool
wg_peer_endpoint_t src
enum ip_address_family_t_ ip_address_family_t
u32 rehandshake_interval_tick
u32 wg_sw_if_index
u32 table_id
Definition: wireguard.api:102
udp_header_t udp
u16 port
Definition: lb_types.api:73
f64 last_received_packet
static u32 wg_peer_assign_thread(u32 thread_id)
ip46_address_t addr
u32 input_thread_index
static u32 vlib_num_workers()
Definition: threads.h:377
struct ip4_udp_header_t_ ip4_udp_header_t
static wg_peer_t * wg_peer_get(index_t peeri)
u32 timer_handshake_attempts
u32 table_id
u32 output_thread_index