99#include "alloc-util.h"
1010#include "bridge.h"
1111#include "netlink-util.h"
12- #include "networkd-fdb.h"
12+ #include "networkd-bridge- fdb.h"
1313#include "networkd-link.h"
1414#include "networkd-manager.h"
1515#include "networkd-network.h"
1818#include "vlan-util.h"
1919#include "vxlan.h"
2020
21- #define STATIC_FDB_ENTRIES_PER_NETWORK_MAX 1024U
21+ #define STATIC_BRIDGE_FDB_ENTRIES_PER_NETWORK_MAX 1024U
2222
2323/* remove and FDB entry. */
24- FdbEntry * fdb_entry_free ( FdbEntry * fdb_entry ) {
25- if (!fdb_entry )
24+ BridgeFDB * bridge_fdb_free ( BridgeFDB * fdb ) {
25+ if (!fdb )
2626 return NULL ;
2727
28- if (fdb_entry -> network ) {
29- assert (fdb_entry -> section );
30- hashmap_remove (fdb_entry -> network -> fdb_entries_by_section , fdb_entry -> section );
28+ if (fdb -> network ) {
29+ assert (fdb -> section );
30+ hashmap_remove (fdb -> network -> bridge_fdb_entries_by_section , fdb -> section );
3131 }
3232
33- network_config_section_free (fdb_entry -> section );
34- return mfree (fdb_entry );
33+ network_config_section_free (fdb -> section );
34+ return mfree (fdb );
3535}
3636
37- DEFINE_NETWORK_SECTION_FUNCTIONS (FdbEntry , fdb_entry_free );
37+ DEFINE_NETWORK_SECTION_FUNCTIONS (BridgeFDB , bridge_fdb_free );
3838
3939/* create a new FDB entry or get an existing one. */
40- static int fdb_entry_new_static (
40+ static int bridge_fdb_new_static (
4141 Network * network ,
4242 const char * filename ,
4343 unsigned section_line ,
44- FdbEntry * * ret ) {
44+ BridgeFDB * * ret ) {
4545
4646 _cleanup_ (network_config_section_freep ) NetworkConfigSection * n = NULL ;
47- _cleanup_ (fdb_entry_freep ) FdbEntry * fdb_entry = NULL ;
47+ _cleanup_ (bridge_fdb_freep ) BridgeFDB * fdb = NULL ;
4848 int r ;
4949
5050 assert (network );
@@ -57,34 +57,34 @@ static int fdb_entry_new_static(
5757 return r ;
5858
5959 /* search entry in hashmap first. */
60- fdb_entry = hashmap_get (network -> fdb_entries_by_section , n );
61- if (fdb_entry ) {
62- * ret = TAKE_PTR (fdb_entry );
60+ fdb = hashmap_get (network -> bridge_fdb_entries_by_section , n );
61+ if (fdb ) {
62+ * ret = TAKE_PTR (fdb );
6363 return 0 ;
6464 }
6565
66- if (hashmap_size (network -> fdb_entries_by_section ) >= STATIC_FDB_ENTRIES_PER_NETWORK_MAX )
66+ if (hashmap_size (network -> bridge_fdb_entries_by_section ) >= STATIC_BRIDGE_FDB_ENTRIES_PER_NETWORK_MAX )
6767 return - E2BIG ;
6868
6969 /* allocate space for and FDB entry. */
70- fdb_entry = new (FdbEntry , 1 );
71- if (!fdb_entry )
70+ fdb = new (BridgeFDB , 1 );
71+ if (!fdb )
7272 return - ENOMEM ;
7373
7474 /* init FDB structure. */
75- * fdb_entry = (FdbEntry ) {
75+ * fdb = (BridgeFDB ) {
7676 .network = network ,
7777 .section = TAKE_PTR (n ),
7878 .vni = VXLAN_VID_MAX + 1 ,
79- .fdb_ntf_flags = NEIGHBOR_CACHE_ENTRY_FLAGS_SELF ,
79+ .ntf_flags = NEIGHBOR_CACHE_ENTRY_FLAGS_SELF ,
8080 };
8181
82- r = hashmap_ensure_put (& network -> fdb_entries_by_section , & network_config_hash_ops , fdb_entry -> section , fdb_entry );
82+ r = hashmap_ensure_put (& network -> bridge_fdb_entries_by_section , & network_config_hash_ops , fdb -> section , fdb );
8383 if (r < 0 )
8484 return r ;
8585
8686 /* return allocated FDB structure. */
87- * ret = TAKE_PTR (fdb_entry );
87+ * ret = TAKE_PTR (fdb );
8888
8989 return 0 ;
9090}
@@ -108,21 +108,21 @@ static int set_fdb_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link)
108108}
109109
110110/* send a request to the kernel to add a FDB entry in its static MAC table. */
111- static int fdb_entry_configure (Link * link , FdbEntry * fdb_entry ) {
111+ static int bridge_fdb_configure (Link * link , BridgeFDB * fdb ) {
112112 _cleanup_ (sd_netlink_message_unrefp ) sd_netlink_message * req = NULL ;
113113 int r ;
114114
115115 assert (link );
116116 assert (link -> network );
117117 assert (link -> manager );
118- assert (fdb_entry );
118+ assert (fdb );
119119
120120 /* create new RTM message */
121121 r = sd_rtnl_message_new_neigh (link -> manager -> rtnl , & req , RTM_NEWNEIGH , link -> ifindex , AF_BRIDGE );
122122 if (r < 0 )
123123 return log_link_error_errno (link , r , "Could not create RTM_NEWNEIGH message: %m" );
124124
125- r = sd_rtnl_message_neigh_set_flags (req , fdb_entry -> fdb_ntf_flags );
125+ r = sd_rtnl_message_neigh_set_flags (req , fdb -> ntf_flags );
126126 if (r < 0 )
127127 return log_link_error_errno (link , r , "Could not set neighbor flags: %m" );
128128
@@ -131,25 +131,25 @@ static int fdb_entry_configure(Link *link, FdbEntry *fdb_entry) {
131131 if (r < 0 )
132132 return log_link_error_errno (link , r , "Could not set neighbor state: %m" );
133133
134- r = sd_netlink_message_append_data (req , NDA_LLADDR , & fdb_entry -> mac_addr , sizeof (fdb_entry -> mac_addr ));
134+ r = sd_netlink_message_append_data (req , NDA_LLADDR , & fdb -> mac_addr , sizeof (fdb -> mac_addr ));
135135 if (r < 0 )
136136 return log_link_error_errno (link , r , "Could not append NDA_LLADDR attribute: %m" );
137137
138138 /* VLAN Id is optional. We'll add VLAN Id only if it's specified. */
139- if (fdb_entry -> vlan_id > 0 ) {
140- r = sd_netlink_message_append_u16 (req , NDA_VLAN , fdb_entry -> vlan_id );
139+ if (fdb -> vlan_id > 0 ) {
140+ r = sd_netlink_message_append_u16 (req , NDA_VLAN , fdb -> vlan_id );
141141 if (r < 0 )
142142 return log_link_error_errno (link , r , "Could not append NDA_VLAN attribute: %m" );
143143 }
144144
145- if (in_addr_is_set (fdb_entry -> family , & fdb_entry -> destination_addr )) {
146- r = netlink_message_append_in_addr_union (req , NDA_DST , fdb_entry -> family , & fdb_entry -> destination_addr );
145+ if (in_addr_is_set (fdb -> family , & fdb -> destination_addr )) {
146+ r = netlink_message_append_in_addr_union (req , NDA_DST , fdb -> family , & fdb -> destination_addr );
147147 if (r < 0 )
148148 return log_link_error_errno (link , r , "Could not append NDA_DST attribute: %m" );
149149 }
150150
151- if (fdb_entry -> vni <= VXLAN_VID_MAX ) {
152- r = sd_netlink_message_append_u32 (req , NDA_VNI , fdb_entry -> vni );
151+ if (fdb -> vni <= VXLAN_VID_MAX ) {
152+ r = sd_netlink_message_append_u32 (req , NDA_VNI , fdb -> vni );
153153 if (r < 0 )
154154 return log_link_error_errno (link , r , "Could not append NDA_VNI attribute: %m" );
155155 }
@@ -166,29 +166,29 @@ static int fdb_entry_configure(Link *link, FdbEntry *fdb_entry) {
166166}
167167
168168int link_set_bridge_fdb (Link * link ) {
169- FdbEntry * fdb_entry ;
169+ BridgeFDB * fdb ;
170170 int r ;
171171
172172 assert (link );
173173 assert (link -> network );
174174
175- HASHMAP_FOREACH (fdb_entry , link -> network -> fdb_entries_by_section ) {
176- r = fdb_entry_configure (link , fdb_entry );
175+ HASHMAP_FOREACH (fdb , link -> network -> bridge_fdb_entries_by_section ) {
176+ r = bridge_fdb_configure (link , fdb );
177177 if (r < 0 )
178178 return log_link_error_errno (link , r , "Failed to add MAC entry to static MAC table: %m" );
179179 }
180180
181181 return 0 ;
182182}
183183
184- void network_drop_invalid_fdb_entries (Network * network ) {
185- FdbEntry * fdb_entry ;
184+ void network_drop_invalid_bridge_fdb_entries (Network * network ) {
185+ BridgeFDB * fdb ;
186186
187187 assert (network );
188188
189- HASHMAP_FOREACH (fdb_entry , network -> fdb_entries_by_section )
190- if (section_is_invalid (fdb_entry -> section ))
191- fdb_entry_free ( fdb_entry );
189+ HASHMAP_FOREACH (fdb , network -> bridge_fdb_entries_by_section )
190+ if (section_is_invalid (fdb -> section ))
191+ bridge_fdb_free ( fdb );
192192}
193193
194194/* parse the HW address from config files. */
@@ -204,8 +204,8 @@ int config_parse_fdb_hwaddr(
204204 void * data ,
205205 void * userdata ) {
206206
207+ _cleanup_ (bridge_fdb_free_or_set_invalidp ) BridgeFDB * fdb = NULL ;
207208 Network * network = userdata ;
208- _cleanup_ (fdb_entry_free_or_set_invalidp ) FdbEntry * fdb_entry = NULL ;
209209 int r ;
210210
211211 assert (filename );
@@ -214,18 +214,17 @@ int config_parse_fdb_hwaddr(
214214 assert (rvalue );
215215 assert (data );
216216
217- r = fdb_entry_new_static (network , filename , section_line , & fdb_entry );
217+ r = bridge_fdb_new_static (network , filename , section_line , & fdb );
218218 if (r < 0 )
219219 return log_oom ();
220220
221- r = ether_addr_from_string (rvalue , & fdb_entry -> mac_addr );
221+ r = ether_addr_from_string (rvalue , & fdb -> mac_addr );
222222 if (r < 0 ) {
223223 log_syntax (unit , LOG_WARNING , filename , line , r , "Not a valid MAC address, ignoring assignment: %s" , rvalue );
224224 return 0 ;
225225 }
226226
227- fdb_entry = NULL ;
228-
227+ TAKE_PTR (fdb );
229228 return 0 ;
230229}
231230
@@ -242,8 +241,8 @@ int config_parse_fdb_vlan_id(
242241 void * data ,
243242 void * userdata ) {
244243
244+ _cleanup_ (bridge_fdb_free_or_set_invalidp ) BridgeFDB * fdb = NULL ;
245245 Network * network = userdata ;
246- _cleanup_ (fdb_entry_free_or_set_invalidp ) FdbEntry * fdb_entry = NULL ;
247246 int r ;
248247
249248 assert (filename );
@@ -252,18 +251,17 @@ int config_parse_fdb_vlan_id(
252251 assert (rvalue );
253252 assert (data );
254253
255- r = fdb_entry_new_static (network , filename , section_line , & fdb_entry );
254+ r = bridge_fdb_new_static (network , filename , section_line , & fdb );
256255 if (r < 0 )
257256 return log_oom ();
258257
259258 r = config_parse_vlanid (unit , filename , line , section ,
260259 section_line , lvalue , ltype ,
261- rvalue , & fdb_entry -> vlan_id , userdata );
260+ rvalue , & fdb -> vlan_id , userdata );
262261 if (r < 0 )
263262 return r ;
264263
265- fdb_entry = NULL ;
266-
264+ TAKE_PTR (fdb );
267265 return 0 ;
268266}
269267
@@ -279,7 +277,7 @@ int config_parse_fdb_destination(
279277 void * data ,
280278 void * userdata ) {
281279
282- _cleanup_ (fdb_entry_free_or_set_invalidp ) FdbEntry * fdb_entry = NULL ;
280+ _cleanup_ (bridge_fdb_free_or_set_invalidp ) BridgeFDB * fdb = NULL ;
283281 Network * network = userdata ;
284282 int r ;
285283
@@ -289,20 +287,19 @@ int config_parse_fdb_destination(
289287 assert (rvalue );
290288 assert (data );
291289
292- r = fdb_entry_new_static (network , filename , section_line , & fdb_entry );
290+ r = bridge_fdb_new_static (network , filename , section_line , & fdb );
293291 if (r < 0 )
294292 return log_oom ();
295293
296- r = in_addr_from_string_auto (rvalue , & fdb_entry -> family , & fdb_entry -> destination_addr );
294+ r = in_addr_from_string_auto (rvalue , & fdb -> family , & fdb -> destination_addr );
297295 if (r < 0 ) {
298296 log_syntax (unit , LOG_WARNING , filename , line , r ,
299297 "FDB destination IP address is invalid, ignoring assignment: %s" ,
300298 rvalue );
301299 return 0 ;
302300 }
303301
304- fdb_entry = NULL ;
305-
302+ TAKE_PTR (fdb );
306303 return 0 ;
307304}
308305
@@ -318,7 +315,7 @@ int config_parse_fdb_vxlan_vni(
318315 void * data ,
319316 void * userdata ) {
320317
321- _cleanup_ (fdb_entry_free_or_set_invalidp ) FdbEntry * fdb_entry = NULL ;
318+ _cleanup_ (bridge_fdb_free_or_set_invalidp ) BridgeFDB * fdb = NULL ;
322319 Network * network = userdata ;
323320 uint32_t vni ;
324321 int r ;
@@ -329,7 +326,7 @@ int config_parse_fdb_vxlan_vni(
329326 assert (rvalue );
330327 assert (data );
331328
332- r = fdb_entry_new_static (network , filename , section_line , & fdb_entry );
329+ r = bridge_fdb_new_static (network , filename , section_line , & fdb );
333330 if (r < 0 )
334331 return log_oom ();
335332
@@ -348,20 +345,20 @@ int config_parse_fdb_vxlan_vni(
348345 return 0 ;
349346 }
350347
351- fdb_entry -> vni = vni ;
352- fdb_entry = NULL ;
348+ fdb -> vni = vni ;
353349
350+ TAKE_PTR (fdb );
354351 return 0 ;
355352}
356353
357- static const char * const fdb_ntf_flags_table [_NEIGHBOR_CACHE_ENTRY_FLAGS_MAX ] = {
354+ static const char * const ntf_flags_table [_NEIGHBOR_CACHE_ENTRY_FLAGS_MAX ] = {
358355 [NEIGHBOR_CACHE_ENTRY_FLAGS_USE ] = "use" ,
359356 [NEIGHBOR_CACHE_ENTRY_FLAGS_SELF ] = "self" ,
360357 [NEIGHBOR_CACHE_ENTRY_FLAGS_MASTER ] = "master" ,
361358 [NEIGHBOR_CACHE_ENTRY_FLAGS_ROUTER ] = "router" ,
362359};
363360
364- DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING (fdb_ntf_flags , NeighborCacheEntryFlags );
361+ DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING (ntf_flags , NeighborCacheEntryFlags );
365362
366363int config_parse_fdb_ntf_flags (
367364 const char * unit ,
@@ -375,8 +372,9 @@ int config_parse_fdb_ntf_flags(
375372 void * data ,
376373 void * userdata ) {
377374
378- _cleanup_ (fdb_entry_free_or_set_invalidp ) FdbEntry * fdb_entry = NULL ;
375+ _cleanup_ (bridge_fdb_free_or_set_invalidp ) BridgeFDB * fdb = NULL ;
379376 Network * network = userdata ;
377+ NeighborCacheEntryFlags f ;
380378 int r ;
381379
382380 assert (filename );
@@ -385,20 +383,20 @@ int config_parse_fdb_ntf_flags(
385383 assert (rvalue );
386384 assert (data );
387385
388- r = fdb_entry_new_static (network , filename , section_line , & fdb_entry );
386+ r = bridge_fdb_new_static (network , filename , section_line , & fdb );
389387 if (r < 0 )
390388 return log_oom ();
391389
392- NeighborCacheEntryFlags f = fdb_ntf_flags_from_string (rvalue );
390+ f = ntf_flags_from_string (rvalue );
393391 if (f < 0 ) {
394392 log_syntax (unit , LOG_WARNING , filename , line , f ,
395393 "FDB failed to parse AssociatedWith=, ignoring assignment: %s" ,
396394 rvalue );
397395 return 0 ;
398396 }
399397
400- fdb_entry -> fdb_ntf_flags = f ;
401- fdb_entry = NULL ;
398+ fdb -> ntf_flags = f ;
402399
400+ TAKE_PTR (fdb );
403401 return 0 ;
404402}
0 commit comments