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