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