Line data Source code
1 : /*
2 : * l2_bd.h : layer 2 bridge domain
3 : *
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:
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>
24 : #include <vnet/ip/ip46_address.h>
25 : #include <vnet/ethernet/mac_address.h>
26 :
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 :
34 : typedef struct
35 : {
36 : /* hash bd_id -> bd_index */
37 : uword *bd_index_by_bd_id;
38 :
39 : /* Busy bd_index bitmap */
40 : uword *bd_index_bitmap;
41 :
42 : /* convenience */
43 : vlib_main_t *vlib_main;
44 : vnet_main_t *vnet_main;
45 : } bd_main_t;
46 :
47 : extern bd_main_t bd_main;
48 :
49 : /* Bridge domain member */
50 :
51 : #define L2_FLOOD_MEMBER_NORMAL 0
52 : #define L2_FLOOD_MEMBER_BVI 1
53 :
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;
60 : } l2_flood_member_t;
61 :
62 : /* Per-bridge domain configuration */
63 :
64 : typedef struct
65 : {
66 : /*
67 : * Contains bit enables for flooding, learning, and forwarding.
68 : * All other feature bits should always be set.
69 : */
70 : u32 feature_bitmap;
71 : /*
72 : * identity of the bridge-domain's BVI interface
73 : * set to ~0 if there is no BVI
74 : */
75 : u32 bvi_sw_if_index;
76 :
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 :
83 : /* bridge domain id, not to be confused with bd_index */
84 : u32 bd_id;
85 :
86 : /* Vector of member ports */
87 : l2_flood_member_t *members;
88 :
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 :
98 : /* Interface on which packets are not flooded */
99 : u32 no_flood_count;
100 :
101 : /* hash ip4/ip6 -> mac for arp/nd termination */
102 : uword *mac_by_ip4;
103 : uword *mac_by_ip6;
104 :
105 : /* mac aging */
106 : u8 mac_age;
107 :
108 : /* sequence number for bridge domain based flush of MACs */
109 : u8 seq_num;
110 :
111 : /* Bridge domain tag (C string NULL terminated) */
112 : u8 *bd_tag;
113 :
114 : /* Maximum number of learned entries */
115 : u32 learn_limit;
116 :
117 : /* Current number of learned entries */
118 : u32 learn_count;
119 :
120 : } l2_bridge_domain_t;
121 :
122 : /* Limit Bridge Domain ID to 24 bits to match 24-bit VNI range */
123 : #define L2_BD_ID_MAX ((1<<24)-1)
124 :
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;
133 : u8 arp_ufwd;
134 : u8 mac_age;
135 : u8 *bd_tag;
136 : u8 is_add;
137 : } l2_bridge_domain_add_del_args_t;
138 :
139 : /* Return 1 if bridge domain has been initialized */
140 : always_inline u32
141 2148 : bd_is_valid (l2_bridge_domain_t * bd_config)
142 : {
143 2148 : return (bd_config->feature_bitmap != 0);
144 : }
145 :
146 : /* Init bridge domain if not done already */
147 : void bd_validate (l2_bridge_domain_t * bd_config);
148 :
149 : void
150 : bd_add_member (l2_bridge_domain_t * bd_config, l2_flood_member_t * member);
151 :
152 : u32 bd_remove_member (l2_bridge_domain_t * bd_config, u32 sw_if_index);
153 :
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),
162 : L2_ARP_UFWD = (1 << 5),
163 : } bd_flags_t;
164 :
165 : u32 bd_set_flags (vlib_main_t * vm, u32 bd_index, bd_flags_t flags,
166 : u32 enable);
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);
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);
191 :
192 : /**
193 : * \brief Get or create a bridge domain.
194 : *
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..
197 : *
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.
201 : */
202 : static inline u32
203 1256 : bd_find_or_add_bd_index (bd_main_t * bdm, u32 bd_id)
204 : {
205 1256 : u32 bd_index = bd_find_index (bdm, bd_id);
206 1256 : if (bd_index == ~0)
207 29 : return bd_add_bd_index (bdm, bd_id);
208 1227 : return bd_index;
209 : }
210 :
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 :
221 : u32 bd_add_del_ip_mac (u32 bd_index,
222 : ip46_type_t type,
223 : const ip46_address_t * ip_addr,
224 : const mac_address_t * mac, u8 is_add);
225 :
226 : void bd_flush_ip_mac (u32 bd_index);
227 :
228 : #endif
229 :
230 : /*
231 : * fd.io coding-style-patch-verification: ON
232 : *
233 : * Local Variables:
234 : * eval: (c-set-style "gnu")
235 : * End:
236 : */
|