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> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 46 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 47 | typedef struct |
| 48 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 49 | u32 sw_if_index; |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 50 | u32 flags; |
| 51 | u16 gso_size; |
| 52 | u8 gso_l4_hdr_sz; |
| 53 | u8 data[128 - 3 * sizeof (u32)]; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 54 | } |
| 55 | interface_output_trace_t; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 56 | |
Filip Tehlar | 6266877 | 2019-03-04 03:33:32 -0800 | [diff] [blame^] | 57 | #ifndef CLIB_MARCH_VARIANT |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 58 | u8 * |
| 59 | format_vnet_interface_output_trace (u8 * s, va_list * va) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 60 | { |
| 61 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 62 | vlib_node_t *node = va_arg (*va, vlib_node_t *); |
| 63 | interface_output_trace_t *t = va_arg (*va, interface_output_trace_t *); |
| 64 | vnet_main_t *vnm = vnet_get_main (); |
| 65 | vnet_sw_interface_t *si; |
Christophe Fontaine | d3c008d | 2017-10-02 18:10:54 +0200 | [diff] [blame] | 66 | u32 indent; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 67 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 68 | if (t->sw_if_index != (u32) ~ 0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 69 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 70 | indent = format_get_indent (s); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 71 | |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 72 | if (pool_is_free_index |
| 73 | (vnm->interface_main.sw_interfaces, t->sw_if_index)) |
| 74 | { |
| 75 | /* 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] | 76 | s = format (s, "sw_if_index: %d ", t->sw_if_index); |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 77 | } |
| 78 | else |
| 79 | { |
| 80 | si = vnet_get_sw_interface (vnm, t->sw_if_index); |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 81 | s = |
| 82 | format (s, "%U ", format_vnet_sw_interface_name, vnm, si, |
| 83 | t->flags); |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 84 | } |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 85 | #define _(bit, name, v, x) \ |
| 86 | if (v && (t->flags & VNET_BUFFER_F_##name)) \ |
| 87 | s = format (s, "%s ", v); |
| 88 | foreach_vnet_buffer_flag |
| 89 | #undef _ |
| 90 | if (t->flags & VNET_BUFFER_F_GSO) |
| 91 | { |
| 92 | s = format (s, "\n%Ugso_sz %d gso_l4_hdr_sz %d", |
| 93 | format_white_space, indent + 2, t->gso_size, |
| 94 | t->gso_l4_hdr_sz); |
| 95 | } |
| 96 | s = |
| 97 | format (s, "\n%U%U", format_white_space, indent, |
| 98 | node->format_buffer ? node->format_buffer : format_hex_bytes, |
| 99 | t->data, sizeof (t->data)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 100 | } |
| 101 | return s; |
| 102 | } |
| 103 | |
| 104 | static void |
| 105 | vnet_interface_output_trace (vlib_main_t * vm, |
| 106 | vlib_node_runtime_t * node, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 107 | vlib_frame_t * frame, uword n_buffers) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 108 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 109 | u32 n_left, *from; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 110 | |
| 111 | n_left = n_buffers; |
Damjan Marion | a3d5986 | 2018-11-10 10:23:00 +0100 | [diff] [blame] | 112 | from = vlib_frame_vector_args (frame); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 113 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 114 | while (n_left >= 4) |
| 115 | { |
| 116 | u32 bi0, bi1; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 117 | vlib_buffer_t *b0, *b1; |
| 118 | interface_output_trace_t *t0, *t1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 119 | |
| 120 | /* Prefetch next iteration. */ |
| 121 | vlib_prefetch_buffer_with_index (vm, from[2], LOAD); |
| 122 | vlib_prefetch_buffer_with_index (vm, from[3], LOAD); |
| 123 | |
| 124 | bi0 = from[0]; |
| 125 | bi1 = from[1]; |
| 126 | |
| 127 | b0 = vlib_get_buffer (vm, bi0); |
| 128 | b1 = vlib_get_buffer (vm, bi1); |
| 129 | |
| 130 | if (b0->flags & VLIB_BUFFER_IS_TRACED) |
| 131 | { |
| 132 | t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0])); |
| 133 | t0->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_TX]; |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 134 | t0->flags = b0->flags; |
| 135 | t0->gso_size = vnet_buffer2 (b0)->gso_size; |
| 136 | t0->gso_l4_hdr_sz = vnet_buffer2 (b0)->gso_l4_hdr_sz; |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 137 | clib_memcpy_fast (t0->data, vlib_buffer_get_current (b0), |
| 138 | sizeof (t0->data)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 139 | } |
| 140 | if (b1->flags & VLIB_BUFFER_IS_TRACED) |
| 141 | { |
| 142 | t1 = vlib_add_trace (vm, node, b1, sizeof (t1[0])); |
| 143 | t1->sw_if_index = vnet_buffer (b1)->sw_if_index[VLIB_TX]; |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 144 | t1->flags = b1->flags; |
| 145 | t1->gso_size = vnet_buffer2 (b1)->gso_size; |
| 146 | t1->gso_l4_hdr_sz = vnet_buffer2 (b1)->gso_l4_hdr_sz; |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 147 | clib_memcpy_fast (t1->data, vlib_buffer_get_current (b1), |
| 148 | sizeof (t1->data)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 149 | } |
| 150 | from += 2; |
| 151 | n_left -= 2; |
| 152 | } |
| 153 | |
| 154 | while (n_left >= 1) |
| 155 | { |
| 156 | u32 bi0; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 157 | vlib_buffer_t *b0; |
| 158 | interface_output_trace_t *t0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 159 | |
| 160 | bi0 = from[0]; |
| 161 | |
| 162 | b0 = vlib_get_buffer (vm, bi0); |
| 163 | |
| 164 | if (b0->flags & VLIB_BUFFER_IS_TRACED) |
| 165 | { |
| 166 | t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0])); |
| 167 | t0->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_TX]; |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 168 | t0->flags = b0->flags; |
| 169 | t0->gso_size = vnet_buffer2 (b0)->gso_size; |
| 170 | t0->gso_l4_hdr_sz = vnet_buffer2 (b0)->gso_l4_hdr_sz; |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 171 | clib_memcpy_fast (t0->data, vlib_buffer_get_current (b0), |
| 172 | sizeof (t0->data)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 173 | } |
| 174 | from += 1; |
| 175 | n_left -= 1; |
| 176 | } |
| 177 | } |
| 178 | |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 179 | static_always_inline void |
| 180 | calc_checksums (vlib_main_t * vm, vlib_buffer_t * b) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 181 | { |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 182 | ip4_header_t *ip4; |
| 183 | ip6_header_t *ip6; |
| 184 | tcp_header_t *th; |
| 185 | udp_header_t *uh; |
| 186 | |
| 187 | int is_ip4 = (b->flags & VNET_BUFFER_F_IS_IP4) != 0; |
| 188 | int is_ip6 = (b->flags & VNET_BUFFER_F_IS_IP6) != 0; |
| 189 | |
| 190 | ASSERT (!(is_ip4 && is_ip6)); |
| 191 | |
| 192 | ip4 = (ip4_header_t *) (b->data + vnet_buffer (b)->l3_hdr_offset); |
| 193 | ip6 = (ip6_header_t *) (b->data + vnet_buffer (b)->l3_hdr_offset); |
| 194 | th = (tcp_header_t *) (b->data + vnet_buffer (b)->l4_hdr_offset); |
| 195 | uh = (udp_header_t *) (b->data + vnet_buffer (b)->l4_hdr_offset); |
| 196 | |
| 197 | if (is_ip4) |
| 198 | { |
| 199 | ip4 = (ip4_header_t *) (b->data + vnet_buffer (b)->l3_hdr_offset); |
| 200 | if (b->flags & VNET_BUFFER_F_OFFLOAD_IP_CKSUM) |
| 201 | ip4->checksum = ip4_header_checksum (ip4); |
| 202 | if (b->flags & VNET_BUFFER_F_OFFLOAD_TCP_CKSUM) |
Andrej Kozemcak | 9d7570c | 2019-01-07 08:39:22 +0100 | [diff] [blame] | 203 | { |
| 204 | th->checksum = 0; |
| 205 | th->checksum = ip4_tcp_udp_compute_checksum (vm, b, ip4); |
| 206 | } |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 207 | if (b->flags & VNET_BUFFER_F_OFFLOAD_UDP_CKSUM) |
| 208 | uh->checksum = ip4_tcp_udp_compute_checksum (vm, b, ip4); |
| 209 | } |
| 210 | if (is_ip6) |
| 211 | { |
| 212 | int bogus; |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 213 | if (b->flags & VNET_BUFFER_F_OFFLOAD_TCP_CKSUM) |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 214 | { |
| 215 | th->checksum = 0; |
| 216 | th->checksum = |
| 217 | ip6_tcp_udp_icmp_compute_checksum (vm, b, ip6, &bogus); |
| 218 | } |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 219 | if (b->flags & VNET_BUFFER_F_OFFLOAD_UDP_CKSUM) |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 220 | { |
| 221 | uh->checksum = 0; |
| 222 | uh->checksum = |
| 223 | ip6_tcp_udp_icmp_compute_checksum (vm, b, ip6, &bogus); |
| 224 | } |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | b->flags &= ~VNET_BUFFER_F_OFFLOAD_TCP_CKSUM; |
| 228 | b->flags &= ~VNET_BUFFER_F_OFFLOAD_UDP_CKSUM; |
| 229 | b->flags &= ~VNET_BUFFER_F_OFFLOAD_IP_CKSUM; |
| 230 | } |
| 231 | |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 232 | static_always_inline u16 |
| 233 | tso_alloc_tx_bufs (vlib_main_t * vm, |
| 234 | vnet_interface_per_thread_data_t * ptd, |
| 235 | vlib_buffer_t * b0, u16 l4_hdr_sz) |
| 236 | { |
| 237 | u32 n_bytes_b0 = vlib_buffer_length_in_chain (vm, b0); |
| 238 | u16 gso_size = vnet_buffer2 (b0)->gso_size; |
| 239 | u16 l234_sz = vnet_buffer (b0)->l4_hdr_offset + l4_hdr_sz; |
| 240 | /* rounded-up division */ |
| 241 | u16 n_bufs = (n_bytes_b0 - l234_sz + (gso_size - 1)) / gso_size; |
| 242 | u16 n_alloc; |
| 243 | |
| 244 | ASSERT (n_bufs > 0); |
| 245 | vec_validate (ptd->split_buffers, n_bufs - 1); |
| 246 | |
| 247 | n_alloc = vlib_buffer_alloc (vm, ptd->split_buffers, n_bufs); |
| 248 | if (n_alloc < n_bufs) |
| 249 | { |
| 250 | vlib_buffer_free (vm, ptd->split_buffers, n_alloc); |
| 251 | return 0; |
| 252 | } |
| 253 | return 1; |
| 254 | } |
| 255 | |
| 256 | static_always_inline void |
| 257 | tso_init_buf_from_template_base (vlib_buffer_t * nb0, vlib_buffer_t * b0, |
| 258 | u32 flags, u16 length) |
| 259 | { |
| 260 | nb0->current_data = 0; |
| 261 | nb0->total_length_not_including_first_buffer = 0; |
| 262 | nb0->flags = VLIB_BUFFER_TOTAL_LENGTH_VALID | flags; |
| 263 | clib_memcpy_fast (&nb0->opaque, &b0->opaque, sizeof (nb0->opaque)); |
| 264 | clib_memcpy_fast (nb0->data, b0->data, length); |
| 265 | nb0->current_length = length; |
| 266 | } |
| 267 | |
| 268 | static_always_inline void |
| 269 | tso_init_buf_from_template (vlib_main_t * vm, vlib_buffer_t * nb0, |
| 270 | vlib_buffer_t * b0, u16 template_data_sz, |
| 271 | u16 gso_size, u8 ** p_dst_ptr, u16 * p_dst_left, |
| 272 | u32 next_tcp_seq, u32 flags) |
| 273 | { |
| 274 | tso_init_buf_from_template_base (nb0, b0, flags, template_data_sz); |
| 275 | |
| 276 | *p_dst_left = |
| 277 | clib_min (gso_size, |
| 278 | vlib_buffer_get_default_data_size (vm) - template_data_sz); |
| 279 | *p_dst_ptr = nb0->data + template_data_sz; |
| 280 | |
| 281 | tcp_header_t *tcp = |
| 282 | (tcp_header_t *) (nb0->data + vnet_buffer (nb0)->l4_hdr_offset); |
| 283 | tcp->seq_number = clib_host_to_net_u32 (next_tcp_seq); |
| 284 | } |
| 285 | |
| 286 | static_always_inline void |
| 287 | tso_fixup_segmented_buf (vlib_buffer_t * b0, u8 tcp_flags, int is_ip6) |
| 288 | { |
| 289 | u16 l3_hdr_offset = vnet_buffer (b0)->l3_hdr_offset; |
| 290 | u16 l4_hdr_offset = vnet_buffer (b0)->l4_hdr_offset; |
| 291 | ip4_header_t *ip4 = (ip4_header_t *) (b0->data + l3_hdr_offset); |
| 292 | ip6_header_t *ip6 = (ip6_header_t *) (b0->data + l3_hdr_offset); |
| 293 | tcp_header_t *tcp = (tcp_header_t *) (b0->data + l4_hdr_offset); |
| 294 | |
| 295 | tcp->flags = tcp_flags; |
| 296 | |
| 297 | if (is_ip6) |
| 298 | ip6->payload_length = |
| 299 | clib_host_to_net_u16 (b0->current_length - |
| 300 | vnet_buffer (b0)->l4_hdr_offset); |
| 301 | else |
| 302 | ip4->length = |
| 303 | clib_host_to_net_u16 (b0->current_length - |
| 304 | vnet_buffer (b0)->l3_hdr_offset); |
| 305 | } |
| 306 | |
| 307 | /** |
| 308 | * Allocate the necessary number of ptd->split_buffers, |
| 309 | * and segment the possibly chained buffer(s) from b0 into |
| 310 | * there. |
| 311 | * |
| 312 | * Return the cumulative number of bytes sent or zero |
| 313 | * if allocation failed. |
| 314 | */ |
| 315 | |
| 316 | static_always_inline u32 |
| 317 | tso_segment_buffer (vlib_main_t * vm, vnet_interface_per_thread_data_t * ptd, |
| 318 | int do_tx_offloads, u32 sbi0, vlib_buffer_t * sb0, |
| 319 | u32 n_bytes_b0) |
| 320 | { |
| 321 | u32 n_tx_bytes = 0; |
| 322 | int is_ip4 = sb0->flags & VNET_BUFFER_F_IS_IP4; |
| 323 | int is_ip6 = sb0->flags & VNET_BUFFER_F_IS_IP6; |
| 324 | ASSERT (is_ip4 || is_ip6); |
| 325 | ASSERT (sb0->flags & VNET_BUFFER_F_L2_HDR_OFFSET_VALID); |
| 326 | ASSERT (sb0->flags & VNET_BUFFER_F_L3_HDR_OFFSET_VALID); |
| 327 | ASSERT (sb0->flags & VNET_BUFFER_F_L4_HDR_OFFSET_VALID); |
| 328 | u16 gso_size = vnet_buffer2 (sb0)->gso_size; |
| 329 | |
| 330 | int l4_hdr_sz = vnet_buffer2 (sb0)->gso_l4_hdr_sz; |
| 331 | u8 save_tcp_flags = 0; |
| 332 | u8 tcp_flags_no_fin_psh = 0; |
| 333 | u32 next_tcp_seq = 0; |
| 334 | |
| 335 | tcp_header_t *tcp = |
| 336 | (tcp_header_t *) (sb0->data + vnet_buffer (sb0)->l4_hdr_offset); |
| 337 | next_tcp_seq = clib_net_to_host_u32 (tcp->seq_number); |
| 338 | /* store original flags for last packet and reset FIN and PSH */ |
| 339 | save_tcp_flags = tcp->flags; |
| 340 | tcp_flags_no_fin_psh = tcp->flags & ~(TCP_FLAG_FIN | TCP_FLAG_PSH); |
| 341 | tcp->checksum = 0; |
| 342 | |
| 343 | u32 default_bflags = |
| 344 | sb0->flags & ~(VNET_BUFFER_F_GSO | VLIB_BUFFER_NEXT_PRESENT); |
| 345 | u16 l234_sz = vnet_buffer (sb0)->l4_hdr_offset + l4_hdr_sz; |
| 346 | int first_data_size = clib_min (gso_size, sb0->current_length - l234_sz); |
| 347 | next_tcp_seq += first_data_size; |
| 348 | |
| 349 | if (PREDICT_FALSE (!tso_alloc_tx_bufs (vm, ptd, sb0, l4_hdr_sz))) |
| 350 | return 0; |
| 351 | |
| 352 | vlib_buffer_t *b0 = vlib_get_buffer (vm, ptd->split_buffers[0]); |
| 353 | tso_init_buf_from_template_base (b0, sb0, default_bflags, |
| 354 | l4_hdr_sz + first_data_size); |
| 355 | |
| 356 | u32 total_src_left = n_bytes_b0 - l234_sz - first_data_size; |
| 357 | if (total_src_left) |
| 358 | { |
| 359 | /* Need to copy more segments */ |
| 360 | u8 *src_ptr, *dst_ptr; |
| 361 | u16 src_left, dst_left; |
| 362 | /* current source buffer */ |
| 363 | vlib_buffer_t *csb0 = sb0; |
| 364 | u32 csbi0 = sbi0; |
| 365 | /* current dest buffer */ |
| 366 | vlib_buffer_t *cdb0; |
| 367 | u16 dbi = 1; /* the buffer [0] is b0 */ |
| 368 | |
| 369 | src_ptr = sb0->data + l234_sz + first_data_size; |
| 370 | src_left = sb0->current_length - l234_sz - first_data_size; |
| 371 | b0->current_length = l234_sz + first_data_size; |
| 372 | |
| 373 | tso_fixup_segmented_buf (b0, tcp_flags_no_fin_psh, is_ip6); |
| 374 | if (do_tx_offloads) |
| 375 | calc_checksums (vm, b0); |
| 376 | |
| 377 | /* grab a second buffer and prepare the loop */ |
| 378 | ASSERT (dbi < vec_len (ptd->split_buffers)); |
| 379 | cdb0 = vlib_get_buffer (vm, ptd->split_buffers[dbi++]); |
| 380 | tso_init_buf_from_template (vm, cdb0, b0, l234_sz, gso_size, &dst_ptr, |
| 381 | &dst_left, next_tcp_seq, default_bflags); |
| 382 | |
| 383 | /* an arbitrary large number to catch the runaway loops */ |
| 384 | int nloops = 2000; |
| 385 | while (total_src_left) |
| 386 | { |
Dave Barach | a2aefef | 2019-02-27 12:36:28 -0500 | [diff] [blame] | 387 | if (nloops-- <= 0) |
| 388 | clib_panic ("infinite loop detected"); |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 389 | u16 bytes_to_copy = clib_min (src_left, dst_left); |
| 390 | |
| 391 | clib_memcpy_fast (dst_ptr, src_ptr, bytes_to_copy); |
| 392 | |
| 393 | src_left -= bytes_to_copy; |
| 394 | src_ptr += bytes_to_copy; |
| 395 | total_src_left -= bytes_to_copy; |
| 396 | dst_left -= bytes_to_copy; |
| 397 | dst_ptr += bytes_to_copy; |
| 398 | next_tcp_seq += bytes_to_copy; |
| 399 | cdb0->current_length += bytes_to_copy; |
| 400 | |
| 401 | if (0 == src_left) |
| 402 | { |
| 403 | int has_next = (csb0->flags & VLIB_BUFFER_NEXT_PRESENT); |
| 404 | u32 next_bi = csb0->next_buffer; |
| 405 | |
| 406 | /* init src to the next buffer in chain */ |
| 407 | if (has_next) |
| 408 | { |
| 409 | csbi0 = next_bi; |
| 410 | csb0 = vlib_get_buffer (vm, csbi0); |
| 411 | src_left = csb0->current_length; |
| 412 | src_ptr = csb0->data; |
| 413 | } |
| 414 | else |
| 415 | { |
| 416 | ASSERT (total_src_left == 0); |
| 417 | break; |
| 418 | } |
| 419 | } |
| 420 | if (0 == dst_left && total_src_left) |
| 421 | { |
| 422 | if (do_tx_offloads) |
| 423 | calc_checksums (vm, cdb0); |
| 424 | n_tx_bytes += cdb0->current_length; |
| 425 | ASSERT (dbi < vec_len (ptd->split_buffers)); |
| 426 | cdb0 = vlib_get_buffer (vm, ptd->split_buffers[dbi++]); |
| 427 | tso_init_buf_from_template (vm, cdb0, b0, l234_sz, |
| 428 | gso_size, &dst_ptr, &dst_left, |
| 429 | next_tcp_seq, default_bflags); |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | tso_fixup_segmented_buf (cdb0, save_tcp_flags, is_ip6); |
| 434 | if (do_tx_offloads) |
| 435 | calc_checksums (vm, cdb0); |
| 436 | |
| 437 | n_tx_bytes += cdb0->current_length; |
| 438 | } |
| 439 | n_tx_bytes += b0->current_length; |
| 440 | return n_tx_bytes; |
| 441 | } |
| 442 | |
| 443 | static_always_inline void |
| 444 | drop_one_buffer_and_count (vlib_main_t * vm, vnet_main_t * vnm, |
| 445 | vlib_node_runtime_t * node, u32 * pbi0, |
| 446 | u32 drop_error_code) |
| 447 | { |
| 448 | u32 thread_index = vm->thread_index; |
| 449 | vnet_interface_output_runtime_t *rt = (void *) node->runtime_data; |
| 450 | |
| 451 | vlib_simple_counter_main_t *cm; |
| 452 | cm = |
| 453 | vec_elt_at_index (vnm->interface_main.sw_if_counters, |
| 454 | VNET_INTERFACE_COUNTER_TX_ERROR); |
| 455 | vlib_increment_simple_counter (cm, thread_index, rt->sw_if_index, 1); |
| 456 | |
| 457 | vlib_error_drop_buffers (vm, node, pbi0, |
| 458 | /* buffer stride */ 1, |
| 459 | /* n_buffers */ 1, |
| 460 | VNET_INTERFACE_OUTPUT_NEXT_DROP, |
| 461 | node->node_index, drop_error_code); |
| 462 | } |
| 463 | |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 464 | static_always_inline uword |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 465 | vnet_interface_output_node_inline_gso (vlib_main_t * vm, |
| 466 | vlib_node_runtime_t * node, |
| 467 | vlib_frame_t * frame, |
| 468 | vnet_main_t * vnm, |
| 469 | vnet_hw_interface_t * hi, |
| 470 | int do_tx_offloads, |
| 471 | int do_segmentation) |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 472 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 473 | vnet_interface_output_runtime_t *rt = (void *) node->runtime_data; |
| 474 | vnet_sw_interface_t *si; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 475 | u32 n_left_to_tx, *from, *from_end, *to_tx; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 476 | u32 n_bytes, n_buffers, n_packets; |
Damjan Marion | 363640d | 2017-03-06 11:53:10 +0100 | [diff] [blame] | 477 | 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] | 478 | u32 thread_index = vm->thread_index; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 479 | vnet_interface_main_t *im = &vnm->interface_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 480 | u32 next_index = VNET_INTERFACE_OUTPUT_NEXT_TX; |
Damjan Marion | 152e21d | 2016-11-29 14:55:43 +0100 | [diff] [blame] | 481 | u32 current_config_index = ~0; |
| 482 | u8 arc = im->output_feature_arc_index; |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 483 | vnet_interface_per_thread_data_t *ptd = |
| 484 | vec_elt_at_index (im->per_thread_data, thread_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 485 | |
| 486 | n_buffers = frame->n_vectors; |
| 487 | |
| 488 | if (node->flags & VLIB_NODE_FLAG_TRACE) |
| 489 | vnet_interface_output_trace (vm, node, frame, n_buffers); |
| 490 | |
Damjan Marion | a3d5986 | 2018-11-10 10:23:00 +0100 | [diff] [blame] | 491 | from = vlib_frame_vector_args (frame); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 492 | |
| 493 | if (rt->is_deleted) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 494 | return vlib_error_drop_buffers (vm, node, from, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 495 | /* buffer stride */ 1, |
| 496 | n_buffers, |
| 497 | VNET_INTERFACE_OUTPUT_NEXT_DROP, |
| 498 | node->node_index, |
| 499 | VNET_INTERFACE_OUTPUT_ERROR_INTERFACE_DELETED); |
| 500 | |
| 501 | si = vnet_get_sw_interface (vnm, rt->sw_if_index); |
| 502 | hi = vnet_get_sup_hw_interface (vnm, rt->sw_if_index); |
Steve Shin | 042a621 | 2017-07-07 14:57:46 -0700 | [diff] [blame] | 503 | if (!(si->flags & (VNET_SW_INTERFACE_FLAG_ADMIN_UP | |
| 504 | VNET_SW_INTERFACE_FLAG_BOND_SLAVE)) || |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 505 | !(hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 506 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 507 | vlib_simple_counter_main_t *cm; |
| 508 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 509 | cm = vec_elt_at_index (vnm->interface_main.sw_if_counters, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 510 | VNET_INTERFACE_COUNTER_TX_ERROR); |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 511 | vlib_increment_simple_counter (cm, thread_index, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 512 | rt->sw_if_index, n_buffers); |
| 513 | |
| 514 | return vlib_error_drop_buffers (vm, node, from, |
| 515 | /* buffer stride */ 1, |
| 516 | n_buffers, |
| 517 | VNET_INTERFACE_OUTPUT_NEXT_DROP, |
| 518 | node->node_index, |
| 519 | VNET_INTERFACE_OUTPUT_ERROR_INTERFACE_DOWN); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | from_end = from + n_buffers; |
| 523 | |
| 524 | /* Total byte count of all buffers. */ |
| 525 | n_bytes = 0; |
| 526 | n_packets = 0; |
| 527 | |
Damjan Marion | 152e21d | 2016-11-29 14:55:43 +0100 | [diff] [blame] | 528 | /* interface-output feature arc handling */ |
| 529 | if (PREDICT_FALSE (vnet_have_features (arc, rt->sw_if_index))) |
| 530 | { |
| 531 | vnet_feature_config_main_t *fcm; |
| 532 | fcm = vnet_feature_get_config_main (arc); |
| 533 | current_config_index = vnet_get_feature_config_index (arc, |
| 534 | rt->sw_if_index); |
| 535 | vnet_get_config_data (&fcm->config_main, ¤t_config_index, |
| 536 | &next_index, 0); |
| 537 | } |
| 538 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 539 | while (from < from_end) |
| 540 | { |
| 541 | /* Get new next frame since previous incomplete frame may have less |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 542 | than VNET_FRAME_SIZE vectors in it. */ |
| 543 | 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] | 544 | |
Damjan Marion | 363640d | 2017-03-06 11:53:10 +0100 | [diff] [blame] | 545 | while (from + 8 <= from_end && n_left_to_tx >= 4) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 546 | { |
Damjan Marion | 363640d | 2017-03-06 11:53:10 +0100 | [diff] [blame] | 547 | u32 bi0, bi1, bi2, bi3; |
| 548 | vlib_buffer_t *b0, *b1, *b2, *b3; |
| 549 | u32 tx_swif0, tx_swif1, tx_swif2, tx_swif3; |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 550 | u32 or_flags; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 551 | |
| 552 | /* Prefetch next iteration. */ |
Damjan Marion | 363640d | 2017-03-06 11:53:10 +0100 | [diff] [blame] | 553 | vlib_prefetch_buffer_with_index (vm, from[4], LOAD); |
| 554 | vlib_prefetch_buffer_with_index (vm, from[5], LOAD); |
| 555 | vlib_prefetch_buffer_with_index (vm, from[6], LOAD); |
| 556 | vlib_prefetch_buffer_with_index (vm, from[7], LOAD); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 557 | |
| 558 | bi0 = from[0]; |
| 559 | bi1 = from[1]; |
Damjan Marion | 363640d | 2017-03-06 11:53:10 +0100 | [diff] [blame] | 560 | bi2 = from[2]; |
| 561 | bi3 = from[3]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 562 | to_tx[0] = bi0; |
| 563 | to_tx[1] = bi1; |
Damjan Marion | 363640d | 2017-03-06 11:53:10 +0100 | [diff] [blame] | 564 | to_tx[2] = bi2; |
| 565 | to_tx[3] = bi3; |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 566 | if (!do_segmentation) |
| 567 | { |
| 568 | from += 4; |
| 569 | to_tx += 4; |
| 570 | n_left_to_tx -= 4; |
| 571 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 572 | |
| 573 | b0 = vlib_get_buffer (vm, bi0); |
| 574 | b1 = vlib_get_buffer (vm, bi1); |
Damjan Marion | 363640d | 2017-03-06 11:53:10 +0100 | [diff] [blame] | 575 | b2 = vlib_get_buffer (vm, bi2); |
| 576 | b3 = vlib_get_buffer (vm, bi3); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 577 | |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 578 | if (do_segmentation) |
| 579 | { |
| 580 | or_flags = b0->flags | b1->flags | b2->flags | b3->flags; |
| 581 | |
| 582 | /* go to single loop if we need TSO segmentation */ |
| 583 | if (PREDICT_FALSE (or_flags & VNET_BUFFER_F_GSO)) |
| 584 | break; |
| 585 | from += 4; |
| 586 | to_tx += 4; |
| 587 | n_left_to_tx -= 4; |
| 588 | } |
| 589 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 590 | /* Be grumpy about zero length buffers for benefit of |
| 591 | driver tx function. */ |
| 592 | ASSERT (b0->current_length > 0); |
| 593 | ASSERT (b1->current_length > 0); |
Damjan Marion | 363640d | 2017-03-06 11:53:10 +0100 | [diff] [blame] | 594 | ASSERT (b2->current_length > 0); |
| 595 | ASSERT (b3->current_length > 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 596 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 597 | n_bytes_b0 = vlib_buffer_length_in_chain (vm, b0); |
| 598 | n_bytes_b1 = vlib_buffer_length_in_chain (vm, b1); |
Damjan Marion | 363640d | 2017-03-06 11:53:10 +0100 | [diff] [blame] | 599 | n_bytes_b2 = vlib_buffer_length_in_chain (vm, b2); |
| 600 | n_bytes_b3 = vlib_buffer_length_in_chain (vm, b3); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 601 | tx_swif0 = vnet_buffer (b0)->sw_if_index[VLIB_TX]; |
| 602 | tx_swif1 = vnet_buffer (b1)->sw_if_index[VLIB_TX]; |
Damjan Marion | 363640d | 2017-03-06 11:53:10 +0100 | [diff] [blame] | 603 | tx_swif2 = vnet_buffer (b2)->sw_if_index[VLIB_TX]; |
| 604 | tx_swif3 = vnet_buffer (b3)->sw_if_index[VLIB_TX]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 605 | |
| 606 | n_bytes += n_bytes_b0 + n_bytes_b1; |
Damjan Marion | 363640d | 2017-03-06 11:53:10 +0100 | [diff] [blame] | 607 | n_bytes += n_bytes_b2 + n_bytes_b3; |
| 608 | n_packets += 4; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 609 | |
Damjan Marion | 152e21d | 2016-11-29 14:55:43 +0100 | [diff] [blame] | 610 | if (PREDICT_FALSE (current_config_index != ~0)) |
| 611 | { |
Damjan Marion | aa682a3 | 2018-04-26 22:45:40 +0200 | [diff] [blame] | 612 | vnet_buffer (b0)->feature_arc_index = arc; |
| 613 | vnet_buffer (b1)->feature_arc_index = arc; |
| 614 | vnet_buffer (b2)->feature_arc_index = arc; |
| 615 | vnet_buffer (b3)->feature_arc_index = arc; |
Damjan Marion | 152e21d | 2016-11-29 14:55:43 +0100 | [diff] [blame] | 616 | b0->current_config_index = current_config_index; |
| 617 | b1->current_config_index = current_config_index; |
Damjan Marion | 363640d | 2017-03-06 11:53:10 +0100 | [diff] [blame] | 618 | b2->current_config_index = current_config_index; |
| 619 | b3->current_config_index = current_config_index; |
Damjan Marion | 152e21d | 2016-11-29 14:55:43 +0100 | [diff] [blame] | 620 | } |
| 621 | |
Damjan Marion | 363640d | 2017-03-06 11:53:10 +0100 | [diff] [blame] | 622 | /* update vlan subif tx counts, if required */ |
Damjan Marion | 9c6ae5f | 2016-11-15 23:20:01 +0100 | [diff] [blame] | 623 | if (PREDICT_FALSE (tx_swif0 != rt->sw_if_index)) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 624 | { |
Damjan Marion | 9c6ae5f | 2016-11-15 23:20:01 +0100 | [diff] [blame] | 625 | vlib_increment_combined_counter (im->combined_sw_if_counters + |
| 626 | VNET_INTERFACE_COUNTER_TX, |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 627 | thread_index, tx_swif0, 1, |
Damjan Marion | 9c6ae5f | 2016-11-15 23:20:01 +0100 | [diff] [blame] | 628 | n_bytes_b0); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 629 | } |
Damjan Marion | 9c6ae5f | 2016-11-15 23:20:01 +0100 | [diff] [blame] | 630 | |
Damjan Marion | 9c6ae5f | 2016-11-15 23:20:01 +0100 | [diff] [blame] | 631 | if (PREDICT_FALSE (tx_swif1 != rt->sw_if_index)) |
| 632 | { |
| 633 | |
| 634 | vlib_increment_combined_counter (im->combined_sw_if_counters + |
| 635 | VNET_INTERFACE_COUNTER_TX, |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 636 | thread_index, tx_swif1, 1, |
Damjan Marion | 9c6ae5f | 2016-11-15 23:20:01 +0100 | [diff] [blame] | 637 | n_bytes_b1); |
| 638 | } |
Damjan Marion | 363640d | 2017-03-06 11:53:10 +0100 | [diff] [blame] | 639 | |
| 640 | if (PREDICT_FALSE (tx_swif2 != rt->sw_if_index)) |
| 641 | { |
| 642 | |
| 643 | vlib_increment_combined_counter (im->combined_sw_if_counters + |
| 644 | VNET_INTERFACE_COUNTER_TX, |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 645 | thread_index, tx_swif2, 1, |
Damjan Marion | 363640d | 2017-03-06 11:53:10 +0100 | [diff] [blame] | 646 | n_bytes_b2); |
| 647 | } |
| 648 | if (PREDICT_FALSE (tx_swif3 != rt->sw_if_index)) |
| 649 | { |
| 650 | |
| 651 | vlib_increment_combined_counter (im->combined_sw_if_counters + |
| 652 | VNET_INTERFACE_COUNTER_TX, |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 653 | thread_index, tx_swif3, 1, |
Damjan Marion | 363640d | 2017-03-06 11:53:10 +0100 | [diff] [blame] | 654 | n_bytes_b3); |
| 655 | } |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 656 | |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 657 | if (!do_segmentation) |
| 658 | or_flags = b0->flags | b1->flags | b2->flags | b3->flags; |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 659 | |
| 660 | if (do_tx_offloads) |
| 661 | { |
| 662 | if (or_flags & |
| 663 | (VNET_BUFFER_F_OFFLOAD_TCP_CKSUM | |
| 664 | VNET_BUFFER_F_OFFLOAD_UDP_CKSUM | |
| 665 | VNET_BUFFER_F_OFFLOAD_IP_CKSUM)) |
| 666 | { |
| 667 | calc_checksums (vm, b0); |
| 668 | calc_checksums (vm, b1); |
| 669 | calc_checksums (vm, b2); |
| 670 | calc_checksums (vm, b3); |
| 671 | } |
| 672 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | while (from + 1 <= from_end && n_left_to_tx >= 1) |
| 676 | { |
| 677 | u32 bi0; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 678 | vlib_buffer_t *b0; |
| 679 | u32 tx_swif0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 680 | |
| 681 | bi0 = from[0]; |
| 682 | to_tx[0] = bi0; |
| 683 | from += 1; |
| 684 | to_tx += 1; |
| 685 | n_left_to_tx -= 1; |
| 686 | |
| 687 | b0 = vlib_get_buffer (vm, bi0); |
| 688 | |
| 689 | /* Be grumpy about zero length buffers for benefit of |
| 690 | driver tx function. */ |
| 691 | ASSERT (b0->current_length > 0); |
| 692 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 693 | n_bytes_b0 = vlib_buffer_length_in_chain (vm, b0); |
| 694 | tx_swif0 = vnet_buffer (b0)->sw_if_index[VLIB_TX]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 695 | n_bytes += n_bytes_b0; |
| 696 | n_packets += 1; |
| 697 | |
Damjan Marion | 152e21d | 2016-11-29 14:55:43 +0100 | [diff] [blame] | 698 | if (PREDICT_FALSE (current_config_index != ~0)) |
| 699 | { |
Damjan Marion | aa682a3 | 2018-04-26 22:45:40 +0200 | [diff] [blame] | 700 | vnet_buffer (b0)->feature_arc_index = arc; |
Damjan Marion | 152e21d | 2016-11-29 14:55:43 +0100 | [diff] [blame] | 701 | b0->current_config_index = current_config_index; |
| 702 | } |
| 703 | |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 704 | if (do_segmentation) |
| 705 | { |
| 706 | if (PREDICT_FALSE (b0->flags & VNET_BUFFER_F_GSO)) |
| 707 | { |
| 708 | /* |
| 709 | * Undo the enqueue of the b0 - it is not going anywhere, |
| 710 | * and will be freed either after it's segmented or |
| 711 | * when dropped, if there is no buffers to segment into. |
| 712 | */ |
| 713 | to_tx -= 1; |
| 714 | n_left_to_tx += 1; |
| 715 | /* undo the counting. */ |
| 716 | n_bytes -= n_bytes_b0; |
| 717 | n_packets -= 1; |
| 718 | |
| 719 | u32 n_tx_bytes = 0; |
| 720 | |
| 721 | n_tx_bytes = |
| 722 | tso_segment_buffer (vm, ptd, do_tx_offloads, bi0, b0, |
| 723 | n_bytes_b0); |
| 724 | |
| 725 | if (PREDICT_FALSE (n_tx_bytes == 0)) |
| 726 | { |
| 727 | drop_one_buffer_and_count (vm, vnm, node, from - 1, |
| 728 | VNET_INTERFACE_OUTPUT_ERROR_NO_BUFFERS_FOR_GSO); |
| 729 | continue; |
| 730 | } |
| 731 | |
| 732 | u16 n_tx_bufs = vec_len (ptd->split_buffers); |
| 733 | u32 *from_tx_seg = ptd->split_buffers; |
| 734 | |
| 735 | while (n_tx_bufs > 0) |
| 736 | { |
| 737 | if (n_tx_bufs >= n_left_to_tx) |
| 738 | { |
| 739 | while (n_left_to_tx > 0) |
| 740 | { |
| 741 | to_tx[0] = from_tx_seg[0]; |
| 742 | to_tx += 1; |
| 743 | from_tx_seg += 1; |
| 744 | n_left_to_tx -= 1; |
| 745 | n_tx_bufs -= 1; |
| 746 | n_packets += 1; |
| 747 | } |
| 748 | vlib_put_next_frame (vm, node, next_index, |
| 749 | n_left_to_tx); |
| 750 | vlib_get_new_next_frame (vm, node, next_index, |
| 751 | to_tx, n_left_to_tx); |
| 752 | } |
| 753 | else |
| 754 | { |
| 755 | while (n_tx_bufs > 0) |
| 756 | { |
| 757 | to_tx[0] = from_tx_seg[0]; |
| 758 | to_tx += 1; |
| 759 | from_tx_seg += 1; |
| 760 | n_left_to_tx -= 1; |
| 761 | n_tx_bufs -= 1; |
| 762 | n_packets += 1; |
| 763 | } |
| 764 | } |
| 765 | } |
| 766 | n_bytes += n_tx_bytes; |
| 767 | if (PREDICT_FALSE (tx_swif0 != rt->sw_if_index)) |
| 768 | { |
| 769 | |
| 770 | vlib_increment_combined_counter |
| 771 | (im->combined_sw_if_counters + |
| 772 | VNET_INTERFACE_COUNTER_TX, thread_index, tx_swif0, |
| 773 | _vec_len (ptd->split_buffers), n_tx_bytes); |
| 774 | } |
| 775 | /* The buffers were enqueued. Reset the length */ |
| 776 | _vec_len (ptd->split_buffers) = 0; |
| 777 | /* Free the now segmented buffer */ |
| 778 | vlib_buffer_free_one (vm, bi0); |
| 779 | continue; |
| 780 | } |
| 781 | } |
| 782 | |
Damjan Marion | 9c6ae5f | 2016-11-15 23:20:01 +0100 | [diff] [blame] | 783 | if (PREDICT_FALSE (tx_swif0 != rt->sw_if_index)) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 784 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 785 | |
Damjan Marion | 9c6ae5f | 2016-11-15 23:20:01 +0100 | [diff] [blame] | 786 | vlib_increment_combined_counter (im->combined_sw_if_counters + |
| 787 | VNET_INTERFACE_COUNTER_TX, |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 788 | thread_index, tx_swif0, 1, |
Damjan Marion | 9c6ae5f | 2016-11-15 23:20:01 +0100 | [diff] [blame] | 789 | n_bytes_b0); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 790 | } |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 791 | |
| 792 | if (do_tx_offloads) |
| 793 | calc_checksums (vm, b0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 794 | } |
| 795 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 796 | vlib_put_next_frame (vm, node, next_index, n_left_to_tx); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | /* Update main interface stats. */ |
| 800 | vlib_increment_combined_counter (im->combined_sw_if_counters |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 801 | + VNET_INTERFACE_COUNTER_TX, |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 802 | thread_index, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 803 | rt->sw_if_index, n_packets, n_bytes); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 804 | return n_buffers; |
| 805 | } |
Filip Tehlar | 6266877 | 2019-03-04 03:33:32 -0800 | [diff] [blame^] | 806 | #endif /* CLIB_MARCH_VARIANT */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 807 | |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 808 | static_always_inline void vnet_interface_pcap_tx_trace |
| 809 | (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame, |
| 810 | int sw_if_index_from_buffer) |
| 811 | { |
| 812 | u32 n_left_from, *from; |
| 813 | u32 sw_if_index; |
| 814 | |
| 815 | if (PREDICT_TRUE (vm->pcap[VLIB_TX].pcap_enable == 0)) |
| 816 | return; |
| 817 | |
| 818 | if (sw_if_index_from_buffer == 0) |
| 819 | { |
| 820 | vnet_interface_output_runtime_t *rt = (void *) node->runtime_data; |
| 821 | sw_if_index = rt->sw_if_index; |
| 822 | } |
| 823 | else |
| 824 | sw_if_index = ~0; |
| 825 | |
| 826 | n_left_from = frame->n_vectors; |
| 827 | from = vlib_frame_vector_args (frame); |
| 828 | |
| 829 | while (n_left_from > 0) |
| 830 | { |
| 831 | u32 bi0 = from[0]; |
| 832 | vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0); |
| 833 | |
| 834 | if (sw_if_index_from_buffer) |
| 835 | sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_TX]; |
| 836 | |
| 837 | if (vm->pcap[VLIB_TX].pcap_sw_if_index == 0 || |
| 838 | vm->pcap[VLIB_TX].pcap_sw_if_index == sw_if_index) |
| 839 | pcap_add_buffer (&vm->pcap[VLIB_TX].pcap_main, vm, bi0, 512); |
| 840 | from++; |
| 841 | n_left_from--; |
| 842 | } |
| 843 | } |
| 844 | |
Filip Tehlar | 6266877 | 2019-03-04 03:33:32 -0800 | [diff] [blame^] | 845 | #ifndef CLIB_MARCH_VARIANT |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 846 | static_always_inline uword |
| 847 | vnet_interface_output_node_inline (vlib_main_t * vm, |
| 848 | vlib_node_runtime_t * node, |
| 849 | vlib_frame_t * frame, vnet_main_t * vnm, |
| 850 | vnet_hw_interface_t * hi, |
| 851 | int do_tx_offloads) |
| 852 | { |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 853 | vnet_interface_pcap_tx_trace (vm, node, frame, |
| 854 | 0 /* sw_if_index_from_buffer */ ); |
| 855 | |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 856 | /* |
| 857 | * The 3-headed "if" is here because we want to err on the side |
| 858 | * of not impacting the non-GSO performance - so for the more |
| 859 | * common case of no GSO interfaces we want to prevent the |
| 860 | * segmentation codepath from being there altogether. |
| 861 | */ |
| 862 | if (PREDICT_TRUE (vnm->interface_main.gso_interface_count == 0)) |
| 863 | return vnet_interface_output_node_inline_gso (vm, node, frame, vnm, hi, |
| 864 | do_tx_offloads, |
| 865 | /* do_segmentation */ 0); |
| 866 | else if (hi->flags & VNET_HW_INTERFACE_FLAG_SUPPORTS_GSO) |
| 867 | return vnet_interface_output_node_inline_gso (vm, node, frame, vnm, hi, |
| 868 | do_tx_offloads, |
| 869 | /* do_segmentation */ 0); |
| 870 | else |
| 871 | return vnet_interface_output_node_inline_gso (vm, node, frame, vnm, hi, |
| 872 | do_tx_offloads, |
| 873 | /* do_segmentation */ 1); |
| 874 | } |
| 875 | |
Damjan Marion | 652d2e1 | 2019-02-02 00:15:27 +0100 | [diff] [blame] | 876 | uword |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 877 | vnet_interface_output_node (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 878 | vlib_frame_t * frame) |
| 879 | { |
| 880 | vnet_main_t *vnm = vnet_get_main (); |
| 881 | vnet_hw_interface_t *hi; |
| 882 | vnet_interface_output_runtime_t *rt = (void *) node->runtime_data; |
| 883 | hi = vnet_get_sup_hw_interface (vnm, rt->sw_if_index); |
| 884 | |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 885 | vnet_interface_pcap_tx_trace (vm, node, frame, |
| 886 | 0 /* sw_if_index_from_buffer */ ); |
| 887 | |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 888 | if (hi->flags & VNET_HW_INTERFACE_FLAG_SUPPORTS_TX_L4_CKSUM_OFFLOAD) |
| 889 | return vnet_interface_output_node_inline (vm, node, frame, vnm, hi, |
| 890 | /* do_tx_offloads */ 0); |
| 891 | else |
| 892 | return vnet_interface_output_node_inline (vm, node, frame, vnm, hi, |
| 893 | /* do_tx_offloads */ 1); |
| 894 | } |
Filip Tehlar | 6266877 | 2019-03-04 03:33:32 -0800 | [diff] [blame^] | 895 | #endif /* CLIB_MARCH_VARIANT */ |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 896 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 897 | /* Use buffer's sw_if_index[VNET_TX] to choose output interface. */ |
Filip Tehlar | 6266877 | 2019-03-04 03:33:32 -0800 | [diff] [blame^] | 898 | VLIB_NODE_FN (vnet_per_buffer_interface_output_node) (vlib_main_t * vm, |
| 899 | vlib_node_runtime_t * |
| 900 | node, |
| 901 | vlib_frame_t * frame) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 902 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 903 | vnet_main_t *vnm = vnet_get_main (); |
| 904 | u32 n_left_to_next, *from, *to_next; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 905 | u32 n_left_from, next_index; |
| 906 | |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 907 | vnet_interface_pcap_tx_trace (vm, node, frame, |
| 908 | 1 /* sw_if_index_from_buffer */ ); |
| 909 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 910 | n_left_from = frame->n_vectors; |
| 911 | |
Damjan Marion | a3d5986 | 2018-11-10 10:23:00 +0100 | [diff] [blame] | 912 | from = vlib_frame_vector_args (frame); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 913 | next_index = node->cached_next_index; |
| 914 | |
| 915 | while (n_left_from > 0) |
| 916 | { |
| 917 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
| 918 | |
| 919 | while (n_left_from >= 4 && n_left_to_next >= 2) |
| 920 | { |
| 921 | u32 bi0, bi1, next0, next1; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 922 | vlib_buffer_t *b0, *b1; |
| 923 | vnet_hw_interface_t *hi0, *hi1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 924 | |
| 925 | /* Prefetch next iteration. */ |
| 926 | vlib_prefetch_buffer_with_index (vm, from[2], LOAD); |
| 927 | vlib_prefetch_buffer_with_index (vm, from[3], LOAD); |
| 928 | |
| 929 | bi0 = from[0]; |
| 930 | bi1 = from[1]; |
| 931 | to_next[0] = bi0; |
| 932 | to_next[1] = bi1; |
| 933 | from += 2; |
| 934 | to_next += 2; |
| 935 | n_left_to_next -= 2; |
| 936 | n_left_from -= 2; |
| 937 | |
| 938 | b0 = vlib_get_buffer (vm, bi0); |
| 939 | b1 = vlib_get_buffer (vm, bi1); |
| 940 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 941 | hi0 = |
| 942 | vnet_get_sup_hw_interface (vnm, |
| 943 | vnet_buffer (b0)->sw_if_index |
| 944 | [VLIB_TX]); |
| 945 | hi1 = |
| 946 | vnet_get_sup_hw_interface (vnm, |
| 947 | vnet_buffer (b1)->sw_if_index |
| 948 | [VLIB_TX]); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 949 | |
John Lo | e5453d0 | 2018-01-23 19:21:34 -0500 | [diff] [blame] | 950 | next0 = hi0->output_node_next_index; |
| 951 | next1 = hi1->output_node_next_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 952 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 953 | vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next, |
| 954 | n_left_to_next, bi0, bi1, next0, |
| 955 | next1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 956 | } |
| 957 | |
| 958 | while (n_left_from > 0 && n_left_to_next > 0) |
| 959 | { |
| 960 | u32 bi0, next0; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 961 | vlib_buffer_t *b0; |
| 962 | vnet_hw_interface_t *hi0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 963 | |
| 964 | bi0 = from[0]; |
| 965 | to_next[0] = bi0; |
| 966 | from += 1; |
| 967 | to_next += 1; |
| 968 | n_left_to_next -= 1; |
| 969 | n_left_from -= 1; |
| 970 | |
| 971 | b0 = vlib_get_buffer (vm, bi0); |
| 972 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 973 | hi0 = |
| 974 | vnet_get_sup_hw_interface (vnm, |
| 975 | vnet_buffer (b0)->sw_if_index |
| 976 | [VLIB_TX]); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 977 | |
John Lo | e5453d0 | 2018-01-23 19:21:34 -0500 | [diff] [blame] | 978 | next0 = hi0->output_node_next_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 979 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 980 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next, |
| 981 | n_left_to_next, bi0, next0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 982 | } |
| 983 | |
| 984 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 985 | } |
| 986 | |
| 987 | return frame->n_vectors; |
| 988 | } |
| 989 | |
| 990 | always_inline u32 |
| 991 | counter_index (vlib_main_t * vm, vlib_error_t e) |
| 992 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 993 | vlib_node_t *n; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 994 | u32 ci, ni; |
| 995 | |
| 996 | ni = vlib_error_get_node (e); |
| 997 | n = vlib_get_node (vm, ni); |
| 998 | |
| 999 | ci = vlib_error_get_code (e); |
| 1000 | ASSERT (ci < n->n_errors); |
| 1001 | |
| 1002 | ci += n->error_heap_index; |
| 1003 | |
| 1004 | return ci; |
| 1005 | } |
| 1006 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1007 | static u8 * |
| 1008 | format_vnet_error_trace (u8 * s, va_list * va) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1009 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1010 | vlib_main_t *vm = va_arg (*va, vlib_main_t *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1011 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1012 | vlib_error_t *e = va_arg (*va, vlib_error_t *); |
| 1013 | vlib_node_t *error_node; |
| 1014 | vlib_error_main_t *em = &vm->error_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1015 | u32 i; |
| 1016 | |
| 1017 | error_node = vlib_get_node (vm, vlib_error_get_node (e[0])); |
| 1018 | i = counter_index (vm, e[0]); |
| 1019 | s = format (s, "%v: %s", error_node->name, em->error_strings_heap[i]); |
| 1020 | |
| 1021 | return s; |
| 1022 | } |
| 1023 | |
| 1024 | static void |
| 1025 | trace_errors_with_buffers (vlib_main_t * vm, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1026 | vlib_node_runtime_t * node, vlib_frame_t * frame) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1027 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1028 | u32 n_left, *buffers; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1029 | |
| 1030 | buffers = vlib_frame_vector_args (frame); |
| 1031 | n_left = frame->n_vectors; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1032 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1033 | while (n_left >= 4) |
| 1034 | { |
| 1035 | u32 bi0, bi1; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1036 | vlib_buffer_t *b0, *b1; |
| 1037 | vlib_error_t *t0, *t1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1038 | |
| 1039 | /* Prefetch next iteration. */ |
| 1040 | vlib_prefetch_buffer_with_index (vm, buffers[2], LOAD); |
| 1041 | vlib_prefetch_buffer_with_index (vm, buffers[3], LOAD); |
| 1042 | |
| 1043 | bi0 = buffers[0]; |
| 1044 | bi1 = buffers[1]; |
| 1045 | |
| 1046 | b0 = vlib_get_buffer (vm, bi0); |
| 1047 | b1 = vlib_get_buffer (vm, bi1); |
| 1048 | |
| 1049 | if (b0->flags & VLIB_BUFFER_IS_TRACED) |
| 1050 | { |
| 1051 | t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0])); |
| 1052 | t0[0] = b0->error; |
| 1053 | } |
| 1054 | if (b1->flags & VLIB_BUFFER_IS_TRACED) |
| 1055 | { |
| 1056 | t1 = vlib_add_trace (vm, node, b1, sizeof (t1[0])); |
| 1057 | t1[0] = b1->error; |
| 1058 | } |
| 1059 | buffers += 2; |
| 1060 | n_left -= 2; |
| 1061 | } |
| 1062 | |
| 1063 | while (n_left >= 1) |
| 1064 | { |
| 1065 | u32 bi0; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1066 | vlib_buffer_t *b0; |
| 1067 | vlib_error_t *t0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1068 | |
| 1069 | bi0 = buffers[0]; |
| 1070 | |
| 1071 | b0 = vlib_get_buffer (vm, bi0); |
| 1072 | |
| 1073 | if (b0->flags & VLIB_BUFFER_IS_TRACED) |
| 1074 | { |
| 1075 | t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0])); |
| 1076 | t0[0] = b0->error; |
| 1077 | } |
| 1078 | buffers += 1; |
| 1079 | n_left -= 1; |
| 1080 | } |
| 1081 | } |
| 1082 | |
| 1083 | static u8 * |
| 1084 | validate_error (vlib_main_t * vm, vlib_error_t * e, u32 index) |
| 1085 | { |
| 1086 | uword node_index = vlib_error_get_node (e[0]); |
| 1087 | uword code = vlib_error_get_code (e[0]); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1088 | vlib_node_t *n; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1089 | |
| 1090 | if (node_index >= vec_len (vm->node_main.nodes)) |
| 1091 | return format (0, "[%d], node index out of range 0x%x, error 0x%x", |
| 1092 | index, node_index, e[0]); |
| 1093 | |
| 1094 | n = vlib_get_node (vm, node_index); |
| 1095 | if (code >= n->n_errors) |
| 1096 | return format (0, "[%d], code %d out of range for node %v", |
| 1097 | index, code, n->name); |
| 1098 | |
| 1099 | return 0; |
| 1100 | } |
| 1101 | |
| 1102 | static u8 * |
| 1103 | validate_error_frame (vlib_main_t * vm, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1104 | vlib_node_runtime_t * node, vlib_frame_t * f) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1105 | { |
Damjan Marion | a3d5986 | 2018-11-10 10:23:00 +0100 | [diff] [blame] | 1106 | u32 *buffers = vlib_frame_vector_args (f); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1107 | vlib_buffer_t *b; |
| 1108 | u8 *msg = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1109 | uword i; |
| 1110 | |
| 1111 | for (i = 0; i < f->n_vectors; i++) |
| 1112 | { |
| 1113 | b = vlib_get_buffer (vm, buffers[i]); |
| 1114 | msg = validate_error (vm, &b->error, i); |
| 1115 | if (msg) |
| 1116 | return msg; |
| 1117 | } |
| 1118 | |
| 1119 | return msg; |
| 1120 | } |
| 1121 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1122 | typedef enum |
| 1123 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1124 | VNET_ERROR_DISPOSITION_DROP, |
| 1125 | VNET_ERROR_DISPOSITION_PUNT, |
| 1126 | VNET_ERROR_N_DISPOSITION, |
| 1127 | } vnet_error_disposition_t; |
| 1128 | |
| 1129 | always_inline void |
| 1130 | do_packet (vlib_main_t * vm, vlib_error_t a) |
| 1131 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1132 | vlib_error_main_t *em = &vm->error_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1133 | u32 i = counter_index (vm, a); |
| 1134 | em->counters[i] += 1; |
| 1135 | vlib_error_elog_count (vm, i, 1); |
| 1136 | } |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1137 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1138 | static_always_inline uword |
| 1139 | process_drop_punt (vlib_main_t * vm, |
| 1140 | vlib_node_runtime_t * node, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1141 | vlib_frame_t * frame, vnet_error_disposition_t disposition) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1142 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1143 | vnet_main_t *vnm = vnet_get_main (); |
| 1144 | vlib_error_main_t *em = &vm->error_main; |
| 1145 | u32 *buffers, *first_buffer; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1146 | vlib_error_t current_error; |
| 1147 | u32 current_counter_index, n_errors_left; |
| 1148 | u32 current_sw_if_index, n_errors_current_sw_if_index; |
| 1149 | u64 current_counter; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1150 | vlib_simple_counter_main_t *cm; |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 1151 | u32 thread_index = vm->thread_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1152 | |
| 1153 | static vlib_error_t memory[VNET_ERROR_N_DISPOSITION]; |
| 1154 | static char memory_init[VNET_ERROR_N_DISPOSITION]; |
| 1155 | |
Damjan Marion | a3d5986 | 2018-11-10 10:23:00 +0100 | [diff] [blame] | 1156 | buffers = vlib_frame_vector_args (frame); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1157 | first_buffer = buffers; |
| 1158 | |
| 1159 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1160 | vlib_buffer_t *b = vlib_get_buffer (vm, first_buffer[0]); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1161 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1162 | if (!memory_init[disposition]) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1163 | { |
| 1164 | memory_init[disposition] = 1; |
| 1165 | memory[disposition] = b->error; |
| 1166 | } |
| 1167 | |
| 1168 | current_sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_RX]; |
| 1169 | n_errors_current_sw_if_index = 0; |
| 1170 | } |
| 1171 | |
| 1172 | current_error = memory[disposition]; |
| 1173 | current_counter_index = counter_index (vm, memory[disposition]); |
| 1174 | current_counter = em->counters[current_counter_index]; |
| 1175 | |
| 1176 | if (node->flags & VLIB_NODE_FLAG_TRACE) |
| 1177 | trace_errors_with_buffers (vm, node, frame); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1178 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1179 | n_errors_left = frame->n_vectors; |
| 1180 | cm = vec_elt_at_index (vnm->interface_main.sw_if_counters, |
| 1181 | (disposition == VNET_ERROR_DISPOSITION_PUNT |
| 1182 | ? VNET_INTERFACE_COUNTER_PUNT |
| 1183 | : VNET_INTERFACE_COUNTER_DROP)); |
| 1184 | |
| 1185 | while (n_errors_left >= 2) |
| 1186 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1187 | vlib_buffer_t *b0, *b1; |
| 1188 | vnet_sw_interface_t *sw_if0, *sw_if1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1189 | vlib_error_t e0, e1; |
| 1190 | u32 bi0, bi1; |
| 1191 | u32 sw_if_index0, sw_if_index1; |
| 1192 | |
| 1193 | bi0 = buffers[0]; |
| 1194 | bi1 = buffers[1]; |
| 1195 | |
| 1196 | buffers += 2; |
| 1197 | n_errors_left -= 2; |
| 1198 | |
| 1199 | b0 = vlib_get_buffer (vm, bi0); |
| 1200 | b1 = vlib_get_buffer (vm, bi1); |
| 1201 | |
| 1202 | e0 = b0->error; |
| 1203 | e1 = b1->error; |
| 1204 | |
| 1205 | sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX]; |
| 1206 | sw_if_index1 = vnet_buffer (b1)->sw_if_index[VLIB_RX]; |
| 1207 | |
| 1208 | /* Speculate that sw_if_index == sw_if_index[01]. */ |
| 1209 | n_errors_current_sw_if_index += 2; |
| 1210 | |
| 1211 | /* Speculatively assume all 2 (node, code) pairs are equal |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1212 | to current (node, code). */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1213 | current_counter += 2; |
| 1214 | |
| 1215 | if (PREDICT_FALSE (e0 != current_error |
| 1216 | || e1 != current_error |
| 1217 | || sw_if_index0 != current_sw_if_index |
| 1218 | || sw_if_index1 != current_sw_if_index)) |
| 1219 | { |
| 1220 | current_counter -= 2; |
| 1221 | n_errors_current_sw_if_index -= 2; |
| 1222 | |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 1223 | vlib_increment_simple_counter (cm, thread_index, sw_if_index0, 1); |
| 1224 | vlib_increment_simple_counter (cm, thread_index, sw_if_index1, 1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1225 | |
| 1226 | /* Increment super-interface drop/punt counters for |
| 1227 | sub-interfaces. */ |
| 1228 | sw_if0 = vnet_get_sw_interface (vnm, sw_if_index0); |
| 1229 | vlib_increment_simple_counter |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 1230 | (cm, thread_index, sw_if0->sup_sw_if_index, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1231 | sw_if0->sup_sw_if_index != sw_if_index0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1232 | |
| 1233 | sw_if1 = vnet_get_sw_interface (vnm, sw_if_index1); |
| 1234 | vlib_increment_simple_counter |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 1235 | (cm, thread_index, sw_if1->sup_sw_if_index, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1236 | sw_if1->sup_sw_if_index != sw_if_index1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1237 | |
| 1238 | em->counters[current_counter_index] = current_counter; |
| 1239 | do_packet (vm, e0); |
| 1240 | do_packet (vm, e1); |
| 1241 | |
| 1242 | /* For 2 repeated errors, change current error. */ |
| 1243 | if (e0 == e1 && e1 != current_error) |
| 1244 | { |
| 1245 | current_error = e0; |
| 1246 | current_counter_index = counter_index (vm, e0); |
| 1247 | } |
| 1248 | current_counter = em->counters[current_counter_index]; |
| 1249 | } |
| 1250 | } |
| 1251 | |
| 1252 | while (n_errors_left >= 1) |
| 1253 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1254 | vlib_buffer_t *b0; |
| 1255 | vnet_sw_interface_t *sw_if0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1256 | vlib_error_t e0; |
| 1257 | u32 bi0, sw_if_index0; |
| 1258 | |
| 1259 | bi0 = buffers[0]; |
| 1260 | |
| 1261 | buffers += 1; |
| 1262 | n_errors_left -= 1; |
| 1263 | current_counter += 1; |
| 1264 | |
| 1265 | b0 = vlib_get_buffer (vm, bi0); |
| 1266 | e0 = b0->error; |
| 1267 | |
| 1268 | sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX]; |
| 1269 | |
| 1270 | /* Increment drop/punt counters. */ |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 1271 | vlib_increment_simple_counter (cm, thread_index, sw_if_index0, 1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1272 | |
| 1273 | /* Increment super-interface drop/punt counters for sub-interfaces. */ |
| 1274 | sw_if0 = vnet_get_sw_interface (vnm, sw_if_index0); |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 1275 | vlib_increment_simple_counter (cm, thread_index, |
| 1276 | sw_if0->sup_sw_if_index, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1277 | sw_if0->sup_sw_if_index != sw_if_index0); |
| 1278 | |
| 1279 | if (PREDICT_FALSE (e0 != current_error)) |
| 1280 | { |
| 1281 | current_counter -= 1; |
| 1282 | |
| 1283 | vlib_error_elog_count (vm, current_counter_index, |
| 1284 | (current_counter |
| 1285 | - em->counters[current_counter_index])); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1286 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1287 | em->counters[current_counter_index] = current_counter; |
| 1288 | |
| 1289 | do_packet (vm, e0); |
| 1290 | current_error = e0; |
| 1291 | current_counter_index = counter_index (vm, e0); |
| 1292 | current_counter = em->counters[current_counter_index]; |
| 1293 | } |
| 1294 | } |
| 1295 | |
| 1296 | if (n_errors_current_sw_if_index > 0) |
| 1297 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1298 | vnet_sw_interface_t *si; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1299 | |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 1300 | vlib_increment_simple_counter (cm, thread_index, current_sw_if_index, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1301 | n_errors_current_sw_if_index); |
| 1302 | |
| 1303 | si = vnet_get_sw_interface (vnm, current_sw_if_index); |
| 1304 | if (si->sup_sw_if_index != current_sw_if_index) |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 1305 | vlib_increment_simple_counter (cm, thread_index, si->sup_sw_if_index, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1306 | n_errors_current_sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1307 | } |
| 1308 | |
| 1309 | vlib_error_elog_count (vm, current_counter_index, |
| 1310 | (current_counter |
| 1311 | - em->counters[current_counter_index])); |
| 1312 | |
| 1313 | /* Return cached counter. */ |
| 1314 | em->counters[current_counter_index] = current_counter; |
| 1315 | |
| 1316 | /* Save memory for next iteration. */ |
| 1317 | memory[disposition] = current_error; |
| 1318 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1319 | if (disposition == VNET_ERROR_DISPOSITION_DROP || !vm->os_punt_frame) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1320 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1321 | vlib_buffer_free (vm, first_buffer, frame->n_vectors); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1322 | |
| 1323 | /* If there is no punt function, free the frame as well. */ |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1324 | if (disposition == VNET_ERROR_DISPOSITION_PUNT && !vm->os_punt_frame) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1325 | vlib_frame_free (vm, node, frame); |
| 1326 | } |
| 1327 | else |
| 1328 | vm->os_punt_frame (vm, node, frame); |
| 1329 | |
| 1330 | return frame->n_vectors; |
| 1331 | } |
| 1332 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1333 | static inline void |
| 1334 | pcap_drop_trace (vlib_main_t * vm, |
| 1335 | vnet_interface_main_t * im, vlib_frame_t * f) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1336 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1337 | u32 *from; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1338 | u32 n_left = f->n_vectors; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1339 | vlib_buffer_t *b0, *p1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1340 | u32 bi0; |
| 1341 | i16 save_current_data; |
| 1342 | u16 save_current_length; |
| 1343 | |
| 1344 | from = vlib_frame_vector_args (f); |
| 1345 | |
| 1346 | while (n_left > 0) |
| 1347 | { |
| 1348 | if (PREDICT_TRUE (n_left > 1)) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1349 | { |
| 1350 | p1 = vlib_get_buffer (vm, from[1]); |
| 1351 | vlib_prefetch_buffer_header (p1, LOAD); |
| 1352 | } |
| 1353 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1354 | bi0 = from[0]; |
| 1355 | b0 = vlib_get_buffer (vm, bi0); |
| 1356 | from++; |
| 1357 | n_left--; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1358 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1359 | /* See if we're pointedly ignoring this specific error */ |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1360 | if (im->pcap_drop_filter_hash |
| 1361 | && hash_get (im->pcap_drop_filter_hash, b0->error)) |
| 1362 | continue; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1363 | |
| 1364 | /* Trace all drops, or drops received on a specific interface */ |
| 1365 | if (im->pcap_sw_if_index == 0 || |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1366 | im->pcap_sw_if_index == vnet_buffer (b0)->sw_if_index[VLIB_RX]) |
| 1367 | { |
| 1368 | save_current_data = b0->current_data; |
| 1369 | save_current_length = b0->current_length; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1370 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1371 | /* |
| 1372 | * Typically, we'll need to rewind the buffer |
| 1373 | */ |
| 1374 | if (b0->current_data > 0) |
| 1375 | vlib_buffer_advance (b0, (word) - b0->current_data); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1376 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1377 | pcap_add_buffer (&im->pcap_main, vm, bi0, 512); |
| 1378 | |
| 1379 | b0->current_data = save_current_data; |
| 1380 | b0->current_length = save_current_length; |
| 1381 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1382 | } |
| 1383 | } |
| 1384 | |
Filip Tehlar | 6266877 | 2019-03-04 03:33:32 -0800 | [diff] [blame^] | 1385 | #ifndef CLIB_MARCH_VARIANT |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1386 | void |
| 1387 | 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] | 1388 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1389 | vnet_interface_main_t *im = &vnet_get_main ()->interface_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1390 | |
| 1391 | if (im->pcap_drop_filter_hash == 0) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1392 | im->pcap_drop_filter_hash = hash_create (0, sizeof (uword)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1393 | |
| 1394 | if (is_add) |
| 1395 | hash_set (im->pcap_drop_filter_hash, error_index, 1); |
| 1396 | else |
| 1397 | hash_unset (im->pcap_drop_filter_hash, error_index); |
| 1398 | } |
Filip Tehlar | 6266877 | 2019-03-04 03:33:32 -0800 | [diff] [blame^] | 1399 | #endif /* CLIB_MARCH_VARIANT */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1400 | |
Filip Tehlar | 6266877 | 2019-03-04 03:33:32 -0800 | [diff] [blame^] | 1401 | VLIB_NODE_FN (drop_buffers) (vlib_main_t * vm, |
| 1402 | vlib_node_runtime_t * node, vlib_frame_t * frame) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1403 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1404 | vnet_interface_main_t *im = &vnet_get_main ()->interface_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1405 | |
| 1406 | if (PREDICT_FALSE (im->drop_pcap_enable)) |
| 1407 | pcap_drop_trace (vm, im, frame); |
| 1408 | |
| 1409 | return process_drop_punt (vm, node, frame, VNET_ERROR_DISPOSITION_DROP); |
| 1410 | } |
| 1411 | |
Filip Tehlar | 6266877 | 2019-03-04 03:33:32 -0800 | [diff] [blame^] | 1412 | VLIB_NODE_FN (punt_buffers) (vlib_main_t * vm, |
| 1413 | vlib_node_runtime_t * node, vlib_frame_t * frame) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1414 | { |
| 1415 | return process_drop_punt (vm, node, frame, VNET_ERROR_DISPOSITION_PUNT); |
| 1416 | } |
| 1417 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1418 | /* *INDENT-OFF* */ |
Filip Tehlar | 6266877 | 2019-03-04 03:33:32 -0800 | [diff] [blame^] | 1419 | VLIB_REGISTER_NODE (drop_buffers) = { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1420 | .name = "error-drop", |
| 1421 | .flags = VLIB_NODE_FLAG_IS_DROP, |
| 1422 | .vector_size = sizeof (u32), |
| 1423 | .format_trace = format_vnet_error_trace, |
| 1424 | .validate_frame = validate_error_frame, |
| 1425 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1426 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1427 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1428 | /* *INDENT-OFF* */ |
Filip Tehlar | 6266877 | 2019-03-04 03:33:32 -0800 | [diff] [blame^] | 1429 | VLIB_REGISTER_NODE (punt_buffers) = { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1430 | .flags = (VLIB_NODE_FLAG_FRAME_NO_FREE_AFTER_DISPATCH |
| 1431 | | VLIB_NODE_FLAG_IS_PUNT), |
| 1432 | .name = "error-punt", |
| 1433 | .vector_size = sizeof (u32), |
| 1434 | .format_trace = format_vnet_error_trace, |
| 1435 | .validate_frame = validate_error_frame, |
| 1436 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1437 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1438 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1439 | /* *INDENT-OFF* */ |
Filip Tehlar | 6266877 | 2019-03-04 03:33:32 -0800 | [diff] [blame^] | 1440 | VLIB_REGISTER_NODE (vnet_per_buffer_interface_output_node) = { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1441 | .name = "interface-output", |
| 1442 | .vector_size = sizeof (u32), |
| 1443 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1444 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1445 | |
Dave Barach | 8704097 | 2019-01-24 15:12:53 -0500 | [diff] [blame] | 1446 | /* Convenience node to drop a vector of buffers with a "misc error". */ |
| 1447 | static uword |
| 1448 | misc_drop_buffers (vlib_main_t * vm, |
| 1449 | vlib_node_runtime_t * node, vlib_frame_t * frame) |
| 1450 | { |
| 1451 | return vlib_error_drop_buffers (vm, node, vlib_frame_vector_args (frame), |
| 1452 | /* buffer stride */ 1, |
| 1453 | frame->n_vectors, |
| 1454 | /* next */ 0, |
| 1455 | node->node_index, |
| 1456 | /* error */ 0); |
| 1457 | } |
| 1458 | |
| 1459 | static char *misc_drop_buffers_error_strings[] = { |
| 1460 | [0] = "misc. errors", |
| 1461 | }; |
| 1462 | |
| 1463 | /* *INDENT-OFF* */ |
| 1464 | VLIB_REGISTER_NODE (misc_drop_buffers_node,static) = { |
| 1465 | .function = misc_drop_buffers, |
| 1466 | .name = "misc-drop-buffers", |
| 1467 | .vector_size = sizeof (u32), |
| 1468 | .n_errors = 1, |
| 1469 | .n_next_nodes = 1, |
| 1470 | .next_nodes = { |
| 1471 | "error-drop", |
| 1472 | }, |
| 1473 | .error_strings = misc_drop_buffers_error_strings, |
| 1474 | }; |
| 1475 | /* *INDENT-ON* */ |
| 1476 | |
Damjan Marion | 152e21d | 2016-11-29 14:55:43 +0100 | [diff] [blame] | 1477 | static uword |
| 1478 | interface_tx_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 1479 | vlib_frame_t * from_frame) |
| 1480 | { |
| 1481 | vnet_main_t *vnm = vnet_get_main (); |
| 1482 | u32 last_sw_if_index = ~0; |
| 1483 | vlib_frame_t *to_frame = 0; |
| 1484 | vnet_hw_interface_t *hw = 0; |
| 1485 | u32 *from, *to_next = 0; |
| 1486 | u32 n_left_from; |
| 1487 | |
| 1488 | from = vlib_frame_vector_args (from_frame); |
| 1489 | n_left_from = from_frame->n_vectors; |
| 1490 | while (n_left_from > 0) |
| 1491 | { |
| 1492 | u32 bi0; |
| 1493 | vlib_buffer_t *b0; |
| 1494 | u32 sw_if_index0; |
| 1495 | |
| 1496 | bi0 = from[0]; |
| 1497 | from++; |
| 1498 | n_left_from--; |
| 1499 | b0 = vlib_get_buffer (vm, bi0); |
| 1500 | sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_TX]; |
| 1501 | |
| 1502 | if (PREDICT_FALSE ((last_sw_if_index != sw_if_index0) || to_frame == 0)) |
| 1503 | { |
| 1504 | if (to_frame) |
| 1505 | { |
| 1506 | hw = vnet_get_sup_hw_interface (vnm, last_sw_if_index); |
| 1507 | vlib_put_frame_to_node (vm, hw->tx_node_index, to_frame); |
| 1508 | } |
| 1509 | last_sw_if_index = sw_if_index0; |
| 1510 | hw = vnet_get_sup_hw_interface (vnm, sw_if_index0); |
| 1511 | to_frame = vlib_get_frame_to_node (vm, hw->tx_node_index); |
| 1512 | to_next = vlib_frame_vector_args (to_frame); |
| 1513 | } |
| 1514 | |
| 1515 | to_next[0] = bi0; |
| 1516 | to_next++; |
| 1517 | to_frame->n_vectors++; |
| 1518 | } |
| 1519 | vlib_put_frame_to_node (vm, hw->tx_node_index, to_frame); |
| 1520 | return from_frame->n_vectors; |
| 1521 | } |
| 1522 | |
| 1523 | /* *INDENT-OFF* */ |
| 1524 | VLIB_REGISTER_NODE (interface_tx, static) = { |
| 1525 | .function = interface_tx_node_fn, |
| 1526 | .name = "interface-tx", |
| 1527 | .vector_size = sizeof (u32), |
| 1528 | .n_next_nodes = 1, |
| 1529 | .next_nodes = { |
| 1530 | [0] = "error-drop", |
| 1531 | }, |
| 1532 | }; |
| 1533 | |
| 1534 | VNET_FEATURE_ARC_INIT (interface_output, static) = |
| 1535 | { |
| 1536 | .arc_name = "interface-output", |
| 1537 | .start_nodes = VNET_FEATURES (0), |
Dave Barach | a25def7 | 2018-11-26 11:04:45 -0500 | [diff] [blame] | 1538 | .last_in_arc = "interface-tx", |
Damjan Marion | 152e21d | 2016-11-29 14:55:43 +0100 | [diff] [blame] | 1539 | .arc_index_ptr = &vnet_main.interface_main.output_feature_arc_index, |
| 1540 | }; |
| 1541 | |
Pavel Kotucek | 3a2a1c4 | 2016-12-06 10:10:10 +0100 | [diff] [blame] | 1542 | VNET_FEATURE_INIT (span_tx, static) = { |
| 1543 | .arc_name = "interface-output", |
| 1544 | .node_name = "span-output", |
| 1545 | .runs_before = VNET_FEATURES ("interface-tx"), |
| 1546 | }; |
| 1547 | |
Matthew Smith | 537eeec | 2018-04-09 11:49:20 -0500 | [diff] [blame] | 1548 | VNET_FEATURE_INIT (ipsec_if_tx, static) = { |
| 1549 | .arc_name = "interface-output", |
| 1550 | .node_name = "ipsec-if-output", |
| 1551 | .runs_before = VNET_FEATURES ("interface-tx"), |
| 1552 | }; |
| 1553 | |
Damjan Marion | 152e21d | 2016-11-29 14:55:43 +0100 | [diff] [blame] | 1554 | VNET_FEATURE_INIT (interface_tx, static) = { |
| 1555 | .arc_name = "interface-output", |
| 1556 | .node_name = "interface-tx", |
| 1557 | .runs_before = 0, |
| 1558 | }; |
| 1559 | /* *INDENT-ON* */ |
| 1560 | |
Filip Tehlar | 6266877 | 2019-03-04 03:33:32 -0800 | [diff] [blame^] | 1561 | #ifndef CLIB_MARCH_VARIANT |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1562 | clib_error_t * |
| 1563 | vnet_per_buffer_interface_output_hw_interface_add_del (vnet_main_t * vnm, |
| 1564 | u32 hw_if_index, |
| 1565 | u32 is_create) |
| 1566 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1567 | 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] | 1568 | u32 next_index; |
| 1569 | |
John Lo | e5453d0 | 2018-01-23 19:21:34 -0500 | [diff] [blame] | 1570 | if (hi->output_node_index == 0) |
| 1571 | return 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1572 | |
John Lo | e5453d0 | 2018-01-23 19:21:34 -0500 | [diff] [blame] | 1573 | next_index = vlib_node_add_next |
| 1574 | (vnm->vlib_main, vnet_per_buffer_interface_output_node.index, |
| 1575 | hi->output_node_index); |
| 1576 | hi->output_node_next_index = next_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1577 | |
| 1578 | return 0; |
| 1579 | } |
| 1580 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1581 | VNET_HW_INTERFACE_ADD_DEL_FUNCTION |
| 1582 | (vnet_per_buffer_interface_output_hw_interface_add_del); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1583 | |
John Lo | e5453d0 | 2018-01-23 19:21:34 -0500 | [diff] [blame] | 1584 | void |
| 1585 | vnet_set_interface_output_node (vnet_main_t * vnm, |
| 1586 | u32 hw_if_index, u32 node_index) |
| 1587 | { |
| 1588 | ASSERT (node_index); |
| 1589 | vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index); |
| 1590 | u32 next_index = vlib_node_add_next |
| 1591 | (vnm->vlib_main, vnet_per_buffer_interface_output_node.index, node_index); |
| 1592 | hi->output_node_next_index = next_index; |
| 1593 | hi->output_node_index = node_index; |
| 1594 | } |
Filip Tehlar | 6266877 | 2019-03-04 03:33:32 -0800 | [diff] [blame^] | 1595 | #endif /* CLIB_MARCH_VARIANT */ |
John Lo | e5453d0 | 2018-01-23 19:21:34 -0500 | [diff] [blame] | 1596 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1597 | static clib_error_t * |
| 1598 | pcap_drop_trace_command_fn (vlib_main_t * vm, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1599 | unformat_input_t * input, |
| 1600 | vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1601 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1602 | vnet_main_t *vnm = vnet_get_main (); |
| 1603 | vnet_interface_main_t *im = &vnm->interface_main; |
| 1604 | u8 *filename; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1605 | u32 max; |
| 1606 | int matched = 0; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1607 | clib_error_t *error = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1608 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1609 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1610 | { |
| 1611 | if (unformat (input, "on")) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1612 | { |
| 1613 | if (im->drop_pcap_enable == 0) |
| 1614 | { |
| 1615 | if (im->pcap_filename == 0) |
| 1616 | im->pcap_filename = format (0, "/tmp/drop.pcap%c", 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1617 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 1618 | clib_memset (&im->pcap_main, 0, sizeof (im->pcap_main)); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1619 | im->pcap_main.file_name = (char *) im->pcap_filename; |
| 1620 | im->pcap_main.n_packets_to_capture = 100; |
| 1621 | if (im->pcap_pkts_to_capture) |
| 1622 | im->pcap_main.n_packets_to_capture = im->pcap_pkts_to_capture; |
| 1623 | |
| 1624 | im->pcap_main.packet_type = PCAP_PACKET_TYPE_ethernet; |
| 1625 | im->drop_pcap_enable = 1; |
| 1626 | matched = 1; |
| 1627 | vlib_cli_output (vm, "pcap drop capture on..."); |
| 1628 | } |
| 1629 | else |
| 1630 | { |
| 1631 | vlib_cli_output (vm, "pcap drop capture already on..."); |
| 1632 | } |
| 1633 | matched = 1; |
| 1634 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1635 | else if (unformat (input, "off")) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1636 | { |
| 1637 | matched = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1638 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1639 | if (im->drop_pcap_enable) |
| 1640 | { |
| 1641 | vlib_cli_output (vm, "captured %d pkts...", |
| 1642 | im->pcap_main.n_packets_captured); |
| 1643 | if (im->pcap_main.n_packets_captured) |
| 1644 | { |
| 1645 | im->pcap_main.n_packets_to_capture = |
| 1646 | im->pcap_main.n_packets_captured; |
| 1647 | error = pcap_write (&im->pcap_main); |
| 1648 | if (error) |
| 1649 | clib_error_report (error); |
| 1650 | else |
| 1651 | vlib_cli_output (vm, "saved to %s...", im->pcap_filename); |
| 1652 | } |
| 1653 | } |
| 1654 | else |
| 1655 | { |
| 1656 | vlib_cli_output (vm, "pcap drop capture already off..."); |
| 1657 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1658 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1659 | im->drop_pcap_enable = 0; |
| 1660 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1661 | else if (unformat (input, "max %d", &max)) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1662 | { |
| 1663 | im->pcap_pkts_to_capture = max; |
| 1664 | matched = 1; |
| 1665 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1666 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1667 | else if (unformat (input, "intfc %U", |
| 1668 | unformat_vnet_sw_interface, vnm, |
| 1669 | &im->pcap_sw_if_index)) |
| 1670 | matched = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1671 | else if (unformat (input, "intfc any")) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1672 | { |
| 1673 | im->pcap_sw_if_index = 0; |
| 1674 | matched = 1; |
| 1675 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1676 | else if (unformat (input, "file %s", &filename)) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1677 | { |
| 1678 | u8 *chroot_filename; |
| 1679 | /* Brain-police user path input */ |
| 1680 | if (strstr ((char *) filename, "..") |
| 1681 | || index ((char *) filename, '/')) |
| 1682 | { |
| 1683 | vlib_cli_output (vm, "illegal characters in filename '%s'", |
| 1684 | filename); |
| 1685 | continue; |
| 1686 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1687 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1688 | chroot_filename = format (0, "/tmp/%s%c", filename, 0); |
| 1689 | vec_free (filename); |
| 1690 | |
| 1691 | if (im->pcap_filename) |
| 1692 | vec_free (im->pcap_filename); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1693 | im->pcap_filename = chroot_filename; |
jerryian | 361abef | 2017-04-10 18:48:07 +0800 | [diff] [blame] | 1694 | im->pcap_main.file_name = (char *) im->pcap_filename; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1695 | matched = 1; |
| 1696 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1697 | else if (unformat (input, "status")) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1698 | { |
| 1699 | if (im->drop_pcap_enable == 0) |
| 1700 | { |
| 1701 | vlib_cli_output (vm, "pcap drop capture is off..."); |
| 1702 | continue; |
| 1703 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1704 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1705 | vlib_cli_output (vm, "pcap drop capture: %d of %d pkts...", |
| 1706 | im->pcap_main.n_packets_captured, |
| 1707 | im->pcap_main.n_packets_to_capture); |
| 1708 | matched = 1; |
| 1709 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1710 | |
| 1711 | else |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1712 | break; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1713 | } |
| 1714 | |
| 1715 | if (matched == 0) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1716 | return clib_error_return (0, "unknown input `%U'", |
| 1717 | format_unformat_error, input); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1718 | |
| 1719 | return 0; |
| 1720 | } |
| 1721 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1722 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1723 | VLIB_CLI_COMMAND (pcap_trace_command, static) = { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1724 | .path = "pcap drop trace", |
| 1725 | .short_help = |
| 1726 | "pcap drop trace on off max <nn> intfc <intfc> file <name> status", |
| 1727 | .function = pcap_drop_trace_command_fn, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1728 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1729 | /* *INDENT-ON* */ |
| 1730 | |
| 1731 | /* |
| 1732 | * fd.io coding-style-patch-verification: ON |
| 1733 | * |
| 1734 | * Local Variables: |
| 1735 | * eval: (c-set-style "gnu") |
| 1736 | * End: |
| 1737 | */ |