From a361a3951c5cc825fcb4e94c41255e2074261769 Mon Sep 17 00:00:00 2001 From: Steven Luong Date: Mon, 13 Mar 2023 11:07:40 -0700 Subject: udp: Use udp_output_get_connection instead of udp_connection_get udp_output_get_connection handles correctly if the connection is a listener whereas udp_connection_get does not which may lead to a crash. Type: fix Signed-off-by: Steven Luong Change-Id: I40b57287a8686820d29872cae2cfd6ae27a57c26 --- src/vnet/udp/udp_output.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'src/vnet/udp') diff --git a/src/vnet/udp/udp_output.c b/src/vnet/udp/udp_output.c index 2d995136e19..22b94141365 100644 --- a/src/vnet/udp/udp_output.c +++ b/src/vnet/udp/udp_output.c @@ -51,6 +51,16 @@ format_udp_tx_trace (u8 *s, va_list *args) return s; } +always_inline udp_connection_t * +udp_output_get_connection (vlib_buffer_t *b, u32 thread_index) +{ + if (PREDICT_FALSE (vnet_buffer (b)->tcp.flags & UDP_CONN_F_LISTEN)) + return udp_listener_get (vnet_buffer (b)->tcp.connection_index); + + return udp_connection_get (vnet_buffer (b)->tcp.connection_index, + thread_index); +} + static void udp46_output_trace_frame (vlib_main_t *vm, vlib_node_runtime_t *node, u32 *to_next, u32 n_bufs) @@ -67,8 +77,7 @@ udp46_output_trace_frame (vlib_main_t *vm, vlib_node_runtime_t *node, if (!(b->flags & VLIB_BUFFER_IS_TRACED)) continue; uh = vlib_buffer_get_current (b); - uc = udp_connection_get (vnet_buffer (b)->tcp.connection_index, - vm->thread_index); + uc = udp_output_get_connection (b, vm->thread_index); t = vlib_add_trace (vm, node, b, sizeof (*t)); clib_memcpy_fast (&t->udp_header, uh, sizeof (t->udp_header)); clib_memcpy_fast (&t->udp_connection, uc, sizeof (t->udp_connection)); @@ -95,16 +104,6 @@ udp_output_handle_packet (udp_connection_t *uc0, vlib_buffer_t *b0, vnet_buffer (b0)->sw_if_index[VLIB_RX] = uc0->sw_if_index; } -always_inline udp_connection_t * -udp_output_get_connection (vlib_buffer_t *b, u32 thread_index) -{ - if (PREDICT_FALSE (vnet_buffer (b)->tcp.flags & UDP_CONN_F_LISTEN)) - return udp_listener_get (vnet_buffer (b)->tcp.connection_index); - - return udp_connection_get (vnet_buffer (b)->tcp.connection_index, - thread_index); -} - always_inline uword udp46_output_inline (vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, int is_ip4) -- cgit 1.2.3-korg