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