blob: ed9e5ac22581c22674367bdc3bf1f9a5b98372fe [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
Dave Barach97d8dc22016-08-15 15:31:15 -04002 * l2_flood.c : layer 2 flooding
Ed Warnickecb9cada2015-12-08 15:45:58 -07003 *
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#include <vnet/l2/l2_input.h>
24#include <vnet/l2/feat_bitmap.h>
25#include <vnet/l2/l2_bvi.h>
26#include <vnet/replication.h>
27#include <vnet/l2/l2_fib.h>
28
29#include <vppinfra/error.h>
30#include <vppinfra/hash.h>
31
32
Billy McFall22aa3e92016-09-09 08:46:40 -040033/**
34 * @file
35 * @brief Ethernet Flooding.
36 *
Ed Warnickecb9cada2015-12-08 15:45:58 -070037 * Flooding uses the packet replication infrastructure to send a copy of the
38 * packet to each member interface. Logically the replication infrastructure
39 * expects two graph nodes: a prep node that initiates replication and sends the
40 * packet to the first destination, and a recycle node that is passed the packet
41 * after it has been transmitted.
42 *
43 * To decrease the amount of code, l2 flooding implements both functions in
44 * the same graph node. This node can tell if is it being called as the "prep"
45 * or "recycle" using replication_is_recycled().
46 */
47
48
Dave Barach97d8dc22016-08-15 15:31:15 -040049typedef struct
50{
Ed Warnickecb9cada2015-12-08 15:45:58 -070051
Dave Barach97d8dc22016-08-15 15:31:15 -040052 /* Next nodes for each feature */
Ed Warnickecb9cada2015-12-08 15:45:58 -070053 u32 feat_next_node_index[32];
Dave Barach97d8dc22016-08-15 15:31:15 -040054
55 /* next node index for the L3 input node of each ethertype */
Ed Warnickecb9cada2015-12-08 15:45:58 -070056 next_by_ethertype_t l3_next;
57
58 /* convenience variables */
Dave Barach97d8dc22016-08-15 15:31:15 -040059 vlib_main_t *vlib_main;
60 vnet_main_t *vnet_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070061} l2flood_main_t;
62
Dave Barach97d8dc22016-08-15 15:31:15 -040063typedef struct
64{
Ed Warnickecb9cada2015-12-08 15:45:58 -070065 u8 src[6];
66 u8 dst[6];
67 u32 sw_if_index;
68 u16 bd_index;
69} l2flood_trace_t;
70
71
72/* packet trace format function */
Dave Barach97d8dc22016-08-15 15:31:15 -040073static u8 *
74format_l2flood_trace (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -070075{
76 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
77 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
Dave Barach97d8dc22016-08-15 15:31:15 -040078 l2flood_trace_t *t = va_arg (*args, l2flood_trace_t *);
79
Ed Warnickecb9cada2015-12-08 15:45:58 -070080 s = format (s, "l2-flood: sw_if_index %d dst %U src %U bd_index %d",
Dave Barach97d8dc22016-08-15 15:31:15 -040081 t->sw_if_index,
82 format_ethernet_address, t->dst,
83 format_ethernet_address, t->src, t->bd_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -070084 return s;
85}
86
87l2flood_main_t l2flood_main;
88
89static vlib_node_registration_t l2flood_node;
90
91#define foreach_l2flood_error \
92_(L2FLOOD, "L2 flood packets") \
93_(REPL_FAIL, "L2 replication failures") \
94_(NO_MEMBERS, "L2 replication complete") \
John Lo7185c3b2016-06-04 00:02:37 -040095_(BVI_BAD_MAC, "BVI L3 mac mismatch") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070096_(BVI_ETHERTYPE, "BVI packet with unhandled ethertype")
97
Dave Barach97d8dc22016-08-15 15:31:15 -040098typedef enum
99{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700100#define _(sym,str) L2FLOOD_ERROR_##sym,
101 foreach_l2flood_error
102#undef _
Dave Barach97d8dc22016-08-15 15:31:15 -0400103 L2FLOOD_N_ERROR,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700104} l2flood_error_t;
105
Dave Barach97d8dc22016-08-15 15:31:15 -0400106static char *l2flood_error_strings[] = {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700107#define _(sym,string) string,
108 foreach_l2flood_error
109#undef _
110};
111
Dave Barach97d8dc22016-08-15 15:31:15 -0400112typedef enum
113{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700114 L2FLOOD_NEXT_L2_OUTPUT,
115 L2FLOOD_NEXT_DROP,
116 L2FLOOD_N_NEXT,
117} l2flood_next_t;
118
119/*
120 * Perform flooding on one packet
121 *
122 * Due to the way BVI processing can modify the packet, the BVI interface
123 * (if present) must be processed last in the replication. The member vector
Dave Barach97d8dc22016-08-15 15:31:15 -0400124 * is arranged so that the BVI interface is always the first element.
Ed Warnickecb9cada2015-12-08 15:45:58 -0700125 * Flooding walks the vector in reverse.
126 *
127 * BVI processing causes the packet to go to L3 processing. This strips the
128 * L2 header, which is fine because the replication infrastructure restores
129 * it. However L3 processing can trigger larger changes to the packet. For
130 * example, an ARP request could be turned into an ARP reply, an ICMP request
Dave Barach97d8dc22016-08-15 15:31:15 -0400131 * could be turned into an ICMP reply. If BVI processing is not performed
132 * last, the modified packet would be replicated to the remaining members.
Ed Warnickecb9cada2015-12-08 15:45:58 -0700133 */
134
135static_always_inline void
136l2flood_process (vlib_main_t * vm,
Dave Barach97d8dc22016-08-15 15:31:15 -0400137 vlib_node_runtime_t * node,
138 l2flood_main_t * msm,
139 u64 * counter_base,
140 vlib_buffer_t * b0,
141 u32 * sw_if_index0,
142 l2fib_entry_key_t * key0,
143 u32 * bucket0, l2fib_entry_result_t * result0, u32 * next0)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700144{
145 u16 bd_index0;
146 l2_bridge_domain_t *bd_config;
Dave Barach97d8dc22016-08-15 15:31:15 -0400147 l2_flood_member_t *members;
148 i32 current_member; /* signed */
149 replication_context_t *ctx;
150 u8 in_shg = vnet_buffer (b0)->l2.shg;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700151
Dave Barach97d8dc22016-08-15 15:31:15 -0400152 if (!replication_is_recycled (b0))
153 {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700154
Dave Barach97d8dc22016-08-15 15:31:15 -0400155 /* Do flood "prep node" processing */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700156
Dave Barach97d8dc22016-08-15 15:31:15 -0400157 /* Get config for the bridge domain interface */
158 bd_index0 = vnet_buffer (b0)->l2.bd_index;
159 bd_config = vec_elt_at_index (l2input_main.bd_configs, bd_index0);
160 members = bd_config->members;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700161
Dave Barach97d8dc22016-08-15 15:31:15 -0400162 /* Find first member that passes the reflection and SHG checks */
Eyal Baric5b13602016-11-24 19:42:43 +0200163 current_member = bd_config->flood_count - 1;
Dave Barach97d8dc22016-08-15 15:31:15 -0400164 while ((current_member >= 0) &&
165 ((members[current_member].sw_if_index == *sw_if_index0) ||
166 (in_shg && members[current_member].shg == in_shg)))
167 {
168 current_member--;
169 }
170
171 if (current_member < 0)
172 {
173 /* No members to flood to */
174 *next0 = L2FLOOD_NEXT_DROP;
175 b0->error = node->errors[L2FLOOD_ERROR_NO_MEMBERS];
176 return;
177 }
178
179 if ((current_member > 0) &&
180 ((current_member > 1) ||
181 ((members[0].sw_if_index != *sw_if_index0) &&
182 (!in_shg || members[0].shg != in_shg))))
183 {
184 /* If more than one member then initiate replication */
185 ctx =
186 replication_prep (vm, b0, l2flood_node.index, 1 /* l2_packet */ );
187 ctx->feature_replicas = (uword) members;
188 ctx->feature_counter = current_member;
189 }
190
Ed Warnickecb9cada2015-12-08 15:45:58 -0700191 }
Dave Barach97d8dc22016-08-15 15:31:15 -0400192 else
193 {
194 vnet_buffer_opaque_t *vnet_buff_op;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700195
Dave Barach97d8dc22016-08-15 15:31:15 -0400196 /* Do flood "recycle node" processing */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700197
Dave Barach97d8dc22016-08-15 15:31:15 -0400198 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_REPL_FAIL))
199 {
200 (void) replication_recycle (vm, b0, 1 /* is_last */ );
201 *next0 = L2FLOOD_NEXT_DROP;
202 b0->error = node->errors[L2FLOOD_ERROR_REPL_FAIL];
203 return;
204 }
205
206 ctx = replication_get_ctx (b0);
207 replication_clear_recycled (b0);
208
209 members = (l2_flood_member_t *) (intptr_t) ctx->feature_replicas;
210 current_member = (i32) ctx->feature_counter - 1;
211
212 /* Need to update input index from saved packet context */
213 vnet_buff_op = (vnet_buffer_opaque_t *) ctx->vnet_buffer;
214 *sw_if_index0 = vnet_buff_op->sw_if_index[VLIB_RX];
215
216 /* Find next member that passes the reflection and SHG check */
217 while ((current_member >= 0) &&
218 ((members[current_member].sw_if_index == *sw_if_index0) ||
219 (in_shg && members[current_member].shg == in_shg)))
220 {
221 current_member--;
222 }
223
224 if (current_member < 0)
225 {
226 /*
227 * No more members to flood to.
228 * Terminate replication and drop packet.
229 */
230
231 replication_recycle (vm, b0, 1 /* is_last */ );
232
233 *next0 = L2FLOOD_NEXT_DROP;
234 /* Ideally we woudn't bump a counter here, just silently complete */
235 b0->error = node->errors[L2FLOOD_ERROR_NO_MEMBERS];
236 return;
237 }
238
239 /* Restore packet and context and continue replication */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700240 ctx->feature_counter = current_member;
Dave Barach97d8dc22016-08-15 15:31:15 -0400241 replication_recycle (vm, b0, ((current_member == 0) || /*is_last */
242 ((current_member == 1) &&
243 ((members[0].sw_if_index ==
244 *sw_if_index0) || (in_shg
245 && members[0].shg ==
246 in_shg)))));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700247 }
248
Dave Barach97d8dc22016-08-15 15:31:15 -0400249 /* Forward packet to the current member */
Eyal Baric5b13602016-11-24 19:42:43 +0200250 if (PREDICT_FALSE (members[current_member].flags & L2_FLOOD_MEMBER_BVI))
Dave Barach97d8dc22016-08-15 15:31:15 -0400251 {
252 /* Do BVI processing */
253 u32 rc;
254 rc = l2_to_bvi (vm,
255 msm->vnet_main,
256 b0,
257 members[current_member].sw_if_index,
258 &msm->l3_next, next0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700259
Dave Barach97d8dc22016-08-15 15:31:15 -0400260 if (PREDICT_FALSE (rc))
261 {
262 if (rc == TO_BVI_ERR_BAD_MAC)
263 {
264 b0->error = node->errors[L2FLOOD_ERROR_BVI_BAD_MAC];
265 *next0 = L2FLOOD_NEXT_DROP;
266 }
267 else if (rc == TO_BVI_ERR_ETHERTYPE)
268 {
269 b0->error = node->errors[L2FLOOD_ERROR_BVI_ETHERTYPE];
270 *next0 = L2FLOOD_NEXT_DROP;
271 }
272 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700273 }
Eyal Baric5b13602016-11-24 19:42:43 +0200274 else
275 {
276 /* Do normal L2 forwarding */
277 vnet_buffer (b0)->sw_if_index[VLIB_TX] =
278 members[current_member].sw_if_index;
279 *next0 = L2FLOOD_NEXT_L2_OUTPUT;
280
281 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700282
Ed Warnickecb9cada2015-12-08 15:45:58 -0700283}
284
285
286static uword
287l2flood_node_fn (vlib_main_t * vm,
Dave Barach97d8dc22016-08-15 15:31:15 -0400288 vlib_node_runtime_t * node, vlib_frame_t * frame)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700289{
Dave Barach97d8dc22016-08-15 15:31:15 -0400290 u32 n_left_from, *from, *to_next;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700291 l2flood_next_t next_index;
Dave Barach97d8dc22016-08-15 15:31:15 -0400292 l2flood_main_t *msm = &l2flood_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700293 vlib_node_t *n = vlib_get_node (vm, l2flood_node.index);
294 u32 node_counter_base_index = n->error_heap_index;
Dave Barach97d8dc22016-08-15 15:31:15 -0400295 vlib_error_main_t *em = &vm->error_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700296
297 from = vlib_frame_vector_args (frame);
Dave Barach97d8dc22016-08-15 15:31:15 -0400298 n_left_from = frame->n_vectors; /* number of packets to process */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700299 next_index = node->cached_next_index;
Dave Barach97d8dc22016-08-15 15:31:15 -0400300
Ed Warnickecb9cada2015-12-08 15:45:58 -0700301 while (n_left_from > 0)
302 {
303 u32 n_left_to_next;
304
305 /* get space to enqueue frame to graph node "next_index" */
Dave Barach97d8dc22016-08-15 15:31:15 -0400306 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700307
308 while (n_left_from >= 6 && n_left_to_next >= 2)
309 {
Dave Barach97d8dc22016-08-15 15:31:15 -0400310 u32 bi0, bi1;
311 vlib_buffer_t *b0, *b1;
312 u32 next0, next1;
313 u32 sw_if_index0, sw_if_index1;
314 l2fib_entry_key_t key0, key1;
315 l2fib_entry_result_t result0, result1;
316 u32 bucket0, bucket1;
317
Ed Warnickecb9cada2015-12-08 15:45:58 -0700318 /* Prefetch next iteration. */
319 {
Dave Barach97d8dc22016-08-15 15:31:15 -0400320 vlib_buffer_t *p2, *p3, *p4, *p5;
321
Ed Warnickecb9cada2015-12-08 15:45:58 -0700322 p2 = vlib_get_buffer (vm, from[2]);
323 p3 = vlib_get_buffer (vm, from[3]);
324 p4 = vlib_get_buffer (vm, from[4]);
325 p5 = vlib_get_buffer (vm, from[5]);
Dave Barach97d8dc22016-08-15 15:31:15 -0400326
327 /* Prefetch the buffer header for the N+2 loop iteration */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700328 vlib_prefetch_buffer_header (p4, LOAD);
329 vlib_prefetch_buffer_header (p5, LOAD);
330
Dave Barach97d8dc22016-08-15 15:31:15 -0400331 /* Prefetch the replication context for the N+1 loop iteration */
332 /* This depends on the buffer header above */
333 replication_prefetch_ctx (p2);
334 replication_prefetch_ctx (p3);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700335
Dave Barach97d8dc22016-08-15 15:31:15 -0400336 /* Prefetch the packet for the N+1 loop iteration */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700337 CLIB_PREFETCH (p2->data, CLIB_CACHE_LINE_BYTES, STORE);
338 CLIB_PREFETCH (p3->data, CLIB_CACHE_LINE_BYTES, STORE);
339 }
340
Dave Barach97d8dc22016-08-15 15:31:15 -0400341 /* speculatively enqueue b0 and b1 to the current next frame */
342 /* bi is "buffer index", b is pointer to the buffer */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700343 to_next[0] = bi0 = from[0];
344 to_next[1] = bi1 = from[1];
345 from += 2;
346 to_next += 2;
347 n_left_from -= 2;
348 n_left_to_next -= 2;
349
350 b0 = vlib_get_buffer (vm, bi0);
351 b1 = vlib_get_buffer (vm, bi1);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700352
Dave Barach97d8dc22016-08-15 15:31:15 -0400353 /* RX interface handles */
354 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
355 sw_if_index1 = vnet_buffer (b1)->sw_if_index[VLIB_RX];
Ed Warnickecb9cada2015-12-08 15:45:58 -0700356
Dave Barach97d8dc22016-08-15 15:31:15 -0400357 /* process 2 pkts */
358 em->counters[node_counter_base_index + L2FLOOD_ERROR_L2FLOOD] += 2;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700359
Dave Barach97d8dc22016-08-15 15:31:15 -0400360 l2flood_process (vm, node, msm,
361 &em->counters[node_counter_base_index], b0,
362 &sw_if_index0, &key0, &bucket0, &result0, &next0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700363
Dave Barach97d8dc22016-08-15 15:31:15 -0400364 l2flood_process (vm, node, msm,
365 &em->counters[node_counter_base_index], b1,
366 &sw_if_index1, &key1, &bucket1, &result1, &next1);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700367
Dave Barach97d8dc22016-08-15 15:31:15 -0400368 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)))
369 {
370 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
371 {
372 l2flood_trace_t *t =
373 vlib_add_trace (vm, node, b0, sizeof (*t));
374 ethernet_header_t *h0 = vlib_buffer_get_current (b0);
375 t->sw_if_index = sw_if_index0;
376 t->bd_index = vnet_buffer (b0)->l2.bd_index;
377 clib_memcpy (t->src, h0->src_address, 6);
378 clib_memcpy (t->dst, h0->dst_address, 6);
379 }
380 if (PREDICT_FALSE (b1->flags & VLIB_BUFFER_IS_TRACED))
381 {
382 l2flood_trace_t *t =
383 vlib_add_trace (vm, node, b1, sizeof (*t));
384 ethernet_header_t *h1 = vlib_buffer_get_current (b1);
385 t->sw_if_index = sw_if_index1;
386 t->bd_index = vnet_buffer (b1)->l2.bd_index;
387 clib_memcpy (t->src, h1->src_address, 6);
388 clib_memcpy (t->dst, h1->dst_address, 6);
389 }
390 }
391
392 /* verify speculative enqueues, maybe switch current next frame */
393 /* if next0==next1==next_index then nothing special needs to be done */
394 vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
395 to_next, n_left_to_next,
396 bi0, bi1, next0, next1);
397 }
398
Ed Warnickecb9cada2015-12-08 15:45:58 -0700399 while (n_left_from > 0 && n_left_to_next > 0)
400 {
Dave Barach97d8dc22016-08-15 15:31:15 -0400401 u32 bi0;
402 vlib_buffer_t *b0;
403 u32 next0;
404 u32 sw_if_index0;
405 l2fib_entry_key_t key0;
406 l2fib_entry_result_t result0;
407 u32 bucket0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700408
Dave Barach97d8dc22016-08-15 15:31:15 -0400409 /* speculatively enqueue b0 to the current next frame */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700410 bi0 = from[0];
411 to_next[0] = bi0;
412 from += 1;
413 to_next += 1;
414 n_left_from -= 1;
415 n_left_to_next -= 1;
416
417 b0 = vlib_get_buffer (vm, bi0);
418
Dave Barach97d8dc22016-08-15 15:31:15 -0400419 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
Ed Warnickecb9cada2015-12-08 15:45:58 -0700420
Dave Barach97d8dc22016-08-15 15:31:15 -0400421 /* process 1 pkt */
422 em->counters[node_counter_base_index + L2FLOOD_ERROR_L2FLOOD] += 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700423
Dave Barach97d8dc22016-08-15 15:31:15 -0400424 l2flood_process (vm, node, msm,
425 &em->counters[node_counter_base_index], b0,
426 &sw_if_index0, &key0, &bucket0, &result0, &next0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700427
Dave Barach97d8dc22016-08-15 15:31:15 -0400428 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) &&
429 (b0->flags & VLIB_BUFFER_IS_TRACED)))
430 {
431 l2flood_trace_t *t = vlib_add_trace (vm, node, b0, sizeof (*t));
432 ethernet_header_t *h0 = vlib_buffer_get_current (b0);
433 t->sw_if_index = sw_if_index0;
434 t->bd_index = vnet_buffer (b0)->l2.bd_index;
435 clib_memcpy (t->src, h0->src_address, 6);
436 clib_memcpy (t->dst, h0->dst_address, 6);
437 }
438
439 /* verify speculative enqueue, maybe switch current next frame */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700440 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
441 to_next, n_left_to_next,
442 bi0, next0);
443 }
444
445 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
446 }
447
448 return frame->n_vectors;
449}
450
451
Dave Barach97d8dc22016-08-15 15:31:15 -0400452/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700453VLIB_REGISTER_NODE (l2flood_node,static) = {
454 .function = l2flood_node_fn,
455 .name = "l2-flood",
456 .vector_size = sizeof (u32),
457 .format_trace = format_l2flood_trace,
458 .type = VLIB_NODE_TYPE_INTERNAL,
Dave Barach97d8dc22016-08-15 15:31:15 -0400459
Ed Warnickecb9cada2015-12-08 15:45:58 -0700460 .n_errors = ARRAY_LEN(l2flood_error_strings),
461 .error_strings = l2flood_error_strings,
462
463 .n_next_nodes = L2FLOOD_N_NEXT,
464
465 /* edit / add dispositions here */
466 .next_nodes = {
467 [L2FLOOD_NEXT_L2_OUTPUT] = "l2-output",
468 [L2FLOOD_NEXT_DROP] = "error-drop",
469 },
470};
Dave Barach97d8dc22016-08-15 15:31:15 -0400471/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700472
Damjan Marion1c80e832016-05-11 23:07:18 +0200473VLIB_NODE_FUNCTION_MULTIARCH (l2flood_node, l2flood_node_fn)
Dave Barach97d8dc22016-08-15 15:31:15 -0400474 clib_error_t *l2flood_init (vlib_main_t * vm)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700475{
Dave Barach97d8dc22016-08-15 15:31:15 -0400476 l2flood_main_t *mp = &l2flood_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700477
Dave Barach97d8dc22016-08-15 15:31:15 -0400478 mp->vlib_main = vm;
479 mp->vnet_main = vnet_get_main ();
480
481 /* Initialize the feature next-node indexes */
482 feat_bitmap_init_next_nodes (vm,
483 l2flood_node.index,
484 L2INPUT_N_FEAT,
485 l2input_get_feat_names (),
486 mp->feat_next_node_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700487
488 return 0;
489}
490
491VLIB_INIT_FUNCTION (l2flood_init);
492
493
494
Chris Luke16bcf7d2016-09-01 14:31:46 -0400495/** Add the L3 input node for this ethertype to the next nodes structure. */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700496void
497l2flood_register_input_type (vlib_main_t * vm,
Dave Barach97d8dc22016-08-15 15:31:15 -0400498 ethernet_type_t type, u32 node_index)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700499{
Dave Barach97d8dc22016-08-15 15:31:15 -0400500 l2flood_main_t *mp = &l2flood_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700501 u32 next_index;
502
Dave Barach97d8dc22016-08-15 15:31:15 -0400503 next_index = vlib_node_add_next (vm, l2flood_node.index, node_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700504
505 next_by_ethertype_register (&mp->l3_next, type, next_index);
506}
507
508
Dave Barach97d8dc22016-08-15 15:31:15 -0400509/**
Chris Luke16bcf7d2016-09-01 14:31:46 -0400510 * Set subinterface flood enable/disable.
Dave Barach97d8dc22016-08-15 15:31:15 -0400511 * The CLI format is:
512 * set interface l2 flood <interface> [disable]
513 */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700514static clib_error_t *
515int_flood (vlib_main_t * vm,
Dave Barach97d8dc22016-08-15 15:31:15 -0400516 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700517{
Dave Barach97d8dc22016-08-15 15:31:15 -0400518 vnet_main_t *vnm = vnet_get_main ();
519 clib_error_t *error = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700520 u32 sw_if_index;
521 u32 enable;
522
Dave Barach97d8dc22016-08-15 15:31:15 -0400523 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700524 {
525 error = clib_error_return (0, "unknown interface `%U'",
Dave Barach97d8dc22016-08-15 15:31:15 -0400526 format_unformat_error, input);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700527 goto done;
528 }
529
530 enable = 1;
Dave Barach97d8dc22016-08-15 15:31:15 -0400531 if (unformat (input, "disable"))
532 {
533 enable = 0;
534 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700535
Dave Barach97d8dc22016-08-15 15:31:15 -0400536 /* set the interface flag */
537 l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_FLOOD, enable);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700538
Dave Barach97d8dc22016-08-15 15:31:15 -0400539done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700540 return error;
541}
542
Billy McFall22aa3e92016-09-09 08:46:40 -0400543/*?
544 * Layer 2 flooding can be enabled and disabled on each
545 * interface and on each bridge-domain. Use this command to
546 * manage interfaces. It is enabled by default.
547 *
548 * @cliexpar
549 * Example of how to enable flooding:
550 * @cliexcmd{set interface l2 flood GigabitEthernet0/8/0}
551 * Example of how to disable flooding:
552 * @cliexcmd{set interface l2 flood GigabitEthernet0/8/0 disable}
553?*/
Dave Barach97d8dc22016-08-15 15:31:15 -0400554/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700555VLIB_CLI_COMMAND (int_flood_cli, static) = {
556 .path = "set interface l2 flood",
557 .short_help = "set interface l2 flood <interface> [disable]",
558 .function = int_flood,
559};
Dave Barach97d8dc22016-08-15 15:31:15 -0400560/* *INDENT-ON* */
561
562/*
563 * fd.io coding-style-patch-verification: ON
564 *
565 * Local Variables:
566 * eval: (c-set-style "gnu")
567 * End:
568 */