25 #define foreach_wg_input_error \ 26 _ (NONE, "No error") \ 27 _ (HANDSHAKE_MAC, "Invalid MAC handshake") \ 28 _ (PEER, "Peer error") \ 29 _ (INTERFACE, "Interface error") \ 30 _ (DECRYPTION, "Failed during decryption") \ 31 _ (KEEPALIVE_SEND, "Failed while sending Keepalive") \ 32 _ (HANDSHAKE_SEND, "Failed while sending Handshake") \ 33 _ (HANDSHAKE_RECEIVE, "Failed while receiving Handshake") \ 34 _ (TOO_BIG, "Packet too big") \ 35 _ (UNDEFINED, "Undefined error") 39 #define _(sym,str) WG_INPUT_ERROR_##sym, 46 #define _(sym,string) string, 66 #define _(v,a) case MESSAGE_##v: return (format (s, "%s", a)); 70 return (
format (s,
"unknown"));
82 s =
format (s,
"WG input: \n");
117 bool packet_needs_cookie;
137 return WG_INPUT_ERROR_INTERFACE;
148 return WG_INPUT_ERROR_PEER;
152 return WG_INPUT_ERROR_NONE;
155 u32 len = (header->
type == MESSAGE_HANDSHAKE_INITIATION ?
160 ((
u8 *) current_b_data + len -
sizeof (*macs));
164 current_b_data, len, under_load, ip4_src,
169 packet_needs_cookie =
false;
171 packet_needs_cookie =
true;
173 return WG_INPUT_ERROR_HANDSHAKE_MAC;
175 switch (header->
type)
177 case MESSAGE_HANDSHAKE_INITIATION:
181 if (packet_needs_cookie)
195 return WG_INPUT_ERROR_PEER;
202 WG_INPUT_ERROR_HANDSHAKE_SEND, 1);
206 case MESSAGE_HANDSHAKE_RESPONSE:
216 return WG_INPUT_ERROR_PEER;
219 return WG_INPUT_ERROR_PEER;
226 return WG_INPUT_ERROR_PEER;
228 if (packet_needs_cookie)
242 WG_INPUT_ERROR_KEEPALIVE_SEND,
249 return WG_INPUT_ERROR_HANDSHAKE_RECEIVE;
254 return WG_INPUT_ERROR_NONE;
287 n_left_from =
frame->n_vectors;
296 while (n_left_from > 0)
298 bool is_keepalive =
false;
318 b[0]->
error =
node->errors[WG_INPUT_ERROR_PEER];
341 b[0]->
error =
node->errors[WG_INPUT_ERROR_TOO_BIG];
366 b[0]->
error =
node->errors[WG_INPUT_ERROR_DECRYPTION];
373 VNET_BUFFER_OFFLOAD_F_UDP_CKSUM);
390 bool allowed =
false;
417 if (thread_index != 0)
424 if (ret != WG_INPUT_ERROR_NONE)
433 && (b[0]->
flags & VLIB_BUFFER_IS_TRACED)))
436 t->
type = header_type;
448 return frame->n_vectors;
455 .vector_size =
sizeof (
u32),
#define WG_DEFAULT_DATA_SIZE
wg_per_thread_data_t * per_thread_data
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
fib_protocol_t fp_proto
protocol type
u8 encrypted_static[noise_encrypted_len(NOISE_PUBLIC_KEY_LEN)]
wg_peer_allowed_ip_t * allowed_ips
struct message_handshake_initiation message_handshake_initiation_t
enum cookie_mac_state cookie_checker_validate_macs(vlib_main_t *vm, cookie_checker_t *cc, message_macs_t *cm, void *buf, size_t len, bool busy, ip4_address_t ip4, u16 udp_port)
#define NOISE_AUTHTAG_LEN
u16 nexts[VLIB_FRAME_SIZE]
u16 current_length
Nbytes between current data and the end of this buffer.
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
u32 index_t
A Data-Path Object is an object that represents actions that are applied to packets are they are swit...
void wg_timers_any_authenticated_packet_traversal(wg_peer_t *peer)
static uword ip4_destination_matches_route(const ip4_main_t *im, const ip4_address_t *key, const ip4_address_t *dest, uword dest_length)
#define VLIB_NODE_FN(node)
#define clib_memcpy(d, s, n)
bool noise_remote_begin_session(vlib_main_t *vm, noise_remote_t *r)
#define static_always_inline
vlib_get_buffers(vm, from, b, n_left_from)
bool wg_send_handshake_response(vlib_main_t *vm, wg_peer_t *peer)
description fragment has unexpected format
Aggregate type for a prefix.
void wg_send_handshake_from_mt(u32 peer_idx, bool is_retry)
vlib_buffer_enqueue_to_next(vm, node, from,(u16 *) nexts, frame->n_vectors)
u16 fp_len
The mask length.
void wg_timers_any_authenticated_packet_received(wg_peer_t *peer)
vl_api_fib_path_type_t type
vlib_error_t error
Error code for buffers to be enqueued to error handler.
u16 udp_src_port[default=4500]
u8 encrypted_nothing[noise_encrypted_len(0)]
ip46_address_t fp_addr
The address type is not deriveable from the fp_addr member.
description malformed packet
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
void wg_timers_data_received(wg_peer_t *peer)
#define VLIB_REGISTER_NODE(x,...)
u8 data[WG_DEFAULT_DATA_SIZE]
wg_index_table_t index_table
#define clib_atomic_cmp_and_swap(addr, old, new)
struct message_data message_data_t
bool noise_consume_response(vlib_main_t *vm, noise_remote_t *r, uint32_t s_idx, uint32_t r_idx, uint8_t ue[NOISE_PUBLIC_KEY_LEN], uint8_t en[0+NOISE_AUTHTAG_LEN])
bool noise_consume_initiation(vlib_main_t *vm, noise_local_t *l, noise_remote_t **rp, uint32_t s_idx, uint8_t ue[NOISE_PUBLIC_KEY_LEN], uint8_t es[NOISE_PUBLIC_KEY_LEN+NOISE_AUTHTAG_LEN], uint8_t ets[NOISE_TIMESTAMP_LEN+NOISE_AUTHTAG_LEN])
u16 udp_dst_port[default=4500]
u8 encrypted_timestamp[noise_encrypted_len(NOISE_TIMESTAMP_LEN)]
u8 unencrypted_ephemeral[NOISE_PUBLIC_KEY_LEN]
static_always_inline wg_if_t * wg_if_get_by_port(u16 port)
vlib_main_t vlib_node_runtime_t * node
#define INDEX_INVALID
Invalid index - used when no index is known blazoned capitals INVALID speak volumes where ~0 does not...
VLIB buffer representation.
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
void wg_timers_session_derived(wg_peer_t *peer)
static u32 wg_peer_assign_thread(u32 thread_id)
static_always_inline void vnet_buffer_offload_flags_clear(vlib_buffer_t *b, vnet_buffer_oflags_t oflags)
ip4_main_t ip4_main
Global ip4 main structure.
bool wg_send_keepalive(vlib_main_t *vm, wg_peer_t *peer)
static_always_inline noise_local_t * noise_local_get(uint32_t locali)
enum noise_state_crypt noise_remote_decrypt(vlib_main_t *vm, noise_remote_t *r, uint32_t r_idx, uint64_t nonce, uint8_t *src, size_t srclen, uint8_t *dst)
#define vec_foreach(var, vec)
Vector iterator.
u8 unencrypted_ephemeral[NOISE_PUBLIC_KEY_LEN]
void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
cookie_checker_t cookie_checker
enum message_type message_type_t
#define VLIB_NODE_FLAG_TRACE
static wg_peer_t * wg_peer_get(index_t peeri)
vlib_buffer_t * bufs[VLIB_FRAME_SIZE]
u32 * wg_index_table_lookup(const wg_index_table_t *table, u32 key)
void wg_timers_handshake_complete(wg_peer_t *peer)