@@ -20,13 +20,8 @@ void nexthop_free(NextHop *nexthop) {
2020 return ;
2121
2222 if (nexthop -> network ) {
23- LIST_REMOVE (nexthops , nexthop -> network -> static_nexthops , nexthop );
24-
25- assert (nexthop -> network -> n_static_nexthops > 0 );
26- nexthop -> network -> n_static_nexthops -- ;
27-
28- if (nexthop -> section )
29- hashmap_remove (nexthop -> network -> nexthops_by_section , nexthop -> section );
23+ assert (nexthop -> section );
24+ hashmap_remove (nexthop -> network -> nexthops_by_section , nexthop -> section );
3025 }
3126
3227 network_config_section_free (nexthop -> section );
@@ -64,19 +59,17 @@ static int nexthop_new_static(Network *network, const char *filename, unsigned s
6459
6560 assert (network );
6661 assert (ret );
67- assert (!!filename == (section_line > 0 ));
68-
69- if (filename ) {
70- r = network_config_section_new (filename , section_line , & n );
71- if (r < 0 )
72- return r ;
62+ assert (filename );
63+ assert (section_line > 0 );
7364
74- nexthop = hashmap_get ( network -> nexthops_by_section , n );
75- if (nexthop ) {
76- * ret = TAKE_PTR ( nexthop ) ;
65+ r = network_config_section_new ( filename , section_line , & n );
66+ if (r < 0 )
67+ return r ;
7768
78- return 0 ;
79- }
69+ nexthop = hashmap_get (network -> nexthops_by_section , n );
70+ if (nexthop ) {
71+ * ret = TAKE_PTR (nexthop );
72+ return 0 ;
8073 }
8174
8275 r = nexthop_new (& nexthop );
@@ -85,23 +78,17 @@ static int nexthop_new_static(Network *network, const char *filename, unsigned s
8578
8679 nexthop -> protocol = RTPROT_STATIC ;
8780 nexthop -> network = network ;
88- LIST_PREPEND (nexthops , network -> static_nexthops , nexthop );
89- network -> n_static_nexthops ++ ;
81+ nexthop -> section = TAKE_PTR (n );
9082
91- if (filename ) {
92- nexthop -> section = TAKE_PTR (n );
93-
94- r = hashmap_ensure_allocated (& network -> nexthops_by_section , & network_config_hash_ops );
95- if (r < 0 )
96- return r ;
83+ r = hashmap_ensure_allocated (& network -> nexthops_by_section , & network_config_hash_ops );
84+ if (r < 0 )
85+ return r ;
9786
98- r = hashmap_put (network -> nexthops_by_section , nexthop -> section , nexthop );
99- if (r < 0 )
100- return r ;
101- }
87+ r = hashmap_put (network -> nexthops_by_section , nexthop -> section , nexthop );
88+ if (r < 0 )
89+ return r ;
10290
10391 * ret = TAKE_PTR (nexthop );
104-
10592 return 0 ;
10693}
10794
@@ -343,12 +330,12 @@ int link_set_nexthop(Link *link) {
343330
344331 link -> static_nexthops_configured = false;
345332
346- LIST_FOREACH ( nexthops , nh , link -> network -> static_nexthops ) {
333+ HASHMAP_FOREACH ( nh , link -> network -> nexthops_by_section ) {
347334 r = nexthop_configure (nh , link );
348335 if (r < 0 )
349336 return log_link_warning_errno (link , r , "Could not set nexthop: %m" );
350- if ( r > 0 )
351- link -> nexthop_messages ++ ;
337+
338+ link -> nexthop_messages ++ ;
352339 }
353340
354341 if (link -> nexthop_messages == 0 ) {
0 commit comments