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