2 * l2_bd.h : layer 2 bridge domain
4 * Copyright (c) 2013 Cisco and/or its affiliates.
5 * Copyright (c) 2022 Nordix Foundation.
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:
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #ifndef included_l2bd_h
20 #define included_l2bd_h
22 #include <vlib/vlib.h>
23 #include <vnet/vnet.h>
24 #include <vnet/ip/ip46_address.h>
25 #include <vnet/ethernet/mac_address.h>
27 typedef enum l2_bd_port_type_t_
29 L2_BD_PORT_TYPE_NORMAL = 0,
30 L2_BD_PORT_TYPE_BVI = 1,
31 L2_BD_PORT_TYPE_UU_FWD = 2,
36 /* hash bd_id -> bd_index */
37 uword *bd_index_by_bd_id;
39 /* Busy bd_index bitmap */
40 uword *bd_index_bitmap;
43 vlib_main_t *vlib_main;
44 vnet_main_t *vnet_main;
47 extern bd_main_t bd_main;
49 /* Bridge domain member */
51 #define L2_FLOOD_MEMBER_NORMAL 0
52 #define L2_FLOOD_MEMBER_BVI 1
56 u32 sw_if_index; /* the output L2 interface */
57 u8 flags; /* 0=normal, 1=bvi */
58 u8 shg; /* split horizon group number */
62 /* Per-bridge domain configuration */
67 * Contains bit enables for flooding, learning, and forwarding.
68 * All other feature bits should always be set.
72 * identity of the bridge-domain's BVI interface
73 * set to ~0 if there is no BVI
78 * identity of the bridge-domain's UU flood interface
79 * set to ~0 if there is no such configuration
81 u32 uu_fwd_sw_if_index;
83 /* bridge domain id, not to be confused with bd_index */
86 /* Vector of member ports */
87 l2_flood_member_t *members;
89 /* First flood_count member ports are flooded */
92 /* Tunnel Master (Multicast vxlan) are always flooded */
95 /* Tunnels (Unicast vxlan) are flooded if there are no masters */
98 /* Interface on which packets are not flooded */
101 /* hash ip4/ip6 -> mac for arp/nd termination */
108 /* sequence number for bridge domain based flush of MACs */
111 /* Bridge domain tag (C string NULL terminated) */
114 /* Maximum number of learned entries */
117 /* Current number of learned entries */
120 } l2_bridge_domain_t;
122 /* Limit Bridge Domain ID to 24 bits to match 24-bit VNI range */
123 #define L2_BD_ID_MAX ((1<<24)-1)
137 } l2_bridge_domain_add_del_args_t;
139 /* Return 1 if bridge domain has been initialized */
141 bd_is_valid (l2_bridge_domain_t * bd_config)
143 return (bd_config->feature_bitmap != 0);
146 /* Init bridge domain if not done already */
147 void bd_validate (l2_bridge_domain_t * bd_config);
150 bd_add_member (l2_bridge_domain_t * bd_config, l2_flood_member_t * member);
152 u32 bd_remove_member (l2_bridge_domain_t * bd_config, u32 sw_if_index);
154 typedef enum bd_flags_t_
160 L2_UU_FLOOD = (1 << 3),
161 L2_ARP_TERM = (1 << 4),
162 L2_ARP_UFWD = (1 << 5),
165 u32 bd_set_flags (vlib_main_t * vm, u32 bd_index, bd_flags_t flags,
167 void bd_set_mac_age (vlib_main_t * vm, u32 bd_index, u8 age);
168 void bd_set_learn_limit (vlib_main_t *vm, u32 bd_index, u32 learn_limit);
169 int bd_add_del (l2_bridge_domain_add_del_args_t * args);
170 u32 bd_get_unused_id (void);
172 * \brief Get a bridge domain.
174 * Get a bridge domain with the given bridge domain ID.
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.
180 u32 bd_find_index (bd_main_t * bdm, u32 bd_id);
183 * \brief Create a bridge domain.
185 * Create a bridge domain with the given bridge domain ID
187 * \param bdm bd_main pointer.
188 * \return The bridge domain index in \c l2input_main->l2_bridge_domain_t vector.
190 u32 bd_add_bd_index (bd_main_t * bdm, u32 bd_id);
193 * \brief Get or create a bridge domain.
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..
198 * \param bdm bd_main pointer.
199 * \param bd_id The bridge domain ID
200 * \return The bridge domain index in \c l2input_main->l2_bridge_domain_t vector.
203 bd_find_or_add_bd_index (bd_main_t * bdm, u32 bd_id)
205 u32 bd_index = bd_find_index (bdm, bd_id);
207 return bd_add_bd_index (bdm, bd_id);
212 * \brief Walk all the input interfaces in the BD
214 typedef walk_rc_t (*bd_input_walk_fn_t) (u32 bd_index, u32 sw_if_index);
216 u32 bd_input_walk (u32 bd_index, bd_input_walk_fn_t fn, void *data);
218 l2_bridge_domain_t *bd_get (u32 bd_index);
219 l2_bridge_domain_t *bd_get_by_table_id (u32 table_id);
221 u32 bd_add_del_ip_mac (u32 bd_index,
223 const ip46_address_t * ip_addr,
224 const mac_address_t * mac, u8 is_add);
226 void bd_flush_ip_mac (u32 bd_index);
231 * fd.io coding-style-patch-verification: ON
234 * eval: (c-set-style "gnu")