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