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