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