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 | 7b3339e | 2022-09-29 15:28:04 +0000 | [diff] [blame] | 83 | static_always_inline void |
| 84 | tso_segment_ipip_tunnel_fixup (vlib_main_t *vm, |
| 85 | vnet_interface_per_thread_data_t *ptd, |
| 86 | vlib_buffer_t *sb0) |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 87 | { |
| 88 | u16 n_tx_bufs = vec_len (ptd->split_buffers); |
Mohsin Kazmi | 7b3339e | 2022-09-29 15:28:04 +0000 | [diff] [blame] | 89 | u16 i = 0; |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 90 | |
| 91 | while (i < n_tx_bufs) |
| 92 | { |
| 93 | vlib_buffer_t *b0 = vlib_get_buffer (vm, ptd->split_buffers[i]); |
Mohsin Kazmi | 7b3339e | 2022-09-29 15:28:04 +0000 | [diff] [blame] | 94 | i16 outer_l3_hdr_offset = vnet_buffer2 (b0)->outer_l3_hdr_offset; |
| 95 | i16 l3_hdr_offset = vnet_buffer (b0)->l3_hdr_offset; |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 96 | |
Mohsin Kazmi | 7b3339e | 2022-09-29 15:28:04 +0000 | [diff] [blame] | 97 | 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 Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 99 | |
Mohsin Kazmi | 7b3339e | 2022-09-29 15:28:04 +0000 | [diff] [blame] | 100 | if (vnet_buffer (b0)->oflags & VNET_BUFFER_OFFLOAD_F_OUTER_IP_CKSUM) |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 101 | { |
Mohsin Kazmi | 7b3339e | 2022-09-29 15:28:04 +0000 | [diff] [blame] | 102 | ip4->length = clib_host_to_net_u16 ( |
| 103 | b0->current_length - (outer_l3_hdr_offset - b0->current_data)); |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 104 | ip4->checksum = ip4_header_checksum (ip4); |
Mohsin Kazmi | 7b3339e | 2022-09-29 15:28:04 +0000 | [diff] [blame] | 105 | vnet_buffer_offload_flags_clear ( |
| 106 | b0, VNET_BUFFER_OFFLOAD_F_OUTER_IP_CKSUM | |
| 107 | VNET_BUFFER_OFFLOAD_F_TNL_IPIP); |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 108 | } |
Mohsin Kazmi | 7b3339e | 2022-09-29 15:28:04 +0000 | [diff] [blame] | 109 | else |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 110 | { |
Mohsin Kazmi | 7b3339e | 2022-09-29 15:28:04 +0000 | [diff] [blame] | 111 | 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 Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 114 | } |
| 115 | |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 116 | i++; |
| 117 | } |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 118 | } |
| 119 | |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 120 | static_always_inline void |
Mohsin Kazmi | 7b3339e | 2022-09-29 15:28:04 +0000 | [diff] [blame] | 121 | tso_segment_vxlan_tunnel_headers_fixup (vlib_main_t *vm, vlib_buffer_t *b) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 122 | { |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 123 | ip4_header_t *ip4 = 0; |
| 124 | ip6_header_t *ip6 = 0; |
| 125 | udp_header_t *udp = 0; |
Mohsin Kazmi | 7b3339e | 2022-09-29 15:28:04 +0000 | [diff] [blame] | 126 | 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 Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 128 | |
Mohsin Kazmi | 7b3339e | 2022-09-29 15:28:04 +0000 | [diff] [blame] | 129 | 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 Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 132 | |
Mohsin Kazmi | 7b3339e | 2022-09-29 15:28:04 +0000 | [diff] [blame] | 133 | if (vnet_buffer (b)->oflags & VNET_BUFFER_OFFLOAD_F_OUTER_IP_CKSUM) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 134 | { |
Mohsin Kazmi | 7b3339e | 2022-09-29 15:28:04 +0000 | [diff] [blame] | 135 | ip4->length = clib_host_to_net_u16 ( |
| 136 | b->current_length - (outer_l3_hdr_offset - b->current_data)); |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 137 | ip4->checksum = ip4_header_checksum (ip4); |
Mohsin Kazmi | 7b3339e | 2022-09-29 15:28:04 +0000 | [diff] [blame] | 138 | if (vnet_buffer (b)->oflags & VNET_BUFFER_OFFLOAD_F_OUTER_UDP_CKSUM) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 139 | { |
Mohsin Kazmi | 7b3339e | 2022-09-29 15:28:04 +0000 | [diff] [blame] | 140 | 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 Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 161 | udp->checksum = |
| 162 | ip6_tcp_udp_icmp_compute_checksum (vm, b, ip6, &bogus); |
Mohsin Kazmi | 7b3339e | 2022-09-29 15:28:04 +0000 | [diff] [blame] | 163 | vnet_buffer_offload_flags_clear ( |
| 164 | b, VNET_BUFFER_OFFLOAD_F_OUTER_UDP_CKSUM | |
| 165 | VNET_BUFFER_OFFLOAD_F_TNL_VXLAN); |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 166 | } |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 167 | } |
| 168 | } |
| 169 | |
Mohsin Kazmi | 7b3339e | 2022-09-29 15:28:04 +0000 | [diff] [blame] | 170 | static_always_inline void |
| 171 | tso_segment_vxlan_tunnel_fixup (vlib_main_t *vm, |
| 172 | vnet_interface_per_thread_data_t *ptd, |
| 173 | vlib_buffer_t *sb0) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 174 | { |
| 175 | u16 n_tx_bufs = vec_len (ptd->split_buffers); |
Mohsin Kazmi | 7b3339e | 2022-09-29 15:28:04 +0000 | [diff] [blame] | 176 | u16 i = 0; |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 177 | |
| 178 | while (i < n_tx_bufs) |
| 179 | { |
| 180 | vlib_buffer_t *b0 = vlib_get_buffer (vm, ptd->split_buffers[i]); |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 181 | |
Mohsin Kazmi | 7b3339e | 2022-09-29 15:28:04 +0000 | [diff] [blame] | 182 | tso_segment_vxlan_tunnel_headers_fixup (vm, b0); |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 183 | i++; |
| 184 | } |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 185 | } |
| 186 | |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 187 | static_always_inline u16 |
| 188 | tso_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 Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 191 | u16 gso_size, u16 first_data_size, |
| 192 | generic_header_offset_t * gho) |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 193 | { |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 194 | 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 Kazmi | 222b709 | 2019-12-25 00:12:52 +0100 | [diff] [blame] | 204 | clib_min (gso_size, vlib_buffer_get_default_data_size (vm) - l234_sz |
| 205 | - gho->l2_hdr_offset); |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 206 | |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 207 | /* |
| 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 Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 214 | |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 215 | /* |
| 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 Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 222 | 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 | |
| 233 | static_always_inline void |
| 234 | tso_init_buf_from_template_base (vlib_buffer_t * nb0, vlib_buffer_t * b0, |
| 235 | u32 flags, u16 length) |
| 236 | { |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 237 | /* copying objects from cacheline 0 */ |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 238 | nb0->current_data = b0->current_data; |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 239 | nb0->current_length = length; |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 240 | nb0->flags = VLIB_BUFFER_TOTAL_LENGTH_VALID | flags; |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 241 | nb0->flow_id = b0->flow_id; |
| 242 | nb0->error = b0->error; |
| 243 | nb0->current_config_index = b0->current_config_index; |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 244 | clib_memcpy_fast (&nb0->opaque, &b0->opaque, sizeof (nb0->opaque)); |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 245 | |
| 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 Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 251 | clib_memcpy_fast (vlib_buffer_get_current (nb0), |
| 252 | vlib_buffer_get_current (b0), length); |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | static_always_inline void |
| 256 | tso_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 Kazmi | 72e7312 | 2019-10-22 13:33:13 +0200 | [diff] [blame] | 259 | u32 next_tcp_seq, u32 flags, |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 260 | generic_header_offset_t * gho) |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 261 | { |
| 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 Kazmi | 72e7312 | 2019-10-22 13:33:13 +0200 | [diff] [blame] | 271 | (tcp_header_t *) (vlib_buffer_get_current (nb0) + gho->l4_hdr_offset); |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 272 | tcp->seq_number = clib_host_to_net_u32 (next_tcp_seq); |
| 273 | } |
| 274 | |
| 275 | static_always_inline void |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 276 | 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] | 277 | int is_l2, int is_ip6, generic_header_offset_t * gho) |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 278 | { |
Mohsin Kazmi | 72e7312 | 2019-10-22 13:33:13 +0200 | [diff] [blame] | 279 | 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 Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 285 | |
| 286 | tcp->flags = tcp_flags; |
| 287 | |
| 288 | if (is_ip6) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 289 | { |
| 290 | ip6->payload_length = |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 291 | clib_host_to_net_u16 (b0->current_length - gho->l4_hdr_offset); |
| 292 | if (gho->gho_flags & GHO_F_TCP) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 293 | { |
| 294 | int bogus = 0; |
| 295 | tcp->checksum = 0; |
| 296 | tcp->checksum = |
| 297 | ip6_tcp_udp_icmp_compute_checksum (vm, b0, ip6, &bogus); |
Mohsin Kazmi | 6809538 | 2021-02-10 11:26:24 +0100 | [diff] [blame] | 298 | vnet_buffer_offload_flags_clear (b0, |
| 299 | VNET_BUFFER_OFFLOAD_F_TCP_CKSUM); |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 300 | } |
| 301 | } |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 302 | else |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 303 | { |
| 304 | ip4->length = |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 305 | 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 Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 309 | { |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 310 | tcp->checksum = 0; |
| 311 | tcp->checksum = ip4_tcp_udp_compute_checksum (vm, b0, ip4); |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 312 | } |
Mohsin Kazmi | 6809538 | 2021-02-10 11:26:24 +0100 | [diff] [blame] | 313 | vnet_buffer_offload_flags_clear (b0, (VNET_BUFFER_OFFLOAD_F_IP_CKSUM | |
| 314 | VNET_BUFFER_OFFLOAD_F_TCP_CKSUM)); |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 315 | } |
| 316 | |
Mohsin Kazmi | ec1d61e | 2020-06-24 16:20:54 +0200 | [diff] [blame] | 317 | if (!is_l2 && ((gho->gho_flags & GHO_F_TUNNEL) == 0)) |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 318 | { |
| 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 Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 328 | } |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 329 | } |
| 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 | |
| 340 | static_always_inline u32 |
| 341 | 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] | 342 | u32 sbi0, vlib_buffer_t * sb0, |
Mohsin Kazmi | ec1d61e | 2020-06-24 16:20:54 +0200 | [diff] [blame] | 343 | generic_header_offset_t * gho, u32 n_bytes_b0, int is_l2, |
| 344 | int is_ip6) |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 345 | { |
| 346 | u32 n_tx_bytes = 0; |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 347 | u16 gso_size = vnet_buffer2 (sb0)->gso_size; |
| 348 | |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 349 | 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 Kazmi | 72e7312 | 2019-10-22 13:33:13 +0200 | [diff] [blame] | 354 | (tcp_header_t *) (vlib_buffer_get_current (sb0) + gho->l4_hdr_offset); |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 355 | 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 Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 363 | u16 l234_sz = gho->hdr_sz; |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 364 | 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 Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 368 | (!tso_alloc_tx_bufs |
| 369 | (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] | 370 | 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 Kazmi | ec1d61e | 2020-06-24 16:20:54 +0200 | [diff] [blame] | 392 | tso_fixup_segmented_buf (vm, b0, tcp_flags_no_fin_psh, is_l2, is_ip6, |
| 393 | gho); |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 394 | |
| 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 Kazmi | 72e7312 | 2019-10-22 13:33:13 +0200 | [diff] [blame] | 399 | &dst_left, next_tcp_seq, default_bflags, |
| 400 | gho); |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 401 | |
| 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 Kazmi | ec1d61e | 2020-06-24 16:20:54 +0200 | [diff] [blame] | 442 | tso_fixup_segmented_buf (vm, cdb0, tcp_flags_no_fin_psh, is_l2, |
| 443 | is_ip6, gho); |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 444 | 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 Kazmi | 72e7312 | 2019-10-22 13:33:13 +0200 | [diff] [blame] | 448 | next_tcp_seq, default_bflags, gho); |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 449 | } |
| 450 | } |
| 451 | |
Mohsin Kazmi | ec1d61e | 2020-06-24 16:20:54 +0200 | [diff] [blame] | 452 | 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] | 453 | |
| 454 | n_tx_bytes += cdb0->current_length; |
| 455 | } |
| 456 | n_tx_bytes += b0->current_length; |
| 457 | return n_tx_bytes; |
| 458 | } |
| 459 | |
Mohsin Kazmi | d9e7ac3 | 2021-10-15 22:45:51 +0000 | [diff] [blame] | 460 | __clib_unused u32 |
| 461 | gso_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 Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 469 | static_always_inline void |
| 470 | drop_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 Kazmi | 79e087f | 2021-05-27 21:05:41 +0200 | [diff] [blame] | 484 | /* n_buffers */ 1, GSO_NEXT_DROP, node->node_index, |
| 485 | drop_error_code); |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | static_always_inline uword |
| 489 | vnet_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 Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 494 | int is_l2, int is_ip4, int is_ip6, int do_segmentation) |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 495 | { |
| 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 Kazmi | 70ae4ef | 2019-12-09 11:46:01 +0100 | [diff] [blame] | 515 | 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 Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 523 | |
Mohsin Kazmi | 70ae4ef | 2019-12-09 11:46:01 +0100 | [diff] [blame] | 524 | /* 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 Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 529 | |
Mohsin Kazmi | 70ae4ef | 2019-12-09 11:46:01 +0100 | [diff] [blame] | 530 | 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 Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 538 | |
Mohsin Kazmi | 70ae4ef | 2019-12-09 11:46:01 +0100 | [diff] [blame] | 539 | 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 Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 543 | |
Mohsin Kazmi | 70ae4ef | 2019-12-09 11:46:01 +0100 | [diff] [blame] | 544 | if (PREDICT_FALSE (hi->sw_if_index != swif0)) |
| 545 | { |
| 546 | hi0 = vnet_get_sup_hw_interface (vnm, swif0); |
Damjan Marion | d4f88cc | 2022-01-05 01:52:38 +0100 | [diff] [blame] | 547 | if ((hi0->caps & VNET_HW_IF_CAP_TCP_GSO) == 0 && |
Mohsin Kazmi | 70ae4ef | 2019-12-09 11:46:01 +0100 | [diff] [blame] | 548 | (b[0]->flags & VNET_BUFFER_F_GSO)) |
| 549 | break; |
| 550 | } |
| 551 | if (PREDICT_FALSE (hi->sw_if_index != swif1)) |
| 552 | { |
Steven Luong | a420c5e | 2020-01-16 09:57:22 -0800 | [diff] [blame] | 553 | hi1 = vnet_get_sup_hw_interface (vnm, swif1); |
Damjan Marion | d4f88cc | 2022-01-05 01:52:38 +0100 | [diff] [blame] | 554 | if (!(hi1->caps & VNET_HW_IF_CAP_TCP_GSO) && |
Mohsin Kazmi | 70ae4ef | 2019-12-09 11:46:01 +0100 | [diff] [blame] | 555 | (b[1]->flags & VNET_BUFFER_F_GSO)) |
| 556 | break; |
| 557 | } |
| 558 | if (PREDICT_FALSE (hi->sw_if_index != swif2)) |
| 559 | { |
Steven Luong | a420c5e | 2020-01-16 09:57:22 -0800 | [diff] [blame] | 560 | hi2 = vnet_get_sup_hw_interface (vnm, swif2); |
Damjan Marion | d4f88cc | 2022-01-05 01:52:38 +0100 | [diff] [blame] | 561 | if ((hi2->caps & VNET_HW_IF_CAP_TCP_GSO) == 0 && |
Mohsin Kazmi | 70ae4ef | 2019-12-09 11:46:01 +0100 | [diff] [blame] | 562 | (b[2]->flags & VNET_BUFFER_F_GSO)) |
| 563 | break; |
| 564 | } |
| 565 | if (PREDICT_FALSE (hi->sw_if_index != swif3)) |
| 566 | { |
Steven Luong | a420c5e | 2020-01-16 09:57:22 -0800 | [diff] [blame] | 567 | hi3 = vnet_get_sup_hw_interface (vnm, swif3); |
Damjan Marion | d4f88cc | 2022-01-05 01:52:38 +0100 | [diff] [blame] | 568 | if (!(hi3->caps & VNET_HW_IF_CAP_TCP_GSO) && |
Mohsin Kazmi | 70ae4ef | 2019-12-09 11:46:01 +0100 | [diff] [blame] | 569 | (b[3]->flags & VNET_BUFFER_F_GSO)) |
| 570 | break; |
| 571 | } |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 572 | |
Mohsin Kazmi | 70ae4ef | 2019-12-09 11:46:01 +0100 | [diff] [blame] | 573 | 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 Grishenko | 62fc787 | 2021-11-20 14:52:53 +0500 | [diff] [blame] | 579 | clib_memset (&t0->gho, 0, sizeof (t0->gho)); |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 580 | vnet_generic_header_offset_parser (b[0], &t0->gho, is_l2, |
| 581 | is_ip4, is_ip6); |
Mohsin Kazmi | 70ae4ef | 2019-12-09 11:46:01 +0100 | [diff] [blame] | 582 | } |
| 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 Grishenko | 62fc787 | 2021-11-20 14:52:53 +0500 | [diff] [blame] | 589 | clib_memset (&t1->gho, 0, sizeof (t1->gho)); |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 590 | vnet_generic_header_offset_parser (b[1], &t1->gho, is_l2, |
| 591 | is_ip4, is_ip6); |
Mohsin Kazmi | 70ae4ef | 2019-12-09 11:46:01 +0100 | [diff] [blame] | 592 | } |
| 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 Grishenko | 62fc787 | 2021-11-20 14:52:53 +0500 | [diff] [blame] | 599 | clib_memset (&t2->gho, 0, sizeof (t2->gho)); |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 600 | vnet_generic_header_offset_parser (b[2], &t2->gho, is_l2, |
| 601 | is_ip4, is_ip6); |
Mohsin Kazmi | 70ae4ef | 2019-12-09 11:46:01 +0100 | [diff] [blame] | 602 | } |
| 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 Grishenko | 62fc787 | 2021-11-20 14:52:53 +0500 | [diff] [blame] | 609 | clib_memset (&t3->gho, 0, sizeof (t3->gho)); |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 610 | vnet_generic_header_offset_parser (b[3], &t3->gho, is_l2, |
| 611 | is_ip4, is_ip6); |
Mohsin Kazmi | 70ae4ef | 2019-12-09 11:46:01 +0100 | [diff] [blame] | 612 | } |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 613 | |
Mohsin Kazmi | 70ae4ef | 2019-12-09 11:46:01 +0100 | [diff] [blame] | 614 | from += 4; |
| 615 | to_next += 4; |
| 616 | n_left_to_next -= 4; |
| 617 | n_left_from -= 4; |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 618 | |
Mohsin Kazmi | 70ae4ef | 2019-12-09 11:46:01 +0100 | [diff] [blame] | 619 | 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 Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 630 | |
| 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 Kazmi | 70ae4ef | 2019-12-09 11:46:01 +0100 | [diff] [blame] | 637 | u32 do_segmentation0 = 0; |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 638 | |
| 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 Marion | d4f88cc | 2022-01-05 01:52:38 +0100 | [diff] [blame] | 643 | if ((hi0->caps & VNET_HW_IF_CAP_TCP_GSO) == 0 && |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 644 | (b[0]->flags & VNET_BUFFER_F_GSO)) |
Mohsin Kazmi | 70ae4ef | 2019-12-09 11:46:01 +0100 | [diff] [blame] | 645 | do_segmentation0 = 1; |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 646 | } |
Mohsin Kazmi | 70ae4ef | 2019-12-09 11:46:01 +0100 | [diff] [blame] | 647 | else |
| 648 | do_segmentation0 = do_segmentation; |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 649 | |
| 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 Grishenko | 62fc787 | 2021-11-20 14:52:53 +0500 | [diff] [blame] | 663 | clib_memset (&t0->gho, 0, sizeof (t0->gho)); |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 664 | vnet_generic_header_offset_parser (b[0], &t0->gho, is_l2, |
| 665 | is_ip4, is_ip6); |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 666 | } |
| 667 | |
Mohsin Kazmi | 70ae4ef | 2019-12-09 11:46:01 +0100 | [diff] [blame] | 668 | if (do_segmentation0) |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 669 | { |
| 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 Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 680 | u32 n_tx_bytes = 0; |
| 681 | |
Mohsin Kazmi | 7b3339e | 2022-09-29 15:28:04 +0000 | [diff] [blame] | 682 | n_tx_bytes = |
| 683 | gso_segment_buffer_inline (vm, ptd, b[0], is_l2); |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 684 | |
| 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 Kazmi | 79e087f | 2021-05-27 21:05:41 +0200 | [diff] [blame] | 689 | GSO_ERROR_NO_BUFFERS); |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 690 | b += 1; |
| 691 | continue; |
| 692 | } |
| 693 | |
Mohsin Kazmi | 7b3339e | 2022-09-29 15:28:04 +0000 | [diff] [blame] | 694 | if (PREDICT_FALSE (vnet_buffer (b[0])->oflags & |
| 695 | VNET_BUFFER_OFFLOAD_F_TNL_VXLAN)) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 696 | { |
Mohsin Kazmi | 7b3339e | 2022-09-29 15:28:04 +0000 | [diff] [blame] | 697 | tso_segment_vxlan_tunnel_fixup (vm, ptd, b[0]); |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 698 | } |
Mohsin Kazmi | 7b3339e | 2022-09-29 15:28:04 +0000 | [diff] [blame] | 699 | else if (PREDICT_FALSE (vnet_buffer (b[0])->oflags & |
| 700 | VNET_BUFFER_OFFLOAD_F_TNL_IPIP)) |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 701 | { |
Mohsin Kazmi | 7b3339e | 2022-09-29 15:28:04 +0000 | [diff] [blame] | 702 | tso_segment_ipip_tunnel_fixup (vm, ptd, b[0]); |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 703 | } |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 704 | |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 705 | 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 Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 712 | while (n_tx_bufs > 0 && n_left_to_next > 0) |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 713 | { |
| 714 | sbi0 = to_next[0] = from_seg[0]; |
| 715 | sb0 = vlib_get_buffer (vm, sbi0); |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 716 | ASSERT (sb0->current_length > 0); |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 717 | to_next += 1; |
| 718 | from_seg += 1; |
| 719 | n_left_to_next -= 1; |
| 720 | n_tx_bufs -= 1; |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 721 | next0 = 0; |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 722 | 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 Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 729 | 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 Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 734 | } |
| 735 | /* The buffers were enqueued. Reset the length */ |
Damjan Marion | 8bea589 | 2022-04-04 22:40:45 +0200 | [diff] [blame] | 736 | vec_set_len (ptd->split_buffers, 0); |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 737 | /* 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 | |
| 755 | static_always_inline uword |
| 756 | vnet_gso_inline (vlib_main_t * vm, |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 757 | vlib_node_runtime_t * node, vlib_frame_t * frame, int is_l2, |
| 758 | int is_ip4, int is_ip6) |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 759 | { |
| 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 Kazmi | 70ae4ef | 2019-12-09 11:46:01 +0100 | [diff] [blame] | 769 | |
Damjan Marion | d4f88cc | 2022-01-05 01:52:38 +0100 | [diff] [blame] | 770 | if (hi->caps & (VNET_HW_IF_CAP_TCP_GSO | VNET_HW_IF_CAP_VXLAN_TNL_GSO)) |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 771 | return vnet_gso_node_inline (vm, node, frame, vnm, hi, |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 772 | is_l2, is_ip4, is_ip6, |
| 773 | /* do_segmentation */ 0); |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 774 | else |
| 775 | return vnet_gso_node_inline (vm, node, frame, vnm, hi, |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 776 | is_l2, is_ip4, is_ip6, |
| 777 | /* do_segmentation */ 1); |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 778 | } |
| 779 | return 0; |
| 780 | } |
| 781 | |
| 782 | VLIB_NODE_FN (gso_l2_ip4_node) (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 783 | vlib_frame_t * frame) |
| 784 | { |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 785 | return vnet_gso_inline (vm, node, frame, 1 /* l2 */ , 1 /* ip4 */ , |
| 786 | 0 /* ip6 */ ); |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 787 | } |
| 788 | |
| 789 | VLIB_NODE_FN (gso_l2_ip6_node) (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 790 | vlib_frame_t * frame) |
| 791 | { |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 792 | return vnet_gso_inline (vm, node, frame, 1 /* l2 */ , 0 /* ip4 */ , |
| 793 | 1 /* ip6 */ ); |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 794 | } |
| 795 | |
| 796 | VLIB_NODE_FN (gso_ip4_node) (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 797 | vlib_frame_t * frame) |
| 798 | { |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 799 | return vnet_gso_inline (vm, node, frame, 0 /* l2 */ , 1 /* ip4 */ , |
| 800 | 0 /* ip6 */ ); |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 801 | } |
| 802 | |
| 803 | VLIB_NODE_FN (gso_ip6_node) (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 804 | vlib_frame_t * frame) |
| 805 | { |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 806 | return vnet_gso_inline (vm, node, frame, 0 /* l2 */ , 0 /* ip4 */ , |
| 807 | 1 /* ip6 */ ); |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 808 | } |
| 809 | |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 810 | |
| 811 | VLIB_REGISTER_NODE (gso_l2_ip4_node) = { |
| 812 | .vector_size = sizeof (u32), |
| 813 | .format_trace = format_gso_trace, |
| 814 | .type = VLIB_NODE_TYPE_INTERNAL, |
Mohsin Kazmi | 79e087f | 2021-05-27 21:05:41 +0200 | [diff] [blame] | 815 | .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 Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 821 | .name = "gso-l2-ip4", |
| 822 | }; |
| 823 | |
| 824 | VLIB_REGISTER_NODE (gso_l2_ip6_node) = { |
| 825 | .vector_size = sizeof (u32), |
| 826 | .format_trace = format_gso_trace, |
| 827 | .type = VLIB_NODE_TYPE_INTERNAL, |
Mohsin Kazmi | 79e087f | 2021-05-27 21:05:41 +0200 | [diff] [blame] | 828 | .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 Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 834 | .name = "gso-l2-ip6", |
| 835 | }; |
| 836 | |
| 837 | VLIB_REGISTER_NODE (gso_ip4_node) = { |
| 838 | .vector_size = sizeof (u32), |
| 839 | .format_trace = format_gso_trace, |
| 840 | .type = VLIB_NODE_TYPE_INTERNAL, |
Mohsin Kazmi | 79e087f | 2021-05-27 21:05:41 +0200 | [diff] [blame] | 841 | .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 Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 847 | .name = "gso-ip4", |
| 848 | }; |
| 849 | |
| 850 | VLIB_REGISTER_NODE (gso_ip6_node) = { |
| 851 | .vector_size = sizeof (u32), |
| 852 | .format_trace = format_gso_trace, |
| 853 | .type = VLIB_NODE_TYPE_INTERNAL, |
Mohsin Kazmi | 79e087f | 2021-05-27 21:05:41 +0200 | [diff] [blame] | 854 | .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 Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 860 | .name = "gso-ip6", |
| 861 | }; |
| 862 | |
| 863 | VNET_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 | |
| 869 | VNET_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 | |
| 875 | VNET_FEATURE_INIT (gso_ip4_node, static) = { |
| 876 | .arc_name = "ip4-output", |
| 877 | .node_name = "gso-ip4", |
Neale Ranns | 83d1298 | 2020-05-11 15:24:39 +0000 | [diff] [blame] | 878 | .runs_before = VNET_FEATURES ("ipsec4-output-feature"), |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 879 | }; |
| 880 | |
| 881 | VNET_FEATURE_INIT (gso_ip6_node, static) = { |
| 882 | .arc_name = "ip6-output", |
| 883 | .node_name = "gso-ip6", |
Neale Ranns | 83d1298 | 2020-05-11 15:24:39 +0000 | [diff] [blame] | 884 | .runs_before = VNET_FEATURES ("ipsec6-output-feature"), |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 885 | }; |
| 886 | |
| 887 | /* |
| 888 | * fd.io coding-style-patch-verification: ON |
| 889 | * |
| 890 | * Local Variables: |
| 891 | * eval: (c-set-style "gnu") |
| 892 | * End: |
| 893 | */ |