]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
ether-addr-util: introduce {hw,ether}_addr_hash_ops_free
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 4 Nov 2021 16:33:25 +0000 (01:33 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 9 Nov 2021 12:39:09 +0000 (21:39 +0900)
src/basic/ether-addr-util.c
src/basic/ether-addr-util.h
src/network/netdev/macvlan.c
src/shared/conf-parser.c
src/shared/net-condition.c

index ed0883886a52493abcf90c467d854f1ff7219b04..9be4baf1233153d781cd946d10172157bfc43e58 100644 (file)
@@ -48,6 +48,7 @@ static void hw_addr_hash_func(const struct hw_addr_data *p, struct siphash *stat
 }
 
 DEFINE_HASH_OPS(hw_addr_hash_ops, struct hw_addr_data, hw_addr_hash_func, hw_addr_compare);
+DEFINE_HASH_OPS_WITH_KEY_DESTRUCTOR(hw_addr_hash_ops_free, struct hw_addr_data, hw_addr_hash_func, hw_addr_compare, free);
 
 char* ether_addr_to_string(const struct ether_addr *addr, char buffer[ETHER_ADDR_TO_STRING_MAX]) {
         assert(addr);
@@ -93,6 +94,7 @@ static void ether_addr_hash_func(const struct ether_addr *p, struct siphash *sta
 }
 
 DEFINE_HASH_OPS(ether_addr_hash_ops, struct ether_addr, ether_addr_hash_func, ether_addr_compare);
+DEFINE_HASH_OPS_WITH_KEY_DESTRUCTOR(ether_addr_hash_ops_free, struct ether_addr, ether_addr_hash_func, ether_addr_compare, free);
 
 static int parse_hw_addr_one_field(const char **s, char sep, size_t len, uint8_t *buf) {
         const char *hex = HEXDIGITS, *p;
index 62afe458b051e8c6ceeddc07accce91183ae3ce6..ae6605fb1145005dcd48fb710e0e0da447e8cad6 100644 (file)
@@ -51,6 +51,7 @@ static inline bool hw_addr_is_null(const struct hw_addr_data *addr) {
 }
 
 extern const struct hash_ops hw_addr_hash_ops;
+extern const struct hash_ops hw_addr_hash_ops_free;
 
 #define ETHER_ADDR_FORMAT_STR "%02X%02X%02X%02X%02X%02X"
 #define ETHER_ADDR_FORMAT_VAL(x) (x).ether_addr_octet[0], (x).ether_addr_octet[1], (x).ether_addr_octet[2], (x).ether_addr_octet[3], (x).ether_addr_octet[4], (x).ether_addr_octet[5]
@@ -93,3 +94,4 @@ static inline bool ether_addr_is_local(const struct ether_addr *addr) {
 }
 
 extern const struct hash_ops ether_addr_hash_ops;
+extern const struct hash_ops ether_addr_hash_ops_free;
index 9d037c2f3683a5ab6dc45e9491c6d32853bc8f8d..c295cae2cd4ad99c161e9fca07ea4bd70f690d4f 100644 (file)
@@ -127,7 +127,7 @@ static void macvlan_done(NetDev *n) {
 
         assert(m);
 
-        set_free_free(m->match_source_mac);
+        set_free(m->match_source_mac);
 }
 
 static void macvlan_init(NetDev *n) {
index f0633a71d1c6e17c0882bb5442ec6209c3e0fd49..35027b8dfac70e4cd6f6b7648be7e19c7e06eb9d 100644 (file)
@@ -1384,7 +1384,7 @@ int config_parse_ether_addrs(
 
         if (isempty(rvalue)) {
                 /* Empty assignment resets the list */
-                *hwaddrs = set_free_free(*hwaddrs);
+                *hwaddrs = set_free(*hwaddrs);
                 return 0;
         }
 
@@ -1414,11 +1414,9 @@ int config_parse_ether_addrs(
                         continue;
                 }
 
-                r = set_ensure_put(hwaddrs, &ether_addr_hash_ops, n);
+                r = set_ensure_consume(hwaddrs, &ether_addr_hash_ops_free, TAKE_PTR(n));
                 if (r < 0)
                         return log_oom();
-                if (r > 0)
-                        TAKE_PTR(n); /* avoid cleanup */
         }
 }
 
index 52cac19df3cb77c1d5df54659e30df5c16fcac6a..ac0a364f06865f2917e6a0b722050f9ad03f5880 100644 (file)
@@ -17,8 +17,8 @@ void net_match_clear(NetMatch *match) {
         if (!match)
                 return;
 
-        match->mac = set_free_free(match->mac);
-        match->permanent_mac = set_free_free(match->permanent_mac);
+        match->mac = set_free(match->mac);
+        match->permanent_mac = set_free(match->permanent_mac);
         match->path = strv_free(match->path);
         match->driver = strv_free(match->driver);
         match->iftype = strv_free(match->iftype);
@@ -26,7 +26,7 @@ void net_match_clear(NetMatch *match) {
         match->property = strv_free(match->property);
         match->wlan_iftype = strv_free(match->wlan_iftype);
         match->ssid = strv_free(match->ssid);
-        match->bssid = set_free_free(match->bssid);
+        match->bssid = set_free(match->bssid);
 }
 
 bool net_match_is_empty(const NetMatch *match) {