aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/wireguard/wireguard_send.c
diff options
context:
space:
mode:
authorAlexander Chernavin <achernavin@netgate.com>2022-08-04 08:11:57 +0000
committerAlexander Chernavin <achernavin@netgate.com>2022-08-09 15:55:45 +0000
commitfee9853a4f5d9a180ef6309cc37bd4060d27a51e (patch)
tree09ed324ca250603af84f2994683765a78a2c4191 /src/plugins/wireguard/wireguard_send.c
parenta6328e51e0c831ba3f0f4977f776491ac44eaec5 (diff)
wireguard: add peers roaming support
Type: feature With this change, peers are able to roam between different external endpoints. Successfully authenticated handshake or data packet that is received from a new endpoint will cause the peer's endpoint to be updated accordingly. Signed-off-by: Alexander Chernavin <achernavin@netgate.com> Change-Id: Ib4eb7dfa3403f3fb9e8bbe19ba6237c4960c764c
Diffstat (limited to 'src/plugins/wireguard/wireguard_send.c')
-rw-r--r--src/plugins/wireguard/wireguard_send.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/plugins/wireguard/wireguard_send.c b/src/plugins/wireguard/wireguard_send.c
index 509fe70c777..93e808ad050 100644
--- a/src/plugins/wireguard/wireguard_send.c
+++ b/src/plugins/wireguard/wireguard_send.c
@@ -104,6 +104,9 @@ u8 *
wg_build_rewrite (ip46_address_t *src_addr, u16 src_port,
ip46_address_t *dst_addr, u16 dst_port, u8 is_ip4)
{
+ if (ip46_address_is_zero (dst_addr) || 0 == dst_port)
+ return NULL;
+
u8 *rewrite = NULL;
if (is_ip4)
{
@@ -151,6 +154,9 @@ wg_send_handshake (vlib_main_t * vm, wg_peer_t * peer, bool is_retry)
{
ASSERT (vm->thread_index == 0);
+ if (!wg_peer_can_send (peer))
+ return false;
+
message_handshake_initiation_t packet;
if (!is_retry)
@@ -224,6 +230,9 @@ wg_send_keepalive (vlib_main_t * vm, wg_peer_t * peer)
{
ASSERT (vm->thread_index == 0);
+ if (!wg_peer_can_send (peer))
+ return false;
+
u32 size_of_packet = message_data_len (0);
message_data_t *packet =
(message_data_t *) wg_main.per_thread_data[vm->thread_index].data;
@@ -278,6 +287,9 @@ wg_send_handshake_response (vlib_main_t * vm, wg_peer_t * peer)
{
message_handshake_response_t packet;
+ if (!wg_peer_can_send (peer))
+ return false;
+
if (noise_create_response (vm,
&peer->remote,
&packet.sender_index,
@@ -329,10 +341,14 @@ wg_send_handshake_cookie (vlib_main_t *vm, u32 sender_index,
u32 bi0 = 0;
u8 is_ip4 = ip46_address_is_ip4 (remote_addr);
+ bool ret;
rewrite = wg_build_rewrite (wg_if_addr, wg_if_port, remote_addr, remote_port,
is_ip4);
- if (!wg_create_buffer (vm, rewrite, (u8 *) &packet, sizeof (packet), &bi0,
- is_ip4))
+
+ ret = wg_create_buffer (vm, rewrite, (u8 *) &packet, sizeof (packet), &bi0,
+ is_ip4);
+ vec_free (rewrite);
+ if (!ret)
return false;
ip46_enqueue_packet (vm, bi0, is_ip4);