Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1 | /* |
Florin Coras | c98ef75 | 2020-04-07 17:30:13 +0000 | [diff] [blame] | 2 | * Copyright (c) 2016-2020 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 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 16 | #include <vnet/udp/udp.h> |
| 17 | #include <vnet/session/session.h> |
| 18 | #include <vnet/dpo/load_balance.h> |
Neale Ranns | e403113 | 2020-10-26 13:00:06 +0000 | [diff] [blame] | 19 | #include <vnet/ip/ip4_inlines.h> |
| 20 | #include <vnet/ip/ip6_inlines.h> |
Florin Coras | a039620 | 2020-04-01 00:11:16 +0000 | [diff] [blame] | 21 | #include <vppinfra/sparse_vec.h> |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 22 | |
Filip Tehlar | 2c49ffe | 2019-03-06 07:16:08 -0800 | [diff] [blame] | 23 | udp_main_t udp_main; |
| 24 | |
Florin Coras | a039620 | 2020-04-01 00:11:16 +0000 | [diff] [blame] | 25 | static void |
Florin Coras | c8e4110 | 2022-03-18 10:27:29 -0700 | [diff] [blame] | 26 | udp_connection_register_port (u16 lcl_port, u8 is_ip4) |
Florin Coras | a039620 | 2020-04-01 00:11:16 +0000 | [diff] [blame] | 27 | { |
| 28 | udp_main_t *um = &udp_main; |
Florin Coras | a039620 | 2020-04-01 00:11:16 +0000 | [diff] [blame] | 29 | u16 *n; |
| 30 | |
Florin Coras | e1f2058 | 2022-11-11 11:37:36 -0800 | [diff] [blame] | 31 | /* Setup udp protocol -> next index sparse vector mapping. Do not setup |
| 32 | * udp_dst_port_info_t as that is used to distinguish between external |
| 33 | * and transport consumed ports */ |
Florin Coras | a039620 | 2020-04-01 00:11:16 +0000 | [diff] [blame] | 34 | |
Florin Coras | a039620 | 2020-04-01 00:11:16 +0000 | [diff] [blame] | 35 | if (is_ip4) |
Florin Coras | e1f2058 | 2022-11-11 11:37:36 -0800 | [diff] [blame] | 36 | n = sparse_vec_validate (um->next_by_dst_port4, lcl_port); |
Florin Coras | a039620 | 2020-04-01 00:11:16 +0000 | [diff] [blame] | 37 | else |
Florin Coras | e1f2058 | 2022-11-11 11:37:36 -0800 | [diff] [blame] | 38 | n = sparse_vec_validate (um->next_by_dst_port6, lcl_port); |
Florin Coras | a039620 | 2020-04-01 00:11:16 +0000 | [diff] [blame] | 39 | |
Florin Coras | e1f2058 | 2022-11-11 11:37:36 -0800 | [diff] [blame] | 40 | n[0] = um->local_to_input_edge[is_ip4]; |
Florin Coras | a039620 | 2020-04-01 00:11:16 +0000 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | static void |
| 44 | udp_connection_unregister_port (u16 lcl_port, u8 is_ip4) |
| 45 | { |
| 46 | udp_main_t *um = &udp_main; |
Florin Coras | e1f2058 | 2022-11-11 11:37:36 -0800 | [diff] [blame] | 47 | u16 *n; |
Florin Coras | a039620 | 2020-04-01 00:11:16 +0000 | [diff] [blame] | 48 | |
Florin Coras | e1f2058 | 2022-11-11 11:37:36 -0800 | [diff] [blame] | 49 | if (is_ip4) |
| 50 | n = sparse_vec_validate (um->next_by_dst_port4, lcl_port); |
| 51 | else |
| 52 | n = sparse_vec_validate (um->next_by_dst_port6, lcl_port); |
Florin Coras | a039620 | 2020-04-01 00:11:16 +0000 | [diff] [blame] | 53 | |
Florin Coras | e1f2058 | 2022-11-11 11:37:36 -0800 | [diff] [blame] | 54 | n[0] = UDP_NO_NODE_SET; |
Florin Coras | a039620 | 2020-04-01 00:11:16 +0000 | [diff] [blame] | 55 | } |
| 56 | |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 57 | udp_connection_t * |
| 58 | udp_connection_alloc (u32 thread_index) |
| 59 | { |
Florin Coras | 4c89b18 | 2022-10-24 18:59:06 -0700 | [diff] [blame] | 60 | udp_worker_t *wrk = udp_worker_get (thread_index); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 61 | udp_connection_t *uc; |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 62 | |
Florin Coras | 4c89b18 | 2022-10-24 18:59:06 -0700 | [diff] [blame] | 63 | pool_get_aligned_safe (wrk->connections, uc, CLIB_CACHE_LINE_BYTES); |
Florin Coras | a2b358b | 2022-03-18 12:50:03 -0700 | [diff] [blame] | 64 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 65 | clib_memset (uc, 0, sizeof (*uc)); |
Florin Coras | 4c89b18 | 2022-10-24 18:59:06 -0700 | [diff] [blame] | 66 | uc->c_c_index = uc - wrk->connections; |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 67 | uc->c_thread_index = thread_index; |
| 68 | uc->c_proto = TRANSPORT_PROTO_UDP; |
| 69 | return uc; |
| 70 | } |
| 71 | |
| 72 | void |
| 73 | udp_connection_free (udp_connection_t * uc) |
| 74 | { |
Florin Coras | 4c89b18 | 2022-10-24 18:59:06 -0700 | [diff] [blame] | 75 | udp_worker_t *wrk = udp_worker_get (uc->c_thread_index); |
| 76 | |
Florin Coras | 30fdf39 | 2020-12-02 21:14:56 -0800 | [diff] [blame] | 77 | clib_spinlock_free (&uc->rx_lock); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 78 | if (CLIB_DEBUG) |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 79 | clib_memset (uc, 0xFA, sizeof (*uc)); |
Florin Coras | 4c89b18 | 2022-10-24 18:59:06 -0700 | [diff] [blame] | 80 | pool_put (wrk->connections, uc); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 81 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 82 | |
Florin Coras | 57a5a2d | 2020-04-01 23:16:11 +0000 | [diff] [blame] | 83 | static void |
| 84 | udp_connection_cleanup (udp_connection_t * uc) |
| 85 | { |
Florin Coras | e1f2058 | 2022-11-11 11:37:36 -0800 | [diff] [blame] | 86 | /* Unregister port from udp_local only if refcount went to zero */ |
| 87 | if (!transport_release_local_endpoint (TRANSPORT_PROTO_UDP, &uc->c_lcl_ip, |
| 88 | uc->c_lcl_port)) |
| 89 | udp_connection_unregister_port (uc->c_lcl_port, uc->c_is_ip4); |
Florin Coras | 57a5a2d | 2020-04-01 23:16:11 +0000 | [diff] [blame] | 90 | udp_connection_free (uc); |
| 91 | } |
| 92 | |
Florin Coras | c754239 | 2019-07-22 08:08:43 -0700 | [diff] [blame] | 93 | void |
| 94 | udp_connection_delete (udp_connection_t * uc) |
| 95 | { |
Florin Coras | c754239 | 2019-07-22 08:08:43 -0700 | [diff] [blame] | 96 | session_transport_delete_notify (&uc->connection); |
Florin Coras | 57a5a2d | 2020-04-01 23:16:11 +0000 | [diff] [blame] | 97 | udp_connection_cleanup (uc); |
Florin Coras | c754239 | 2019-07-22 08:08:43 -0700 | [diff] [blame] | 98 | } |
| 99 | |
Florin Coras | 1c29dfb | 2022-10-24 18:46:20 -0700 | [diff] [blame] | 100 | static void |
| 101 | udp_handle_cleanups (void *args) |
| 102 | { |
| 103 | u32 thread_index = (u32) pointer_to_uword (args); |
| 104 | udp_connection_t *uc; |
| 105 | udp_worker_t *wrk; |
| 106 | u32 *uc_index; |
| 107 | |
| 108 | wrk = udp_worker_get (thread_index); |
| 109 | vec_foreach (uc_index, wrk->pending_cleanups) |
| 110 | { |
| 111 | uc = udp_connection_get (*uc_index, thread_index); |
| 112 | udp_connection_delete (uc); |
| 113 | } |
| 114 | vec_reset_length (wrk->pending_cleanups); |
| 115 | } |
| 116 | |
| 117 | static void |
| 118 | udp_connection_program_cleanup (udp_connection_t *uc) |
| 119 | { |
| 120 | uword thread_index = uc->c_thread_index; |
| 121 | udp_worker_t *wrk; |
| 122 | |
| 123 | wrk = udp_worker_get (uc->c_thread_index); |
| 124 | vec_add1 (wrk->pending_cleanups, uc->c_c_index); |
| 125 | |
| 126 | if (vec_len (wrk->pending_cleanups) == 1) |
| 127 | session_send_rpc_evt_to_thread_force ( |
| 128 | thread_index, udp_handle_cleanups, |
| 129 | uword_to_pointer (thread_index, void *)); |
| 130 | } |
| 131 | |
Florin Coras | 57660d9 | 2020-04-04 22:45:34 +0000 | [diff] [blame] | 132 | static u8 |
| 133 | udp_connection_port_used_extern (u16 lcl_port, u8 is_ip4) |
| 134 | { |
| 135 | udp_main_t *um = vnet_get_udp_main (); |
| 136 | udp_dst_port_info_t *pi; |
| 137 | |
| 138 | pi = udp_get_dst_port_info (um, lcl_port, is_ip4); |
Florin Coras | e1f2058 | 2022-11-11 11:37:36 -0800 | [diff] [blame] | 139 | return (pi && udp_is_valid_dst_port (lcl_port, is_ip4)); |
Florin Coras | 57660d9 | 2020-04-04 22:45:34 +0000 | [diff] [blame] | 140 | } |
| 141 | |
Florin Coras | c98ef75 | 2020-04-07 17:30:13 +0000 | [diff] [blame] | 142 | static u16 |
| 143 | udp_default_mtu (udp_main_t * um, u8 is_ip4) |
| 144 | { |
| 145 | u16 ip_hlen = is_ip4 ? sizeof (ip4_header_t) : sizeof (ip6_header_t); |
| 146 | return (um->default_mtu - sizeof (udp_header_t) - ip_hlen); |
| 147 | } |
| 148 | |
| 149 | static u32 |
Florin Coras | 0bce71e | 2022-02-10 11:57:06 -0800 | [diff] [blame] | 150 | udp_session_bind (u32 session_index, transport_endpoint_cfg_t *lcl) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 151 | { |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 152 | udp_main_t *um = vnet_get_udp_main (); |
Florin Coras | 87b7e3d | 2020-03-27 15:06:07 +0000 | [diff] [blame] | 153 | transport_endpoint_cfg_t *lcl_ext; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 154 | udp_connection_t *listener; |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 155 | void *iface_ip; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 156 | |
Florin Coras | e1f2058 | 2022-11-11 11:37:36 -0800 | [diff] [blame] | 157 | if (udp_connection_port_used_extern (clib_net_to_host_u16 (lcl->port), |
| 158 | lcl->is_ip4)) |
Florin Coras | a039620 | 2020-04-01 00:11:16 +0000 | [diff] [blame] | 159 | { |
| 160 | clib_warning ("port already used"); |
Florin Coras | 57660d9 | 2020-04-04 22:45:34 +0000 | [diff] [blame] | 161 | return SESSION_E_PORTINUSE; |
Florin Coras | a039620 | 2020-04-01 00:11:16 +0000 | [diff] [blame] | 162 | } |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 163 | |
| 164 | pool_get (um->listener_pool, listener); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 165 | clib_memset (listener, 0, sizeof (udp_connection_t)); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 166 | |
Florin Coras | 0e49568 | 2017-09-19 22:27:18 -0700 | [diff] [blame] | 167 | listener->c_lcl_port = lcl->port; |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 168 | listener->c_c_index = listener - um->listener_pool; |
| 169 | |
| 170 | /* If we are provided a sw_if_index, bind using one of its ips */ |
| 171 | if (ip_is_zero (&lcl->ip, 1) && lcl->sw_if_index != ENDPOINT_INVALID_INDEX) |
| 172 | { |
| 173 | if ((iface_ip = ip_interface_get_first_ip (lcl->sw_if_index, |
| 174 | lcl->is_ip4))) |
| 175 | ip_set (&lcl->ip, iface_ip, lcl->is_ip4); |
| 176 | } |
| 177 | ip_copy (&listener->c_lcl_ip, &lcl->ip, lcl->is_ip4); |
| 178 | listener->c_is_ip4 = lcl->is_ip4; |
| 179 | listener->c_proto = TRANSPORT_PROTO_UDP; |
| 180 | listener->c_s_index = session_index; |
| 181 | listener->c_fib_index = lcl->fib_index; |
Steven Luong | bf12efc | 2022-07-25 09:29:23 -0700 | [diff] [blame] | 182 | listener->mss = |
| 183 | lcl->mss ? lcl->mss : udp_default_mtu (um, listener->c_is_ip4); |
Florin Coras | 9c4ec6f | 2020-04-01 02:50:13 +0000 | [diff] [blame] | 184 | listener->flags |= UDP_CONN_F_OWNS_PORT | UDP_CONN_F_LISTEN; |
Florin Coras | 87b7e3d | 2020-03-27 15:06:07 +0000 | [diff] [blame] | 185 | lcl_ext = (transport_endpoint_cfg_t *) lcl; |
| 186 | if (lcl_ext->transport_flags & TRANSPORT_CFG_F_CONNECTED) |
| 187 | listener->flags |= UDP_CONN_F_CONNECTED; |
| 188 | else |
| 189 | listener->c_flags |= TRANSPORT_CONNECTION_F_CLESS; |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 190 | clib_spinlock_init (&listener->rx_lock); |
Florin Coras | f8ee39f | 2022-10-18 18:37:56 -0700 | [diff] [blame] | 191 | if (!um->csum_offload) |
| 192 | listener->cfg_flags |= UDP_CFG_F_NO_CSUM_OFFLOAD; |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 193 | |
Florin Coras | e1f2058 | 2022-11-11 11:37:36 -0800 | [diff] [blame] | 194 | udp_connection_register_port (listener->c_lcl_port, lcl->is_ip4); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 195 | return listener->c_c_index; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 196 | } |
| 197 | |
Florin Coras | c98ef75 | 2020-04-07 17:30:13 +0000 | [diff] [blame] | 198 | static u32 |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 199 | udp_session_unbind (u32 listener_index) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 200 | { |
Florin Coras | a039620 | 2020-04-01 00:11:16 +0000 | [diff] [blame] | 201 | udp_main_t *um = &udp_main; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 202 | udp_connection_t *listener; |
Florin Coras | a039620 | 2020-04-01 00:11:16 +0000 | [diff] [blame] | 203 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 204 | listener = udp_listener_get (listener_index); |
Florin Coras | e1f2058 | 2022-11-11 11:37:36 -0800 | [diff] [blame] | 205 | udp_connection_unregister_port (listener->c_lcl_port, listener->c_is_ip4); |
Florin Coras | 30fdf39 | 2020-12-02 21:14:56 -0800 | [diff] [blame] | 206 | clib_spinlock_free (&listener->rx_lock); |
Florin Coras | a039620 | 2020-04-01 00:11:16 +0000 | [diff] [blame] | 207 | pool_put (um->listener_pool, listener); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 208 | return 0; |
| 209 | } |
| 210 | |
Florin Coras | c98ef75 | 2020-04-07 17:30:13 +0000 | [diff] [blame] | 211 | static transport_connection_t * |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 212 | udp_session_get_listener (u32 listener_index) |
| 213 | { |
| 214 | udp_connection_t *us; |
| 215 | |
| 216 | us = udp_listener_get (listener_index); |
| 217 | return &us->connection; |
| 218 | } |
| 219 | |
Florin Coras | f66cc80 | 2021-04-08 19:10:07 -0700 | [diff] [blame] | 220 | always_inline u32 |
| 221 | udp_push_one_header (vlib_main_t *vm, udp_connection_t *uc, vlib_buffer_t *b) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 222 | { |
Florin Coras | f8ee39f | 2022-10-18 18:37:56 -0700 | [diff] [blame] | 223 | vlib_buffer_push_udp (b, uc->c_lcl_port, uc->c_rmt_port, |
| 224 | udp_csum_offload (uc)); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 225 | b->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED; |
Florin Coras | 15952b2 | 2022-12-19 10:55:18 -0800 | [diff] [blame] | 226 | |
| 227 | /* Handle ip header now as session layer overwrite connection details for |
| 228 | * non-connected udp. */ |
| 229 | if (uc->c_is_ip4) |
| 230 | vlib_buffer_push_ip4_custom (vm, b, &uc->c_lcl_ip4, &uc->c_rmt_ip4, |
| 231 | IP_PROTOCOL_UDP, udp_csum_offload (uc), |
| 232 | 0 /* is_df */, uc->c_dscp); |
| 233 | else |
| 234 | vlib_buffer_push_ip6 (vm, b, &uc->c_lcl_ip6, &uc->c_rmt_ip6, |
| 235 | IP_PROTOCOL_UDP); |
| 236 | |
Florin Coras | 8c1be05 | 2022-10-17 11:52:34 -0700 | [diff] [blame] | 237 | /* reuse tcp medatada for now */ |
| 238 | vnet_buffer (b)->tcp.connection_index = uc->c_c_index; |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 239 | |
Florin Coras | 15952b2 | 2022-12-19 10:55:18 -0800 | [diff] [blame] | 240 | /* Not connected udp session. Mark buffer for custom handling in |
| 241 | * udp_output */ |
| 242 | if (PREDICT_FALSE (!(uc->flags & UDP_CONN_F_CONNECTED))) |
| 243 | vnet_buffer (b)->tcp.flags |= UDP_CONN_F_LISTEN; |
| 244 | else |
| 245 | vnet_buffer (b)->tcp.flags = 0; |
| 246 | |
Florin Coras | f66cc80 | 2021-04-08 19:10:07 -0700 | [diff] [blame] | 247 | return 0; |
| 248 | } |
| 249 | |
| 250 | static u32 |
| 251 | udp_push_header (transport_connection_t *tc, vlib_buffer_t **bs, u32 n_bufs) |
| 252 | { |
| 253 | vlib_main_t *vm = vlib_get_main (); |
| 254 | udp_connection_t *uc; |
| 255 | |
| 256 | uc = udp_connection_from_transport (tc); |
| 257 | |
| 258 | while (n_bufs >= 4) |
| 259 | { |
| 260 | vlib_prefetch_buffer_header (bs[2], STORE); |
| 261 | vlib_prefetch_buffer_header (bs[3], STORE); |
| 262 | |
| 263 | udp_push_one_header (vm, uc, bs[0]); |
| 264 | udp_push_one_header (vm, uc, bs[1]); |
| 265 | |
| 266 | n_bufs -= 2; |
| 267 | bs += 2; |
| 268 | } |
| 269 | while (n_bufs) |
| 270 | { |
| 271 | if (n_bufs > 1) |
| 272 | vlib_prefetch_buffer_header (bs[1], STORE); |
| 273 | |
| 274 | udp_push_one_header (vm, uc, bs[0]); |
| 275 | |
| 276 | n_bufs -= 1; |
| 277 | bs += 1; |
| 278 | } |
| 279 | |
Florin Coras | c754239 | 2019-07-22 08:08:43 -0700 | [diff] [blame] | 280 | if (PREDICT_FALSE (uc->flags & UDP_CONN_F_CLOSING)) |
| 281 | { |
| 282 | if (!transport_max_tx_dequeue (&uc->connection)) |
Florin Coras | 1c29dfb | 2022-10-24 18:46:20 -0700 | [diff] [blame] | 283 | udp_connection_program_cleanup (uc); |
Florin Coras | c754239 | 2019-07-22 08:08:43 -0700 | [diff] [blame] | 284 | } |
| 285 | |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 286 | return 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 287 | } |
| 288 | |
Florin Coras | c98ef75 | 2020-04-07 17:30:13 +0000 | [diff] [blame] | 289 | static transport_connection_t * |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 290 | udp_session_get (u32 connection_index, u32 thread_index) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 291 | { |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 292 | udp_connection_t *uc; |
| 293 | uc = udp_connection_get (connection_index, thread_index); |
| 294 | if (uc) |
| 295 | return &uc->connection; |
| 296 | return 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 297 | } |
| 298 | |
Florin Coras | c98ef75 | 2020-04-07 17:30:13 +0000 | [diff] [blame] | 299 | static void |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 300 | udp_session_close (u32 connection_index, u32 thread_index) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 301 | { |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 302 | udp_connection_t *uc; |
Florin Coras | c754239 | 2019-07-22 08:08:43 -0700 | [diff] [blame] | 303 | |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 304 | uc = udp_connection_get (connection_index, thread_index); |
Florin Coras | 0200044 | 2021-11-16 12:45:43 -0800 | [diff] [blame] | 305 | if (!uc || (uc->flags & UDP_CONN_F_MIGRATED)) |
Florin Coras | c754239 | 2019-07-22 08:08:43 -0700 | [diff] [blame] | 306 | return; |
| 307 | |
| 308 | if (!transport_max_tx_dequeue (&uc->connection)) |
Florin Coras | 1c29dfb | 2022-10-24 18:46:20 -0700 | [diff] [blame] | 309 | udp_connection_program_cleanup (uc); |
Florin Coras | c754239 | 2019-07-22 08:08:43 -0700 | [diff] [blame] | 310 | else |
| 311 | uc->flags |= UDP_CONN_F_CLOSING; |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 312 | } |
| 313 | |
Florin Coras | c98ef75 | 2020-04-07 17:30:13 +0000 | [diff] [blame] | 314 | static void |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 315 | udp_session_cleanup (u32 connection_index, u32 thread_index) |
| 316 | { |
| 317 | udp_connection_t *uc; |
| 318 | uc = udp_connection_get (connection_index, thread_index); |
Florin Coras | d85666f | 2020-04-03 00:58:48 +0000 | [diff] [blame] | 319 | if (!uc) |
| 320 | return; |
| 321 | if (uc->flags & UDP_CONN_F_MIGRATED) |
| 322 | udp_connection_free (uc); |
| 323 | else |
Florin Coras | 57a5a2d | 2020-04-01 23:16:11 +0000 | [diff] [blame] | 324 | udp_connection_cleanup (uc); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 325 | } |
| 326 | |
Florin Coras | 70f879d | 2020-03-13 17:54:42 +0000 | [diff] [blame] | 327 | static int |
| 328 | udp_session_send_params (transport_connection_t * tconn, |
| 329 | transport_send_params_t * sp) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 330 | { |
Florin Coras | ba78e23 | 2020-04-06 21:28:59 +0000 | [diff] [blame] | 331 | udp_connection_t *uc; |
| 332 | |
Florin Coras | e759bb5 | 2020-04-08 01:55:39 +0000 | [diff] [blame] | 333 | uc = udp_connection_from_transport (tconn); |
Florin Coras | ba78e23 | 2020-04-06 21:28:59 +0000 | [diff] [blame] | 334 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 335 | /* No constraint on TX window */ |
Florin Coras | 70f879d | 2020-03-13 17:54:42 +0000 | [diff] [blame] | 336 | sp->snd_space = ~0; |
| 337 | /* TODO figure out MTU of output interface */ |
Florin Coras | ba78e23 | 2020-04-06 21:28:59 +0000 | [diff] [blame] | 338 | sp->snd_mss = uc->mss; |
Florin Coras | 70f879d | 2020-03-13 17:54:42 +0000 | [diff] [blame] | 339 | sp->tx_offset = 0; |
| 340 | sp->flags = 0; |
| 341 | return 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 342 | } |
| 343 | |
Florin Coras | c98ef75 | 2020-04-07 17:30:13 +0000 | [diff] [blame] | 344 | static int |
Florin Coras | 5665ced | 2018-10-25 18:03:45 -0700 | [diff] [blame] | 345 | udp_open_connection (transport_endpoint_cfg_t * rmt) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 346 | { |
Florin Coras | ba78e23 | 2020-04-06 21:28:59 +0000 | [diff] [blame] | 347 | udp_main_t *um = &udp_main; |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 348 | ip46_address_t lcl_addr; |
Florin Coras | 57660d9 | 2020-04-04 22:45:34 +0000 | [diff] [blame] | 349 | udp_connection_t *uc; |
Florin Coras | c8e4110 | 2022-03-18 10:27:29 -0700 | [diff] [blame] | 350 | u32 thread_index; |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 351 | u16 lcl_port; |
Florin Coras | 00e01d3 | 2019-10-21 16:07:46 -0700 | [diff] [blame] | 352 | int rv; |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 353 | |
Florin Coras | 00e01d3 | 2019-10-21 16:07:46 -0700 | [diff] [blame] | 354 | rv = transport_alloc_local_endpoint (TRANSPORT_PROTO_UDP, rmt, &lcl_addr, |
| 355 | &lcl_port); |
| 356 | if (rv) |
Florin Coras | 57660d9 | 2020-04-04 22:45:34 +0000 | [diff] [blame] | 357 | { |
| 358 | if (rv != SESSION_E_PORTINUSE) |
| 359 | return rv; |
| 360 | |
| 361 | if (udp_connection_port_used_extern (lcl_port, rmt->is_ip4)) |
| 362 | return SESSION_E_PORTINUSE; |
| 363 | |
| 364 | /* If port in use, check if 5-tuple is also in use */ |
| 365 | if (session_lookup_connection (rmt->fib_index, &lcl_addr, &rmt->ip, |
| 366 | lcl_port, rmt->port, TRANSPORT_PROTO_UDP, |
| 367 | rmt->is_ip4)) |
| 368 | return SESSION_E_PORTINUSE; |
| 369 | |
| 370 | /* 5-tuple is available so increase lcl endpoint refcount and proceed |
| 371 | * with connection allocation */ |
| 372 | transport_share_local_endpoint (TRANSPORT_PROTO_UDP, &lcl_addr, |
| 373 | lcl_port); |
| 374 | goto conn_alloc; |
| 375 | } |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 376 | |
Florin Coras | a039620 | 2020-04-01 00:11:16 +0000 | [diff] [blame] | 377 | if (udp_is_valid_dst_port (lcl_port, rmt->is_ip4)) |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 378 | { |
Florin Coras | a039620 | 2020-04-01 00:11:16 +0000 | [diff] [blame] | 379 | /* If specific source port was requested abort */ |
| 380 | if (rmt->peer.port) |
Florin Coras | 00e01d3 | 2019-10-21 16:07:46 -0700 | [diff] [blame] | 381 | return SESSION_E_PORTINUSE; |
Florin Coras | a039620 | 2020-04-01 00:11:16 +0000 | [diff] [blame] | 382 | |
| 383 | /* Try to find a port that's not used */ |
| 384 | while (udp_is_valid_dst_port (lcl_port, rmt->is_ip4)) |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 385 | { |
Florin Coras | a039620 | 2020-04-01 00:11:16 +0000 | [diff] [blame] | 386 | lcl_port = transport_alloc_local_port (TRANSPORT_PROTO_UDP, |
| 387 | &lcl_addr); |
| 388 | if (lcl_port < 1) |
Florin Coras | 00e01d3 | 2019-10-21 16:07:46 -0700 | [diff] [blame] | 389 | return SESSION_E_PORTINUSE; |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 390 | } |
| 391 | } |
| 392 | |
Florin Coras | 57660d9 | 2020-04-04 22:45:34 +0000 | [diff] [blame] | 393 | conn_alloc: |
| 394 | |
Florin Coras | 40903ac | 2018-06-10 14:41:23 -0700 | [diff] [blame] | 395 | /* We don't poll main thread if we have workers */ |
Florin Coras | fb50bc3 | 2021-05-18 00:28:59 -0700 | [diff] [blame] | 396 | thread_index = transport_cl_thread (); |
Florin Coras | 40903ac | 2018-06-10 14:41:23 -0700 | [diff] [blame] | 397 | |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 398 | uc = udp_connection_alloc (thread_index); |
| 399 | ip_copy (&uc->c_rmt_ip, &rmt->ip, rmt->is_ip4); |
| 400 | ip_copy (&uc->c_lcl_ip, &lcl_addr, rmt->is_ip4); |
| 401 | uc->c_rmt_port = rmt->port; |
| 402 | uc->c_lcl_port = clib_host_to_net_u16 (lcl_port); |
| 403 | uc->c_is_ip4 = rmt->is_ip4; |
| 404 | uc->c_proto = TRANSPORT_PROTO_UDP; |
| 405 | uc->c_fib_index = rmt->fib_index; |
Filip Tehlar | 3ef8bf3 | 2021-10-21 14:07:31 +0000 | [diff] [blame] | 406 | uc->c_dscp = rmt->dscp; |
Florin Coras | c98ef75 | 2020-04-07 17:30:13 +0000 | [diff] [blame] | 407 | uc->mss = rmt->mss ? rmt->mss : udp_default_mtu (um, uc->c_is_ip4); |
Steven Luong | bf12efc | 2022-07-25 09:29:23 -0700 | [diff] [blame] | 408 | if (rmt->peer.sw_if_index != ENDPOINT_INVALID_INDEX) |
| 409 | uc->sw_if_index = rmt->peer.sw_if_index; |
Florin Coras | c754239 | 2019-07-22 08:08:43 -0700 | [diff] [blame] | 410 | uc->flags |= UDP_CONN_F_OWNS_PORT; |
Florin Coras | 87b7e3d | 2020-03-27 15:06:07 +0000 | [diff] [blame] | 411 | if (rmt->transport_flags & TRANSPORT_CFG_F_CONNECTED) |
Florin Coras | 0ac5782 | 2021-03-03 08:06:12 -0800 | [diff] [blame] | 412 | { |
| 413 | uc->flags |= UDP_CONN_F_CONNECTED; |
| 414 | } |
Florin Coras | 87b7e3d | 2020-03-27 15:06:07 +0000 | [diff] [blame] | 415 | else |
Florin Coras | 0ac5782 | 2021-03-03 08:06:12 -0800 | [diff] [blame] | 416 | { |
| 417 | clib_spinlock_init (&uc->rx_lock); |
| 418 | uc->c_flags |= TRANSPORT_CONNECTION_F_CLESS; |
| 419 | } |
Florin Coras | f8ee39f | 2022-10-18 18:37:56 -0700 | [diff] [blame] | 420 | if (!um->csum_offload) |
| 421 | uc->cfg_flags |= UDP_CFG_F_NO_CSUM_OFFLOAD; |
Florin Coras | 8c1be05 | 2022-10-17 11:52:34 -0700 | [diff] [blame] | 422 | uc->next_node_index = rmt->next_node_index; |
| 423 | uc->next_node_opaque = rmt->next_node_opaque; |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 424 | |
Florin Coras | e1f2058 | 2022-11-11 11:37:36 -0800 | [diff] [blame] | 425 | udp_connection_register_port (uc->c_lcl_port, rmt->is_ip4); |
| 426 | |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 427 | return uc->c_c_index; |
| 428 | } |
| 429 | |
Florin Coras | c98ef75 | 2020-04-07 17:30:13 +0000 | [diff] [blame] | 430 | static transport_connection_t * |
Florin Coras | 40903ac | 2018-06-10 14:41:23 -0700 | [diff] [blame] | 431 | udp_session_get_half_open (u32 conn_index) |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 432 | { |
| 433 | udp_connection_t *uc; |
Florin Coras | 40903ac | 2018-06-10 14:41:23 -0700 | [diff] [blame] | 434 | u32 thread_index; |
| 435 | |
| 436 | /* We don't poll main thread if we have workers */ |
Florin Coras | fb50bc3 | 2021-05-18 00:28:59 -0700 | [diff] [blame] | 437 | thread_index = transport_cl_thread (); |
Florin Coras | 40903ac | 2018-06-10 14:41:23 -0700 | [diff] [blame] | 438 | uc = udp_connection_get (conn_index, thread_index); |
Nathan Skrzypczak | e971bc9 | 2019-06-19 13:42:37 +0200 | [diff] [blame] | 439 | if (!uc) |
| 440 | return 0; |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 441 | return &uc->connection; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 442 | } |
| 443 | |
Florin Coras | c98ef75 | 2020-04-07 17:30:13 +0000 | [diff] [blame] | 444 | static u8 * |
| 445 | format_udp_session (u8 * s, va_list * args) |
| 446 | { |
| 447 | u32 uci = va_arg (*args, u32); |
| 448 | u32 thread_index = va_arg (*args, u32); |
| 449 | u32 verbose = va_arg (*args, u32); |
| 450 | udp_connection_t *uc; |
| 451 | |
| 452 | uc = udp_connection_get (uci, thread_index); |
| 453 | return format (s, "%U", format_udp_connection, uc, verbose); |
| 454 | } |
| 455 | |
| 456 | static u8 * |
| 457 | format_udp_half_open_session (u8 * s, va_list * args) |
| 458 | { |
| 459 | u32 __clib_unused tci = va_arg (*args, u32); |
| 460 | u32 __clib_unused thread_index = va_arg (*args, u32); |
| 461 | clib_warning ("BUG"); |
| 462 | return 0; |
| 463 | } |
| 464 | |
| 465 | static u8 * |
| 466 | format_udp_listener_session (u8 * s, va_list * args) |
| 467 | { |
| 468 | u32 tci = va_arg (*args, u32); |
| 469 | u32 __clib_unused thread_index = va_arg (*args, u32); |
| 470 | u32 verbose = va_arg (*args, u32); |
| 471 | udp_connection_t *uc = udp_listener_get (tci); |
| 472 | return format (s, "%U", format_udp_connection, uc, verbose); |
| 473 | } |
| 474 | |
Florin Coras | 797562c | 2022-11-18 18:29:23 -0800 | [diff] [blame] | 475 | static void |
| 476 | udp_realloc_ports_sv (u16 **ports_nh_svp) |
| 477 | { |
| 478 | u16 port, port_no, *ports_nh_sv, *mc; |
| 479 | u32 *ports = 0, *nh = 0, msum, i; |
| 480 | sparse_vec_header_t *h; |
| 481 | uword sv_index, *mb; |
| 482 | |
| 483 | ports_nh_sv = *ports_nh_svp; |
| 484 | |
| 485 | for (port = 1; port < 65535; port++) |
| 486 | { |
| 487 | port_no = clib_host_to_net_u16 (port); |
| 488 | |
| 489 | sv_index = sparse_vec_index (ports_nh_sv, port_no); |
| 490 | if (sv_index != SPARSE_VEC_INVALID_INDEX) |
| 491 | { |
| 492 | vec_add1 (ports, port_no); |
| 493 | vec_add1 (nh, ports_nh_sv[sv_index]); |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | sparse_vec_free (ports_nh_sv); |
| 498 | |
| 499 | ports_nh_sv = |
| 500 | sparse_vec_new (/* elt bytes */ sizeof (ports_nh_sv[0]), |
| 501 | /* bits in index */ BITS (((udp_header_t *) 0)->dst_port)); |
| 502 | |
| 503 | vec_resize (ports_nh_sv, 65535); |
| 504 | |
| 505 | for (port = 1; port < 65535; port++) |
Florin Coras | e1f2058 | 2022-11-11 11:37:36 -0800 | [diff] [blame] | 506 | ports_nh_sv[port] = UDP_NO_NODE_SET; |
Florin Coras | 797562c | 2022-11-18 18:29:23 -0800 | [diff] [blame] | 507 | |
| 508 | for (i = 0; i < vec_len (ports); i++) |
| 509 | ports_nh_sv[ports[i]] = nh[i]; |
| 510 | |
| 511 | h = sparse_vec_header (ports_nh_sv); |
| 512 | vec_foreach (mb, h->is_member_bitmap) |
| 513 | *mb = (uword) ~0; |
| 514 | |
| 515 | msum = 0; |
| 516 | vec_foreach (mc, h->member_counts) |
| 517 | { |
| 518 | *mc = msum; |
| 519 | msum += msum == 0 ? 63 : 64; |
| 520 | } |
| 521 | |
| 522 | vec_free (ports); |
| 523 | vec_free (nh); |
| 524 | |
| 525 | *ports_nh_svp = ports_nh_sv; |
| 526 | } |
| 527 | |
| 528 | static clib_error_t * |
| 529 | udp_enable_disable (vlib_main_t *vm, u8 is_en) |
| 530 | { |
| 531 | udp_main_t *um = &udp_main; |
| 532 | |
| 533 | /* Not ideal. The sparse vector used to map ports to next nodes assumes |
| 534 | * only a few ports are ever used. When udp transport is enabled this does |
| 535 | * not hold and, to make matters worse, ports are consumed in a random |
| 536 | * order. |
| 537 | * |
| 538 | * This can lead to a lot of slow updates to internal data structures |
| 539 | * which in turn can slow udp connection allocations until all ports are |
| 540 | * eventually consumed. |
| 541 | * |
| 542 | * Consequently, reallocate sparse vector, preallocate all ports and have |
| 543 | * them point to UDP_NO_NODE_SET. We could consider switching the sparse |
| 544 | * vector to a preallocated vector but that would increase memory |
| 545 | * consumption for vpp deployments that do not rely on host stack. |
| 546 | */ |
| 547 | |
| 548 | udp_realloc_ports_sv (&um->next_by_dst_port4); |
| 549 | udp_realloc_ports_sv (&um->next_by_dst_port6); |
| 550 | |
| 551 | return 0; |
| 552 | } |
| 553 | |
Nathan Skrzypczak | e971bc9 | 2019-06-19 13:42:37 +0200 | [diff] [blame] | 554 | static const transport_proto_vft_t udp_proto = { |
Florin Coras | 797562c | 2022-11-18 18:29:23 -0800 | [diff] [blame] | 555 | .enable = udp_enable_disable, |
Florin Coras | 1ee7830 | 2019-02-05 15:51:15 -0800 | [diff] [blame] | 556 | .start_listen = udp_session_bind, |
| 557 | .connect = udp_open_connection, |
| 558 | .stop_listen = udp_session_unbind, |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 559 | .push_header = udp_push_header, |
| 560 | .get_connection = udp_session_get, |
| 561 | .get_listener = udp_session_get_listener, |
Florin Coras | 40903ac | 2018-06-10 14:41:23 -0700 | [diff] [blame] | 562 | .get_half_open = udp_session_get_half_open, |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 563 | .close = udp_session_close, |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 564 | .cleanup = udp_session_cleanup, |
Florin Coras | 70f879d | 2020-03-13 17:54:42 +0000 | [diff] [blame] | 565 | .send_params = udp_session_send_params, |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 566 | .format_connection = format_udp_session, |
| 567 | .format_half_open = format_udp_half_open_session, |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 568 | .format_listener = format_udp_listener_session, |
Nathan Skrzypczak | e971bc9 | 2019-06-19 13:42:37 +0200 | [diff] [blame] | 569 | .transport_options = { |
Florin Coras | 07063b8 | 2020-03-13 04:44:51 +0000 | [diff] [blame] | 570 | .name = "udp", |
| 571 | .short_name = "U", |
Nathan Skrzypczak | e971bc9 | 2019-06-19 13:42:37 +0200 | [diff] [blame] | 572 | .tx_type = TRANSPORT_TX_DGRAM, |
| 573 | .service_type = TRANSPORT_SERVICE_CL, |
| 574 | }, |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 575 | }; |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 576 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 577 | static clib_error_t * |
| 578 | udp_init (vlib_main_t * vm) |
| 579 | { |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 580 | udp_main_t *um = vnet_get_udp_main (); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 581 | ip_main_t *im = &ip_main; |
| 582 | vlib_thread_main_t *tm = vlib_get_thread_main (); |
| 583 | u32 num_threads; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 584 | ip_protocol_info_t *pi; |
| 585 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 586 | /* |
| 587 | * Registrations |
| 588 | */ |
| 589 | |
| 590 | /* IP registration */ |
| 591 | pi = ip_get_protocol_info (im, IP_PROTOCOL_UDP); |
| 592 | if (pi == 0) |
| 593 | return clib_error_return (0, "UDP protocol info AWOL"); |
| 594 | pi->format_header = format_udp_header; |
| 595 | pi->unformat_pg_edit = unformat_pg_udp_header; |
| 596 | |
Florin Coras | 8c1be05 | 2022-10-17 11:52:34 -0700 | [diff] [blame] | 597 | /* Register as transport with session layer */ |
Florin Coras | 561af9b | 2017-12-09 10:19:43 -0800 | [diff] [blame] | 598 | transport_register_protocol (TRANSPORT_PROTO_UDP, &udp_proto, |
Florin Coras | 8c1be05 | 2022-10-17 11:52:34 -0700 | [diff] [blame] | 599 | FIB_PROTOCOL_IP4, udp4_output_node.index); |
Florin Coras | 561af9b | 2017-12-09 10:19:43 -0800 | [diff] [blame] | 600 | transport_register_protocol (TRANSPORT_PROTO_UDP, &udp_proto, |
Florin Coras | 8c1be05 | 2022-10-17 11:52:34 -0700 | [diff] [blame] | 601 | FIB_PROTOCOL_IP6, udp6_output_node.index); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 602 | |
| 603 | /* |
| 604 | * Initialize data structures |
| 605 | */ |
| 606 | |
| 607 | num_threads = 1 /* main thread */ + tm->n_threads; |
Florin Coras | 1c29dfb | 2022-10-24 18:46:20 -0700 | [diff] [blame] | 608 | vec_validate (um->wrk, num_threads - 1); |
Florin Coras | a039620 | 2020-04-01 00:11:16 +0000 | [diff] [blame] | 609 | |
| 610 | um->local_to_input_edge[UDP_IP4] = |
| 611 | vlib_node_add_next (vm, udp4_local_node.index, udp4_input_node.index); |
| 612 | um->local_to_input_edge[UDP_IP6] = |
| 613 | vlib_node_add_next (vm, udp6_local_node.index, udp6_input_node.index); |
Florin Coras | ba78e23 | 2020-04-06 21:28:59 +0000 | [diff] [blame] | 614 | |
| 615 | um->default_mtu = 1500; |
Florin Coras | f8ee39f | 2022-10-18 18:37:56 -0700 | [diff] [blame] | 616 | um->csum_offload = 1; |
Dave Barach | f8d5068 | 2019-05-14 18:01:44 -0400 | [diff] [blame] | 617 | return 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 618 | } |
| 619 | |
Dave Barach | f8d5068 | 2019-05-14 18:01:44 -0400 | [diff] [blame] | 620 | /* *INDENT-OFF* */ |
| 621 | VLIB_INIT_FUNCTION (udp_init) = |
| 622 | { |
| 623 | .runs_after = VLIB_INITS("ip_main_init", "ip4_lookup_init", |
| 624 | "ip6_lookup_init"), |
| 625 | }; |
| 626 | /* *INDENT-ON* */ |
| 627 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 628 | /* |
| 629 | * fd.io coding-style-patch-verification: ON |
| 630 | * |
| 631 | * Local Variables: |
| 632 | * eval: (c-set-style "gnu") |
| 633 | * End: |
| 634 | */ |