]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/libsystemd-network/sd-radv.c
sd-radv: follow our usualy rule that destructors can take NULL
[thirdparty/systemd.git] / src / libsystemd-network / sd-radv.c
index ffe22faac30bfff9d7798e1ff7b1dec530c440d7..b45e80e4c167f212df1ee32bc4c156efdb91a508 100644 (file)
@@ -12,6 +12,7 @@
 #include "macro.h"
 #include "alloc-util.h"
 #include "dns-domain.h"
+#include "ether-addr-util.h"
 #include "event-util.h"
 #include "fd-util.h"
 #include "icmp6-util.h"
@@ -87,7 +88,8 @@ static void radv_reset(sd_radv *ra) {
 }
 
 static sd_radv *radv_free(sd_radv *ra) {
-        assert(ra);
+        if (!ra)
+                return NULL;
 
         while (ra->prefixes) {
                 sd_radv_prefix *p = ra->prefixes;
@@ -112,9 +114,7 @@ static sd_radv *radv_free(sd_radv *ra) {
 
 DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(sd_radv, sd_radv, radv_free);
 
-static int radv_send(sd_radv *ra, const struct in6_addr *dst,
-                     const uint32_t router_lifetime) {
-        static const struct ether_addr mac_zero = {};
+static int radv_send(sd_radv *ra, const struct in6_addr *dst, uint32_t router_lifetime) {
         sd_radv_prefix *p;
         struct sockaddr_in6 dst_addr = {
                 .sin6_family = AF_INET6,
@@ -146,11 +146,13 @@ static int radv_send(sd_radv *ra, const struct in6_addr *dst,
         usec_t time_now;
         int r;
 
+        assert(ra);
+
         r = sd_event_now(ra->event, clock_boottime_or_monotonic(), &time_now);
         if (r < 0)
                 return r;
 
-        if (dst && !in_addr_is_null(AF_INET6, (union in_addr_union*) dst))
+        if (dst && !IN6_IS_ADDR_UNSPECIFIED(dst))
                 dst_addr.sin6_addr = *dst;
 
         adv.nd_ra_type = ND_ROUTER_ADVERT;
@@ -163,7 +165,7 @@ static int radv_send(sd_radv *ra, const struct in6_addr *dst,
 
         /* MAC address is optional, either because the link does not use L2
            addresses or load sharing is desired. See RFC 4861, Section 4.2 */
-        if (memcmp(&mac_zero, &ra->mac_addr, sizeof(mac_zero))) {
+        if (!ether_addr_is_null(&ra->mac_addr)) {
                 opt_mac.slladdr = ra->mac_addr;
                 iov[msg.msg_iovlen].iov_base = &opt_mac;
                 iov[msg.msg_iovlen].iov_len = sizeof(opt_mac);