]> git.puffer.fish Git - matthieu/frr.git/commitdiff
vrrpd: use ipaddr_is_zero when needed
authorIgor Ryzhov <iryzhov@nfware.com>
Thu, 27 Jan 2022 18:05:40 +0000 (21:05 +0300)
committerIgor Ryzhov <iryzhov@nfware.com>
Thu, 27 Jan 2022 18:05:40 +0000 (21:05 +0300)
Replace custom implementation or call to ipaddr_isset with a call to
ipaddr_is_zero.

ipaddr_isset is not fully correct, because it's fine to have some
non-zero bytes at the end of the struct in case of IPv4 and the function
doesn't allow that.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
lib/ipaddr.h
vrrpd/vrrp_northbound.c

index a334ea969e84a43fe0aea489da8a5eb714052535..d7ab358afea794f45f7fd207c79386eded772df9 100644 (file)
@@ -136,15 +136,6 @@ static inline void ipv4_mapped_ipv6_to_ipv4(const struct in6_addr *in6,
        memcpy(in, (char *)in6 + 12, sizeof(struct in_addr));
 }
 
-/*
- * Check if a struct ipaddr has nonzero value
- */
-static inline bool ipaddr_isset(struct ipaddr *ip)
-{
-       static struct ipaddr a = {};
-       return (0 != memcmp(&a, ip, sizeof(struct ipaddr)));
-}
-
 /*
  * generic ordering comparison between IP addresses
  */
index f814963fe5407b7bc86b535dd47a2088a7f1548a..d25dc0a19780821036915837d1bd5ff1ae8e4f20 100644 (file)
@@ -246,11 +246,8 @@ lib_interface_vrrp_vrrp_group_v4_source_address_get_elem(
 {
        const struct vrrp_vrouter *vr = args->list_entry;
        struct yang_data *val = NULL;
-       struct ipaddr ip;
-
-       memset(&ip, 0x00, sizeof(ip));
 
-       if (memcmp(&vr->v4->src.ipaddr_v4, &ip.ipaddr_v4, sizeof(ip.ipaddr_v4)))
+       if (!ipaddr_is_zero(&vr->v4->src))
                val = yang_data_new_ip(args->xpath, &vr->v4->src);
 
        return val;
@@ -410,7 +407,7 @@ lib_interface_vrrp_vrrp_group_v6_source_address_get_elem(
        const struct vrrp_vrouter *vr = args->list_entry;
        struct yang_data *val = NULL;
 
-       if (ipaddr_isset(&vr->v6->src))
+       if (!ipaddr_is_zero(&vr->v6->src))
                val = yang_data_new_ip(args->xpath, &vr->v6->src);
 
        return val;