Unregister UDPC port only when owned
Needed in QUIC, when cleaning up accepted UDP sessions
Change-Id: Ifcb32687175562bed4ca69bdc519cedd4dc3c2bc
Signed-off-by: Nathan Skrzypczak <nathan.skrzypczak@gmail.com>
diff --git a/src/vnet/udp/udp.c b/src/vnet/udp/udp.c
index 4178a49..d5166d9 100644
--- a/src/vnet/udp/udp.c
+++ b/src/vnet/udp/udp.c
@@ -95,6 +95,7 @@
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 @@
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 @@
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;
}
diff --git a/src/vnet/udp/udp.h b/src/vnet/udp/udp.h
index 03dbcdd..f5efbbc 100644
--- a/src/vnet/udp/udp.h
+++ b/src/vnet/udp/udp.h
@@ -41,6 +41,7 @@
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_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;
}
diff --git a/src/vnet/udp/udp_input.c b/src/vnet/udp/udp_input.c
index e42f9fa..c6b9167 100644
--- a/src/vnet/udp/udp_input.c
+++ b/src/vnet/udp/udp_input.c
@@ -207,6 +207,7 @@
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))