FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
l2_bd.h
Go to the documentation of this file.
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>
23 #include <vnet/ip/ip46_address.h>
25 
26 typedef enum l2_bd_port_type_t_
27 {
32 
33 typedef struct
34 {
35  /* hash bd_id -> bd_index */
37 
38  /* Busy bd_index bitmap */
40 
41  /* convenience */
44 } bd_main_t;
45 
46 extern bd_main_t bd_main;
47 
48 /* Bridge domain member */
49 
50 #define L2_FLOOD_MEMBER_NORMAL 0
51 #define L2_FLOOD_MEMBER_BVI 1
52 
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 */
60 
61 /* Per-bridge domain configuration */
62 
63 typedef struct
64 {
65  /*
66  * Contains bit enables for flooding, learning, and forwarding.
67  * All other feature bits should always be set.
68  */
70  /*
71  * identity of the bridge-domain's BVI interface
72  * set to ~0 if there is no BVI
73  */
75 
76  /*
77  * identity of the bridge-domain's UU flood interface
78  * set to ~0 if there is no such configuration
79  */
81 
82  /* bridge domain id, not to be confused with bd_index */
84 
85  /* Vector of member ports */
87 
88  /* First flood_count member ports are flooded */
90 
91  /* Tunnel Master (Multicast vxlan) are always flooded */
93 
94  /* Tunnels (Unicast vxlan) are flooded if there are no masters */
96 
97  /* Interface on which packets are not flooded */
99 
100  /* hash ip4/ip6 -> mac for arp/nd termination */
103 
104  /* mac aging */
106 
107  /* sequence number for bridge domain based flush of MACs */
109 
110  /* Bridge domain tag (C string NULL terminated) */
112 
113  /* Maximum number of learned entries */
115 
116  /* Current number of learned entries */
118 
120 
121 /* Limit Bridge Domain ID to 24 bits to match 24-bit VNI range */
122 #define L2_BD_ID_MAX ((1<<24)-1)
123 
124 typedef struct
125 {
137 
138 /* Return 1 if bridge domain has been initialized */
141 {
142  return (bd_config->feature_bitmap != 0);
143 }
144 
145 /* Init bridge domain if not done already */
146 void bd_validate (l2_bridge_domain_t * bd_config);
147 
148 void
149 bd_add_member (l2_bridge_domain_t * bd_config, l2_flood_member_t * member);
150 
152 
153 typedef enum bd_flags_t_
154 {
155  L2_NONE = 0,
156  L2_LEARN = (1 << 0),
157  L2_FWD = (1 << 1),
158  L2_FLOOD = (1 << 2),
159  L2_UU_FLOOD = (1 << 3),
160  L2_ARP_TERM = (1 << 4),
161  L2_ARP_UFWD = (1 << 5),
162 } bd_flags_t;
163 
165  u32 enable);
166 void bd_set_mac_age (vlib_main_t * vm, u32 bd_index, u8 age);
167 void bd_set_learn_limit (vlib_main_t *vm, u32 bd_index, u32 learn_limit);
169 
170 /**
171  * \brief Get a bridge domain.
172  *
173  * Get a bridge domain with the given bridge domain ID.
174  *
175  * \param bdm bd_main pointer.
176  * \param bd_id The bridge domain ID
177  * \return The bridge domain index in \c l2input_main->l2_bridge_domain_t vector.
178  */
180 
181 /**
182  * \brief Create a bridge domain.
183  *
184  * Create a bridge domain with the given bridge domain ID
185  *
186  * \param bdm bd_main pointer.
187  * \return The bridge domain index in \c l2input_main->l2_bridge_domain_t vector.
188  */
190 
191 /**
192  * \brief Get or create a bridge domain.
193  *
194  * Get a bridge domain with the given bridge domain ID, if one exists, otherwise
195  * create one with the given ID, or the first unused ID if the given ID is ~0..
196  *
197  * \param bdm bd_main pointer.
198  * \param bd_id The bridge domain ID
199  * \return The bridge domain index in \c l2input_main->l2_bridge_domain_t vector.
200  */
201 static inline u32
203 {
204  u32 bd_index = bd_find_index (bdm, bd_id);
205  if (bd_index == ~0)
206  return bd_add_bd_index (bdm, bd_id);
207  return bd_index;
208 }
209 
210 /**
211  * \brief Walk all the input interfaces in the BD
212  */
214 
215 u32 bd_input_walk (u32 bd_index, bd_input_walk_fn_t fn, void *data);
216 
217 l2_bridge_domain_t *bd_get (u32 bd_index);
219 
220 u32 bd_add_del_ip_mac (u32 bd_index,
222  const ip46_address_t * ip_addr,
223  const mac_address_t * mac, u8 is_add);
224 
225 void bd_flush_ip_mac (u32 bd_index);
226 
227 #endif
228 
229 /*
230  * fd.io coding-style-patch-verification: ON
231  *
232  * Local Variables:
233  * eval: (c-set-style "gnu")
234  * End:
235  */
vlib.h
bd_set_learn_limit
void bd_set_learn_limit(vlib_main_t *vm, u32 bd_index, u32 learn_limit)
Set learn limit for the bridge domain.
Definition: l2_bd.c:367
l2_bridge_domain_add_del_args_t
Definition: l2_bd.h:124
l2_bridge_domain_t::tun_master_count
u32 tun_master_count
Definition: l2_bd.h:92
L2_FWD
@ L2_FWD
Definition: l2_bd.h:157
l2_bridge_domain_add_del_args_t::learn
u8 learn
Definition: l2_bd.h:130
l2_bridge_domain_t
Definition: l2_bd.h:63
mac
vl_api_mac_address_t mac
Definition: l2.api:559
l2_bd_port_type_t_
l2_bd_port_type_t_
Definition: l2_bd.h:26
l2_bridge_domain_add_del_args_t::is_add
u8 is_add
Definition: l2_bd.h:135
l2_bridge_domain_add_del_args_t::bd_id
u32 bd_id
Definition: l2_bd.h:126
l2_flood_member_t::sw_if_index
u32 sw_if_index
Definition: l2_bd.h:55
bd_set_mac_age
void bd_set_mac_age(vlib_main_t *vm, u32 bd_index, u8 age)
Set the mac age for the bridge domain.
Definition: l2_bd.c:344
bd_main_t
Definition: l2_bd.h:33
L2_FLOOD
@ L2_FLOOD
Definition: l2_bd.h:158
u16
unsigned short u16
Definition: types.h:57
bd_main
bd_main_t bd_main
Definition: l2_bd.c:44
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
bd_add_bd_index
u32 bd_add_bd_index(bd_main_t *bdm, u32 bd_id)
Create a bridge domain.
Definition: l2_bd.c:79
l2_bridge_domain_t::flood_count
u32 flood_count
Definition: l2_bd.h:89
bd_main_t::vnet_main
vnet_main_t * vnet_main
Definition: l2_bd.h:43
l2_bridge_domain_t::mac_age
u8 mac_age
Definition: l2_bd.h:105
bd_add_del
int bd_add_del(l2_bridge_domain_add_del_args_t *args)
Definition: l2_bd.c:1361
L2_BD_PORT_TYPE_UU_FWD
@ L2_BD_PORT_TYPE_UU_FWD
Definition: l2_bd.h:30
bd_add_member
void bd_add_member(l2_bridge_domain_t *bd_config, l2_flood_member_t *member)
Definition: l2_bd.c:153
L2_ARP_TERM
@ L2_ARP_TERM
Definition: l2_bd.h:160
bd_set_flags
u32 bd_set_flags(vlib_main_t *vm, u32 bd_index, bd_flags_t flags, u32 enable)
Set the learn/forward/flood flags for the bridge domain.
Definition: l2_bd.c:294
l2_bridge_domain_t::mac_by_ip4
uword * mac_by_ip4
Definition: l2_bd.h:101
l2_bridge_domain_t::learn_count
u32 learn_count
Definition: l2_bd.h:117
bd_input_walk_fn_t
walk_rc_t(* bd_input_walk_fn_t)(u32 bd_index, u32 sw_if_index)
Walk all the input interfaces in the BD.
Definition: l2_bd.h:213
l2_bridge_domain_t::tun_normal_count
u32 tun_normal_count
Definition: l2_bd.h:95
l2_bridge_domain_t::no_flood_count
u32 no_flood_count
Definition: l2_bd.h:98
bd_id
u32 bd_id
Definition: gbp.api:188
bd_input_walk
u32 bd_input_walk(u32 bd_index, bd_input_walk_fn_t fn, void *data)
Definition: l2_bd.c:260
l2_bridge_domain_t::uu_fwd_sw_if_index
u32 uu_fwd_sw_if_index
Definition: l2_bd.h:80
bd_main_t::bd_index_bitmap
uword * bd_index_bitmap
Definition: l2_bd.h:39
mac_address.h
uword
u64 uword
Definition: types.h:112
l2_flood_member_t::spare
u16 spare
Definition: l2_bd.h:58
L2_ARP_UFWD
@ L2_ARP_UFWD
Definition: l2_bd.h:161
l2_bridge_domain_add_del_args_t::arp_term
u8 arp_term
Definition: l2_bd.h:131
bd_find_or_add_bd_index
static u32 bd_find_or_add_bd_index(bd_main_t *bdm, u32 bd_id)
Get or create a bridge domain.
Definition: l2_bd.h:202
l2_bridge_domain_add_del_args_t::arp_ufwd
u8 arp_ufwd
Definition: l2_bd.h:132
l2_bridge_domain_t::feature_bitmap
u32 feature_bitmap
Definition: l2_bd.h:69
bd_add_del_ip_mac
u32 bd_add_del_ip_mac(u32 bd_index, ip46_type_t type, const ip46_address_t *ip_addr, const mac_address_t *mac, u8 is_add)
Add/delete IP address to MAC address mapping.
Definition: l2_bd.c:945
l2_bridge_domain_t::seq_num
u8 seq_num
Definition: l2_bd.h:108
bd_flags_t
enum bd_flags_t_ bd_flags_t
L2_LEARN
@ L2_LEARN
Definition: l2_bd.h:156
ip46_address.h
bd_remove_member
u32 bd_remove_member(l2_bridge_domain_t *bd_config, u32 sw_if_index)
Definition: l2_bd.c:198
l2_bridge_domain_add_del_args_t::mac_age
u8 mac_age
Definition: l2_bd.h:133
data
u8 data[128]
Definition: ipsec_types.api:95
l2_bridge_domain_add_del_args_t::flood
u8 flood
Definition: l2_bd.h:127
bd_find_index
u32 bd_find_index(bd_main_t *bdm, u32 bd_id)
Get a bridge domain.
Definition: l2_bd.c:70
l2_bridge_domain_add_del_args_t::bd_tag
u8 * bd_tag
Definition: l2_bd.h:134
vnet_main_t
Definition: vnet.h:76
always_inline
#define always_inline
Definition: rdma_mlx5dv.h:23
l2_flood_member_t::shg
u8 shg
Definition: l2_bd.h:57
bd_is_valid
static u32 bd_is_valid(l2_bridge_domain_t *bd_config)
Definition: l2_bd.h:140
l2_bridge_domain_t::bd_id
u32 bd_id
Definition: l2_bd.h:83
l2_bridge_domain_t::learn_limit
u32 learn_limit
Definition: l2_bd.h:114
l2_bridge_domain_t::bvi_sw_if_index
u32 bvi_sw_if_index
Definition: l2_bd.h:74
L2_UU_FLOOD
@ L2_UU_FLOOD
Definition: l2_bd.h:159
L2_BD_PORT_TYPE_NORMAL
@ L2_BD_PORT_TYPE_NORMAL
Definition: l2_bd.h:28
l2_bridge_domain_add_del_args_t::uu_flood
u8 uu_flood
Definition: l2_bd.h:128
bd_main_t::vlib_main
vlib_main_t * vlib_main
Definition: l2_bd.h:42
u32
unsigned int u32
Definition: types.h:88
bd_validate
void bd_validate(l2_bridge_domain_t *bd_config)
Init bridge domain if not done already.
Definition: l2_bd.c:51
bd_flush_ip_mac
void bd_flush_ip_mac(u32 bd_index)
Flush IP address to MAC address mapping tables in a BD.
Definition: l2_bd.c:1022
bd_get
l2_bridge_domain_t * bd_get(u32 bd_index)
Definition: l2_bd.c:252
table_id
u32 table_id
Definition: wireguard.api:102
bd_flags_t_
bd_flags_t_
Definition: l2_bd.h:153
bd_get_by_table_id
l2_bridge_domain_t * bd_get_by_table_id(u32 table_id)
l2_flood_member_t
Definition: l2_bd.h:53
mac_address_t_
Definition: mac_address.h:21
vlib_main_t
Definition: main.h:102
u8
unsigned char u8
Definition: types.h:56
l2_bridge_domain_t::members
l2_flood_member_t * members
Definition: l2_bd.h:86
l2_bridge_domain_t::bd_tag
u8 * bd_tag
Definition: l2_bd.h:111
ip46_type_t
ip46_type_t
Definition: ip46_address.h:22
l2_bd_port_type_t
enum l2_bd_port_type_t_ l2_bd_port_type_t
l2_flood_member_t::flags
u8 flags
Definition: l2_bd.h:56
vnet.h
l2_bridge_domain_t::mac_by_ip6
uword * mac_by_ip6
Definition: l2_bd.h:102
L2_NONE
@ L2_NONE
Definition: l2_bd.h:155
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
walk_rc_t
enum walk_rc_t_ walk_rc_t
Walk return code.
L2_BD_PORT_TYPE_BVI
@ L2_BD_PORT_TYPE_BVI
Definition: l2_bd.h:29
bd_main_t::bd_index_by_bd_id
uword * bd_index_by_bd_id
Definition: l2_bd.h:36
type
vl_api_fib_path_type_t type
Definition: fib_types.api:123
l2_bridge_domain_add_del_args_t::forward
u8 forward
Definition: l2_bd.h:129
flags
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:105