Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1 | /* |
Florin Coras | c5df8c7 | 2019-04-08 07:42:30 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016-2019 Cisco and/or its affiliates. |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 16 | #include <vlibmemory/api.h> |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 17 | #include <vlib/vlib.h> |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 18 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 19 | #include <vppinfra/hash.h> |
| 20 | #include <vppinfra/error.h> |
| 21 | #include <vppinfra/elog.h> |
| 22 | |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 23 | #include <vnet/vnet.h> |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 24 | #include <vnet/ip/ip.h> |
| 25 | #include <vnet/udp/udp.h> |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 26 | #include <vnet/udp/udp_packet.h> |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 27 | #include <vnet/session/session.h> |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 28 | |
Filip Tehlar | 0c56217 | 2021-10-06 12:48:34 +0000 | [diff] [blame] | 29 | static vlib_error_desc_t udp_error_counters[] = { |
| 30 | #define udp_error(f, n, s, d) { #n, d, VL_COUNTER_SEVERITY_##s }, |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 31 | #include "udp_error.def" |
| 32 | #undef udp_error |
| 33 | }; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 34 | |
| 35 | typedef struct |
| 36 | { |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 37 | u32 connection; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 38 | u32 disposition; |
| 39 | u32 thread_index; |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 40 | } udp_input_trace_t; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 41 | |
| 42 | /* packet trace format function */ |
| 43 | static u8 * |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 44 | format_udp_input_trace (u8 * s, va_list * args) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 45 | { |
| 46 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 47 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 48 | udp_input_trace_t *t = va_arg (*args, udp_input_trace_t *); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 49 | |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 50 | s = format (s, "UDP_INPUT: connection %d, disposition %d, thread %d", |
| 51 | t->connection, t->disposition, t->thread_index); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 52 | return s; |
| 53 | } |
| 54 | |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 55 | #define foreach_udp_input_next \ |
| 56 | _ (DROP, "error-drop") |
| 57 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 58 | typedef enum |
| 59 | { |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 60 | #define _(s, n) UDP_INPUT_NEXT_##s, |
| 61 | foreach_udp_input_next |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 62 | #undef _ |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 63 | UDP_INPUT_N_NEXT, |
| 64 | } udp_input_next_t; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 65 | |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 66 | always_inline void |
| 67 | udp_input_inc_counter (vlib_main_t * vm, u8 is_ip4, u8 evt, u8 val) |
| 68 | { |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 69 | if (is_ip4) |
| 70 | vlib_node_increment_counter (vm, udp4_input_node.index, evt, val); |
| 71 | else |
| 72 | vlib_node_increment_counter (vm, udp6_input_node.index, evt, val); |
| 73 | } |
| 74 | |
Florin Coras | e759bb5 | 2020-04-08 01:55:39 +0000 | [diff] [blame] | 75 | #define udp_store_err_counters(vm, is_ip4, cnts) \ |
| 76 | { \ |
| 77 | int i; \ |
| 78 | for (i = 0; i < UDP_N_ERROR; i++) \ |
| 79 | if (cnts[i]) \ |
| 80 | udp_input_inc_counter(vm, is_ip4, i, cnts[i]); \ |
| 81 | } |
| 82 | |
| 83 | #define udp_inc_err_counter(cnts, err, val) \ |
| 84 | { \ |
| 85 | cnts[err] += val; \ |
| 86 | } |
| 87 | |
| 88 | static void |
| 89 | udp_trace_buffer (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 90 | vlib_buffer_t * b, session_t * s, u16 error0) |
| 91 | { |
| 92 | udp_input_trace_t *t; |
| 93 | |
| 94 | if (PREDICT_TRUE (!(b->flags & VLIB_BUFFER_IS_TRACED))) |
| 95 | return; |
| 96 | |
| 97 | t = vlib_add_trace (vm, node, b, sizeof (*t)); |
| 98 | t->connection = s ? s->connection_index : ~0; |
| 99 | t->disposition = error0; |
Florin Coras | 92bbfc2 | 2020-04-09 14:20:52 +0000 | [diff] [blame] | 100 | t->thread_index = s ? s->thread_index : vm->thread_index; |
Florin Coras | e759bb5 | 2020-04-08 01:55:39 +0000 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | static udp_connection_t * |
| 104 | udp_connection_accept (udp_connection_t * listener, session_dgram_hdr_t * hdr, |
| 105 | u32 thread_index) |
| 106 | { |
| 107 | udp_connection_t *uc; |
| 108 | |
| 109 | uc = udp_connection_alloc (thread_index); |
| 110 | ip_copy (&uc->c_lcl_ip, &hdr->lcl_ip, hdr->is_ip4); |
| 111 | ip_copy (&uc->c_rmt_ip, &hdr->rmt_ip, hdr->is_ip4); |
| 112 | uc->c_lcl_port = hdr->lcl_port; |
| 113 | uc->c_rmt_port = hdr->rmt_port; |
| 114 | uc->c_is_ip4 = hdr->is_ip4; |
| 115 | uc->c_fib_index = listener->c_fib_index; |
| 116 | uc->mss = listener->mss; |
| 117 | uc->flags |= UDP_CONN_F_CONNECTED; |
Florin Coras | f8ee39f | 2022-10-18 18:37:56 -0700 | [diff] [blame] | 118 | uc->cfg_flags = listener->cfg_flags; |
Florin Coras | e759bb5 | 2020-04-08 01:55:39 +0000 | [diff] [blame] | 119 | |
| 120 | if (session_dgram_accept (&uc->connection, listener->c_s_index, |
| 121 | listener->c_thread_index)) |
| 122 | { |
| 123 | udp_connection_free (uc); |
| 124 | return 0; |
| 125 | } |
Florin Coras | e1f2058 | 2022-11-11 11:37:36 -0800 | [diff] [blame] | 126 | transport_share_local_endpoint (TRANSPORT_PROTO_UDP, &uc->c_lcl_ip, |
| 127 | uc->c_lcl_port); |
Florin Coras | e759bb5 | 2020-04-08 01:55:39 +0000 | [diff] [blame] | 128 | return uc; |
| 129 | } |
| 130 | |
| 131 | static void |
| 132 | udp_connection_enqueue (udp_connection_t * uc0, session_t * s0, |
| 133 | session_dgram_hdr_t * hdr0, u32 thread_index, |
| 134 | vlib_buffer_t * b, u8 queue_event, u32 * error0) |
| 135 | { |
| 136 | int wrote0; |
| 137 | |
Florin Coras | 30fdf39 | 2020-12-02 21:14:56 -0800 | [diff] [blame] | 138 | if (!(uc0->flags & UDP_CONN_F_CONNECTED)) |
Florin Coras | 7428eaa | 2023-12-11 16:04:57 -0800 | [diff] [blame] | 139 | { |
| 140 | clib_spinlock_lock (&uc0->rx_lock); |
| 141 | |
| 142 | wrote0 = session_enqueue_dgram_connection_cl ( |
| 143 | s0, hdr0, b, TRANSPORT_PROTO_UDP, queue_event); |
| 144 | |
| 145 | clib_spinlock_unlock (&uc0->rx_lock); |
| 146 | |
| 147 | /* Expect cl udp enqueue to fail because fifo enqueue */ |
| 148 | if (PREDICT_FALSE (wrote0 == 0)) |
| 149 | *error0 = UDP_ERROR_FIFO_FULL; |
| 150 | |
| 151 | return; |
| 152 | } |
Florin Coras | e759bb5 | 2020-04-08 01:55:39 +0000 | [diff] [blame] | 153 | |
| 154 | if (svm_fifo_max_enqueue_prod (s0->rx_fifo) |
| 155 | < hdr0->data_length + sizeof (session_dgram_hdr_t)) |
| 156 | { |
| 157 | *error0 = UDP_ERROR_FIFO_FULL; |
Florin Coras | 7428eaa | 2023-12-11 16:04:57 -0800 | [diff] [blame] | 158 | return; |
Florin Coras | e759bb5 | 2020-04-08 01:55:39 +0000 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | /* If session is owned by another thread and rx event needed, |
| 162 | * enqueue event now while we still have the peeker lock */ |
| 163 | if (s0->thread_index != thread_index) |
| 164 | { |
Florin Coras | 7428eaa | 2023-12-11 16:04:57 -0800 | [diff] [blame] | 165 | wrote0 = session_enqueue_dgram_connection2 ( |
Florin Coras | 0242d30 | 2022-12-22 15:03:44 -0800 | [diff] [blame] | 166 | s0, hdr0, b, TRANSPORT_PROTO_UDP, |
Florin Coras | 7428eaa | 2023-12-11 16:04:57 -0800 | [diff] [blame] | 167 | queue_event && !svm_fifo_has_event (s0->rx_fifo)); |
Florin Coras | e759bb5 | 2020-04-08 01:55:39 +0000 | [diff] [blame] | 168 | } |
| 169 | else |
| 170 | { |
Florin Coras | 7428eaa | 2023-12-11 16:04:57 -0800 | [diff] [blame] | 171 | wrote0 = session_enqueue_dgram_connection ( |
| 172 | s0, hdr0, b, TRANSPORT_PROTO_UDP, queue_event); |
Florin Coras | e759bb5 | 2020-04-08 01:55:39 +0000 | [diff] [blame] | 173 | } |
Mohammed Hawari | 2cc8c0a | 2023-02-27 15:33:30 +0100 | [diff] [blame] | 174 | |
| 175 | /* In some rare cases, session_enqueue_dgram_connection can fail because a |
| 176 | * chunk cannot be allocated in the RX FIFO */ |
| 177 | if (PREDICT_FALSE (wrote0 == 0)) |
| 178 | *error0 = UDP_ERROR_FIFO_NOMEM; |
Florin Coras | e759bb5 | 2020-04-08 01:55:39 +0000 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | always_inline session_t * |
| 182 | udp_parse_and_lookup_buffer (vlib_buffer_t * b, session_dgram_hdr_t * hdr, |
| 183 | u8 is_ip4) |
| 184 | { |
| 185 | udp_header_t *udp; |
| 186 | u32 fib_index; |
| 187 | session_t *s; |
| 188 | |
| 189 | /* udp_local hands us a pointer to the udp data */ |
| 190 | udp = (udp_header_t *) (vlib_buffer_get_current (b) - sizeof (*udp)); |
| 191 | fib_index = vnet_buffer (b)->ip.fib_index; |
| 192 | |
| 193 | hdr->data_offset = 0; |
| 194 | hdr->lcl_port = udp->dst_port; |
| 195 | hdr->rmt_port = udp->src_port; |
| 196 | hdr->is_ip4 = is_ip4; |
Florin Coras | 6d39c1e | 2023-01-09 14:00:33 -0800 | [diff] [blame] | 197 | hdr->gso_size = 0; |
Florin Coras | e759bb5 | 2020-04-08 01:55:39 +0000 | [diff] [blame] | 198 | |
| 199 | if (is_ip4) |
| 200 | { |
| 201 | ip4_header_t *ip4; |
| 202 | |
| 203 | /* TODO: must fix once udp_local does ip options correctly */ |
| 204 | ip4 = (ip4_header_t *) (((u8 *) udp) - sizeof (*ip4)); |
| 205 | ip_set (&hdr->lcl_ip, &ip4->dst_address, 1); |
| 206 | ip_set (&hdr->rmt_ip, &ip4->src_address, 1); |
| 207 | hdr->data_length = clib_net_to_host_u16 (ip4->length); |
| 208 | hdr->data_length -= sizeof (ip4_header_t) + sizeof (udp_header_t); |
| 209 | s = session_lookup_safe4 (fib_index, &ip4->dst_address, |
| 210 | &ip4->src_address, udp->dst_port, |
| 211 | udp->src_port, TRANSPORT_PROTO_UDP); |
| 212 | } |
| 213 | else |
| 214 | { |
| 215 | ip6_header_t *ip60; |
| 216 | |
| 217 | ip60 = (ip6_header_t *) (((u8 *) udp) - sizeof (*ip60)); |
| 218 | ip_set (&hdr->lcl_ip, &ip60->dst_address, 0); |
| 219 | ip_set (&hdr->rmt_ip, &ip60->src_address, 0); |
| 220 | hdr->data_length = clib_net_to_host_u16 (ip60->payload_length); |
| 221 | hdr->data_length -= sizeof (udp_header_t); |
| 222 | s = session_lookup_safe6 (fib_index, &ip60->dst_address, |
| 223 | &ip60->src_address, udp->dst_port, |
| 224 | udp->src_port, TRANSPORT_PROTO_UDP); |
| 225 | } |
| 226 | |
| 227 | if (PREDICT_TRUE (!(b->flags & VLIB_BUFFER_NEXT_PRESENT))) |
| 228 | b->current_length = hdr->data_length; |
| 229 | else |
| 230 | b->total_length_not_including_first_buffer = hdr->data_length |
| 231 | - b->current_length; |
| 232 | |
| 233 | return s; |
| 234 | } |
| 235 | |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 236 | always_inline uword |
| 237 | udp46_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 238 | vlib_frame_t * frame, u8 is_ip4) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 239 | { |
Florin Coras | 0242d30 | 2022-12-22 15:03:44 -0800 | [diff] [blame] | 240 | u32 thread_index = vm->thread_index, n_left_from, *from, *first_buffer; |
Florin Coras | e759bb5 | 2020-04-08 01:55:39 +0000 | [diff] [blame] | 241 | vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b; |
| 242 | u16 err_counters[UDP_N_ERROR] = { 0 }; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 243 | |
Aloys Augustin | 8fadb65 | 2019-09-24 18:57:50 +0200 | [diff] [blame] | 244 | from = first_buffer = vlib_frame_vector_args (frame); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 245 | n_left_from = frame->n_vectors; |
Florin Coras | e759bb5 | 2020-04-08 01:55:39 +0000 | [diff] [blame] | 246 | vlib_get_buffers (vm, from, bufs, n_left_from); |
| 247 | |
| 248 | b = bufs; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 249 | |
| 250 | while (n_left_from > 0) |
| 251 | { |
Aloys Augustin | 8fadb65 | 2019-09-24 18:57:50 +0200 | [diff] [blame] | 252 | u32 error0 = UDP_ERROR_ENQUEUED; |
Aloys Augustin | 8fadb65 | 2019-09-24 18:57:50 +0200 | [diff] [blame] | 253 | session_dgram_hdr_t hdr0; |
Florin Coras | e759bb5 | 2020-04-08 01:55:39 +0000 | [diff] [blame] | 254 | udp_connection_t *uc0; |
| 255 | session_t *s0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 256 | |
Florin Coras | e759bb5 | 2020-04-08 01:55:39 +0000 | [diff] [blame] | 257 | s0 = udp_parse_and_lookup_buffer (b[0], &hdr0, is_ip4); |
Aloys Augustin | 8fadb65 | 2019-09-24 18:57:50 +0200 | [diff] [blame] | 258 | if (PREDICT_FALSE (!s0)) |
| 259 | { |
| 260 | error0 = UDP_ERROR_NO_LISTENER; |
Florin Coras | e759bb5 | 2020-04-08 01:55:39 +0000 | [diff] [blame] | 261 | goto done; |
Aloys Augustin | 8fadb65 | 2019-09-24 18:57:50 +0200 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | if (s0->session_state == SESSION_STATE_OPENED) |
| 265 | { |
Florin Coras | e759bb5 | 2020-04-08 01:55:39 +0000 | [diff] [blame] | 266 | u8 queue_event = 1; |
| 267 | uc0 = udp_connection_from_transport (session_get_transport (s0)); |
Steven Luong | bf12efc | 2022-07-25 09:29:23 -0700 | [diff] [blame] | 268 | uc0->sw_if_index = vnet_buffer (b[0])->sw_if_index[VLIB_RX]; |
Aloys Augustin | 8fadb65 | 2019-09-24 18:57:50 +0200 | [diff] [blame] | 269 | if (uc0->flags & UDP_CONN_F_CONNECTED) |
| 270 | { |
Florin Coras | e759bb5 | 2020-04-08 01:55:39 +0000 | [diff] [blame] | 271 | if (s0->thread_index != thread_index) |
Aloys Augustin | 8fadb65 | 2019-09-24 18:57:50 +0200 | [diff] [blame] | 272 | { |
| 273 | /* |
| 274 | * Clone the transport. It will be cleaned up with the |
| 275 | * session once we notify the session layer. |
| 276 | */ |
Florin Coras | e759bb5 | 2020-04-08 01:55:39 +0000 | [diff] [blame] | 277 | uc0 = udp_connection_clone_safe (s0->connection_index, |
| 278 | s0->thread_index); |
| 279 | ASSERT (s0->session_index == uc0->c_s_index); |
Aloys Augustin | 8fadb65 | 2019-09-24 18:57:50 +0200 | [diff] [blame] | 280 | |
| 281 | /* |
Florin Coras | 6bd8d3f | 2022-03-14 21:17:25 -0700 | [diff] [blame] | 282 | * Ask session layer for a new session. |
Aloys Augustin | 8fadb65 | 2019-09-24 18:57:50 +0200 | [diff] [blame] | 283 | */ |
Florin Coras | e759bb5 | 2020-04-08 01:55:39 +0000 | [diff] [blame] | 284 | session_dgram_connect_notify (&uc0->connection, |
Aloys Augustin | 8fadb65 | 2019-09-24 18:57:50 +0200 | [diff] [blame] | 285 | s0->thread_index, &s0); |
Aloys Augustin | 8fadb65 | 2019-09-24 18:57:50 +0200 | [diff] [blame] | 286 | queue_event = 0; |
| 287 | } |
| 288 | else |
| 289 | s0->session_state = SESSION_STATE_READY; |
| 290 | } |
Florin Coras | e759bb5 | 2020-04-08 01:55:39 +0000 | [diff] [blame] | 291 | udp_connection_enqueue (uc0, s0, &hdr0, thread_index, b[0], |
| 292 | queue_event, &error0); |
Aloys Augustin | 8fadb65 | 2019-09-24 18:57:50 +0200 | [diff] [blame] | 293 | } |
Florin Coras | 931a328 | 2023-09-01 17:19:33 -0700 | [diff] [blame] | 294 | else if (s0->session_state == SESSION_STATE_READY || |
| 295 | s0->session_state == SESSION_STATE_ACCEPTING) |
Aloys Augustin | 8fadb65 | 2019-09-24 18:57:50 +0200 | [diff] [blame] | 296 | { |
Florin Coras | e759bb5 | 2020-04-08 01:55:39 +0000 | [diff] [blame] | 297 | uc0 = udp_connection_from_transport (session_get_transport (s0)); |
| 298 | udp_connection_enqueue (uc0, s0, &hdr0, thread_index, b[0], 1, |
| 299 | &error0); |
Aloys Augustin | 8fadb65 | 2019-09-24 18:57:50 +0200 | [diff] [blame] | 300 | } |
| 301 | else if (s0->session_state == SESSION_STATE_LISTENING) |
| 302 | { |
Florin Coras | e759bb5 | 2020-04-08 01:55:39 +0000 | [diff] [blame] | 303 | uc0 = udp_connection_from_transport (session_get_transport (s0)); |
Aloys Augustin | 8fadb65 | 2019-09-24 18:57:50 +0200 | [diff] [blame] | 304 | if (uc0->flags & UDP_CONN_F_CONNECTED) |
| 305 | { |
Florin Coras | e759bb5 | 2020-04-08 01:55:39 +0000 | [diff] [blame] | 306 | uc0 = udp_connection_accept (uc0, &hdr0, thread_index); |
| 307 | if (!uc0) |
Aloys Augustin | 8fadb65 | 2019-09-24 18:57:50 +0200 | [diff] [blame] | 308 | { |
| 309 | error0 = UDP_ERROR_CREATE_SESSION; |
Florin Coras | e759bb5 | 2020-04-08 01:55:39 +0000 | [diff] [blame] | 310 | goto done; |
Aloys Augustin | 8fadb65 | 2019-09-24 18:57:50 +0200 | [diff] [blame] | 311 | } |
Florin Coras | e759bb5 | 2020-04-08 01:55:39 +0000 | [diff] [blame] | 312 | s0 = session_get (uc0->c_s_index, uc0->c_thread_index); |
Steven Luong | bf12efc | 2022-07-25 09:29:23 -0700 | [diff] [blame] | 313 | uc0->sw_if_index = vnet_buffer (b[0])->sw_if_index[VLIB_RX]; |
Florin Coras | e759bb5 | 2020-04-08 01:55:39 +0000 | [diff] [blame] | 314 | error0 = UDP_ERROR_ACCEPT; |
Aloys Augustin | 8fadb65 | 2019-09-24 18:57:50 +0200 | [diff] [blame] | 315 | } |
Florin Coras | e759bb5 | 2020-04-08 01:55:39 +0000 | [diff] [blame] | 316 | udp_connection_enqueue (uc0, s0, &hdr0, thread_index, b[0], 1, |
| 317 | &error0); |
Aloys Augustin | 8fadb65 | 2019-09-24 18:57:50 +0200 | [diff] [blame] | 318 | } |
| 319 | else |
| 320 | { |
| 321 | error0 = UDP_ERROR_NOT_READY; |
Aloys Augustin | 8fadb65 | 2019-09-24 18:57:50 +0200 | [diff] [blame] | 322 | } |
| 323 | |
Florin Coras | e759bb5 | 2020-04-08 01:55:39 +0000 | [diff] [blame] | 324 | done: |
Andreas Schultz | 063f2b8 | 2020-04-16 16:18:57 +0200 | [diff] [blame] | 325 | if (PREDICT_FALSE (node->flags & VLIB_NODE_FLAG_TRACE)) |
| 326 | udp_trace_buffer (vm, node, b[0], s0, error0); |
Aloys Augustin | 8fadb65 | 2019-09-24 18:57:50 +0200 | [diff] [blame] | 327 | |
Florin Coras | e759bb5 | 2020-04-08 01:55:39 +0000 | [diff] [blame] | 328 | b += 1; |
| 329 | n_left_from -= 1; |
Florin Coras | ba78e23 | 2020-04-06 21:28:59 +0000 | [diff] [blame] | 330 | |
Florin Coras | e759bb5 | 2020-04-08 01:55:39 +0000 | [diff] [blame] | 331 | udp_inc_err_counter (err_counters, error0, 1); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 332 | } |
| 333 | |
Aloys Augustin | 8fadb65 | 2019-09-24 18:57:50 +0200 | [diff] [blame] | 334 | vlib_buffer_free (vm, first_buffer, frame->n_vectors); |
Florin Coras | 0242d30 | 2022-12-22 15:03:44 -0800 | [diff] [blame] | 335 | session_main_flush_enqueue_events (TRANSPORT_PROTO_UDP, thread_index); |
Florin Coras | e759bb5 | 2020-04-08 01:55:39 +0000 | [diff] [blame] | 336 | udp_store_err_counters (vm, is_ip4, err_counters); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 337 | return frame->n_vectors; |
| 338 | } |
| 339 | |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 340 | static uword |
| 341 | udp4_input (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 342 | vlib_frame_t * frame) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 343 | { |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 344 | return udp46_input_inline (vm, node, frame, 1); |
| 345 | } |
| 346 | |
| 347 | /* *INDENT-OFF* */ |
| 348 | VLIB_REGISTER_NODE (udp4_input_node) = |
| 349 | { |
| 350 | .function = udp4_input, |
| 351 | .name = "udp4-input", |
| 352 | .vector_size = sizeof (u32), |
| 353 | .format_trace = format_udp_input_trace, |
| 354 | .type = VLIB_NODE_TYPE_INTERNAL, |
Filip Tehlar | 0c56217 | 2021-10-06 12:48:34 +0000 | [diff] [blame] | 355 | .n_errors = UDP_N_ERROR, |
| 356 | .error_counters = udp_error_counters, |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 357 | .n_next_nodes = UDP_INPUT_N_NEXT, |
| 358 | .next_nodes = { |
| 359 | #define _(s, n) [UDP_INPUT_NEXT_##s] = n, |
| 360 | foreach_udp_input_next |
| 361 | #undef _ |
| 362 | }, |
| 363 | }; |
| 364 | /* *INDENT-ON* */ |
| 365 | |
| 366 | static uword |
| 367 | udp6_input (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 368 | vlib_frame_t * frame) |
| 369 | { |
| 370 | return udp46_input_inline (vm, node, frame, 0); |
| 371 | } |
| 372 | |
| 373 | /* *INDENT-OFF* */ |
| 374 | VLIB_REGISTER_NODE (udp6_input_node) = |
| 375 | { |
| 376 | .function = udp6_input, |
| 377 | .name = "udp6-input", |
| 378 | .vector_size = sizeof (u32), |
| 379 | .format_trace = format_udp_input_trace, |
| 380 | .type = VLIB_NODE_TYPE_INTERNAL, |
Filip Tehlar | 0c56217 | 2021-10-06 12:48:34 +0000 | [diff] [blame] | 381 | .n_errors = UDP_N_ERROR, |
| 382 | .error_counters = udp_error_counters, |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 383 | .n_next_nodes = UDP_INPUT_N_NEXT, |
| 384 | .next_nodes = { |
| 385 | #define _(s, n) [UDP_INPUT_NEXT_##s] = n, |
| 386 | foreach_udp_input_next |
| 387 | #undef _ |
| 388 | }, |
| 389 | }; |
| 390 | /* *INDENT-ON* */ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 391 | |
| 392 | /* |
| 393 | * fd.io coding-style-patch-verification: ON |
| 394 | * |
| 395 | * Local Variables: |
| 396 | * eval: (c-set-style "gnu") |
| 397 | * End: |
| 398 | */ |