Unregister UDPC port only when owned 41/19541/2
authorNathan Skrzypczak <nathan.skrzypczak@gmail.com>
Mon, 13 May 2019 14:25:50 +0000 (16:25 +0200)
committerFlorin Coras <florin.coras@gmail.com>
Tue, 14 May 2019 02:02:43 +0000 (02:02 +0000)
Needed in QUIC, when cleaning up accepted UDP sessions

Change-Id: Ifcb32687175562bed4ca69bdc519cedd4dc3c2bc
Signed-off-by: Nathan Skrzypczak <nathan.skrzypczak@gmail.com>
src/vnet/udp/udp.c
src/vnet/udp/udp.h
src/vnet/udp/udp_input.c

index 4178a49..d5166d9 100644 (file)
@@ -95,6 +95,7 @@ udp_session_bind (u32 session_index, transport_endpoint_t * lcl)
   listener->c_proto = TRANSPORT_PROTO_UDP;
   listener->c_s_index = session_index;
   listener->c_fib_index = lcl->fib_index;
+  listener->owns_port = 1;
   clib_spinlock_init (&listener->rx_lock);
 
   node_index = lcl->is_ip4 ? udp4_input_node.index : udp6_input_node.index;
@@ -168,8 +169,9 @@ udp_session_close (u32 connection_index, u32 thread_index)
   uc = udp_connection_get (connection_index, thread_index);
   if (uc)
     {
-      udp_unregister_dst_port (vm, clib_net_to_host_u16 (uc->c_lcl_port),
-                              uc->c_is_ip4);
+      if (uc->owns_port || !uc->is_connected)
+       udp_unregister_dst_port (vm, clib_net_to_host_u16 (uc->c_lcl_port),
+                                uc->c_is_ip4);
       session_transport_delete_notify (&uc->connection);
       udp_connection_free (uc);
     }
@@ -302,6 +304,7 @@ udp_open_connection (transport_endpoint_cfg_t * rmt)
   uc->c_is_ip4 = rmt->is_ip4;
   uc->c_proto = TRANSPORT_PROTO_UDP;
   uc->c_fib_index = rmt->fib_index;
+  uc->owns_port = 1;
 
   return uc->c_c_index;
 }
index 03dbcdd..f5efbbc 100644 (file)
@@ -41,6 +41,7 @@ typedef struct
   transport_connection_t connection;   /**< must be first */
   clib_spinlock_t rx_lock;             /**< rx fifo lock */
   u8 is_connected;                     /**< connected mode */
+  u8 owns_port;                                /**< does port belong to conn (UDPC) */
 } udp_connection_t;
 
 #define foreach_udp4_dst_port                  \
@@ -234,6 +235,8 @@ udp_connection_clone_safe (u32 connection_index, u32 thread_index)
   udp_pool_remove_peeker (thread_index);
   new_c->c_thread_index = current_thread_index;
   new_c->c_c_index = udp_connection_index (new_c);
+  new_c->is_connected = old_c->is_connected;
+  new_c->c_fib_index = old_c->c_fib_index;
   return new_c;
 }
 
index e42f9fa..c6b9167 100644 (file)
@@ -207,6 +207,7 @@ udp46_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
                  child0->c_rmt_port = udp0->src_port;
                  child0->c_is_ip4 = is_ip4;
                  child0->c_fib_index = tc0->fib_index;
+                 child0->is_connected = 1;
 
                  if (session_stream_accept (&child0->connection,
                                             tc0->s_index, 1))