@@ -35,7 +35,7 @@ bool link_radv_enabled(Link *link) {
3535 return link -> network -> router_prefix_delegation ;
3636}
3737
38- Prefix * prefix_free (Prefix * prefix ) {
38+ static Prefix * prefix_free (Prefix * prefix ) {
3939 if (!prefix )
4040 return NULL ;
4141
@@ -52,6 +52,11 @@ Prefix* prefix_free(Prefix *prefix) {
5252
5353DEFINE_SECTION_CLEANUP_FUNCTIONS (Prefix , prefix_free );
5454
55+ DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR (
56+ prefix_hash_ops_by_section ,
57+ ConfigSection , config_section_hash_func , config_section_compare_func ,
58+ Prefix , prefix_free );
59+
5560static int prefix_new_static (Network * network , const char * filename , unsigned section_line , Prefix * * ret ) {
5661 _cleanup_ (config_section_freep ) ConfigSection * n = NULL ;
5762 _cleanup_ (prefix_freep ) Prefix * prefix = NULL ;
@@ -87,15 +92,15 @@ static int prefix_new_static(Network *network, const char *filename, unsigned se
8792 .prefix .preferred_until = USEC_INFINITY ,
8893 };
8994
90- r = hashmap_ensure_put (& network -> prefixes_by_section , & config_section_hash_ops , prefix -> section , prefix );
95+ r = hashmap_ensure_put (& network -> prefixes_by_section , & prefix_hash_ops_by_section , prefix -> section , prefix );
9196 if (r < 0 )
9297 return r ;
9398
9499 * ret = TAKE_PTR (prefix );
95100 return 0 ;
96101}
97102
98- RoutePrefix * route_prefix_free (RoutePrefix * prefix ) {
103+ static RoutePrefix * route_prefix_free (RoutePrefix * prefix ) {
99104 if (!prefix )
100105 return NULL ;
101106
@@ -111,6 +116,11 @@ RoutePrefix* route_prefix_free(RoutePrefix *prefix) {
111116
112117DEFINE_SECTION_CLEANUP_FUNCTIONS (RoutePrefix , route_prefix_free );
113118
119+ DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR (
120+ route_prefix_hash_ops_by_section ,
121+ ConfigSection , config_section_hash_func , config_section_compare_func ,
122+ RoutePrefix , route_prefix_free );
123+
114124static int route_prefix_new_static (Network * network , const char * filename , unsigned section_line , RoutePrefix * * ret ) {
115125 _cleanup_ (config_section_freep ) ConfigSection * n = NULL ;
116126 _cleanup_ (route_prefix_freep ) RoutePrefix * prefix = NULL ;
@@ -143,15 +153,15 @@ static int route_prefix_new_static(Network *network, const char *filename, unsig
143153 .route .valid_until = USEC_INFINITY ,
144154 };
145155
146- r = hashmap_ensure_put (& network -> route_prefixes_by_section , & config_section_hash_ops , prefix -> section , prefix );
156+ r = hashmap_ensure_put (& network -> route_prefixes_by_section , & route_prefix_hash_ops_by_section , prefix -> section , prefix );
147157 if (r < 0 )
148158 return r ;
149159
150160 * ret = TAKE_PTR (prefix );
151161 return 0 ;
152162}
153163
154- Prefix64 * prefix64_free (Prefix64 * prefix ) {
164+ static Prefix64 * prefix64_free (Prefix64 * prefix ) {
155165 if (!prefix )
156166 return NULL ;
157167
@@ -167,6 +177,11 @@ Prefix64* prefix64_free(Prefix64 *prefix) {
167177
168178DEFINE_SECTION_CLEANUP_FUNCTIONS (Prefix64 , prefix64_free );
169179
180+ DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR (
181+ prefix64_hash_ops_by_section ,
182+ ConfigSection , config_section_hash_func , config_section_compare_func ,
183+ Prefix64 , prefix64_free );
184+
170185static int prefix64_new_static (Network * network , const char * filename , unsigned section_line , Prefix64 * * ret ) {
171186 _cleanup_ (config_section_freep ) ConfigSection * n = NULL ;
172187 _cleanup_ (prefix64_freep ) Prefix64 * prefix = NULL ;
@@ -199,7 +214,7 @@ static int prefix64_new_static(Network *network, const char *filename, unsigned
199214 .prefix64 .valid_until = USEC_INFINITY ,
200215 };
201216
202- r = hashmap_ensure_put (& network -> pref64_prefixes_by_section , & config_section_hash_ops , prefix -> section , prefix );
217+ r = hashmap_ensure_put (& network -> pref64_prefixes_by_section , & prefix64_hash_ops_by_section , prefix -> section , prefix );
203218 if (r < 0 )
204219 return r ;
205220
@@ -809,9 +824,9 @@ void network_adjust_radv(Network *network) {
809824 }
810825
811826 if (!FLAGS_SET (network -> router_prefix_delegation , RADV_PREFIX_DELEGATION_STATIC )) {
812- network -> prefixes_by_section = hashmap_free_with_destructor (network -> prefixes_by_section , prefix_free );
813- network -> route_prefixes_by_section = hashmap_free_with_destructor (network -> route_prefixes_by_section , route_prefix_free );
814- network -> pref64_prefixes_by_section = hashmap_free_with_destructor (network -> pref64_prefixes_by_section , prefix64_free );
827+ network -> prefixes_by_section = hashmap_free (network -> prefixes_by_section );
828+ network -> route_prefixes_by_section = hashmap_free (network -> route_prefixes_by_section );
829+ network -> pref64_prefixes_by_section = hashmap_free (network -> pref64_prefixes_by_section );
815830 }
816831
817832 if (!network -> router_prefix_delegation )
0 commit comments