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> |
| 22 | #include <vnet/ip/icmp46_packet.h> |
| 23 | #include <vnet/ip/ip4.h> |
| 24 | #include <vnet/ip/ip6.h> |
| 25 | #include <vnet/udp/udp_packet.h> |
| 26 | |
| 27 | typedef struct |
| 28 | { |
| 29 | u32 flags; |
| 30 | u16 gso_size; |
| 31 | u8 gso_l4_hdr_sz; |
| 32 | } gso_trace_t; |
| 33 | |
| 34 | static u8 * |
| 35 | format_gso_trace (u8 * s, va_list * args) |
| 36 | { |
| 37 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 38 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
| 39 | gso_trace_t *t = va_arg (*args, gso_trace_t *); |
| 40 | |
| 41 | if (t->flags & VNET_BUFFER_F_GSO) |
| 42 | { |
| 43 | s = format (s, "gso_sz %d gso_l4_hdr_sz %d", |
| 44 | t->gso_size, t->gso_l4_hdr_sz); |
| 45 | } |
| 46 | |
| 47 | return s; |
| 48 | } |
| 49 | |
| 50 | static_always_inline u16 |
| 51 | tso_alloc_tx_bufs (vlib_main_t * vm, |
| 52 | vnet_interface_per_thread_data_t * ptd, |
| 53 | vlib_buffer_t * b0, u32 n_bytes_b0, u16 l234_sz, |
| 54 | u16 gso_size) |
| 55 | { |
| 56 | u16 size = |
| 57 | clib_min (gso_size, vlib_buffer_get_default_data_size (vm) - l234_sz); |
| 58 | |
| 59 | /* rounded-up division */ |
| 60 | u16 n_bufs = (n_bytes_b0 - l234_sz + (size - 1)) / size; |
| 61 | u16 n_alloc; |
| 62 | |
| 63 | ASSERT (n_bufs > 0); |
| 64 | vec_validate (ptd->split_buffers, n_bufs - 1); |
| 65 | |
| 66 | n_alloc = vlib_buffer_alloc (vm, ptd->split_buffers, n_bufs); |
| 67 | if (n_alloc < n_bufs) |
| 68 | { |
| 69 | vlib_buffer_free (vm, ptd->split_buffers, n_alloc); |
| 70 | return 0; |
| 71 | } |
| 72 | return n_alloc; |
| 73 | } |
| 74 | |
| 75 | static_always_inline void |
| 76 | tso_init_buf_from_template_base (vlib_buffer_t * nb0, vlib_buffer_t * b0, |
| 77 | u32 flags, u16 length) |
| 78 | { |
| 79 | nb0->current_data = b0->current_data; |
| 80 | nb0->total_length_not_including_first_buffer = 0; |
| 81 | nb0->flags = VLIB_BUFFER_TOTAL_LENGTH_VALID | flags; |
| 82 | clib_memcpy_fast (&nb0->opaque, &b0->opaque, sizeof (nb0->opaque)); |
| 83 | clib_memcpy_fast (vlib_buffer_get_current (nb0), |
| 84 | vlib_buffer_get_current (b0), length); |
| 85 | nb0->current_length = length; |
| 86 | } |
| 87 | |
| 88 | static_always_inline void |
| 89 | tso_init_buf_from_template (vlib_main_t * vm, vlib_buffer_t * nb0, |
| 90 | vlib_buffer_t * b0, u16 template_data_sz, |
| 91 | u16 gso_size, u8 ** p_dst_ptr, u16 * p_dst_left, |
| 92 | u32 next_tcp_seq, u32 flags) |
| 93 | { |
| 94 | tso_init_buf_from_template_base (nb0, b0, flags, template_data_sz); |
| 95 | |
| 96 | *p_dst_left = |
| 97 | clib_min (gso_size, |
| 98 | vlib_buffer_get_default_data_size (vm) - (template_data_sz + |
| 99 | nb0->current_data)); |
| 100 | *p_dst_ptr = vlib_buffer_get_current (nb0) + template_data_sz; |
| 101 | |
| 102 | tcp_header_t *tcp = |
| 103 | (tcp_header_t *) (nb0->data + vnet_buffer (nb0)->l4_hdr_offset); |
| 104 | tcp->seq_number = clib_host_to_net_u32 (next_tcp_seq); |
| 105 | } |
| 106 | |
| 107 | static_always_inline void |
| 108 | tso_fixup_segmented_buf (vlib_buffer_t * b0, u8 tcp_flags, int is_ip6) |
| 109 | { |
| 110 | u16 l3_hdr_offset = vnet_buffer (b0)->l3_hdr_offset; |
| 111 | u16 l4_hdr_offset = vnet_buffer (b0)->l4_hdr_offset; |
| 112 | ip4_header_t *ip4 = (ip4_header_t *) (b0->data + l3_hdr_offset); |
| 113 | ip6_header_t *ip6 = (ip6_header_t *) (b0->data + l3_hdr_offset); |
| 114 | tcp_header_t *tcp = (tcp_header_t *) (b0->data + l4_hdr_offset); |
| 115 | |
| 116 | tcp->flags = tcp_flags; |
| 117 | |
| 118 | if (is_ip6) |
| 119 | ip6->payload_length = |
| 120 | clib_host_to_net_u16 (b0->current_length - |
| 121 | (l4_hdr_offset - b0->current_data)); |
| 122 | else |
| 123 | ip4->length = |
| 124 | clib_host_to_net_u16 (b0->current_length - |
| 125 | (l3_hdr_offset - b0->current_data)); |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * Allocate the necessary number of ptd->split_buffers, |
| 130 | * and segment the possibly chained buffer(s) from b0 into |
| 131 | * there. |
| 132 | * |
| 133 | * Return the cumulative number of bytes sent or zero |
| 134 | * if allocation failed. |
| 135 | */ |
| 136 | |
| 137 | static_always_inline u32 |
| 138 | tso_segment_buffer (vlib_main_t * vm, vnet_interface_per_thread_data_t * ptd, |
| 139 | u32 sbi0, vlib_buffer_t * sb0, u32 n_bytes_b0, int is_ip6) |
| 140 | { |
| 141 | u32 n_tx_bytes = 0; |
| 142 | ASSERT (sb0->flags & VNET_BUFFER_F_L2_HDR_OFFSET_VALID); |
| 143 | ASSERT (sb0->flags & VNET_BUFFER_F_L3_HDR_OFFSET_VALID); |
| 144 | ASSERT (sb0->flags & VNET_BUFFER_F_L4_HDR_OFFSET_VALID); |
| 145 | u16 gso_size = vnet_buffer2 (sb0)->gso_size; |
| 146 | |
| 147 | int l4_hdr_sz = vnet_buffer2 (sb0)->gso_l4_hdr_sz; |
| 148 | u8 save_tcp_flags = 0; |
| 149 | u8 tcp_flags_no_fin_psh = 0; |
| 150 | u32 next_tcp_seq = 0; |
| 151 | |
| 152 | tcp_header_t *tcp = |
| 153 | (tcp_header_t *) (sb0->data + vnet_buffer (sb0)->l4_hdr_offset); |
| 154 | next_tcp_seq = clib_net_to_host_u32 (tcp->seq_number); |
| 155 | /* store original flags for last packet and reset FIN and PSH */ |
| 156 | save_tcp_flags = tcp->flags; |
| 157 | tcp_flags_no_fin_psh = tcp->flags & ~(TCP_FLAG_FIN | TCP_FLAG_PSH); |
| 158 | tcp->checksum = 0; |
| 159 | |
| 160 | u32 default_bflags = |
| 161 | sb0->flags & ~(VNET_BUFFER_F_GSO | VLIB_BUFFER_NEXT_PRESENT); |
| 162 | u16 l234_sz = vnet_buffer (sb0)->l4_hdr_offset + l4_hdr_sz |
| 163 | - sb0->current_data; |
| 164 | int first_data_size = clib_min (gso_size, sb0->current_length - l234_sz); |
| 165 | next_tcp_seq += first_data_size; |
| 166 | |
| 167 | if (PREDICT_FALSE |
| 168 | (!tso_alloc_tx_bufs (vm, ptd, sb0, n_bytes_b0, l234_sz, gso_size))) |
| 169 | return 0; |
| 170 | |
| 171 | vlib_buffer_t *b0 = vlib_get_buffer (vm, ptd->split_buffers[0]); |
| 172 | tso_init_buf_from_template_base (b0, sb0, default_bflags, |
| 173 | l234_sz + first_data_size); |
| 174 | |
| 175 | u32 total_src_left = n_bytes_b0 - l234_sz - first_data_size; |
| 176 | if (total_src_left) |
| 177 | { |
| 178 | /* Need to copy more segments */ |
| 179 | u8 *src_ptr, *dst_ptr; |
| 180 | u16 src_left, dst_left; |
| 181 | /* current source buffer */ |
| 182 | vlib_buffer_t *csb0 = sb0; |
| 183 | u32 csbi0 = sbi0; |
| 184 | /* current dest buffer */ |
| 185 | vlib_buffer_t *cdb0; |
| 186 | u16 dbi = 1; /* the buffer [0] is b0 */ |
| 187 | |
| 188 | src_ptr = vlib_buffer_get_current (sb0) + l234_sz + first_data_size; |
| 189 | src_left = sb0->current_length - l234_sz - first_data_size; |
| 190 | |
| 191 | tso_fixup_segmented_buf (b0, tcp_flags_no_fin_psh, is_ip6); |
| 192 | |
| 193 | /* grab a second buffer and prepare the loop */ |
| 194 | ASSERT (dbi < vec_len (ptd->split_buffers)); |
| 195 | cdb0 = vlib_get_buffer (vm, ptd->split_buffers[dbi++]); |
| 196 | tso_init_buf_from_template (vm, cdb0, b0, l234_sz, gso_size, &dst_ptr, |
| 197 | &dst_left, next_tcp_seq, default_bflags); |
| 198 | |
| 199 | /* an arbitrary large number to catch the runaway loops */ |
| 200 | int nloops = 2000; |
| 201 | while (total_src_left) |
| 202 | { |
| 203 | if (nloops-- <= 0) |
| 204 | clib_panic ("infinite loop detected"); |
| 205 | u16 bytes_to_copy = clib_min (src_left, dst_left); |
| 206 | |
| 207 | clib_memcpy_fast (dst_ptr, src_ptr, bytes_to_copy); |
| 208 | |
| 209 | src_left -= bytes_to_copy; |
| 210 | src_ptr += bytes_to_copy; |
| 211 | total_src_left -= bytes_to_copy; |
| 212 | dst_left -= bytes_to_copy; |
| 213 | dst_ptr += bytes_to_copy; |
| 214 | next_tcp_seq += bytes_to_copy; |
| 215 | cdb0->current_length += bytes_to_copy; |
| 216 | |
| 217 | if (0 == src_left) |
| 218 | { |
| 219 | int has_next = (csb0->flags & VLIB_BUFFER_NEXT_PRESENT); |
| 220 | u32 next_bi = csb0->next_buffer; |
| 221 | |
| 222 | /* init src to the next buffer in chain */ |
| 223 | if (has_next) |
| 224 | { |
| 225 | csbi0 = next_bi; |
| 226 | csb0 = vlib_get_buffer (vm, csbi0); |
| 227 | src_left = csb0->current_length; |
| 228 | src_ptr = vlib_buffer_get_current (csb0); |
| 229 | } |
| 230 | else |
| 231 | { |
| 232 | ASSERT (total_src_left == 0); |
| 233 | break; |
| 234 | } |
| 235 | } |
| 236 | if (0 == dst_left && total_src_left) |
| 237 | { |
| 238 | n_tx_bytes += cdb0->current_length; |
| 239 | ASSERT (dbi < vec_len (ptd->split_buffers)); |
| 240 | cdb0 = vlib_get_buffer (vm, ptd->split_buffers[dbi++]); |
| 241 | tso_init_buf_from_template (vm, cdb0, b0, l234_sz, |
| 242 | gso_size, &dst_ptr, &dst_left, |
| 243 | next_tcp_seq, default_bflags); |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | tso_fixup_segmented_buf (cdb0, save_tcp_flags, is_ip6); |
| 248 | |
| 249 | n_tx_bytes += cdb0->current_length; |
| 250 | } |
| 251 | n_tx_bytes += b0->current_length; |
| 252 | return n_tx_bytes; |
| 253 | } |
| 254 | |
| 255 | static_always_inline void |
| 256 | drop_one_buffer_and_count (vlib_main_t * vm, vnet_main_t * vnm, |
| 257 | vlib_node_runtime_t * node, u32 * pbi0, |
| 258 | u32 sw_if_index, u32 drop_error_code) |
| 259 | { |
| 260 | u32 thread_index = vm->thread_index; |
| 261 | |
| 262 | vlib_simple_counter_main_t *cm; |
| 263 | cm = |
| 264 | vec_elt_at_index (vnm->interface_main.sw_if_counters, |
| 265 | VNET_INTERFACE_COUNTER_TX_ERROR); |
| 266 | vlib_increment_simple_counter (cm, thread_index, sw_if_index, 1); |
| 267 | |
| 268 | vlib_error_drop_buffers (vm, node, pbi0, |
| 269 | /* buffer stride */ 1, |
| 270 | /* n_buffers */ 1, |
| 271 | VNET_INTERFACE_OUTPUT_NEXT_DROP, |
| 272 | node->node_index, drop_error_code); |
| 273 | } |
| 274 | |
| 275 | static_always_inline uword |
| 276 | vnet_gso_node_inline (vlib_main_t * vm, |
| 277 | vlib_node_runtime_t * node, |
| 278 | vlib_frame_t * frame, |
| 279 | vnet_main_t * vnm, |
| 280 | vnet_hw_interface_t * hi, |
| 281 | int is_ip6, int do_segmentation) |
| 282 | { |
| 283 | u32 *to_next; |
| 284 | u32 next_index = node->cached_next_index; |
| 285 | u32 *from = vlib_frame_vector_args (frame); |
| 286 | u32 n_left_from = frame->n_vectors; |
| 287 | u32 *from_end = from + n_left_from; |
| 288 | u32 thread_index = vm->thread_index; |
| 289 | vnet_interface_main_t *im = &vnm->interface_main; |
| 290 | vnet_interface_per_thread_data_t *ptd = |
| 291 | vec_elt_at_index (im->per_thread_data, thread_index); |
| 292 | vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs; |
| 293 | |
| 294 | vlib_get_buffers (vm, from, b, n_left_from); |
| 295 | |
| 296 | while (n_left_from > 0) |
| 297 | { |
| 298 | u32 n_left_to_next; |
| 299 | |
| 300 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
| 301 | |
| 302 | while (from + 8 <= from_end && n_left_to_next >= 4) |
| 303 | { |
| 304 | u32 bi0, bi1, bi2, bi3; |
| 305 | u32 next0, next1, next2, next3; |
| 306 | u32 swif0, swif1, swif2, swif3; |
| 307 | gso_trace_t *t0, *t1, *t2, *t3; |
| 308 | vnet_hw_interface_t *hi0, *hi1, *hi2, *hi3; |
| 309 | |
| 310 | /* Prefetch next iteration. */ |
| 311 | vlib_prefetch_buffer_header (b[4], LOAD); |
| 312 | vlib_prefetch_buffer_header (b[5], LOAD); |
| 313 | vlib_prefetch_buffer_header (b[6], LOAD); |
| 314 | vlib_prefetch_buffer_header (b[7], LOAD); |
| 315 | |
| 316 | bi0 = from[0]; |
| 317 | bi1 = from[1]; |
| 318 | bi2 = from[2]; |
| 319 | bi3 = from[3]; |
| 320 | to_next[0] = bi0; |
| 321 | to_next[1] = bi1; |
| 322 | to_next[2] = bi2; |
| 323 | to_next[3] = bi3; |
| 324 | |
| 325 | swif0 = vnet_buffer (b[0])->sw_if_index[VLIB_TX]; |
| 326 | swif1 = vnet_buffer (b[1])->sw_if_index[VLIB_TX]; |
| 327 | swif2 = vnet_buffer (b[2])->sw_if_index[VLIB_TX]; |
| 328 | swif3 = vnet_buffer (b[3])->sw_if_index[VLIB_TX]; |
| 329 | |
| 330 | if (PREDICT_FALSE (hi->sw_if_index != swif0)) |
| 331 | { |
| 332 | hi0 = vnet_get_sup_hw_interface (vnm, swif0); |
| 333 | if ((hi0->flags & VNET_HW_INTERFACE_FLAG_SUPPORTS_GSO) == 0 && |
| 334 | (b[0]->flags & VNET_BUFFER_F_GSO)) |
| 335 | break; |
| 336 | } |
| 337 | if (PREDICT_FALSE (hi->sw_if_index != swif1)) |
| 338 | { |
| 339 | hi1 = vnet_get_sup_hw_interface (vnm, swif0); |
| 340 | if (!(hi1->flags & VNET_HW_INTERFACE_FLAG_SUPPORTS_GSO) && |
| 341 | (b[1]->flags & VNET_BUFFER_F_GSO)) |
| 342 | break; |
| 343 | } |
| 344 | if (PREDICT_FALSE (hi->sw_if_index != swif2)) |
| 345 | { |
| 346 | hi2 = vnet_get_sup_hw_interface (vnm, swif0); |
| 347 | if ((hi2->flags & VNET_HW_INTERFACE_FLAG_SUPPORTS_GSO) == 0 && |
| 348 | (b[2]->flags & VNET_BUFFER_F_GSO)) |
| 349 | break; |
| 350 | } |
| 351 | if (PREDICT_FALSE (hi->sw_if_index != swif3)) |
| 352 | { |
| 353 | hi3 = vnet_get_sup_hw_interface (vnm, swif0); |
| 354 | if (!(hi3->flags & VNET_HW_INTERFACE_FLAG_SUPPORTS_GSO) && |
| 355 | (b[3]->flags & VNET_BUFFER_F_GSO)) |
| 356 | break; |
| 357 | } |
| 358 | |
| 359 | if (b[0]->flags & VLIB_BUFFER_IS_TRACED) |
| 360 | { |
| 361 | t0 = vlib_add_trace (vm, node, b[0], sizeof (t0[0])); |
| 362 | t0->flags = b[0]->flags & VNET_BUFFER_F_GSO; |
| 363 | t0->gso_size = vnet_buffer2 (b[0])->gso_size; |
| 364 | t0->gso_l4_hdr_sz = vnet_buffer2 (b[0])->gso_l4_hdr_sz; |
| 365 | } |
| 366 | if (b[1]->flags & VLIB_BUFFER_IS_TRACED) |
| 367 | { |
| 368 | t1 = vlib_add_trace (vm, node, b[1], sizeof (t1[0])); |
| 369 | t1->flags = b[1]->flags & VNET_BUFFER_F_GSO; |
| 370 | t1->gso_size = vnet_buffer2 (b[1])->gso_size; |
| 371 | t1->gso_l4_hdr_sz = vnet_buffer2 (b[1])->gso_l4_hdr_sz; |
| 372 | } |
| 373 | if (b[2]->flags & VLIB_BUFFER_IS_TRACED) |
| 374 | { |
| 375 | t2 = vlib_add_trace (vm, node, b[2], sizeof (t2[0])); |
| 376 | t2->flags = b[2]->flags & VNET_BUFFER_F_GSO; |
| 377 | t2->gso_size = vnet_buffer2 (b[2])->gso_size; |
| 378 | t2->gso_l4_hdr_sz = vnet_buffer2 (b[2])->gso_l4_hdr_sz; |
| 379 | } |
| 380 | if (b[3]->flags & VLIB_BUFFER_IS_TRACED) |
| 381 | { |
| 382 | t3 = vlib_add_trace (vm, node, b[3], sizeof (t3[0])); |
| 383 | t3->flags = b[3]->flags & VNET_BUFFER_F_GSO; |
| 384 | t3->gso_size = vnet_buffer2 (b[3])->gso_size; |
| 385 | t3->gso_l4_hdr_sz = vnet_buffer2 (b[3])->gso_l4_hdr_sz; |
| 386 | } |
| 387 | |
| 388 | from += 4; |
| 389 | to_next += 4; |
| 390 | n_left_to_next -= 4; |
| 391 | n_left_from -= 4; |
| 392 | |
| 393 | next0 = next1 = 0; |
| 394 | next2 = next3 = 0; |
| 395 | vnet_feature_next (&next0, b[0]); |
| 396 | vnet_feature_next (&next1, b[1]); |
| 397 | vnet_feature_next (&next2, b[2]); |
| 398 | vnet_feature_next (&next3, b[3]); |
| 399 | vlib_validate_buffer_enqueue_x4 (vm, node, next_index, to_next, |
| 400 | n_left_to_next, bi0, bi1, bi2, bi3, |
| 401 | next0, next1, next2, next3); |
| 402 | b += 4; |
| 403 | } |
| 404 | |
| 405 | while (from + 1 <= from_end && n_left_to_next > 0) |
| 406 | { |
| 407 | u32 bi0, swif0; |
| 408 | gso_trace_t *t0; |
| 409 | vnet_hw_interface_t *hi0; |
| 410 | u32 next0 = 0; |
| 411 | |
| 412 | swif0 = vnet_buffer (b[0])->sw_if_index[VLIB_TX]; |
| 413 | if (PREDICT_FALSE (hi->sw_if_index != swif0)) |
| 414 | { |
| 415 | hi0 = vnet_get_sup_hw_interface (vnm, swif0); |
| 416 | if ((hi0->flags & VNET_HW_INTERFACE_FLAG_SUPPORTS_GSO) == 0 && |
| 417 | (b[0]->flags & VNET_BUFFER_F_GSO)) |
| 418 | do_segmentation = 1; |
| 419 | } |
| 420 | |
| 421 | /* speculatively enqueue b0 to the current next frame */ |
| 422 | to_next[0] = bi0 = from[0]; |
| 423 | to_next += 1; |
| 424 | n_left_to_next -= 1; |
| 425 | from += 1; |
| 426 | n_left_from -= 1; |
| 427 | |
| 428 | if (b[0]->flags & VLIB_BUFFER_IS_TRACED) |
| 429 | { |
| 430 | t0 = vlib_add_trace (vm, node, b[0], sizeof (t0[0])); |
| 431 | t0->flags = b[0]->flags & VNET_BUFFER_F_GSO; |
| 432 | t0->gso_size = vnet_buffer2 (b[0])->gso_size; |
| 433 | t0->gso_l4_hdr_sz = vnet_buffer2 (b[0])->gso_l4_hdr_sz; |
| 434 | } |
| 435 | |
| 436 | if (do_segmentation) |
| 437 | { |
| 438 | if (PREDICT_FALSE (b[0]->flags & VNET_BUFFER_F_GSO)) |
| 439 | { |
| 440 | /* |
| 441 | * Undo the enqueue of the b0 - it is not going anywhere, |
| 442 | * and will be freed either after it's segmented or |
| 443 | * when dropped, if there is no buffers to segment into. |
| 444 | */ |
| 445 | to_next -= 1; |
| 446 | n_left_to_next += 1; |
| 447 | /* undo the counting. */ |
| 448 | u32 n_bytes_b0 = vlib_buffer_length_in_chain (vm, b[0]); |
| 449 | u32 n_tx_bytes = 0; |
| 450 | |
| 451 | n_tx_bytes = |
| 452 | tso_segment_buffer (vm, ptd, bi0, b[0], n_bytes_b0, |
| 453 | is_ip6); |
| 454 | |
| 455 | if (PREDICT_FALSE (n_tx_bytes == 0)) |
| 456 | { |
| 457 | drop_one_buffer_and_count (vm, vnm, node, from - 1, |
| 458 | hi->sw_if_index, |
| 459 | VNET_INTERFACE_OUTPUT_ERROR_NO_BUFFERS_FOR_GSO); |
| 460 | b += 1; |
| 461 | continue; |
| 462 | } |
| 463 | |
| 464 | u16 n_tx_bufs = vec_len (ptd->split_buffers); |
| 465 | u32 *from_seg = ptd->split_buffers; |
| 466 | |
| 467 | while (n_tx_bufs > 0) |
| 468 | { |
| 469 | u32 sbi0; |
| 470 | vlib_buffer_t *sb0; |
| 471 | if (n_tx_bufs >= n_left_to_next) |
| 472 | { |
| 473 | while (n_left_to_next > 0) |
| 474 | { |
| 475 | sbi0 = to_next[0] = from_seg[0]; |
| 476 | sb0 = vlib_get_buffer (vm, sbi0); |
| 477 | to_next += 1; |
| 478 | from_seg += 1; |
| 479 | n_left_to_next -= 1; |
| 480 | n_tx_bufs -= 1; |
| 481 | vnet_feature_next (&next0, sb0); |
| 482 | vlib_validate_buffer_enqueue_x1 (vm, node, |
| 483 | next_index, |
| 484 | to_next, |
| 485 | n_left_to_next, |
| 486 | sbi0, next0); |
| 487 | } |
| 488 | vlib_put_next_frame (vm, node, next_index, |
| 489 | n_left_to_next); |
| 490 | vlib_get_new_next_frame (vm, node, next_index, |
| 491 | to_next, n_left_to_next); |
| 492 | } |
| 493 | while (n_tx_bufs > 0) |
| 494 | { |
| 495 | sbi0 = to_next[0] = from_seg[0]; |
| 496 | sb0 = vlib_get_buffer (vm, sbi0); |
| 497 | to_next += 1; |
| 498 | from_seg += 1; |
| 499 | n_left_to_next -= 1; |
| 500 | n_tx_bufs -= 1; |
| 501 | vnet_feature_next (&next0, sb0); |
| 502 | vlib_validate_buffer_enqueue_x1 (vm, node, |
| 503 | next_index, |
| 504 | to_next, |
| 505 | n_left_to_next, |
| 506 | sbi0, next0); |
| 507 | } |
| 508 | } |
| 509 | /* The buffers were enqueued. Reset the length */ |
| 510 | _vec_len (ptd->split_buffers) = 0; |
| 511 | /* Free the now segmented buffer */ |
| 512 | vlib_buffer_free_one (vm, bi0); |
| 513 | b += 1; |
| 514 | continue; |
| 515 | } |
| 516 | } |
| 517 | |
| 518 | vnet_feature_next (&next0, b[0]); |
| 519 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next, |
| 520 | n_left_to_next, bi0, next0); |
| 521 | b += 1; |
| 522 | } |
| 523 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 524 | } |
| 525 | |
| 526 | return frame->n_vectors; |
| 527 | } |
| 528 | |
| 529 | static_always_inline uword |
| 530 | vnet_gso_inline (vlib_main_t * vm, |
| 531 | vlib_node_runtime_t * node, vlib_frame_t * frame, int is_ip6) |
| 532 | { |
| 533 | vnet_main_t *vnm = vnet_get_main (); |
| 534 | vnet_hw_interface_t *hi; |
| 535 | |
| 536 | if (frame->n_vectors > 0) |
| 537 | { |
| 538 | u32 *from = vlib_frame_vector_args (frame); |
| 539 | vlib_buffer_t *b = vlib_get_buffer (vm, from[0]); |
| 540 | hi = vnet_get_sup_hw_interface (vnm, |
| 541 | vnet_buffer (b)->sw_if_index[VLIB_TX]); |
| 542 | /* |
| 543 | * The 3-headed "if" is here because we want to err on the side |
| 544 | * of not impacting the non-GSO performance - so for the more |
| 545 | * common case of no GSO interfaces we want to prevent the |
| 546 | * segmentation codepath from being there altogether. |
| 547 | */ |
| 548 | if (hi->flags & VNET_HW_INTERFACE_FLAG_SUPPORTS_GSO) |
| 549 | return vnet_gso_node_inline (vm, node, frame, vnm, hi, |
| 550 | is_ip6, /* do_segmentation */ 0); |
| 551 | else |
| 552 | return vnet_gso_node_inline (vm, node, frame, vnm, hi, |
| 553 | is_ip6, /* do_segmentation */ 1); |
| 554 | } |
| 555 | return 0; |
| 556 | } |
| 557 | |
| 558 | VLIB_NODE_FN (gso_l2_ip4_node) (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 559 | vlib_frame_t * frame) |
| 560 | { |
| 561 | return vnet_gso_inline (vm, node, frame, 0 /* ip6 */ ); |
| 562 | } |
| 563 | |
| 564 | VLIB_NODE_FN (gso_l2_ip6_node) (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 565 | vlib_frame_t * frame) |
| 566 | { |
| 567 | return vnet_gso_inline (vm, node, frame, 1 /* ip6 */ ); |
| 568 | } |
| 569 | |
| 570 | VLIB_NODE_FN (gso_ip4_node) (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 571 | vlib_frame_t * frame) |
| 572 | { |
| 573 | return vnet_gso_inline (vm, node, frame, 0 /* ip6 */ ); |
| 574 | } |
| 575 | |
| 576 | VLIB_NODE_FN (gso_ip6_node) (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 577 | vlib_frame_t * frame) |
| 578 | { |
| 579 | return vnet_gso_inline (vm, node, frame, 1 /* ip6 */ ); |
| 580 | } |
| 581 | |
| 582 | /* *INDENT-OFF* */ |
| 583 | |
| 584 | VLIB_REGISTER_NODE (gso_l2_ip4_node) = { |
| 585 | .vector_size = sizeof (u32), |
| 586 | .format_trace = format_gso_trace, |
| 587 | .type = VLIB_NODE_TYPE_INTERNAL, |
| 588 | .n_errors = 0, |
| 589 | .n_next_nodes = 0, |
| 590 | .name = "gso-l2-ip4", |
| 591 | }; |
| 592 | |
| 593 | VLIB_REGISTER_NODE (gso_l2_ip6_node) = { |
| 594 | .vector_size = sizeof (u32), |
| 595 | .format_trace = format_gso_trace, |
| 596 | .type = VLIB_NODE_TYPE_INTERNAL, |
| 597 | .n_errors = 0, |
| 598 | .n_next_nodes = 0, |
| 599 | .name = "gso-l2-ip6", |
| 600 | }; |
| 601 | |
| 602 | VLIB_REGISTER_NODE (gso_ip4_node) = { |
| 603 | .vector_size = sizeof (u32), |
| 604 | .format_trace = format_gso_trace, |
| 605 | .type = VLIB_NODE_TYPE_INTERNAL, |
| 606 | .n_errors = 0, |
| 607 | .n_next_nodes = 0, |
| 608 | .name = "gso-ip4", |
| 609 | }; |
| 610 | |
| 611 | VLIB_REGISTER_NODE (gso_ip6_node) = { |
| 612 | .vector_size = sizeof (u32), |
| 613 | .format_trace = format_gso_trace, |
| 614 | .type = VLIB_NODE_TYPE_INTERNAL, |
| 615 | .n_errors = 0, |
| 616 | .n_next_nodes = 0, |
| 617 | .name = "gso-ip6", |
| 618 | }; |
| 619 | |
| 620 | VNET_FEATURE_INIT (gso_l2_ip4_node, static) = { |
| 621 | .arc_name = "l2-output-ip4", |
| 622 | .node_name = "gso-l2-ip4", |
| 623 | .runs_before = VNET_FEATURES ("l2-output-feat-arc-end"), |
| 624 | }; |
| 625 | |
| 626 | VNET_FEATURE_INIT (gso_l2_ip6_node, static) = { |
| 627 | .arc_name = "l2-output-ip6", |
| 628 | .node_name = "gso-l2-ip6", |
| 629 | .runs_before = VNET_FEATURES ("l2-output-feat-arc-end"), |
| 630 | }; |
| 631 | |
| 632 | VNET_FEATURE_INIT (gso_ip4_node, static) = { |
| 633 | .arc_name = "ip4-output", |
| 634 | .node_name = "gso-ip4", |
| 635 | .runs_after = VNET_FEATURES ("ipsec4-output-feature"), |
| 636 | .runs_before = VNET_FEATURES ("interface-output"), |
| 637 | }; |
| 638 | |
| 639 | VNET_FEATURE_INIT (gso_ip6_node, static) = { |
| 640 | .arc_name = "ip6-output", |
| 641 | .node_name = "gso-ip6", |
| 642 | .runs_after = VNET_FEATURES ("ipsec6-output-feature"), |
| 643 | .runs_before = VNET_FEATURES ("interface-output"), |
| 644 | }; |
| 645 | |
| 646 | /* |
| 647 | * fd.io coding-style-patch-verification: ON |
| 648 | * |
| 649 | * Local Variables: |
| 650 | * eval: (c-set-style "gnu") |
| 651 | * End: |
| 652 | */ |