Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 2 | * l2_flood.c : layer 2 flooding |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 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 | #include <vnet/l2/l2_input.h> |
| 24 | #include <vnet/l2/feat_bitmap.h> |
| 25 | #include <vnet/l2/l2_bvi.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 26 | #include <vnet/l2/l2_fib.h> |
| 27 | |
| 28 | #include <vppinfra/error.h> |
| 29 | #include <vppinfra/hash.h> |
| 30 | |
| 31 | |
Billy McFall | 22aa3e9 | 2016-09-09 08:46:40 -0400 | [diff] [blame] | 32 | /** |
| 33 | * @file |
| 34 | * @brief Ethernet Flooding. |
| 35 | * |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 36 | * Flooding uses the packet replication infrastructure to send a copy of the |
| 37 | * packet to each member interface. Logically the replication infrastructure |
| 38 | * expects two graph nodes: a prep node that initiates replication and sends the |
| 39 | * packet to the first destination, and a recycle node that is passed the packet |
| 40 | * after it has been transmitted. |
| 41 | * |
| 42 | * To decrease the amount of code, l2 flooding implements both functions in |
| 43 | * the same graph node. This node can tell if is it being called as the "prep" |
| 44 | * or "recycle" using replication_is_recycled(). |
| 45 | */ |
| 46 | |
| 47 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 48 | typedef struct |
| 49 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 50 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 51 | /* Next nodes for each feature */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 52 | u32 feat_next_node_index[32]; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 53 | |
| 54 | /* next node index for the L3 input node of each ethertype */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 55 | next_by_ethertype_t l3_next; |
| 56 | |
| 57 | /* convenience variables */ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 58 | vlib_main_t *vlib_main; |
| 59 | vnet_main_t *vnet_main; |
Neale Ranns | 055b231 | 2018-07-20 01:16:04 -0700 | [diff] [blame] | 60 | |
| 61 | /* per-cpu vector of cloned packets */ |
| 62 | u32 **clones; |
| 63 | l2_flood_member_t ***members; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 64 | } l2flood_main_t; |
| 65 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 66 | typedef struct |
| 67 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 68 | u8 src[6]; |
| 69 | u8 dst[6]; |
| 70 | u32 sw_if_index; |
| 71 | u16 bd_index; |
| 72 | } l2flood_trace_t; |
| 73 | |
| 74 | |
| 75 | /* packet trace format function */ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 76 | static u8 * |
| 77 | format_l2flood_trace (u8 * s, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 78 | { |
| 79 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 80 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 81 | l2flood_trace_t *t = va_arg (*args, l2flood_trace_t *); |
| 82 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 83 | s = format (s, "l2-flood: sw_if_index %d dst %U src %U bd_index %d", |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 84 | t->sw_if_index, |
| 85 | format_ethernet_address, t->dst, |
| 86 | format_ethernet_address, t->src, t->bd_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 87 | return s; |
| 88 | } |
| 89 | |
Filip Tehlar | 44f0f71 | 2019-03-11 04:26:37 -0700 | [diff] [blame] | 90 | extern l2flood_main_t l2flood_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 91 | |
Filip Tehlar | 44f0f71 | 2019-03-11 04:26:37 -0700 | [diff] [blame] | 92 | #ifndef CLIB_MARCH_VARIANT |
| 93 | l2flood_main_t l2flood_main; |
| 94 | #endif /* CLIB_MARCH_VARIANT */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 95 | |
| 96 | #define foreach_l2flood_error \ |
| 97 | _(L2FLOOD, "L2 flood packets") \ |
| 98 | _(REPL_FAIL, "L2 replication failures") \ |
| 99 | _(NO_MEMBERS, "L2 replication complete") \ |
John Lo | 7185c3b | 2016-06-04 00:02:37 -0400 | [diff] [blame] | 100 | _(BVI_BAD_MAC, "BVI L3 mac mismatch") \ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 101 | _(BVI_ETHERTYPE, "BVI packet with unhandled ethertype") |
| 102 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 103 | typedef enum |
| 104 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 105 | #define _(sym,str) L2FLOOD_ERROR_##sym, |
| 106 | foreach_l2flood_error |
| 107 | #undef _ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 108 | L2FLOOD_N_ERROR, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 109 | } l2flood_error_t; |
| 110 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 111 | static char *l2flood_error_strings[] = { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 112 | #define _(sym,string) string, |
| 113 | foreach_l2flood_error |
| 114 | #undef _ |
| 115 | }; |
| 116 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 117 | typedef enum |
| 118 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 119 | L2FLOOD_NEXT_L2_OUTPUT, |
| 120 | L2FLOOD_NEXT_DROP, |
| 121 | L2FLOOD_N_NEXT, |
| 122 | } l2flood_next_t; |
| 123 | |
| 124 | /* |
| 125 | * Perform flooding on one packet |
| 126 | * |
| 127 | * Due to the way BVI processing can modify the packet, the BVI interface |
| 128 | * (if present) must be processed last in the replication. The member vector |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 129 | * is arranged so that the BVI interface is always the first element. |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 130 | * Flooding walks the vector in reverse. |
| 131 | * |
| 132 | * BVI processing causes the packet to go to L3 processing. This strips the |
| 133 | * L2 header, which is fine because the replication infrastructure restores |
| 134 | * it. However L3 processing can trigger larger changes to the packet. For |
| 135 | * example, an ARP request could be turned into an ARP reply, an ICMP request |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 136 | * could be turned into an ICMP reply. If BVI processing is not performed |
| 137 | * last, the modified packet would be replicated to the remaining members. |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 138 | */ |
Filip Tehlar | 44f0f71 | 2019-03-11 04:26:37 -0700 | [diff] [blame] | 139 | VLIB_NODE_FN (l2flood_node) (vlib_main_t * vm, |
| 140 | vlib_node_runtime_t * node, vlib_frame_t * frame) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 141 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 142 | u32 n_left_from, *from, *to_next; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 143 | l2flood_next_t next_index; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 144 | l2flood_main_t *msm = &l2flood_main; |
Neale Ranns | 055b231 | 2018-07-20 01:16:04 -0700 | [diff] [blame] | 145 | u32 thread_index = vm->thread_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 146 | |
| 147 | from = vlib_frame_vector_args (frame); |
Neale Ranns | 055b231 | 2018-07-20 01:16:04 -0700 | [diff] [blame] | 148 | n_left_from = frame->n_vectors; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 149 | next_index = node->cached_next_index; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 150 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 151 | while (n_left_from > 0) |
| 152 | { |
| 153 | u32 n_left_to_next; |
| 154 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 155 | 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] | 156 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 157 | while (n_left_from > 0 && n_left_to_next > 0) |
| 158 | { |
Neale Ranns | 055b231 | 2018-07-20 01:16:04 -0700 | [diff] [blame] | 159 | u16 n_clones, n_cloned, clone0; |
| 160 | l2_bridge_domain_t *bd_config; |
Neale Ranns | c25eb45 | 2018-09-12 06:53:03 -0400 | [diff] [blame] | 161 | u32 sw_if_index0, bi0, ci0; |
Neale Ranns | 055b231 | 2018-07-20 01:16:04 -0700 | [diff] [blame] | 162 | l2_flood_member_t *member; |
| 163 | vlib_buffer_t *b0, *c0; |
Neale Ranns | c25eb45 | 2018-09-12 06:53:03 -0400 | [diff] [blame] | 164 | u16 next0; |
Neale Ranns | 055b231 | 2018-07-20 01:16:04 -0700 | [diff] [blame] | 165 | u8 in_shg; |
| 166 | i32 mi; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 167 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 168 | /* speculatively enqueue b0 to the current next frame */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 169 | bi0 = from[0]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 170 | from += 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 171 | n_left_from -= 1; |
John Lo | fe80c49 | 2018-08-09 11:03:21 -0400 | [diff] [blame] | 172 | next0 = L2FLOOD_NEXT_L2_OUTPUT; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 173 | |
| 174 | b0 = vlib_get_buffer (vm, bi0); |
| 175 | |
Neale Ranns | 055b231 | 2018-07-20 01:16:04 -0700 | [diff] [blame] | 176 | /* Get config for the bridge domain interface */ |
| 177 | bd_config = vec_elt_at_index (l2input_main.bd_configs, |
| 178 | vnet_buffer (b0)->l2.bd_index); |
| 179 | in_shg = vnet_buffer (b0)->l2.shg; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 180 | sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 181 | |
Neale Ranns | 055b231 | 2018-07-20 01:16:04 -0700 | [diff] [blame] | 182 | vec_validate (msm->members[thread_index], |
| 183 | vec_len (bd_config->members)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 184 | |
Neale Ranns | 055b231 | 2018-07-20 01:16:04 -0700 | [diff] [blame] | 185 | vec_reset_length (msm->members[thread_index]); |
| 186 | |
| 187 | /* Find first members that passes the reflection and SHG checks */ |
| 188 | for (mi = bd_config->flood_count - 1; mi >= 0; mi--) |
| 189 | { |
| 190 | member = &bd_config->members[mi]; |
| 191 | if ((member->sw_if_index != sw_if_index0) && |
| 192 | (!in_shg || (member->shg != in_shg))) |
| 193 | { |
| 194 | vec_add1 (msm->members[thread_index], member); |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | n_clones = vec_len (msm->members[thread_index]); |
| 199 | |
| 200 | if (0 == n_clones) |
| 201 | { |
| 202 | /* No members to flood to */ |
| 203 | to_next[0] = bi0; |
| 204 | to_next += 1; |
| 205 | n_left_to_next -= 1; |
| 206 | |
| 207 | b0->error = node->errors[L2FLOOD_ERROR_NO_MEMBERS]; |
| 208 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, |
| 209 | to_next, n_left_to_next, |
| 210 | bi0, L2FLOOD_NEXT_DROP); |
| 211 | continue; |
| 212 | } |
Neale Ranns | b9fa29d | 2018-10-02 07:27:02 -0700 | [diff] [blame] | 213 | else if (n_clones > 1) |
Neale Ranns | 055b231 | 2018-07-20 01:16:04 -0700 | [diff] [blame] | 214 | { |
Neale Ranns | b9fa29d | 2018-10-02 07:27:02 -0700 | [diff] [blame] | 215 | vec_validate (msm->clones[thread_index], n_clones); |
Neale Ranns | 055b231 | 2018-07-20 01:16:04 -0700 | [diff] [blame] | 216 | |
Neale Ranns | b9fa29d | 2018-10-02 07:27:02 -0700 | [diff] [blame] | 217 | /* |
| 218 | * the header offset needs to be large enough to incorporate |
| 219 | * all the L3 headers that could be touched when doing BVI |
| 220 | * processing. So take the current l2 length plus 2 * IPv6 |
| 221 | * headers (for tunnel encap) |
| 222 | */ |
| 223 | n_cloned = vlib_buffer_clone (vm, bi0, |
| 224 | msm->clones[thread_index], |
| 225 | n_clones, |
Damjan Marion | bd0da97 | 2018-10-31 10:59:02 +0100 | [diff] [blame] | 226 | VLIB_BUFFER_CLONE_HEAD_SIZE); |
Neale Ranns | b9fa29d | 2018-10-02 07:27:02 -0700 | [diff] [blame] | 227 | |
Benoît Ganne | 8a4bfda | 2019-07-22 14:21:46 +0200 | [diff] [blame] | 228 | vec_set_len (msm->clones[thread_index], n_cloned); |
| 229 | |
Neale Ranns | b9fa29d | 2018-10-02 07:27:02 -0700 | [diff] [blame] | 230 | if (PREDICT_FALSE (n_cloned != n_clones)) |
| 231 | { |
| 232 | b0->error = node->errors[L2FLOOD_ERROR_REPL_FAIL]; |
| 233 | } |
| 234 | |
| 235 | /* |
| 236 | * for all but the last clone, these are not BVI bound |
| 237 | */ |
| 238 | for (clone0 = 0; clone0 < n_cloned - 1; clone0++) |
| 239 | { |
| 240 | member = msm->members[thread_index][clone0]; |
| 241 | ci0 = msm->clones[thread_index][clone0]; |
| 242 | c0 = vlib_get_buffer (vm, ci0); |
| 243 | |
| 244 | to_next[0] = ci0; |
| 245 | to_next += 1; |
| 246 | n_left_to_next -= 1; |
| 247 | |
| 248 | if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && |
| 249 | (b0->flags & VLIB_BUFFER_IS_TRACED))) |
| 250 | { |
| 251 | ethernet_header_t *h0; |
| 252 | l2flood_trace_t *t; |
| 253 | |
Neale Ranns | b9fa29d | 2018-10-02 07:27:02 -0700 | [diff] [blame] | 254 | t = vlib_add_trace (vm, node, c0, sizeof (*t)); |
| 255 | h0 = vlib_buffer_get_current (c0); |
| 256 | t->sw_if_index = sw_if_index0; |
| 257 | t->bd_index = vnet_buffer (c0)->l2.bd_index; |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 258 | clib_memcpy_fast (t->src, h0->src_address, 6); |
| 259 | clib_memcpy_fast (t->dst, h0->dst_address, 6); |
Neale Ranns | b9fa29d | 2018-10-02 07:27:02 -0700 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | /* Do normal L2 forwarding */ |
| 263 | vnet_buffer (c0)->sw_if_index[VLIB_TX] = |
| 264 | member->sw_if_index; |
| 265 | |
| 266 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, |
| 267 | to_next, n_left_to_next, |
| 268 | ci0, next0); |
| 269 | if (PREDICT_FALSE (0 == n_left_to_next)) |
| 270 | { |
| 271 | vlib_put_next_frame (vm, node, next_index, |
| 272 | n_left_to_next); |
| 273 | vlib_get_next_frame (vm, node, next_index, to_next, |
| 274 | n_left_to_next); |
| 275 | } |
| 276 | } |
Neale Ranns | 055b231 | 2018-07-20 01:16:04 -0700 | [diff] [blame] | 277 | member = msm->members[thread_index][clone0]; |
| 278 | ci0 = msm->clones[thread_index][clone0]; |
Neale Ranns | b9fa29d | 2018-10-02 07:27:02 -0700 | [diff] [blame] | 279 | } |
| 280 | else |
| 281 | { |
| 282 | /* one clone */ |
| 283 | ci0 = bi0; |
| 284 | member = msm->members[thread_index][0]; |
Neale Ranns | 055b231 | 2018-07-20 01:16:04 -0700 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | /* |
| 288 | * the last clone that might go to a BVI |
| 289 | */ |
Neale Ranns | 055b231 | 2018-07-20 01:16:04 -0700 | [diff] [blame] | 290 | c0 = vlib_get_buffer (vm, ci0); |
| 291 | |
| 292 | to_next[0] = ci0; |
| 293 | to_next += 1; |
| 294 | n_left_to_next -= 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 295 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 296 | if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && |
| 297 | (b0->flags & VLIB_BUFFER_IS_TRACED))) |
| 298 | { |
Neale Ranns | 055b231 | 2018-07-20 01:16:04 -0700 | [diff] [blame] | 299 | ethernet_header_t *h0; |
| 300 | l2flood_trace_t *t; |
| 301 | |
Neale Ranns | 055b231 | 2018-07-20 01:16:04 -0700 | [diff] [blame] | 302 | t = vlib_add_trace (vm, node, c0, sizeof (*t)); |
| 303 | h0 = vlib_buffer_get_current (c0); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 304 | t->sw_if_index = sw_if_index0; |
Neale Ranns | 055b231 | 2018-07-20 01:16:04 -0700 | [diff] [blame] | 305 | t->bd_index = vnet_buffer (c0)->l2.bd_index; |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 306 | clib_memcpy_fast (t->src, h0->src_address, 6); |
| 307 | clib_memcpy_fast (t->dst, h0->dst_address, 6); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 308 | } |
| 309 | |
Neale Ranns | 055b231 | 2018-07-20 01:16:04 -0700 | [diff] [blame] | 310 | |
| 311 | /* Forward packet to the current member */ |
| 312 | if (PREDICT_FALSE (member->flags & L2_FLOOD_MEMBER_BVI)) |
| 313 | { |
| 314 | /* Do BVI processing */ |
| 315 | u32 rc; |
| 316 | rc = l2_to_bvi (vm, |
| 317 | msm->vnet_main, |
| 318 | c0, member->sw_if_index, &msm->l3_next, &next0); |
| 319 | |
John Lo | fe80c49 | 2018-08-09 11:03:21 -0400 | [diff] [blame] | 320 | if (PREDICT_FALSE (rc != TO_BVI_ERR_OK)) |
Neale Ranns | 055b231 | 2018-07-20 01:16:04 -0700 | [diff] [blame] | 321 | { |
| 322 | if (rc == TO_BVI_ERR_BAD_MAC) |
| 323 | { |
| 324 | c0->error = node->errors[L2FLOOD_ERROR_BVI_BAD_MAC]; |
| 325 | } |
| 326 | else if (rc == TO_BVI_ERR_ETHERTYPE) |
| 327 | { |
| 328 | c0->error = node->errors[L2FLOOD_ERROR_BVI_ETHERTYPE]; |
| 329 | } |
John Lo | fe80c49 | 2018-08-09 11:03:21 -0400 | [diff] [blame] | 330 | next0 = L2FLOOD_NEXT_DROP; |
Neale Ranns | 055b231 | 2018-07-20 01:16:04 -0700 | [diff] [blame] | 331 | } |
| 332 | } |
| 333 | else |
| 334 | { |
| 335 | /* Do normal L2 forwarding */ |
| 336 | vnet_buffer (c0)->sw_if_index[VLIB_TX] = member->sw_if_index; |
Neale Ranns | 055b231 | 2018-07-20 01:16:04 -0700 | [diff] [blame] | 337 | } |
| 338 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 339 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, |
| 340 | to_next, n_left_to_next, |
Neale Ranns | 055b231 | 2018-07-20 01:16:04 -0700 | [diff] [blame] | 341 | ci0, next0); |
| 342 | if (PREDICT_FALSE (0 == n_left_to_next)) |
| 343 | { |
| 344 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 345 | vlib_get_next_frame (vm, node, next_index, |
| 346 | to_next, n_left_to_next); |
| 347 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 351 | } |
| 352 | |
Neale Ranns | 055b231 | 2018-07-20 01:16:04 -0700 | [diff] [blame] | 353 | vlib_node_increment_counter (vm, node->node_index, |
| 354 | L2FLOOD_ERROR_L2FLOOD, frame->n_vectors); |
| 355 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 356 | return frame->n_vectors; |
| 357 | } |
| 358 | |
| 359 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 360 | /* *INDENT-OFF* */ |
Filip Tehlar | 44f0f71 | 2019-03-11 04:26:37 -0700 | [diff] [blame] | 361 | VLIB_REGISTER_NODE (l2flood_node) = { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 362 | .name = "l2-flood", |
| 363 | .vector_size = sizeof (u32), |
| 364 | .format_trace = format_l2flood_trace, |
| 365 | .type = VLIB_NODE_TYPE_INTERNAL, |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 366 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 367 | .n_errors = ARRAY_LEN(l2flood_error_strings), |
| 368 | .error_strings = l2flood_error_strings, |
| 369 | |
| 370 | .n_next_nodes = L2FLOOD_N_NEXT, |
| 371 | |
| 372 | /* edit / add dispositions here */ |
| 373 | .next_nodes = { |
| 374 | [L2FLOOD_NEXT_L2_OUTPUT] = "l2-output", |
| 375 | [L2FLOOD_NEXT_DROP] = "error-drop", |
| 376 | }, |
| 377 | }; |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 378 | /* *INDENT-ON* */ |
| 379 | |
Filip Tehlar | 44f0f71 | 2019-03-11 04:26:37 -0700 | [diff] [blame] | 380 | #ifndef CLIB_MARCH_VARIANT |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 381 | clib_error_t * |
| 382 | l2flood_init (vlib_main_t * vm) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 383 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 384 | l2flood_main_t *mp = &l2flood_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 385 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 386 | mp->vlib_main = vm; |
| 387 | mp->vnet_main = vnet_get_main (); |
| 388 | |
Neale Ranns | 055b231 | 2018-07-20 01:16:04 -0700 | [diff] [blame] | 389 | vec_validate (mp->clones, vlib_num_workers ()); |
| 390 | vec_validate (mp->members, vlib_num_workers ()); |
| 391 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 392 | /* Initialize the feature next-node indexes */ |
| 393 | feat_bitmap_init_next_nodes (vm, |
| 394 | l2flood_node.index, |
| 395 | L2INPUT_N_FEAT, |
| 396 | l2input_get_feat_names (), |
| 397 | mp->feat_next_node_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 398 | |
Neale Ranns | 055b231 | 2018-07-20 01:16:04 -0700 | [diff] [blame] | 399 | return NULL; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | VLIB_INIT_FUNCTION (l2flood_init); |
| 403 | |
| 404 | |
| 405 | |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 406 | /** Add the L3 input node for this ethertype to the next nodes structure. */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 407 | void |
| 408 | l2flood_register_input_type (vlib_main_t * vm, |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 409 | ethernet_type_t type, u32 node_index) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 410 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 411 | l2flood_main_t *mp = &l2flood_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 412 | u32 next_index; |
| 413 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 414 | next_index = vlib_node_add_next (vm, l2flood_node.index, node_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 415 | |
| 416 | next_by_ethertype_register (&mp->l3_next, type, next_index); |
| 417 | } |
Filip Tehlar | 44f0f71 | 2019-03-11 04:26:37 -0700 | [diff] [blame] | 418 | #endif /* CLIB_MARCH_VARIANT */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 419 | |
| 420 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 421 | /** |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 422 | * Set subinterface flood enable/disable. |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 423 | * The CLI format is: |
| 424 | * set interface l2 flood <interface> [disable] |
| 425 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 426 | static clib_error_t * |
| 427 | int_flood (vlib_main_t * vm, |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 428 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 429 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 430 | vnet_main_t *vnm = vnet_get_main (); |
| 431 | clib_error_t *error = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 432 | u32 sw_if_index; |
| 433 | u32 enable; |
| 434 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 435 | if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 436 | { |
| 437 | error = clib_error_return (0, "unknown interface `%U'", |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 438 | format_unformat_error, input); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 439 | goto done; |
| 440 | } |
| 441 | |
| 442 | enable = 1; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 443 | if (unformat (input, "disable")) |
| 444 | { |
| 445 | enable = 0; |
| 446 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 447 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 448 | /* set the interface flag */ |
| 449 | l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_FLOOD, enable); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 450 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 451 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 452 | return error; |
| 453 | } |
| 454 | |
Billy McFall | 22aa3e9 | 2016-09-09 08:46:40 -0400 | [diff] [blame] | 455 | /*? |
| 456 | * Layer 2 flooding can be enabled and disabled on each |
| 457 | * interface and on each bridge-domain. Use this command to |
| 458 | * manage interfaces. It is enabled by default. |
| 459 | * |
| 460 | * @cliexpar |
| 461 | * Example of how to enable flooding: |
| 462 | * @cliexcmd{set interface l2 flood GigabitEthernet0/8/0} |
| 463 | * Example of how to disable flooding: |
| 464 | * @cliexcmd{set interface l2 flood GigabitEthernet0/8/0 disable} |
| 465 | ?*/ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 466 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 467 | VLIB_CLI_COMMAND (int_flood_cli, static) = { |
| 468 | .path = "set interface l2 flood", |
| 469 | .short_help = "set interface l2 flood <interface> [disable]", |
| 470 | .function = int_flood, |
| 471 | }; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 472 | /* *INDENT-ON* */ |
| 473 | |
| 474 | /* |
| 475 | * fd.io coding-style-patch-verification: ON |
| 476 | * |
| 477 | * Local Variables: |
| 478 | * eval: (c-set-style "gnu") |
| 479 | * End: |
| 480 | */ |