Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 Cisco and/or its affiliates. |
| 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 | |
| 16 | #include <vlib/vlib.h> |
| 17 | #include <vnet/vnet.h> |
| 18 | #include <vppinfra/error.h> |
| 19 | #include <vnet/ethernet/ethernet.h> |
| 20 | #include <vnet/feature/feature.h> |
| 21 | #include <vnet/gso/gso.h> |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 22 | #include <vnet/gso/hdr_offset_parser.h> |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 23 | #include <vnet/ip/icmp46_packet.h> |
| 24 | #include <vnet/ip/ip4.h> |
| 25 | #include <vnet/ip/ip6.h> |
| 26 | #include <vnet/udp/udp_packet.h> |
| 27 | |
Mohsin Kazmi | 79e087f | 2021-05-27 21:05:41 +0200 | [diff] [blame] | 28 | #define foreach_gso_error \ |
| 29 | _ (NO_BUFFERS, "no buffers to segment GSO") \ |
| 30 | _ (UNHANDLED_TYPE, "unhandled gso type") |
| 31 | |
| 32 | static char *gso_error_strings[] = { |
| 33 | #define _(sym, string) string, |
| 34 | foreach_gso_error |
| 35 | #undef _ |
| 36 | }; |
| 37 | |
| 38 | typedef enum |
| 39 | { |
| 40 | #define _(sym, str) GSO_ERROR_##sym, |
| 41 | foreach_gso_error |
| 42 | #undef _ |
| 43 | GSO_N_ERROR, |
| 44 | } gso_error_t; |
| 45 | |
| 46 | typedef enum |
| 47 | { |
| 48 | GSO_NEXT_DROP, |
| 49 | GSO_N_NEXT, |
| 50 | } gso_next_t; |
| 51 | |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 52 | typedef struct |
| 53 | { |
| 54 | u32 flags; |
| 55 | u16 gso_size; |
| 56 | u8 gso_l4_hdr_sz; |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 57 | generic_header_offset_t gho; |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 58 | } gso_trace_t; |
| 59 | |
| 60 | static u8 * |
| 61 | format_gso_trace (u8 * s, va_list * args) |
| 62 | { |
| 63 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 64 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
| 65 | gso_trace_t *t = va_arg (*args, gso_trace_t *); |
| 66 | |
| 67 | if (t->flags & VNET_BUFFER_F_GSO) |
| 68 | { |
Mohsin Kazmi | b3a8f4e | 2020-09-15 16:41:44 +0000 | [diff] [blame] | 69 | s = format (s, "gso_sz %d gso_l4_hdr_sz %d\n%U", |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 70 | t->gso_size, t->gso_l4_hdr_sz, format_generic_header_offset, |
| 71 | &t->gho); |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 72 | } |
Mohsin Kazmi | 70ae4ef | 2019-12-09 11:46:01 +0100 | [diff] [blame] | 73 | else |
| 74 | { |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 75 | s = |
Mohsin Kazmi | b3a8f4e | 2020-09-15 16:41:44 +0000 | [diff] [blame] | 76 | format (s, "non-gso buffer\n%U", format_generic_header_offset, |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 77 | &t->gho); |
Mohsin Kazmi | 70ae4ef | 2019-12-09 11:46:01 +0100 | [diff] [blame] | 78 | } |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 79 | |
| 80 | return s; |
| 81 | } |
| 82 | |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 83 | static_always_inline u16 |
| 84 | tso_segment_ipip_tunnel_fixup (vlib_main_t * vm, |
| 85 | vnet_interface_per_thread_data_t * ptd, |
| 86 | vlib_buffer_t * sb0, |
| 87 | generic_header_offset_t * gho) |
| 88 | { |
| 89 | u16 n_tx_bufs = vec_len (ptd->split_buffers); |
| 90 | u16 i = 0, n_tx_bytes = 0; |
| 91 | |
| 92 | while (i < n_tx_bufs) |
| 93 | { |
| 94 | vlib_buffer_t *b0 = vlib_get_buffer (vm, ptd->split_buffers[i]); |
| 95 | vnet_get_outer_header (b0, gho); |
| 96 | clib_memcpy_fast (vlib_buffer_get_current (b0), |
| 97 | vlib_buffer_get_current (sb0), gho->outer_hdr_sz); |
| 98 | |
| 99 | ip4_header_t *ip4 = |
| 100 | (ip4_header_t *) (vlib_buffer_get_current (b0) + |
| 101 | gho->outer_l3_hdr_offset); |
| 102 | ip6_header_t *ip6 = |
| 103 | (ip6_header_t *) (vlib_buffer_get_current (b0) + |
| 104 | gho->outer_l3_hdr_offset); |
| 105 | |
| 106 | if (gho->gho_flags & GHO_F_OUTER_IP4) |
| 107 | { |
| 108 | ip4->length = |
| 109 | clib_host_to_net_u16 (b0->current_length - |
| 110 | gho->outer_l3_hdr_offset); |
| 111 | ip4->checksum = ip4_header_checksum (ip4); |
| 112 | } |
| 113 | else if (gho->gho_flags & GHO_F_OUTER_IP6) |
| 114 | { |
| 115 | ip6->payload_length = |
| 116 | clib_host_to_net_u16 (b0->current_length - |
| 117 | gho->outer_l4_hdr_offset); |
| 118 | } |
| 119 | |
| 120 | n_tx_bytes += gho->outer_hdr_sz; |
| 121 | i++; |
| 122 | } |
| 123 | return n_tx_bytes; |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 124 | } |
| 125 | |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 126 | static_always_inline void |
| 127 | tso_segment_vxlan_tunnel_headers_fixup (vlib_main_t * vm, vlib_buffer_t * b, |
| 128 | generic_header_offset_t * gho) |
| 129 | { |
| 130 | u8 proto = 0; |
| 131 | ip4_header_t *ip4 = 0; |
| 132 | ip6_header_t *ip6 = 0; |
| 133 | udp_header_t *udp = 0; |
| 134 | |
| 135 | ip4 = |
| 136 | (ip4_header_t *) (vlib_buffer_get_current (b) + gho->outer_l3_hdr_offset); |
| 137 | ip6 = |
| 138 | (ip6_header_t *) (vlib_buffer_get_current (b) + gho->outer_l3_hdr_offset); |
| 139 | udp = |
| 140 | (udp_header_t *) (vlib_buffer_get_current (b) + gho->outer_l4_hdr_offset); |
| 141 | |
| 142 | if (gho->gho_flags & GHO_F_OUTER_IP4) |
| 143 | { |
| 144 | proto = ip4->protocol; |
| 145 | ip4->length = |
| 146 | clib_host_to_net_u16 (b->current_length - gho->outer_l3_hdr_offset); |
| 147 | ip4->checksum = ip4_header_checksum (ip4); |
| 148 | } |
| 149 | else if (gho->gho_flags & GHO_F_OUTER_IP6) |
| 150 | { |
| 151 | proto = ip6->protocol; |
| 152 | ip6->payload_length = |
| 153 | clib_host_to_net_u16 (b->current_length - gho->outer_l4_hdr_offset); |
| 154 | } |
| 155 | if (proto == IP_PROTOCOL_UDP) |
| 156 | { |
| 157 | int bogus; |
| 158 | udp->length = |
| 159 | clib_host_to_net_u16 (b->current_length - gho->outer_l4_hdr_offset); |
| 160 | udp->checksum = 0; |
| 161 | if (gho->gho_flags & GHO_F_OUTER_IP6) |
| 162 | { |
| 163 | udp->checksum = |
| 164 | ip6_tcp_udp_icmp_compute_checksum (vm, b, ip6, &bogus); |
| 165 | } |
| 166 | else if (gho->gho_flags & GHO_F_OUTER_IP4) |
| 167 | { |
| 168 | udp->checksum = ip4_tcp_udp_compute_checksum (vm, b, ip4); |
| 169 | } |
Mohsin Kazmi | 6809538 | 2021-02-10 11:26:24 +0100 | [diff] [blame] | 170 | /* FIXME: it should be OUTER_UDP_CKSUM */ |
| 171 | vnet_buffer_offload_flags_clear (b, VNET_BUFFER_OFFLOAD_F_UDP_CKSUM); |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 172 | } |
| 173 | } |
| 174 | |
| 175 | static_always_inline u16 |
| 176 | tso_segment_vxlan_tunnel_fixup (vlib_main_t * vm, |
| 177 | vnet_interface_per_thread_data_t * ptd, |
| 178 | vlib_buffer_t * sb0, |
| 179 | generic_header_offset_t * gho) |
| 180 | { |
| 181 | u16 n_tx_bufs = vec_len (ptd->split_buffers); |
| 182 | u16 i = 0, n_tx_bytes = 0; |
| 183 | |
| 184 | while (i < n_tx_bufs) |
| 185 | { |
| 186 | vlib_buffer_t *b0 = vlib_get_buffer (vm, ptd->split_buffers[i]); |
| 187 | vnet_get_outer_header (b0, gho); |
| 188 | clib_memcpy_fast (vlib_buffer_get_current (b0), |
| 189 | vlib_buffer_get_current (sb0), gho->outer_hdr_sz); |
| 190 | |
| 191 | tso_segment_vxlan_tunnel_headers_fixup (vm, b0, gho); |
| 192 | n_tx_bytes += gho->outer_hdr_sz; |
| 193 | i++; |
| 194 | } |
| 195 | return n_tx_bytes; |
| 196 | } |
| 197 | |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 198 | static_always_inline u16 |
| 199 | tso_alloc_tx_bufs (vlib_main_t * vm, |
| 200 | vnet_interface_per_thread_data_t * ptd, |
| 201 | vlib_buffer_t * b0, u32 n_bytes_b0, u16 l234_sz, |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 202 | u16 gso_size, u16 first_data_size, |
| 203 | generic_header_offset_t * gho) |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 204 | { |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 205 | u16 n_alloc, size; |
| 206 | u16 first_packet_length = l234_sz + first_data_size; |
| 207 | |
| 208 | /* |
| 209 | * size is the amount of data per segmented buffer except the 1st |
| 210 | * segmented buffer. |
| 211 | * l2_hdr_offset is an offset == current_data of vlib_buffer_t. |
| 212 | * l234_sz is hdr_sz from l2_hdr_offset. |
| 213 | */ |
| 214 | size = |
Mohsin Kazmi | 222b709 | 2019-12-25 00:12:52 +0100 | [diff] [blame] | 215 | clib_min (gso_size, vlib_buffer_get_default_data_size (vm) - l234_sz |
| 216 | - gho->l2_hdr_offset); |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 217 | |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 218 | /* |
| 219 | * First segmented buffer length is calculated separately. |
| 220 | * As it may contain less data than gso_size (when gso_size is |
| 221 | * greater than current_length of 1st buffer from GSO chained |
| 222 | * buffers) and/or size calculated above. |
| 223 | */ |
| 224 | u16 n_bufs = 1; |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 225 | |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 226 | /* |
| 227 | * Total packet length minus first packet length including l234 header. |
| 228 | * rounded-up division |
| 229 | */ |
| 230 | ASSERT (n_bytes_b0 > first_packet_length); |
| 231 | n_bufs += ((n_bytes_b0 - first_packet_length + (size - 1)) / size); |
| 232 | |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 233 | vec_validate (ptd->split_buffers, n_bufs - 1); |
| 234 | |
| 235 | n_alloc = vlib_buffer_alloc (vm, ptd->split_buffers, n_bufs); |
| 236 | if (n_alloc < n_bufs) |
| 237 | { |
| 238 | vlib_buffer_free (vm, ptd->split_buffers, n_alloc); |
| 239 | return 0; |
| 240 | } |
| 241 | return n_alloc; |
| 242 | } |
| 243 | |
| 244 | static_always_inline void |
| 245 | tso_init_buf_from_template_base (vlib_buffer_t * nb0, vlib_buffer_t * b0, |
| 246 | u32 flags, u16 length) |
| 247 | { |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 248 | /* copying objects from cacheline 0 */ |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 249 | nb0->current_data = b0->current_data; |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 250 | nb0->current_length = length; |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 251 | nb0->flags = VLIB_BUFFER_TOTAL_LENGTH_VALID | flags; |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 252 | nb0->flow_id = b0->flow_id; |
| 253 | nb0->error = b0->error; |
| 254 | nb0->current_config_index = b0->current_config_index; |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 255 | clib_memcpy_fast (&nb0->opaque, &b0->opaque, sizeof (nb0->opaque)); |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 256 | |
| 257 | /* copying objects from cacheline 1 */ |
| 258 | nb0->trace_handle = b0->trace_handle; |
| 259 | nb0->total_length_not_including_first_buffer = 0; |
| 260 | |
| 261 | /* copying data */ |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 262 | clib_memcpy_fast (vlib_buffer_get_current (nb0), |
| 263 | vlib_buffer_get_current (b0), length); |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | static_always_inline void |
| 267 | tso_init_buf_from_template (vlib_main_t * vm, vlib_buffer_t * nb0, |
| 268 | vlib_buffer_t * b0, u16 template_data_sz, |
| 269 | u16 gso_size, u8 ** p_dst_ptr, u16 * p_dst_left, |
Mohsin Kazmi | 72e7312 | 2019-10-22 13:33:13 +0200 | [diff] [blame] | 270 | u32 next_tcp_seq, u32 flags, |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 271 | generic_header_offset_t * gho) |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 272 | { |
| 273 | tso_init_buf_from_template_base (nb0, b0, flags, template_data_sz); |
| 274 | |
| 275 | *p_dst_left = |
| 276 | clib_min (gso_size, |
| 277 | vlib_buffer_get_default_data_size (vm) - (template_data_sz + |
| 278 | nb0->current_data)); |
| 279 | *p_dst_ptr = vlib_buffer_get_current (nb0) + template_data_sz; |
| 280 | |
| 281 | tcp_header_t *tcp = |
Mohsin Kazmi | 72e7312 | 2019-10-22 13:33:13 +0200 | [diff] [blame] | 282 | (tcp_header_t *) (vlib_buffer_get_current (nb0) + gho->l4_hdr_offset); |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 283 | tcp->seq_number = clib_host_to_net_u32 (next_tcp_seq); |
| 284 | } |
| 285 | |
| 286 | static_always_inline void |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 287 | tso_fixup_segmented_buf (vlib_main_t * vm, vlib_buffer_t * b0, u8 tcp_flags, |
Mohsin Kazmi | ec1d61e | 2020-06-24 16:20:54 +0200 | [diff] [blame] | 288 | int is_l2, int is_ip6, generic_header_offset_t * gho) |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 289 | { |
Mohsin Kazmi | 72e7312 | 2019-10-22 13:33:13 +0200 | [diff] [blame] | 290 | ip4_header_t *ip4 = |
| 291 | (ip4_header_t *) (vlib_buffer_get_current (b0) + gho->l3_hdr_offset); |
| 292 | ip6_header_t *ip6 = |
| 293 | (ip6_header_t *) (vlib_buffer_get_current (b0) + gho->l3_hdr_offset); |
| 294 | tcp_header_t *tcp = |
| 295 | (tcp_header_t *) (vlib_buffer_get_current (b0) + gho->l4_hdr_offset); |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 296 | |
| 297 | tcp->flags = tcp_flags; |
| 298 | |
| 299 | if (is_ip6) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 300 | { |
| 301 | ip6->payload_length = |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 302 | clib_host_to_net_u16 (b0->current_length - gho->l4_hdr_offset); |
| 303 | if (gho->gho_flags & GHO_F_TCP) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 304 | { |
| 305 | int bogus = 0; |
| 306 | tcp->checksum = 0; |
| 307 | tcp->checksum = |
| 308 | ip6_tcp_udp_icmp_compute_checksum (vm, b0, ip6, &bogus); |
Mohsin Kazmi | 6809538 | 2021-02-10 11:26:24 +0100 | [diff] [blame] | 309 | vnet_buffer_offload_flags_clear (b0, |
| 310 | VNET_BUFFER_OFFLOAD_F_TCP_CKSUM); |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 311 | } |
| 312 | } |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 313 | else |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 314 | { |
| 315 | ip4->length = |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 316 | clib_host_to_net_u16 (b0->current_length - gho->l3_hdr_offset); |
| 317 | if (gho->gho_flags & GHO_F_IP4) |
| 318 | ip4->checksum = ip4_header_checksum (ip4); |
| 319 | if (gho->gho_flags & GHO_F_TCP) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 320 | { |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 321 | tcp->checksum = 0; |
| 322 | tcp->checksum = ip4_tcp_udp_compute_checksum (vm, b0, ip4); |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 323 | } |
Mohsin Kazmi | 6809538 | 2021-02-10 11:26:24 +0100 | [diff] [blame] | 324 | vnet_buffer_offload_flags_clear (b0, (VNET_BUFFER_OFFLOAD_F_IP_CKSUM | |
| 325 | VNET_BUFFER_OFFLOAD_F_TCP_CKSUM)); |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 326 | } |
| 327 | |
Mohsin Kazmi | ec1d61e | 2020-06-24 16:20:54 +0200 | [diff] [blame] | 328 | if (!is_l2 && ((gho->gho_flags & GHO_F_TUNNEL) == 0)) |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 329 | { |
| 330 | u32 adj_index0 = vnet_buffer (b0)->ip.adj_index[VLIB_TX]; |
| 331 | |
| 332 | ip_adjacency_t *adj0 = adj_get (adj_index0); |
| 333 | |
| 334 | if (adj0->lookup_next_index == IP_LOOKUP_NEXT_MIDCHAIN && |
| 335 | adj0->sub_type.midchain.fixup_func) |
| 336 | /* calls e.g. ipip44_fixup */ |
| 337 | adj0->sub_type.midchain.fixup_func |
| 338 | (vm, adj0, b0, adj0->sub_type.midchain.fixup_data); |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 339 | } |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | /** |
| 343 | * Allocate the necessary number of ptd->split_buffers, |
| 344 | * and segment the possibly chained buffer(s) from b0 into |
| 345 | * there. |
| 346 | * |
| 347 | * Return the cumulative number of bytes sent or zero |
| 348 | * if allocation failed. |
| 349 | */ |
| 350 | |
| 351 | static_always_inline u32 |
| 352 | tso_segment_buffer (vlib_main_t * vm, vnet_interface_per_thread_data_t * ptd, |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 353 | u32 sbi0, vlib_buffer_t * sb0, |
Mohsin Kazmi | ec1d61e | 2020-06-24 16:20:54 +0200 | [diff] [blame] | 354 | generic_header_offset_t * gho, u32 n_bytes_b0, int is_l2, |
| 355 | int is_ip6) |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 356 | { |
| 357 | u32 n_tx_bytes = 0; |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 358 | u16 gso_size = vnet_buffer2 (sb0)->gso_size; |
| 359 | |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 360 | u8 save_tcp_flags = 0; |
| 361 | u8 tcp_flags_no_fin_psh = 0; |
| 362 | u32 next_tcp_seq = 0; |
| 363 | |
| 364 | tcp_header_t *tcp = |
Mohsin Kazmi | 72e7312 | 2019-10-22 13:33:13 +0200 | [diff] [blame] | 365 | (tcp_header_t *) (vlib_buffer_get_current (sb0) + gho->l4_hdr_offset); |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 366 | next_tcp_seq = clib_net_to_host_u32 (tcp->seq_number); |
| 367 | /* store original flags for last packet and reset FIN and PSH */ |
| 368 | save_tcp_flags = tcp->flags; |
| 369 | tcp_flags_no_fin_psh = tcp->flags & ~(TCP_FLAG_FIN | TCP_FLAG_PSH); |
| 370 | tcp->checksum = 0; |
| 371 | |
| 372 | u32 default_bflags = |
| 373 | sb0->flags & ~(VNET_BUFFER_F_GSO | VLIB_BUFFER_NEXT_PRESENT); |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 374 | u16 l234_sz = gho->hdr_sz; |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 375 | int first_data_size = clib_min (gso_size, sb0->current_length - l234_sz); |
| 376 | next_tcp_seq += first_data_size; |
| 377 | |
| 378 | if (PREDICT_FALSE |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 379 | (!tso_alloc_tx_bufs |
| 380 | (vm, ptd, sb0, n_bytes_b0, l234_sz, gso_size, first_data_size, gho))) |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 381 | return 0; |
| 382 | |
| 383 | vlib_buffer_t *b0 = vlib_get_buffer (vm, ptd->split_buffers[0]); |
| 384 | tso_init_buf_from_template_base (b0, sb0, default_bflags, |
| 385 | l234_sz + first_data_size); |
| 386 | |
| 387 | u32 total_src_left = n_bytes_b0 - l234_sz - first_data_size; |
| 388 | if (total_src_left) |
| 389 | { |
| 390 | /* Need to copy more segments */ |
| 391 | u8 *src_ptr, *dst_ptr; |
| 392 | u16 src_left, dst_left; |
| 393 | /* current source buffer */ |
| 394 | vlib_buffer_t *csb0 = sb0; |
| 395 | u32 csbi0 = sbi0; |
| 396 | /* current dest buffer */ |
| 397 | vlib_buffer_t *cdb0; |
| 398 | u16 dbi = 1; /* the buffer [0] is b0 */ |
| 399 | |
| 400 | src_ptr = vlib_buffer_get_current (sb0) + l234_sz + first_data_size; |
| 401 | src_left = sb0->current_length - l234_sz - first_data_size; |
| 402 | |
Mohsin Kazmi | ec1d61e | 2020-06-24 16:20:54 +0200 | [diff] [blame] | 403 | tso_fixup_segmented_buf (vm, b0, tcp_flags_no_fin_psh, is_l2, is_ip6, |
| 404 | gho); |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 405 | |
| 406 | /* grab a second buffer and prepare the loop */ |
| 407 | ASSERT (dbi < vec_len (ptd->split_buffers)); |
| 408 | cdb0 = vlib_get_buffer (vm, ptd->split_buffers[dbi++]); |
| 409 | tso_init_buf_from_template (vm, cdb0, b0, l234_sz, gso_size, &dst_ptr, |
Mohsin Kazmi | 72e7312 | 2019-10-22 13:33:13 +0200 | [diff] [blame] | 410 | &dst_left, next_tcp_seq, default_bflags, |
| 411 | gho); |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 412 | |
| 413 | /* an arbitrary large number to catch the runaway loops */ |
| 414 | int nloops = 2000; |
| 415 | while (total_src_left) |
| 416 | { |
| 417 | if (nloops-- <= 0) |
| 418 | clib_panic ("infinite loop detected"); |
| 419 | u16 bytes_to_copy = clib_min (src_left, dst_left); |
| 420 | |
| 421 | clib_memcpy_fast (dst_ptr, src_ptr, bytes_to_copy); |
| 422 | |
| 423 | src_left -= bytes_to_copy; |
| 424 | src_ptr += bytes_to_copy; |
| 425 | total_src_left -= bytes_to_copy; |
| 426 | dst_left -= bytes_to_copy; |
| 427 | dst_ptr += bytes_to_copy; |
| 428 | next_tcp_seq += bytes_to_copy; |
| 429 | cdb0->current_length += bytes_to_copy; |
| 430 | |
| 431 | if (0 == src_left) |
| 432 | { |
| 433 | int has_next = (csb0->flags & VLIB_BUFFER_NEXT_PRESENT); |
| 434 | u32 next_bi = csb0->next_buffer; |
| 435 | |
| 436 | /* init src to the next buffer in chain */ |
| 437 | if (has_next) |
| 438 | { |
| 439 | csbi0 = next_bi; |
| 440 | csb0 = vlib_get_buffer (vm, csbi0); |
| 441 | src_left = csb0->current_length; |
| 442 | src_ptr = vlib_buffer_get_current (csb0); |
| 443 | } |
| 444 | else |
| 445 | { |
| 446 | ASSERT (total_src_left == 0); |
| 447 | break; |
| 448 | } |
| 449 | } |
| 450 | if (0 == dst_left && total_src_left) |
| 451 | { |
| 452 | n_tx_bytes += cdb0->current_length; |
Mohsin Kazmi | ec1d61e | 2020-06-24 16:20:54 +0200 | [diff] [blame] | 453 | tso_fixup_segmented_buf (vm, cdb0, tcp_flags_no_fin_psh, is_l2, |
| 454 | is_ip6, gho); |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 455 | ASSERT (dbi < vec_len (ptd->split_buffers)); |
| 456 | cdb0 = vlib_get_buffer (vm, ptd->split_buffers[dbi++]); |
| 457 | tso_init_buf_from_template (vm, cdb0, b0, l234_sz, |
| 458 | gso_size, &dst_ptr, &dst_left, |
Mohsin Kazmi | 72e7312 | 2019-10-22 13:33:13 +0200 | [diff] [blame] | 459 | next_tcp_seq, default_bflags, gho); |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 460 | } |
| 461 | } |
| 462 | |
Mohsin Kazmi | ec1d61e | 2020-06-24 16:20:54 +0200 | [diff] [blame] | 463 | tso_fixup_segmented_buf (vm, cdb0, save_tcp_flags, is_l2, is_ip6, gho); |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 464 | |
| 465 | n_tx_bytes += cdb0->current_length; |
| 466 | } |
| 467 | n_tx_bytes += b0->current_length; |
| 468 | return n_tx_bytes; |
| 469 | } |
| 470 | |
Mohsin Kazmi | d9e7ac3 | 2021-10-15 22:45:51 +0000 | [diff] [blame^] | 471 | __clib_unused u32 |
| 472 | gso_segment_buffer (vlib_main_t *vm, vnet_interface_per_thread_data_t *ptd, |
| 473 | u32 bi, vlib_buffer_t *b, generic_header_offset_t *gho, |
| 474 | u32 n_bytes_b, u8 is_l2, u8 is_ip6) |
| 475 | { |
| 476 | |
| 477 | return tso_segment_buffer (vm, ptd, bi, b, gho, n_bytes_b, is_l2, is_ip6); |
| 478 | } |
| 479 | |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 480 | static_always_inline void |
| 481 | drop_one_buffer_and_count (vlib_main_t * vm, vnet_main_t * vnm, |
| 482 | vlib_node_runtime_t * node, u32 * pbi0, |
| 483 | u32 sw_if_index, u32 drop_error_code) |
| 484 | { |
| 485 | u32 thread_index = vm->thread_index; |
| 486 | |
| 487 | vlib_simple_counter_main_t *cm; |
| 488 | cm = |
| 489 | vec_elt_at_index (vnm->interface_main.sw_if_counters, |
| 490 | VNET_INTERFACE_COUNTER_TX_ERROR); |
| 491 | vlib_increment_simple_counter (cm, thread_index, sw_if_index, 1); |
| 492 | |
| 493 | vlib_error_drop_buffers (vm, node, pbi0, |
| 494 | /* buffer stride */ 1, |
Mohsin Kazmi | 79e087f | 2021-05-27 21:05:41 +0200 | [diff] [blame] | 495 | /* n_buffers */ 1, GSO_NEXT_DROP, node->node_index, |
| 496 | drop_error_code); |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | static_always_inline uword |
| 500 | vnet_gso_node_inline (vlib_main_t * vm, |
| 501 | vlib_node_runtime_t * node, |
| 502 | vlib_frame_t * frame, |
| 503 | vnet_main_t * vnm, |
| 504 | vnet_hw_interface_t * hi, |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 505 | int is_l2, int is_ip4, int is_ip6, int do_segmentation) |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 506 | { |
| 507 | u32 *to_next; |
| 508 | u32 next_index = node->cached_next_index; |
| 509 | u32 *from = vlib_frame_vector_args (frame); |
| 510 | u32 n_left_from = frame->n_vectors; |
| 511 | u32 *from_end = from + n_left_from; |
| 512 | u32 thread_index = vm->thread_index; |
| 513 | vnet_interface_main_t *im = &vnm->interface_main; |
| 514 | vnet_interface_per_thread_data_t *ptd = |
| 515 | vec_elt_at_index (im->per_thread_data, thread_index); |
| 516 | vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs; |
| 517 | |
| 518 | vlib_get_buffers (vm, from, b, n_left_from); |
| 519 | |
| 520 | while (n_left_from > 0) |
| 521 | { |
| 522 | u32 n_left_to_next; |
| 523 | |
| 524 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
| 525 | |
Mohsin Kazmi | 70ae4ef | 2019-12-09 11:46:01 +0100 | [diff] [blame] | 526 | if (!do_segmentation) |
| 527 | while (from + 8 <= from_end && n_left_to_next >= 4) |
| 528 | { |
| 529 | u32 bi0, bi1, bi2, bi3; |
| 530 | u32 next0, next1, next2, next3; |
| 531 | u32 swif0, swif1, swif2, swif3; |
| 532 | gso_trace_t *t0, *t1, *t2, *t3; |
| 533 | vnet_hw_interface_t *hi0, *hi1, *hi2, *hi3; |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 534 | |
Mohsin Kazmi | 70ae4ef | 2019-12-09 11:46:01 +0100 | [diff] [blame] | 535 | /* Prefetch next iteration. */ |
| 536 | vlib_prefetch_buffer_header (b[4], LOAD); |
| 537 | vlib_prefetch_buffer_header (b[5], LOAD); |
| 538 | vlib_prefetch_buffer_header (b[6], LOAD); |
| 539 | vlib_prefetch_buffer_header (b[7], LOAD); |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 540 | |
Mohsin Kazmi | 70ae4ef | 2019-12-09 11:46:01 +0100 | [diff] [blame] | 541 | bi0 = from[0]; |
| 542 | bi1 = from[1]; |
| 543 | bi2 = from[2]; |
| 544 | bi3 = from[3]; |
| 545 | to_next[0] = bi0; |
| 546 | to_next[1] = bi1; |
| 547 | to_next[2] = bi2; |
| 548 | to_next[3] = bi3; |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 549 | |
Mohsin Kazmi | 70ae4ef | 2019-12-09 11:46:01 +0100 | [diff] [blame] | 550 | swif0 = vnet_buffer (b[0])->sw_if_index[VLIB_TX]; |
| 551 | swif1 = vnet_buffer (b[1])->sw_if_index[VLIB_TX]; |
| 552 | swif2 = vnet_buffer (b[2])->sw_if_index[VLIB_TX]; |
| 553 | swif3 = vnet_buffer (b[3])->sw_if_index[VLIB_TX]; |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 554 | |
Mohsin Kazmi | 70ae4ef | 2019-12-09 11:46:01 +0100 | [diff] [blame] | 555 | if (PREDICT_FALSE (hi->sw_if_index != swif0)) |
| 556 | { |
| 557 | hi0 = vnet_get_sup_hw_interface (vnm, swif0); |
Mohsin Kazmi | 5b3f523 | 2021-02-10 12:03:53 +0100 | [diff] [blame] | 558 | if ((hi0->caps & VNET_HW_INTERFACE_CAP_SUPPORTS_TCP_GSO) == |
| 559 | 0 && |
Mohsin Kazmi | 70ae4ef | 2019-12-09 11:46:01 +0100 | [diff] [blame] | 560 | (b[0]->flags & VNET_BUFFER_F_GSO)) |
| 561 | break; |
| 562 | } |
| 563 | if (PREDICT_FALSE (hi->sw_if_index != swif1)) |
| 564 | { |
Steven Luong | a420c5e | 2020-01-16 09:57:22 -0800 | [diff] [blame] | 565 | hi1 = vnet_get_sup_hw_interface (vnm, swif1); |
Mohsin Kazmi | 5b3f523 | 2021-02-10 12:03:53 +0100 | [diff] [blame] | 566 | if (!(hi1->caps & VNET_HW_INTERFACE_CAP_SUPPORTS_TCP_GSO) && |
Mohsin Kazmi | 70ae4ef | 2019-12-09 11:46:01 +0100 | [diff] [blame] | 567 | (b[1]->flags & VNET_BUFFER_F_GSO)) |
| 568 | break; |
| 569 | } |
| 570 | if (PREDICT_FALSE (hi->sw_if_index != swif2)) |
| 571 | { |
Steven Luong | a420c5e | 2020-01-16 09:57:22 -0800 | [diff] [blame] | 572 | hi2 = vnet_get_sup_hw_interface (vnm, swif2); |
Mohsin Kazmi | 5b3f523 | 2021-02-10 12:03:53 +0100 | [diff] [blame] | 573 | if ((hi2->caps & VNET_HW_INTERFACE_CAP_SUPPORTS_TCP_GSO) == |
| 574 | 0 && |
Mohsin Kazmi | 70ae4ef | 2019-12-09 11:46:01 +0100 | [diff] [blame] | 575 | (b[2]->flags & VNET_BUFFER_F_GSO)) |
| 576 | break; |
| 577 | } |
| 578 | if (PREDICT_FALSE (hi->sw_if_index != swif3)) |
| 579 | { |
Steven Luong | a420c5e | 2020-01-16 09:57:22 -0800 | [diff] [blame] | 580 | hi3 = vnet_get_sup_hw_interface (vnm, swif3); |
Mohsin Kazmi | 5b3f523 | 2021-02-10 12:03:53 +0100 | [diff] [blame] | 581 | if (!(hi3->caps & VNET_HW_INTERFACE_CAP_SUPPORTS_TCP_GSO) && |
Mohsin Kazmi | 70ae4ef | 2019-12-09 11:46:01 +0100 | [diff] [blame] | 582 | (b[3]->flags & VNET_BUFFER_F_GSO)) |
| 583 | break; |
| 584 | } |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 585 | |
Mohsin Kazmi | 70ae4ef | 2019-12-09 11:46:01 +0100 | [diff] [blame] | 586 | if (b[0]->flags & VLIB_BUFFER_IS_TRACED) |
| 587 | { |
| 588 | t0 = vlib_add_trace (vm, node, b[0], sizeof (t0[0])); |
| 589 | t0->flags = b[0]->flags & VNET_BUFFER_F_GSO; |
| 590 | t0->gso_size = vnet_buffer2 (b[0])->gso_size; |
| 591 | t0->gso_l4_hdr_sz = vnet_buffer2 (b[0])->gso_l4_hdr_sz; |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 592 | vnet_generic_header_offset_parser (b[0], &t0->gho, is_l2, |
| 593 | is_ip4, is_ip6); |
Mohsin Kazmi | 70ae4ef | 2019-12-09 11:46:01 +0100 | [diff] [blame] | 594 | } |
| 595 | if (b[1]->flags & VLIB_BUFFER_IS_TRACED) |
| 596 | { |
| 597 | t1 = vlib_add_trace (vm, node, b[1], sizeof (t1[0])); |
| 598 | t1->flags = b[1]->flags & VNET_BUFFER_F_GSO; |
| 599 | t1->gso_size = vnet_buffer2 (b[1])->gso_size; |
| 600 | t1->gso_l4_hdr_sz = vnet_buffer2 (b[1])->gso_l4_hdr_sz; |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 601 | vnet_generic_header_offset_parser (b[1], &t1->gho, is_l2, |
| 602 | is_ip4, is_ip6); |
Mohsin Kazmi | 70ae4ef | 2019-12-09 11:46:01 +0100 | [diff] [blame] | 603 | } |
| 604 | if (b[2]->flags & VLIB_BUFFER_IS_TRACED) |
| 605 | { |
| 606 | t2 = vlib_add_trace (vm, node, b[2], sizeof (t2[0])); |
| 607 | t2->flags = b[2]->flags & VNET_BUFFER_F_GSO; |
| 608 | t2->gso_size = vnet_buffer2 (b[2])->gso_size; |
| 609 | t2->gso_l4_hdr_sz = vnet_buffer2 (b[2])->gso_l4_hdr_sz; |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 610 | vnet_generic_header_offset_parser (b[2], &t2->gho, is_l2, |
| 611 | is_ip4, is_ip6); |
Mohsin Kazmi | 70ae4ef | 2019-12-09 11:46:01 +0100 | [diff] [blame] | 612 | } |
| 613 | if (b[3]->flags & VLIB_BUFFER_IS_TRACED) |
| 614 | { |
| 615 | t3 = vlib_add_trace (vm, node, b[3], sizeof (t3[0])); |
| 616 | t3->flags = b[3]->flags & VNET_BUFFER_F_GSO; |
| 617 | t3->gso_size = vnet_buffer2 (b[3])->gso_size; |
| 618 | t3->gso_l4_hdr_sz = vnet_buffer2 (b[3])->gso_l4_hdr_sz; |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 619 | vnet_generic_header_offset_parser (b[3], &t3->gho, is_l2, |
| 620 | is_ip4, is_ip6); |
Mohsin Kazmi | 70ae4ef | 2019-12-09 11:46:01 +0100 | [diff] [blame] | 621 | } |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 622 | |
Mohsin Kazmi | 70ae4ef | 2019-12-09 11:46:01 +0100 | [diff] [blame] | 623 | from += 4; |
| 624 | to_next += 4; |
| 625 | n_left_to_next -= 4; |
| 626 | n_left_from -= 4; |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 627 | |
Mohsin Kazmi | 70ae4ef | 2019-12-09 11:46:01 +0100 | [diff] [blame] | 628 | next0 = next1 = 0; |
| 629 | next2 = next3 = 0; |
| 630 | vnet_feature_next (&next0, b[0]); |
| 631 | vnet_feature_next (&next1, b[1]); |
| 632 | vnet_feature_next (&next2, b[2]); |
| 633 | vnet_feature_next (&next3, b[3]); |
| 634 | vlib_validate_buffer_enqueue_x4 (vm, node, next_index, to_next, |
| 635 | n_left_to_next, bi0, bi1, bi2, |
| 636 | bi3, next0, next1, next2, next3); |
| 637 | b += 4; |
| 638 | } |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 639 | |
| 640 | while (from + 1 <= from_end && n_left_to_next > 0) |
| 641 | { |
| 642 | u32 bi0, swif0; |
| 643 | gso_trace_t *t0; |
| 644 | vnet_hw_interface_t *hi0; |
| 645 | u32 next0 = 0; |
Mohsin Kazmi | 70ae4ef | 2019-12-09 11:46:01 +0100 | [diff] [blame] | 646 | u32 do_segmentation0 = 0; |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 647 | |
| 648 | swif0 = vnet_buffer (b[0])->sw_if_index[VLIB_TX]; |
| 649 | if (PREDICT_FALSE (hi->sw_if_index != swif0)) |
| 650 | { |
| 651 | hi0 = vnet_get_sup_hw_interface (vnm, swif0); |
Mohsin Kazmi | 5b3f523 | 2021-02-10 12:03:53 +0100 | [diff] [blame] | 652 | if ((hi0->caps & VNET_HW_INTERFACE_CAP_SUPPORTS_TCP_GSO) == 0 && |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 653 | (b[0]->flags & VNET_BUFFER_F_GSO)) |
Mohsin Kazmi | 70ae4ef | 2019-12-09 11:46:01 +0100 | [diff] [blame] | 654 | do_segmentation0 = 1; |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 655 | } |
Mohsin Kazmi | 70ae4ef | 2019-12-09 11:46:01 +0100 | [diff] [blame] | 656 | else |
| 657 | do_segmentation0 = do_segmentation; |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 658 | |
| 659 | /* speculatively enqueue b0 to the current next frame */ |
| 660 | to_next[0] = bi0 = from[0]; |
| 661 | to_next += 1; |
| 662 | n_left_to_next -= 1; |
| 663 | from += 1; |
| 664 | n_left_from -= 1; |
| 665 | |
| 666 | if (b[0]->flags & VLIB_BUFFER_IS_TRACED) |
| 667 | { |
| 668 | t0 = vlib_add_trace (vm, node, b[0], sizeof (t0[0])); |
| 669 | t0->flags = b[0]->flags & VNET_BUFFER_F_GSO; |
| 670 | t0->gso_size = vnet_buffer2 (b[0])->gso_size; |
| 671 | t0->gso_l4_hdr_sz = vnet_buffer2 (b[0])->gso_l4_hdr_sz; |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 672 | vnet_generic_header_offset_parser (b[0], &t0->gho, is_l2, |
| 673 | is_ip4, is_ip6); |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 674 | } |
| 675 | |
Mohsin Kazmi | 70ae4ef | 2019-12-09 11:46:01 +0100 | [diff] [blame] | 676 | if (do_segmentation0) |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 677 | { |
| 678 | if (PREDICT_FALSE (b[0]->flags & VNET_BUFFER_F_GSO)) |
| 679 | { |
| 680 | /* |
| 681 | * Undo the enqueue of the b0 - it is not going anywhere, |
| 682 | * and will be freed either after it's segmented or |
| 683 | * when dropped, if there is no buffers to segment into. |
| 684 | */ |
| 685 | to_next -= 1; |
| 686 | n_left_to_next += 1; |
| 687 | /* undo the counting. */ |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 688 | generic_header_offset_t gho = { 0 }; |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 689 | u32 n_bytes_b0 = vlib_buffer_length_in_chain (vm, b[0]); |
| 690 | u32 n_tx_bytes = 0; |
Mohsin Kazmi | be03b5c | 2020-05-28 20:56:43 +0200 | [diff] [blame] | 691 | u32 inner_is_ip6 = is_ip6; |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 692 | |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 693 | vnet_generic_header_offset_parser (b[0], &gho, is_l2, |
| 694 | is_ip4, is_ip6); |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 695 | |
| 696 | if (PREDICT_FALSE (gho.gho_flags & GHO_F_TUNNEL)) |
| 697 | { |
| 698 | if (PREDICT_FALSE |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 699 | (gho.gho_flags & (GHO_F_GRE_TUNNEL | |
| 700 | GHO_F_GENEVE_TUNNEL))) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 701 | { |
| 702 | /* not supported yet */ |
| 703 | drop_one_buffer_and_count (vm, vnm, node, from - 1, |
| 704 | hi->sw_if_index, |
Mohsin Kazmi | 79e087f | 2021-05-27 21:05:41 +0200 | [diff] [blame] | 705 | GSO_ERROR_UNHANDLED_TYPE); |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 706 | b += 1; |
| 707 | continue; |
| 708 | } |
| 709 | |
| 710 | vnet_get_inner_header (b[0], &gho); |
| 711 | |
| 712 | n_bytes_b0 -= gho.outer_hdr_sz; |
Mohsin Kazmi | be03b5c | 2020-05-28 20:56:43 +0200 | [diff] [blame] | 713 | inner_is_ip6 = (gho.gho_flags & GHO_F_IP6) != 0; |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 714 | } |
| 715 | |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 716 | n_tx_bytes = |
Mohsin Kazmi | 72e7312 | 2019-10-22 13:33:13 +0200 | [diff] [blame] | 717 | tso_segment_buffer (vm, ptd, bi0, b[0], &gho, n_bytes_b0, |
Mohsin Kazmi | ec1d61e | 2020-06-24 16:20:54 +0200 | [diff] [blame] | 718 | is_l2, inner_is_ip6); |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 719 | |
| 720 | if (PREDICT_FALSE (n_tx_bytes == 0)) |
| 721 | { |
| 722 | drop_one_buffer_and_count (vm, vnm, node, from - 1, |
| 723 | hi->sw_if_index, |
Mohsin Kazmi | 79e087f | 2021-05-27 21:05:41 +0200 | [diff] [blame] | 724 | GSO_ERROR_NO_BUFFERS); |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 725 | b += 1; |
| 726 | continue; |
| 727 | } |
| 728 | |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 729 | |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 730 | if (PREDICT_FALSE (gho.gho_flags & GHO_F_VXLAN_TUNNEL)) |
| 731 | { |
| 732 | vnet_get_outer_header (b[0], &gho); |
| 733 | n_tx_bytes += |
| 734 | tso_segment_vxlan_tunnel_fixup (vm, ptd, b[0], &gho); |
| 735 | } |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 736 | else |
| 737 | if (PREDICT_FALSE |
| 738 | (gho.gho_flags & (GHO_F_IPIP_TUNNEL | |
| 739 | GHO_F_IPIP6_TUNNEL))) |
| 740 | { |
| 741 | vnet_get_outer_header (b[0], &gho); |
| 742 | n_tx_bytes += |
| 743 | tso_segment_ipip_tunnel_fixup (vm, ptd, b[0], &gho); |
| 744 | } |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 745 | |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 746 | u16 n_tx_bufs = vec_len (ptd->split_buffers); |
| 747 | u32 *from_seg = ptd->split_buffers; |
| 748 | |
| 749 | while (n_tx_bufs > 0) |
| 750 | { |
| 751 | u32 sbi0; |
| 752 | vlib_buffer_t *sb0; |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 753 | while (n_tx_bufs > 0 && n_left_to_next > 0) |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 754 | { |
| 755 | sbi0 = to_next[0] = from_seg[0]; |
| 756 | sb0 = vlib_get_buffer (vm, sbi0); |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 757 | ASSERT (sb0->current_length > 0); |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 758 | to_next += 1; |
| 759 | from_seg += 1; |
| 760 | n_left_to_next -= 1; |
| 761 | n_tx_bufs -= 1; |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 762 | next0 = 0; |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 763 | vnet_feature_next (&next0, sb0); |
| 764 | vlib_validate_buffer_enqueue_x1 (vm, node, |
| 765 | next_index, |
| 766 | to_next, |
| 767 | n_left_to_next, |
| 768 | sbi0, next0); |
| 769 | } |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 770 | vlib_put_next_frame (vm, node, next_index, |
| 771 | n_left_to_next); |
| 772 | if (n_tx_bufs > 0) |
| 773 | vlib_get_next_frame (vm, node, next_index, |
| 774 | to_next, n_left_to_next); |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 775 | } |
| 776 | /* The buffers were enqueued. Reset the length */ |
| 777 | _vec_len (ptd->split_buffers) = 0; |
| 778 | /* Free the now segmented buffer */ |
| 779 | vlib_buffer_free_one (vm, bi0); |
| 780 | b += 1; |
| 781 | continue; |
| 782 | } |
| 783 | } |
| 784 | |
| 785 | vnet_feature_next (&next0, b[0]); |
| 786 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next, |
| 787 | n_left_to_next, bi0, next0); |
| 788 | b += 1; |
| 789 | } |
| 790 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 791 | } |
| 792 | |
| 793 | return frame->n_vectors; |
| 794 | } |
| 795 | |
| 796 | static_always_inline uword |
| 797 | vnet_gso_inline (vlib_main_t * vm, |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 798 | vlib_node_runtime_t * node, vlib_frame_t * frame, int is_l2, |
| 799 | int is_ip4, int is_ip6) |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 800 | { |
| 801 | vnet_main_t *vnm = vnet_get_main (); |
| 802 | vnet_hw_interface_t *hi; |
| 803 | |
| 804 | if (frame->n_vectors > 0) |
| 805 | { |
| 806 | u32 *from = vlib_frame_vector_args (frame); |
| 807 | vlib_buffer_t *b = vlib_get_buffer (vm, from[0]); |
| 808 | hi = vnet_get_sup_hw_interface (vnm, |
| 809 | vnet_buffer (b)->sw_if_index[VLIB_TX]); |
Mohsin Kazmi | 70ae4ef | 2019-12-09 11:46:01 +0100 | [diff] [blame] | 810 | |
Mohsin Kazmi | 4fd9f10 | 2021-06-17 17:29:27 +0000 | [diff] [blame] | 811 | if (hi->caps & (VNET_HW_INTERFACE_CAP_SUPPORTS_TCP_GSO | |
| 812 | VNET_HW_INTERFACE_CAP_SUPPORTS_VXLAN_TNL_GSO)) |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 813 | return vnet_gso_node_inline (vm, node, frame, vnm, hi, |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 814 | is_l2, is_ip4, is_ip6, |
| 815 | /* do_segmentation */ 0); |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 816 | else |
| 817 | return vnet_gso_node_inline (vm, node, frame, vnm, hi, |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 818 | is_l2, is_ip4, is_ip6, |
| 819 | /* do_segmentation */ 1); |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 820 | } |
| 821 | return 0; |
| 822 | } |
| 823 | |
| 824 | VLIB_NODE_FN (gso_l2_ip4_node) (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 825 | vlib_frame_t * frame) |
| 826 | { |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 827 | return vnet_gso_inline (vm, node, frame, 1 /* l2 */ , 1 /* ip4 */ , |
| 828 | 0 /* ip6 */ ); |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 829 | } |
| 830 | |
| 831 | VLIB_NODE_FN (gso_l2_ip6_node) (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 832 | vlib_frame_t * frame) |
| 833 | { |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 834 | return vnet_gso_inline (vm, node, frame, 1 /* l2 */ , 0 /* ip4 */ , |
| 835 | 1 /* ip6 */ ); |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 836 | } |
| 837 | |
| 838 | VLIB_NODE_FN (gso_ip4_node) (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 839 | vlib_frame_t * frame) |
| 840 | { |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 841 | return vnet_gso_inline (vm, node, frame, 0 /* l2 */ , 1 /* ip4 */ , |
| 842 | 0 /* ip6 */ ); |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | VLIB_NODE_FN (gso_ip6_node) (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 846 | vlib_frame_t * frame) |
| 847 | { |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 848 | return vnet_gso_inline (vm, node, frame, 0 /* l2 */ , 0 /* ip4 */ , |
| 849 | 1 /* ip6 */ ); |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | /* *INDENT-OFF* */ |
| 853 | |
| 854 | VLIB_REGISTER_NODE (gso_l2_ip4_node) = { |
| 855 | .vector_size = sizeof (u32), |
| 856 | .format_trace = format_gso_trace, |
| 857 | .type = VLIB_NODE_TYPE_INTERNAL, |
Mohsin Kazmi | 79e087f | 2021-05-27 21:05:41 +0200 | [diff] [blame] | 858 | .n_errors = ARRAY_LEN(gso_error_strings), |
| 859 | .error_strings = gso_error_strings, |
| 860 | .n_next_nodes = GSO_N_NEXT, |
| 861 | .next_nodes = { |
| 862 | [GSO_NEXT_DROP] = "error-drop", |
| 863 | }, |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 864 | .name = "gso-l2-ip4", |
| 865 | }; |
| 866 | |
| 867 | VLIB_REGISTER_NODE (gso_l2_ip6_node) = { |
| 868 | .vector_size = sizeof (u32), |
| 869 | .format_trace = format_gso_trace, |
| 870 | .type = VLIB_NODE_TYPE_INTERNAL, |
Mohsin Kazmi | 79e087f | 2021-05-27 21:05:41 +0200 | [diff] [blame] | 871 | .n_errors = ARRAY_LEN(gso_error_strings), |
| 872 | .error_strings = gso_error_strings, |
| 873 | .n_next_nodes = GSO_N_NEXT, |
| 874 | .next_nodes = { |
| 875 | [GSO_NEXT_DROP] = "error-drop", |
| 876 | }, |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 877 | .name = "gso-l2-ip6", |
| 878 | }; |
| 879 | |
| 880 | VLIB_REGISTER_NODE (gso_ip4_node) = { |
| 881 | .vector_size = sizeof (u32), |
| 882 | .format_trace = format_gso_trace, |
| 883 | .type = VLIB_NODE_TYPE_INTERNAL, |
Mohsin Kazmi | 79e087f | 2021-05-27 21:05:41 +0200 | [diff] [blame] | 884 | .n_errors = ARRAY_LEN(gso_error_strings), |
| 885 | .error_strings = gso_error_strings, |
| 886 | .n_next_nodes = GSO_N_NEXT, |
| 887 | .next_nodes = { |
| 888 | [GSO_NEXT_DROP] = "error-drop", |
| 889 | }, |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 890 | .name = "gso-ip4", |
| 891 | }; |
| 892 | |
| 893 | VLIB_REGISTER_NODE (gso_ip6_node) = { |
| 894 | .vector_size = sizeof (u32), |
| 895 | .format_trace = format_gso_trace, |
| 896 | .type = VLIB_NODE_TYPE_INTERNAL, |
Mohsin Kazmi | 79e087f | 2021-05-27 21:05:41 +0200 | [diff] [blame] | 897 | .n_errors = ARRAY_LEN(gso_error_strings), |
| 898 | .error_strings = gso_error_strings, |
| 899 | .n_next_nodes = GSO_N_NEXT, |
| 900 | .next_nodes = { |
| 901 | [GSO_NEXT_DROP] = "error-drop", |
| 902 | }, |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 903 | .name = "gso-ip6", |
| 904 | }; |
| 905 | |
| 906 | VNET_FEATURE_INIT (gso_l2_ip4_node, static) = { |
| 907 | .arc_name = "l2-output-ip4", |
| 908 | .node_name = "gso-l2-ip4", |
| 909 | .runs_before = VNET_FEATURES ("l2-output-feat-arc-end"), |
| 910 | }; |
| 911 | |
| 912 | VNET_FEATURE_INIT (gso_l2_ip6_node, static) = { |
| 913 | .arc_name = "l2-output-ip6", |
| 914 | .node_name = "gso-l2-ip6", |
| 915 | .runs_before = VNET_FEATURES ("l2-output-feat-arc-end"), |
| 916 | }; |
| 917 | |
| 918 | VNET_FEATURE_INIT (gso_ip4_node, static) = { |
| 919 | .arc_name = "ip4-output", |
| 920 | .node_name = "gso-ip4", |
Neale Ranns | 83d1298 | 2020-05-11 15:24:39 +0000 | [diff] [blame] | 921 | .runs_before = VNET_FEATURES ("ipsec4-output-feature"), |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 922 | }; |
| 923 | |
| 924 | VNET_FEATURE_INIT (gso_ip6_node, static) = { |
| 925 | .arc_name = "ip6-output", |
| 926 | .node_name = "gso-ip6", |
Neale Ranns | 83d1298 | 2020-05-11 15:24:39 +0000 | [diff] [blame] | 927 | .runs_before = VNET_FEATURES ("ipsec6-output-feature"), |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 928 | }; |
| 929 | |
| 930 | /* |
| 931 | * fd.io coding-style-patch-verification: ON |
| 932 | * |
| 933 | * Local Variables: |
| 934 | * eval: (c-set-style "gnu") |
| 935 | * End: |
| 936 | */ |