wireguard: fix udp-port registration 56/29156/2
authorArtem Glazychev <artem.glazychev@xored.com>
Tue, 29 Sep 2020 18:07:46 +0000 (01:07 +0700)
committerMatthew Smith <mgsmith@netgate.com>
Wed, 30 Sep 2020 00:16:53 +0000 (00:16 +0000)
Type: fix

Signed-off-by: Artem Glazychev <artem.glazychev@xored.com>
Change-Id: I698ef299316004b797da1e74b64d067caac4bd2d

src/plugins/wireguard/test/test_wireguard.py
src/plugins/wireguard/wireguard_if.c

index cee1e93..82ba262 100755 (executable)
@@ -488,7 +488,7 @@ class TestWg(VppTestCase):
         wg_output_node_name = '/err/wg-output-tun/'
         wg_input_node_name = '/err/wg-input/'
 
-        port = 12323
+        port = 12333
 
         # Create interfaces
         wg0 = VppWgInterface(self,
@@ -602,7 +602,7 @@ class TestWg(VppTestCase):
 
     def test_wg_multi_peer(self):
         """ multiple peer setup """
-        port = 12323
+        port = 12343
 
         # Create interfaces
         wg0 = VppWgInterface(self,
@@ -670,7 +670,7 @@ class WireguardHandoffTests(TestWg):
         wg_output_node_name = '/err/wg-output-tun/'
         wg_input_node_name = '/err/wg-input/'
 
-        port = 12323
+        port = 12353
 
         # Create interfaces
         wg0 = VppWgInterface(self,
index 46abdf6..3c59407 100644 (file)
@@ -250,6 +250,13 @@ wg_if_create (u32 user_instance,
 
   *sw_if_indexp = (u32) ~ 0;
 
+  /*
+   * Check if the required port is already in use
+   */
+  udp_dst_port_info_t *pi = udp_get_dst_port_info (&udp_main, port, UDP_IP4);
+  if (pi)
+    return VNET_API_ERROR_UDP_PORT_TAKEN;
+
   /*
    * Allocate a wg_if instance. Either select on dynamically
    * or try to use the desired user_instance number.