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