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> |
Mohsin Kazmi | 72e7312 | 2019-10-22 13:33:13 +0200 | [diff] [blame] | 41 | #include <vnet/gso/gso.h> |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 42 | #include <vnet/ip/icmp46_packet.h> |
| 43 | #include <vnet/ip/ip4.h> |
| 44 | #include <vnet/ip/ip6.h> |
| 45 | #include <vnet/udp/udp_packet.h> |
Damjan Marion | 152e21d | 2016-11-29 14:55:43 +0100 | [diff] [blame] | 46 | #include <vnet/feature/feature.h> |
Dave Barach | 9137e54 | 2019-09-13 17:47:50 -0400 | [diff] [blame] | 47 | #include <vnet/classify/trace_classify.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 48 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 49 | typedef struct |
| 50 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 51 | u32 sw_if_index; |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 52 | u32 flags; |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 53 | u8 data[128 - 2 * 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 | s = |
| 86 | format (s, "\n%U%U", format_white_space, indent, |
| 87 | node->format_buffer ? node->format_buffer : format_hex_bytes, |
| 88 | t->data, sizeof (t->data)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 89 | } |
| 90 | return s; |
| 91 | } |
| 92 | |
| 93 | static void |
| 94 | vnet_interface_output_trace (vlib_main_t * vm, |
| 95 | vlib_node_runtime_t * node, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 96 | vlib_frame_t * frame, uword n_buffers) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 97 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 98 | u32 n_left, *from; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 99 | |
| 100 | n_left = n_buffers; |
Damjan Marion | a3d5986 | 2018-11-10 10:23:00 +0100 | [diff] [blame] | 101 | from = vlib_frame_vector_args (frame); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 102 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 103 | while (n_left >= 4) |
| 104 | { |
| 105 | u32 bi0, bi1; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 106 | vlib_buffer_t *b0, *b1; |
| 107 | interface_output_trace_t *t0, *t1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 108 | |
| 109 | /* Prefetch next iteration. */ |
| 110 | vlib_prefetch_buffer_with_index (vm, from[2], LOAD); |
| 111 | vlib_prefetch_buffer_with_index (vm, from[3], LOAD); |
| 112 | |
| 113 | bi0 = from[0]; |
| 114 | bi1 = from[1]; |
| 115 | |
| 116 | b0 = vlib_get_buffer (vm, bi0); |
| 117 | b1 = vlib_get_buffer (vm, bi1); |
| 118 | |
| 119 | if (b0->flags & VLIB_BUFFER_IS_TRACED) |
| 120 | { |
| 121 | t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0])); |
| 122 | t0->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_TX]; |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 123 | t0->flags = b0->flags; |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 124 | clib_memcpy_fast (t0->data, vlib_buffer_get_current (b0), |
| 125 | sizeof (t0->data)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 126 | } |
| 127 | if (b1->flags & VLIB_BUFFER_IS_TRACED) |
| 128 | { |
| 129 | t1 = vlib_add_trace (vm, node, b1, sizeof (t1[0])); |
| 130 | t1->sw_if_index = vnet_buffer (b1)->sw_if_index[VLIB_TX]; |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 131 | t1->flags = b1->flags; |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 132 | clib_memcpy_fast (t1->data, vlib_buffer_get_current (b1), |
| 133 | sizeof (t1->data)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 134 | } |
| 135 | from += 2; |
| 136 | n_left -= 2; |
| 137 | } |
| 138 | |
| 139 | while (n_left >= 1) |
| 140 | { |
| 141 | u32 bi0; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 142 | vlib_buffer_t *b0; |
| 143 | interface_output_trace_t *t0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 144 | |
| 145 | bi0 = from[0]; |
| 146 | |
| 147 | b0 = vlib_get_buffer (vm, bi0); |
| 148 | |
| 149 | if (b0->flags & VLIB_BUFFER_IS_TRACED) |
| 150 | { |
| 151 | t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0])); |
| 152 | t0->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_TX]; |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 153 | t0->flags = b0->flags; |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 154 | clib_memcpy_fast (t0->data, vlib_buffer_get_current (b0), |
| 155 | sizeof (t0->data)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 156 | } |
| 157 | from += 1; |
| 158 | n_left -= 1; |
| 159 | } |
| 160 | } |
| 161 | |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 162 | static_always_inline void |
| 163 | calc_checksums (vlib_main_t * vm, vlib_buffer_t * b) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 164 | { |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 165 | tcp_header_t *th; |
| 166 | udp_header_t *uh; |
Mohsin Kazmi | 72e7312 | 2019-10-22 13:33:13 +0200 | [diff] [blame] | 167 | gso_header_offset_t gho = { 0 }; |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 168 | |
| 169 | int is_ip4 = (b->flags & VNET_BUFFER_F_IS_IP4) != 0; |
| 170 | int is_ip6 = (b->flags & VNET_BUFFER_F_IS_IP6) != 0; |
| 171 | |
| 172 | ASSERT (!(is_ip4 && is_ip6)); |
| 173 | |
Mohsin Kazmi | 72e7312 | 2019-10-22 13:33:13 +0200 | [diff] [blame] | 174 | gho = vnet_gso_header_offset_parser (b, is_ip6); |
| 175 | th = (tcp_header_t *) (vlib_buffer_get_current (b) + gho.l4_hdr_offset); |
| 176 | uh = (udp_header_t *) (vlib_buffer_get_current (b) + gho.l4_hdr_offset); |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 177 | |
| 178 | if (is_ip4) |
| 179 | { |
Zhiyong Yang | 24c5012 | 2019-04-19 05:22:31 -0400 | [diff] [blame] | 180 | ip4_header_t *ip4; |
| 181 | |
Mohsin Kazmi | 72e7312 | 2019-10-22 13:33:13 +0200 | [diff] [blame] | 182 | ip4 = |
| 183 | (ip4_header_t *) (vlib_buffer_get_current (b) + gho.l3_hdr_offset); |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 184 | if (b->flags & VNET_BUFFER_F_OFFLOAD_IP_CKSUM) |
| 185 | ip4->checksum = ip4_header_checksum (ip4); |
| 186 | if (b->flags & VNET_BUFFER_F_OFFLOAD_TCP_CKSUM) |
Andrej Kozemcak | 9d7570c | 2019-01-07 08:39:22 +0100 | [diff] [blame] | 187 | { |
| 188 | th->checksum = 0; |
| 189 | th->checksum = ip4_tcp_udp_compute_checksum (vm, b, ip4); |
| 190 | } |
Zhiyong Yang | 24c5012 | 2019-04-19 05:22:31 -0400 | [diff] [blame] | 191 | else if (b->flags & VNET_BUFFER_F_OFFLOAD_UDP_CKSUM) |
Steven Luong | 03328ec | 2020-01-27 10:37:56 -0800 | [diff] [blame] | 192 | { |
| 193 | uh->checksum = 0; |
| 194 | uh->checksum = ip4_tcp_udp_compute_checksum (vm, b, ip4); |
| 195 | } |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 196 | } |
Zhiyong Yang | 24c5012 | 2019-04-19 05:22:31 -0400 | [diff] [blame] | 197 | else if (is_ip6) |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 198 | { |
| 199 | int bogus; |
Zhiyong Yang | 24c5012 | 2019-04-19 05:22:31 -0400 | [diff] [blame] | 200 | ip6_header_t *ip6; |
| 201 | |
Mohsin Kazmi | 72e7312 | 2019-10-22 13:33:13 +0200 | [diff] [blame] | 202 | ip6 = |
| 203 | (ip6_header_t *) (vlib_buffer_get_current (b) + gho.l3_hdr_offset); |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 204 | if (b->flags & VNET_BUFFER_F_OFFLOAD_TCP_CKSUM) |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 205 | { |
| 206 | th->checksum = 0; |
| 207 | th->checksum = |
| 208 | ip6_tcp_udp_icmp_compute_checksum (vm, b, ip6, &bogus); |
| 209 | } |
Zhiyong Yang | 24c5012 | 2019-04-19 05:22:31 -0400 | [diff] [blame] | 210 | else if (b->flags & VNET_BUFFER_F_OFFLOAD_UDP_CKSUM) |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 211 | { |
| 212 | uh->checksum = 0; |
| 213 | uh->checksum = |
| 214 | ip6_tcp_udp_icmp_compute_checksum (vm, b, ip6, &bogus); |
| 215 | } |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 216 | } |
Florin Coras | 08f2a5d | 2019-08-06 13:48:50 -0700 | [diff] [blame] | 217 | b->flags &= ~VNET_BUFFER_F_OFFLOAD_TCP_CKSUM; |
| 218 | b->flags &= ~VNET_BUFFER_F_OFFLOAD_UDP_CKSUM; |
| 219 | b->flags &= ~VNET_BUFFER_F_OFFLOAD_IP_CKSUM; |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | static_always_inline uword |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 223 | vnet_interface_output_node_inline (vlib_main_t * vm, |
| 224 | vlib_node_runtime_t * node, |
| 225 | vlib_frame_t * frame, |
| 226 | vnet_main_t * vnm, |
| 227 | vnet_hw_interface_t * hi, |
| 228 | int do_tx_offloads) |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 229 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 230 | vnet_interface_output_runtime_t *rt = (void *) node->runtime_data; |
| 231 | vnet_sw_interface_t *si; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 232 | u32 n_left_to_tx, *from, *from_end, *to_tx; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 233 | u32 n_bytes, n_buffers, n_packets; |
Damjan Marion | 363640d | 2017-03-06 11:53:10 +0100 | [diff] [blame] | 234 | 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] | 235 | u32 thread_index = vm->thread_index; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 236 | vnet_interface_main_t *im = &vnm->interface_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 237 | u32 next_index = VNET_INTERFACE_OUTPUT_NEXT_TX; |
Damjan Marion | 152e21d | 2016-11-29 14:55:43 +0100 | [diff] [blame] | 238 | u32 current_config_index = ~0; |
| 239 | u8 arc = im->output_feature_arc_index; |
Zhiyong Yang | a462c07 | 2019-05-05 19:32:25 +0800 | [diff] [blame] | 240 | vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 241 | |
| 242 | n_buffers = frame->n_vectors; |
| 243 | |
| 244 | if (node->flags & VLIB_NODE_FLAG_TRACE) |
| 245 | vnet_interface_output_trace (vm, node, frame, n_buffers); |
| 246 | |
Damjan Marion | a3d5986 | 2018-11-10 10:23:00 +0100 | [diff] [blame] | 247 | from = vlib_frame_vector_args (frame); |
Zhiyong Yang | a462c07 | 2019-05-05 19:32:25 +0800 | [diff] [blame] | 248 | vlib_get_buffers (vm, from, b, n_buffers); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 249 | |
| 250 | if (rt->is_deleted) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 251 | return vlib_error_drop_buffers (vm, node, from, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 252 | /* buffer stride */ 1, |
| 253 | n_buffers, |
| 254 | VNET_INTERFACE_OUTPUT_NEXT_DROP, |
| 255 | node->node_index, |
| 256 | VNET_INTERFACE_OUTPUT_ERROR_INTERFACE_DELETED); |
| 257 | |
| 258 | si = vnet_get_sw_interface (vnm, rt->sw_if_index); |
| 259 | hi = vnet_get_sup_hw_interface (vnm, rt->sw_if_index); |
Steven Luong | 5ad541e | 2019-08-27 07:43:27 -0700 | [diff] [blame] | 260 | if (!(si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) || |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 261 | !(hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 262 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 263 | vlib_simple_counter_main_t *cm; |
| 264 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 265 | cm = vec_elt_at_index (vnm->interface_main.sw_if_counters, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 266 | VNET_INTERFACE_COUNTER_TX_ERROR); |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 267 | vlib_increment_simple_counter (cm, thread_index, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 268 | rt->sw_if_index, n_buffers); |
| 269 | |
| 270 | return vlib_error_drop_buffers (vm, node, from, |
| 271 | /* buffer stride */ 1, |
| 272 | n_buffers, |
| 273 | VNET_INTERFACE_OUTPUT_NEXT_DROP, |
| 274 | node->node_index, |
| 275 | VNET_INTERFACE_OUTPUT_ERROR_INTERFACE_DOWN); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | from_end = from + n_buffers; |
| 279 | |
| 280 | /* Total byte count of all buffers. */ |
| 281 | n_bytes = 0; |
| 282 | n_packets = 0; |
| 283 | |
Damjan Marion | 152e21d | 2016-11-29 14:55:43 +0100 | [diff] [blame] | 284 | /* interface-output feature arc handling */ |
| 285 | if (PREDICT_FALSE (vnet_have_features (arc, rt->sw_if_index))) |
| 286 | { |
| 287 | vnet_feature_config_main_t *fcm; |
| 288 | fcm = vnet_feature_get_config_main (arc); |
| 289 | current_config_index = vnet_get_feature_config_index (arc, |
| 290 | rt->sw_if_index); |
| 291 | vnet_get_config_data (&fcm->config_main, ¤t_config_index, |
| 292 | &next_index, 0); |
| 293 | } |
| 294 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 295 | while (from < from_end) |
| 296 | { |
| 297 | /* Get new next frame since previous incomplete frame may have less |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 298 | than VNET_FRAME_SIZE vectors in it. */ |
| 299 | 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] | 300 | |
Damjan Marion | 363640d | 2017-03-06 11:53:10 +0100 | [diff] [blame] | 301 | while (from + 8 <= from_end && n_left_to_tx >= 4) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 302 | { |
Damjan Marion | 363640d | 2017-03-06 11:53:10 +0100 | [diff] [blame] | 303 | u32 bi0, bi1, bi2, bi3; |
Damjan Marion | 363640d | 2017-03-06 11:53:10 +0100 | [diff] [blame] | 304 | u32 tx_swif0, tx_swif1, tx_swif2, tx_swif3; |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 305 | u32 or_flags; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 306 | |
| 307 | /* Prefetch next iteration. */ |
Zhiyong Yang | a462c07 | 2019-05-05 19:32:25 +0800 | [diff] [blame] | 308 | vlib_prefetch_buffer_header (b[4], LOAD); |
| 309 | vlib_prefetch_buffer_header (b[5], LOAD); |
| 310 | vlib_prefetch_buffer_header (b[6], LOAD); |
| 311 | vlib_prefetch_buffer_header (b[7], LOAD); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 312 | |
| 313 | bi0 = from[0]; |
| 314 | bi1 = from[1]; |
Damjan Marion | 363640d | 2017-03-06 11:53:10 +0100 | [diff] [blame] | 315 | bi2 = from[2]; |
| 316 | bi3 = from[3]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 317 | to_tx[0] = bi0; |
| 318 | to_tx[1] = bi1; |
Damjan Marion | 363640d | 2017-03-06 11:53:10 +0100 | [diff] [blame] | 319 | to_tx[2] = bi2; |
| 320 | to_tx[3] = bi3; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 321 | |
Zhiyong Yang | a462c07 | 2019-05-05 19:32:25 +0800 | [diff] [blame] | 322 | 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] | 323 | |
Zhiyong Yang | a462c07 | 2019-05-05 19:32:25 +0800 | [diff] [blame] | 324 | from += 4; |
| 325 | to_tx += 4; |
| 326 | n_left_to_tx -= 4; |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 327 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 328 | /* Be grumpy about zero length buffers for benefit of |
| 329 | driver tx function. */ |
Zhiyong Yang | a462c07 | 2019-05-05 19:32:25 +0800 | [diff] [blame] | 330 | ASSERT (b[0]->current_length > 0); |
| 331 | ASSERT (b[1]->current_length > 0); |
| 332 | ASSERT (b[2]->current_length > 0); |
| 333 | ASSERT (b[3]->current_length > 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 334 | |
Zhiyong Yang | a462c07 | 2019-05-05 19:32:25 +0800 | [diff] [blame] | 335 | n_bytes_b0 = vlib_buffer_length_in_chain (vm, b[0]); |
| 336 | n_bytes_b1 = vlib_buffer_length_in_chain (vm, b[1]); |
| 337 | n_bytes_b2 = vlib_buffer_length_in_chain (vm, b[2]); |
| 338 | n_bytes_b3 = vlib_buffer_length_in_chain (vm, b[3]); |
| 339 | tx_swif0 = vnet_buffer (b[0])->sw_if_index[VLIB_TX]; |
| 340 | tx_swif1 = vnet_buffer (b[1])->sw_if_index[VLIB_TX]; |
| 341 | tx_swif2 = vnet_buffer (b[2])->sw_if_index[VLIB_TX]; |
| 342 | tx_swif3 = vnet_buffer (b[3])->sw_if_index[VLIB_TX]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 343 | |
| 344 | n_bytes += n_bytes_b0 + n_bytes_b1; |
Damjan Marion | 363640d | 2017-03-06 11:53:10 +0100 | [diff] [blame] | 345 | n_bytes += n_bytes_b2 + n_bytes_b3; |
| 346 | n_packets += 4; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 347 | |
Damjan Marion | 152e21d | 2016-11-29 14:55:43 +0100 | [diff] [blame] | 348 | if (PREDICT_FALSE (current_config_index != ~0)) |
| 349 | { |
Zhiyong Yang | a462c07 | 2019-05-05 19:32:25 +0800 | [diff] [blame] | 350 | vnet_buffer (b[0])->feature_arc_index = arc; |
| 351 | vnet_buffer (b[1])->feature_arc_index = arc; |
| 352 | vnet_buffer (b[2])->feature_arc_index = arc; |
| 353 | vnet_buffer (b[3])->feature_arc_index = arc; |
| 354 | b[0]->current_config_index = current_config_index; |
| 355 | b[1]->current_config_index = current_config_index; |
| 356 | b[2]->current_config_index = current_config_index; |
| 357 | b[3]->current_config_index = current_config_index; |
Damjan Marion | 152e21d | 2016-11-29 14:55:43 +0100 | [diff] [blame] | 358 | } |
| 359 | |
Damjan Marion | 363640d | 2017-03-06 11:53:10 +0100 | [diff] [blame] | 360 | /* update vlan subif tx counts, if required */ |
Damjan Marion | 9c6ae5f | 2016-11-15 23:20:01 +0100 | [diff] [blame] | 361 | if (PREDICT_FALSE (tx_swif0 != rt->sw_if_index)) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 362 | { |
Damjan Marion | 9c6ae5f | 2016-11-15 23:20:01 +0100 | [diff] [blame] | 363 | vlib_increment_combined_counter (im->combined_sw_if_counters + |
| 364 | VNET_INTERFACE_COUNTER_TX, |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 365 | thread_index, tx_swif0, 1, |
Damjan Marion | 9c6ae5f | 2016-11-15 23:20:01 +0100 | [diff] [blame] | 366 | n_bytes_b0); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 367 | } |
Damjan Marion | 9c6ae5f | 2016-11-15 23:20:01 +0100 | [diff] [blame] | 368 | |
Damjan Marion | 9c6ae5f | 2016-11-15 23:20:01 +0100 | [diff] [blame] | 369 | if (PREDICT_FALSE (tx_swif1 != rt->sw_if_index)) |
| 370 | { |
| 371 | |
| 372 | vlib_increment_combined_counter (im->combined_sw_if_counters + |
| 373 | VNET_INTERFACE_COUNTER_TX, |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 374 | thread_index, tx_swif1, 1, |
Damjan Marion | 9c6ae5f | 2016-11-15 23:20:01 +0100 | [diff] [blame] | 375 | n_bytes_b1); |
| 376 | } |
Damjan Marion | 363640d | 2017-03-06 11:53:10 +0100 | [diff] [blame] | 377 | |
| 378 | if (PREDICT_FALSE (tx_swif2 != rt->sw_if_index)) |
| 379 | { |
| 380 | |
| 381 | vlib_increment_combined_counter (im->combined_sw_if_counters + |
| 382 | VNET_INTERFACE_COUNTER_TX, |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 383 | thread_index, tx_swif2, 1, |
Damjan Marion | 363640d | 2017-03-06 11:53:10 +0100 | [diff] [blame] | 384 | n_bytes_b2); |
| 385 | } |
| 386 | if (PREDICT_FALSE (tx_swif3 != rt->sw_if_index)) |
| 387 | { |
| 388 | |
| 389 | vlib_increment_combined_counter (im->combined_sw_if_counters + |
| 390 | VNET_INTERFACE_COUNTER_TX, |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 391 | thread_index, tx_swif3, 1, |
Damjan Marion | 363640d | 2017-03-06 11:53:10 +0100 | [diff] [blame] | 392 | n_bytes_b3); |
| 393 | } |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 394 | |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 395 | if (do_tx_offloads) |
| 396 | { |
| 397 | if (or_flags & |
| 398 | (VNET_BUFFER_F_OFFLOAD_TCP_CKSUM | |
| 399 | VNET_BUFFER_F_OFFLOAD_UDP_CKSUM | |
| 400 | VNET_BUFFER_F_OFFLOAD_IP_CKSUM)) |
| 401 | { |
Zhiyong Yang | a462c07 | 2019-05-05 19:32:25 +0800 | [diff] [blame] | 402 | calc_checksums (vm, b[0]); |
| 403 | calc_checksums (vm, b[1]); |
| 404 | calc_checksums (vm, b[2]); |
| 405 | calc_checksums (vm, b[3]); |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 406 | } |
| 407 | } |
Zhiyong Yang | a462c07 | 2019-05-05 19:32:25 +0800 | [diff] [blame] | 408 | b += 4; |
| 409 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | while (from + 1 <= from_end && n_left_to_tx >= 1) |
| 413 | { |
| 414 | u32 bi0; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 415 | u32 tx_swif0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 416 | |
| 417 | bi0 = from[0]; |
| 418 | to_tx[0] = bi0; |
| 419 | from += 1; |
| 420 | to_tx += 1; |
| 421 | n_left_to_tx -= 1; |
| 422 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 423 | /* Be grumpy about zero length buffers for benefit of |
| 424 | driver tx function. */ |
Zhiyong Yang | a462c07 | 2019-05-05 19:32:25 +0800 | [diff] [blame] | 425 | ASSERT (b[0]->current_length > 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 426 | |
Zhiyong Yang | a462c07 | 2019-05-05 19:32:25 +0800 | [diff] [blame] | 427 | n_bytes_b0 = vlib_buffer_length_in_chain (vm, b[0]); |
| 428 | tx_swif0 = vnet_buffer (b[0])->sw_if_index[VLIB_TX]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 429 | n_bytes += n_bytes_b0; |
| 430 | n_packets += 1; |
| 431 | |
Damjan Marion | 152e21d | 2016-11-29 14:55:43 +0100 | [diff] [blame] | 432 | if (PREDICT_FALSE (current_config_index != ~0)) |
| 433 | { |
Zhiyong Yang | a462c07 | 2019-05-05 19:32:25 +0800 | [diff] [blame] | 434 | vnet_buffer (b[0])->feature_arc_index = arc; |
| 435 | b[0]->current_config_index = current_config_index; |
Damjan Marion | 152e21d | 2016-11-29 14:55:43 +0100 | [diff] [blame] | 436 | } |
| 437 | |
Damjan Marion | 9c6ae5f | 2016-11-15 23:20:01 +0100 | [diff] [blame] | 438 | if (PREDICT_FALSE (tx_swif0 != rt->sw_if_index)) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 439 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 440 | |
Damjan Marion | 9c6ae5f | 2016-11-15 23:20:01 +0100 | [diff] [blame] | 441 | vlib_increment_combined_counter (im->combined_sw_if_counters + |
| 442 | VNET_INTERFACE_COUNTER_TX, |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 443 | thread_index, tx_swif0, 1, |
Damjan Marion | 9c6ae5f | 2016-11-15 23:20:01 +0100 | [diff] [blame] | 444 | n_bytes_b0); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 445 | } |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 446 | |
| 447 | if (do_tx_offloads) |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 448 | { |
| 449 | if (b[0]->flags & |
| 450 | (VNET_BUFFER_F_OFFLOAD_TCP_CKSUM | |
| 451 | VNET_BUFFER_F_OFFLOAD_UDP_CKSUM | |
| 452 | VNET_BUFFER_F_OFFLOAD_IP_CKSUM)) |
| 453 | calc_checksums (vm, b[0]); |
| 454 | } |
Zhiyong Yang | a462c07 | 2019-05-05 19:32:25 +0800 | [diff] [blame] | 455 | b += 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 456 | } |
| 457 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 458 | vlib_put_next_frame (vm, node, next_index, n_left_to_tx); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | /* Update main interface stats. */ |
| 462 | vlib_increment_combined_counter (im->combined_sw_if_counters |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 463 | + VNET_INTERFACE_COUNTER_TX, |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 464 | thread_index, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 465 | rt->sw_if_index, n_packets, n_bytes); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 466 | return n_buffers; |
| 467 | } |
Filip Tehlar | 6266877 | 2019-03-04 03:33:32 -0800 | [diff] [blame] | 468 | #endif /* CLIB_MARCH_VARIANT */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 469 | |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 470 | static_always_inline void vnet_interface_pcap_tx_trace |
| 471 | (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame, |
| 472 | int sw_if_index_from_buffer) |
| 473 | { |
| 474 | u32 n_left_from, *from; |
| 475 | u32 sw_if_index; |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 476 | vnet_pcap_t *pp = &vlib_global_main.pcap; |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 477 | |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 478 | if (PREDICT_TRUE (pp->pcap_tx_enable == 0)) |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 479 | return; |
| 480 | |
| 481 | if (sw_if_index_from_buffer == 0) |
| 482 | { |
| 483 | vnet_interface_output_runtime_t *rt = (void *) node->runtime_data; |
| 484 | sw_if_index = rt->sw_if_index; |
| 485 | } |
| 486 | else |
| 487 | sw_if_index = ~0; |
| 488 | |
| 489 | n_left_from = frame->n_vectors; |
| 490 | from = vlib_frame_vector_args (frame); |
| 491 | |
| 492 | while (n_left_from > 0) |
| 493 | { |
Dave Barach | 9137e54 | 2019-09-13 17:47:50 -0400 | [diff] [blame] | 494 | int classify_filter_result; |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 495 | u32 bi0 = from[0]; |
| 496 | vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0); |
Dave Barach | 9137e54 | 2019-09-13 17:47:50 -0400 | [diff] [blame] | 497 | from++; |
| 498 | n_left_from--; |
| 499 | |
Dave Barach | f5667c3 | 2019-09-25 11:27:46 -0400 | [diff] [blame] | 500 | if (pp->filter_classify_table_index != ~0) |
Dave Barach | 9137e54 | 2019-09-13 17:47:50 -0400 | [diff] [blame] | 501 | { |
| 502 | classify_filter_result = |
| 503 | vnet_is_packet_traced_inline |
Dave Barach | f5667c3 | 2019-09-25 11:27:46 -0400 | [diff] [blame] | 504 | (b0, pp->filter_classify_table_index, 0 /* full classify */ ); |
Dave Barach | 9137e54 | 2019-09-13 17:47:50 -0400 | [diff] [blame] | 505 | if (classify_filter_result) |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 506 | 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] | 507 | continue; |
| 508 | } |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 509 | |
| 510 | if (sw_if_index_from_buffer) |
| 511 | sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_TX]; |
| 512 | |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 513 | if (pp->pcap_sw_if_index == 0 || pp->pcap_sw_if_index == sw_if_index) |
Dave Barach | d28437c | 2019-11-20 09:28:31 -0500 | [diff] [blame] | 514 | { |
| 515 | vnet_main_t *vnm = vnet_get_main (); |
| 516 | vnet_hw_interface_t *hi = |
| 517 | vnet_get_sup_hw_interface (vnm, sw_if_index); |
| 518 | /* Capture pkt if not filtered, or if filter hits */ |
| 519 | if (hi->trace_classify_table_index == ~0 || |
| 520 | vnet_is_packet_traced_inline |
| 521 | (b0, hi->trace_classify_table_index, 0 /* full classify */ )) |
| 522 | pcap_add_buffer (&pp->pcap_main, vm, bi0, pp->max_bytes_per_pkt); |
| 523 | } |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 524 | } |
| 525 | } |
| 526 | |
Filip Tehlar | 6266877 | 2019-03-04 03:33:32 -0800 | [diff] [blame] | 527 | #ifndef CLIB_MARCH_VARIANT |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 528 | |
Damjan Marion | 652d2e1 | 2019-02-02 00:15:27 +0100 | [diff] [blame] | 529 | uword |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 530 | vnet_interface_output_node (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 531 | vlib_frame_t * frame) |
| 532 | { |
| 533 | vnet_main_t *vnm = vnet_get_main (); |
| 534 | vnet_hw_interface_t *hi; |
| 535 | vnet_interface_output_runtime_t *rt = (void *) node->runtime_data; |
| 536 | hi = vnet_get_sup_hw_interface (vnm, rt->sw_if_index); |
| 537 | |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 538 | vnet_interface_pcap_tx_trace (vm, node, frame, |
| 539 | 0 /* sw_if_index_from_buffer */ ); |
| 540 | |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 541 | if (hi->flags & VNET_HW_INTERFACE_FLAG_SUPPORTS_TX_L4_CKSUM_OFFLOAD) |
| 542 | return vnet_interface_output_node_inline (vm, node, frame, vnm, hi, |
| 543 | /* do_tx_offloads */ 0); |
| 544 | else |
| 545 | return vnet_interface_output_node_inline (vm, node, frame, vnm, hi, |
| 546 | /* do_tx_offloads */ 1); |
| 547 | } |
Filip Tehlar | 6266877 | 2019-03-04 03:33:32 -0800 | [diff] [blame] | 548 | #endif /* CLIB_MARCH_VARIANT */ |
Dave Barach | 2c0a4f4 | 2017-06-29 09:30:15 -0400 | [diff] [blame] | 549 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 550 | /* Use buffer's sw_if_index[VNET_TX] to choose output interface. */ |
Filip Tehlar | 6266877 | 2019-03-04 03:33:32 -0800 | [diff] [blame] | 551 | VLIB_NODE_FN (vnet_per_buffer_interface_output_node) (vlib_main_t * vm, |
| 552 | vlib_node_runtime_t * |
| 553 | node, |
| 554 | vlib_frame_t * frame) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 555 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 556 | vnet_main_t *vnm = vnet_get_main (); |
| 557 | u32 n_left_to_next, *from, *to_next; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 558 | u32 n_left_from, next_index; |
| 559 | |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 560 | vnet_interface_pcap_tx_trace (vm, node, frame, |
| 561 | 1 /* sw_if_index_from_buffer */ ); |
| 562 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 563 | n_left_from = frame->n_vectors; |
| 564 | |
Damjan Marion | a3d5986 | 2018-11-10 10:23:00 +0100 | [diff] [blame] | 565 | from = vlib_frame_vector_args (frame); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 566 | next_index = node->cached_next_index; |
| 567 | |
| 568 | while (n_left_from > 0) |
| 569 | { |
| 570 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
| 571 | |
| 572 | while (n_left_from >= 4 && n_left_to_next >= 2) |
| 573 | { |
| 574 | u32 bi0, bi1, next0, next1; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 575 | vlib_buffer_t *b0, *b1; |
| 576 | vnet_hw_interface_t *hi0, *hi1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 577 | |
| 578 | /* Prefetch next iteration. */ |
| 579 | vlib_prefetch_buffer_with_index (vm, from[2], LOAD); |
| 580 | vlib_prefetch_buffer_with_index (vm, from[3], LOAD); |
| 581 | |
| 582 | bi0 = from[0]; |
| 583 | bi1 = from[1]; |
| 584 | to_next[0] = bi0; |
| 585 | to_next[1] = bi1; |
| 586 | from += 2; |
| 587 | to_next += 2; |
| 588 | n_left_to_next -= 2; |
| 589 | n_left_from -= 2; |
| 590 | |
| 591 | b0 = vlib_get_buffer (vm, bi0); |
| 592 | b1 = vlib_get_buffer (vm, bi1); |
| 593 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 594 | hi0 = |
| 595 | vnet_get_sup_hw_interface (vnm, |
| 596 | vnet_buffer (b0)->sw_if_index |
| 597 | [VLIB_TX]); |
| 598 | hi1 = |
| 599 | vnet_get_sup_hw_interface (vnm, |
| 600 | vnet_buffer (b1)->sw_if_index |
| 601 | [VLIB_TX]); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 602 | |
John Lo | e5453d0 | 2018-01-23 19:21:34 -0500 | [diff] [blame] | 603 | next0 = hi0->output_node_next_index; |
| 604 | next1 = hi1->output_node_next_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 605 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 606 | vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next, |
| 607 | n_left_to_next, bi0, bi1, next0, |
| 608 | next1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | while (n_left_from > 0 && n_left_to_next > 0) |
| 612 | { |
| 613 | u32 bi0, next0; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 614 | vlib_buffer_t *b0; |
| 615 | vnet_hw_interface_t *hi0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 616 | |
| 617 | bi0 = from[0]; |
| 618 | to_next[0] = bi0; |
| 619 | from += 1; |
| 620 | to_next += 1; |
| 621 | n_left_to_next -= 1; |
| 622 | n_left_from -= 1; |
| 623 | |
| 624 | b0 = vlib_get_buffer (vm, bi0); |
| 625 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 626 | hi0 = |
| 627 | vnet_get_sup_hw_interface (vnm, |
| 628 | vnet_buffer (b0)->sw_if_index |
| 629 | [VLIB_TX]); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 630 | |
John Lo | e5453d0 | 2018-01-23 19:21:34 -0500 | [diff] [blame] | 631 | next0 = hi0->output_node_next_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 632 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 633 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next, |
| 634 | n_left_to_next, bi0, next0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 638 | } |
| 639 | |
| 640 | return frame->n_vectors; |
| 641 | } |
| 642 | |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 643 | typedef struct vnet_error_trace_t_ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 644 | { |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 645 | u32 sw_if_index; |
| 646 | } vnet_error_trace_t; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 647 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 648 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 649 | static u8 * |
| 650 | format_vnet_error_trace (u8 * s, va_list * va) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 651 | { |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 652 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 653 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *); |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 654 | vnet_error_trace_t *t = va_arg (*va, vnet_error_trace_t *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 655 | |
Neale Ranns | 7227c39 | 2019-03-21 10:20:15 +0000 | [diff] [blame] | 656 | s = format (s, "rx:%U", format_vnet_sw_if_index_name, |
| 657 | vnet_get_main (), t->sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 658 | |
| 659 | return s; |
| 660 | } |
| 661 | |
| 662 | static void |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 663 | interface_trace_buffers (vlib_main_t * vm, |
| 664 | vlib_node_runtime_t * node, vlib_frame_t * frame) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 665 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 666 | u32 n_left, *buffers; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 667 | |
| 668 | buffers = vlib_frame_vector_args (frame); |
| 669 | n_left = frame->n_vectors; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 670 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 671 | while (n_left >= 4) |
| 672 | { |
| 673 | u32 bi0, bi1; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 674 | vlib_buffer_t *b0, *b1; |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 675 | vnet_error_trace_t *t0, *t1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 676 | |
| 677 | /* Prefetch next iteration. */ |
| 678 | vlib_prefetch_buffer_with_index (vm, buffers[2], LOAD); |
| 679 | vlib_prefetch_buffer_with_index (vm, buffers[3], LOAD); |
| 680 | |
| 681 | bi0 = buffers[0]; |
| 682 | bi1 = buffers[1]; |
| 683 | |
| 684 | b0 = vlib_get_buffer (vm, bi0); |
| 685 | b1 = vlib_get_buffer (vm, bi1); |
| 686 | |
| 687 | if (b0->flags & VLIB_BUFFER_IS_TRACED) |
| 688 | { |
| 689 | t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0])); |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 690 | t0->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 691 | } |
| 692 | if (b1->flags & VLIB_BUFFER_IS_TRACED) |
| 693 | { |
| 694 | t1 = vlib_add_trace (vm, node, b1, sizeof (t1[0])); |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 695 | t1->sw_if_index = vnet_buffer (b1)->sw_if_index[VLIB_RX]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 696 | } |
| 697 | buffers += 2; |
| 698 | n_left -= 2; |
| 699 | } |
| 700 | |
| 701 | while (n_left >= 1) |
| 702 | { |
| 703 | u32 bi0; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 704 | vlib_buffer_t *b0; |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 705 | vnet_error_trace_t *t0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 706 | |
| 707 | bi0 = buffers[0]; |
| 708 | |
| 709 | b0 = vlib_get_buffer (vm, bi0); |
| 710 | |
| 711 | if (b0->flags & VLIB_BUFFER_IS_TRACED) |
| 712 | { |
| 713 | t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0])); |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 714 | t0->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 715 | } |
| 716 | buffers += 1; |
| 717 | n_left -= 1; |
| 718 | } |
| 719 | } |
| 720 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 721 | typedef enum |
| 722 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 723 | VNET_ERROR_DISPOSITION_DROP, |
| 724 | VNET_ERROR_DISPOSITION_PUNT, |
| 725 | VNET_ERROR_N_DISPOSITION, |
| 726 | } vnet_error_disposition_t; |
| 727 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 728 | static_always_inline uword |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 729 | interface_drop_punt (vlib_main_t * vm, |
| 730 | vlib_node_runtime_t * node, |
| 731 | vlib_frame_t * frame, |
| 732 | vnet_error_disposition_t disposition) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 733 | { |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 734 | u32 *from, n_left, thread_index, *sw_if_index; |
| 735 | vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b; |
| 736 | u32 sw_if_indices[VLIB_FRAME_SIZE]; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 737 | vlib_simple_counter_main_t *cm; |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 738 | u16 nexts[VLIB_FRAME_SIZE]; |
| 739 | vnet_main_t *vnm; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 740 | |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 741 | vnm = vnet_get_main (); |
| 742 | thread_index = vm->thread_index; |
| 743 | from = vlib_frame_vector_args (frame); |
| 744 | n_left = frame->n_vectors; |
| 745 | b = bufs; |
| 746 | sw_if_index = sw_if_indices; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 747 | |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 748 | vlib_get_buffers (vm, from, bufs, n_left); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 749 | |
| 750 | if (node->flags & VLIB_NODE_FLAG_TRACE) |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 751 | interface_trace_buffers (vm, node, frame); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 752 | |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 753 | /* All going to drop regardless, this is just a counting exercise */ |
| 754 | clib_memset (nexts, 0, sizeof (nexts)); |
| 755 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 756 | cm = vec_elt_at_index (vnm->interface_main.sw_if_counters, |
| 757 | (disposition == VNET_ERROR_DISPOSITION_PUNT |
| 758 | ? VNET_INTERFACE_COUNTER_PUNT |
| 759 | : VNET_INTERFACE_COUNTER_DROP)); |
| 760 | |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 761 | /* collect the array of interfaces first ... */ |
| 762 | while (n_left >= 4) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 763 | { |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 764 | if (n_left >= 12) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 765 | { |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 766 | /* Prefetch 8 ahead - there's not much going on in each iteration */ |
| 767 | vlib_prefetch_buffer_header (b[4], LOAD); |
| 768 | vlib_prefetch_buffer_header (b[5], LOAD); |
| 769 | vlib_prefetch_buffer_header (b[6], LOAD); |
| 770 | vlib_prefetch_buffer_header (b[7], LOAD); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 771 | } |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 772 | sw_if_index[0] = vnet_buffer (b[0])->sw_if_index[VLIB_RX]; |
| 773 | sw_if_index[1] = vnet_buffer (b[1])->sw_if_index[VLIB_RX]; |
| 774 | sw_if_index[2] = vnet_buffer (b[2])->sw_if_index[VLIB_RX]; |
| 775 | sw_if_index[3] = vnet_buffer (b[3])->sw_if_index[VLIB_RX]; |
| 776 | |
| 777 | sw_if_index += 4; |
| 778 | n_left -= 4; |
| 779 | b += 4; |
| 780 | } |
| 781 | while (n_left) |
| 782 | { |
| 783 | sw_if_index[0] = vnet_buffer (b[0])->sw_if_index[VLIB_RX]; |
| 784 | |
| 785 | sw_if_index += 1; |
| 786 | n_left -= 1; |
| 787 | b += 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 788 | } |
| 789 | |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 790 | /* ... then count against them in blocks */ |
| 791 | n_left = frame->n_vectors; |
| 792 | |
| 793 | while (n_left) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 794 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 795 | vnet_sw_interface_t *sw_if0; |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 796 | u16 off, count; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 797 | |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 798 | off = frame->n_vectors - n_left; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 799 | |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 800 | sw_if_index = sw_if_indices + off; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 801 | |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 802 | count = clib_count_equal_u32 (sw_if_index, n_left); |
| 803 | n_left -= count; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 804 | |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 805 | vlib_increment_simple_counter (cm, thread_index, sw_if_index[0], count); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 806 | |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 807 | /* Increment super-interface drop/punt counters for |
| 808 | sub-interfaces. */ |
| 809 | sw_if0 = vnet_get_sw_interface (vnm, sw_if_index[0]); |
| 810 | if (sw_if0->sup_sw_if_index != sw_if_index[0]) |
| 811 | vlib_increment_simple_counter |
| 812 | (cm, thread_index, sw_if0->sup_sw_if_index, count); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 813 | } |
| 814 | |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 815 | vlib_buffer_enqueue_to_next (vm, node, from, nexts, frame->n_vectors); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 816 | |
| 817 | return frame->n_vectors; |
| 818 | } |
| 819 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 820 | static inline void |
| 821 | pcap_drop_trace (vlib_main_t * vm, |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 822 | vnet_interface_main_t * im, |
| 823 | vnet_pcap_t * pp, vlib_frame_t * f) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 824 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 825 | u32 *from; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 826 | u32 n_left = f->n_vectors; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 827 | vlib_buffer_t *b0, *p1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 828 | u32 bi0; |
| 829 | i16 save_current_data; |
| 830 | u16 save_current_length; |
Dave Barach | 9382ad9 | 2019-09-23 16:03:49 -0400 | [diff] [blame] | 831 | vlib_error_main_t *em = &vm->error_main; |
Dave Barach | f5667c3 | 2019-09-25 11:27:46 -0400 | [diff] [blame] | 832 | int do_trace = 0; |
| 833 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 834 | |
| 835 | from = vlib_frame_vector_args (f); |
| 836 | |
| 837 | while (n_left > 0) |
| 838 | { |
| 839 | if (PREDICT_TRUE (n_left > 1)) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 840 | { |
| 841 | p1 = vlib_get_buffer (vm, from[1]); |
| 842 | vlib_prefetch_buffer_header (p1, LOAD); |
| 843 | } |
| 844 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 845 | bi0 = from[0]; |
| 846 | b0 = vlib_get_buffer (vm, bi0); |
| 847 | from++; |
| 848 | n_left--; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 849 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 850 | /* See if we're pointedly ignoring this specific error */ |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 851 | if (im->pcap_drop_filter_hash |
| 852 | && hash_get (im->pcap_drop_filter_hash, b0->error)) |
| 853 | continue; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 854 | |
Dave Barach | f5667c3 | 2019-09-25 11:27:46 -0400 | [diff] [blame] | 855 | do_trace = (pp->pcap_sw_if_index == 0) || |
| 856 | pp->pcap_sw_if_index == vnet_buffer (b0)->sw_if_index[VLIB_RX]; |
| 857 | |
| 858 | if (PREDICT_FALSE |
| 859 | (do_trace == 0 && pp->filter_classify_table_index != ~0)) |
| 860 | { |
| 861 | do_trace = vnet_is_packet_traced_inline |
| 862 | (b0, pp->filter_classify_table_index, 0 /* full classify */ ); |
| 863 | } |
| 864 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 865 | /* Trace all drops, or drops received on a specific interface */ |
Dave Barach | f5667c3 | 2019-09-25 11:27:46 -0400 | [diff] [blame] | 866 | if (do_trace) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 867 | { |
| 868 | save_current_data = b0->current_data; |
| 869 | save_current_length = b0->current_length; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 870 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 871 | /* |
| 872 | * Typically, we'll need to rewind the buffer |
Benoît Ganne | 4e323cb | 2019-09-17 17:30:35 +0200 | [diff] [blame] | 873 | * if l2_hdr_offset is valid, make sure to rewind to the start of |
| 874 | * the L2 header. This may not be the buffer start in case we pop-ed |
| 875 | * vlan tags. |
| 876 | * Otherwise, rewind to buffer start and hope for the best. |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 877 | */ |
Benoît Ganne | 4e323cb | 2019-09-17 17:30:35 +0200 | [diff] [blame] | 878 | if (b0->flags & VNET_BUFFER_F_L2_HDR_OFFSET_VALID) |
| 879 | { |
| 880 | if (b0->current_data > vnet_buffer (b0)->l2_hdr_offset) |
| 881 | vlib_buffer_advance (b0, |
| 882 | vnet_buffer (b0)->l2_hdr_offset - |
| 883 | b0->current_data); |
| 884 | } |
| 885 | else if (b0->current_data > 0) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 886 | vlib_buffer_advance (b0, (word) - b0->current_data); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 887 | |
Dave Barach | 9382ad9 | 2019-09-23 16:03:49 -0400 | [diff] [blame] | 888 | { |
| 889 | vlib_buffer_t *last = b0; |
| 890 | u32 error_node_index; |
| 891 | int drop_string_len; |
| 892 | vlib_node_t *n; |
| 893 | /* Length of the error string */ |
| 894 | int error_string_len = |
| 895 | clib_strnlen (em->error_strings_heap[b0->error], 128); |
| 896 | |
| 897 | /* Dig up the drop node */ |
| 898 | error_node_index = vm->node_main.node_by_error[b0->error]; |
| 899 | n = vlib_get_node (vm, error_node_index); |
| 900 | |
| 901 | /* Length of full drop string, w/ "nodename: " prepended */ |
| 902 | drop_string_len = error_string_len + vec_len (n->name) + 2; |
| 903 | |
| 904 | /* Find the last buffer in the chain */ |
| 905 | while (last->flags & VLIB_BUFFER_NEXT_PRESENT) |
| 906 | last = vlib_get_buffer (vm, last->next_buffer); |
| 907 | |
| 908 | /* |
| 909 | * Append <nodename>: <error-string> to the capture, |
| 910 | * only if we can do that without allocating a new buffer. |
| 911 | */ |
| 912 | if (PREDICT_TRUE ((last->current_data + last->current_length) |
| 913 | < (VLIB_BUFFER_DEFAULT_DATA_SIZE |
| 914 | - drop_string_len))) |
| 915 | { |
| 916 | clib_memcpy_fast (last->data + last->current_data + |
| 917 | last->current_length, n->name, |
| 918 | vec_len (n->name)); |
| 919 | clib_memcpy_fast (last->data + last->current_data + |
| 920 | last->current_length + vec_len (n->name), |
| 921 | ": ", 2); |
| 922 | clib_memcpy_fast (last->data + last->current_data + |
| 923 | last->current_length + vec_len (n->name) + |
| 924 | 2, em->error_strings_heap[b0->error], |
| 925 | error_string_len); |
| 926 | last->current_length += drop_string_len; |
| 927 | b0->flags &= ~(VLIB_BUFFER_TOTAL_LENGTH_VALID); |
| 928 | pcap_add_buffer (&pp->pcap_main, vm, bi0, |
| 929 | pp->max_bytes_per_pkt); |
| 930 | last->current_length -= drop_string_len; |
| 931 | b0->current_data = save_current_data; |
| 932 | b0->current_length = save_current_length; |
| 933 | continue; |
| 934 | } |
| 935 | } |
| 936 | |
| 937 | /* |
| 938 | * Didn't have space in the last buffer, here's the dropped |
| 939 | * packet as-is |
| 940 | */ |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 941 | 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] | 942 | |
| 943 | b0->current_data = save_current_data; |
| 944 | b0->current_length = save_current_length; |
| 945 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 946 | } |
| 947 | } |
| 948 | |
Filip Tehlar | 6266877 | 2019-03-04 03:33:32 -0800 | [diff] [blame] | 949 | #ifndef CLIB_MARCH_VARIANT |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 950 | void |
| 951 | 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] | 952 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 953 | vnet_interface_main_t *im = &vnet_get_main ()->interface_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 954 | |
| 955 | if (im->pcap_drop_filter_hash == 0) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 956 | im->pcap_drop_filter_hash = hash_create (0, sizeof (uword)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 957 | |
| 958 | if (is_add) |
| 959 | hash_set (im->pcap_drop_filter_hash, error_index, 1); |
| 960 | else |
| 961 | hash_unset (im->pcap_drop_filter_hash, error_index); |
| 962 | } |
Filip Tehlar | 6266877 | 2019-03-04 03:33:32 -0800 | [diff] [blame] | 963 | #endif /* CLIB_MARCH_VARIANT */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 964 | |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 965 | VLIB_NODE_FN (interface_drop) (vlib_main_t * vm, |
| 966 | vlib_node_runtime_t * node, |
| 967 | vlib_frame_t * frame) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 968 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 969 | vnet_interface_main_t *im = &vnet_get_main ()->interface_main; |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 970 | vnet_pcap_t *pp = &vlib_global_main.pcap; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 971 | |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 972 | if (PREDICT_FALSE (pp->pcap_drop_enable)) |
| 973 | pcap_drop_trace (vm, im, pp, frame); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 974 | |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 975 | return interface_drop_punt (vm, node, frame, VNET_ERROR_DISPOSITION_DROP); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 976 | } |
| 977 | |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 978 | VLIB_NODE_FN (interface_punt) (vlib_main_t * vm, |
| 979 | vlib_node_runtime_t * node, |
| 980 | vlib_frame_t * frame) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 981 | { |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 982 | return interface_drop_punt (vm, node, frame, VNET_ERROR_DISPOSITION_PUNT); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 983 | } |
| 984 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 985 | /* *INDENT-OFF* */ |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 986 | VLIB_REGISTER_NODE (interface_drop) = { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 987 | .name = "error-drop", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 988 | .vector_size = sizeof (u32), |
| 989 | .format_trace = format_vnet_error_trace, |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 990 | .n_next_nodes = 1, |
| 991 | .next_nodes = { |
| 992 | [0] = "drop", |
| 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 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 996 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 997 | /* *INDENT-OFF* */ |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 998 | VLIB_REGISTER_NODE (interface_punt) = { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 999 | .name = "error-punt", |
| 1000 | .vector_size = sizeof (u32), |
| 1001 | .format_trace = format_vnet_error_trace, |
Neale Ranns | 22e1f1d | 2019-03-01 15:53:11 +0000 | [diff] [blame] | 1002 | .n_next_nodes = 1, |
| 1003 | .next_nodes = { |
| 1004 | [0] = "punt", |
| 1005 | }, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1006 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1007 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1008 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1009 | /* *INDENT-OFF* */ |
Filip Tehlar | 6266877 | 2019-03-04 03:33:32 -0800 | [diff] [blame] | 1010 | VLIB_REGISTER_NODE (vnet_per_buffer_interface_output_node) = { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1011 | .name = "interface-output", |
| 1012 | .vector_size = sizeof (u32), |
| 1013 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1014 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1015 | |
Damjan Marion | 152e21d | 2016-11-29 14:55:43 +0100 | [diff] [blame] | 1016 | static uword |
| 1017 | interface_tx_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 1018 | vlib_frame_t * from_frame) |
| 1019 | { |
| 1020 | vnet_main_t *vnm = vnet_get_main (); |
| 1021 | u32 last_sw_if_index = ~0; |
| 1022 | vlib_frame_t *to_frame = 0; |
| 1023 | vnet_hw_interface_t *hw = 0; |
| 1024 | u32 *from, *to_next = 0; |
| 1025 | u32 n_left_from; |
| 1026 | |
| 1027 | from = vlib_frame_vector_args (from_frame); |
| 1028 | n_left_from = from_frame->n_vectors; |
| 1029 | while (n_left_from > 0) |
| 1030 | { |
| 1031 | u32 bi0; |
| 1032 | vlib_buffer_t *b0; |
| 1033 | u32 sw_if_index0; |
| 1034 | |
| 1035 | bi0 = from[0]; |
| 1036 | from++; |
| 1037 | n_left_from--; |
| 1038 | b0 = vlib_get_buffer (vm, bi0); |
| 1039 | sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_TX]; |
| 1040 | |
| 1041 | if (PREDICT_FALSE ((last_sw_if_index != sw_if_index0) || to_frame == 0)) |
| 1042 | { |
| 1043 | if (to_frame) |
| 1044 | { |
| 1045 | hw = vnet_get_sup_hw_interface (vnm, last_sw_if_index); |
| 1046 | vlib_put_frame_to_node (vm, hw->tx_node_index, to_frame); |
| 1047 | } |
| 1048 | last_sw_if_index = sw_if_index0; |
| 1049 | hw = vnet_get_sup_hw_interface (vnm, sw_if_index0); |
| 1050 | to_frame = vlib_get_frame_to_node (vm, hw->tx_node_index); |
| 1051 | to_next = vlib_frame_vector_args (to_frame); |
| 1052 | } |
| 1053 | |
| 1054 | to_next[0] = bi0; |
| 1055 | to_next++; |
| 1056 | to_frame->n_vectors++; |
| 1057 | } |
| 1058 | vlib_put_frame_to_node (vm, hw->tx_node_index, to_frame); |
| 1059 | return from_frame->n_vectors; |
| 1060 | } |
| 1061 | |
| 1062 | /* *INDENT-OFF* */ |
Damjan Marion | d770cfc | 2019-09-02 19:00:33 +0200 | [diff] [blame] | 1063 | VLIB_REGISTER_NODE (interface_tx) = { |
Damjan Marion | 152e21d | 2016-11-29 14:55:43 +0100 | [diff] [blame] | 1064 | .function = interface_tx_node_fn, |
| 1065 | .name = "interface-tx", |
| 1066 | .vector_size = sizeof (u32), |
| 1067 | .n_next_nodes = 1, |
| 1068 | .next_nodes = { |
| 1069 | [0] = "error-drop", |
| 1070 | }, |
| 1071 | }; |
| 1072 | |
| 1073 | VNET_FEATURE_ARC_INIT (interface_output, static) = |
| 1074 | { |
| 1075 | .arc_name = "interface-output", |
| 1076 | .start_nodes = VNET_FEATURES (0), |
Dave Barach | a25def7 | 2018-11-26 11:04:45 -0500 | [diff] [blame] | 1077 | .last_in_arc = "interface-tx", |
Damjan Marion | 152e21d | 2016-11-29 14:55:43 +0100 | [diff] [blame] | 1078 | .arc_index_ptr = &vnet_main.interface_main.output_feature_arc_index, |
| 1079 | }; |
| 1080 | |
Pavel Kotucek | 3a2a1c4 | 2016-12-06 10:10:10 +0100 | [diff] [blame] | 1081 | VNET_FEATURE_INIT (span_tx, static) = { |
| 1082 | .arc_name = "interface-output", |
| 1083 | .node_name = "span-output", |
| 1084 | .runs_before = VNET_FEATURES ("interface-tx"), |
| 1085 | }; |
| 1086 | |
Matthew Smith | 537eeec | 2018-04-09 11:49:20 -0500 | [diff] [blame] | 1087 | VNET_FEATURE_INIT (ipsec_if_tx, static) = { |
| 1088 | .arc_name = "interface-output", |
| 1089 | .node_name = "ipsec-if-output", |
| 1090 | .runs_before = VNET_FEATURES ("interface-tx"), |
| 1091 | }; |
| 1092 | |
Damjan Marion | 152e21d | 2016-11-29 14:55:43 +0100 | [diff] [blame] | 1093 | VNET_FEATURE_INIT (interface_tx, static) = { |
| 1094 | .arc_name = "interface-output", |
| 1095 | .node_name = "interface-tx", |
| 1096 | .runs_before = 0, |
| 1097 | }; |
| 1098 | /* *INDENT-ON* */ |
| 1099 | |
Filip Tehlar | 6266877 | 2019-03-04 03:33:32 -0800 | [diff] [blame] | 1100 | #ifndef CLIB_MARCH_VARIANT |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1101 | clib_error_t * |
| 1102 | vnet_per_buffer_interface_output_hw_interface_add_del (vnet_main_t * vnm, |
| 1103 | u32 hw_if_index, |
| 1104 | u32 is_create) |
| 1105 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1106 | 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] | 1107 | u32 next_index; |
| 1108 | |
John Lo | e5453d0 | 2018-01-23 19:21:34 -0500 | [diff] [blame] | 1109 | if (hi->output_node_index == 0) |
| 1110 | return 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1111 | |
John Lo | e5453d0 | 2018-01-23 19:21:34 -0500 | [diff] [blame] | 1112 | next_index = vlib_node_add_next |
| 1113 | (vnm->vlib_main, vnet_per_buffer_interface_output_node.index, |
| 1114 | hi->output_node_index); |
| 1115 | hi->output_node_next_index = next_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1116 | |
| 1117 | return 0; |
| 1118 | } |
| 1119 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1120 | VNET_HW_INTERFACE_ADD_DEL_FUNCTION |
| 1121 | (vnet_per_buffer_interface_output_hw_interface_add_del); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1122 | |
John Lo | e5453d0 | 2018-01-23 19:21:34 -0500 | [diff] [blame] | 1123 | void |
| 1124 | vnet_set_interface_output_node (vnet_main_t * vnm, |
| 1125 | u32 hw_if_index, u32 node_index) |
| 1126 | { |
| 1127 | ASSERT (node_index); |
| 1128 | vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index); |
| 1129 | u32 next_index = vlib_node_add_next |
| 1130 | (vnm->vlib_main, vnet_per_buffer_interface_output_node.index, node_index); |
| 1131 | hi->output_node_next_index = next_index; |
| 1132 | hi->output_node_index = node_index; |
| 1133 | } |
Filip Tehlar | 6266877 | 2019-03-04 03:33:32 -0800 | [diff] [blame] | 1134 | #endif /* CLIB_MARCH_VARIANT */ |
John Lo | e5453d0 | 2018-01-23 19:21:34 -0500 | [diff] [blame] | 1135 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1136 | /* |
| 1137 | * fd.io coding-style-patch-verification: ON |
| 1138 | * |
| 1139 | * Local Variables: |
| 1140 | * eval: (c-set-style "gnu") |
| 1141 | * End: |
| 1142 | */ |