Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * l2_output.c : layer 2 output packet processing |
| 3 | * |
| 4 | * Copyright (c) 2013 Cisco and/or its affiliates. |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at: |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #include <vlib/vlib.h> |
| 19 | #include <vnet/vnet.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 20 | #include <vnet/ethernet/ethernet.h> |
| 21 | #include <vlib/cli.h> |
| 22 | |
| 23 | #include <vppinfra/error.h> |
| 24 | #include <vppinfra/hash.h> |
| 25 | #include <vnet/l2/feat_bitmap.h> |
| 26 | #include <vnet/l2/l2_output.h> |
| 27 | |
| 28 | |
Damjan Marion | 812b32d | 2018-05-28 21:26:47 +0200 | [diff] [blame] | 29 | #ifndef CLIB_MARCH_VARIANT |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 30 | /* Feature graph node names */ |
| 31 | static char *l2output_feat_names[] = { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 32 | #define _(sym,name) name, |
| 33 | foreach_l2output_feat |
| 34 | #undef _ |
| 35 | }; |
| 36 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 37 | char ** |
| 38 | l2output_get_feat_names (void) |
| 39 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 40 | return l2output_feat_names; |
| 41 | } |
| 42 | |
Eyal Bari | 942402b | 2017-07-26 11:57:04 +0300 | [diff] [blame] | 43 | u8 * |
| 44 | format_l2_output_features (u8 * s, va_list * args) |
| 45 | { |
| 46 | static char *display_names[] = { |
| 47 | #define _(sym,name) #sym, |
| 48 | foreach_l2output_feat |
| 49 | #undef _ |
| 50 | }; |
| 51 | u32 feature_bitmap = va_arg (*args, u32); |
Neale Ranns | 5d9df1d | 2018-11-09 08:19:27 -0800 | [diff] [blame] | 52 | u32 verbose = va_arg (*args, u32); |
Eyal Bari | 942402b | 2017-07-26 11:57:04 +0300 | [diff] [blame] | 53 | |
| 54 | if (feature_bitmap == 0) |
| 55 | { |
| 56 | s = format (s, " none configured"); |
| 57 | return s; |
| 58 | } |
| 59 | |
| 60 | int i; |
| 61 | for (i = L2OUTPUT_N_FEAT - 1; i >= 0; i--) |
Neale Ranns | 5d9df1d | 2018-11-09 08:19:27 -0800 | [diff] [blame] | 62 | { |
| 63 | if (feature_bitmap & (1 << i)) |
| 64 | { |
| 65 | if (verbose) |
| 66 | s = |
| 67 | format (s, "%17s (%s)\n", display_names[i], |
| 68 | l2output_feat_names[i]); |
| 69 | else |
| 70 | s = format (s, "%s ", l2output_feat_names[i]); |
| 71 | } |
| 72 | } |
| 73 | |
Eyal Bari | 942402b | 2017-07-26 11:57:04 +0300 | [diff] [blame] | 74 | return s; |
| 75 | } |
| 76 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 77 | l2output_main_t l2output_main; |
Damjan Marion | f3b2746 | 2018-05-15 19:51:38 +0200 | [diff] [blame] | 78 | #endif |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 79 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 80 | typedef struct |
| 81 | { |
| 82 | /* per-pkt trace data */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 83 | u8 src[6]; |
| 84 | u8 dst[6]; |
| 85 | u32 sw_if_index; |
Pavel Kotucek | 65e8457 | 2017-01-16 17:01:56 +0100 | [diff] [blame] | 86 | u8 raw[12]; /* raw data */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 87 | } l2output_trace_t; |
| 88 | |
| 89 | /* packet trace format function */ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 90 | static u8 * |
| 91 | format_l2output_trace (u8 * s, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 92 | { |
| 93 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 94 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 95 | l2output_trace_t *t = va_arg (*args, l2output_trace_t *); |
| 96 | |
Pavel Kotucek | 65e8457 | 2017-01-16 17:01:56 +0100 | [diff] [blame] | 97 | s = format (s, "l2-output: sw_if_index %d dst %U src %U data " |
| 98 | "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 99 | t->sw_if_index, |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 100 | format_ethernet_address, t->dst, |
Pavel Kotucek | 65e8457 | 2017-01-16 17:01:56 +0100 | [diff] [blame] | 101 | format_ethernet_address, t->src, |
| 102 | t->raw[0], t->raw[1], t->raw[2], t->raw[3], t->raw[4], |
| 103 | t->raw[5], t->raw[6], t->raw[7], t->raw[8], t->raw[9], |
| 104 | t->raw[10], t->raw[11]); |
| 105 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 106 | return s; |
| 107 | } |
| 108 | |
| 109 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 110 | static char *l2output_error_strings[] = { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 111 | #define _(sym,string) string, |
| 112 | foreach_l2output_error |
| 113 | #undef _ |
| 114 | }; |
| 115 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 116 | /** |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 117 | * Check for split horizon violations. |
| 118 | * Return 0 if split horizon check passes, otherwise return non-zero. |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 119 | * Packets should not be transmitted out an interface with the same |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 120 | * split-horizon group as the input interface, except if the @c shg is 0 |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 121 | * in which case the check always passes. |
| 122 | */ |
John Lo | beb0b2e | 2017-07-22 00:21:36 -0400 | [diff] [blame] | 123 | static_always_inline void |
Damjan Marion | f3b2746 | 2018-05-15 19:51:38 +0200 | [diff] [blame] | 124 | split_horizon_violation (vlib_node_runtime_t * node, u8 shg, |
| 125 | vlib_buffer_t * b, u16 * next) |
John Lo | beb0b2e | 2017-07-22 00:21:36 -0400 | [diff] [blame] | 126 | { |
Damjan Marion | f3b2746 | 2018-05-15 19:51:38 +0200 | [diff] [blame] | 127 | if (shg != vnet_buffer (b)->l2.shg) |
| 128 | return; |
| 129 | next[0] = L2OUTPUT_NEXT_DROP; |
| 130 | b->error = node->errors[L2OUTPUT_ERROR_SHG_DROP]; |
John Lo | beb0b2e | 2017-07-22 00:21:36 -0400 | [diff] [blame] | 131 | } |
| 132 | |
Damjan Marion | dc5252b | 2016-11-24 19:25:01 -0800 | [diff] [blame] | 133 | static_always_inline void |
Damjan Marion | f3b2746 | 2018-05-15 19:51:38 +0200 | [diff] [blame] | 134 | l2output_process_batch_inline (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 135 | l2_output_config_t * config, |
| 136 | vlib_buffer_t ** b, i16 * cdo, u16 * next, |
| 137 | u32 n_left, int l2_efp, int l2_vtr, int l2_pbb, |
| 138 | int shg_set, int update_feature_bitmap) |
Damjan Marion | dc5252b | 2016-11-24 19:25:01 -0800 | [diff] [blame] | 139 | { |
Damjan Marion | f3b2746 | 2018-05-15 19:51:38 +0200 | [diff] [blame] | 140 | while (n_left >= 8) |
Damjan Marion | dc5252b | 2016-11-24 19:25:01 -0800 | [diff] [blame] | 141 | { |
Damjan Marion | f3b2746 | 2018-05-15 19:51:38 +0200 | [diff] [blame] | 142 | vlib_prefetch_buffer_header (b[4], LOAD); |
| 143 | vlib_prefetch_buffer_header (b[5], LOAD); |
| 144 | vlib_prefetch_buffer_header (b[6], LOAD); |
| 145 | vlib_prefetch_buffer_header (b[7], LOAD); |
Damjan Marion | dc5252b | 2016-11-24 19:25:01 -0800 | [diff] [blame] | 146 | |
Damjan Marion | f3b2746 | 2018-05-15 19:51:38 +0200 | [diff] [blame] | 147 | /* prefetch eth headers only if we need to touch them */ |
| 148 | if (l2_vtr || l2_pbb || shg_set) |
| 149 | { |
Damjan Marion | af7fb04 | 2021-07-15 11:54:41 +0200 | [diff] [blame] | 150 | clib_prefetch_load (b[4]->data + cdo[4]); |
| 151 | clib_prefetch_load (b[5]->data + cdo[5]); |
| 152 | clib_prefetch_load (b[6]->data + cdo[6]); |
| 153 | clib_prefetch_load (b[7]->data + cdo[7]); |
Damjan Marion | f3b2746 | 2018-05-15 19:51:38 +0200 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | if (update_feature_bitmap) |
| 157 | { |
| 158 | vnet_buffer (b[0])->l2.feature_bitmap = config->feature_bitmap; |
| 159 | vnet_buffer (b[1])->l2.feature_bitmap = config->feature_bitmap; |
| 160 | vnet_buffer (b[2])->l2.feature_bitmap = config->feature_bitmap; |
| 161 | vnet_buffer (b[3])->l2.feature_bitmap = config->feature_bitmap; |
| 162 | } |
| 163 | |
| 164 | if (l2_vtr) |
| 165 | { |
| 166 | int i; |
| 167 | for (i = 0; i < 4; i++) |
| 168 | { |
| 169 | u32 failed1 = l2_efp && |
| 170 | l2_efp_filter_process (b[i], &(config->input_vtr)); |
| 171 | u32 failed2 = l2_vtr_process (b[i], &(config->output_vtr)); |
| 172 | if (PREDICT_FALSE (failed1 | failed2)) |
| 173 | { |
| 174 | next[i] = L2OUTPUT_NEXT_DROP; |
| 175 | if (failed2) |
| 176 | b[i]->error = node->errors[L2OUTPUT_ERROR_VTR_DROP]; |
| 177 | if (failed1) |
| 178 | b[i]->error = node->errors[L2OUTPUT_ERROR_EFP_DROP]; |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | if (l2_pbb) |
| 184 | { |
| 185 | int i; |
| 186 | for (i = 0; i < 4; i++) |
| 187 | if (l2_pbb_process (b[i], &(config->output_pbb_vtr))) |
| 188 | { |
| 189 | next[i] = L2OUTPUT_NEXT_DROP; |
| 190 | b[i]->error = node->errors[L2OUTPUT_ERROR_VTR_DROP]; |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | if (shg_set) |
| 195 | { |
| 196 | split_horizon_violation (node, config->shg, b[0], next); |
| 197 | split_horizon_violation (node, config->shg, b[1], next + 1); |
| 198 | split_horizon_violation (node, config->shg, b[2], next + 2); |
| 199 | split_horizon_violation (node, config->shg, b[3], next + 3); |
| 200 | } |
| 201 | /* next */ |
| 202 | n_left -= 4; |
| 203 | b += 4; |
| 204 | next += 4; |
| 205 | cdo += 4; |
| 206 | } |
| 207 | |
| 208 | while (n_left) |
| 209 | { |
| 210 | if (update_feature_bitmap) |
| 211 | vnet_buffer (b[0])->l2.feature_bitmap = config->feature_bitmap; |
| 212 | |
| 213 | if (l2_vtr) |
| 214 | { |
| 215 | u32 failed1 = l2_efp && |
| 216 | l2_efp_filter_process (b[0], &(config->input_vtr)); |
| 217 | u32 failed2 = l2_vtr_process (b[0], &(config->output_vtr)); |
Damjan Marion | dc5252b | 2016-11-24 19:25:01 -0800 | [diff] [blame] | 218 | if (PREDICT_FALSE (failed1 | failed2)) |
| 219 | { |
| 220 | *next = L2OUTPUT_NEXT_DROP; |
| 221 | if (failed2) |
Damjan Marion | f3b2746 | 2018-05-15 19:51:38 +0200 | [diff] [blame] | 222 | b[0]->error = node->errors[L2OUTPUT_ERROR_VTR_DROP]; |
Damjan Marion | dc5252b | 2016-11-24 19:25:01 -0800 | [diff] [blame] | 223 | if (failed1) |
Damjan Marion | f3b2746 | 2018-05-15 19:51:38 +0200 | [diff] [blame] | 224 | b[0]->error = node->errors[L2OUTPUT_ERROR_EFP_DROP]; |
Damjan Marion | dc5252b | 2016-11-24 19:25:01 -0800 | [diff] [blame] | 225 | } |
| 226 | } |
Damjan Marion | f3b2746 | 2018-05-15 19:51:38 +0200 | [diff] [blame] | 227 | |
| 228 | if (l2_pbb && l2_pbb_process (b[0], &(config->output_pbb_vtr))) |
Damjan Marion | dc5252b | 2016-11-24 19:25:01 -0800 | [diff] [blame] | 229 | { |
Damjan Marion | f3b2746 | 2018-05-15 19:51:38 +0200 | [diff] [blame] | 230 | next[0] = L2OUTPUT_NEXT_DROP; |
| 231 | b[0]->error = node->errors[L2OUTPUT_ERROR_VTR_DROP]; |
Damjan Marion | dc5252b | 2016-11-24 19:25:01 -0800 | [diff] [blame] | 232 | } |
Damjan Marion | f3b2746 | 2018-05-15 19:51:38 +0200 | [diff] [blame] | 233 | |
| 234 | if (shg_set) |
| 235 | split_horizon_violation (node, config->shg, b[0], next); |
| 236 | |
| 237 | /* next */ |
| 238 | n_left -= 1; |
| 239 | b += 1; |
| 240 | next += 1; |
Damjan Marion | dc5252b | 2016-11-24 19:25:01 -0800 | [diff] [blame] | 241 | } |
| 242 | } |
| 243 | |
Damjan Marion | f3b2746 | 2018-05-15 19:51:38 +0200 | [diff] [blame] | 244 | static_always_inline void |
| 245 | l2output_set_buffer_error (vlib_buffer_t ** b, u32 n_left, vlib_error_t error) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 246 | { |
Damjan Marion | f3b2746 | 2018-05-15 19:51:38 +0200 | [diff] [blame] | 247 | while (n_left >= 8) |
| 248 | { |
| 249 | vlib_prefetch_buffer_header (b[4], LOAD); |
| 250 | vlib_prefetch_buffer_header (b[5], LOAD); |
| 251 | vlib_prefetch_buffer_header (b[6], LOAD); |
| 252 | vlib_prefetch_buffer_header (b[7], LOAD); |
| 253 | b[0]->error = b[1]->error = b[2]->error = b[3]->error = error; |
| 254 | b += 4; |
| 255 | n_left -= 4; |
| 256 | } |
| 257 | while (n_left) |
| 258 | { |
| 259 | b[0]->error = error; |
| 260 | b += 1; |
| 261 | n_left -= 1; |
| 262 | } |
| 263 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 264 | |
Damjan Marion | f3b2746 | 2018-05-15 19:51:38 +0200 | [diff] [blame] | 265 | static_always_inline void |
| 266 | l2output_process_batch (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 267 | l2_output_config_t * config, vlib_buffer_t ** b, |
| 268 | i16 * cdo, u16 * next, u32 n_left, int l2_efp, |
| 269 | int l2_vtr, int l2_pbb) |
| 270 | { |
| 271 | u32 feature_bitmap = config->feature_bitmap & ~L2OUTPUT_FEAT_OUTPUT; |
| 272 | if (config->shg == 0 && feature_bitmap == 0) |
Eyal Bari | ceb8d5a | 2018-09-02 17:08:22 +0300 | [diff] [blame] | 273 | { |
| 274 | if ((l2_efp | l2_vtr | l2_pbb) == 0) |
| 275 | return; |
| 276 | l2output_process_batch_inline (vm, node, config, b, cdo, next, n_left, |
| 277 | l2_efp, l2_vtr, l2_pbb, 0, 0); |
| 278 | } |
Damjan Marion | f3b2746 | 2018-05-15 19:51:38 +0200 | [diff] [blame] | 279 | else if (config->shg == 0) |
| 280 | l2output_process_batch_inline (vm, node, config, b, cdo, next, n_left, |
| 281 | l2_efp, l2_vtr, l2_pbb, 0, 1); |
| 282 | else if (feature_bitmap == 0) |
| 283 | l2output_process_batch_inline (vm, node, config, b, cdo, next, n_left, |
| 284 | l2_efp, l2_vtr, l2_pbb, 1, 0); |
| 285 | else |
| 286 | l2output_process_batch_inline (vm, node, config, b, cdo, next, n_left, |
| 287 | l2_efp, l2_vtr, l2_pbb, 1, 1); |
| 288 | } |
| 289 | |
Damjan Marion | 812b32d | 2018-05-28 21:26:47 +0200 | [diff] [blame] | 290 | VLIB_NODE_FN (l2output_node) (vlib_main_t * vm, |
| 291 | vlib_node_runtime_t * node, |
| 292 | vlib_frame_t * frame) |
Damjan Marion | f3b2746 | 2018-05-15 19:51:38 +0200 | [diff] [blame] | 293 | { |
| 294 | u32 n_left, *from; |
| 295 | l2output_main_t *msm = &l2output_main; |
| 296 | vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b; |
| 297 | u16 nexts[VLIB_FRAME_SIZE]; |
| 298 | u32 sw_if_indices[VLIB_FRAME_SIZE], *sw_if_index; |
| 299 | i16 cur_data_offsets[VLIB_FRAME_SIZE], *cdo; |
| 300 | l2_output_config_t *config; |
| 301 | u32 feature_bitmap; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 302 | |
| 303 | from = vlib_frame_vector_args (frame); |
Damjan Marion | f3b2746 | 2018-05-15 19:51:38 +0200 | [diff] [blame] | 304 | n_left = frame->n_vectors; /* number of packets to process */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 305 | |
Damjan Marion | f3b2746 | 2018-05-15 19:51:38 +0200 | [diff] [blame] | 306 | vlib_get_buffers (vm, from, bufs, n_left); |
| 307 | b = bufs; |
| 308 | sw_if_index = sw_if_indices; |
| 309 | cdo = cur_data_offsets; |
| 310 | |
| 311 | /* extract data from buffer metadata */ |
| 312 | while (n_left >= 8) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 313 | { |
Damjan Marion | f3b2746 | 2018-05-15 19:51:38 +0200 | [diff] [blame] | 314 | /* Prefetch the buffer header for the N+2 loop iteration */ |
| 315 | vlib_prefetch_buffer_header (b[4], LOAD); |
| 316 | vlib_prefetch_buffer_header (b[5], LOAD); |
| 317 | vlib_prefetch_buffer_header (b[6], LOAD); |
| 318 | vlib_prefetch_buffer_header (b[7], LOAD); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 319 | |
Damjan Marion | f3b2746 | 2018-05-15 19:51:38 +0200 | [diff] [blame] | 320 | sw_if_index[0] = vnet_buffer (b[0])->sw_if_index[VLIB_TX]; |
| 321 | cdo[0] = b[0]->current_data; |
| 322 | sw_if_index[1] = vnet_buffer (b[1])->sw_if_index[VLIB_TX]; |
| 323 | cdo[1] = b[1]->current_data; |
| 324 | sw_if_index[2] = vnet_buffer (b[2])->sw_if_index[VLIB_TX]; |
| 325 | cdo[2] = b[2]->current_data; |
| 326 | sw_if_index[3] = vnet_buffer (b[3])->sw_if_index[VLIB_TX]; |
| 327 | cdo[3] = b[3]->current_data; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 328 | |
Damjan Marion | f3b2746 | 2018-05-15 19:51:38 +0200 | [diff] [blame] | 329 | /* next */ |
| 330 | sw_if_index += 4; |
| 331 | n_left -= 4; |
| 332 | b += 4; |
| 333 | cdo += 4; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 334 | } |
Damjan Marion | f3b2746 | 2018-05-15 19:51:38 +0200 | [diff] [blame] | 335 | while (n_left) |
| 336 | { |
| 337 | sw_if_index[0] = vnet_buffer (b[0])->sw_if_index[VLIB_TX]; |
| 338 | cdo[0] = b[0]->current_data; |
| 339 | |
| 340 | /* next */ |
| 341 | sw_if_index += 1; |
| 342 | n_left -= 1; |
| 343 | b += 1; |
| 344 | cdo += 1; |
| 345 | } |
| 346 | |
| 347 | n_left = frame->n_vectors; |
| 348 | while (n_left) |
| 349 | { |
| 350 | u16 count, new_next, *next; |
| 351 | u16 off = frame->n_vectors - n_left; |
| 352 | b = bufs + off; |
| 353 | |
| 354 | if (n_left >= 4) |
| 355 | { |
| 356 | vlib_prefetch_buffer_header (b[0], LOAD); |
| 357 | vlib_prefetch_buffer_header (b[1], LOAD); |
| 358 | vlib_prefetch_buffer_header (b[2], LOAD); |
| 359 | vlib_prefetch_buffer_header (b[3], LOAD); |
| 360 | } |
| 361 | |
| 362 | sw_if_index = sw_if_indices + off; |
| 363 | cdo = cur_data_offsets + off; |
| 364 | next = nexts + off; |
| 365 | |
| 366 | count = clib_count_equal_u32 (sw_if_index, n_left); |
| 367 | n_left -= count; |
| 368 | |
| 369 | config = vec_elt_at_index (msm->configs, sw_if_index[0]); |
| 370 | feature_bitmap = config->feature_bitmap; |
| 371 | if (PREDICT_FALSE ((feature_bitmap & ~L2OUTPUT_FEAT_OUTPUT) != 0)) |
| 372 | new_next = feat_bitmap_get_next_node_index |
| 373 | (l2output_main.l2_out_feat_next, feature_bitmap); |
| 374 | else |
| 375 | new_next = vec_elt (l2output_main.output_node_index_vec, |
| 376 | sw_if_index[0]); |
| 377 | clib_memset_u16 (nexts + off, new_next, count); |
| 378 | |
| 379 | if (new_next == L2OUTPUT_NEXT_DROP) |
| 380 | { |
| 381 | l2output_set_buffer_error |
| 382 | (b, count, node->errors[L2OUTPUT_ERROR_MAPPING_DROP]); |
| 383 | continue; |
| 384 | } |
| 385 | |
| 386 | /* VTR */ |
| 387 | if (config->out_vtr_flag && config->output_vtr.push_and_pop_bytes) |
| 388 | { |
| 389 | if (feature_bitmap & L2OUTPUT_FEAT_EFP_FILTER) |
| 390 | l2output_process_batch (vm, node, config, b, cdo, next, count, |
| 391 | /* l2_efp */ 1, |
| 392 | /* l2_vtr */ 1, |
| 393 | /* l2_pbb */ 0); |
| 394 | else |
| 395 | l2output_process_batch (vm, node, config, b, cdo, next, count, |
| 396 | /* l2_efp */ 0, |
| 397 | /* l2_vtr */ 1, |
| 398 | /* l2_pbb */ 0); |
| 399 | } |
| 400 | else if (config->out_vtr_flag && |
| 401 | config->output_pbb_vtr.push_and_pop_bytes) |
| 402 | l2output_process_batch (vm, node, config, b, cdo, next, count, |
| 403 | /* l2_efp */ 0, |
| 404 | /* l2_vtr */ 0, |
| 405 | /* l2_pbb */ 1); |
| 406 | else |
| 407 | l2output_process_batch (vm, node, config, b, cdo, next, count, |
| 408 | /* l2_efp */ 0, |
| 409 | /* l2_vtr */ 0, |
| 410 | /* l2_pbb */ 0); |
| 411 | } |
| 412 | |
| 413 | |
| 414 | if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE))) |
| 415 | { |
| 416 | n_left = frame->n_vectors; /* number of packets to process */ |
| 417 | b = bufs; |
| 418 | |
| 419 | while (n_left) |
| 420 | { |
| 421 | if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED)) |
| 422 | { |
| 423 | ethernet_header_t *h; |
| 424 | l2output_trace_t *t = |
| 425 | vlib_add_trace (vm, node, b[0], sizeof (*t)); |
| 426 | t->sw_if_index = vnet_buffer (b[0])->sw_if_index[VLIB_TX]; |
| 427 | h = vlib_buffer_get_current (b[0]); |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 428 | clib_memcpy_fast (t->src, h->src_address, 6); |
| 429 | clib_memcpy_fast (t->dst, h->dst_address, 6); |
| 430 | clib_memcpy_fast (t->raw, &h->type, sizeof (t->raw)); |
Damjan Marion | f3b2746 | 2018-05-15 19:51:38 +0200 | [diff] [blame] | 431 | } |
| 432 | /* next */ |
| 433 | n_left--; |
| 434 | b++; |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | vlib_buffer_enqueue_to_next (vm, node, from, nexts, frame->n_vectors); |
| 439 | vlib_node_increment_counter (vm, l2output_node.index, |
| 440 | L2OUTPUT_ERROR_L2OUTPUT, frame->n_vectors); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 441 | |
| 442 | return frame->n_vectors; |
| 443 | } |
| 444 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 445 | /* *INDENT-OFF* */ |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 446 | VLIB_REGISTER_NODE (l2output_node) = { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 447 | .name = "l2-output", |
| 448 | .vector_size = sizeof (u32), |
| 449 | .format_trace = format_l2output_trace, |
| 450 | .type = VLIB_NODE_TYPE_INTERNAL, |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 451 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 452 | .n_errors = ARRAY_LEN(l2output_error_strings), |
| 453 | .error_strings = l2output_error_strings, |
| 454 | |
| 455 | .n_next_nodes = L2OUTPUT_N_NEXT, |
| 456 | |
| 457 | /* edit / add dispositions here */ |
| 458 | .next_nodes = { |
| 459 | [L2OUTPUT_NEXT_DROP] = "error-drop", |
John Lo | 0fc9bc1 | 2016-10-27 11:17:02 -0400 | [diff] [blame] | 460 | [L2OUTPUT_NEXT_BAD_INTF] = "l2-output-bad-intf", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 461 | }, |
| 462 | }; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 463 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 464 | |
John Lo | 3ef822e | 2016-06-07 09:14:07 -0400 | [diff] [blame] | 465 | |
John Lo | 0fc9bc1 | 2016-10-27 11:17:02 -0400 | [diff] [blame] | 466 | #define foreach_l2output_bad_intf_error \ |
| 467 | _(DROP, "L2 output to interface not in L2 mode or deleted") |
John Lo | 3ef822e | 2016-06-07 09:14:07 -0400 | [diff] [blame] | 468 | |
John Lo | 0fc9bc1 | 2016-10-27 11:17:02 -0400 | [diff] [blame] | 469 | static char *l2output_bad_intf_error_strings[] = { |
John Lo | 3ef822e | 2016-06-07 09:14:07 -0400 | [diff] [blame] | 470 | #define _(sym,string) string, |
John Lo | 0fc9bc1 | 2016-10-27 11:17:02 -0400 | [diff] [blame] | 471 | foreach_l2output_bad_intf_error |
John Lo | 3ef822e | 2016-06-07 09:14:07 -0400 | [diff] [blame] | 472 | #undef _ |
| 473 | }; |
| 474 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 475 | typedef enum |
| 476 | { |
John Lo | 0fc9bc1 | 2016-10-27 11:17:02 -0400 | [diff] [blame] | 477 | #define _(sym,str) L2OUTPUT_BAD_INTF_ERROR_##sym, |
| 478 | foreach_l2output_bad_intf_error |
John Lo | 3ef822e | 2016-06-07 09:14:07 -0400 | [diff] [blame] | 479 | #undef _ |
John Lo | 0fc9bc1 | 2016-10-27 11:17:02 -0400 | [diff] [blame] | 480 | L2OUTPUT_BAD_INTF_N_ERROR, |
| 481 | } l2output_bad_intf_error_t; |
John Lo | 3ef822e | 2016-06-07 09:14:07 -0400 | [diff] [blame] | 482 | |
| 483 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 484 | /** |
John Lo | 0fc9bc1 | 2016-10-27 11:17:02 -0400 | [diff] [blame] | 485 | * Output node for interfaces/tunnels which was in L2 mode but were changed |
| 486 | * to L3 mode or possibly deleted thereafter. On changing forwarding mode |
| 487 | * of any tunnel/interface from L2 to L3, its entry in l2_output_main table |
| 488 | * next_nodes.output_node_index_vec[sw_if_index] MUST be set to the value of |
| 489 | * L2OUTPUT_NEXT_BAD_INTF. Thus, if there are stale entries in the L2FIB for |
| 490 | * this sw_if_index, l2-output will send packets for this sw_if_index to the |
| 491 | * l2-output-bad-intf node which just setup the proper drop reason before |
| 492 | * sending packets to the error-drop node to drop the packet. Then, stale L2FIB |
Paul Vinciguerra | bdc0e6b | 2018-09-22 05:32:50 -0700 | [diff] [blame] | 493 | * entries for deleted tunnels won't cause possible packet or memory corruption. |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 494 | */ |
John Lo | 3ef822e | 2016-06-07 09:14:07 -0400 | [diff] [blame] | 495 | |
Damjan Marion | 6e36351 | 2018-08-10 22:39:11 +0200 | [diff] [blame] | 496 | VLIB_NODE_FN (l2output_bad_intf_node) (vlib_main_t * vm, |
| 497 | vlib_node_runtime_t * node, |
| 498 | vlib_frame_t * frame) |
John Lo | 3ef822e | 2016-06-07 09:14:07 -0400 | [diff] [blame] | 499 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 500 | u32 n_left_from, *from, *to_next; |
John Lo | 3ef822e | 2016-06-07 09:14:07 -0400 | [diff] [blame] | 501 | l2output_next_t next_index = 0; |
| 502 | |
| 503 | from = vlib_frame_vector_args (frame); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 504 | n_left_from = frame->n_vectors; /* number of packets to process */ |
John Lo | 3ef822e | 2016-06-07 09:14:07 -0400 | [diff] [blame] | 505 | |
| 506 | while (n_left_from > 0) |
| 507 | { |
| 508 | u32 n_left_to_next; |
| 509 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 510 | /* get space to enqueue frame to graph node "next_index" */ |
| 511 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
John Lo | 3ef822e | 2016-06-07 09:14:07 -0400 | [diff] [blame] | 512 | |
| 513 | while (n_left_from >= 4 && n_left_to_next >= 2) |
| 514 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 515 | u32 bi0, bi1; |
| 516 | vlib_buffer_t *b0, *b1; |
John Lo | 3ef822e | 2016-06-07 09:14:07 -0400 | [diff] [blame] | 517 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 518 | to_next[0] = bi0 = from[0]; |
John Lo | 3ef822e | 2016-06-07 09:14:07 -0400 | [diff] [blame] | 519 | to_next[1] = bi1 = from[1]; |
| 520 | from += 2; |
| 521 | to_next += 2; |
| 522 | n_left_from -= 2; |
| 523 | n_left_to_next -= 2; |
| 524 | b0 = vlib_get_buffer (vm, bi0); |
| 525 | b1 = vlib_get_buffer (vm, bi1); |
John Lo | 0fc9bc1 | 2016-10-27 11:17:02 -0400 | [diff] [blame] | 526 | b0->error = node->errors[L2OUTPUT_BAD_INTF_ERROR_DROP]; |
| 527 | b1->error = node->errors[L2OUTPUT_BAD_INTF_ERROR_DROP]; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 528 | } |
| 529 | |
John Lo | 3ef822e | 2016-06-07 09:14:07 -0400 | [diff] [blame] | 530 | while (n_left_from > 0 && n_left_to_next > 0) |
| 531 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 532 | u32 bi0; |
| 533 | vlib_buffer_t *b0; |
John Lo | 3ef822e | 2016-06-07 09:14:07 -0400 | [diff] [blame] | 534 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 535 | bi0 = from[0]; |
John Lo | 3ef822e | 2016-06-07 09:14:07 -0400 | [diff] [blame] | 536 | to_next[0] = bi0; |
| 537 | from += 1; |
| 538 | to_next += 1; |
| 539 | n_left_from -= 1; |
| 540 | n_left_to_next -= 1; |
| 541 | b0 = vlib_get_buffer (vm, bi0); |
John Lo | 0fc9bc1 | 2016-10-27 11:17:02 -0400 | [diff] [blame] | 542 | b0->error = node->errors[L2OUTPUT_BAD_INTF_ERROR_DROP]; |
John Lo | 3ef822e | 2016-06-07 09:14:07 -0400 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 546 | } |
| 547 | |
| 548 | return frame->n_vectors; |
| 549 | } |
| 550 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 551 | /* *INDENT-OFF* */ |
Damjan Marion | 6e36351 | 2018-08-10 22:39:11 +0200 | [diff] [blame] | 552 | VLIB_REGISTER_NODE (l2output_bad_intf_node) = { |
John Lo | 0fc9bc1 | 2016-10-27 11:17:02 -0400 | [diff] [blame] | 553 | .name = "l2-output-bad-intf", |
John Lo | 3ef822e | 2016-06-07 09:14:07 -0400 | [diff] [blame] | 554 | .vector_size = sizeof (u32), |
| 555 | .type = VLIB_NODE_TYPE_INTERNAL, |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 556 | |
John Lo | 0fc9bc1 | 2016-10-27 11:17:02 -0400 | [diff] [blame] | 557 | .n_errors = ARRAY_LEN(l2output_bad_intf_error_strings), |
| 558 | .error_strings = l2output_bad_intf_error_strings, |
John Lo | 3ef822e | 2016-06-07 09:14:07 -0400 | [diff] [blame] | 559 | |
| 560 | .n_next_nodes = 1, |
| 561 | |
| 562 | /* edit / add dispositions here */ |
| 563 | .next_nodes = { |
| 564 | [0] = "error-drop", |
| 565 | }, |
| 566 | }; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 567 | /* *INDENT-ON* */ |
John Lo | 3ef822e | 2016-06-07 09:14:07 -0400 | [diff] [blame] | 568 | |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 569 | static clib_error_t * |
| 570 | l2output_init (vlib_main_t * vm) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 571 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 572 | l2output_main_t *mp = &l2output_main; |
| 573 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 574 | mp->vlib_main = vm; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 575 | mp->vnet_main = vnet_get_main (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 576 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 577 | /* Create the config vector */ |
| 578 | vec_validate (mp->configs, 100); |
| 579 | /* Until we hook up the CLI config, just create 100 sw interface entries and zero them */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 580 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 581 | /* Initialize the feature next-node indexes */ |
| 582 | feat_bitmap_init_next_nodes (vm, |
| 583 | l2output_node.index, |
| 584 | L2OUTPUT_N_FEAT, |
| 585 | l2output_get_feat_names (), |
John Lo | beb0b2e | 2017-07-22 00:21:36 -0400 | [diff] [blame] | 586 | mp->l2_out_feat_next); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 587 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 588 | /* Initialize the output node mapping table */ |
John Lo | beb0b2e | 2017-07-22 00:21:36 -0400 | [diff] [blame] | 589 | vec_validate_init_empty (mp->output_node_index_vec, 100, |
John Lo | b2fd6cb | 2017-07-12 19:56:45 -0400 | [diff] [blame] | 590 | L2OUTPUT_NEXT_DROP); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 591 | |
| 592 | return 0; |
| 593 | } |
| 594 | |
| 595 | VLIB_INIT_FUNCTION (l2output_init); |
| 596 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 597 | |
Damjan Marion | 6e36351 | 2018-08-10 22:39:11 +0200 | [diff] [blame] | 598 | #ifndef CLIB_MARCH_VARIANT |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 599 | /** Create a mapping in the next node mapping table for the given sw_if_index. */ |
John Lo | b2fd6cb | 2017-07-12 19:56:45 -0400 | [diff] [blame] | 600 | void |
| 601 | l2output_create_output_node_mapping (vlib_main_t * vlib_main, |
| 602 | vnet_main_t * vnet_main, u32 sw_if_index) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 603 | { |
John Lo | b2fd6cb | 2017-07-12 19:56:45 -0400 | [diff] [blame] | 604 | vnet_hw_interface_t *hw0 = |
| 605 | vnet_get_sup_hw_interface (vnet_main, sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 606 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 607 | /* dynamically create graph node arc */ |
John Lo | b2fd6cb | 2017-07-12 19:56:45 -0400 | [diff] [blame] | 608 | u32 next = vlib_node_add_next (vlib_main, l2output_node.index, |
| 609 | hw0->output_node_index); |
John Lo | beb0b2e | 2017-07-22 00:21:36 -0400 | [diff] [blame] | 610 | l2output_main.output_node_index_vec[sw_if_index] = next; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 611 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 612 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 613 | /* Get a pointer to the config for the given interface */ |
| 614 | l2_output_config_t * |
| 615 | l2output_intf_config (u32 sw_if_index) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 616 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 617 | l2output_main_t *mp = &l2output_main; |
| 618 | |
| 619 | vec_validate (mp->configs, sw_if_index); |
| 620 | return vec_elt_at_index (mp->configs, sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 621 | } |
| 622 | |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 623 | /** Enable (or disable) the feature in the bitmap for the given interface. */ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 624 | void |
Neale Ranns | a117958 | 2018-10-24 02:31:51 -0700 | [diff] [blame] | 625 | l2output_intf_bitmap_enable (u32 sw_if_index, |
| 626 | l2output_feat_masks_t feature_bitmap, u32 enable) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 627 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 628 | l2output_main_t *mp = &l2output_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 629 | l2_output_config_t *config; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 630 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 631 | vec_validate (mp->configs, sw_if_index); |
| 632 | config = vec_elt_at_index (mp->configs, sw_if_index); |
| 633 | |
| 634 | if (enable) |
| 635 | { |
| 636 | config->feature_bitmap |= feature_bitmap; |
| 637 | } |
| 638 | else |
| 639 | { |
| 640 | config->feature_bitmap &= ~feature_bitmap; |
| 641 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 642 | } |
Damjan Marion | f3b2746 | 2018-05-15 19:51:38 +0200 | [diff] [blame] | 643 | #endif |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 644 | |
| 645 | /* |
| 646 | * fd.io coding-style-patch-verification: ON |
| 647 | * |
| 648 | * Local Variables: |
| 649 | * eval: (c-set-style "gnu") |
| 650 | * End: |
| 651 | */ |