Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 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 | * interface_output.c: interface output node |
| 17 | * |
| 18 | * Copyright (c) 2008 Eliot Dresselhaus |
| 19 | * |
| 20 | * Permission is hereby granted, free of charge, to any person obtaining |
| 21 | * a copy of this software and associated documentation files (the |
| 22 | * "Software"), to deal in the Software without restriction, including |
| 23 | * without limitation the rights to use, copy, modify, merge, publish, |
| 24 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 25 | * permit persons to whom the Software is furnished to do so, subject to |
| 26 | * the following conditions: |
| 27 | * |
| 28 | * The above copyright notice and this permission notice shall be |
| 29 | * included in all copies or substantial portions of the Software. |
| 30 | * |
| 31 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 32 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 33 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 34 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
| 35 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 36 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 37 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 38 | */ |
| 39 | |
| 40 | #include <vnet/vnet.h> |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 41 | #include <vnet/ip/icmp46_packet.h> |
| 42 | #include <vnet/ip/ip4.h> |
| 43 | #include <vnet/ip/ip6.h> |
| 44 | #include <vnet/udp/udp_packet.h> |
Damjan Marion | 152e21d | 2016-11-29 14:55:43 +0100 | [diff] [blame] | 45 | #include <vnet/feature/feature.h> |
Dave Barach | 9137e54 | 2019-09-13 17:47:50 -0400 | [diff] [blame] | 46 | #include <vnet/classify/trace_classify.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 47 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 48 | typedef struct |
| 49 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 50 | u32 sw_if_index; |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 51 | u32 flags; |
| 52 | u16 gso_size; |
| 53 | u8 gso_l4_hdr_sz; |
| 54 | u8 data[128 - 3 * sizeof (u32)]; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 55 | } |
| 56 | interface_output_trace_t; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 57 | |
Filip Tehlar | 6266877 | 2019-03-04 03:33:32 -0800 | [diff] [blame] | 58 | #ifndef CLIB_MARCH_VARIANT |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 59 | u8 * |
| 60 | format_vnet_interface_output_trace (u8 * s, va_list * va) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 61 | { |
| 62 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 63 | vlib_node_t *node = va_arg (*va, vlib_node_t *); |
| 64 | interface_output_trace_t *t = va_arg (*va, interface_output_trace_t *); |
| 65 | vnet_main_t *vnm = vnet_get_main (); |
| 66 | vnet_sw_interface_t *si; |
Christophe Fontaine | d3c008d | 2017-10-02 18:10:54 +0200 | [diff] [blame] | 67 | u32 indent; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 68 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 69 | if (t->sw_if_index != (u32) ~ 0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 70 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 71 | indent = format_get_indent (s); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 72 | |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 73 | if (pool_is_free_index |
| 74 | (vnm->interface_main.sw_interfaces, t->sw_if_index)) |
| 75 | { |
| 76 | /* the interface may have been deleted by the time the trace is printed */ |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 77 | s = format (s, "sw_if_index: %d ", t->sw_if_index); |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 78 | } |
| 79 | else |
| 80 | { |
| 81 | si = vnet_get_sw_interface (vnm, t->sw_if_index); |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 82 | s = |
| 83 | format (s, "%U ", format_vnet_sw_interface_name, vnm, si, |
| 84 | t->flags); |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 85 | } |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 86 | #define _(bit, name, v, x) \ |
| 87 | if (v && (t->flags & VNET_BUFFER_F_##name)) \ |
| 88 | s = format (s, "%s ", v); |
| 89 | foreach_vnet_buffer_flag |
| 90 | #undef _ |
| 91 | if (t->flags & VNET_BUFFER_F_GSO) |
| 92 | { |
| 93 | s = format (s, "\n%Ugso_sz %d gso_l4_hdr_sz %d", |
| 94 | format_white_space, indent + 2, t->gso_size, |
| 95 | t->gso_l4_hdr_sz); |
| 96 | } |
| 97 | s = |
| 98 | format (s, "\n%U%U", format_white_space, indent, |
| 99 | node->format_buffer ? node->format_buffer : format_hex_bytes, |
| 100 | t->data, sizeof (t->data)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 101 | } |
| 102 | return s; |
| 103 | } |
| 104 | |
| 105 | static void |
| 106 | vnet_interface_output_trace (vlib_main_t * vm, |
| 107 | vlib_node_runtime_t * node, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 108 | vlib_frame_t * frame, uword n_buffers) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 109 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 110 | u32 n_left, *from; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 111 | |
| 112 | n_left = n_buffers; |
Damjan Marion | a3d5986 | 2018-11-10 10:23:00 +0100 | [diff] [blame] | 113 | from = vlib_frame_vector_args (frame); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 114 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 115 | while (n_left >= 4) |
| 116 | { |
| 117 | u32 bi0, bi1; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 118 | vlib_buffer_t *b0, *b1; |
| 119 | interface_output_trace_t *t0, *t1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 120 | |
| 121 | /* Prefetch next iteration. */ |
| 122 | vlib_prefetch_buffer_with_index (vm, from[2], LOAD); |
| 123 | vlib_prefetch_buffer_with_index (vm, from[3], LOAD); |
| 124 | |
| 125 | bi0 = from[0]; |
| 126 | bi1 = from[1]; |
| 127 | |
| 128 | b0 = vlib_get_buffer (vm, bi0); |
| 129 | b1 = vlib_get_buffer (vm, bi1); |
| 130 | |
| 131 | if (b0->flags & VLIB_BUFFER_IS_TRACED) |
| 132 | { |
| 133 | t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0])); |
| 134 | t0->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_TX]; |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 135 | t0->flags = b0->flags; |
| 136 | t0->gso_size = vnet_buffer2 (b0)->gso_size; |
| 137 | t0->gso_l4_hdr_sz = vnet_buffer2 (b0)->gso_l4_hdr_sz; |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 138 | clib_memcpy_fast (t0->data, vlib_buffer_get_current (b0), |
| 139 | sizeof (t0->data)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 140 | } |
| 141 | if (b1->flags & VLIB_BUFFER_IS_TRACED) |
| 142 | { |
| 143 | t1 = vlib_add_trace (vm, node, b1, sizeof (t1[0])); |
| 144 | t1->sw_if_index = vnet_buffer (b1)->sw_if_index[VLIB_TX]; |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 145 | t1->flags = b1->flags; |
| 146 | t1->gso_size = vnet_buffer2 (b1)->gso_size; |
| 147 | t1->gso_l4_hdr_sz = vnet_buffer2 (b1)->gso_l4_hdr_sz; |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 148 | clib_memcpy_fast (t1->data, vlib_buffer_get_current (b1), |
| 149 | sizeof (t1->data)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 150 | } |
| 151 | from += 2; |
| 152 | n_left -= 2; |
| 153 | } |
| 154 | |
| 155 | while (n_left >= 1) |
| 156 | { |
| 157 | u32 bi0; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 158 | vlib_buffer_t *b0; |
| 159 | interface_output_trace_t *t0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 160 | |
| 161 | bi0 = from[0]; |
| 162 | |
| 163 | b0 = vlib_get_buffer (vm, bi0); |
| 164 | |
| 165 | if (b0->flags & VLIB_BUFFER_IS_TRACED) |
| 166 | { |
| 167 | t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0])); |
| 168 | t0->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_TX]; |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 169 | t0->flags = b0->flags; |
| 170 | t0->gso_size = vnet_buffer2 (b0)->gso_size; |
| 171 | t0->gso_l4_hdr_sz = vnet_buffer2 (b0)->gso_l4_hdr_sz; |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 172 | clib_memcpy_fast (t0->data, vlib_buffer_get_current (b0), |
| 173 | sizeof (t0->data)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 174 | } |
| 175 | from += 1; |
| 176 | n_left -= 1; |
| 177 | } |
| 178 | } |
| 179 | |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 180 | static_always_inline void |
| 181 | calc_checksums (vlib_main_t * vm, vlib_buffer_t * b) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 182 | { |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 183 | tcp_header_t *th; |
| 184 | udp_header_t *uh; |
| 185 | |
| 186 | int is_ip4 = (b->flags & VNET_BUFFER_F_IS_IP4) != 0; |
| 187 | int is_ip6 = (b->flags & VNET_BUFFER_F_IS_IP6) != 0; |
| 188 | |
| 189 | ASSERT (!(is_ip4 && is_ip6)); |
| 190 | |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 191 | th = (tcp_header_t *) (b->data + vnet_buffer (b)->l4_hdr_offset); |
| 192 | uh = (udp_header_t *) (b->data + vnet_buffer (b)->l4_hdr_offset); |
| 193 | |
| 194 | if (is_ip4) |
| 195 | { |
Zhiyong Yang | 24c5012 | 2019-04-19 05:22:31 -0400 | [diff] [blame] | 196 | ip4_header_t *ip4; |
| 197 | |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 198 | ip4 = (ip4_header_t *) (b->data + vnet_buffer (b)->l3_hdr_offset); |
| 199 | if (b->flags & VNET_BUFFER_F_OFFLOAD_IP_CKSUM) |
| 200 | ip4->checksum = ip4_header_checksum (ip4); |
| 201 | if (b->flags & VNET_BUFFER_F_OFFLOAD_TCP_CKSUM) |
Andrej Kozemcak | 9d7570c | 2019-01-07 08:39:22 +0100 | [diff] [blame] | 202 | { |
| 203 | th->checksum = 0; |
| 204 | th->checksum = ip4_tcp_udp_compute_checksum (vm, b, ip4); |
| 205 | } |
Zhiyong Yang | 24c5012 | 2019-04-19 05:22:31 -0400 | [diff] [blame] | 206 | else if (b->flags & VNET_BUFFER_F_OFFLOAD_UDP_CKSUM) |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 207 | uh->checksum = ip4_tcp_udp_compute_checksum (vm, b, ip4); |
| 208 | } |
Zhiyong Yang | 24c5012 | 2019-04-19 05:22:31 -0400 | [diff] [blame] | 209 | else if (is_ip6) |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 210 | { |
| 211 | int bogus; |
Zhiyong Yang | 24c5012 | 2019-04-19 05:22:31 -0400 | [diff] [blame] | 212 | ip6_header_t *ip6; |
| 213 | |
| 214 | ip6 = (ip6_header_t *) (b->data + vnet_buffer (b)->l3_hdr_offset); |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 215 | if (b->flags & VNET_BUFFER_F_OFFLOAD_TCP_CKSUM) |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 216 | { |
| 217 | th->checksum = 0; |
| 218 | th->checksum = |
| 219 | ip6_tcp_udp_icmp_compute_checksum (vm, b, ip6, &bogus); |
| 220 | } |
Zhiyong Yang | 24c5012 | 2019-04-19 05:22:31 -0400 | [diff] [blame] | 221 | else if (b->flags & VNET_BUFFER_F_OFFLOAD_UDP_CKSUM) |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 222 | { |
| 223 | uh->checksum = 0; |
| 224 | uh->checksum = |
| 225 | ip6_tcp_udp_icmp_compute_checksum (vm, b, ip6, &bogus); |
| 226 | } |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 227 | } |
Florin Coras | 08f2a5d | 2019-08-06 13:48:50 -0700 | [diff] [blame] | 228 | b->flags &= ~VNET_BUFFER_F_OFFLOAD_TCP_CKSUM; |
| 229 | b->flags &= ~VNET_BUFFER_F_OFFLOAD_UDP_CKSUM; |
| 230 | b->flags &= ~VNET_BUFFER_F_OFFLOAD_IP_CKSUM; |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 231 | } |
| 232 | |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 233 | static_always_inline u16 |
| 234 | tso_alloc_tx_bufs (vlib_main_t * vm, |
| 235 | vnet_interface_per_thread_data_t * ptd, |
Mohsin Kazmi | 0a57343 | 2019-08-13 18:23:26 +0200 | [diff] [blame] | 236 | vlib_buffer_t * b0, u32 n_bytes_b0, u16 l234_sz, |
| 237 | u16 gso_size) |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 238 | { |
Mohsin Kazmi | 3f1964d | 2019-08-22 18:40:28 +0200 | [diff] [blame] | 239 | u16 size = |
| 240 | clib_min (gso_size, vlib_buffer_get_default_data_size (vm) - l234_sz); |
| 241 | |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 242 | /* rounded-up division */ |
Mohsin Kazmi | 3f1964d | 2019-08-22 18:40:28 +0200 | [diff] [blame] | 243 | u16 n_bufs = (n_bytes_b0 - l234_sz + (size - 1)) / size; |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 244 | u16 n_alloc; |
| 245 | |
| 246 | ASSERT (n_bufs > 0); |
| 247 | vec_validate (ptd->split_buffers, n_bufs - 1); |
| 248 | |
| 249 | n_alloc = vlib_buffer_alloc (vm, ptd->split_buffers, n_bufs); |
| 250 | if (n_alloc < n_bufs) |
| 251 | { |
| 252 | vlib_buffer_free (vm, ptd->split_buffers, n_alloc); |
| 253 | return 0; |
| 254 | } |
Mohsin Kazmi | 0a57343 | 2019-08-13 18:23:26 +0200 | [diff] [blame] | 255 | return n_alloc; |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | static_always_inline void |
| 259 | tso_init_buf_from_template_base (vlib_buffer_t * nb0, vlib_buffer_t * b0, |
| 260 | u32 flags, u16 length) |
| 261 | { |
Mohsin Kazmi | 0a57343 | 2019-08-13 18:23:26 +0200 | [diff] [blame] | 262 | nb0->current_data = b0->current_data; |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 263 | nb0->total_length_not_including_first_buffer = 0; |
| 264 | nb0->flags = VLIB_BUFFER_TOTAL_LENGTH_VALID | flags; |
| 265 | clib_memcpy_fast (&nb0->opaque, &b0->opaque, sizeof (nb0->opaque)); |
Mohsin Kazmi | 0a57343 | 2019-08-13 18:23:26 +0200 | [diff] [blame] | 266 | clib_memcpy_fast (vlib_buffer_get_current (nb0), |
| 267 | vlib_buffer_get_current (b0), length); |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 268 | nb0->current_length = length; |
| 269 | } |
| 270 | |
| 271 | static_always_inline void |
| 272 | tso_init_buf_from_template (vlib_main_t * vm, vlib_buffer_t * nb0, |
| 273 | vlib_buffer_t * b0, u16 template_data_sz, |
| 274 | u16 gso_size, u8 ** p_dst_ptr, u16 * p_dst_left, |
| 275 | u32 next_tcp_seq, u32 flags) |
| 276 | { |
| 277 | tso_init_buf_from_template_base (nb0, b0, flags, template_data_sz); |
| 278 | |
| 279 | *p_dst_left = |
| 280 | clib_min (gso_size, |
Mohsin Kazmi | 0a57343 | 2019-08-13 18:23:26 +0200 | [diff] [blame] | 281 | vlib_buffer_get_default_data_size (vm) - (template_data_sz + |
| 282 | nb0->current_data)); |
| 283 | *p_dst_ptr = vlib_buffer_get_current (nb0) + template_data_sz; |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 284 | |
| 285 | tcp_header_t *tcp = |
| 286 | (tcp_header_t *) (nb0->data + vnet_buffer (nb0)->l4_hdr_offset); |
| 287 | tcp->seq_number = clib_host_to_net_u32 (next_tcp_seq); |
| 288 | } |
| 289 | |
| 290 | static_always_inline void |
| 291 | tso_fixup_segmented_buf (vlib_buffer_t * b0, u8 tcp_flags, int is_ip6) |
| 292 | { |
| 293 | u16 l3_hdr_offset = vnet_buffer (b0)->l3_hdr_offset; |
| 294 | u16 l4_hdr_offset = vnet_buffer (b0)->l4_hdr_offset; |
| 295 | ip4_header_t *ip4 = (ip4_header_t *) (b0->data + l3_hdr_offset); |
| 296 | ip6_header_t *ip6 = (ip6_header_t *) (b0->data + l3_hdr_offset); |
| 297 | tcp_header_t *tcp = (tcp_header_t *) (b0->data + l4_hdr_offset); |
| 298 | |
| 299 | tcp->flags = tcp_flags; |
| 300 | |
| 301 | if (is_ip6) |
| 302 | ip6->payload_length = |
| 303 | clib_host_to_net_u16 (b0->current_length - |
Mohsin Kazmi | 0a57343 | 2019-08-13 18:23:26 +0200 | [diff] [blame] | 304 | (l4_hdr_offset - b0->current_data)); |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 305 | else |
| 306 | ip4->length = |
| 307 | clib_host_to_net_u16 (b0->current_length - |
Mohsin Kazmi | 0a57343 | 2019-08-13 18:23:26 +0200 | [diff] [blame] | 308 | (l3_hdr_offset - b0->current_data)); |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | /** |
| 312 | * Allocate the necessary number of ptd->split_buffers, |
| 313 | * and segment the possibly chained buffer(s) from b0 into |
| 314 | * there. |
| 315 | * |
| 316 | * Return the cumulative number of bytes sent or zero |
| 317 | * if allocation failed. |
| 318 | */ |
| 319 | |
| 320 | static_always_inline u32 |
| 321 | tso_segment_buffer (vlib_main_t * vm, vnet_interface_per_thread_data_t * ptd, |
| 322 | int do_tx_offloads, u32 sbi0, vlib_buffer_t * sb0, |
| 323 | u32 n_bytes_b0) |
| 324 | { |
| 325 | u32 n_tx_bytes = 0; |
| 326 | int is_ip4 = sb0->flags & VNET_BUFFER_F_IS_IP4; |
| 327 | int is_ip6 = sb0->flags & VNET_BUFFER_F_IS_IP6; |
| 328 | ASSERT (is_ip4 || is_ip6); |
| 329 | ASSERT (sb0->flags & VNET_BUFFER_F_L2_HDR_OFFSET_VALID); |
| 330 | ASSERT (sb0->flags & VNET_BUFFER_F_L3_HDR_OFFSET_VALID); |
| 331 | ASSERT (sb0->flags & VNET_BUFFER_F_L4_HDR_OFFSET_VALID); |
| 332 | u16 gso_size = vnet_buffer2 (sb0)->gso_size; |
| 333 | |
| 334 | int l4_hdr_sz = vnet_buffer2 (sb0)->gso_l4_hdr_sz; |
| 335 | u8 save_tcp_flags = 0; |
| 336 | u8 tcp_flags_no_fin_psh = 0; |
| 337 | u32 next_tcp_seq = 0; |
| 338 | |
| 339 | tcp_header_t *tcp = |
| 340 | (tcp_header_t *) (sb0->data + vnet_buffer (sb0)->l4_hdr_offset); |
| 341 | next_tcp_seq = clib_net_to_host_u32 (tcp->seq_number); |
| 342 | /* store original flags for last packet and reset FIN and PSH */ |
| 343 | save_tcp_flags = tcp->flags; |
| 344 | tcp_flags_no_fin_psh = tcp->flags & ~(TCP_FLAG_FIN | TCP_FLAG_PSH); |
| 345 | tcp->checksum = 0; |
| 346 | |
| 347 | u32 default_bflags = |
| 348 | sb0->flags & ~(VNET_BUFFER_F_GSO | VLIB_BUFFER_NEXT_PRESENT); |
Mohsin Kazmi | 0a57343 | 2019-08-13 18:23:26 +0200 | [diff] [blame] | 349 | u16 l234_sz = vnet_buffer (sb0)->l4_hdr_offset + l4_hdr_sz |
| 350 | - sb0->current_data; |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +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 | |
Mohsin Kazmi | 0a57343 | 2019-08-13 18:23:26 +0200 | [diff] [blame] | 354 | if (PREDICT_FALSE |
| 355 | (!tso_alloc_tx_bufs (vm, ptd, sb0, n_bytes_b0, l234_sz, gso_size))) |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 356 | return 0; |
| 357 | |
| 358 | vlib_buffer_t *b0 = vlib_get_buffer (vm, ptd->split_buffers[0]); |
| 359 | tso_init_buf_from_template_base (b0, sb0, default_bflags, |
Andrew Yourtchenko | 4f740c8 | 2019-06-19 12:09:51 +0000 | [diff] [blame] | 360 | l234_sz + first_data_size); |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 361 | |
| 362 | u32 total_src_left = n_bytes_b0 - l234_sz - first_data_size; |
| 363 | if (total_src_left) |
| 364 | { |
| 365 | /* Need to copy more segments */ |
| 366 | u8 *src_ptr, *dst_ptr; |
| 367 | u16 src_left, dst_left; |
| 368 | /* current source buffer */ |
| 369 | vlib_buffer_t *csb0 = sb0; |
| 370 | u32 csbi0 = sbi0; |
| 371 | /* current dest buffer */ |
| 372 | vlib_buffer_t *cdb0; |
| 373 | u16 dbi = 1; /* the buffer [0] is b0 */ |
| 374 | |
Mohsin Kazmi | 0a57343 | 2019-08-13 18:23:26 +0200 | [diff] [blame] | 375 | src_ptr = vlib_buffer_get_current (sb0) + l234_sz + first_data_size; |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 376 | src_left = sb0->current_length - l234_sz - first_data_size; |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 377 | |
| 378 | tso_fixup_segmented_buf (b0, tcp_flags_no_fin_psh, is_ip6); |
| 379 | if (do_tx_offloads) |
| 380 | calc_checksums (vm, b0); |
| 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, |
| 386 | &dst_left, next_tcp_seq, default_bflags); |
| 387 | |
| 388 | /* an arbitrary large number to catch the runaway loops */ |
| 389 | int nloops = 2000; |
| 390 | while (total_src_left) |
| 391 | { |
Dave Barach | a2aefef | 2019-02-27 12:36:28 -0500 | [diff] [blame] | 392 | if (nloops-- <= 0) |
| 393 | clib_panic ("infinite loop detected"); |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 394 | u16 bytes_to_copy = clib_min (src_left, dst_left); |
| 395 | |
| 396 | clib_memcpy_fast (dst_ptr, src_ptr, bytes_to_copy); |
| 397 | |
| 398 | src_left -= bytes_to_copy; |
| 399 | src_ptr += bytes_to_copy; |
| 400 | total_src_left -= bytes_to_copy; |
| 401 | dst_left -= bytes_to_copy; |
| 402 | dst_ptr += bytes_to_copy; |
| 403 | next_tcp_seq += bytes_to_copy; |
| 404 | cdb0->current_length += bytes_to_copy; |
| 405 | |
| 406 | if (0 == src_left) |
| 407 | { |
| 408 | int has_next = (csb0->flags & VLIB_BUFFER_NEXT_PRESENT); |
| 409 | u32 next_bi = csb0->next_buffer; |
| 410 | |
| 411 | /* init src to the next buffer in chain */ |
| 412 | if (has_next) |
| 413 | { |
| 414 | csbi0 = next_bi; |
| 415 | csb0 = vlib_get_buffer (vm, csbi0); |
| 416 | src_left = csb0->current_length; |
Andrew Yourtchenko | 4f740c8 | 2019-06-19 12:09:51 +0000 | [diff] [blame] | 417 | src_ptr = vlib_buffer_get_current (csb0); |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 418 | } |
| 419 | else |
| 420 | { |
| 421 | ASSERT (total_src_left == 0); |
| 422 | break; |
| 423 | } |
| 424 | } |
| 425 | if (0 == dst_left && total_src_left) |
| 426 | { |
| 427 | if (do_tx_offloads) |
| 428 | calc_checksums (vm, cdb0); |
| 429 | n_tx_bytes += cdb0->current_length; |
| 430 | ASSERT (dbi < vec_len (ptd->split_buffers)); |
| 431 | cdb0 = vlib_get_buffer (vm, ptd->split_buffers[dbi++]); |
| 432 | tso_init_buf_from_template (vm, cdb0, b0, l234_sz, |
| 433 | gso_size, &dst_ptr, &dst_left, |
| 434 | next_tcp_seq, default_bflags); |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | tso_fixup_segmented_buf (cdb0, save_tcp_flags, is_ip6); |
| 439 | if (do_tx_offloads) |
| 440 | calc_checksums (vm, cdb0); |
| 441 | |
| 442 | n_tx_bytes += cdb0->current_length; |
| 443 | } |
| 444 | n_tx_bytes += b0->current_length; |
| 445 | return n_tx_bytes; |
| 446 | } |
| 447 | |
| 448 | static_always_inline void |
| 449 | drop_one_buffer_and_count (vlib_main_t * vm, vnet_main_t * vnm, |
| 450 | vlib_node_runtime_t * node, u32 * pbi0, |
| 451 | u32 drop_error_code) |
| 452 | { |
| 453 | u32 thread_index = vm->thread_index; |
| 454 | vnet_interface_output_runtime_t *rt = (void *) node->runtime_data; |
| 455 | |
| 456 | vlib_simple_counter_main_t *cm; |
| 457 | cm = |
| 458 | vec_elt_at_index (vnm->interface_main.sw_if_counters, |
| 459 | VNET_INTERFACE_COUNTER_TX_ERROR); |
| 460 | vlib_increment_simple_counter (cm, thread_index, rt->sw_if_index, 1); |
| 461 | |
| 462 | vlib_error_drop_buffers (vm, node, pbi0, |
| 463 | /* buffer stride */ 1, |
| 464 | /* n_buffers */ 1, |
| 465 | VNET_INTERFACE_OUTPUT_NEXT_DROP, |
| 466 | node->node_index, drop_error_code); |
| 467 | } |
| 468 | |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 469 | static_always_inline uword |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 470 | vnet_interface_output_node_inline_gso (vlib_main_t * vm, |
| 471 | vlib_node_runtime_t * node, |
| 472 | vlib_frame_t * frame, |
| 473 | vnet_main_t * vnm, |
| 474 | vnet_hw_interface_t * hi, |
| 475 | int do_tx_offloads, |
| 476 | int do_segmentation) |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 477 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 478 | vnet_interface_output_runtime_t *rt = (void *) node->runtime_data; |
| 479 | vnet_sw_interface_t *si; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 480 | u32 n_left_to_tx, *from, *from_end, *to_tx; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 481 | u32 n_bytes, n_buffers, n_packets; |
Damjan Marion | 363640d | 2017-03-06 11:53:10 +0100 | [diff] [blame] | 482 | u32 n_bytes_b0, n_bytes_b1, n_bytes_b2, n_bytes_b3; |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 483 | u32 thread_index = vm->thread_index; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 484 | vnet_interface_main_t *im = &vnm->interface_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 485 | u32 next_index = VNET_INTERFACE_OUTPUT_NEXT_TX; |
Damjan Marion | 152e21d | 2016-11-29 14:55:43 +0100 | [diff] [blame] | 486 | u32 current_config_index = ~0; |
| 487 | u8 arc = im->output_feature_arc_index; |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 488 | vnet_interface_per_thread_data_t *ptd = |
| 489 | vec_elt_at_index (im->per_thread_data, thread_index); |
Zhiyong Yang | a462c07 | 2019-05-05 19:32:25 +0800 | [diff] [blame] | 490 | vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 491 | |
| 492 | n_buffers = frame->n_vectors; |
| 493 | |
| 494 | if (node->flags & VLIB_NODE_FLAG_TRACE) |
| 495 | vnet_interface_output_trace (vm, node, frame, n_buffers); |
| 496 | |
Damjan Marion | a3d5986 | 2018-11-10 10:23:00 +0100 | [diff] [blame] | 497 | from = vlib_frame_vector_args (frame); |
Zhiyong Yang | a462c07 | 2019-05-05 19:32:25 +0800 | [diff] [blame] | 498 | vlib_get_buffers (vm, from, b, n_buffers); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 499 | |
| 500 | if (rt->is_deleted) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 501 | return vlib_error_drop_buffers (vm, node, from, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 502 | /* buffer stride */ 1, |
| 503 | n_buffers, |
| 504 | VNET_INTERFACE_OUTPUT_NEXT_DROP, |
| 505 | node->node_index, |
| 506 | VNET_INTERFACE_OUTPUT_ERROR_INTERFACE_DELETED); |
| 507 | |
| 508 | si = vnet_get_sw_interface (vnm, rt->sw_if_index); |
| 509 | hi = vnet_get_sup_hw_interface (vnm, rt->sw_if_index); |
Steven Luong | 5ad541e | 2019-08-27 07:43:27 -0700 | [diff] [blame] | 510 | if (!(si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) || |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 511 | !(hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 512 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 513 | vlib_simple_counter_main_t *cm; |
| 514 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 515 | cm = vec_elt_at_index (vnm->interface_main.sw_if_counters, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 516 | VNET_INTERFACE_COUNTER_TX_ERROR); |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 517 | vlib_increment_simple_counter (cm, thread_index, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 518 | rt->sw_if_index, n_buffers); |
| 519 | |
| 520 | return vlib_error_drop_buffers (vm, node, from, |
| 521 | /* buffer stride */ 1, |
| 522 | n_buffers, |
| 523 | VNET_INTERFACE_OUTPUT_NEXT_DROP, |
| 524 | node->node_index, |
| 525 | VNET_INTERFACE_OUTPUT_ERROR_INTERFACE_DOWN); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | from_end = from + n_buffers; |
| 529 | |
| 530 | /* Total byte count of all buffers. */ |
| 531 | n_bytes = 0; |
| 532 | n_packets = 0; |
| 533 | |
Damjan Marion | 152e21d | 2016-11-29 14:55:43 +0100 | [diff] [blame] | 534 | /* interface-output feature arc handling */ |
| 535 | if (PREDICT_FALSE (vnet_have_features (arc, rt->sw_if_index))) |
| 536 | { |
| 537 | vnet_feature_config_main_t *fcm; |
| 538 | fcm = vnet_feature_get_config_main (arc); |
| 539 | current_config_index = vnet_get_feature_config_index (arc, |
| 540 | rt->sw_if_index); |
| 541 | vnet_get_config_data (&fcm->config_main, ¤t_config_index, |
| 542 | &next_index, 0); |
| 543 | } |
| 544 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 545 | while (from < from_end) |
| 546 | { |
| 547 | /* Get new next frame since previous incomplete frame may have less |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 548 | than VNET_FRAME_SIZE vectors in it. */ |
| 549 | vlib_get_new_next_frame (vm, node, next_index, to_tx, n_left_to_tx); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 550 | |
Damjan Marion | 363640d | 2017-03-06 11:53:10 +0100 | [diff] [blame] | 551 | while (from + 8 <= from_end && n_left_to_tx >= 4) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 552 | { |
Damjan Marion | 363640d | 2017-03-06 11:53:10 +0100 | [diff] [blame] | 553 | u32 bi0, bi1, bi2, bi3; |
Damjan Marion | 363640d | 2017-03-06 11:53:10 +0100 | [diff] [blame] | 554 | u32 tx_swif0, tx_swif1, tx_swif2, tx_swif3; |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 555 | u32 or_flags; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 556 | |
| 557 | /* Prefetch next iteration. */ |
Zhiyong Yang | a462c07 | 2019-05-05 19:32:25 +0800 | [diff] [blame] | 558 | vlib_prefetch_buffer_header (b[4], LOAD); |
| 559 | vlib_prefetch_buffer_header (b[5], LOAD); |
| 560 | vlib_prefetch_buffer_header (b[6], LOAD); |
| 561 | vlib_prefetch_buffer_header (b[7], LOAD); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 562 | |
| 563 | bi0 = from[0]; |
| 564 | bi1 = from[1]; |
Damjan Marion | 363640d | 2017-03-06 11:53:10 +0100 | [diff] [blame] | 565 | bi2 = from[2]; |
| 566 | bi3 = from[3]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 567 | to_tx[0] = bi0; |
| 568 | to_tx[1] = bi1; |
Damjan Marion | 363640d | 2017-03-06 11:53:10 +0100 | [diff] [blame] | 569 | to_tx[2] = bi2; |
| 570 | to_tx[3] = bi3; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 571 | |
Zhiyong Yang | a462c07 | 2019-05-05 19:32:25 +0800 | [diff] [blame] | 572 | or_flags = b[0]->flags | b[1]->flags | b[2]->flags | b[3]->flags; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 573 | |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 574 | if (do_segmentation) |
| 575 | { |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 576 | /* go to single loop if we need TSO segmentation */ |
| 577 | if (PREDICT_FALSE (or_flags & VNET_BUFFER_F_GSO)) |
| 578 | break; |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 579 | } |
Zhiyong Yang | a462c07 | 2019-05-05 19:32:25 +0800 | [diff] [blame] | 580 | from += 4; |
| 581 | to_tx += 4; |
| 582 | n_left_to_tx -= 4; |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 583 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 584 | /* Be grumpy about zero length buffers for benefit of |
| 585 | driver tx function. */ |
Zhiyong Yang | a462c07 | 2019-05-05 19:32:25 +0800 | [diff] [blame] | 586 | ASSERT (b[0]->current_length > 0); |
| 587 | ASSERT (b[1]->current_length > 0); |
| 588 | ASSERT (b[2]->current_length > 0); |
| 589 | ASSERT (b[3]->current_length > 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 590 | |
Zhiyong Yang | a462c07 | 2019-05-05 19:32:25 +0800 | [diff] [blame] | 591 | n_bytes_b0 = vlib_buffer_length_in_chain (vm, b[0]); |
| 592 | n_bytes_b1 = vlib_buffer_length_in_chain (vm, b[1]); |
| 593 | n_bytes_b2 = vlib_buffer_length_in_chain (vm, b[2]); |
| 594 | n_bytes_b3 = vlib_buffer_length_in_chain (vm, b[3]); |
| 595 | tx_swif0 = vnet_buffer (b[0])->sw_if_index[VLIB_TX]; |
| 596 | tx_swif1 = vnet_buffer (b[1])->sw_if_index[VLIB_TX]; |
| 597 | tx_swif2 = vnet_buffer (b[2])->sw_if_index[VLIB_TX]; |
| 598 | tx_swif3 = vnet_buffer (b[3])->sw_if_index[VLIB_TX]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 599 | |
| 600 | n_bytes += n_bytes_b0 + n_bytes_b1; |
Damjan Marion | 363640d | 2017-03-06 11:53:10 +0100 | [diff] [blame] | 601 | n_bytes += n_bytes_b2 + n_bytes_b3; |
| 602 | n_packets += 4; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 603 | |
Damjan Marion | 152e21d | 2016-11-29 14:55:43 +0100 | [diff] [blame] | 604 | if (PREDICT_FALSE (current_config_index != ~0)) |
| 605 | { |
Zhiyong Yang | a462c07 | 2019-05-05 19:32:25 +0800 | [diff] [blame] | 606 | vnet_buffer (b[0])->feature_arc_index = arc; |
| 607 | vnet_buffer (b[1])->feature_arc_index = arc; |
| 608 | vnet_buffer (b[2])->feature_arc_index = arc; |
| 609 | vnet_buffer (b[3])->feature_arc_index = arc; |
| 610 | b[0]->current_config_index = current_config_index; |
| 611 | b[1]->current_config_index = current_config_index; |
| 612 | b[2]->current_config_index = current_config_index; |
| 613 | b[3]->current_config_index = current_config_index; |
Damjan Marion | 152e21d | 2016-11-29 14:55:43 +0100 | [diff] [blame] | 614 | } |
| 615 | |
Damjan Marion | 363640d | 2017-03-06 11:53:10 +0100 | [diff] [blame] | 616 | /* update vlan subif tx counts, if required */ |
Damjan Marion | 9c6ae5f | 2016-11-15 23:20:01 +0100 | [diff] [blame] | 617 | if (PREDICT_FALSE (tx_swif0 != rt->sw_if_index)) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 618 | { |
Damjan Marion | 9c6ae5f | 2016-11-15 23:20:01 +0100 | [diff] [blame] | 619 | vlib_increment_combined_counter (im->combined_sw_if_counters + |
| 620 | VNET_INTERFACE_COUNTER_TX, |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 621 | thread_index, tx_swif0, 1, |
Damjan Marion | 9c6ae5f | 2016-11-15 23:20:01 +0100 | [diff] [blame] | 622 | n_bytes_b0); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 623 | } |
Damjan Marion | 9c6ae5f | 2016-11-15 23:20:01 +0100 | [diff] [blame] | 624 | |
Damjan Marion | 9c6ae5f | 2016-11-15 23:20:01 +0100 | [diff] [blame] | 625 | if (PREDICT_FALSE (tx_swif1 != rt->sw_if_index)) |
| 626 | { |
| 627 | |
| 628 | vlib_increment_combined_counter (im->combined_sw_if_counters + |
| 629 | VNET_INTERFACE_COUNTER_TX, |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 630 | thread_index, tx_swif1, 1, |
Damjan Marion | 9c6ae5f | 2016-11-15 23:20:01 +0100 | [diff] [blame] | 631 | n_bytes_b1); |
| 632 | } |
Damjan Marion | 363640d | 2017-03-06 11:53:10 +0100 | [diff] [blame] | 633 | |
| 634 | if (PREDICT_FALSE (tx_swif2 != rt->sw_if_index)) |
| 635 | { |
| 636 | |
| 637 | vlib_increment_combined_counter (im->combined_sw_if_counters + |
| 638 | VNET_INTERFACE_COUNTER_TX, |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 639 | thread_index, tx_swif2, 1, |
Damjan Marion | 363640d | 2017-03-06 11:53:10 +0100 | [diff] [blame] | 640 | n_bytes_b2); |
| 641 | } |
| 642 | if (PREDICT_FALSE (tx_swif3 != rt->sw_if_index)) |
| 643 | { |
| 644 | |
| 645 | vlib_increment_combined_counter (im->combined_sw_if_counters + |
| 646 | VNET_INTERFACE_COUNTER_TX, |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 647 | thread_index, tx_swif3, 1, |
Damjan Marion | 363640d | 2017-03-06 11:53:10 +0100 | [diff] [blame] | 648 | n_bytes_b3); |
| 649 | } |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 650 | |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 651 | if (do_tx_offloads) |
| 652 | { |
| 653 | if (or_flags & |
| 654 | (VNET_BUFFER_F_OFFLOAD_TCP_CKSUM | |
| 655 | VNET_BUFFER_F_OFFLOAD_UDP_CKSUM | |
| 656 | VNET_BUFFER_F_OFFLOAD_IP_CKSUM)) |
| 657 | { |
Zhiyong Yang | a462c07 | 2019-05-05 19:32:25 +0800 | [diff] [blame] | 658 | calc_checksums (vm, b[0]); |
| 659 | calc_checksums (vm, b[1]); |
| 660 | calc_checksums (vm, b[2]); |
| 661 | calc_checksums (vm, b[3]); |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 662 | } |
| 663 | } |
Zhiyong Yang | a462c07 | 2019-05-05 19:32:25 +0800 | [diff] [blame] | 664 | b += 4; |
| 665 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | while (from + 1 <= from_end && n_left_to_tx >= 1) |
| 669 | { |
| 670 | u32 bi0; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 671 | u32 tx_swif0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 672 | |
| 673 | bi0 = from[0]; |
| 674 | to_tx[0] = bi0; |
| 675 | from += 1; |
| 676 | to_tx += 1; |
| 677 | n_left_to_tx -= 1; |
| 678 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 679 | /* Be grumpy about zero length buffers for benefit of |
| 680 | driver tx function. */ |
Zhiyong Yang | a462c07 | 2019-05-05 19:32:25 +0800 | [diff] [blame] | 681 | ASSERT (b[0]->current_length > 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 682 | |
Zhiyong Yang | a462c07 | 2019-05-05 19:32:25 +0800 | [diff] [blame] | 683 | n_bytes_b0 = vlib_buffer_length_in_chain (vm, b[0]); |
| 684 | tx_swif0 = vnet_buffer (b[0])->sw_if_index[VLIB_TX]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 685 | n_bytes += n_bytes_b0; |
| 686 | n_packets += 1; |
| 687 | |
Damjan Marion | 152e21d | 2016-11-29 14:55:43 +0100 | [diff] [blame] | 688 | if (PREDICT_FALSE (current_config_index != ~0)) |
| 689 | { |
Zhiyong Yang | a462c07 | 2019-05-05 19:32:25 +0800 | [diff] [blame] | 690 | vnet_buffer (b[0])->feature_arc_index = arc; |
| 691 | b[0]->current_config_index = current_config_index; |
Damjan Marion | 152e21d | 2016-11-29 14:55:43 +0100 | [diff] [blame] | 692 | } |
| 693 | |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 694 | if (do_segmentation) |
| 695 | { |
Zhiyong Yang | a462c07 | 2019-05-05 19:32:25 +0800 | [diff] [blame] | 696 | if (PREDICT_FALSE (b[0]->flags & VNET_BUFFER_F_GSO)) |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 697 | { |
| 698 | /* |
| 699 | * Undo the enqueue of the b0 - it is not going anywhere, |
| 700 | * and will be freed either after it's segmented or |
| 701 | * when dropped, if there is no buffers to segment into. |
| 702 | */ |
| 703 | to_tx -= 1; |
| 704 | n_left_to_tx += 1; |
| 705 | /* undo the counting. */ |
| 706 | n_bytes -= n_bytes_b0; |
| 707 | n_packets -= 1; |
| 708 | |
| 709 | u32 n_tx_bytes = 0; |
| 710 | |
| 711 | n_tx_bytes = |
Zhiyong Yang | a462c07 | 2019-05-05 19:32:25 +0800 | [diff] [blame] | 712 | tso_segment_buffer (vm, ptd, do_tx_offloads, bi0, b[0], |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 713 | n_bytes_b0); |
| 714 | |
| 715 | if (PREDICT_FALSE (n_tx_bytes == 0)) |
| 716 | { |
| 717 | drop_one_buffer_and_count (vm, vnm, node, from - 1, |
| 718 | VNET_INTERFACE_OUTPUT_ERROR_NO_BUFFERS_FOR_GSO); |
Mohsin Kazmi | dac1edb | 2019-06-18 23:45:54 +0200 | [diff] [blame] | 719 | b += 1; |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 720 | continue; |
| 721 | } |
| 722 | |
| 723 | u16 n_tx_bufs = vec_len (ptd->split_buffers); |
| 724 | u32 *from_tx_seg = ptd->split_buffers; |
| 725 | |
| 726 | while (n_tx_bufs > 0) |
| 727 | { |
| 728 | if (n_tx_bufs >= n_left_to_tx) |
| 729 | { |
| 730 | while (n_left_to_tx > 0) |
| 731 | { |
| 732 | to_tx[0] = from_tx_seg[0]; |
| 733 | to_tx += 1; |
| 734 | from_tx_seg += 1; |
| 735 | n_left_to_tx -= 1; |
| 736 | n_tx_bufs -= 1; |
| 737 | n_packets += 1; |
| 738 | } |
| 739 | vlib_put_next_frame (vm, node, next_index, |
| 740 | n_left_to_tx); |
| 741 | vlib_get_new_next_frame (vm, node, next_index, |
| 742 | to_tx, n_left_to_tx); |
| 743 | } |
Mohsin Kazmi | dac1edb | 2019-06-18 23:45:54 +0200 | [diff] [blame] | 744 | while (n_tx_bufs > 0) |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 745 | { |
Mohsin Kazmi | dac1edb | 2019-06-18 23:45:54 +0200 | [diff] [blame] | 746 | to_tx[0] = from_tx_seg[0]; |
| 747 | to_tx += 1; |
| 748 | from_tx_seg += 1; |
| 749 | n_left_to_tx -= 1; |
| 750 | n_tx_bufs -= 1; |
| 751 | n_packets += 1; |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 752 | } |
| 753 | } |
| 754 | n_bytes += n_tx_bytes; |
| 755 | if (PREDICT_FALSE (tx_swif0 != rt->sw_if_index)) |
| 756 | { |
| 757 | |
| 758 | vlib_increment_combined_counter |
| 759 | (im->combined_sw_if_counters + |
| 760 | VNET_INTERFACE_COUNTER_TX, thread_index, tx_swif0, |
| 761 | _vec_len (ptd->split_buffers), n_tx_bytes); |
| 762 | } |
| 763 | /* The buffers were enqueued. Reset the length */ |
| 764 | _vec_len (ptd->split_buffers) = 0; |
| 765 | /* Free the now segmented buffer */ |
| 766 | vlib_buffer_free_one (vm, bi0); |
Mohsin Kazmi | dac1edb | 2019-06-18 23:45:54 +0200 | [diff] [blame] | 767 | b += 1; |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 768 | continue; |
| 769 | } |
| 770 | } |
| 771 | |
Damjan Marion | 9c6ae5f | 2016-11-15 23:20:01 +0100 | [diff] [blame] | 772 | if (PREDICT_FALSE (tx_swif0 != rt->sw_if_index)) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 773 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 774 | |
Damjan Marion | 9c6ae5f | 2016-11-15 23:20:01 +0100 | [diff] [blame] | 775 | vlib_increment_combined_counter (im->combined_sw_if_counters + |
| 776 | VNET_INTERFACE_COUNTER_TX, |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 777 | thread_index, tx_swif0, 1, |
Damjan Marion | 9c6ae5f | 2016-11-15 23:20:01 +0100 | [diff] [blame] | 778 | n_bytes_b0); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 779 | } |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 780 | |
| 781 | if (do_tx_offloads) |
Zhiyong Yang | a462c07 | 2019-05-05 19:32:25 +0800 | [diff] [blame] | 782 | calc_checksums (vm, b[0]); |
| 783 | |
| 784 | b += 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 785 | } |
| 786 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 787 | vlib_put_next_frame (vm, node, next_index, n_left_to_tx); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | /* Update main interface stats. */ |
| 791 | vlib_increment_combined_counter (im->combined_sw_if_counters |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 792 | + VNET_INTERFACE_COUNTER_TX, |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 793 | thread_index, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 794 | rt->sw_if_index, n_packets, n_bytes); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 795 | return n_buffers; |
| 796 | } |
Filip Tehlar | 6266877 | 2019-03-04 03:33:32 -0800 | [diff] [blame] | 797 | #endif /* CLIB_MARCH_VARIANT */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 798 | |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 799 | static_always_inline void vnet_interface_pcap_tx_trace |
| 800 | (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame, |
| 801 | int sw_if_index_from_buffer) |
| 802 | { |
| 803 | u32 n_left_from, *from; |
| 804 | u32 sw_if_index; |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 805 | vnet_pcap_t *pp = &vlib_global_main.pcap; |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 806 | |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 807 | if (PREDICT_TRUE (pp->pcap_tx_enable == 0)) |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 808 | return; |
| 809 | |
| 810 | if (sw_if_index_from_buffer == 0) |
| 811 | { |
| 812 | vnet_interface_output_runtime_t *rt = (void *) node->runtime_data; |
| 813 | sw_if_index = rt->sw_if_index; |
| 814 | } |
| 815 | else |
| 816 | sw_if_index = ~0; |
| 817 | |
| 818 | n_left_from = frame->n_vectors; |
| 819 | from = vlib_frame_vector_args (frame); |
| 820 | |
| 821 | while (n_left_from > 0) |
| 822 | { |
Dave Barach | 9137e54 | 2019-09-13 17:47:50 -0400 | [diff] [blame] | 823 | int classify_filter_result; |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 824 | u32 bi0 = from[0]; |
| 825 | vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0); |
Dave Barach | 9137e54 | 2019-09-13 17:47:50 -0400 | [diff] [blame] | 826 | from++; |
| 827 | n_left_from--; |
| 828 | |
Dave Barach | f5667c3 | 2019-09-25 11:27:46 -0400 | [diff] [blame] | 829 | if (pp->filter_classify_table_index != ~0) |
Dave Barach | 9137e54 | 2019-09-13 17:47:50 -0400 | [diff] [blame] | 830 | { |
| 831 | classify_filter_result = |
| 832 | vnet_is_packet_traced_inline |
Dave Barach | f5667c3 | 2019-09-25 11:27:46 -0400 | [diff] [blame] | 833 | (b0, pp->filter_classify_table_index, 0 /* full classify */ ); |
Dave Barach | 9137e54 | 2019-09-13 17:47:50 -0400 | [diff] [blame] | 834 | if (classify_filter_result) |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 835 | pcap_add_buffer (&pp->pcap_main, vm, bi0, pp->max_bytes_per_pkt); |
Dave Barach | 9137e54 | 2019-09-13 17:47:50 -0400 | [diff] [blame] | 836 | continue; |
| 837 | } |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 838 | |
| 839 | if (sw_if_index_from_buffer) |
| 840 | sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_TX]; |
| 841 | |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 842 | if (pp->pcap_sw_if_index == 0 || pp->pcap_sw_if_index == sw_if_index) |
| 843 | pcap_add_buffer (&pp->pcap_main, vm, bi0, pp->max_bytes_per_pkt); |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 844 | } |
| 845 | } |
| 846 | |
Filip Tehlar | 6266877 | 2019-03-04 03:33:32 -0800 | [diff] [blame] | 847 | #ifndef CLIB_MARCH_VARIANT |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 848 | static_always_inline uword |
| 849 | vnet_interface_output_node_inline (vlib_main_t * vm, |
| 850 | vlib_node_runtime_t * node, |
| 851 | vlib_frame_t * frame, vnet_main_t * vnm, |
| 852 | vnet_hw_interface_t * hi, |
| 853 | int do_tx_offloads) |
| 854 | { |
| 855 | /* |
| 856 | * The 3-headed "if" is here because we want to err on the side |
| 857 | * of not impacting the non-GSO performance - so for the more |
| 858 | * common case of no GSO interfaces we want to prevent the |
| 859 | * segmentation codepath from being there altogether. |
| 860 | */ |
| 861 | if (PREDICT_TRUE (vnm->interface_main.gso_interface_count == 0)) |
| 862 | return vnet_interface_output_node_inline_gso (vm, node, frame, vnm, hi, |
| 863 | do_tx_offloads, |
| 864 | /* do_segmentation */ 0); |
| 865 | else if (hi->flags & VNET_HW_INTERFACE_FLAG_SUPPORTS_GSO) |
| 866 | return vnet_interface_output_node_inline_gso (vm, node, frame, vnm, hi, |
| 867 | do_tx_offloads, |
| 868 | /* do_segmentation */ 0); |
| 869 | else |
| 870 | return vnet_interface_output_node_inline_gso (vm, node, frame, vnm, hi, |
| 871 | do_tx_offloads, |
| 872 | /* do_segmentation */ 1); |
| 873 | } |
| 874 | |
Damjan Marion | 652d2e1 | 2019-02-02 00:15:27 +0100 | [diff] [blame] | 875 | uword |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 876 | vnet_interface_output_node (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 877 | vlib_frame_t * frame) |
| 878 | { |
| 879 | vnet_main_t *vnm = vnet_get_main (); |
| 880 | vnet_hw_interface_t *hi; |
| 881 | vnet_interface_output_runtime_t *rt = (void *) node->runtime_data; |
| 882 | hi = vnet_get_sup_hw_interface (vnm, rt->sw_if_index); |
| 883 | |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 884 | vnet_interface_pcap_tx_trace (vm, node, frame, |
| 885 | 0 /* sw_if_index_from_buffer */ ); |
| 886 | |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 887 | if (hi->flags & VNET_HW_INTERFACE_FLAG_SUPPORTS_TX_L4_CKSUM_OFFLOAD) |
| 888 | return vnet_interface_output_node_inline (vm, node, frame, vnm, hi, |
| 889 | /* do_tx_offloads */ 0); |
| 890 | else |
| 891 | return vnet_interface_output_node_inline (vm, node, frame, vnm, hi, |
| 892 | /* do_tx_offloads */ 1); |
| 893 | } |
Filip Tehlar | 6266877 | 2019-03-04 03:33:32 -0800 | [diff] [blame] | 894 | #endif /* CLIB_MARCH_VARIANT */ |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 895 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 896 | /* Use buffer's sw_if_index[VNET_TX] to choose output interface. */ |
Filip Tehlar | 6266877 | 2019-03-04 03:33:32 -0800 | [diff] [blame] | 897 | VLIB_NODE_FN (vnet_per_buffer_interface_output_node) (vlib_main_t * vm, |
| 898 | vlib_node_runtime_t * |
| 899 | node, |
| 900 | vlib_frame_t * frame) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 901 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 902 | vnet_main_t *vnm = vnet_get_main (); |
| 903 | u32 n_left_to_next, *from, *to_next; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 904 | u32 n_left_from, next_index; |
| 905 | |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 906 | vnet_interface_pcap_tx_trace (vm, node, frame, |
| 907 | 1 /* sw_if_index_from_buffer */ ); |
| 908 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 909 | n_left_from = frame->n_vectors; |
| 910 | |
Damjan Marion | a3d5986 | 2018-11-10 10:23:00 +0100 | [diff] [blame] | 911 | from = vlib_frame_vector_args (frame); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 912 | next_index = node->cached_next_index; |
| 913 | |
| 914 | while (n_left_from > 0) |
| 915 | { |
| 916 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
| 917 | |
| 918 | while (n_left_from >= 4 && n_left_to_next >= 2) |
| 919 | { |
| 920 | u32 bi0, bi1, next0, next1; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 921 | vlib_buffer_t *b0, *b1; |
| 922 | vnet_hw_interface_t *hi0, *hi1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 923 | |
| 924 | /* Prefetch next iteration. */ |
| 925 | vlib_prefetch_buffer_with_index (vm, from[2], LOAD); |
| 926 | vlib_prefetch_buffer_with_index (vm, from[3], LOAD); |
| 927 | |
| 928 | bi0 = from[0]; |
| 929 | bi1 = from[1]; |
| 930 | to_next[0] = bi0; |
| 931 | to_next[1] = bi1; |
| 932 | from += 2; |
| 933 | to_next += 2; |
| 934 | n_left_to_next -= 2; |
| 935 | n_left_from -= 2; |
| 936 | |
| 937 | b0 = vlib_get_buffer (vm, bi0); |
| 938 | b1 = vlib_get_buffer (vm, bi1); |
| 939 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 940 | hi0 = |
| 941 | vnet_get_sup_hw_interface (vnm, |
| 942 | vnet_buffer (b0)->sw_if_index |
| 943 | [VLIB_TX]); |
| 944 | hi1 = |
| 945 | vnet_get_sup_hw_interface (vnm, |
| 946 | vnet_buffer (b1)->sw_if_index |
| 947 | [VLIB_TX]); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 948 | |
John Lo | e5453d0 | 2018-01-23 19:21:34 -0500 | [diff] [blame] | 949 | next0 = hi0->output_node_next_index; |
| 950 | next1 = hi1->output_node_next_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 951 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 952 | vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next, |
| 953 | n_left_to_next, bi0, bi1, next0, |
| 954 | next1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 955 | } |
| 956 | |
| 957 | while (n_left_from > 0 && n_left_to_next > 0) |
| 958 | { |
| 959 | u32 bi0, next0; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 960 | vlib_buffer_t *b0; |
| 961 | vnet_hw_interface_t *hi0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 962 | |
| 963 | bi0 = from[0]; |
| 964 | to_next[0] = bi0; |
| 965 | from += 1; |
| 966 | to_next += 1; |
| 967 | n_left_to_next -= 1; |
| 968 | n_left_from -= 1; |
| 969 | |
| 970 | b0 = vlib_get_buffer (vm, bi0); |
| 971 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 972 | hi0 = |
| 973 | vnet_get_sup_hw_interface (vnm, |
| 974 | vnet_buffer (b0)->sw_if_index |
| 975 | [VLIB_TX]); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 976 | |
John Lo | e5453d0 | 2018-01-23 19:21:34 -0500 | [diff] [blame] | 977 | next0 = hi0->output_node_next_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 978 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 979 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next, |
| 980 | n_left_to_next, bi0, next0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 981 | } |
| 982 | |
| 983 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 984 | } |
| 985 | |
| 986 | return frame->n_vectors; |
| 987 | } |
| 988 | |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 989 | typedef struct vnet_error_trace_t_ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 990 | { |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 991 | u32 sw_if_index; |
| 992 | } vnet_error_trace_t; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 993 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 994 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 995 | static u8 * |
| 996 | format_vnet_error_trace (u8 * s, va_list * va) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 997 | { |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 998 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 999 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *); |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 1000 | vnet_error_trace_t *t = va_arg (*va, vnet_error_trace_t *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1001 | |
Neale Ranns | 7227c39 | 2019-03-21 10:20:15 +0000 | [diff] [blame] | 1002 | s = format (s, "rx:%U", format_vnet_sw_if_index_name, |
| 1003 | vnet_get_main (), t->sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1004 | |
| 1005 | return s; |
| 1006 | } |
| 1007 | |
| 1008 | static void |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 1009 | interface_trace_buffers (vlib_main_t * vm, |
| 1010 | vlib_node_runtime_t * node, vlib_frame_t * frame) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1011 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1012 | u32 n_left, *buffers; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1013 | |
| 1014 | buffers = vlib_frame_vector_args (frame); |
| 1015 | n_left = frame->n_vectors; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1016 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1017 | while (n_left >= 4) |
| 1018 | { |
| 1019 | u32 bi0, bi1; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1020 | vlib_buffer_t *b0, *b1; |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 1021 | vnet_error_trace_t *t0, *t1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1022 | |
| 1023 | /* Prefetch next iteration. */ |
| 1024 | vlib_prefetch_buffer_with_index (vm, buffers[2], LOAD); |
| 1025 | vlib_prefetch_buffer_with_index (vm, buffers[3], LOAD); |
| 1026 | |
| 1027 | bi0 = buffers[0]; |
| 1028 | bi1 = buffers[1]; |
| 1029 | |
| 1030 | b0 = vlib_get_buffer (vm, bi0); |
| 1031 | b1 = vlib_get_buffer (vm, bi1); |
| 1032 | |
| 1033 | if (b0->flags & VLIB_BUFFER_IS_TRACED) |
| 1034 | { |
| 1035 | t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0])); |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 1036 | t0->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1037 | } |
| 1038 | if (b1->flags & VLIB_BUFFER_IS_TRACED) |
| 1039 | { |
| 1040 | t1 = vlib_add_trace (vm, node, b1, sizeof (t1[0])); |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 1041 | t1->sw_if_index = vnet_buffer (b1)->sw_if_index[VLIB_RX]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1042 | } |
| 1043 | buffers += 2; |
| 1044 | n_left -= 2; |
| 1045 | } |
| 1046 | |
| 1047 | while (n_left >= 1) |
| 1048 | { |
| 1049 | u32 bi0; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1050 | vlib_buffer_t *b0; |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 1051 | vnet_error_trace_t *t0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1052 | |
| 1053 | bi0 = buffers[0]; |
| 1054 | |
| 1055 | b0 = vlib_get_buffer (vm, bi0); |
| 1056 | |
| 1057 | if (b0->flags & VLIB_BUFFER_IS_TRACED) |
| 1058 | { |
| 1059 | t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0])); |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 1060 | t0->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1061 | } |
| 1062 | buffers += 1; |
| 1063 | n_left -= 1; |
| 1064 | } |
| 1065 | } |
| 1066 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1067 | typedef enum |
| 1068 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1069 | VNET_ERROR_DISPOSITION_DROP, |
| 1070 | VNET_ERROR_DISPOSITION_PUNT, |
| 1071 | VNET_ERROR_N_DISPOSITION, |
| 1072 | } vnet_error_disposition_t; |
| 1073 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1074 | static_always_inline uword |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 1075 | interface_drop_punt (vlib_main_t * vm, |
| 1076 | vlib_node_runtime_t * node, |
| 1077 | vlib_frame_t * frame, |
| 1078 | vnet_error_disposition_t disposition) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1079 | { |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 1080 | u32 *from, n_left, thread_index, *sw_if_index; |
| 1081 | vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b; |
| 1082 | u32 sw_if_indices[VLIB_FRAME_SIZE]; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1083 | vlib_simple_counter_main_t *cm; |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 1084 | u16 nexts[VLIB_FRAME_SIZE]; |
| 1085 | vnet_main_t *vnm; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1086 | |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 1087 | vnm = vnet_get_main (); |
| 1088 | thread_index = vm->thread_index; |
| 1089 | from = vlib_frame_vector_args (frame); |
| 1090 | n_left = frame->n_vectors; |
| 1091 | b = bufs; |
| 1092 | sw_if_index = sw_if_indices; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1093 | |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 1094 | vlib_get_buffers (vm, from, bufs, n_left); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1095 | |
| 1096 | if (node->flags & VLIB_NODE_FLAG_TRACE) |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 1097 | interface_trace_buffers (vm, node, frame); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1098 | |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 1099 | /* All going to drop regardless, this is just a counting exercise */ |
| 1100 | clib_memset (nexts, 0, sizeof (nexts)); |
| 1101 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1102 | cm = vec_elt_at_index (vnm->interface_main.sw_if_counters, |
| 1103 | (disposition == VNET_ERROR_DISPOSITION_PUNT |
| 1104 | ? VNET_INTERFACE_COUNTER_PUNT |
| 1105 | : VNET_INTERFACE_COUNTER_DROP)); |
| 1106 | |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 1107 | /* collect the array of interfaces first ... */ |
| 1108 | while (n_left >= 4) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1109 | { |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 1110 | if (n_left >= 12) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1111 | { |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 1112 | /* Prefetch 8 ahead - there's not much going on in each iteration */ |
| 1113 | vlib_prefetch_buffer_header (b[4], LOAD); |
| 1114 | vlib_prefetch_buffer_header (b[5], LOAD); |
| 1115 | vlib_prefetch_buffer_header (b[6], LOAD); |
| 1116 | vlib_prefetch_buffer_header (b[7], LOAD); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1117 | } |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 1118 | sw_if_index[0] = vnet_buffer (b[0])->sw_if_index[VLIB_RX]; |
| 1119 | sw_if_index[1] = vnet_buffer (b[1])->sw_if_index[VLIB_RX]; |
| 1120 | sw_if_index[2] = vnet_buffer (b[2])->sw_if_index[VLIB_RX]; |
| 1121 | sw_if_index[3] = vnet_buffer (b[3])->sw_if_index[VLIB_RX]; |
| 1122 | |
| 1123 | sw_if_index += 4; |
| 1124 | n_left -= 4; |
| 1125 | b += 4; |
| 1126 | } |
| 1127 | while (n_left) |
| 1128 | { |
| 1129 | sw_if_index[0] = vnet_buffer (b[0])->sw_if_index[VLIB_RX]; |
| 1130 | |
| 1131 | sw_if_index += 1; |
| 1132 | n_left -= 1; |
| 1133 | b += 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1134 | } |
| 1135 | |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 1136 | /* ... then count against them in blocks */ |
| 1137 | n_left = frame->n_vectors; |
| 1138 | |
| 1139 | while (n_left) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1140 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1141 | vnet_sw_interface_t *sw_if0; |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 1142 | u16 off, count; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1143 | |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 1144 | off = frame->n_vectors - n_left; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1145 | |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 1146 | sw_if_index = sw_if_indices + off; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1147 | |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 1148 | count = clib_count_equal_u32 (sw_if_index, n_left); |
| 1149 | n_left -= count; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1150 | |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 1151 | vlib_increment_simple_counter (cm, thread_index, sw_if_index[0], count); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1152 | |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 1153 | /* Increment super-interface drop/punt counters for |
| 1154 | sub-interfaces. */ |
| 1155 | sw_if0 = vnet_get_sw_interface (vnm, sw_if_index[0]); |
| 1156 | if (sw_if0->sup_sw_if_index != sw_if_index[0]) |
| 1157 | vlib_increment_simple_counter |
| 1158 | (cm, thread_index, sw_if0->sup_sw_if_index, count); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1159 | } |
| 1160 | |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 1161 | vlib_buffer_enqueue_to_next (vm, node, from, nexts, frame->n_vectors); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1162 | |
| 1163 | return frame->n_vectors; |
| 1164 | } |
| 1165 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1166 | static inline void |
| 1167 | pcap_drop_trace (vlib_main_t * vm, |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 1168 | vnet_interface_main_t * im, |
| 1169 | vnet_pcap_t * pp, vlib_frame_t * f) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1170 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1171 | u32 *from; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1172 | u32 n_left = f->n_vectors; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1173 | vlib_buffer_t *b0, *p1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1174 | u32 bi0; |
| 1175 | i16 save_current_data; |
| 1176 | u16 save_current_length; |
Dave Barach | 9382ad9 | 2019-09-23 16:03:49 -0400 | [diff] [blame] | 1177 | vlib_error_main_t *em = &vm->error_main; |
Dave Barach | f5667c3 | 2019-09-25 11:27:46 -0400 | [diff] [blame] | 1178 | int do_trace = 0; |
| 1179 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1180 | |
| 1181 | from = vlib_frame_vector_args (f); |
| 1182 | |
| 1183 | while (n_left > 0) |
| 1184 | { |
| 1185 | if (PREDICT_TRUE (n_left > 1)) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1186 | { |
| 1187 | p1 = vlib_get_buffer (vm, from[1]); |
| 1188 | vlib_prefetch_buffer_header (p1, LOAD); |
| 1189 | } |
| 1190 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1191 | bi0 = from[0]; |
| 1192 | b0 = vlib_get_buffer (vm, bi0); |
| 1193 | from++; |
| 1194 | n_left--; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1195 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1196 | /* See if we're pointedly ignoring this specific error */ |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1197 | if (im->pcap_drop_filter_hash |
| 1198 | && hash_get (im->pcap_drop_filter_hash, b0->error)) |
| 1199 | continue; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1200 | |
Dave Barach | f5667c3 | 2019-09-25 11:27:46 -0400 | [diff] [blame] | 1201 | do_trace = (pp->pcap_sw_if_index == 0) || |
| 1202 | pp->pcap_sw_if_index == vnet_buffer (b0)->sw_if_index[VLIB_RX]; |
| 1203 | |
| 1204 | if (PREDICT_FALSE |
| 1205 | (do_trace == 0 && pp->filter_classify_table_index != ~0)) |
| 1206 | { |
| 1207 | do_trace = vnet_is_packet_traced_inline |
| 1208 | (b0, pp->filter_classify_table_index, 0 /* full classify */ ); |
| 1209 | } |
| 1210 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1211 | /* Trace all drops, or drops received on a specific interface */ |
Dave Barach | f5667c3 | 2019-09-25 11:27:46 -0400 | [diff] [blame] | 1212 | if (do_trace) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1213 | { |
| 1214 | save_current_data = b0->current_data; |
| 1215 | save_current_length = b0->current_length; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1216 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1217 | /* |
| 1218 | * Typically, we'll need to rewind the buffer |
Benoît Ganne | 4e323cb | 2019-09-17 17:30:35 +0200 | [diff] [blame] | 1219 | * if l2_hdr_offset is valid, make sure to rewind to the start of |
| 1220 | * the L2 header. This may not be the buffer start in case we pop-ed |
| 1221 | * vlan tags. |
| 1222 | * Otherwise, rewind to buffer start and hope for the best. |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1223 | */ |
Benoît Ganne | 4e323cb | 2019-09-17 17:30:35 +0200 | [diff] [blame] | 1224 | if (b0->flags & VNET_BUFFER_F_L2_HDR_OFFSET_VALID) |
| 1225 | { |
| 1226 | if (b0->current_data > vnet_buffer (b0)->l2_hdr_offset) |
| 1227 | vlib_buffer_advance (b0, |
| 1228 | vnet_buffer (b0)->l2_hdr_offset - |
| 1229 | b0->current_data); |
| 1230 | } |
| 1231 | else if (b0->current_data > 0) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1232 | vlib_buffer_advance (b0, (word) - b0->current_data); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1233 | |
Dave Barach | 9382ad9 | 2019-09-23 16:03:49 -0400 | [diff] [blame] | 1234 | { |
| 1235 | vlib_buffer_t *last = b0; |
| 1236 | u32 error_node_index; |
| 1237 | int drop_string_len; |
| 1238 | vlib_node_t *n; |
| 1239 | /* Length of the error string */ |
| 1240 | int error_string_len = |
| 1241 | clib_strnlen (em->error_strings_heap[b0->error], 128); |
| 1242 | |
| 1243 | /* Dig up the drop node */ |
| 1244 | error_node_index = vm->node_main.node_by_error[b0->error]; |
| 1245 | n = vlib_get_node (vm, error_node_index); |
| 1246 | |
| 1247 | /* Length of full drop string, w/ "nodename: " prepended */ |
| 1248 | drop_string_len = error_string_len + vec_len (n->name) + 2; |
| 1249 | |
| 1250 | /* Find the last buffer in the chain */ |
| 1251 | while (last->flags & VLIB_BUFFER_NEXT_PRESENT) |
| 1252 | last = vlib_get_buffer (vm, last->next_buffer); |
| 1253 | |
| 1254 | /* |
| 1255 | * Append <nodename>: <error-string> to the capture, |
| 1256 | * only if we can do that without allocating a new buffer. |
| 1257 | */ |
| 1258 | if (PREDICT_TRUE ((last->current_data + last->current_length) |
| 1259 | < (VLIB_BUFFER_DEFAULT_DATA_SIZE |
| 1260 | - drop_string_len))) |
| 1261 | { |
| 1262 | clib_memcpy_fast (last->data + last->current_data + |
| 1263 | last->current_length, n->name, |
| 1264 | vec_len (n->name)); |
| 1265 | clib_memcpy_fast (last->data + last->current_data + |
| 1266 | last->current_length + vec_len (n->name), |
| 1267 | ": ", 2); |
| 1268 | clib_memcpy_fast (last->data + last->current_data + |
| 1269 | last->current_length + vec_len (n->name) + |
| 1270 | 2, em->error_strings_heap[b0->error], |
| 1271 | error_string_len); |
| 1272 | last->current_length += drop_string_len; |
| 1273 | b0->flags &= ~(VLIB_BUFFER_TOTAL_LENGTH_VALID); |
| 1274 | pcap_add_buffer (&pp->pcap_main, vm, bi0, |
| 1275 | pp->max_bytes_per_pkt); |
| 1276 | last->current_length -= drop_string_len; |
| 1277 | b0->current_data = save_current_data; |
| 1278 | b0->current_length = save_current_length; |
| 1279 | continue; |
| 1280 | } |
| 1281 | } |
| 1282 | |
| 1283 | /* |
| 1284 | * Didn't have space in the last buffer, here's the dropped |
| 1285 | * packet as-is |
| 1286 | */ |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 1287 | pcap_add_buffer (&pp->pcap_main, vm, bi0, pp->max_bytes_per_pkt); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1288 | |
| 1289 | b0->current_data = save_current_data; |
| 1290 | b0->current_length = save_current_length; |
| 1291 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1292 | } |
| 1293 | } |
| 1294 | |
Filip Tehlar | 6266877 | 2019-03-04 03:33:32 -0800 | [diff] [blame] | 1295 | #ifndef CLIB_MARCH_VARIANT |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1296 | void |
| 1297 | vnet_pcap_drop_trace_filter_add_del (u32 error_index, int is_add) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1298 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1299 | vnet_interface_main_t *im = &vnet_get_main ()->interface_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1300 | |
| 1301 | if (im->pcap_drop_filter_hash == 0) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1302 | im->pcap_drop_filter_hash = hash_create (0, sizeof (uword)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1303 | |
| 1304 | if (is_add) |
| 1305 | hash_set (im->pcap_drop_filter_hash, error_index, 1); |
| 1306 | else |
| 1307 | hash_unset (im->pcap_drop_filter_hash, error_index); |
| 1308 | } |
Filip Tehlar | 6266877 | 2019-03-04 03:33:32 -0800 | [diff] [blame] | 1309 | #endif /* CLIB_MARCH_VARIANT */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1310 | |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 1311 | VLIB_NODE_FN (interface_drop) (vlib_main_t * vm, |
| 1312 | vlib_node_runtime_t * node, |
| 1313 | vlib_frame_t * frame) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1314 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1315 | vnet_interface_main_t *im = &vnet_get_main ()->interface_main; |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 1316 | vnet_pcap_t *pp = &vlib_global_main.pcap; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1317 | |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 1318 | if (PREDICT_FALSE (pp->pcap_drop_enable)) |
| 1319 | pcap_drop_trace (vm, im, pp, frame); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1320 | |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 1321 | return interface_drop_punt (vm, node, frame, VNET_ERROR_DISPOSITION_DROP); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1322 | } |
| 1323 | |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 1324 | VLIB_NODE_FN (interface_punt) (vlib_main_t * vm, |
| 1325 | vlib_node_runtime_t * node, |
| 1326 | vlib_frame_t * frame) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1327 | { |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 1328 | return interface_drop_punt (vm, node, frame, VNET_ERROR_DISPOSITION_PUNT); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1329 | } |
| 1330 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1331 | /* *INDENT-OFF* */ |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 1332 | VLIB_REGISTER_NODE (interface_drop) = { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1333 | .name = "error-drop", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1334 | .vector_size = sizeof (u32), |
| 1335 | .format_trace = format_vnet_error_trace, |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 1336 | .n_next_nodes = 1, |
| 1337 | .next_nodes = { |
| 1338 | [0] = "drop", |
| 1339 | }, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1340 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1341 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1342 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1343 | /* *INDENT-OFF* */ |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 1344 | VLIB_REGISTER_NODE (interface_punt) = { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1345 | .name = "error-punt", |
| 1346 | .vector_size = sizeof (u32), |
| 1347 | .format_trace = format_vnet_error_trace, |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 1348 | .n_next_nodes = 1, |
| 1349 | .next_nodes = { |
| 1350 | [0] = "punt", |
| 1351 | }, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1352 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1353 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1354 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1355 | /* *INDENT-OFF* */ |
Filip Tehlar | 6266877 | 2019-03-04 03:33:32 -0800 | [diff] [blame] | 1356 | VLIB_REGISTER_NODE (vnet_per_buffer_interface_output_node) = { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1357 | .name = "interface-output", |
| 1358 | .vector_size = sizeof (u32), |
| 1359 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1360 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1361 | |
Damjan Marion | 152e21d | 2016-11-29 14:55:43 +0100 | [diff] [blame] | 1362 | static uword |
| 1363 | interface_tx_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 1364 | vlib_frame_t * from_frame) |
| 1365 | { |
| 1366 | vnet_main_t *vnm = vnet_get_main (); |
| 1367 | u32 last_sw_if_index = ~0; |
| 1368 | vlib_frame_t *to_frame = 0; |
| 1369 | vnet_hw_interface_t *hw = 0; |
| 1370 | u32 *from, *to_next = 0; |
| 1371 | u32 n_left_from; |
| 1372 | |
| 1373 | from = vlib_frame_vector_args (from_frame); |
| 1374 | n_left_from = from_frame->n_vectors; |
| 1375 | while (n_left_from > 0) |
| 1376 | { |
| 1377 | u32 bi0; |
| 1378 | vlib_buffer_t *b0; |
| 1379 | u32 sw_if_index0; |
| 1380 | |
| 1381 | bi0 = from[0]; |
| 1382 | from++; |
| 1383 | n_left_from--; |
| 1384 | b0 = vlib_get_buffer (vm, bi0); |
| 1385 | sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_TX]; |
| 1386 | |
| 1387 | if (PREDICT_FALSE ((last_sw_if_index != sw_if_index0) || to_frame == 0)) |
| 1388 | { |
| 1389 | if (to_frame) |
| 1390 | { |
| 1391 | hw = vnet_get_sup_hw_interface (vnm, last_sw_if_index); |
| 1392 | vlib_put_frame_to_node (vm, hw->tx_node_index, to_frame); |
| 1393 | } |
| 1394 | last_sw_if_index = sw_if_index0; |
| 1395 | hw = vnet_get_sup_hw_interface (vnm, sw_if_index0); |
| 1396 | to_frame = vlib_get_frame_to_node (vm, hw->tx_node_index); |
| 1397 | to_next = vlib_frame_vector_args (to_frame); |
| 1398 | } |
| 1399 | |
| 1400 | to_next[0] = bi0; |
| 1401 | to_next++; |
| 1402 | to_frame->n_vectors++; |
| 1403 | } |
| 1404 | vlib_put_frame_to_node (vm, hw->tx_node_index, to_frame); |
| 1405 | return from_frame->n_vectors; |
| 1406 | } |
| 1407 | |
| 1408 | /* *INDENT-OFF* */ |
Damjan Marion | d770cfc | 2019-09-02 19:00:33 +0200 | [diff] [blame] | 1409 | VLIB_REGISTER_NODE (interface_tx) = { |
Damjan Marion | 152e21d | 2016-11-29 14:55:43 +0100 | [diff] [blame] | 1410 | .function = interface_tx_node_fn, |
| 1411 | .name = "interface-tx", |
| 1412 | .vector_size = sizeof (u32), |
| 1413 | .n_next_nodes = 1, |
| 1414 | .next_nodes = { |
| 1415 | [0] = "error-drop", |
| 1416 | }, |
| 1417 | }; |
| 1418 | |
| 1419 | VNET_FEATURE_ARC_INIT (interface_output, static) = |
| 1420 | { |
| 1421 | .arc_name = "interface-output", |
| 1422 | .start_nodes = VNET_FEATURES (0), |
Dave Barach | a25def7 | 2018-11-26 11:04:45 -0500 | [diff] [blame] | 1423 | .last_in_arc = "interface-tx", |
Damjan Marion | 152e21d | 2016-11-29 14:55:43 +0100 | [diff] [blame] | 1424 | .arc_index_ptr = &vnet_main.interface_main.output_feature_arc_index, |
| 1425 | }; |
| 1426 | |
Pavel Kotucek | 3a2a1c4 | 2016-12-06 10:10:10 +0100 | [diff] [blame] | 1427 | VNET_FEATURE_INIT (span_tx, static) = { |
| 1428 | .arc_name = "interface-output", |
| 1429 | .node_name = "span-output", |
| 1430 | .runs_before = VNET_FEATURES ("interface-tx"), |
| 1431 | }; |
| 1432 | |
Matthew Smith | 537eeec | 2018-04-09 11:49:20 -0500 | [diff] [blame] | 1433 | VNET_FEATURE_INIT (ipsec_if_tx, static) = { |
| 1434 | .arc_name = "interface-output", |
| 1435 | .node_name = "ipsec-if-output", |
| 1436 | .runs_before = VNET_FEATURES ("interface-tx"), |
| 1437 | }; |
| 1438 | |
Damjan Marion | 152e21d | 2016-11-29 14:55:43 +0100 | [diff] [blame] | 1439 | VNET_FEATURE_INIT (interface_tx, static) = { |
| 1440 | .arc_name = "interface-output", |
| 1441 | .node_name = "interface-tx", |
| 1442 | .runs_before = 0, |
| 1443 | }; |
| 1444 | /* *INDENT-ON* */ |
| 1445 | |
Filip Tehlar | 6266877 | 2019-03-04 03:33:32 -0800 | [diff] [blame] | 1446 | #ifndef CLIB_MARCH_VARIANT |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1447 | clib_error_t * |
| 1448 | vnet_per_buffer_interface_output_hw_interface_add_del (vnet_main_t * vnm, |
| 1449 | u32 hw_if_index, |
| 1450 | u32 is_create) |
| 1451 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1452 | vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1453 | u32 next_index; |
| 1454 | |
John Lo | e5453d0 | 2018-01-23 19:21:34 -0500 | [diff] [blame] | 1455 | if (hi->output_node_index == 0) |
| 1456 | return 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1457 | |
John Lo | e5453d0 | 2018-01-23 19:21:34 -0500 | [diff] [blame] | 1458 | next_index = vlib_node_add_next |
| 1459 | (vnm->vlib_main, vnet_per_buffer_interface_output_node.index, |
| 1460 | hi->output_node_index); |
| 1461 | hi->output_node_next_index = next_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1462 | |
| 1463 | return 0; |
| 1464 | } |
| 1465 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1466 | VNET_HW_INTERFACE_ADD_DEL_FUNCTION |
| 1467 | (vnet_per_buffer_interface_output_hw_interface_add_del); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1468 | |
John Lo | e5453d0 | 2018-01-23 19:21:34 -0500 | [diff] [blame] | 1469 | void |
| 1470 | vnet_set_interface_output_node (vnet_main_t * vnm, |
| 1471 | u32 hw_if_index, u32 node_index) |
| 1472 | { |
| 1473 | ASSERT (node_index); |
| 1474 | vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index); |
| 1475 | u32 next_index = vlib_node_add_next |
| 1476 | (vnm->vlib_main, vnet_per_buffer_interface_output_node.index, node_index); |
| 1477 | hi->output_node_next_index = next_index; |
| 1478 | hi->output_node_index = node_index; |
| 1479 | } |
Filip Tehlar | 6266877 | 2019-03-04 03:33:32 -0800 | [diff] [blame] | 1480 | #endif /* CLIB_MARCH_VARIANT */ |
John Lo | e5453d0 | 2018-01-23 19:21:34 -0500 | [diff] [blame] | 1481 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1482 | /* |
| 1483 | * fd.io coding-style-patch-verification: ON |
| 1484 | * |
| 1485 | * Local Variables: |
| 1486 | * eval: (c-set-style "gnu") |
| 1487 | * End: |
| 1488 | */ |