FD.io VPP  v20.09-64-g4f7b92f0a
Vector Packet Processing
wireguard_if.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Doc.ai and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef __WG_ITF_H__
17 #define __WG_ITF_H__
18 
21 
22 typedef struct wg_if_t_
23 {
26 
27  // Interface params
28  /* noise_local_pool elt index */
32 
34 
35  /* Source IP address for originated packets */
37 
38  /* hash table of peers on this link */
40 } wg_if_t;
41 
42 
44  const u8 private_key_64[NOISE_PUBLIC_KEY_LEN],
45  u16 port, const ip_address_t * src_ip, u32 * sw_if_indexp);
48 
49 u8 *format_wg_if (u8 * s, va_list * va);
50 
51 typedef walk_rc_t (*wg_if_walk_cb_t) (index_t wgi, void *data);
52 void wg_if_walk (wg_if_walk_cb_t fn, void *data);
53 
54 typedef walk_rc_t (*wg_if_peer_walk_cb_t) (wg_if_t * wgi, index_t peeri,
55  void *data);
57 
58 void wg_if_peer_add (wg_if_t * wgi, index_t peeri);
59 void wg_if_peer_remove (wg_if_t * wgi, index_t peeri);
60 
61 /**
62  * Data-plane exposed functions
63  */
64 extern wg_if_t *wg_if_pool;
65 
68 {
69  if (INDEX_INVALID == wgii)
70  return (NULL);
71  return (pool_elt_at_index (wg_if_pool, wgii));
72 }
73 
75 
78 {
79  if (vec_len (wg_if_index_by_port) < port)
80  return (NULL);
82  return (NULL);
83  return (wg_if_get (wg_if_index_by_port[port]));
84 }
85 
86 
87 #endif
88 
89 /*
90  * fd.io coding-style-patch-verification: ON
91  *
92  * Local Variables:
93  * eval: (c-set-style "gnu")
94  * End:
95  */
uword * peers
Definition: wireguard_if.h:39
static_always_inline wg_if_t * wg_if_get(index_t wgii)
Definition: wireguard_if.h:67
wg_if_t * wg_if_pool
Data-plane exposed functions.
Definition: wireguard_if.c:11
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_if_walk_cb_t)(index_t wgi, void *data)
Definition: wireguard_if.h:51
index_t wg_if_peer_walk(wg_if_t *wgi, wg_if_peer_walk_cb_t fn, void *data)
Definition: wireguard_if.c:363
index_t wg_if_find_by_sw_if_index(u32 sw_if_index)
Definition: wireguard_if.c:65
unsigned char u8
Definition: types.h:56
u8 data[128]
Definition: ipsec_types.api:89
int wg_if_create(u32 user_instance, const u8 private_key_64[NOISE_PUBLIC_KEY_LEN], u16 port, const ip_address_t *src_ip, u32 *sw_if_indexp)
Definition: wireguard_if.c:224
enum walk_rc_t_ walk_rc_t
Walk return code.
#define static_always_inline
Definition: clib.h:108
int wg_if_delete(u32 sw_if_index)
Definition: wireguard_if.c:300
void wg_if_peer_remove(wg_if_t *wgi, index_t peeri)
Definition: wireguard_if.c:339
unsigned int u32
Definition: types.h:88
u32 local_idx
Definition: wireguard_if.h:29
#define NOISE_PUBLIC_KEY_LEN
index_t * wg_if_index_by_port
Definition: wireguard_if.c:20
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:534
unsigned short u16
Definition: types.h:57
struct wg_if_t_ wg_if_t
u8 * format_wg_if(u8 *s, va_list *va)
Definition: wireguard_if.c:30
int user_instance
Definition: wireguard_if.h:24
walk_rc_t(* wg_if_peer_walk_cb_t)(wg_if_t *wgi, index_t peeri, void *data)
Definition: wireguard_if.h:54
ip_address_t src_ip
Definition: wireguard_if.h:36
void wg_if_walk(wg_if_walk_cb_t fn, void *data)
Definition: wireguard_if.c:349
wg_index_table_t index_table
Definition: wireguard_if.h:33
static_always_inline wg_if_t * wg_if_get_by_port(u16 port)
Definition: wireguard_if.h:77
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
#define INDEX_INVALID
Invalid index - used when no index is known blazoned capitals INVALID speak volumes where ~0 does not...
Definition: dpo.h:47
u64 uword
Definition: types.h:112
cookie_checker_t cookie_checker
Definition: wireguard_if.h:30
u32 sw_if_index
Definition: wireguard_if.h:25
void wg_if_peer_add(wg_if_t *wgi, index_t peeri)
Definition: wireguard_if.c:329