Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * l2_bd.c : layer 2 bridge domain |
| 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 <vlib/cli.h> |
| 21 | #include <vnet/ethernet/ethernet.h> |
| 22 | #include <vnet/ip/format.h> |
| 23 | #include <vnet/l2/l2_input.h> |
| 24 | #include <vnet/l2/feat_bitmap.h> |
| 25 | #include <vnet/l2/l2_bd.h> |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 26 | #include <vnet/l2/l2_learn.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 27 | #include <vnet/l2/l2_fib.h> |
| 28 | #include <vnet/l2/l2_vtr.h> |
| 29 | #include <vnet/ip/ip4_packet.h> |
| 30 | #include <vnet/ip/ip6_packet.h> |
| 31 | |
| 32 | #include <vppinfra/error.h> |
| 33 | #include <vppinfra/hash.h> |
| 34 | #include <vppinfra/vec.h> |
| 35 | |
Billy McFall | 22aa3e9 | 2016-09-09 08:46:40 -0400 | [diff] [blame] | 36 | /** |
| 37 | * @file |
| 38 | * @brief Ethernet Bridge Domain. |
| 39 | * |
| 40 | * Code in this file manages Layer 2 bridge domains. |
| 41 | * |
| 42 | */ |
| 43 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 44 | bd_main_t bd_main; |
| 45 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 46 | /** |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 47 | Init bridge domain if not done already. |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 48 | For feature bitmap, set all bits except ARP termination |
| 49 | */ |
Damjan Marion | 99d8c76 | 2015-12-14 15:01:56 +0100 | [diff] [blame] | 50 | void |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 51 | bd_validate (l2_bridge_domain_t * bd_config) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 52 | { |
Eyal Bari | b1352ed | 2017-04-07 23:14:17 +0300 | [diff] [blame] | 53 | if (bd_is_valid (bd_config)) |
| 54 | return; |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 55 | bd_config->feature_bitmap = ~(L2INPUT_FEAT_ARP_TERM | L2INPUT_FEAT_UU_FWD); |
Eyal Bari | b1352ed | 2017-04-07 23:14:17 +0300 | [diff] [blame] | 56 | bd_config->bvi_sw_if_index = ~0; |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 57 | bd_config->uu_fwd_sw_if_index = ~0; |
Eyal Bari | b1352ed | 2017-04-07 23:14:17 +0300 | [diff] [blame] | 58 | bd_config->members = 0; |
| 59 | bd_config->flood_count = 0; |
| 60 | bd_config->tun_master_count = 0; |
| 61 | bd_config->tun_normal_count = 0; |
Eyal Bari | b6b04f0 | 2018-07-11 14:01:36 +0300 | [diff] [blame] | 62 | bd_config->no_flood_count = 0; |
Eyal Bari | b1352ed | 2017-04-07 23:14:17 +0300 | [diff] [blame] | 63 | bd_config->mac_by_ip4 = 0; |
| 64 | bd_config->mac_by_ip6 = hash_create_mem (0, sizeof (ip6_address_t), |
| 65 | sizeof (uword)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 66 | } |
| 67 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 68 | u32 |
Eyal Bari | b1352ed | 2017-04-07 23:14:17 +0300 | [diff] [blame] | 69 | bd_find_index (bd_main_t * bdm, u32 bd_id) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 70 | { |
Eyal Bari | b1352ed | 2017-04-07 23:14:17 +0300 | [diff] [blame] | 71 | u32 *p = (u32 *) hash_get (bdm->bd_index_by_bd_id, bd_id); |
| 72 | if (!p) |
| 73 | return ~0; |
| 74 | return p[0]; |
| 75 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 76 | |
Eyal Bari | b1352ed | 2017-04-07 23:14:17 +0300 | [diff] [blame] | 77 | u32 |
| 78 | bd_add_bd_index (bd_main_t * bdm, u32 bd_id) |
| 79 | { |
| 80 | ASSERT (!hash_get (bdm->bd_index_by_bd_id, bd_id)); |
| 81 | u32 rv = clib_bitmap_first_clear (bdm->bd_index_bitmap); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 82 | |
Eyal Bari | b1352ed | 2017-04-07 23:14:17 +0300 | [diff] [blame] | 83 | /* mark this index taken */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 84 | bdm->bd_index_bitmap = clib_bitmap_set (bdm->bd_index_bitmap, rv, 1); |
| 85 | |
| 86 | hash_set (bdm->bd_index_by_bd_id, bd_id, rv); |
| 87 | |
| 88 | vec_validate (l2input_main.bd_configs, rv); |
| 89 | l2input_main.bd_configs[rv].bd_id = bd_id; |
| 90 | |
| 91 | return rv; |
| 92 | } |
| 93 | |
John Lo | e26c81f | 2019-01-07 15:16:33 -0500 | [diff] [blame] | 94 | static inline void |
| 95 | bd_free_ip_mac_tables (l2_bridge_domain_t * bd) |
| 96 | { |
| 97 | u64 mac_addr; |
| 98 | ip6_address_t *ip6_addr_key; |
| 99 | |
| 100 | hash_free (bd->mac_by_ip4); |
| 101 | /* *INDENT-OFF* */ |
| 102 | hash_foreach_mem (ip6_addr_key, mac_addr, bd->mac_by_ip6, |
| 103 | ({ |
| 104 | clib_mem_free (ip6_addr_key); /* free memory used for ip6 addr key */ |
| 105 | })); |
| 106 | /* *INDENT-ON* */ |
| 107 | hash_free (bd->mac_by_ip6); |
| 108 | } |
| 109 | |
Eyal Bari | b1352ed | 2017-04-07 23:14:17 +0300 | [diff] [blame] | 110 | static int |
| 111 | bd_delete (bd_main_t * bdm, u32 bd_index) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 112 | { |
John Lo | d77630a | 2017-04-28 00:33:36 -0400 | [diff] [blame] | 113 | l2_bridge_domain_t *bd = &l2input_main.bd_configs[bd_index]; |
| 114 | u32 bd_id = bd->bd_id; |
Eyal Bari | afc47aa | 2017-04-20 14:45:17 +0300 | [diff] [blame] | 115 | |
John Lo | d48c8eb | 2017-05-05 12:35:25 -0400 | [diff] [blame] | 116 | /* flush non-static MACs in BD and removed bd_id from hash table */ |
| 117 | l2fib_flush_bd_mac (vlib_get_main (), bd_index); |
Eyal Bari | b1352ed | 2017-04-07 23:14:17 +0300 | [diff] [blame] | 118 | hash_unset (bdm->bd_index_by_bd_id, bd_id); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 119 | |
| 120 | /* mark this index clear */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 121 | bdm->bd_index_bitmap = clib_bitmap_set (bdm->bd_index_bitmap, bd_index, 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 122 | |
John Lo | d77630a | 2017-04-28 00:33:36 -0400 | [diff] [blame] | 123 | /* clear BD config for reuse: bd_id to -1 and clear feature_bitmap */ |
| 124 | bd->bd_id = ~0; |
| 125 | bd->feature_bitmap = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 126 | |
Jerome Tollet | 4830414 | 2017-09-05 12:13:22 +0100 | [diff] [blame] | 127 | /* free BD tag */ |
| 128 | vec_free (bd->bd_tag); |
| 129 | |
John Lo | d48c8eb | 2017-05-05 12:35:25 -0400 | [diff] [blame] | 130 | /* free memory used by BD */ |
John Lo | d77630a | 2017-04-28 00:33:36 -0400 | [diff] [blame] | 131 | vec_free (bd->members); |
John Lo | e26c81f | 2019-01-07 15:16:33 -0500 | [diff] [blame] | 132 | bd_free_ip_mac_tables (bd); |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 133 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 134 | return 0; |
| 135 | } |
| 136 | |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 137 | static void |
| 138 | update_flood_count (l2_bridge_domain_t * bd_config) |
| 139 | { |
Neale Ranns | 87dad11 | 2018-04-09 01:53:01 -0700 | [diff] [blame] | 140 | bd_config->flood_count = (vec_len (bd_config->members) - |
| 141 | (bd_config->tun_master_count ? |
| 142 | bd_config->tun_normal_count : 0)); |
| 143 | bd_config->flood_count -= bd_config->no_flood_count; |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 144 | } |
| 145 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 146 | void |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 147 | bd_add_member (l2_bridge_domain_t * bd_config, l2_flood_member_t * member) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 148 | { |
Neale Ranns | 87dad11 | 2018-04-09 01:53:01 -0700 | [diff] [blame] | 149 | u32 ix = 0; |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 150 | vnet_sw_interface_t *sw_if = vnet_get_sw_interface |
| 151 | (vnet_get_main (), member->sw_if_index); |
| 152 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 153 | /* |
| 154 | * Add one element to the vector |
Neale Ranns | 87dad11 | 2018-04-09 01:53:01 -0700 | [diff] [blame] | 155 | * vector is ordered [ bvi, normal/tun_masters..., tun_normals... no_flood] |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 156 | * When flooding, the bvi interface (if present) must be the last member |
| 157 | * processed due to how BVI processing can change the packet. To enable |
| 158 | * this order, we make the bvi interface the first in the vector and |
Neale Ranns | 87dad11 | 2018-04-09 01:53:01 -0700 | [diff] [blame] | 159 | * flooding walks the vector in reverse. The flood-count determines where |
| 160 | * in the member list to start the walk from. |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 161 | */ |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 162 | switch (sw_if->flood_class) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 163 | { |
Neale Ranns | 87dad11 | 2018-04-09 01:53:01 -0700 | [diff] [blame] | 164 | case VNET_FLOOD_CLASS_NO_FLOOD: |
| 165 | bd_config->no_flood_count++; |
| 166 | ix = vec_len (bd_config->members); |
| 167 | break; |
| 168 | case VNET_FLOOD_CLASS_BVI: |
| 169 | ix = 0; |
| 170 | break; |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 171 | case VNET_FLOOD_CLASS_TUNNEL_MASTER: |
| 172 | bd_config->tun_master_count++; |
| 173 | /* Fall through */ |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 174 | case VNET_FLOOD_CLASS_NORMAL: |
Neale Ranns | 87dad11 | 2018-04-09 01:53:01 -0700 | [diff] [blame] | 175 | ix = (vec_len (bd_config->members) - |
| 176 | bd_config->tun_normal_count - bd_config->no_flood_count); |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 177 | break; |
| 178 | case VNET_FLOOD_CLASS_TUNNEL_NORMAL: |
Neale Ranns | 87dad11 | 2018-04-09 01:53:01 -0700 | [diff] [blame] | 179 | ix = (vec_len (bd_config->members) - bd_config->no_flood_count); |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 180 | bd_config->tun_normal_count++; |
| 181 | break; |
| 182 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 183 | |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 184 | vec_insert_elts (bd_config->members, member, 1, ix); |
| 185 | update_flood_count (bd_config); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 186 | } |
| 187 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 188 | #define BD_REMOVE_ERROR_OK 0 |
| 189 | #define BD_REMOVE_ERROR_NOT_FOUND 1 |
| 190 | |
| 191 | u32 |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 192 | bd_remove_member (l2_bridge_domain_t * bd_config, u32 sw_if_index) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 193 | { |
| 194 | u32 ix; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 195 | |
| 196 | /* Find and delete the member */ |
| 197 | vec_foreach_index (ix, bd_config->members) |
| 198 | { |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 199 | l2_flood_member_t *m = vec_elt_at_index (bd_config->members, ix); |
| 200 | if (m->sw_if_index == sw_if_index) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 201 | { |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 202 | vnet_sw_interface_t *sw_if = vnet_get_sw_interface |
| 203 | (vnet_get_main (), sw_if_index); |
| 204 | |
| 205 | if (sw_if->flood_class != VNET_FLOOD_CLASS_NORMAL) |
| 206 | { |
| 207 | if (sw_if->flood_class == VNET_FLOOD_CLASS_TUNNEL_MASTER) |
| 208 | bd_config->tun_master_count--; |
| 209 | else if (sw_if->flood_class == VNET_FLOOD_CLASS_TUNNEL_NORMAL) |
| 210 | bd_config->tun_normal_count--; |
Eyal Bari | b6b04f0 | 2018-07-11 14:01:36 +0300 | [diff] [blame] | 211 | else if (sw_if->flood_class == VNET_FLOOD_CLASS_NO_FLOOD) |
| 212 | bd_config->no_flood_count--; |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 213 | } |
Eyal Bari | 25b3667 | 2017-03-02 10:43:19 +0200 | [diff] [blame] | 214 | vec_delete (bd_config->members, 1, ix); |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 215 | update_flood_count (bd_config); |
| 216 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 217 | return BD_REMOVE_ERROR_OK; |
| 218 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | return BD_REMOVE_ERROR_NOT_FOUND; |
| 222 | } |
| 223 | |
| 224 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 225 | clib_error_t * |
| 226 | l2bd_init (vlib_main_t * vm) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 227 | { |
| 228 | bd_main_t *bdm = &bd_main; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 229 | bdm->bd_index_by_bd_id = hash_create (0, sizeof (uword)); |
| 230 | /* |
| 231 | * create a dummy bd with bd_id of 0 and bd_index of 0 with feature set |
| 232 | * to packet drop only. Thus, packets received from any L2 interface with |
| 233 | * uninitialized bd_index of 0 can be dropped safely. |
| 234 | */ |
Eyal Bari | b1352ed | 2017-04-07 23:14:17 +0300 | [diff] [blame] | 235 | u32 bd_index = bd_add_bd_index (bdm, 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 236 | ASSERT (bd_index == 0); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 237 | l2input_main.bd_configs[0].feature_bitmap = L2INPUT_FEAT_DROP; |
Choonho Son | 0548079 | 2017-03-29 20:07:45 +0900 | [diff] [blame] | 238 | |
| 239 | bdm->vlib_main = vm; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 240 | return 0; |
| 241 | } |
| 242 | |
| 243 | VLIB_INIT_FUNCTION (l2bd_init); |
| 244 | |
| 245 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 246 | /** |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 247 | Set the learn/forward/flood flags for the bridge domain. |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 248 | Return 0 if ok, non-zero if for an error. |
| 249 | */ |
| 250 | u32 |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 251 | bd_set_flags (vlib_main_t * vm, u32 bd_index, bd_flags_t flags, u32 enable) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 252 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 253 | |
Eyal Bari | afc47aa | 2017-04-20 14:45:17 +0300 | [diff] [blame] | 254 | l2_bridge_domain_t *bd_config = l2input_bd_config (bd_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 255 | bd_validate (bd_config); |
Eyal Bari | afc47aa | 2017-04-20 14:45:17 +0300 | [diff] [blame] | 256 | u32 feature_bitmap = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 257 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 258 | if (flags & L2_LEARN) |
| 259 | { |
| 260 | feature_bitmap |= L2INPUT_FEAT_LEARN; |
| 261 | } |
| 262 | if (flags & L2_FWD) |
| 263 | { |
| 264 | feature_bitmap |= L2INPUT_FEAT_FWD; |
| 265 | } |
| 266 | if (flags & L2_FLOOD) |
| 267 | { |
| 268 | feature_bitmap |= L2INPUT_FEAT_FLOOD; |
| 269 | } |
| 270 | if (flags & L2_UU_FLOOD) |
| 271 | { |
| 272 | feature_bitmap |= L2INPUT_FEAT_UU_FLOOD; |
| 273 | } |
| 274 | if (flags & L2_ARP_TERM) |
| 275 | { |
| 276 | feature_bitmap |= L2INPUT_FEAT_ARP_TERM; |
| 277 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 278 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 279 | if (enable) |
| 280 | { |
| 281 | bd_config->feature_bitmap |= feature_bitmap; |
| 282 | } |
| 283 | else |
| 284 | { |
| 285 | bd_config->feature_bitmap &= ~feature_bitmap; |
| 286 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 287 | |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 288 | return bd_config->feature_bitmap; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 289 | } |
| 290 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 291 | /** |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 292 | Set the mac age for the bridge domain. |
| 293 | */ |
| 294 | void |
| 295 | bd_set_mac_age (vlib_main_t * vm, u32 bd_index, u8 age) |
| 296 | { |
| 297 | l2_bridge_domain_t *bd_config; |
| 298 | int enable = 0; |
| 299 | |
| 300 | vec_validate (l2input_main.bd_configs, bd_index); |
| 301 | bd_config = vec_elt_at_index (l2input_main.bd_configs, bd_index); |
| 302 | bd_config->mac_age = age; |
| 303 | |
| 304 | /* check if there is at least one bd with mac aging enabled */ |
| 305 | vec_foreach (bd_config, l2input_main.bd_configs) |
Eyal Bari | fead670 | 2017-04-04 04:46:32 +0300 | [diff] [blame] | 306 | enable |= bd_config->bd_id != ~0 && bd_config->mac_age != 0; |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 307 | |
| 308 | vlib_process_signal_event (vm, l2fib_mac_age_scanner_process_node.index, |
| 309 | enable ? L2_MAC_AGE_PROCESS_EVENT_START : |
| 310 | L2_MAC_AGE_PROCESS_EVENT_STOP, 0); |
| 311 | } |
| 312 | |
Jerome Tollet | 50570ec | 2017-09-14 12:53:56 +0100 | [diff] [blame] | 313 | /** |
| 314 | Set the tag for the bridge domain. |
| 315 | */ |
Jerome Tollet | 4830414 | 2017-09-05 12:13:22 +0100 | [diff] [blame] | 316 | |
Jerome Tollet | 50570ec | 2017-09-14 12:53:56 +0100 | [diff] [blame] | 317 | static void |
Jerome Tollet | 4830414 | 2017-09-05 12:13:22 +0100 | [diff] [blame] | 318 | bd_set_bd_tag (vlib_main_t * vm, u32 bd_index, u8 * bd_tag) |
| 319 | { |
| 320 | u8 *old; |
| 321 | l2_bridge_domain_t *bd_config; |
| 322 | vec_validate (l2input_main.bd_configs, bd_index); |
| 323 | bd_config = vec_elt_at_index (l2input_main.bd_configs, bd_index); |
| 324 | |
| 325 | old = bd_config->bd_tag; |
| 326 | |
| 327 | if (bd_tag[0]) |
| 328 | { |
| 329 | bd_config->bd_tag = format (0, "%s%c", bd_tag, 0); |
| 330 | } |
| 331 | else |
| 332 | { |
| 333 | bd_config->bd_tag = NULL; |
| 334 | } |
| 335 | |
| 336 | vec_free (old); |
| 337 | } |
| 338 | |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 339 | /** |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 340 | Set bridge-domain learn enable/disable. |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 341 | The CLI format is: |
| 342 | set bridge-domain learn <bd_id> [disable] |
| 343 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 344 | static clib_error_t * |
| 345 | bd_learn (vlib_main_t * vm, |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 346 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 347 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 348 | bd_main_t *bdm = &bd_main; |
| 349 | clib_error_t *error = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 350 | u32 bd_index, bd_id; |
| 351 | u32 enable; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 352 | uword *p; |
| 353 | |
| 354 | if (!unformat (input, "%d", &bd_id)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 355 | { |
| 356 | error = clib_error_return (0, "expecting bridge-domain id but got `%U'", |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 357 | format_unformat_error, input); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 358 | goto done; |
| 359 | } |
| 360 | |
Jon Loeliger | 1c7d485 | 2017-05-02 11:06:23 -0500 | [diff] [blame] | 361 | if (bd_id == 0) |
| 362 | return clib_error_return (0, |
| 363 | "No operations on the default bridge domain are supported"); |
| 364 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 365 | p = hash_get (bdm->bd_index_by_bd_id, bd_id); |
| 366 | |
| 367 | if (p == 0) |
| 368 | return clib_error_return (0, "No such bridge domain %d", bd_id); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 369 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 370 | bd_index = p[0]; |
| 371 | |
| 372 | enable = 1; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 373 | if (unformat (input, "disable")) |
| 374 | { |
| 375 | enable = 0; |
| 376 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 377 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 378 | /* set the bridge domain flag */ |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 379 | bd_set_flags (vm, bd_index, L2_LEARN, enable); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 380 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 381 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 382 | return error; |
| 383 | } |
| 384 | |
Billy McFall | 22aa3e9 | 2016-09-09 08:46:40 -0400 | [diff] [blame] | 385 | /*? |
| 386 | * Layer 2 learning can be enabled and disabled on each |
| 387 | * interface and on each bridge-domain. Use this command to |
| 388 | * manage bridge-domains. It is enabled by default. |
| 389 | * |
| 390 | * @cliexpar |
| 391 | * Example of how to enable learning (where 200 is the bridge-domain-id): |
| 392 | * @cliexcmd{set bridge-domain learn 200} |
| 393 | * Example of how to disable learning (where 200 is the bridge-domain-id): |
| 394 | * @cliexcmd{set bridge-domain learn 200 disable} |
| 395 | ?*/ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 396 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 397 | VLIB_CLI_COMMAND (bd_learn_cli, static) = { |
| 398 | .path = "set bridge-domain learn", |
| 399 | .short_help = "set bridge-domain learn <bridge-domain-id> [disable]", |
| 400 | .function = bd_learn, |
| 401 | }; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 402 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 403 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 404 | /** |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 405 | Set bridge-domain forward enable/disable. |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 406 | The CLI format is: |
| 407 | set bridge-domain forward <bd_index> [disable] |
| 408 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 409 | static clib_error_t * |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 410 | bd_fwd (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 411 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 412 | bd_main_t *bdm = &bd_main; |
| 413 | clib_error_t *error = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 414 | u32 bd_index, bd_id; |
| 415 | u32 enable; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 416 | uword *p; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 417 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 418 | if (!unformat (input, "%d", &bd_id)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 419 | { |
| 420 | error = clib_error_return (0, "expecting bridge-domain id but got `%U'", |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 421 | format_unformat_error, input); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 422 | goto done; |
| 423 | } |
| 424 | |
Jon Loeliger | 1c7d485 | 2017-05-02 11:06:23 -0500 | [diff] [blame] | 425 | if (bd_id == 0) |
| 426 | return clib_error_return (0, |
| 427 | "No operations on the default bridge domain are supported"); |
| 428 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 429 | p = hash_get (bdm->bd_index_by_bd_id, bd_id); |
| 430 | |
| 431 | if (p == 0) |
| 432 | return clib_error_return (0, "No such bridge domain %d", bd_id); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 433 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 434 | bd_index = p[0]; |
| 435 | |
| 436 | enable = 1; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 437 | if (unformat (input, "disable")) |
| 438 | { |
| 439 | enable = 0; |
| 440 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 441 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 442 | /* set the bridge domain flag */ |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 443 | bd_set_flags (vm, bd_index, L2_FWD, enable); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 444 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 445 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 446 | return error; |
| 447 | } |
| 448 | |
Billy McFall | 22aa3e9 | 2016-09-09 08:46:40 -0400 | [diff] [blame] | 449 | |
| 450 | /*? |
| 451 | * Layer 2 unicast forwarding can be enabled and disabled on each |
| 452 | * interface and on each bridge-domain. Use this command to |
| 453 | * manage bridge-domains. It is enabled by default. |
| 454 | * |
| 455 | * @cliexpar |
| 456 | * Example of how to enable forwarding (where 200 is the bridge-domain-id): |
| 457 | * @cliexcmd{set bridge-domain forward 200} |
| 458 | * Example of how to disable forwarding (where 200 is the bridge-domain-id): |
| 459 | * @cliexcmd{set bridge-domain forward 200 disable} |
| 460 | ?*/ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 461 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 462 | VLIB_CLI_COMMAND (bd_fwd_cli, static) = { |
| 463 | .path = "set bridge-domain forward", |
| 464 | .short_help = "set bridge-domain forward <bridge-domain-id> [disable]", |
| 465 | .function = bd_fwd, |
| 466 | }; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 467 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 468 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 469 | /** |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 470 | Set bridge-domain flood enable/disable. |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 471 | The CLI format is: |
| 472 | set bridge-domain flood <bd_index> [disable] |
| 473 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 474 | static clib_error_t * |
| 475 | bd_flood (vlib_main_t * vm, |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 476 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 477 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 478 | bd_main_t *bdm = &bd_main; |
| 479 | clib_error_t *error = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 480 | u32 bd_index, bd_id; |
| 481 | u32 enable; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 482 | uword *p; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 483 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 484 | if (!unformat (input, "%d", &bd_id)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 485 | { |
| 486 | error = clib_error_return (0, "expecting bridge-domain id but got `%U'", |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 487 | format_unformat_error, input); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 488 | goto done; |
| 489 | } |
| 490 | |
Jon Loeliger | 1c7d485 | 2017-05-02 11:06:23 -0500 | [diff] [blame] | 491 | if (bd_id == 0) |
| 492 | return clib_error_return (0, |
| 493 | "No operations on the default bridge domain are supported"); |
| 494 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 495 | p = hash_get (bdm->bd_index_by_bd_id, bd_id); |
| 496 | |
| 497 | if (p == 0) |
| 498 | return clib_error_return (0, "No such bridge domain %d", bd_id); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 499 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 500 | bd_index = p[0]; |
| 501 | |
| 502 | enable = 1; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 503 | if (unformat (input, "disable")) |
| 504 | { |
| 505 | enable = 0; |
| 506 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 507 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 508 | /* set the bridge domain flag */ |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 509 | bd_set_flags (vm, bd_index, L2_FLOOD, enable); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 510 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 511 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 512 | return error; |
| 513 | } |
| 514 | |
Billy McFall | 22aa3e9 | 2016-09-09 08:46:40 -0400 | [diff] [blame] | 515 | /*? |
| 516 | * Layer 2 flooding can be enabled and disabled on each |
| 517 | * interface and on each bridge-domain. Use this command to |
| 518 | * manage bridge-domains. It is enabled by default. |
| 519 | * |
| 520 | * @cliexpar |
| 521 | * Example of how to enable flooding (where 200 is the bridge-domain-id): |
| 522 | * @cliexcmd{set bridge-domain flood 200} |
| 523 | * Example of how to disable flooding (where 200 is the bridge-domain-id): |
| 524 | * @cliexcmd{set bridge-domain flood 200 disable} |
| 525 | ?*/ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 526 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 527 | VLIB_CLI_COMMAND (bd_flood_cli, static) = { |
| 528 | .path = "set bridge-domain flood", |
| 529 | .short_help = "set bridge-domain flood <bridge-domain-id> [disable]", |
| 530 | .function = bd_flood, |
| 531 | }; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 532 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 533 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 534 | /** |
Andrey "Zed" Zaikin | 701625b | 2018-04-18 17:07:07 +0300 | [diff] [blame] | 535 | Set bridge-domain unknown-unicast flood enable/disable. |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 536 | The CLI format is: |
| 537 | set bridge-domain uu-flood <bd_index> [disable] |
| 538 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 539 | static clib_error_t * |
| 540 | bd_uu_flood (vlib_main_t * vm, |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 541 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 542 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 543 | bd_main_t *bdm = &bd_main; |
| 544 | clib_error_t *error = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 545 | u32 bd_index, bd_id; |
| 546 | u32 enable; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 547 | uword *p; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 548 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 549 | if (!unformat (input, "%d", &bd_id)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 550 | { |
| 551 | error = clib_error_return (0, "expecting bridge-domain id but got `%U'", |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 552 | format_unformat_error, input); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 553 | goto done; |
| 554 | } |
| 555 | |
Jon Loeliger | 1c7d485 | 2017-05-02 11:06:23 -0500 | [diff] [blame] | 556 | if (bd_id == 0) |
| 557 | return clib_error_return (0, |
| 558 | "No operations on the default bridge domain are supported"); |
| 559 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 560 | p = hash_get (bdm->bd_index_by_bd_id, bd_id); |
| 561 | |
| 562 | if (p == 0) |
| 563 | return clib_error_return (0, "No such bridge domain %d", bd_id); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 564 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 565 | bd_index = p[0]; |
| 566 | |
| 567 | enable = 1; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 568 | if (unformat (input, "disable")) |
| 569 | { |
| 570 | enable = 0; |
| 571 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 572 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 573 | /* set the bridge domain flag */ |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 574 | bd_set_flags (vm, bd_index, L2_UU_FLOOD, enable); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 575 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 576 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 577 | return error; |
| 578 | } |
| 579 | |
Billy McFall | 22aa3e9 | 2016-09-09 08:46:40 -0400 | [diff] [blame] | 580 | /*? |
| 581 | * Layer 2 unknown-unicast flooding can be enabled and disabled on each |
| 582 | * bridge-domain. It is enabled by default. |
| 583 | * |
| 584 | * @cliexpar |
| 585 | * Example of how to enable unknown-unicast flooding (where 200 is the |
| 586 | * bridge-domain-id): |
| 587 | * @cliexcmd{set bridge-domain uu-flood 200} |
| 588 | * Example of how to disable unknown-unicast flooding (where 200 is the bridge-domain-id): |
| 589 | * @cliexcmd{set bridge-domain uu-flood 200 disable} |
| 590 | ?*/ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 591 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 592 | VLIB_CLI_COMMAND (bd_uu_flood_cli, static) = { |
| 593 | .path = "set bridge-domain uu-flood", |
| 594 | .short_help = "set bridge-domain uu-flood <bridge-domain-id> [disable]", |
| 595 | .function = bd_uu_flood, |
| 596 | }; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 597 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 598 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 599 | /** |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 600 | Set bridge-domain arp term enable/disable. |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 601 | The CLI format is: |
| 602 | set bridge-domain arp term <bridge-domain-id> [disable] |
| 603 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 604 | static clib_error_t * |
| 605 | bd_arp_term (vlib_main_t * vm, |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 606 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 607 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 608 | bd_main_t *bdm = &bd_main; |
| 609 | clib_error_t *error = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 610 | u32 bd_index, bd_id; |
| 611 | u32 enable; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 612 | uword *p; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 613 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 614 | if (!unformat (input, "%d", &bd_id)) |
| 615 | { |
| 616 | error = clib_error_return (0, "expecting bridge-domain id but got `%U'", |
| 617 | format_unformat_error, input); |
| 618 | goto done; |
| 619 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 620 | |
Jon Loeliger | 1c7d485 | 2017-05-02 11:06:23 -0500 | [diff] [blame] | 621 | if (bd_id == 0) |
| 622 | return clib_error_return (0, |
| 623 | "No operations on the default bridge domain are supported"); |
| 624 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 625 | p = hash_get (bdm->bd_index_by_bd_id, bd_id); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 626 | if (p) |
| 627 | bd_index = *p; |
| 628 | else |
| 629 | return clib_error_return (0, "No such bridge domain %d", bd_id); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 630 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 631 | enable = 1; |
| 632 | if (unformat (input, "disable")) |
| 633 | enable = 0; |
| 634 | |
| 635 | /* set the bridge domain flag */ |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 636 | bd_set_flags (vm, bd_index, L2_ARP_TERM, enable); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 637 | |
| 638 | done: |
| 639 | return error; |
| 640 | } |
| 641 | |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 642 | static clib_error_t * |
| 643 | bd_mac_age (vlib_main_t * vm, |
| 644 | unformat_input_t * input, vlib_cli_command_t * cmd) |
| 645 | { |
| 646 | bd_main_t *bdm = &bd_main; |
| 647 | clib_error_t *error = 0; |
| 648 | u32 bd_index, bd_id; |
| 649 | u32 age; |
| 650 | uword *p; |
| 651 | |
| 652 | if (!unformat (input, "%d", &bd_id)) |
| 653 | { |
| 654 | error = clib_error_return (0, "expecting bridge-domain id but got `%U'", |
| 655 | format_unformat_error, input); |
| 656 | goto done; |
| 657 | } |
| 658 | |
Jon Loeliger | 1c7d485 | 2017-05-02 11:06:23 -0500 | [diff] [blame] | 659 | if (bd_id == 0) |
| 660 | return clib_error_return (0, |
| 661 | "No operations on the default bridge domain are supported"); |
| 662 | |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 663 | p = hash_get (bdm->bd_index_by_bd_id, bd_id); |
| 664 | |
| 665 | if (p == 0) |
| 666 | return clib_error_return (0, "No such bridge domain %d", bd_id); |
| 667 | |
| 668 | bd_index = p[0]; |
| 669 | |
| 670 | if (!unformat (input, "%u", &age)) |
| 671 | { |
| 672 | error = |
| 673 | clib_error_return (0, "expecting ageing time in minutes but got `%U'", |
| 674 | format_unformat_error, input); |
| 675 | goto done; |
| 676 | } |
| 677 | |
| 678 | /* set the bridge domain flag */ |
| 679 | if (age > 255) |
| 680 | { |
| 681 | error = |
| 682 | clib_error_return (0, "mac aging time cannot be bigger than 255"); |
| 683 | goto done; |
| 684 | } |
| 685 | bd_set_mac_age (vm, bd_index, (u8) age); |
| 686 | |
| 687 | done: |
| 688 | return error; |
| 689 | } |
| 690 | |
| 691 | /*? |
| 692 | * Layer 2 mac aging can be enabled and disabled on each |
| 693 | * bridge-domain. Use this command to set or disable mac aging |
| 694 | * on specific bridge-domains. It is disabled by default. |
| 695 | * |
| 696 | * @cliexpar |
| 697 | * Example of how to set mac aging (where 200 is the bridge-domain-id and |
| 698 | * 5 is aging time in minutes): |
| 699 | * @cliexcmd{set bridge-domain mac-age 200 5} |
| 700 | * Example of how to disable mac aging (where 200 is the bridge-domain-id): |
| 701 | * @cliexcmd{set bridge-domain flood 200 0} |
| 702 | ?*/ |
| 703 | /* *INDENT-OFF* */ |
| 704 | VLIB_CLI_COMMAND (bd_mac_age_cli, static) = { |
| 705 | .path = "set bridge-domain mac-age", |
| 706 | .short_help = "set bridge-domain mac-age <bridge-domain-id> <mins>", |
| 707 | .function = bd_mac_age, |
| 708 | }; |
| 709 | /* *INDENT-ON* */ |
| 710 | |
Billy McFall | 22aa3e9 | 2016-09-09 08:46:40 -0400 | [diff] [blame] | 711 | /*? |
| 712 | * Modify whether or not an existing bridge-domain should terminate and respond |
| 713 | * to ARP Requests. ARP Termination is disabled by default. |
| 714 | * |
| 715 | * @cliexpar |
| 716 | * Example of how to enable ARP termination (where 200 is the bridge-domain-id): |
| 717 | * @cliexcmd{set bridge-domain arp term 200} |
| 718 | * Example of how to disable ARP termination (where 200 is the bridge-domain-id): |
| 719 | * @cliexcmd{set bridge-domain arp term 200 disable} |
| 720 | ?*/ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 721 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 722 | VLIB_CLI_COMMAND (bd_arp_term_cli, static) = { |
| 723 | .path = "set bridge-domain arp term", |
| 724 | .short_help = "set bridge-domain arp term <bridge-domain-id> [disable]", |
| 725 | .function = bd_arp_term, |
| 726 | }; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 727 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 728 | |
| 729 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 730 | /** |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 731 | * Add/delete IP address to MAC address mapping. |
| 732 | * |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 733 | * The clib hash implementation stores uword entries in the hash table. |
| 734 | * The hash table mac_by_ip4 is keyed via IP4 address and store the |
| 735 | * 6-byte MAC address directly in the hash table entry uword. |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 736 | * |
| 737 | * @warning This only works for 64-bit processor with 8-byte uword; |
Paul Vinciguerra | bdc0e6b | 2018-09-22 05:32:50 -0700 | [diff] [blame] | 738 | * which means this code *WILL NOT WORK* for a 32-bit processor with |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 739 | * 4-byte uword. |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 740 | */ |
| 741 | u32 |
| 742 | bd_add_del_ip_mac (u32 bd_index, |
Neale Ranns | 4d5b917 | 2018-10-24 02:57:49 -0700 | [diff] [blame] | 743 | ip46_type_t type, |
| 744 | const ip46_address_t * ip, |
| 745 | const mac_address_t * mac, u8 is_add) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 746 | { |
Eyal Bari | afc47aa | 2017-04-20 14:45:17 +0300 | [diff] [blame] | 747 | l2_bridge_domain_t *bd_cfg = l2input_bd_config (bd_index); |
Neale Ranns | 4d5b917 | 2018-10-24 02:57:49 -0700 | [diff] [blame] | 748 | u64 new_mac = mac_address_as_u64 (mac); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 749 | u64 *old_mac; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 750 | |
Neale Ranns | 4d5b917 | 2018-10-24 02:57:49 -0700 | [diff] [blame] | 751 | /* make sure uword is 8 bytes */ |
| 752 | ASSERT (sizeof (uword) == sizeof (u64)); |
Eyal Bari | afc47aa | 2017-04-20 14:45:17 +0300 | [diff] [blame] | 753 | ASSERT (bd_is_valid (bd_cfg)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 754 | |
Neale Ranns | 4d5b917 | 2018-10-24 02:57:49 -0700 | [diff] [blame] | 755 | if (IP46_TYPE_IP6 == type) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 756 | { |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 757 | ip6_address_t *ip6_addr_key; |
| 758 | hash_pair_t *hp; |
Neale Ranns | 4d5b917 | 2018-10-24 02:57:49 -0700 | [diff] [blame] | 759 | old_mac = (u64 *) hash_get_mem (bd_cfg->mac_by_ip6, &ip->ip6); |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 760 | if (is_add) |
| 761 | { |
Neale Ranns | 4d5b917 | 2018-10-24 02:57:49 -0700 | [diff] [blame] | 762 | if (old_mac == NULL) |
| 763 | { |
| 764 | /* new entry - allocate and create ip6 address key */ |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 765 | ip6_addr_key = clib_mem_alloc (sizeof (ip6_address_t)); |
Neale Ranns | 4d5b917 | 2018-10-24 02:57:49 -0700 | [diff] [blame] | 766 | clib_memcpy (ip6_addr_key, &ip->ip6, sizeof (ip6_address_t)); |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 767 | } |
| 768 | else if (*old_mac == new_mac) |
Neale Ranns | 4d5b917 | 2018-10-24 02:57:49 -0700 | [diff] [blame] | 769 | { |
| 770 | /* same mac entry already exist for ip6 address */ |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 771 | return 0; |
| 772 | } |
| 773 | else |
Neale Ranns | 4d5b917 | 2018-10-24 02:57:49 -0700 | [diff] [blame] | 774 | { |
| 775 | /* update mac for ip6 address */ |
| 776 | hp = hash_get_pair (bd_cfg->mac_by_ip6, &ip->ip6); |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 777 | ip6_addr_key = (ip6_address_t *) hp->key; |
| 778 | } |
| 779 | hash_set_mem (bd_cfg->mac_by_ip6, ip6_addr_key, new_mac); |
| 780 | } |
| 781 | else |
| 782 | { |
| 783 | if (old_mac && (*old_mac == new_mac)) |
| 784 | { |
Neale Ranns | 4d5b917 | 2018-10-24 02:57:49 -0700 | [diff] [blame] | 785 | hp = hash_get_pair (bd_cfg->mac_by_ip6, &ip->ip6); |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 786 | ip6_addr_key = (ip6_address_t *) hp->key; |
Neale Ranns | 4d5b917 | 2018-10-24 02:57:49 -0700 | [diff] [blame] | 787 | hash_unset_mem (bd_cfg->mac_by_ip6, &ip->ip6); |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 788 | clib_mem_free (ip6_addr_key); |
| 789 | } |
| 790 | else |
| 791 | return 1; |
| 792 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 793 | } |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 794 | else |
| 795 | { |
Neale Ranns | 4d5b917 | 2018-10-24 02:57:49 -0700 | [diff] [blame] | 796 | old_mac = (u64 *) hash_get (bd_cfg->mac_by_ip4, ip->ip4.as_u32); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 797 | if (is_add) |
| 798 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 799 | if (old_mac && (*old_mac == new_mac)) |
Neale Ranns | 4d5b917 | 2018-10-24 02:57:49 -0700 | [diff] [blame] | 800 | /* mac entry already exist */ |
| 801 | return 0; |
| 802 | hash_set (bd_cfg->mac_by_ip4, ip->ip4.as_u32, new_mac); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 803 | } |
| 804 | else |
| 805 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 806 | if (old_mac && (*old_mac == new_mac)) |
Neale Ranns | 4d5b917 | 2018-10-24 02:57:49 -0700 | [diff] [blame] | 807 | hash_unset (bd_cfg->mac_by_ip4, ip->ip4.as_u32); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 808 | else |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 809 | return 1; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 810 | } |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 811 | } |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 812 | return 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 813 | } |
| 814 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 815 | /** |
John Lo | e26c81f | 2019-01-07 15:16:33 -0500 | [diff] [blame] | 816 | * Flush IP address to MAC address mapping tables in a BD. |
| 817 | */ |
| 818 | void |
| 819 | bd_flush_ip_mac (u32 bd_index) |
| 820 | { |
| 821 | l2_bridge_domain_t *bd = l2input_bd_config (bd_index); |
| 822 | ASSERT (bd_is_valid (bd)); |
| 823 | bd_free_ip_mac_tables (bd); |
| 824 | bd->mac_by_ip4 = 0; |
| 825 | bd->mac_by_ip6 = |
| 826 | hash_create_mem (0, sizeof (ip6_address_t), sizeof (uword)); |
| 827 | } |
| 828 | |
| 829 | /** |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 830 | Set bridge-domain arp entry add/delete. |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 831 | The CLI format is: |
Billy McFall | 22aa3e9 | 2016-09-09 08:46:40 -0400 | [diff] [blame] | 832 | set bridge-domain arp entry <bridge-domain-id> <ip-addr> <mac-addr> [del] |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 833 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 834 | static clib_error_t * |
| 835 | bd_arp_entry (vlib_main_t * vm, |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 836 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 837 | { |
Neale Ranns | 4d5b917 | 2018-10-24 02:57:49 -0700 | [diff] [blame] | 838 | ip46_address_t ip_addr = ip46_address_initializer; |
| 839 | ip46_type_t type = IP46_TYPE_IP4; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 840 | bd_main_t *bdm = &bd_main; |
| 841 | clib_error_t *error = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 842 | u32 bd_index, bd_id; |
Neale Ranns | 4d5b917 | 2018-10-24 02:57:49 -0700 | [diff] [blame] | 843 | mac_address_t mac; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 844 | u8 is_add = 1; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 845 | uword *p; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 846 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 847 | if (!unformat (input, "%d", &bd_id)) |
| 848 | { |
| 849 | error = clib_error_return (0, "expecting bridge-domain id but got `%U'", |
| 850 | format_unformat_error, input); |
| 851 | goto done; |
| 852 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 853 | |
Jon Loeliger | 1c7d485 | 2017-05-02 11:06:23 -0500 | [diff] [blame] | 854 | if (bd_id == 0) |
| 855 | return clib_error_return (0, |
| 856 | "No operations on the default bridge domain are supported"); |
| 857 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 858 | p = hash_get (bdm->bd_index_by_bd_id, bd_id); |
| 859 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 860 | if (p) |
| 861 | bd_index = *p; |
| 862 | else |
| 863 | return clib_error_return (0, "No such bridge domain %d", bd_id); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 864 | |
Neale Ranns | 4d5b917 | 2018-10-24 02:57:49 -0700 | [diff] [blame] | 865 | if (unformat (input, "%U", unformat_ip4_address, &ip_addr.ip4)) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 866 | { |
Neale Ranns | 4d5b917 | 2018-10-24 02:57:49 -0700 | [diff] [blame] | 867 | type = IP46_TYPE_IP4; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 868 | } |
Neale Ranns | 4d5b917 | 2018-10-24 02:57:49 -0700 | [diff] [blame] | 869 | else if (unformat (input, "%U", unformat_ip6_address, &ip_addr.ip6)) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 870 | { |
Neale Ranns | 4d5b917 | 2018-10-24 02:57:49 -0700 | [diff] [blame] | 871 | type = IP46_TYPE_IP6; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 872 | } |
John Lo | e26c81f | 2019-01-07 15:16:33 -0500 | [diff] [blame] | 873 | else if (unformat (input, "del-all")) |
| 874 | { |
| 875 | bd_flush_ip_mac (bd_index); |
| 876 | goto done; |
| 877 | } |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 878 | else |
| 879 | { |
| 880 | error = clib_error_return (0, "expecting IP address but got `%U'", |
| 881 | format_unformat_error, input); |
| 882 | goto done; |
| 883 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 884 | |
Neale Ranns | 4d5b917 | 2018-10-24 02:57:49 -0700 | [diff] [blame] | 885 | if (!unformat (input, "%U", unformat_mac_address_t, &mac)) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 886 | { |
| 887 | error = clib_error_return (0, "expecting MAC address but got `%U'", |
| 888 | format_unformat_error, input); |
| 889 | goto done; |
| 890 | } |
| 891 | |
| 892 | if (unformat (input, "del")) |
| 893 | { |
| 894 | is_add = 0; |
| 895 | } |
| 896 | |
| 897 | /* set the bridge domain flagAdd IP-MAC entry into bridge domain */ |
Neale Ranns | 4d5b917 | 2018-10-24 02:57:49 -0700 | [diff] [blame] | 898 | if (bd_add_del_ip_mac (bd_index, type, &ip_addr, &mac, is_add)) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 899 | { |
| 900 | error = clib_error_return (0, "MAC %s for IP %U and MAC %U failed", |
| 901 | is_add ? "add" : "del", |
Neale Ranns | 4d5b917 | 2018-10-24 02:57:49 -0700 | [diff] [blame] | 902 | format_ip46_address, &ip_addr, IP46_TYPE_ANY, |
| 903 | format_mac_address_t, &mac); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 904 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 905 | |
| 906 | done: |
| 907 | return error; |
| 908 | } |
| 909 | |
Billy McFall | 22aa3e9 | 2016-09-09 08:46:40 -0400 | [diff] [blame] | 910 | /*? |
| 911 | * Add an ARP entry to an existing bridge-domain. |
| 912 | * |
| 913 | * @cliexpar |
| 914 | * Example of how to add an ARP entry (where 200 is the bridge-domain-id): |
| 915 | * @cliexcmd{set bridge-domain arp entry 200 192.168.72.45 52:54:00:3b:83:1a} |
| 916 | * Example of how to delete an ARP entry (where 200 is the bridge-domain-id): |
| 917 | * @cliexcmd{set bridge-domain arp entry 200 192.168.72.45 52:54:00:3b:83:1a del} |
| 918 | ?*/ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 919 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 920 | VLIB_CLI_COMMAND (bd_arp_entry_cli, static) = { |
| 921 | .path = "set bridge-domain arp entry", |
John Lo | e26c81f | 2019-01-07 15:16:33 -0500 | [diff] [blame] | 922 | .short_help = "set bridge-domain arp entry <bridge-domain-id> [<ip-addr> <mac-addr> [del] | del-all]", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 923 | .function = bd_arp_entry, |
| 924 | }; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 925 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 926 | |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 927 | static u8 * |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 928 | format_vtr (u8 * s, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 929 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 930 | u32 vtr_op = va_arg (*args, u32); |
| 931 | u32 dot1q = va_arg (*args, u32); |
| 932 | u32 tag1 = va_arg (*args, u32); |
| 933 | u32 tag2 = va_arg (*args, u32); |
| 934 | switch (vtr_op) |
| 935 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 936 | case L2_VTR_DISABLED: |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 937 | return format (s, "none"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 938 | case L2_VTR_PUSH_1: |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 939 | return format (s, "push-1 %s %d", dot1q ? "dot1q" : "dot1ad", tag1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 940 | case L2_VTR_PUSH_2: |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 941 | return format (s, "push-2 %s %d %d", dot1q ? "dot1q" : "dot1ad", tag1, |
| 942 | tag2); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 943 | case L2_VTR_POP_1: |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 944 | return format (s, "pop-1"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 945 | case L2_VTR_POP_2: |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 946 | return format (s, "pop-2"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 947 | case L2_VTR_TRANSLATE_1_1: |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 948 | return format (s, "trans-1-1 %s %d", dot1q ? "dot1q" : "dot1ad", tag1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 949 | case L2_VTR_TRANSLATE_1_2: |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 950 | return format (s, "trans-1-2 %s %d %d", dot1q ? "dot1q" : "dot1ad", |
| 951 | tag1, tag2); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 952 | case L2_VTR_TRANSLATE_2_1: |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 953 | return format (s, "trans-2-1 %s %d", dot1q ? "dot1q" : "dot1ad", tag1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 954 | case L2_VTR_TRANSLATE_2_2: |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 955 | return format (s, "trans-2-2 %s %d %d", dot1q ? "dot1q" : "dot1ad", |
| 956 | tag1, tag2); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 957 | default: |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 958 | return format (s, "none"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 959 | } |
| 960 | } |
| 961 | |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 962 | static u8 * |
| 963 | format_uu_cfg (u8 * s, va_list * args) |
| 964 | { |
| 965 | l2_bridge_domain_t *bd_config = va_arg (*args, l2_bridge_domain_t *); |
| 966 | |
| 967 | if (bd_config->feature_bitmap & L2INPUT_FEAT_UU_FWD) |
| 968 | return (format (s, "%U", format_vnet_sw_if_index_name_with_NA, |
| 969 | vnet_get_main (), bd_config->uu_fwd_sw_if_index)); |
| 970 | else if (bd_config->feature_bitmap & L2INPUT_FEAT_UU_FLOOD) |
| 971 | return (format (s, "flood")); |
| 972 | else |
| 973 | return (format (s, "drop")); |
| 974 | } |
| 975 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 976 | /** |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 977 | Show bridge-domain state. |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 978 | The CLI format is: |
| 979 | show bridge-domain [<bd_index>] |
| 980 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 981 | static clib_error_t * |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 982 | bd_show (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 983 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 984 | vnet_main_t *vnm = vnet_get_main (); |
| 985 | bd_main_t *bdm = &bd_main; |
| 986 | clib_error_t *error = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 987 | u32 bd_index = ~0; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 988 | l2_bridge_domain_t *bd_config; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 989 | u32 start, end; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 990 | u32 detail = 0; |
| 991 | u32 intf = 0; |
| 992 | u32 arp = 0; |
Jerome Tollet | 4830414 | 2017-09-05 12:13:22 +0100 | [diff] [blame] | 993 | u32 bd_tag = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 994 | u32 bd_id = ~0; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 995 | uword *p; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 996 | |
Jon Loeliger | 1c7d485 | 2017-05-02 11:06:23 -0500 | [diff] [blame] | 997 | start = 1; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 998 | end = vec_len (l2input_main.bd_configs); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 999 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1000 | if (unformat (input, "%d", &bd_id)) |
| 1001 | { |
| 1002 | if (unformat (input, "detail")) |
| 1003 | detail = 1; |
| 1004 | else if (unformat (input, "det")) |
| 1005 | detail = 1; |
| 1006 | if (unformat (input, "int")) |
| 1007 | intf = 1; |
| 1008 | if (unformat (input, "arp")) |
| 1009 | arp = 1; |
Jerome Tollet | 4830414 | 2017-09-05 12:13:22 +0100 | [diff] [blame] | 1010 | if (unformat (input, "bd-tag")) |
| 1011 | bd_tag = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1012 | |
Jon Loeliger | 1c7d485 | 2017-05-02 11:06:23 -0500 | [diff] [blame] | 1013 | if (bd_id == 0) |
| 1014 | return clib_error_return (0, |
| 1015 | "No operations on the default bridge domain are supported"); |
| 1016 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1017 | p = hash_get (bdm->bd_index_by_bd_id, bd_id); |
| 1018 | if (p) |
| 1019 | bd_index = *p; |
| 1020 | else |
| 1021 | return clib_error_return (0, "No such bridge domain %d", bd_id); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1022 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1023 | vec_validate (l2input_main.bd_configs, bd_index); |
| 1024 | bd_config = vec_elt_at_index (l2input_main.bd_configs, bd_index); |
| 1025 | if (bd_is_valid (bd_config)) |
| 1026 | { |
| 1027 | start = bd_index; |
| 1028 | end = start + 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1029 | } |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1030 | else |
| 1031 | { |
| 1032 | vlib_cli_output (vm, "bridge-domain %d not in use", bd_id); |
| 1033 | goto done; |
| 1034 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1035 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1036 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1037 | /* Show all bridge-domains that have been initialized */ |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 1038 | u32 printed = 0; |
| 1039 | u8 *as = 0; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1040 | for (bd_index = start; bd_index < end; bd_index++) |
| 1041 | { |
| 1042 | bd_config = vec_elt_at_index (l2input_main.bd_configs, bd_index); |
| 1043 | if (bd_is_valid (bd_config)) |
| 1044 | { |
| 1045 | if (!printed) |
| 1046 | { |
| 1047 | printed = 1; |
| 1048 | vlib_cli_output (vm, |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 1049 | "%=8s %=7s %=4s %=9s %=9s %=9s %=11s %=9s %=9s %=11s", |
John Lo | 9793477 | 2017-05-18 22:26:47 -0400 | [diff] [blame] | 1050 | "BD-ID", "Index", "BSN", "Age(min)", |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 1051 | "Learning", "U-Forwrd", "UU-Flood", |
| 1052 | "Flooding", "ARP-Term", "BVI-Intf"); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1053 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1054 | |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 1055 | if (bd_config->mac_age) |
| 1056 | as = format (as, "%d", bd_config->mac_age); |
| 1057 | else |
| 1058 | as = format (as, "off"); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1059 | vlib_cli_output (vm, |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 1060 | "%=8d %=7d %=4d %=9v %=9s %=9s %=11U %=9s %=9s %=11U", |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 1061 | bd_config->bd_id, bd_index, bd_config->seq_num, as, |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1062 | bd_config->feature_bitmap & L2INPUT_FEAT_LEARN ? |
| 1063 | "on" : "off", |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 1064 | bd_config->feature_bitmap & L2INPUT_FEAT_FWD ? |
| 1065 | "on" : "off", |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 1066 | format_uu_cfg, bd_config, |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1067 | bd_config->feature_bitmap & L2INPUT_FEAT_FLOOD ? |
| 1068 | "on" : "off", |
| 1069 | bd_config->feature_bitmap & L2INPUT_FEAT_ARP_TERM ? |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 1070 | "on" : "off", |
| 1071 | format_vnet_sw_if_index_name_with_NA, |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1072 | vnm, bd_config->bvi_sw_if_index); |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 1073 | vec_reset_length (as); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1074 | |
| 1075 | if (detail || intf) |
| 1076 | { |
| 1077 | /* Show all member interfaces */ |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 1078 | int i; |
| 1079 | vec_foreach_index (i, bd_config->members) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1080 | { |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 1081 | l2_flood_member_t *member = |
| 1082 | vec_elt_at_index (bd_config->members, i); |
Eyal Bari | 0f360dc | 2017-06-14 13:11:20 +0300 | [diff] [blame] | 1083 | u8 swif_seq_num = *l2fib_swif_seq_num (member->sw_if_index); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1084 | u32 vtr_opr, dot1q, tag1, tag2; |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 1085 | if (i == 0) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1086 | { |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 1087 | vlib_cli_output (vm, "\n%=30s%=7s%=5s%=5s%=5s%=9s%=30s", |
| 1088 | "Interface", "If-idx", "ISN", "SHG", |
| 1089 | "BVI", "TxFlood", "VLAN-Tag-Rewrite"); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1090 | } |
| 1091 | l2vtr_get (vm, vnm, member->sw_if_index, &vtr_opr, &dot1q, |
| 1092 | &tag1, &tag2); |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 1093 | vlib_cli_output (vm, "%=30U%=7d%=5d%=5d%=5s%=9s%=30U", |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1094 | format_vnet_sw_if_index_name, vnm, |
| 1095 | member->sw_if_index, member->sw_if_index, |
Eyal Bari | 0f360dc | 2017-06-14 13:11:20 +0300 | [diff] [blame] | 1096 | swif_seq_num, member->shg, |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1097 | member->flags & L2_FLOOD_MEMBER_BVI ? "*" : |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 1098 | "-", i < bd_config->flood_count ? "*" : "-", |
| 1099 | format_vtr, vtr_opr, dot1q, tag1, tag2); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1100 | } |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 1101 | if (~0 != bd_config->uu_fwd_sw_if_index) |
| 1102 | vlib_cli_output (vm, "%=30U%=7d%=5d%=5d%=5s%=9s%=30s", |
| 1103 | format_vnet_sw_if_index_name, vnm, |
| 1104 | bd_config->uu_fwd_sw_if_index, |
| 1105 | bd_config->uu_fwd_sw_if_index, |
| 1106 | 0, 0, "uu", "-", "None"); |
| 1107 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1108 | } |
| 1109 | |
| 1110 | if ((detail || arp) && |
| 1111 | (bd_config->feature_bitmap & L2INPUT_FEAT_ARP_TERM)) |
| 1112 | { |
| 1113 | u32 ip4_addr; |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 1114 | ip6_address_t *ip6_addr; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1115 | u64 mac_addr; |
| 1116 | vlib_cli_output (vm, |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 1117 | "\n IP4/IP6 to MAC table for ARP Termination"); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1118 | |
| 1119 | /* *INDENT-OFF* */ |
| 1120 | hash_foreach (ip4_addr, mac_addr, bd_config->mac_by_ip4, |
| 1121 | ({ |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 1122 | vlib_cli_output (vm, "%=40U => %=20U", |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1123 | format_ip4_address, &ip4_addr, |
| 1124 | format_ethernet_address, &mac_addr); |
| 1125 | })); |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 1126 | |
| 1127 | hash_foreach_mem (ip6_addr, mac_addr, bd_config->mac_by_ip6, |
| 1128 | ({ |
| 1129 | vlib_cli_output (vm, "%=40U => %=20U", |
| 1130 | format_ip6_address, ip6_addr, |
| 1131 | format_ethernet_address, &mac_addr); |
| 1132 | })); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1133 | /* *INDENT-ON* */ |
| 1134 | } |
Jerome Tollet | 4830414 | 2017-09-05 12:13:22 +0100 | [diff] [blame] | 1135 | |
| 1136 | if ((detail || bd_tag) && (bd_config->bd_tag)) |
| 1137 | { |
| 1138 | vlib_cli_output (vm, "\n BD-Tag: %s", bd_config->bd_tag); |
| 1139 | |
| 1140 | } |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1141 | } |
| 1142 | } |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 1143 | vec_free (as); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1144 | |
| 1145 | if (!printed) |
| 1146 | { |
| 1147 | vlib_cli_output (vm, "no bridge-domains in use"); |
| 1148 | } |
| 1149 | |
| 1150 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1151 | return error; |
| 1152 | } |
| 1153 | |
Billy McFall | 22aa3e9 | 2016-09-09 08:46:40 -0400 | [diff] [blame] | 1154 | /*? |
| 1155 | * Show a summary of all the bridge-domain instances or detailed view of a |
| 1156 | * single bridge-domain. Bridge-domains are created by adding an interface |
| 1157 | * to a bridge using the '<em>set interface l2 bridge</em>' command. |
| 1158 | * |
| 1159 | * @cliexpar |
| 1160 | * @parblock |
| 1161 | * Example of displaying all bridge-domains: |
| 1162 | * @cliexstart{show bridge-domain} |
| 1163 | * ID Index Learning U-Forwrd UU-Flood Flooding ARP-Term BVI-Intf |
| 1164 | * 0 0 off off off off off local0 |
| 1165 | * 200 1 on on on on off N/A |
| 1166 | * @cliexend |
| 1167 | * |
| 1168 | * Example of displaying details of a single bridge-domains: |
| 1169 | * @cliexstart{show bridge-domain 200 detail} |
| 1170 | * ID Index Learning U-Forwrd UU-Flood Flooding ARP-Term BVI-Intf |
| 1171 | * 200 1 on on on on off N/A |
| 1172 | * |
| 1173 | * Interface Index SHG BVI VLAN-Tag-Rewrite |
| 1174 | * GigabitEthernet0/8/0.200 3 0 - none |
| 1175 | * GigabitEthernet0/9/0.200 4 0 - none |
| 1176 | * @cliexend |
| 1177 | * @endparblock |
| 1178 | ?*/ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1179 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1180 | VLIB_CLI_COMMAND (bd_show_cli, static) = { |
| 1181 | .path = "show bridge-domain", |
Jerome Tollet | 4830414 | 2017-09-05 12:13:22 +0100 | [diff] [blame] | 1182 | .short_help = "show bridge-domain [bridge-domain-id [detail|int|arp|bd-tag]]", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1183 | .function = bd_show, |
| 1184 | }; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1185 | /* *INDENT-ON* */ |
| 1186 | |
Choonho Son | 0548079 | 2017-03-29 20:07:45 +0900 | [diff] [blame] | 1187 | int |
| 1188 | bd_add_del (l2_bridge_domain_add_del_args_t * a) |
| 1189 | { |
| 1190 | bd_main_t *bdm = &bd_main; |
| 1191 | vlib_main_t *vm = bdm->vlib_main; |
Choonho Son | 0548079 | 2017-03-29 20:07:45 +0900 | [diff] [blame] | 1192 | int rv = 0; |
| 1193 | |
Eyal Bari | b1352ed | 2017-04-07 23:14:17 +0300 | [diff] [blame] | 1194 | u32 bd_index = bd_find_index (bdm, a->bd_id); |
Choonho Son | 0548079 | 2017-03-29 20:07:45 +0900 | [diff] [blame] | 1195 | if (a->is_add) |
| 1196 | { |
Eyal Bari | b1352ed | 2017-04-07 23:14:17 +0300 | [diff] [blame] | 1197 | if (bd_index != ~0) |
| 1198 | return VNET_API_ERROR_BD_ALREADY_EXISTS; |
John Lo | 9793477 | 2017-05-18 22:26:47 -0400 | [diff] [blame] | 1199 | if (a->bd_id > L2_BD_ID_MAX) |
| 1200 | return VNET_API_ERROR_BD_ID_EXCEED_MAX; |
Eyal Bari | b1352ed | 2017-04-07 23:14:17 +0300 | [diff] [blame] | 1201 | bd_index = bd_add_bd_index (bdm, a->bd_id); |
Choonho Son | 0548079 | 2017-03-29 20:07:45 +0900 | [diff] [blame] | 1202 | |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 1203 | bd_flags_t enable_flags = 0, disable_flags = 0; |
Choonho Son | 0548079 | 2017-03-29 20:07:45 +0900 | [diff] [blame] | 1204 | if (a->flood) |
| 1205 | enable_flags |= L2_FLOOD; |
| 1206 | else |
| 1207 | disable_flags |= L2_FLOOD; |
| 1208 | |
| 1209 | if (a->uu_flood) |
| 1210 | enable_flags |= L2_UU_FLOOD; |
| 1211 | else |
| 1212 | disable_flags |= L2_UU_FLOOD; |
| 1213 | |
| 1214 | if (a->forward) |
| 1215 | enable_flags |= L2_FWD; |
| 1216 | else |
| 1217 | disable_flags |= L2_FWD; |
| 1218 | |
| 1219 | if (a->learn) |
| 1220 | enable_flags |= L2_LEARN; |
| 1221 | else |
| 1222 | disable_flags |= L2_LEARN; |
| 1223 | |
| 1224 | if (a->arp_term) |
| 1225 | enable_flags |= L2_ARP_TERM; |
| 1226 | else |
| 1227 | disable_flags |= L2_ARP_TERM; |
| 1228 | |
| 1229 | if (enable_flags) |
| 1230 | bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */ ); |
| 1231 | |
| 1232 | if (disable_flags) |
| 1233 | bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */ ); |
| 1234 | |
| 1235 | bd_set_mac_age (vm, bd_index, a->mac_age); |
Jerome Tollet | 4830414 | 2017-09-05 12:13:22 +0100 | [diff] [blame] | 1236 | |
| 1237 | if (a->bd_tag) |
| 1238 | bd_set_bd_tag (vm, bd_index, a->bd_tag); |
| 1239 | |
Choonho Son | 0548079 | 2017-03-29 20:07:45 +0900 | [diff] [blame] | 1240 | } |
| 1241 | else |
Eyal Bari | b1352ed | 2017-04-07 23:14:17 +0300 | [diff] [blame] | 1242 | { |
| 1243 | if (bd_index == ~0) |
| 1244 | return VNET_API_ERROR_NO_SUCH_ENTRY; |
Jon Loeliger | 1c7d485 | 2017-05-02 11:06:23 -0500 | [diff] [blame] | 1245 | if (bd_index == 0) |
| 1246 | return VNET_API_ERROR_BD_NOT_MODIFIABLE; |
Eyal Bari | b1352ed | 2017-04-07 23:14:17 +0300 | [diff] [blame] | 1247 | if (vec_len (l2input_main.bd_configs[bd_index].members)) |
| 1248 | return VNET_API_ERROR_BD_IN_USE; |
| 1249 | rv = bd_delete (bdm, bd_index); |
| 1250 | } |
Choonho Son | 0548079 | 2017-03-29 20:07:45 +0900 | [diff] [blame] | 1251 | |
| 1252 | return rv; |
| 1253 | } |
| 1254 | |
| 1255 | /** |
| 1256 | Create or delete bridge-domain. |
Choonho Son | 5ee51f8 | 2017-04-05 19:09:52 +0900 | [diff] [blame] | 1257 | The CLI format: |
Jerome Tollet | 50570ec | 2017-09-14 12:53:56 +0100 | [diff] [blame] | 1258 | create bridge-domain <bd_index> [learn <0|1>] [forward <0|1>] [uu-flood <0|1>] [flood <0|1>] |
| 1259 | [arp-term <0|1>] [mac-age <nn>] [bd-tag <tag>] [del] |
Choonho Son | 0548079 | 2017-03-29 20:07:45 +0900 | [diff] [blame] | 1260 | */ |
| 1261 | |
| 1262 | static clib_error_t * |
| 1263 | bd_add_del_command_fn (vlib_main_t * vm, unformat_input_t * input, |
| 1264 | vlib_cli_command_t * cmd) |
| 1265 | { |
| 1266 | unformat_input_t _line_input, *line_input = &_line_input; |
| 1267 | clib_error_t *error = 0; |
| 1268 | u8 is_add = 1; |
| 1269 | u32 bd_id = ~0; |
Choonho Son | 5ee51f8 | 2017-04-05 19:09:52 +0900 | [diff] [blame] | 1270 | u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0; |
Choonho Son | 0548079 | 2017-03-29 20:07:45 +0900 | [diff] [blame] | 1271 | u32 mac_age = 0; |
Jerome Tollet | 4830414 | 2017-09-05 12:13:22 +0100 | [diff] [blame] | 1272 | u8 *bd_tag = NULL; |
Choonho Son | 0548079 | 2017-03-29 20:07:45 +0900 | [diff] [blame] | 1273 | l2_bridge_domain_add_del_args_t _a, *a = &_a; |
| 1274 | int rv; |
| 1275 | |
| 1276 | /* Get a line of input. */ |
| 1277 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 1278 | return 0; |
| 1279 | |
| 1280 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 1281 | { |
| 1282 | if (unformat (line_input, "%d", &bd_id)) |
| 1283 | ; |
| 1284 | else if (unformat (line_input, "flood %d", &flood)) |
| 1285 | ; |
| 1286 | else if (unformat (line_input, "uu-flood %d", &uu_flood)) |
| 1287 | ; |
| 1288 | else if (unformat (line_input, "forward %d", &forward)) |
| 1289 | ; |
Choonho Son | 5ee51f8 | 2017-04-05 19:09:52 +0900 | [diff] [blame] | 1290 | else if (unformat (line_input, "learn %d", &learn)) |
| 1291 | ; |
Choonho Son | 0548079 | 2017-03-29 20:07:45 +0900 | [diff] [blame] | 1292 | else if (unformat (line_input, "arp-term %d", &arp_term)) |
| 1293 | ; |
| 1294 | else if (unformat (line_input, "mac-age %d", &mac_age)) |
| 1295 | ; |
Jerome Tollet | 4830414 | 2017-09-05 12:13:22 +0100 | [diff] [blame] | 1296 | else if (unformat (line_input, "bd-tag %s", &bd_tag)) |
| 1297 | ; |
Choonho Son | 0548079 | 2017-03-29 20:07:45 +0900 | [diff] [blame] | 1298 | else if (unformat (line_input, "del")) |
| 1299 | { |
| 1300 | is_add = 0; |
| 1301 | flood = uu_flood = forward = learn = 0; |
| 1302 | } |
| 1303 | else |
| 1304 | break; |
| 1305 | } |
| 1306 | |
| 1307 | if (bd_id == ~0) |
| 1308 | { |
| 1309 | error = clib_error_return (0, "bridge-domain-id not specified"); |
| 1310 | goto done; |
| 1311 | } |
| 1312 | |
Jon Loeliger | 1c7d485 | 2017-05-02 11:06:23 -0500 | [diff] [blame] | 1313 | if (bd_id == 0) |
| 1314 | { |
| 1315 | error = clib_error_return (0, "bridge domain 0 can not be modified"); |
| 1316 | goto done; |
| 1317 | } |
| 1318 | |
Choonho Son | 0548079 | 2017-03-29 20:07:45 +0900 | [diff] [blame] | 1319 | if (mac_age > 255) |
| 1320 | { |
| 1321 | error = clib_error_return (0, "mac age must be less than 256"); |
| 1322 | goto done; |
| 1323 | } |
Jerome Tollet | 4830414 | 2017-09-05 12:13:22 +0100 | [diff] [blame] | 1324 | if ((bd_tag) && (strlen ((char *) bd_tag) > 63)) |
| 1325 | { |
| 1326 | error = clib_error_return (0, "bd-tag cannot be longer than 63"); |
| 1327 | goto done; |
| 1328 | } |
Choonho Son | 0548079 | 2017-03-29 20:07:45 +0900 | [diff] [blame] | 1329 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 1330 | clib_memset (a, 0, sizeof (*a)); |
Choonho Son | 0548079 | 2017-03-29 20:07:45 +0900 | [diff] [blame] | 1331 | a->is_add = is_add; |
| 1332 | a->bd_id = bd_id; |
| 1333 | a->flood = (u8) flood; |
| 1334 | a->uu_flood = (u8) uu_flood; |
| 1335 | a->forward = (u8) forward; |
| 1336 | a->learn = (u8) learn; |
| 1337 | a->arp_term = (u8) arp_term; |
| 1338 | a->mac_age = (u8) mac_age; |
Jerome Tollet | 4830414 | 2017-09-05 12:13:22 +0100 | [diff] [blame] | 1339 | a->bd_tag = bd_tag; |
Choonho Son | 0548079 | 2017-03-29 20:07:45 +0900 | [diff] [blame] | 1340 | |
| 1341 | rv = bd_add_del (a); |
| 1342 | |
| 1343 | switch (rv) |
| 1344 | { |
| 1345 | case 0: |
| 1346 | if (is_add) |
| 1347 | vlib_cli_output (vm, "bridge-domain %d", bd_id); |
| 1348 | break; |
Eyal Bari | b1352ed | 2017-04-07 23:14:17 +0300 | [diff] [blame] | 1349 | case VNET_API_ERROR_BD_IN_USE: |
| 1350 | error = clib_error_return (0, "bridge domain in use - remove members"); |
| 1351 | goto done; |
Choonho Son | 0548079 | 2017-03-29 20:07:45 +0900 | [diff] [blame] | 1352 | case VNET_API_ERROR_NO_SUCH_ENTRY: |
John Lo | 9793477 | 2017-05-18 22:26:47 -0400 | [diff] [blame] | 1353 | error = clib_error_return (0, "bridge domain ID does not exist"); |
Choonho Son | 0548079 | 2017-03-29 20:07:45 +0900 | [diff] [blame] | 1354 | goto done; |
Jon Loeliger | 1c7d485 | 2017-05-02 11:06:23 -0500 | [diff] [blame] | 1355 | case VNET_API_ERROR_BD_NOT_MODIFIABLE: |
| 1356 | error = clib_error_return (0, "bridge domain 0 can not be modified"); |
| 1357 | goto done; |
John Lo | 9793477 | 2017-05-18 22:26:47 -0400 | [diff] [blame] | 1358 | case VNET_API_ERROR_BD_ID_EXCEED_MAX: |
| 1359 | error = clib_error_return (0, "bridge domain ID exceed 16M limit"); |
| 1360 | goto done; |
Choonho Son | 0548079 | 2017-03-29 20:07:45 +0900 | [diff] [blame] | 1361 | default: |
| 1362 | error = clib_error_return (0, "bd_add_del returned %d", rv); |
| 1363 | goto done; |
| 1364 | } |
| 1365 | |
| 1366 | done: |
Jerome Tollet | 4830414 | 2017-09-05 12:13:22 +0100 | [diff] [blame] | 1367 | vec_free (bd_tag); |
Choonho Son | 0548079 | 2017-03-29 20:07:45 +0900 | [diff] [blame] | 1368 | unformat_free (line_input); |
| 1369 | |
| 1370 | return error; |
| 1371 | } |
| 1372 | |
| 1373 | |
| 1374 | /*? |
| 1375 | * Create/Delete bridge-domain instance |
| 1376 | * |
| 1377 | * @cliexpar |
| 1378 | * @parblock |
| 1379 | * Example of creating bridge-domain 1: |
| 1380 | * @cliexstart{create bridge-domain 1} |
| 1381 | * bridge-domain 1 |
| 1382 | * @cliexend |
| 1383 | * |
| 1384 | * Example of creating bridge-domain 2 with enabling arp-term, mac-age 60: |
| 1385 | * @cliexstart{create bridge-domain 2 arp-term 1 mac-age 60} |
| 1386 | * bridge-domain 2 |
| 1387 | * |
| 1388 | * vpp# show bridge-domain |
| 1389 | * ID Index BSN Age(min) Learning U-Forwrd UU-Flood Flooding ARP-Term BVI-Intf |
| 1390 | * 0 0 0 off off off off off off local0 |
| 1391 | * 1 1 0 off on on off on off N/A |
| 1392 | * 2 2 0 60 on on off on on N/A |
| 1393 | * |
| 1394 | * @cliexend |
| 1395 | * |
| 1396 | * Example of delete bridge-domain 1: |
| 1397 | * @cliexstart{create bridge-domain 1 del} |
| 1398 | * @cliexend |
| 1399 | * @endparblock |
| 1400 | ?*/ |
| 1401 | |
| 1402 | /* *INDENT-OFF* */ |
| 1403 | VLIB_CLI_COMMAND (bd_create_cli, static) = { |
| 1404 | .path = "create bridge-domain", |
| 1405 | .short_help = "create bridge-domain <bridge-domain-id>" |
| 1406 | " [learn <0|1>] [forward <0|1>] [uu-flood <0|1>] [flood <0|1>] [arp-term <0|1>]" |
Jerome Tollet | 4830414 | 2017-09-05 12:13:22 +0100 | [diff] [blame] | 1407 | " [mac-age <nn>] [bd-tag <tag>] [del]", |
Choonho Son | 0548079 | 2017-03-29 20:07:45 +0900 | [diff] [blame] | 1408 | .function = bd_add_del_command_fn, |
| 1409 | }; |
| 1410 | /* *INDENT-ON* */ |
| 1411 | |
| 1412 | |
| 1413 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1414 | /* |
| 1415 | * fd.io coding-style-patch-verification: ON |
| 1416 | * |
| 1417 | * Local Variables: |
| 1418 | * eval: (c-set-style "gnu") |
| 1419 | * End: |
| 1420 | */ |