]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-radv: voidify sd_radv_remove_prefix()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 16 Mar 2022 12:12:37 +0000 (21:12 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 17 Mar 2022 05:34:58 +0000 (14:34 +0900)
If the prefix is only referenced by sd_radv, then the returned pointer
is already freed.

networkd does not uses the returned value. Let's voidify the function.

src/libsystemd-network/sd-radv.c
src/network/networkd-dhcp-prefix-delegation.c
src/systemd/sd-radv.h

index e332f6a2ab93796ab42d753d9f166e9cacd63c5c..752c09d89071ad9786650b6d2a0facf4fa7ca452 100644 (file)
@@ -659,15 +659,20 @@ int sd_radv_add_prefix(sd_radv *ra, sd_radv_prefix *p) {
         return 0;
 }
 
-sd_radv_prefix *sd_radv_remove_prefix(sd_radv *ra,
-                                               const struct in6_addr *prefix,
-                                               unsigned char prefixlen) {
-        sd_radv_prefix *cur, *next;
+void sd_radv_remove_prefix(
+                sd_radv *ra,
+                const struct in6_addr *prefix,
+                unsigned char prefixlen) {
 
-        assert_return(ra, NULL);
-        assert_return(prefix, NULL);
+        sd_radv_prefix *cur;
+
+        if (!ra)
+                return;
 
-        LIST_FOREACH_SAFE(prefix, cur, next, ra->prefixes) {
+        if (!prefix)
+                return;
+
+        LIST_FOREACH(prefix, cur, ra->prefixes) {
                 if (prefixlen != cur->opt.prefixlen)
                         continue;
 
@@ -677,11 +682,8 @@ sd_radv_prefix *sd_radv_remove_prefix(sd_radv *ra,
                 LIST_REMOVE(prefix, ra->prefixes, cur);
                 ra->n_prefixes--;
                 sd_radv_prefix_unref(cur);
-
-                break;
+                return;
         }
-
-        return cur;
 }
 
 int sd_radv_add_route_prefix(sd_radv *ra, sd_radv_route_prefix *p) {
index edc893e9f6913cdc77cc515b0f53c21ba4429997..775acb3f95a1c19d20385766ca311b82f0b3f7cd 100644 (file)
@@ -187,7 +187,7 @@ int dhcp_pd_remove(Link *link, bool only_marked) {
                                 continue;
 
                         if (link->radv)
-                                (void) sd_radv_remove_prefix(link->radv, &route->dst.in6, 64);
+                                sd_radv_remove_prefix(link->radv, &route->dst.in6, 64);
 
                         link_remove_dhcp_pd_subnet_prefix(link, &route->dst.in6);
 
@@ -212,7 +212,7 @@ int dhcp_pd_remove(Link *link, bool only_marked) {
                         in6_addr_mask(&prefix, 64);
 
                         if (link->radv)
-                                (void) sd_radv_remove_prefix(link->radv, &prefix, 64);
+                                sd_radv_remove_prefix(link->radv, &prefix, 64);
 
                         link_remove_dhcp_pd_subnet_prefix(link, &prefix);
 
index e604df1371853b29828504d14b71411f8411f5d5..6eeb92c48b1ddfb4f54167d0d0d9220ed005a1f0 100644 (file)
@@ -59,8 +59,7 @@ int sd_radv_set_other_information(sd_radv *ra, int other);
 int sd_radv_set_preference(sd_radv *ra, unsigned preference);
 int sd_radv_add_prefix(sd_radv *ra, sd_radv_prefix *p);
 int sd_radv_add_route_prefix(sd_radv *ra, sd_radv_route_prefix *p);
-sd_radv_prefix *sd_radv_remove_prefix(sd_radv *ra, const struct in6_addr *prefix,
-                                      unsigned char prefixlen);
+void sd_radv_remove_prefix(sd_radv *ra, const struct in6_addr *prefix, unsigned char prefixlen);
 int sd_radv_set_rdnss(sd_radv *ra, uint32_t lifetime,
                       const struct in6_addr *dns, size_t n_dns);
 int sd_radv_set_dnssl(sd_radv *ra, uint32_t lifetime, char **search_list);