25 #define foreach_wg_input_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 _(TOO_BIG, "Packet too big") \ 34 _(UNDEFINED, "Undefined error") 38 #define _(sym,str) WG_INPUT_ERROR_##sym, 45 #define _(sym,string) string, 65 #define _(v,a) case MESSAGE_##v: return (format (s, "%s", a)); 69 return (
format (s,
"unknown"));
81 s =
format (s,
"WG input: \n");
116 bool packet_needs_cookie;
136 return WG_INPUT_ERROR_INTERFACE;
147 return WG_INPUT_ERROR_PEER;
151 return WG_INPUT_ERROR_NONE;
154 u32 len = (header->
type == MESSAGE_HANDSHAKE_INITIATION ?
159 ((
u8 *) current_b_data + len -
sizeof (*macs));
163 current_b_data, len, under_load, ip4_src,
168 packet_needs_cookie =
false;
170 packet_needs_cookie =
true;
172 return WG_INPUT_ERROR_HANDSHAKE_MAC;
174 switch (header->
type)
176 case MESSAGE_HANDSHAKE_INITIATION:
180 if (packet_needs_cookie)
194 return WG_INPUT_ERROR_PEER;
201 WG_INPUT_ERROR_HANDSHAKE_SEND, 1);
205 case MESSAGE_HANDSHAKE_RESPONSE:
215 return WG_INPUT_ERROR_PEER;
218 return WG_INPUT_ERROR_PEER;
225 return WG_INPUT_ERROR_PEER;
227 if (packet_needs_cookie)
241 WG_INPUT_ERROR_KEEPALIVE_SEND,
253 return WG_INPUT_ERROR_NONE;
286 n_left_from =
frame->n_vectors;
295 while (n_left_from > 0)
297 bool is_keepalive =
false;
317 b[0]->
error =
node->errors[WG_INPUT_ERROR_PEER];
340 b[0]->
error =
node->errors[WG_INPUT_ERROR_TOO_BIG];
365 b[0]->
error =
node->errors[WG_INPUT_ERROR_DECRYPTION];
371 b[0]->
flags &= ~VNET_BUFFER_F_OFFLOAD_UDP_CKSUM;
388 bool allowed =
false;
415 if (thread_index != 0)
422 if (ret != WG_INPUT_ERROR_NONE)
431 && (b[0]->
flags & VLIB_BUFFER_IS_TRACED)))
434 t->
type = header_type;
446 return frame->n_vectors;
453 .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 current_length
Nbytes between current data and the end of this buffer.
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
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)
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.
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,...)
static_always_inline void vlib_buffer_enqueue_to_next(vlib_main_t *vm, vlib_node_runtime_t *node, u32 *buffers, u16 *nexts, uword count)
u8 data[WG_DEFAULT_DATA_SIZE]
vlib_main_t vlib_node_runtime_t * node
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)
#define INDEX_INVALID
Invalid index - used when no index is known blazoned capitals INVALID speak volumes where ~0 does not...
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
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)
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
static_always_inline void vlib_get_buffers(vlib_main_t *vm, u32 *bi, vlib_buffer_t **b, int count)
Translate array of buffer indices into buffer pointers.
#define VLIB_NODE_FLAG_TRACE
static wg_peer_t * wg_peer_get(index_t peeri)
u32 * wg_index_table_lookup(const wg_index_table_t *table, u32 key)
void wg_timers_handshake_complete(wg_peer_t *peer)