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 | |
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); |
| 52 | |
| 53 | if (feature_bitmap == 0) |
| 54 | { |
| 55 | s = format (s, " none configured"); |
| 56 | return s; |
| 57 | } |
| 58 | |
| 59 | int i; |
| 60 | for (i = L2OUTPUT_N_FEAT - 1; i >= 0; i--) |
| 61 | if (feature_bitmap & (1 << i)) |
| 62 | s = format (s, "%10s (%s)\n", display_names[i], l2output_feat_names[i]); |
| 63 | return s; |
| 64 | } |
| 65 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 66 | l2output_main_t l2output_main; |
| 67 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 68 | typedef struct |
| 69 | { |
| 70 | /* per-pkt trace data */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 71 | u8 src[6]; |
| 72 | u8 dst[6]; |
| 73 | u32 sw_if_index; |
Pavel Kotucek | 65e8457 | 2017-01-16 17:01:56 +0100 | [diff] [blame] | 74 | u8 raw[12]; /* raw data */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 75 | } l2output_trace_t; |
| 76 | |
| 77 | /* packet trace format function */ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 78 | static u8 * |
| 79 | format_l2output_trace (u8 * s, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 80 | { |
| 81 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 82 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 83 | l2output_trace_t *t = va_arg (*args, l2output_trace_t *); |
| 84 | |
Pavel Kotucek | 65e8457 | 2017-01-16 17:01:56 +0100 | [diff] [blame] | 85 | s = format (s, "l2-output: sw_if_index %d dst %U src %U data " |
| 86 | "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 87 | t->sw_if_index, |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 88 | format_ethernet_address, t->dst, |
Pavel Kotucek | 65e8457 | 2017-01-16 17:01:56 +0100 | [diff] [blame] | 89 | format_ethernet_address, t->src, |
| 90 | t->raw[0], t->raw[1], t->raw[2], t->raw[3], t->raw[4], |
| 91 | t->raw[5], t->raw[6], t->raw[7], t->raw[8], t->raw[9], |
| 92 | t->raw[10], t->raw[11]); |
| 93 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 94 | return s; |
| 95 | } |
| 96 | |
| 97 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 98 | static char *l2output_error_strings[] = { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 99 | #define _(sym,string) string, |
| 100 | foreach_l2output_error |
| 101 | #undef _ |
| 102 | }; |
| 103 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 104 | /** |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 105 | * Check for split horizon violations. |
| 106 | * Return 0 if split horizon check passes, otherwise return non-zero. |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 107 | * Packets should not be transmitted out an interface with the same |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 108 | * 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] | 109 | * in which case the check always passes. |
| 110 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 111 | static_always_inline u32 |
| 112 | split_horizon_violation (u8 shg1, u8 shg2) |
| 113 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 114 | if (PREDICT_TRUE (shg1 == 0)) |
| 115 | { |
| 116 | return 0; |
| 117 | } |
| 118 | else |
| 119 | { |
| 120 | return shg1 == shg2; |
| 121 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 122 | } |
| 123 | |
John Lo | beb0b2e | 2017-07-22 00:21:36 -0400 | [diff] [blame] | 124 | /** Determine the next L2 node based on the output feature bitmap */ |
| 125 | static_always_inline void |
| 126 | l2_output_dispatch (vlib_buffer_t * b0, vlib_node_runtime_t * node, |
| 127 | u32 * cached_sw_if_index, u32 * cached_next_index, |
| 128 | u32 sw_if_index, u32 feature_bitmap, u32 * next0) |
| 129 | { |
| 130 | /* |
| 131 | * The output feature bitmap always have at least the L2 output bit set |
| 132 | * for a normal L2 interface (or 0 if the interface is changed from L2 |
| 133 | * to L3 mode). So if the feature bitmap is 0 or just have L2 output bits set, |
| 134 | * we know there is no more feature and will just output packets on interface. |
| 135 | * Otherwise, get the index of the next feature node. |
| 136 | */ |
| 137 | if (PREDICT_FALSE ((feature_bitmap & ~L2OUTPUT_FEAT_OUTPUT) != 0)) |
| 138 | { |
| 139 | /* Save bitmap for the next feature graph nodes */ |
| 140 | vnet_buffer (b0)->l2.feature_bitmap = feature_bitmap; |
| 141 | |
| 142 | /* Determine the next node */ |
| 143 | *next0 = |
| 144 | feat_bitmap_get_next_node_index (l2output_main.l2_out_feat_next, |
| 145 | feature_bitmap); |
| 146 | } |
| 147 | else |
| 148 | { |
| 149 | /* |
| 150 | * There are no features. Send packet to TX node for sw_if_index0 |
| 151 | * This is a little tricky in that the output interface next node indexes |
| 152 | * are not precomputed at init time. |
| 153 | */ |
| 154 | |
| 155 | if (sw_if_index == *cached_sw_if_index) |
| 156 | { |
| 157 | /* We hit in the one-entry cache. Use it. */ |
| 158 | *next0 = *cached_next_index; |
| 159 | } |
| 160 | else |
| 161 | { |
| 162 | /* Look up the output TX node for the sw_if_index */ |
| 163 | *next0 = vec_elt (l2output_main.output_node_index_vec, sw_if_index); |
| 164 | |
| 165 | if (PREDICT_FALSE (*next0 == L2OUTPUT_NEXT_DROP)) |
| 166 | b0->error = node->errors[L2OUTPUT_ERROR_MAPPING_DROP]; |
| 167 | |
| 168 | /* Update the one-entry cache */ |
| 169 | *cached_sw_if_index = sw_if_index; |
| 170 | *cached_next_index = *next0; |
| 171 | } |
| 172 | } |
| 173 | } |
| 174 | |
Damjan Marion | dc5252b | 2016-11-24 19:25:01 -0800 | [diff] [blame] | 175 | static_always_inline void |
| 176 | l2output_vtr (vlib_node_runtime_t * node, l2_output_config_t * config, |
| 177 | u32 feature_bitmap, vlib_buffer_t * b, u32 * next) |
| 178 | { |
| 179 | if (PREDICT_FALSE (config->out_vtr_flag)) |
| 180 | { |
| 181 | /* Perform pre-vtr EFP filter check if configured */ |
| 182 | if (config->output_vtr.push_and_pop_bytes) |
| 183 | { |
| 184 | /* |
| 185 | * Perform output vlan tag rewrite and the pre-vtr EFP filter check. |
| 186 | * The EFP Filter only needs to be run if there is an output VTR |
| 187 | * configured. The flag for the post-vtr EFP Filter node is used |
| 188 | * to trigger the pre-vtr check as well. |
| 189 | */ |
| 190 | u32 failed1 = (feature_bitmap & L2OUTPUT_FEAT_EFP_FILTER) |
| 191 | && (l2_efp_filter_process (b, &(config->input_vtr))); |
| 192 | u32 failed2 = l2_vtr_process (b, &(config->output_vtr)); |
| 193 | |
| 194 | if (PREDICT_FALSE (failed1 | failed2)) |
| 195 | { |
| 196 | *next = L2OUTPUT_NEXT_DROP; |
| 197 | if (failed2) |
| 198 | { |
| 199 | b->error = node->errors[L2OUTPUT_ERROR_VTR_DROP]; |
| 200 | } |
| 201 | if (failed1) |
| 202 | { |
| 203 | b->error = node->errors[L2OUTPUT_ERROR_EFP_DROP]; |
| 204 | } |
| 205 | } |
| 206 | } |
| 207 | // perform the PBB rewrite |
| 208 | else if (config->output_pbb_vtr.push_and_pop_bytes) |
| 209 | { |
| 210 | u32 failed = l2_pbb_process (b, &(config->output_pbb_vtr)); |
| 211 | if (PREDICT_FALSE (failed)) |
| 212 | { |
| 213 | *next = L2OUTPUT_NEXT_DROP; |
| 214 | b->error = node->errors[L2OUTPUT_ERROR_VTR_DROP]; |
| 215 | } |
| 216 | } |
| 217 | } |
| 218 | } |
| 219 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 220 | |
Dave Barach | 681abe4 | 2017-02-15 09:01:01 -0500 | [diff] [blame] | 221 | static_always_inline uword |
| 222 | l2output_node_inline (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 223 | vlib_frame_t * frame, int do_trace) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 224 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 225 | u32 n_left_from, *from, *to_next; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 226 | l2output_next_t next_index; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 227 | l2output_main_t *msm = &l2output_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 228 | u32 cached_sw_if_index; |
| 229 | u32 cached_next_index; |
| 230 | |
| 231 | /* Invalidate cache */ |
| 232 | cached_sw_if_index = ~0; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 233 | cached_next_index = ~0; /* warning be gone */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 234 | |
| 235 | from = vlib_frame_vector_args (frame); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 236 | n_left_from = frame->n_vectors; /* number of packets to process */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 237 | next_index = node->cached_next_index; |
| 238 | |
| 239 | while (n_left_from > 0) |
| 240 | { |
| 241 | u32 n_left_to_next; |
| 242 | |
| 243 | /* get space to enqueue frame to graph node "next_index" */ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 244 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 245 | |
Damjan Marion | dc5252b | 2016-11-24 19:25:01 -0800 | [diff] [blame] | 246 | while (n_left_from >= 8 && n_left_to_next >= 4) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 247 | { |
Damjan Marion | dc5252b | 2016-11-24 19:25:01 -0800 | [diff] [blame] | 248 | u32 bi0, bi1, bi2, bi3; |
| 249 | vlib_buffer_t *b0, *b1, *b2, *b3; |
| 250 | u32 next0, next1, next2, next3; |
| 251 | u32 sw_if_index0, sw_if_index1, sw_if_index2, sw_if_index3; |
| 252 | ethernet_header_t *h0, *h1, *h2, *h3; |
| 253 | l2_output_config_t *config0, *config1, *config2, *config3; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 254 | u32 feature_bitmap0, feature_bitmap1; |
Damjan Marion | dc5252b | 2016-11-24 19:25:01 -0800 | [diff] [blame] | 255 | u32 feature_bitmap2, feature_bitmap3; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 256 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 257 | /* Prefetch next iteration. */ |
| 258 | { |
Damjan Marion | dc5252b | 2016-11-24 19:25:01 -0800 | [diff] [blame] | 259 | vlib_buffer_t *p4, *p5, *p6, *p7; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 260 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 261 | p4 = vlib_get_buffer (vm, from[4]); |
| 262 | p5 = vlib_get_buffer (vm, from[5]); |
Damjan Marion | dc5252b | 2016-11-24 19:25:01 -0800 | [diff] [blame] | 263 | p6 = vlib_get_buffer (vm, from[6]); |
| 264 | p7 = vlib_get_buffer (vm, from[7]); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 265 | |
| 266 | /* Prefetch the buffer header for the N+2 loop iteration */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 267 | vlib_prefetch_buffer_header (p4, LOAD); |
| 268 | vlib_prefetch_buffer_header (p5, LOAD); |
Damjan Marion | dc5252b | 2016-11-24 19:25:01 -0800 | [diff] [blame] | 269 | vlib_prefetch_buffer_header (p6, LOAD); |
| 270 | vlib_prefetch_buffer_header (p7, LOAD); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 271 | } |
| 272 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 273 | /* speculatively enqueue b0 and b1 to the current next frame */ |
| 274 | /* bi is "buffer index", b is pointer to the buffer */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 275 | to_next[0] = bi0 = from[0]; |
| 276 | to_next[1] = bi1 = from[1]; |
Damjan Marion | dc5252b | 2016-11-24 19:25:01 -0800 | [diff] [blame] | 277 | to_next[2] = bi2 = from[2]; |
| 278 | to_next[3] = bi3 = from[3]; |
| 279 | from += 4; |
| 280 | to_next += 4; |
| 281 | n_left_from -= 4; |
| 282 | n_left_to_next -= 4; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 283 | |
| 284 | b0 = vlib_get_buffer (vm, bi0); |
| 285 | b1 = vlib_get_buffer (vm, bi1); |
Damjan Marion | dc5252b | 2016-11-24 19:25:01 -0800 | [diff] [blame] | 286 | b2 = vlib_get_buffer (vm, bi2); |
| 287 | b3 = vlib_get_buffer (vm, bi3); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 288 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 289 | /* TX interface handles */ |
| 290 | sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_TX]; |
| 291 | sw_if_index1 = vnet_buffer (b1)->sw_if_index[VLIB_TX]; |
Damjan Marion | dc5252b | 2016-11-24 19:25:01 -0800 | [diff] [blame] | 292 | sw_if_index2 = vnet_buffer (b2)->sw_if_index[VLIB_TX]; |
| 293 | sw_if_index3 = vnet_buffer (b3)->sw_if_index[VLIB_TX]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 294 | |
Damjan Marion | dc5252b | 2016-11-24 19:25:01 -0800 | [diff] [blame] | 295 | vlib_node_increment_counter (vm, l2output_node.index, |
| 296 | L2OUTPUT_ERROR_L2OUTPUT, 4); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 297 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 298 | /* Get config for the output interface */ |
| 299 | config0 = vec_elt_at_index (msm->configs, sw_if_index0); |
| 300 | config1 = vec_elt_at_index (msm->configs, sw_if_index1); |
Damjan Marion | dc5252b | 2016-11-24 19:25:01 -0800 | [diff] [blame] | 301 | config2 = vec_elt_at_index (msm->configs, sw_if_index2); |
| 302 | config3 = vec_elt_at_index (msm->configs, sw_if_index3); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 303 | |
| 304 | /* |
| 305 | * Get features from the config |
| 306 | * TODO: mask out any non-applicable features |
| 307 | */ |
| 308 | feature_bitmap0 = config0->feature_bitmap; |
| 309 | feature_bitmap1 = config1->feature_bitmap; |
Damjan Marion | dc5252b | 2016-11-24 19:25:01 -0800 | [diff] [blame] | 310 | feature_bitmap2 = config2->feature_bitmap; |
| 311 | feature_bitmap3 = config3->feature_bitmap; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 312 | |
| 313 | /* Determine next node */ |
John Lo | beb0b2e | 2017-07-22 00:21:36 -0400 | [diff] [blame] | 314 | l2_output_dispatch (b0, node, &cached_sw_if_index, |
| 315 | &cached_next_index, sw_if_index0, |
| 316 | feature_bitmap0, &next0); |
| 317 | l2_output_dispatch (b1, node, &cached_sw_if_index, |
| 318 | &cached_next_index, sw_if_index1, |
| 319 | feature_bitmap1, &next1); |
| 320 | l2_output_dispatch (b2, node, &cached_sw_if_index, |
| 321 | &cached_next_index, sw_if_index2, |
| 322 | feature_bitmap2, &next2); |
| 323 | l2_output_dispatch (b3, node, &cached_sw_if_index, |
| 324 | &cached_next_index, sw_if_index3, |
| 325 | feature_bitmap3, &next3); |
Pavel Kotucek | 95300d1 | 2016-08-26 16:11:36 +0200 | [diff] [blame] | 326 | |
Damjan Marion | dc5252b | 2016-11-24 19:25:01 -0800 | [diff] [blame] | 327 | l2output_vtr (node, config0, feature_bitmap0, b0, &next0); |
| 328 | l2output_vtr (node, config1, feature_bitmap1, b1, &next1); |
| 329 | l2output_vtr (node, config2, feature_bitmap2, b2, &next2); |
| 330 | l2output_vtr (node, config3, feature_bitmap3, b3, &next3); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 331 | |
Pavel Kotucek | 65e8457 | 2017-01-16 17:01:56 +0100 | [diff] [blame] | 332 | if (do_trace) |
| 333 | { |
| 334 | h0 = vlib_buffer_get_current (b0); |
| 335 | h1 = vlib_buffer_get_current (b1); |
| 336 | h2 = vlib_buffer_get_current (b2); |
| 337 | h3 = vlib_buffer_get_current (b3); |
| 338 | if (b0->flags & VLIB_BUFFER_IS_TRACED) |
| 339 | { |
| 340 | l2output_trace_t *t = |
| 341 | vlib_add_trace (vm, node, b0, sizeof (*t)); |
| 342 | t->sw_if_index = sw_if_index0; |
| 343 | clib_memcpy (t->src, h0->src_address, 6); |
| 344 | clib_memcpy (t->dst, h0->dst_address, 6); |
| 345 | clib_memcpy (t->raw, &h0->type, sizeof (t->raw)); |
| 346 | } |
| 347 | if (b1->flags & VLIB_BUFFER_IS_TRACED) |
| 348 | { |
| 349 | l2output_trace_t *t = |
| 350 | vlib_add_trace (vm, node, b1, sizeof (*t)); |
| 351 | t->sw_if_index = sw_if_index1; |
| 352 | clib_memcpy (t->src, h1->src_address, 6); |
| 353 | clib_memcpy (t->dst, h1->dst_address, 6); |
| 354 | clib_memcpy (t->raw, &h1->type, sizeof (t->raw)); |
| 355 | } |
| 356 | if (b2->flags & VLIB_BUFFER_IS_TRACED) |
| 357 | { |
| 358 | l2output_trace_t *t = |
| 359 | vlib_add_trace (vm, node, b2, sizeof (*t)); |
| 360 | t->sw_if_index = sw_if_index2; |
| 361 | clib_memcpy (t->src, h2->src_address, 6); |
| 362 | clib_memcpy (t->dst, h2->dst_address, 6); |
| 363 | clib_memcpy (t->raw, &h2->type, sizeof (t->raw)); |
| 364 | } |
| 365 | if (b3->flags & VLIB_BUFFER_IS_TRACED) |
| 366 | { |
| 367 | l2output_trace_t *t = |
| 368 | vlib_add_trace (vm, node, b3, sizeof (*t)); |
| 369 | t->sw_if_index = sw_if_index3; |
| 370 | clib_memcpy (t->src, h3->src_address, 6); |
| 371 | clib_memcpy (t->dst, h3->dst_address, 6); |
| 372 | clib_memcpy (t->raw, &h3->type, sizeof (t->raw)); |
| 373 | } |
| 374 | } |
| 375 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 376 | /* |
| 377 | * Perform the split horizon check |
| 378 | * The check can only fail for non-zero shg's |
| 379 | */ |
Damjan Marion | dc5252b | 2016-11-24 19:25:01 -0800 | [diff] [blame] | 380 | if (PREDICT_FALSE (config0->shg + config1->shg + |
| 381 | config2->shg + config3->shg)) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 382 | { |
| 383 | /* one of the checks might fail, check both */ |
| 384 | if (split_horizon_violation |
| 385 | (config0->shg, vnet_buffer (b0)->l2.shg)) |
| 386 | { |
| 387 | next0 = L2OUTPUT_NEXT_DROP; |
| 388 | b0->error = node->errors[L2OUTPUT_ERROR_SHG_DROP]; |
| 389 | } |
| 390 | if (split_horizon_violation |
| 391 | (config1->shg, vnet_buffer (b1)->l2.shg)) |
| 392 | { |
| 393 | next1 = L2OUTPUT_NEXT_DROP; |
| 394 | b1->error = node->errors[L2OUTPUT_ERROR_SHG_DROP]; |
| 395 | } |
Damjan Marion | dc5252b | 2016-11-24 19:25:01 -0800 | [diff] [blame] | 396 | if (split_horizon_violation |
| 397 | (config2->shg, vnet_buffer (b2)->l2.shg)) |
| 398 | { |
| 399 | next2 = L2OUTPUT_NEXT_DROP; |
| 400 | b2->error = node->errors[L2OUTPUT_ERROR_SHG_DROP]; |
| 401 | } |
| 402 | if (split_horizon_violation |
| 403 | (config3->shg, vnet_buffer (b3)->l2.shg)) |
| 404 | { |
| 405 | next3 = L2OUTPUT_NEXT_DROP; |
| 406 | b3->error = node->errors[L2OUTPUT_ERROR_SHG_DROP]; |
| 407 | } |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | /* verify speculative enqueues, maybe switch current next frame */ |
| 411 | /* if next0==next1==next_index then nothing special needs to be done */ |
Damjan Marion | dc5252b | 2016-11-24 19:25:01 -0800 | [diff] [blame] | 412 | vlib_validate_buffer_enqueue_x4 (vm, node, next_index, |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 413 | to_next, n_left_to_next, |
Damjan Marion | dc5252b | 2016-11-24 19:25:01 -0800 | [diff] [blame] | 414 | bi0, bi1, bi2, bi3, |
| 415 | next0, next1, next2, next3); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 416 | } |
| 417 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 418 | while (n_left_from > 0 && n_left_to_next > 0) |
| 419 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 420 | u32 bi0; |
| 421 | vlib_buffer_t *b0; |
| 422 | u32 next0; |
| 423 | u32 sw_if_index0; |
| 424 | ethernet_header_t *h0; |
| 425 | l2_output_config_t *config0; |
| 426 | u32 feature_bitmap0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 427 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 428 | /* speculatively enqueue b0 to the current next frame */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 429 | bi0 = from[0]; |
| 430 | to_next[0] = bi0; |
| 431 | from += 1; |
| 432 | to_next += 1; |
| 433 | n_left_from -= 1; |
| 434 | n_left_to_next -= 1; |
| 435 | |
| 436 | b0 = vlib_get_buffer (vm, bi0); |
| 437 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 438 | sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_TX]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 439 | |
Damjan Marion | dc5252b | 2016-11-24 19:25:01 -0800 | [diff] [blame] | 440 | vlib_node_increment_counter (vm, l2output_node.index, |
| 441 | L2OUTPUT_ERROR_L2OUTPUT, 1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 442 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 443 | /* Get config for the output interface */ |
| 444 | config0 = vec_elt_at_index (msm->configs, sw_if_index0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 445 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 446 | /* |
| 447 | * Get features from the config |
| 448 | * TODO: mask out any non-applicable features |
| 449 | */ |
| 450 | feature_bitmap0 = config0->feature_bitmap; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 451 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 452 | /* Determine next node */ |
John Lo | beb0b2e | 2017-07-22 00:21:36 -0400 | [diff] [blame] | 453 | l2_output_dispatch (b0, node, &cached_sw_if_index, |
| 454 | &cached_next_index, sw_if_index0, |
| 455 | feature_bitmap0, &next0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 456 | |
Damjan Marion | dc5252b | 2016-11-24 19:25:01 -0800 | [diff] [blame] | 457 | l2output_vtr (node, config0, feature_bitmap0, b0, &next0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 458 | |
Pavel Kotucek | 65e8457 | 2017-01-16 17:01:56 +0100 | [diff] [blame] | 459 | if (do_trace && PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) |
| 460 | { |
| 461 | l2output_trace_t *t = |
| 462 | vlib_add_trace (vm, node, b0, sizeof (*t)); |
| 463 | t->sw_if_index = sw_if_index0; |
| 464 | h0 = vlib_buffer_get_current (b0); |
| 465 | clib_memcpy (t->src, h0->src_address, 6); |
| 466 | clib_memcpy (t->dst, h0->dst_address, 6); |
| 467 | clib_memcpy (t->raw, &h0->type, sizeof (t->raw)); |
| 468 | } |
| 469 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 470 | /* Perform the split horizon check */ |
| 471 | if (PREDICT_FALSE |
| 472 | (split_horizon_violation |
| 473 | (config0->shg, vnet_buffer (b0)->l2.shg))) |
| 474 | { |
| 475 | next0 = L2OUTPUT_NEXT_DROP; |
| 476 | b0->error = node->errors[L2OUTPUT_ERROR_SHG_DROP]; |
| 477 | } |
| 478 | |
| 479 | /* verify speculative enqueue, maybe switch current next frame */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 480 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, |
| 481 | to_next, n_left_to_next, |
| 482 | bi0, next0); |
| 483 | } |
| 484 | |
| 485 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 486 | } |
| 487 | |
| 488 | return frame->n_vectors; |
| 489 | } |
| 490 | |
Dave Barach | 681abe4 | 2017-02-15 09:01:01 -0500 | [diff] [blame] | 491 | static uword |
| 492 | l2output_node_fn (vlib_main_t * vm, |
| 493 | vlib_node_runtime_t * node, vlib_frame_t * frame) |
| 494 | { |
| 495 | if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE))) |
| 496 | return l2output_node_inline (vm, node, frame, 1 /* do_trace */ ); |
| 497 | return l2output_node_inline (vm, node, frame, 0 /* do_trace */ ); |
| 498 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 499 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 500 | /* *INDENT-OFF* */ |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 501 | VLIB_REGISTER_NODE (l2output_node) = { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 502 | .function = l2output_node_fn, |
| 503 | .name = "l2-output", |
| 504 | .vector_size = sizeof (u32), |
| 505 | .format_trace = format_l2output_trace, |
| 506 | .type = VLIB_NODE_TYPE_INTERNAL, |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 507 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 508 | .n_errors = ARRAY_LEN(l2output_error_strings), |
| 509 | .error_strings = l2output_error_strings, |
| 510 | |
| 511 | .n_next_nodes = L2OUTPUT_N_NEXT, |
| 512 | |
| 513 | /* edit / add dispositions here */ |
| 514 | .next_nodes = { |
| 515 | [L2OUTPUT_NEXT_DROP] = "error-drop", |
John Lo | 0fc9bc1 | 2016-10-27 11:17:02 -0400 | [diff] [blame] | 516 | [L2OUTPUT_NEXT_BAD_INTF] = "l2-output-bad-intf", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 517 | }, |
| 518 | }; |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 519 | |
| 520 | VLIB_NODE_FUNCTION_MULTIARCH (l2output_node, l2output_node_fn); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 521 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 522 | |
John Lo | 3ef822e | 2016-06-07 09:14:07 -0400 | [diff] [blame] | 523 | |
John Lo | 0fc9bc1 | 2016-10-27 11:17:02 -0400 | [diff] [blame] | 524 | #define foreach_l2output_bad_intf_error \ |
| 525 | _(DROP, "L2 output to interface not in L2 mode or deleted") |
John Lo | 3ef822e | 2016-06-07 09:14:07 -0400 | [diff] [blame] | 526 | |
John Lo | 0fc9bc1 | 2016-10-27 11:17:02 -0400 | [diff] [blame] | 527 | static char *l2output_bad_intf_error_strings[] = { |
John Lo | 3ef822e | 2016-06-07 09:14:07 -0400 | [diff] [blame] | 528 | #define _(sym,string) string, |
John Lo | 0fc9bc1 | 2016-10-27 11:17:02 -0400 | [diff] [blame] | 529 | foreach_l2output_bad_intf_error |
John Lo | 3ef822e | 2016-06-07 09:14:07 -0400 | [diff] [blame] | 530 | #undef _ |
| 531 | }; |
| 532 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 533 | typedef enum |
| 534 | { |
John Lo | 0fc9bc1 | 2016-10-27 11:17:02 -0400 | [diff] [blame] | 535 | #define _(sym,str) L2OUTPUT_BAD_INTF_ERROR_##sym, |
| 536 | foreach_l2output_bad_intf_error |
John Lo | 3ef822e | 2016-06-07 09:14:07 -0400 | [diff] [blame] | 537 | #undef _ |
John Lo | 0fc9bc1 | 2016-10-27 11:17:02 -0400 | [diff] [blame] | 538 | L2OUTPUT_BAD_INTF_N_ERROR, |
| 539 | } l2output_bad_intf_error_t; |
John Lo | 3ef822e | 2016-06-07 09:14:07 -0400 | [diff] [blame] | 540 | |
| 541 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 542 | /** |
John Lo | 0fc9bc1 | 2016-10-27 11:17:02 -0400 | [diff] [blame] | 543 | * Output node for interfaces/tunnels which was in L2 mode but were changed |
| 544 | * to L3 mode or possibly deleted thereafter. On changing forwarding mode |
| 545 | * of any tunnel/interface from L2 to L3, its entry in l2_output_main table |
| 546 | * next_nodes.output_node_index_vec[sw_if_index] MUST be set to the value of |
| 547 | * L2OUTPUT_NEXT_BAD_INTF. Thus, if there are stale entries in the L2FIB for |
| 548 | * this sw_if_index, l2-output will send packets for this sw_if_index to the |
| 549 | * l2-output-bad-intf node which just setup the proper drop reason before |
| 550 | * sending packets to the error-drop node to drop the packet. Then, stale L2FIB |
| 551 | * entries for delted tunnels won't cause possible packet or memory corrpution. |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 552 | */ |
John Lo | 0fc9bc1 | 2016-10-27 11:17:02 -0400 | [diff] [blame] | 553 | static vlib_node_registration_t l2output_bad_intf_node; |
John Lo | 3ef822e | 2016-06-07 09:14:07 -0400 | [diff] [blame] | 554 | |
| 555 | static uword |
John Lo | 0fc9bc1 | 2016-10-27 11:17:02 -0400 | [diff] [blame] | 556 | l2output_bad_intf_node_fn (vlib_main_t * vm, |
| 557 | vlib_node_runtime_t * node, vlib_frame_t * frame) |
John Lo | 3ef822e | 2016-06-07 09:14:07 -0400 | [diff] [blame] | 558 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 559 | u32 n_left_from, *from, *to_next; |
John Lo | 3ef822e | 2016-06-07 09:14:07 -0400 | [diff] [blame] | 560 | l2output_next_t next_index = 0; |
| 561 | |
| 562 | from = vlib_frame_vector_args (frame); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 563 | n_left_from = frame->n_vectors; /* number of packets to process */ |
John Lo | 3ef822e | 2016-06-07 09:14:07 -0400 | [diff] [blame] | 564 | |
| 565 | while (n_left_from > 0) |
| 566 | { |
| 567 | u32 n_left_to_next; |
| 568 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 569 | /* get space to enqueue frame to graph node "next_index" */ |
| 570 | 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] | 571 | |
| 572 | while (n_left_from >= 4 && n_left_to_next >= 2) |
| 573 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 574 | u32 bi0, bi1; |
| 575 | vlib_buffer_t *b0, *b1; |
John Lo | 3ef822e | 2016-06-07 09:14:07 -0400 | [diff] [blame] | 576 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 577 | to_next[0] = bi0 = from[0]; |
John Lo | 3ef822e | 2016-06-07 09:14:07 -0400 | [diff] [blame] | 578 | to_next[1] = bi1 = from[1]; |
| 579 | from += 2; |
| 580 | to_next += 2; |
| 581 | n_left_from -= 2; |
| 582 | n_left_to_next -= 2; |
| 583 | b0 = vlib_get_buffer (vm, bi0); |
| 584 | b1 = vlib_get_buffer (vm, bi1); |
John Lo | 0fc9bc1 | 2016-10-27 11:17:02 -0400 | [diff] [blame] | 585 | b0->error = node->errors[L2OUTPUT_BAD_INTF_ERROR_DROP]; |
| 586 | b1->error = node->errors[L2OUTPUT_BAD_INTF_ERROR_DROP]; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 587 | } |
| 588 | |
John Lo | 3ef822e | 2016-06-07 09:14:07 -0400 | [diff] [blame] | 589 | while (n_left_from > 0 && n_left_to_next > 0) |
| 590 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 591 | u32 bi0; |
| 592 | vlib_buffer_t *b0; |
John Lo | 3ef822e | 2016-06-07 09:14:07 -0400 | [diff] [blame] | 593 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 594 | bi0 = from[0]; |
John Lo | 3ef822e | 2016-06-07 09:14:07 -0400 | [diff] [blame] | 595 | to_next[0] = bi0; |
| 596 | from += 1; |
| 597 | to_next += 1; |
| 598 | n_left_from -= 1; |
| 599 | n_left_to_next -= 1; |
| 600 | b0 = vlib_get_buffer (vm, bi0); |
John Lo | 0fc9bc1 | 2016-10-27 11:17:02 -0400 | [diff] [blame] | 601 | b0->error = node->errors[L2OUTPUT_BAD_INTF_ERROR_DROP]; |
John Lo | 3ef822e | 2016-06-07 09:14:07 -0400 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 605 | } |
| 606 | |
| 607 | return frame->n_vectors; |
| 608 | } |
| 609 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 610 | /* *INDENT-OFF* */ |
John Lo | 0fc9bc1 | 2016-10-27 11:17:02 -0400 | [diff] [blame] | 611 | VLIB_REGISTER_NODE (l2output_bad_intf_node,static) = { |
| 612 | .function = l2output_bad_intf_node_fn, |
| 613 | .name = "l2-output-bad-intf", |
John Lo | 3ef822e | 2016-06-07 09:14:07 -0400 | [diff] [blame] | 614 | .vector_size = sizeof (u32), |
| 615 | .type = VLIB_NODE_TYPE_INTERNAL, |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 616 | |
John Lo | 0fc9bc1 | 2016-10-27 11:17:02 -0400 | [diff] [blame] | 617 | .n_errors = ARRAY_LEN(l2output_bad_intf_error_strings), |
| 618 | .error_strings = l2output_bad_intf_error_strings, |
John Lo | 3ef822e | 2016-06-07 09:14:07 -0400 | [diff] [blame] | 619 | |
| 620 | .n_next_nodes = 1, |
| 621 | |
| 622 | /* edit / add dispositions here */ |
| 623 | .next_nodes = { |
| 624 | [0] = "error-drop", |
| 625 | }, |
| 626 | }; |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 627 | |
| 628 | 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] | 629 | /* *INDENT-ON* */ |
John Lo | 3ef822e | 2016-06-07 09:14:07 -0400 | [diff] [blame] | 630 | |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 631 | static clib_error_t * |
| 632 | l2output_init (vlib_main_t * vm) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 633 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 634 | l2output_main_t *mp = &l2output_main; |
| 635 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 636 | mp->vlib_main = vm; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 637 | mp->vnet_main = vnet_get_main (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 638 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 639 | /* Create the config vector */ |
| 640 | vec_validate (mp->configs, 100); |
| 641 | /* 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] | 642 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 643 | /* Initialize the feature next-node indexes */ |
| 644 | feat_bitmap_init_next_nodes (vm, |
| 645 | l2output_node.index, |
| 646 | L2OUTPUT_N_FEAT, |
| 647 | l2output_get_feat_names (), |
John Lo | beb0b2e | 2017-07-22 00:21:36 -0400 | [diff] [blame] | 648 | mp->l2_out_feat_next); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 649 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 650 | /* Initialize the output node mapping table */ |
John Lo | beb0b2e | 2017-07-22 00:21:36 -0400 | [diff] [blame] | 651 | vec_validate_init_empty (mp->output_node_index_vec, 100, |
John Lo | b2fd6cb | 2017-07-12 19:56:45 -0400 | [diff] [blame] | 652 | L2OUTPUT_NEXT_DROP); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 653 | |
| 654 | return 0; |
| 655 | } |
| 656 | |
| 657 | VLIB_INIT_FUNCTION (l2output_init); |
| 658 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 659 | |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 660 | /** 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] | 661 | void |
| 662 | l2output_create_output_node_mapping (vlib_main_t * vlib_main, |
| 663 | vnet_main_t * vnet_main, u32 sw_if_index) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 664 | { |
John Lo | b2fd6cb | 2017-07-12 19:56:45 -0400 | [diff] [blame] | 665 | vnet_hw_interface_t *hw0 = |
| 666 | vnet_get_sup_hw_interface (vnet_main, sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 667 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 668 | /* dynamically create graph node arc */ |
John Lo | b2fd6cb | 2017-07-12 19:56:45 -0400 | [diff] [blame] | 669 | u32 next = vlib_node_add_next (vlib_main, l2output_node.index, |
| 670 | hw0->output_node_index); |
John Lo | beb0b2e | 2017-07-22 00:21:36 -0400 | [diff] [blame] | 671 | l2output_main.output_node_index_vec[sw_if_index] = next; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 672 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 673 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 674 | /* Get a pointer to the config for the given interface */ |
| 675 | l2_output_config_t * |
| 676 | l2output_intf_config (u32 sw_if_index) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 677 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 678 | l2output_main_t *mp = &l2output_main; |
| 679 | |
| 680 | vec_validate (mp->configs, sw_if_index); |
| 681 | return vec_elt_at_index (mp->configs, sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 682 | } |
| 683 | |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 684 | /** Enable (or disable) the feature in the bitmap for the given interface. */ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 685 | void |
| 686 | 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] | 687 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 688 | l2output_main_t *mp = &l2output_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 689 | l2_output_config_t *config; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 690 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 691 | vec_validate (mp->configs, sw_if_index); |
| 692 | config = vec_elt_at_index (mp->configs, sw_if_index); |
| 693 | |
| 694 | if (enable) |
| 695 | { |
| 696 | config->feature_bitmap |= feature_bitmap; |
| 697 | } |
| 698 | else |
| 699 | { |
| 700 | config->feature_bitmap &= ~feature_bitmap; |
| 701 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 702 | } |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 703 | |
| 704 | /* |
| 705 | * fd.io coding-style-patch-verification: ON |
| 706 | * |
| 707 | * Local Variables: |
| 708 | * eval: (c-set-style "gnu") |
| 709 | * End: |
| 710 | */ |