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