Unregister UDPC port only when owned
[vpp.git] / src / vnet / udp / udp.c
index 727efa4..d5166d9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Cisco and/or its affiliates.
+ * Copyright (c) 2016-2019 Cisco and/or its affiliates.
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at:
@@ -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;
 }
@@ -344,9 +347,11 @@ int
 udpc_connection_open (transport_endpoint_cfg_t * rmt)
 {
   udp_connection_t *uc;
+  /* Reproduce the logic of udp_open_connection to find the correct thread */
+  u32 thread_index = vlib_num_workers ()? 1 : vlib_get_main ()->thread_index;
   u32 uc_index;
   uc_index = udp_open_connection (rmt);
-  uc = udp_connection_get (uc_index, vlib_get_thread_index ());
+  uc = udp_connection_get (uc_index, thread_index);
   uc->is_connected = 1;
   return uc_index;
 }
@@ -378,7 +383,7 @@ const static transport_proto_vft_t udpc_proto = {
   .format_connection = format_udp_session,
   .format_half_open = format_udp_half_open_session,
   .format_listener = format_udp_listener_session,
-  .tx_type = TRANSPORT_TX_DEQUEUE,
+  .tx_type = TRANSPORT_TX_DGRAM,
   .service_type = TRANSPORT_SERVICE_CL,
 };
 /* *INDENT-ON* */