Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * l2_bd.h : layer 2 bridge domain |
| 3 | * |
| 4 | * Copyright (c) 2013 Cisco and/or its affiliates. |
Laszlo Kiraly | 0f8f435 | 2022-09-16 13:20:07 +0200 | [diff] [blame] | 5 | * Copyright (c) 2022 Nordix Foundation. |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at: |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | */ |
| 18 | |
| 19 | #ifndef included_l2bd_h |
| 20 | #define included_l2bd_h |
| 21 | |
| 22 | #include <vlib/vlib.h> |
| 23 | #include <vnet/vnet.h> |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 24 | #include <vnet/ip/ip46_address.h> |
Neale Ranns | 4d5b917 | 2018-10-24 02:57:49 -0700 | [diff] [blame] | 25 | #include <vnet/ethernet/mac_address.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 26 | |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 27 | typedef enum l2_bd_port_type_t_ |
| 28 | { |
| 29 | L2_BD_PORT_TYPE_NORMAL = 0, |
| 30 | L2_BD_PORT_TYPE_BVI = 1, |
| 31 | L2_BD_PORT_TYPE_UU_FWD = 2, |
| 32 | } l2_bd_port_type_t; |
| 33 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 34 | typedef struct |
| 35 | { |
| 36 | /* hash bd_id -> bd_index */ |
| 37 | uword *bd_index_by_bd_id; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 38 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 39 | /* Busy bd_index bitmap */ |
| 40 | uword *bd_index_bitmap; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 41 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 42 | /* convenience */ |
| 43 | vlib_main_t *vlib_main; |
| 44 | vnet_main_t *vnet_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 45 | } bd_main_t; |
| 46 | |
Eyal Bari | 942402b | 2017-07-26 11:57:04 +0300 | [diff] [blame] | 47 | extern bd_main_t bd_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 48 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 49 | /* Bridge domain member */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 50 | |
| 51 | #define L2_FLOOD_MEMBER_NORMAL 0 |
| 52 | #define L2_FLOOD_MEMBER_BVI 1 |
| 53 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 54 | typedef struct |
| 55 | { |
| 56 | u32 sw_if_index; /* the output L2 interface */ |
| 57 | u8 flags; /* 0=normal, 1=bvi */ |
| 58 | u8 shg; /* split horizon group number */ |
| 59 | u16 spare; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 60 | } l2_flood_member_t; |
| 61 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 62 | /* Per-bridge domain configuration */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 63 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 64 | typedef struct |
| 65 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 66 | /* |
| 67 | * Contains bit enables for flooding, learning, and forwarding. |
| 68 | * All other feature bits should always be set. |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 69 | */ |
| 70 | u32 feature_bitmap; |
| 71 | /* |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 72 | * identity of the bridge-domain's BVI interface |
| 73 | * set to ~0 if there is no BVI |
| 74 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 75 | u32 bvi_sw_if_index; |
| 76 | |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 77 | /* |
| 78 | * identity of the bridge-domain's UU flood interface |
| 79 | * set to ~0 if there is no such configuration |
| 80 | */ |
| 81 | u32 uu_fwd_sw_if_index; |
| 82 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 83 | /* bridge domain id, not to be confused with bd_index */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 84 | u32 bd_id; |
| 85 | |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 86 | /* Vector of member ports */ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 87 | l2_flood_member_t *members; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 88 | |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 89 | /* First flood_count member ports are flooded */ |
| 90 | u32 flood_count; |
| 91 | |
| 92 | /* Tunnel Master (Multicast vxlan) are always flooded */ |
| 93 | u32 tun_master_count; |
| 94 | |
| 95 | /* Tunnels (Unicast vxlan) are flooded if there are no masters */ |
| 96 | u32 tun_normal_count; |
| 97 | |
Neale Ranns | 87dad11 | 2018-04-09 01:53:01 -0700 | [diff] [blame] | 98 | /* Interface on which packets are not flooded */ |
| 99 | u32 no_flood_count; |
| 100 | |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 101 | /* hash ip4/ip6 -> mac for arp/nd termination */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 102 | uword *mac_by_ip4; |
| 103 | uword *mac_by_ip6; |
| 104 | |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 105 | /* mac aging */ |
| 106 | u8 mac_age; |
| 107 | |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 108 | /* sequence number for bridge domain based flush of MACs */ |
| 109 | u8 seq_num; |
| 110 | |
Jerome Tollet | 4830414 | 2017-09-05 12:13:22 +0100 | [diff] [blame] | 111 | /* Bridge domain tag (C string NULL terminated) */ |
| 112 | u8 *bd_tag; |
| 113 | |
Jerome Tollet | 5f93e3b | 2020-12-18 09:44:24 +0100 | [diff] [blame] | 114 | /* Maximum number of learned entries */ |
| 115 | u32 learn_limit; |
| 116 | |
| 117 | /* Current number of learned entries */ |
| 118 | u32 learn_count; |
| 119 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 120 | } l2_bridge_domain_t; |
| 121 | |
John Lo | 9793477 | 2017-05-18 22:26:47 -0400 | [diff] [blame] | 122 | /* Limit Bridge Domain ID to 24 bits to match 24-bit VNI range */ |
| 123 | #define L2_BD_ID_MAX ((1<<24)-1) |
| 124 | |
Choonho Son | 0548079 | 2017-03-29 20:07:45 +0900 | [diff] [blame] | 125 | typedef struct |
| 126 | { |
| 127 | u32 bd_id; |
| 128 | u8 flood; |
| 129 | u8 uu_flood; |
| 130 | u8 forward; |
| 131 | u8 learn; |
| 132 | u8 arp_term; |
Mohsin Kazmi | 5e6f734 | 2019-04-05 17:40:20 +0200 | [diff] [blame] | 133 | u8 arp_ufwd; |
Choonho Son | 0548079 | 2017-03-29 20:07:45 +0900 | [diff] [blame] | 134 | u8 mac_age; |
Jerome Tollet | 4830414 | 2017-09-05 12:13:22 +0100 | [diff] [blame] | 135 | u8 *bd_tag; |
Choonho Son | 0548079 | 2017-03-29 20:07:45 +0900 | [diff] [blame] | 136 | u8 is_add; |
| 137 | } l2_bridge_domain_add_del_args_t; |
| 138 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 139 | /* Return 1 if bridge domain has been initialized */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 140 | always_inline u32 |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 141 | bd_is_valid (l2_bridge_domain_t * bd_config) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 142 | { |
| 143 | return (bd_config->feature_bitmap != 0); |
| 144 | } |
| 145 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 146 | /* Init bridge domain if not done already */ |
| 147 | void bd_validate (l2_bridge_domain_t * bd_config); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 148 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 149 | void |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 150 | 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] | 151 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 152 | u32 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] | 153 | |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 154 | typedef enum bd_flags_t_ |
| 155 | { |
| 156 | L2_NONE = 0, |
| 157 | L2_LEARN = (1 << 0), |
| 158 | L2_FWD = (1 << 1), |
| 159 | L2_FLOOD = (1 << 2), |
| 160 | L2_UU_FLOOD = (1 << 3), |
| 161 | L2_ARP_TERM = (1 << 4), |
Mohsin Kazmi | 5e6f734 | 2019-04-05 17:40:20 +0200 | [diff] [blame] | 162 | L2_ARP_UFWD = (1 << 5), |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 163 | } bd_flags_t; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 164 | |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 165 | u32 bd_set_flags (vlib_main_t * vm, u32 bd_index, bd_flags_t flags, |
| 166 | u32 enable); |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 167 | void bd_set_mac_age (vlib_main_t * vm, u32 bd_index, u8 age); |
Jerome Tollet | 5f93e3b | 2020-12-18 09:44:24 +0100 | [diff] [blame] | 168 | void bd_set_learn_limit (vlib_main_t *vm, u32 bd_index, u32 learn_limit); |
Eyal Bari | b1352ed | 2017-04-07 23:14:17 +0300 | [diff] [blame] | 169 | int bd_add_del (l2_bridge_domain_add_del_args_t * args); |
Laszlo Kiraly | 0f8f435 | 2022-09-16 13:20:07 +0200 | [diff] [blame] | 170 | u32 bd_get_unused_id (void); |
Eyal Bari | b1352ed | 2017-04-07 23:14:17 +0300 | [diff] [blame] | 171 | /** |
| 172 | * \brief Get a bridge domain. |
| 173 | * |
| 174 | * Get a bridge domain with the given bridge domain ID. |
| 175 | * |
| 176 | * \param bdm bd_main pointer. |
| 177 | * \param bd_id The bridge domain ID |
| 178 | * \return The bridge domain index in \c l2input_main->l2_bridge_domain_t vector. |
| 179 | */ |
| 180 | u32 bd_find_index (bd_main_t * bdm, u32 bd_id); |
| 181 | |
| 182 | /** |
| 183 | * \brief Create a bridge domain. |
| 184 | * |
| 185 | * Create a bridge domain with the given bridge domain ID |
| 186 | * |
| 187 | * \param bdm bd_main pointer. |
| 188 | * \return The bridge domain index in \c l2input_main->l2_bridge_domain_t vector. |
| 189 | */ |
| 190 | u32 bd_add_bd_index (bd_main_t * bdm, u32 bd_id); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 191 | |
Pierre Pfister | 530bd8e | 2016-05-10 17:11:22 +0100 | [diff] [blame] | 192 | /** |
| 193 | * \brief Get or create a bridge domain. |
| 194 | * |
Eyal Bari | b1352ed | 2017-04-07 23:14:17 +0300 | [diff] [blame] | 195 | * Get a bridge domain with the given bridge domain ID, if one exists, otherwise |
| 196 | * create one with the given ID, or the first unused ID if the given ID is ~0.. |
Pierre Pfister | 530bd8e | 2016-05-10 17:11:22 +0100 | [diff] [blame] | 197 | * |
| 198 | * \param bdm bd_main pointer. |
Eyal Bari | b1352ed | 2017-04-07 23:14:17 +0300 | [diff] [blame] | 199 | * \param bd_id The bridge domain ID |
Pierre Pfister | 530bd8e | 2016-05-10 17:11:22 +0100 | [diff] [blame] | 200 | * \return The bridge domain index in \c l2input_main->l2_bridge_domain_t vector. |
| 201 | */ |
Eyal Bari | b1352ed | 2017-04-07 23:14:17 +0300 | [diff] [blame] | 202 | static inline u32 |
| 203 | bd_find_or_add_bd_index (bd_main_t * bdm, u32 bd_id) |
| 204 | { |
| 205 | u32 bd_index = bd_find_index (bdm, bd_id); |
| 206 | if (bd_index == ~0) |
| 207 | return bd_add_bd_index (bdm, bd_id); |
| 208 | return bd_index; |
| 209 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 210 | |
Neale Ranns | 47a3d99 | 2020-09-29 15:38:51 +0000 | [diff] [blame] | 211 | /** |
| 212 | * \brief Walk all the input interfaces in the BD |
| 213 | */ |
| 214 | typedef walk_rc_t (*bd_input_walk_fn_t) (u32 bd_index, u32 sw_if_index); |
| 215 | |
| 216 | u32 bd_input_walk (u32 bd_index, bd_input_walk_fn_t fn, void *data); |
| 217 | |
| 218 | l2_bridge_domain_t *bd_get (u32 bd_index); |
| 219 | l2_bridge_domain_t *bd_get_by_table_id (u32 table_id); |
| 220 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 221 | u32 bd_add_del_ip_mac (u32 bd_index, |
Neale Ranns | 4d5b917 | 2018-10-24 02:57:49 -0700 | [diff] [blame] | 222 | ip46_type_t type, |
| 223 | const ip46_address_t * ip_addr, |
| 224 | const mac_address_t * mac, u8 is_add); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 225 | |
John Lo | e26c81f | 2019-01-07 15:16:33 -0500 | [diff] [blame] | 226 | void bd_flush_ip_mac (u32 bd_index); |
| 227 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 228 | #endif |
| 229 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 230 | /* |
| 231 | * fd.io coding-style-patch-verification: ON |
| 232 | * |
| 233 | * Local Variables: |
| 234 | * eval: (c-set-style "gnu") |
| 235 | * End: |
| 236 | */ |