blob: c1d4459476ed98b56780c21409f62b1986a18a7c [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>
Mohsin Kazmi0b042092020-04-17 16:50:56 +000022#include <vnet/gso/hdr_offset_parser.h>
Mohsin Kazmi29467b52019-10-08 19:42:38 +020023#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 Kazmi79e087f2021-05-27 21:05:41 +020028#define foreach_gso_error \
29 _ (NO_BUFFERS, "no buffers to segment GSO") \
30 _ (UNHANDLED_TYPE, "unhandled gso type")
31
32static char *gso_error_strings[] = {
33#define _(sym, string) string,
34 foreach_gso_error
35#undef _
36};
37
38typedef enum
39{
40#define _(sym, str) GSO_ERROR_##sym,
41 foreach_gso_error
42#undef _
43 GSO_N_ERROR,
44} gso_error_t;
45
46typedef enum
47{
48 GSO_NEXT_DROP,
49 GSO_N_NEXT,
50} gso_next_t;
51
Mohsin Kazmi29467b52019-10-08 19:42:38 +020052typedef struct
53{
54 u32 flags;
55 u16 gso_size;
56 u8 gso_l4_hdr_sz;
Mohsin Kazmi0b042092020-04-17 16:50:56 +000057 generic_header_offset_t gho;
Mohsin Kazmi29467b52019-10-08 19:42:38 +020058} gso_trace_t;
59
60static u8 *
61format_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 Kazmib3a8f4e2020-09-15 16:41:44 +000069 s = format (s, "gso_sz %d gso_l4_hdr_sz %d\n%U",
Mohsin Kazmi0b042092020-04-17 16:50:56 +000070 t->gso_size, t->gso_l4_hdr_sz, format_generic_header_offset,
71 &t->gho);
Mohsin Kazmi29467b52019-10-08 19:42:38 +020072 }
Mohsin Kazmi70ae4ef2019-12-09 11:46:01 +010073 else
74 {
Mohsin Kazmi0b042092020-04-17 16:50:56 +000075 s =
Mohsin Kazmib3a8f4e2020-09-15 16:41:44 +000076 format (s, "non-gso buffer\n%U", format_generic_header_offset,
Mohsin Kazmi0b042092020-04-17 16:50:56 +000077 &t->gho);
Mohsin Kazmi70ae4ef2019-12-09 11:46:01 +010078 }
Mohsin Kazmi29467b52019-10-08 19:42:38 +020079
80 return s;
81}
82
Mohsin Kazmi7b3339e2022-09-29 15:28:04 +000083static_always_inline void
84tso_segment_ipip_tunnel_fixup (vlib_main_t *vm,
85 vnet_interface_per_thread_data_t *ptd,
86 vlib_buffer_t *sb0)
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +020087{
88 u16 n_tx_bufs = vec_len (ptd->split_buffers);
Mohsin Kazmi7b3339e2022-09-29 15:28:04 +000089 u16 i = 0;
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +020090
91 while (i < n_tx_bufs)
92 {
93 vlib_buffer_t *b0 = vlib_get_buffer (vm, ptd->split_buffers[i]);
Mohsin Kazmi7b3339e2022-09-29 15:28:04 +000094 i16 outer_l3_hdr_offset = vnet_buffer2 (b0)->outer_l3_hdr_offset;
95 i16 l3_hdr_offset = vnet_buffer (b0)->l3_hdr_offset;
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +020096
Mohsin Kazmi7b3339e2022-09-29 15:28:04 +000097 ip4_header_t *ip4 = (ip4_header_t *) (b0->data + outer_l3_hdr_offset);
98 ip6_header_t *ip6 = (ip6_header_t *) (b0->data + outer_l3_hdr_offset);
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +020099
Mohsin Kazmi7b3339e2022-09-29 15:28:04 +0000100 if (vnet_buffer (b0)->oflags & VNET_BUFFER_OFFLOAD_F_OUTER_IP_CKSUM)
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200101 {
Mohsin Kazmi7b3339e2022-09-29 15:28:04 +0000102 ip4->length = clib_host_to_net_u16 (
103 b0->current_length - (outer_l3_hdr_offset - b0->current_data));
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200104 ip4->checksum = ip4_header_checksum (ip4);
Mohsin Kazmi7b3339e2022-09-29 15:28:04 +0000105 vnet_buffer_offload_flags_clear (
106 b0, VNET_BUFFER_OFFLOAD_F_OUTER_IP_CKSUM |
107 VNET_BUFFER_OFFLOAD_F_TNL_IPIP);
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200108 }
Mohsin Kazmi7b3339e2022-09-29 15:28:04 +0000109 else
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200110 {
Mohsin Kazmi7b3339e2022-09-29 15:28:04 +0000111 ip6->payload_length = clib_host_to_net_u16 (
112 b0->current_length - (l3_hdr_offset - b0->current_data));
113 vnet_buffer_offload_flags_clear (b0, VNET_BUFFER_OFFLOAD_F_TNL_IPIP);
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200114 }
115
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200116 i++;
117 }
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200118}
119
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000120static_always_inline void
Mohsin Kazmi7b3339e2022-09-29 15:28:04 +0000121tso_segment_vxlan_tunnel_headers_fixup (vlib_main_t *vm, vlib_buffer_t *b)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000122{
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000123 ip4_header_t *ip4 = 0;
124 ip6_header_t *ip6 = 0;
125 udp_header_t *udp = 0;
Mohsin Kazmi7b3339e2022-09-29 15:28:04 +0000126 i16 outer_l3_hdr_offset = vnet_buffer2 (b)->outer_l3_hdr_offset;
127 i16 outer_l4_hdr_offset = vnet_buffer2 (b)->outer_l4_hdr_offset;
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000128
Mohsin Kazmi7b3339e2022-09-29 15:28:04 +0000129 ip4 = (ip4_header_t *) (b->data + outer_l3_hdr_offset);
130 ip6 = (ip6_header_t *) (b->data + outer_l3_hdr_offset);
131 udp = (udp_header_t *) (b->data + outer_l4_hdr_offset);
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000132
Mohsin Kazmi7b3339e2022-09-29 15:28:04 +0000133 if (vnet_buffer (b)->oflags & VNET_BUFFER_OFFLOAD_F_OUTER_IP_CKSUM)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000134 {
Mohsin Kazmi7b3339e2022-09-29 15:28:04 +0000135 ip4->length = clib_host_to_net_u16 (
136 b->current_length - (outer_l3_hdr_offset - b->current_data));
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000137 ip4->checksum = ip4_header_checksum (ip4);
Mohsin Kazmi7b3339e2022-09-29 15:28:04 +0000138 if (vnet_buffer (b)->oflags & VNET_BUFFER_OFFLOAD_F_OUTER_UDP_CKSUM)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000139 {
Mohsin Kazmi7b3339e2022-09-29 15:28:04 +0000140 udp->length = clib_host_to_net_u16 (
141 b->current_length - (outer_l4_hdr_offset - b->current_data));
142 // udp checksum is 0, in udp tunnel
143 udp->checksum = 0;
144 }
145 vnet_buffer_offload_flags_clear (
146 b, VNET_BUFFER_OFFLOAD_F_OUTER_IP_CKSUM |
147 VNET_BUFFER_OFFLOAD_F_OUTER_UDP_CKSUM |
148 VNET_BUFFER_OFFLOAD_F_TNL_VXLAN);
149 }
150 else
151 {
152 ip6->payload_length = clib_host_to_net_u16 (
153 b->current_length - (outer_l4_hdr_offset - b->current_data));
154
155 if (vnet_buffer (b)->oflags & VNET_BUFFER_OFFLOAD_F_OUTER_UDP_CKSUM)
156 {
157 int bogus;
158 udp->length = ip6->payload_length;
159 // udp checksum is 0, in udp tunnel
160 udp->checksum = 0;
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000161 udp->checksum =
162 ip6_tcp_udp_icmp_compute_checksum (vm, b, ip6, &bogus);
Mohsin Kazmi7b3339e2022-09-29 15:28:04 +0000163 vnet_buffer_offload_flags_clear (
164 b, VNET_BUFFER_OFFLOAD_F_OUTER_UDP_CKSUM |
165 VNET_BUFFER_OFFLOAD_F_TNL_VXLAN);
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000166 }
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000167 }
168}
169
Mohsin Kazmi7b3339e2022-09-29 15:28:04 +0000170static_always_inline void
171tso_segment_vxlan_tunnel_fixup (vlib_main_t *vm,
172 vnet_interface_per_thread_data_t *ptd,
173 vlib_buffer_t *sb0)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000174{
175 u16 n_tx_bufs = vec_len (ptd->split_buffers);
Mohsin Kazmi7b3339e2022-09-29 15:28:04 +0000176 u16 i = 0;
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000177
178 while (i < n_tx_bufs)
179 {
180 vlib_buffer_t *b0 = vlib_get_buffer (vm, ptd->split_buffers[i]);
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000181
Mohsin Kazmi7b3339e2022-09-29 15:28:04 +0000182 tso_segment_vxlan_tunnel_headers_fixup (vm, b0);
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000183 i++;
184 }
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000185}
186
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200187static_always_inline u16
188tso_alloc_tx_bufs (vlib_main_t * vm,
189 vnet_interface_per_thread_data_t * ptd,
190 vlib_buffer_t * b0, u32 n_bytes_b0, u16 l234_sz,
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000191 u16 gso_size, u16 first_data_size,
192 generic_header_offset_t * gho)
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200193{
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000194 u16 n_alloc, size;
195 u16 first_packet_length = l234_sz + first_data_size;
196
197 /*
198 * size is the amount of data per segmented buffer except the 1st
199 * segmented buffer.
200 * l2_hdr_offset is an offset == current_data of vlib_buffer_t.
201 * l234_sz is hdr_sz from l2_hdr_offset.
202 */
203 size =
Mohsin Kazmi222b7092019-12-25 00:12:52 +0100204 clib_min (gso_size, vlib_buffer_get_default_data_size (vm) - l234_sz
205 - gho->l2_hdr_offset);
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200206
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000207 /*
208 * First segmented buffer length is calculated separately.
209 * As it may contain less data than gso_size (when gso_size is
210 * greater than current_length of 1st buffer from GSO chained
211 * buffers) and/or size calculated above.
212 */
213 u16 n_bufs = 1;
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200214
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000215 /*
216 * Total packet length minus first packet length including l234 header.
217 * rounded-up division
218 */
219 ASSERT (n_bytes_b0 > first_packet_length);
220 n_bufs += ((n_bytes_b0 - first_packet_length + (size - 1)) / size);
221
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200222 vec_validate (ptd->split_buffers, n_bufs - 1);
223
224 n_alloc = vlib_buffer_alloc (vm, ptd->split_buffers, n_bufs);
225 if (n_alloc < n_bufs)
226 {
227 vlib_buffer_free (vm, ptd->split_buffers, n_alloc);
228 return 0;
229 }
230 return n_alloc;
231}
232
233static_always_inline void
234tso_init_buf_from_template_base (vlib_buffer_t * nb0, vlib_buffer_t * b0,
235 u32 flags, u16 length)
236{
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200237 /* copying objects from cacheline 0 */
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200238 nb0->current_data = b0->current_data;
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200239 nb0->current_length = length;
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200240 nb0->flags = VLIB_BUFFER_TOTAL_LENGTH_VALID | flags;
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200241 nb0->flow_id = b0->flow_id;
242 nb0->error = b0->error;
243 nb0->current_config_index = b0->current_config_index;
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200244 clib_memcpy_fast (&nb0->opaque, &b0->opaque, sizeof (nb0->opaque));
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200245
246 /* copying objects from cacheline 1 */
247 nb0->trace_handle = b0->trace_handle;
248 nb0->total_length_not_including_first_buffer = 0;
249
250 /* copying data */
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200251 clib_memcpy_fast (vlib_buffer_get_current (nb0),
252 vlib_buffer_get_current (b0), length);
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200253}
254
255static_always_inline void
256tso_init_buf_from_template (vlib_main_t * vm, vlib_buffer_t * nb0,
257 vlib_buffer_t * b0, u16 template_data_sz,
258 u16 gso_size, u8 ** p_dst_ptr, u16 * p_dst_left,
Mohsin Kazmi72e73122019-10-22 13:33:13 +0200259 u32 next_tcp_seq, u32 flags,
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000260 generic_header_offset_t * gho)
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200261{
262 tso_init_buf_from_template_base (nb0, b0, flags, template_data_sz);
263
264 *p_dst_left =
265 clib_min (gso_size,
266 vlib_buffer_get_default_data_size (vm) - (template_data_sz +
267 nb0->current_data));
268 *p_dst_ptr = vlib_buffer_get_current (nb0) + template_data_sz;
269
270 tcp_header_t *tcp =
Mohsin Kazmi72e73122019-10-22 13:33:13 +0200271 (tcp_header_t *) (vlib_buffer_get_current (nb0) + gho->l4_hdr_offset);
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200272 tcp->seq_number = clib_host_to_net_u32 (next_tcp_seq);
273}
274
275static_always_inline void
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000276tso_fixup_segmented_buf (vlib_main_t * vm, vlib_buffer_t * b0, u8 tcp_flags,
Mohsin Kazmiec1d61e2020-06-24 16:20:54 +0200277 int is_l2, int is_ip6, generic_header_offset_t * gho)
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200278{
Mohsin Kazmi72e73122019-10-22 13:33:13 +0200279 ip4_header_t *ip4 =
280 (ip4_header_t *) (vlib_buffer_get_current (b0) + gho->l3_hdr_offset);
281 ip6_header_t *ip6 =
282 (ip6_header_t *) (vlib_buffer_get_current (b0) + gho->l3_hdr_offset);
283 tcp_header_t *tcp =
284 (tcp_header_t *) (vlib_buffer_get_current (b0) + gho->l4_hdr_offset);
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200285
286 tcp->flags = tcp_flags;
287
288 if (is_ip6)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000289 {
290 ip6->payload_length =
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200291 clib_host_to_net_u16 (b0->current_length - gho->l4_hdr_offset);
292 if (gho->gho_flags & GHO_F_TCP)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000293 {
294 int bogus = 0;
295 tcp->checksum = 0;
296 tcp->checksum =
297 ip6_tcp_udp_icmp_compute_checksum (vm, b0, ip6, &bogus);
Mohsin Kazmi68095382021-02-10 11:26:24 +0100298 vnet_buffer_offload_flags_clear (b0,
299 VNET_BUFFER_OFFLOAD_F_TCP_CKSUM);
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000300 }
301 }
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200302 else
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000303 {
304 ip4->length =
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200305 clib_host_to_net_u16 (b0->current_length - gho->l3_hdr_offset);
306 if (gho->gho_flags & GHO_F_IP4)
307 ip4->checksum = ip4_header_checksum (ip4);
308 if (gho->gho_flags & GHO_F_TCP)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000309 {
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200310 tcp->checksum = 0;
311 tcp->checksum = ip4_tcp_udp_compute_checksum (vm, b0, ip4);
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000312 }
Mohsin Kazmi68095382021-02-10 11:26:24 +0100313 vnet_buffer_offload_flags_clear (b0, (VNET_BUFFER_OFFLOAD_F_IP_CKSUM |
314 VNET_BUFFER_OFFLOAD_F_TCP_CKSUM));
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200315 }
316
Mohsin Kazmiec1d61e2020-06-24 16:20:54 +0200317 if (!is_l2 && ((gho->gho_flags & GHO_F_TUNNEL) == 0))
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200318 {
319 u32 adj_index0 = vnet_buffer (b0)->ip.adj_index[VLIB_TX];
320
321 ip_adjacency_t *adj0 = adj_get (adj_index0);
322
323 if (adj0->lookup_next_index == IP_LOOKUP_NEXT_MIDCHAIN &&
324 adj0->sub_type.midchain.fixup_func)
325 /* calls e.g. ipip44_fixup */
326 adj0->sub_type.midchain.fixup_func
327 (vm, adj0, b0, adj0->sub_type.midchain.fixup_data);
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000328 }
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200329}
330
331/**
332 * Allocate the necessary number of ptd->split_buffers,
333 * and segment the possibly chained buffer(s) from b0 into
334 * there.
335 *
336 * Return the cumulative number of bytes sent or zero
337 * if allocation failed.
338 */
339
340static_always_inline u32
341tso_segment_buffer (vlib_main_t * vm, vnet_interface_per_thread_data_t * ptd,
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000342 u32 sbi0, vlib_buffer_t * sb0,
Mohsin Kazmiec1d61e2020-06-24 16:20:54 +0200343 generic_header_offset_t * gho, u32 n_bytes_b0, int is_l2,
344 int is_ip6)
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200345{
346 u32 n_tx_bytes = 0;
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200347 u16 gso_size = vnet_buffer2 (sb0)->gso_size;
348
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200349 u8 save_tcp_flags = 0;
350 u8 tcp_flags_no_fin_psh = 0;
351 u32 next_tcp_seq = 0;
352
353 tcp_header_t *tcp =
Mohsin Kazmi72e73122019-10-22 13:33:13 +0200354 (tcp_header_t *) (vlib_buffer_get_current (sb0) + gho->l4_hdr_offset);
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200355 next_tcp_seq = clib_net_to_host_u32 (tcp->seq_number);
356 /* store original flags for last packet and reset FIN and PSH */
357 save_tcp_flags = tcp->flags;
358 tcp_flags_no_fin_psh = tcp->flags & ~(TCP_FLAG_FIN | TCP_FLAG_PSH);
359 tcp->checksum = 0;
360
361 u32 default_bflags =
362 sb0->flags & ~(VNET_BUFFER_F_GSO | VLIB_BUFFER_NEXT_PRESENT);
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000363 u16 l234_sz = gho->hdr_sz;
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200364 int first_data_size = clib_min (gso_size, sb0->current_length - l234_sz);
365 next_tcp_seq += first_data_size;
366
367 if (PREDICT_FALSE
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000368 (!tso_alloc_tx_bufs
369 (vm, ptd, sb0, n_bytes_b0, l234_sz, gso_size, first_data_size, gho)))
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200370 return 0;
371
372 vlib_buffer_t *b0 = vlib_get_buffer (vm, ptd->split_buffers[0]);
373 tso_init_buf_from_template_base (b0, sb0, default_bflags,
374 l234_sz + first_data_size);
375
376 u32 total_src_left = n_bytes_b0 - l234_sz - first_data_size;
377 if (total_src_left)
378 {
379 /* Need to copy more segments */
380 u8 *src_ptr, *dst_ptr;
381 u16 src_left, dst_left;
382 /* current source buffer */
383 vlib_buffer_t *csb0 = sb0;
384 u32 csbi0 = sbi0;
385 /* current dest buffer */
386 vlib_buffer_t *cdb0;
387 u16 dbi = 1; /* the buffer [0] is b0 */
388
389 src_ptr = vlib_buffer_get_current (sb0) + l234_sz + first_data_size;
390 src_left = sb0->current_length - l234_sz - first_data_size;
391
Mohsin Kazmiec1d61e2020-06-24 16:20:54 +0200392 tso_fixup_segmented_buf (vm, b0, tcp_flags_no_fin_psh, is_l2, is_ip6,
393 gho);
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200394
395 /* grab a second buffer and prepare the loop */
396 ASSERT (dbi < vec_len (ptd->split_buffers));
397 cdb0 = vlib_get_buffer (vm, ptd->split_buffers[dbi++]);
398 tso_init_buf_from_template (vm, cdb0, b0, l234_sz, gso_size, &dst_ptr,
Mohsin Kazmi72e73122019-10-22 13:33:13 +0200399 &dst_left, next_tcp_seq, default_bflags,
400 gho);
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200401
402 /* an arbitrary large number to catch the runaway loops */
403 int nloops = 2000;
404 while (total_src_left)
405 {
406 if (nloops-- <= 0)
407 clib_panic ("infinite loop detected");
408 u16 bytes_to_copy = clib_min (src_left, dst_left);
409
410 clib_memcpy_fast (dst_ptr, src_ptr, bytes_to_copy);
411
412 src_left -= bytes_to_copy;
413 src_ptr += bytes_to_copy;
414 total_src_left -= bytes_to_copy;
415 dst_left -= bytes_to_copy;
416 dst_ptr += bytes_to_copy;
417 next_tcp_seq += bytes_to_copy;
418 cdb0->current_length += bytes_to_copy;
419
420 if (0 == src_left)
421 {
422 int has_next = (csb0->flags & VLIB_BUFFER_NEXT_PRESENT);
423 u32 next_bi = csb0->next_buffer;
424
425 /* init src to the next buffer in chain */
426 if (has_next)
427 {
428 csbi0 = next_bi;
429 csb0 = vlib_get_buffer (vm, csbi0);
430 src_left = csb0->current_length;
431 src_ptr = vlib_buffer_get_current (csb0);
432 }
433 else
434 {
435 ASSERT (total_src_left == 0);
436 break;
437 }
438 }
439 if (0 == dst_left && total_src_left)
440 {
441 n_tx_bytes += cdb0->current_length;
Mohsin Kazmiec1d61e2020-06-24 16:20:54 +0200442 tso_fixup_segmented_buf (vm, cdb0, tcp_flags_no_fin_psh, is_l2,
443 is_ip6, gho);
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200444 ASSERT (dbi < vec_len (ptd->split_buffers));
445 cdb0 = vlib_get_buffer (vm, ptd->split_buffers[dbi++]);
446 tso_init_buf_from_template (vm, cdb0, b0, l234_sz,
447 gso_size, &dst_ptr, &dst_left,
Mohsin Kazmi72e73122019-10-22 13:33:13 +0200448 next_tcp_seq, default_bflags, gho);
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200449 }
450 }
451
Mohsin Kazmiec1d61e2020-06-24 16:20:54 +0200452 tso_fixup_segmented_buf (vm, cdb0, save_tcp_flags, is_l2, is_ip6, gho);
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200453
454 n_tx_bytes += cdb0->current_length;
455 }
456 n_tx_bytes += b0->current_length;
457 return n_tx_bytes;
458}
459
Mohsin Kazmid9e7ac32021-10-15 22:45:51 +0000460__clib_unused u32
461gso_segment_buffer (vlib_main_t *vm, vnet_interface_per_thread_data_t *ptd,
462 u32 bi, vlib_buffer_t *b, generic_header_offset_t *gho,
463 u32 n_bytes_b, u8 is_l2, u8 is_ip6)
464{
465
466 return tso_segment_buffer (vm, ptd, bi, b, gho, n_bytes_b, is_l2, is_ip6);
467}
468
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200469static_always_inline void
470drop_one_buffer_and_count (vlib_main_t * vm, vnet_main_t * vnm,
471 vlib_node_runtime_t * node, u32 * pbi0,
472 u32 sw_if_index, u32 drop_error_code)
473{
474 u32 thread_index = vm->thread_index;
475
476 vlib_simple_counter_main_t *cm;
477 cm =
478 vec_elt_at_index (vnm->interface_main.sw_if_counters,
479 VNET_INTERFACE_COUNTER_TX_ERROR);
480 vlib_increment_simple_counter (cm, thread_index, sw_if_index, 1);
481
482 vlib_error_drop_buffers (vm, node, pbi0,
483 /* buffer stride */ 1,
Mohsin Kazmi79e087f2021-05-27 21:05:41 +0200484 /* n_buffers */ 1, GSO_NEXT_DROP, node->node_index,
485 drop_error_code);
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200486}
487
488static_always_inline uword
489vnet_gso_node_inline (vlib_main_t * vm,
490 vlib_node_runtime_t * node,
491 vlib_frame_t * frame,
492 vnet_main_t * vnm,
493 vnet_hw_interface_t * hi,
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200494 int is_l2, int is_ip4, int is_ip6, int do_segmentation)
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200495{
496 u32 *to_next;
497 u32 next_index = node->cached_next_index;
498 u32 *from = vlib_frame_vector_args (frame);
499 u32 n_left_from = frame->n_vectors;
500 u32 *from_end = from + n_left_from;
501 u32 thread_index = vm->thread_index;
502 vnet_interface_main_t *im = &vnm->interface_main;
503 vnet_interface_per_thread_data_t *ptd =
504 vec_elt_at_index (im->per_thread_data, thread_index);
505 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs;
506
507 vlib_get_buffers (vm, from, b, n_left_from);
508
509 while (n_left_from > 0)
510 {
511 u32 n_left_to_next;
512
513 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
514
Mohsin Kazmi70ae4ef2019-12-09 11:46:01 +0100515 if (!do_segmentation)
516 while (from + 8 <= from_end && n_left_to_next >= 4)
517 {
518 u32 bi0, bi1, bi2, bi3;
519 u32 next0, next1, next2, next3;
520 u32 swif0, swif1, swif2, swif3;
521 gso_trace_t *t0, *t1, *t2, *t3;
522 vnet_hw_interface_t *hi0, *hi1, *hi2, *hi3;
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200523
Mohsin Kazmi70ae4ef2019-12-09 11:46:01 +0100524 /* Prefetch next iteration. */
525 vlib_prefetch_buffer_header (b[4], LOAD);
526 vlib_prefetch_buffer_header (b[5], LOAD);
527 vlib_prefetch_buffer_header (b[6], LOAD);
528 vlib_prefetch_buffer_header (b[7], LOAD);
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200529
Mohsin Kazmi70ae4ef2019-12-09 11:46:01 +0100530 bi0 = from[0];
531 bi1 = from[1];
532 bi2 = from[2];
533 bi3 = from[3];
534 to_next[0] = bi0;
535 to_next[1] = bi1;
536 to_next[2] = bi2;
537 to_next[3] = bi3;
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200538
Mohsin Kazmi70ae4ef2019-12-09 11:46:01 +0100539 swif0 = vnet_buffer (b[0])->sw_if_index[VLIB_TX];
540 swif1 = vnet_buffer (b[1])->sw_if_index[VLIB_TX];
541 swif2 = vnet_buffer (b[2])->sw_if_index[VLIB_TX];
542 swif3 = vnet_buffer (b[3])->sw_if_index[VLIB_TX];
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200543
Mohsin Kazmi70ae4ef2019-12-09 11:46:01 +0100544 if (PREDICT_FALSE (hi->sw_if_index != swif0))
545 {
546 hi0 = vnet_get_sup_hw_interface (vnm, swif0);
Damjan Mariond4f88cc2022-01-05 01:52:38 +0100547 if ((hi0->caps & VNET_HW_IF_CAP_TCP_GSO) == 0 &&
Mohsin Kazmi70ae4ef2019-12-09 11:46:01 +0100548 (b[0]->flags & VNET_BUFFER_F_GSO))
549 break;
550 }
551 if (PREDICT_FALSE (hi->sw_if_index != swif1))
552 {
Steven Luonga420c5e2020-01-16 09:57:22 -0800553 hi1 = vnet_get_sup_hw_interface (vnm, swif1);
Damjan Mariond4f88cc2022-01-05 01:52:38 +0100554 if (!(hi1->caps & VNET_HW_IF_CAP_TCP_GSO) &&
Mohsin Kazmi70ae4ef2019-12-09 11:46:01 +0100555 (b[1]->flags & VNET_BUFFER_F_GSO))
556 break;
557 }
558 if (PREDICT_FALSE (hi->sw_if_index != swif2))
559 {
Steven Luonga420c5e2020-01-16 09:57:22 -0800560 hi2 = vnet_get_sup_hw_interface (vnm, swif2);
Damjan Mariond4f88cc2022-01-05 01:52:38 +0100561 if ((hi2->caps & VNET_HW_IF_CAP_TCP_GSO) == 0 &&
Mohsin Kazmi70ae4ef2019-12-09 11:46:01 +0100562 (b[2]->flags & VNET_BUFFER_F_GSO))
563 break;
564 }
565 if (PREDICT_FALSE (hi->sw_if_index != swif3))
566 {
Steven Luonga420c5e2020-01-16 09:57:22 -0800567 hi3 = vnet_get_sup_hw_interface (vnm, swif3);
Damjan Mariond4f88cc2022-01-05 01:52:38 +0100568 if (!(hi3->caps & VNET_HW_IF_CAP_TCP_GSO) &&
Mohsin Kazmi70ae4ef2019-12-09 11:46:01 +0100569 (b[3]->flags & VNET_BUFFER_F_GSO))
570 break;
571 }
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200572
Mohsin Kazmi70ae4ef2019-12-09 11:46:01 +0100573 if (b[0]->flags & VLIB_BUFFER_IS_TRACED)
574 {
575 t0 = vlib_add_trace (vm, node, b[0], sizeof (t0[0]));
576 t0->flags = b[0]->flags & VNET_BUFFER_F_GSO;
577 t0->gso_size = vnet_buffer2 (b[0])->gso_size;
578 t0->gso_l4_hdr_sz = vnet_buffer2 (b[0])->gso_l4_hdr_sz;
Vladislav Grishenko62fc7872021-11-20 14:52:53 +0500579 clib_memset (&t0->gho, 0, sizeof (t0->gho));
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200580 vnet_generic_header_offset_parser (b[0], &t0->gho, is_l2,
581 is_ip4, is_ip6);
Mohsin Kazmi70ae4ef2019-12-09 11:46:01 +0100582 }
583 if (b[1]->flags & VLIB_BUFFER_IS_TRACED)
584 {
585 t1 = vlib_add_trace (vm, node, b[1], sizeof (t1[0]));
586 t1->flags = b[1]->flags & VNET_BUFFER_F_GSO;
587 t1->gso_size = vnet_buffer2 (b[1])->gso_size;
588 t1->gso_l4_hdr_sz = vnet_buffer2 (b[1])->gso_l4_hdr_sz;
Vladislav Grishenko62fc7872021-11-20 14:52:53 +0500589 clib_memset (&t1->gho, 0, sizeof (t1->gho));
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200590 vnet_generic_header_offset_parser (b[1], &t1->gho, is_l2,
591 is_ip4, is_ip6);
Mohsin Kazmi70ae4ef2019-12-09 11:46:01 +0100592 }
593 if (b[2]->flags & VLIB_BUFFER_IS_TRACED)
594 {
595 t2 = vlib_add_trace (vm, node, b[2], sizeof (t2[0]));
596 t2->flags = b[2]->flags & VNET_BUFFER_F_GSO;
597 t2->gso_size = vnet_buffer2 (b[2])->gso_size;
598 t2->gso_l4_hdr_sz = vnet_buffer2 (b[2])->gso_l4_hdr_sz;
Vladislav Grishenko62fc7872021-11-20 14:52:53 +0500599 clib_memset (&t2->gho, 0, sizeof (t2->gho));
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200600 vnet_generic_header_offset_parser (b[2], &t2->gho, is_l2,
601 is_ip4, is_ip6);
Mohsin Kazmi70ae4ef2019-12-09 11:46:01 +0100602 }
603 if (b[3]->flags & VLIB_BUFFER_IS_TRACED)
604 {
605 t3 = vlib_add_trace (vm, node, b[3], sizeof (t3[0]));
606 t3->flags = b[3]->flags & VNET_BUFFER_F_GSO;
607 t3->gso_size = vnet_buffer2 (b[3])->gso_size;
608 t3->gso_l4_hdr_sz = vnet_buffer2 (b[3])->gso_l4_hdr_sz;
Vladislav Grishenko62fc7872021-11-20 14:52:53 +0500609 clib_memset (&t3->gho, 0, sizeof (t3->gho));
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200610 vnet_generic_header_offset_parser (b[3], &t3->gho, is_l2,
611 is_ip4, is_ip6);
Mohsin Kazmi70ae4ef2019-12-09 11:46:01 +0100612 }
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200613
Mohsin Kazmi70ae4ef2019-12-09 11:46:01 +0100614 from += 4;
615 to_next += 4;
616 n_left_to_next -= 4;
617 n_left_from -= 4;
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200618
Mohsin Kazmi70ae4ef2019-12-09 11:46:01 +0100619 next0 = next1 = 0;
620 next2 = next3 = 0;
621 vnet_feature_next (&next0, b[0]);
622 vnet_feature_next (&next1, b[1]);
623 vnet_feature_next (&next2, b[2]);
624 vnet_feature_next (&next3, b[3]);
625 vlib_validate_buffer_enqueue_x4 (vm, node, next_index, to_next,
626 n_left_to_next, bi0, bi1, bi2,
627 bi3, next0, next1, next2, next3);
628 b += 4;
629 }
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200630
631 while (from + 1 <= from_end && n_left_to_next > 0)
632 {
633 u32 bi0, swif0;
634 gso_trace_t *t0;
635 vnet_hw_interface_t *hi0;
636 u32 next0 = 0;
Mohsin Kazmi70ae4ef2019-12-09 11:46:01 +0100637 u32 do_segmentation0 = 0;
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200638
639 swif0 = vnet_buffer (b[0])->sw_if_index[VLIB_TX];
640 if (PREDICT_FALSE (hi->sw_if_index != swif0))
641 {
642 hi0 = vnet_get_sup_hw_interface (vnm, swif0);
Damjan Mariond4f88cc2022-01-05 01:52:38 +0100643 if ((hi0->caps & VNET_HW_IF_CAP_TCP_GSO) == 0 &&
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200644 (b[0]->flags & VNET_BUFFER_F_GSO))
Mohsin Kazmi70ae4ef2019-12-09 11:46:01 +0100645 do_segmentation0 = 1;
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200646 }
Mohsin Kazmi70ae4ef2019-12-09 11:46:01 +0100647 else
648 do_segmentation0 = do_segmentation;
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200649
650 /* speculatively enqueue b0 to the current next frame */
651 to_next[0] = bi0 = from[0];
652 to_next += 1;
653 n_left_to_next -= 1;
654 from += 1;
655 n_left_from -= 1;
656
657 if (b[0]->flags & VLIB_BUFFER_IS_TRACED)
658 {
659 t0 = vlib_add_trace (vm, node, b[0], sizeof (t0[0]));
660 t0->flags = b[0]->flags & VNET_BUFFER_F_GSO;
661 t0->gso_size = vnet_buffer2 (b[0])->gso_size;
662 t0->gso_l4_hdr_sz = vnet_buffer2 (b[0])->gso_l4_hdr_sz;
Vladislav Grishenko62fc7872021-11-20 14:52:53 +0500663 clib_memset (&t0->gho, 0, sizeof (t0->gho));
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200664 vnet_generic_header_offset_parser (b[0], &t0->gho, is_l2,
665 is_ip4, is_ip6);
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200666 }
667
Mohsin Kazmi70ae4ef2019-12-09 11:46:01 +0100668 if (do_segmentation0)
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200669 {
670 if (PREDICT_FALSE (b[0]->flags & VNET_BUFFER_F_GSO))
671 {
672 /*
673 * Undo the enqueue of the b0 - it is not going anywhere,
674 * and will be freed either after it's segmented or
675 * when dropped, if there is no buffers to segment into.
676 */
677 to_next -= 1;
678 n_left_to_next += 1;
679 /* undo the counting. */
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200680 u32 n_tx_bytes = 0;
681
Mohsin Kazmi7b3339e2022-09-29 15:28:04 +0000682 n_tx_bytes =
683 gso_segment_buffer_inline (vm, ptd, b[0], is_l2);
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200684
685 if (PREDICT_FALSE (n_tx_bytes == 0))
686 {
687 drop_one_buffer_and_count (vm, vnm, node, from - 1,
688 hi->sw_if_index,
Mohsin Kazmi79e087f2021-05-27 21:05:41 +0200689 GSO_ERROR_NO_BUFFERS);
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200690 b += 1;
691 continue;
692 }
693
Mohsin Kazmi7b3339e2022-09-29 15:28:04 +0000694 if (PREDICT_FALSE (vnet_buffer (b[0])->oflags &
695 VNET_BUFFER_OFFLOAD_F_TNL_VXLAN))
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000696 {
Mohsin Kazmi7b3339e2022-09-29 15:28:04 +0000697 tso_segment_vxlan_tunnel_fixup (vm, ptd, b[0]);
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000698 }
Mohsin Kazmi7b3339e2022-09-29 15:28:04 +0000699 else if (PREDICT_FALSE (vnet_buffer (b[0])->oflags &
700 VNET_BUFFER_OFFLOAD_F_TNL_IPIP))
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200701 {
Mohsin Kazmi7b3339e2022-09-29 15:28:04 +0000702 tso_segment_ipip_tunnel_fixup (vm, ptd, b[0]);
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200703 }
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000704
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200705 u16 n_tx_bufs = vec_len (ptd->split_buffers);
706 u32 *from_seg = ptd->split_buffers;
707
708 while (n_tx_bufs > 0)
709 {
710 u32 sbi0;
711 vlib_buffer_t *sb0;
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200712 while (n_tx_bufs > 0 && n_left_to_next > 0)
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200713 {
714 sbi0 = to_next[0] = from_seg[0];
715 sb0 = vlib_get_buffer (vm, sbi0);
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000716 ASSERT (sb0->current_length > 0);
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200717 to_next += 1;
718 from_seg += 1;
719 n_left_to_next -= 1;
720 n_tx_bufs -= 1;
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200721 next0 = 0;
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200722 vnet_feature_next (&next0, sb0);
723 vlib_validate_buffer_enqueue_x1 (vm, node,
724 next_index,
725 to_next,
726 n_left_to_next,
727 sbi0, next0);
728 }
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200729 vlib_put_next_frame (vm, node, next_index,
730 n_left_to_next);
731 if (n_tx_bufs > 0)
732 vlib_get_next_frame (vm, node, next_index,
733 to_next, n_left_to_next);
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200734 }
735 /* The buffers were enqueued. Reset the length */
Damjan Marion8bea5892022-04-04 22:40:45 +0200736 vec_set_len (ptd->split_buffers, 0);
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200737 /* Free the now segmented buffer */
738 vlib_buffer_free_one (vm, bi0);
739 b += 1;
740 continue;
741 }
742 }
743
744 vnet_feature_next (&next0, b[0]);
745 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
746 n_left_to_next, bi0, next0);
747 b += 1;
748 }
749 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
750 }
751
752 return frame->n_vectors;
753}
754
755static_always_inline uword
756vnet_gso_inline (vlib_main_t * vm,
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200757 vlib_node_runtime_t * node, vlib_frame_t * frame, int is_l2,
758 int is_ip4, int is_ip6)
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200759{
760 vnet_main_t *vnm = vnet_get_main ();
761 vnet_hw_interface_t *hi;
762
763 if (frame->n_vectors > 0)
764 {
765 u32 *from = vlib_frame_vector_args (frame);
766 vlib_buffer_t *b = vlib_get_buffer (vm, from[0]);
767 hi = vnet_get_sup_hw_interface (vnm,
768 vnet_buffer (b)->sw_if_index[VLIB_TX]);
Mohsin Kazmi70ae4ef2019-12-09 11:46:01 +0100769
Damjan Mariond4f88cc2022-01-05 01:52:38 +0100770 if (hi->caps & (VNET_HW_IF_CAP_TCP_GSO | VNET_HW_IF_CAP_VXLAN_TNL_GSO))
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200771 return vnet_gso_node_inline (vm, node, frame, vnm, hi,
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200772 is_l2, is_ip4, is_ip6,
773 /* do_segmentation */ 0);
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200774 else
775 return vnet_gso_node_inline (vm, node, frame, vnm, hi,
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200776 is_l2, is_ip4, is_ip6,
777 /* do_segmentation */ 1);
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200778 }
779 return 0;
780}
781
782VLIB_NODE_FN (gso_l2_ip4_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
783 vlib_frame_t * frame)
784{
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200785 return vnet_gso_inline (vm, node, frame, 1 /* l2 */ , 1 /* ip4 */ ,
786 0 /* ip6 */ );
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200787}
788
789VLIB_NODE_FN (gso_l2_ip6_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
790 vlib_frame_t * frame)
791{
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200792 return vnet_gso_inline (vm, node, frame, 1 /* l2 */ , 0 /* ip4 */ ,
793 1 /* ip6 */ );
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200794}
795
796VLIB_NODE_FN (gso_ip4_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
797 vlib_frame_t * frame)
798{
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200799 return vnet_gso_inline (vm, node, frame, 0 /* l2 */ , 1 /* ip4 */ ,
800 0 /* ip6 */ );
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200801}
802
803VLIB_NODE_FN (gso_ip6_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
804 vlib_frame_t * frame)
805{
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200806 return vnet_gso_inline (vm, node, frame, 0 /* l2 */ , 0 /* ip4 */ ,
807 1 /* ip6 */ );
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200808}
809
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200810
811VLIB_REGISTER_NODE (gso_l2_ip4_node) = {
812 .vector_size = sizeof (u32),
813 .format_trace = format_gso_trace,
814 .type = VLIB_NODE_TYPE_INTERNAL,
Mohsin Kazmi79e087f2021-05-27 21:05:41 +0200815 .n_errors = ARRAY_LEN(gso_error_strings),
816 .error_strings = gso_error_strings,
817 .n_next_nodes = GSO_N_NEXT,
818 .next_nodes = {
819 [GSO_NEXT_DROP] = "error-drop",
820 },
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200821 .name = "gso-l2-ip4",
822};
823
824VLIB_REGISTER_NODE (gso_l2_ip6_node) = {
825 .vector_size = sizeof (u32),
826 .format_trace = format_gso_trace,
827 .type = VLIB_NODE_TYPE_INTERNAL,
Mohsin Kazmi79e087f2021-05-27 21:05:41 +0200828 .n_errors = ARRAY_LEN(gso_error_strings),
829 .error_strings = gso_error_strings,
830 .n_next_nodes = GSO_N_NEXT,
831 .next_nodes = {
832 [GSO_NEXT_DROP] = "error-drop",
833 },
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200834 .name = "gso-l2-ip6",
835};
836
837VLIB_REGISTER_NODE (gso_ip4_node) = {
838 .vector_size = sizeof (u32),
839 .format_trace = format_gso_trace,
840 .type = VLIB_NODE_TYPE_INTERNAL,
Mohsin Kazmi79e087f2021-05-27 21:05:41 +0200841 .n_errors = ARRAY_LEN(gso_error_strings),
842 .error_strings = gso_error_strings,
843 .n_next_nodes = GSO_N_NEXT,
844 .next_nodes = {
845 [GSO_NEXT_DROP] = "error-drop",
846 },
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200847 .name = "gso-ip4",
848};
849
850VLIB_REGISTER_NODE (gso_ip6_node) = {
851 .vector_size = sizeof (u32),
852 .format_trace = format_gso_trace,
853 .type = VLIB_NODE_TYPE_INTERNAL,
Mohsin Kazmi79e087f2021-05-27 21:05:41 +0200854 .n_errors = ARRAY_LEN(gso_error_strings),
855 .error_strings = gso_error_strings,
856 .n_next_nodes = GSO_N_NEXT,
857 .next_nodes = {
858 [GSO_NEXT_DROP] = "error-drop",
859 },
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200860 .name = "gso-ip6",
861};
862
863VNET_FEATURE_INIT (gso_l2_ip4_node, static) = {
864 .arc_name = "l2-output-ip4",
865 .node_name = "gso-l2-ip4",
866 .runs_before = VNET_FEATURES ("l2-output-feat-arc-end"),
867};
868
869VNET_FEATURE_INIT (gso_l2_ip6_node, static) = {
870 .arc_name = "l2-output-ip6",
871 .node_name = "gso-l2-ip6",
872 .runs_before = VNET_FEATURES ("l2-output-feat-arc-end"),
873};
874
875VNET_FEATURE_INIT (gso_ip4_node, static) = {
876 .arc_name = "ip4-output",
877 .node_name = "gso-ip4",
Neale Ranns83d12982020-05-11 15:24:39 +0000878 .runs_before = VNET_FEATURES ("ipsec4-output-feature"),
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200879};
880
881VNET_FEATURE_INIT (gso_ip6_node, static) = {
882 .arc_name = "ip6-output",
883 .node_name = "gso-ip6",
Neale Ranns83d12982020-05-11 15:24:39 +0000884 .runs_before = VNET_FEATURES ("ipsec6-output-feature"),
Mohsin Kazmi29467b52019-10-08 19:42:38 +0200885};
886
887/*
888 * fd.io coding-style-patch-verification: ON
889 *
890 * Local Variables:
891 * eval: (c-set-style "gnu")
892 * End:
893 */