diff --git a/src/libsystemd-network/sd-radv.c b/src/libsystemd-network/sd-radv.c index e332f6a2ab..c2f633a82b 100644 --- a/src/libsystemd-network/sd-radv.c +++ b/src/libsystemd-network/sd-radv.c @@ -578,8 +578,7 @@ int sd_radv_set_preference(sd_radv *ra, unsigned preference) { int sd_radv_add_prefix(sd_radv *ra, sd_radv_prefix *p) { _cleanup_free_ char *addr_p = NULL; - sd_radv_prefix *cur; - bool update = false; + sd_radv_prefix *cur, *found = NULL; int r; assert_return(ra, -EINVAL); @@ -604,7 +603,7 @@ int sd_radv_add_prefix(sd_radv *ra, sd_radv_prefix *p) { continue; if (cur->opt.prefixlen == p->opt.prefixlen) { - update = true; + found = cur; break; } @@ -615,15 +614,13 @@ int sd_radv_add_prefix(sd_radv *ra, sd_radv_prefix *p) { strna(addr_p), strna(addr_cur)); } - if (update) { - assert(cur); - + if (found) { /* p and cur may be equivalent. First increment the reference counter. */ sd_radv_prefix_ref(p); /* Then, remove the old entry. */ - LIST_REMOVE(prefix, ra->prefixes, cur); - sd_radv_prefix_unref(cur); + LIST_REMOVE(prefix, ra->prefixes, found); + sd_radv_prefix_unref(found); /* Finally, add the new entry. */ LIST_APPEND(prefix, ra->prefixes, p); @@ -659,15 +656,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; - LIST_FOREACH_SAFE(prefix, cur, next, ra->prefixes) { + if (!ra) + return; + + if (!prefix) + return; + + LIST_FOREACH(prefix, cur, ra->prefixes) { if (prefixlen != cur->opt.prefixlen) continue; @@ -677,17 +679,13 @@ 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) { _cleanup_free_ char *addr_p = NULL; - sd_radv_route_prefix *cur; - bool update = false; + sd_radv_route_prefix *cur, *found = NULL; int r; assert_return(ra, -EINVAL); @@ -708,7 +706,7 @@ int sd_radv_add_route_prefix(sd_radv *ra, sd_radv_route_prefix *p) { continue; if (cur->opt.prefixlen == p->opt.prefixlen) { - update = true; + found = cur; break; } @@ -719,15 +717,13 @@ int sd_radv_add_route_prefix(sd_radv *ra, sd_radv_route_prefix *p) { strna(addr_p), strna(addr_cur)); } - if (update) { - assert(cur); - + if (found) { /* p and cur may be equivalent. First increment the reference counter. */ sd_radv_route_prefix_ref(p); /* Then, remove the old entry. */ - LIST_REMOVE(prefix, ra->route_prefixes, cur); - sd_radv_route_prefix_unref(cur); + LIST_REMOVE(prefix, ra->route_prefixes, found); + sd_radv_route_prefix_unref(found); /* Finally, add the new entry. */ LIST_APPEND(prefix, ra->route_prefixes, p); @@ -762,8 +758,12 @@ int sd_radv_add_route_prefix(sd_radv *ra, sd_radv_route_prefix *p) { return 0; } -int sd_radv_set_rdnss(sd_radv *ra, uint32_t lifetime, - const struct in6_addr *dns, size_t n_dns) { +int sd_radv_set_rdnss( + sd_radv *ra, + uint32_t lifetime, + const struct in6_addr *dns, + size_t n_dns) { + _cleanup_free_ struct sd_radv_opt_dns *opt_rdnss = NULL; size_t len; @@ -796,8 +796,11 @@ int sd_radv_set_rdnss(sd_radv *ra, uint32_t lifetime, return 0; } -int sd_radv_set_dnssl(sd_radv *ra, uint32_t lifetime, - char **search_list) { +int sd_radv_set_dnssl( + sd_radv *ra, + uint32_t lifetime, + char **search_list) { + _cleanup_free_ struct sd_radv_opt_dns *opt_dnssl = NULL; size_t len = 0; char **s; @@ -876,8 +879,11 @@ int sd_radv_prefix_new(sd_radv_prefix **ret) { DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(sd_radv_prefix, sd_radv_prefix, mfree); -int sd_radv_prefix_set_prefix(sd_radv_prefix *p, const struct in6_addr *in6_addr, - unsigned char prefixlen) { +int sd_radv_prefix_set_prefix( + sd_radv_prefix *p, + const struct in6_addr *in6_addr, + unsigned char prefixlen) { + assert_return(p, -EINVAL); assert_return(in6_addr, -EINVAL); @@ -894,8 +900,11 @@ int sd_radv_prefix_set_prefix(sd_radv_prefix *p, const struct in6_addr *in6_addr return 0; } -int sd_radv_prefix_get_prefix(sd_radv_prefix *p, struct in6_addr *ret_in6_addr, - unsigned char *ret_prefixlen) { +int sd_radv_prefix_get_prefix( + sd_radv_prefix *p, + struct in6_addr *ret_in6_addr, + unsigned char *ret_prefixlen) { + assert_return(p, -EINVAL); assert_return(ret_in6_addr, -EINVAL); assert_return(ret_prefixlen, -EINVAL); @@ -914,8 +923,7 @@ int sd_radv_prefix_set_onlink(sd_radv_prefix *p, int onlink) { return 0; } -int sd_radv_prefix_set_address_autoconfiguration(sd_radv_prefix *p, - int address_autoconfiguration) { +int sd_radv_prefix_set_address_autoconfiguration(sd_radv_prefix *p, int address_autoconfiguration) { assert_return(p, -EINVAL); SET_FLAG(p->opt.flags, ND_OPT_PI_FLAG_AUTO, address_autoconfiguration); @@ -967,8 +975,11 @@ int sd_radv_route_prefix_new(sd_radv_route_prefix **ret) { DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(sd_radv_route_prefix, sd_radv_route_prefix, mfree); -int sd_radv_route_prefix_set_prefix(sd_radv_route_prefix *p, const struct in6_addr *in6_addr, - unsigned char prefixlen) { +int sd_radv_route_prefix_set_prefix( + sd_radv_route_prefix *p, + const struct in6_addr *in6_addr, + unsigned char prefixlen) { + assert_return(p, -EINVAL); assert_return(in6_addr, -EINVAL); diff --git a/src/network/networkd-dhcp-prefix-delegation.c b/src/network/networkd-dhcp-prefix-delegation.c index edc893e9f6..775acb3f95 100644 --- a/src/network/networkd-dhcp-prefix-delegation.c +++ b/src/network/networkd-dhcp-prefix-delegation.c @@ -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); diff --git a/src/systemd/sd-radv.h b/src/systemd/sd-radv.h index e604df1371..6eeb92c48b 100644 --- a/src/systemd/sd-radv.h +++ b/src/systemd/sd-radv.h @@ -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);