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