]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: use address_get() in address_exists()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 4 Dec 2020 08:29:16 +0000 (17:29 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 8 Dec 2020 03:41:07 +0000 (12:41 +0900)
And rename address_exists() to link_has_ipv6_address().

src/network/networkd-address.c
src/network/networkd-address.h
src/network/networkd-ndisc.c

index bc7e0a5b59536024984d9c18a46f10915c92452f..18eecf6c8a4f76a43f6205a82b535ede92990e63 100644 (file)
@@ -447,29 +447,23 @@ int address_get(Link *link, const Address *in, Address **ret) {
         return -ENOENT;
 }
 
-static bool address_exists_internal(Set *addresses, int family, const union in_addr_union *in_addr) {
-        Address *address;
+int link_has_ipv6_address(Link *link, const struct in6_addr *address) {
+        _cleanup_(address_freep) Address *a = NULL;
+        int r;
 
-        SET_FOREACH(address, addresses) {
-                if (address->family != family)
-                        continue;
-                if (in_addr_equal(address->family, &address->in_addr, in_addr))
-                        return true;
-        }
+        assert(link);
+        assert(address);
 
-        return false;
-}
+        r = address_new(&a);
+        if (r < 0)
+                return r;
 
-bool address_exists(Link *link, int family, const union in_addr_union *in_addr) {
-        assert(link);
-        assert(IN_SET(family, AF_INET, AF_INET6));
-        assert(in_addr);
+        /* address_compare_func() only compares the local address for IPv6 case. So, it is enough to
+         * set only family and the address. */
+        a->family = AF_INET6;
+        a->in_addr.in6 = *address;
 
-        if (address_exists_internal(link->addresses, family, in_addr))
-                return true;
-        if (address_exists_internal(link->addresses_foreign, family, in_addr))
-                return true;
-        return false;
+        return address_get(link, a, NULL) >= 0;
 }
 
 static int address_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
index 036ac7a5646a84adfcc62c4acc82a1b0bf589406..4764766996f735b613a2dcf700b84c8bdd918929 100644 (file)
@@ -49,7 +49,6 @@ typedef struct Address {
 int address_new(Address **ret);
 Address *address_free(Address *address);
 int address_get(Link *link, const Address *in, Address **ret);
-bool address_exists(Link *link, int family, const union in_addr_union *in_addr);
 int address_configure(const Address *address, Link *link, link_netlink_message_handler_t callback, bool update, Address **ret);
 int address_remove(const Address *address, Link *link, link_netlink_message_handler_t callback);
 bool address_equal(const Address *a1, const Address *a2);
@@ -63,6 +62,7 @@ int link_set_addresses(Link *link);
 int link_drop_addresses(Link *link);
 int link_drop_foreign_addresses(Link *link);
 bool link_address_is_dynamic(const Link *link, const Address *address);
+int link_has_ipv6_address(Link *link, const struct in6_addr *address);
 
 void ipv4_dad_unref(Link *link);
 int ipv4_dad_stop(Link *link);
index d2aa3db175fc79da8cf6407cfbc1c982ce6126bb..903c995e743e7a5931e0a04b81c7bcb6e8bac914 100644 (file)
@@ -483,7 +483,7 @@ static int ndisc_router_process_default(Link *link, sd_ndisc_router *rt) {
         if (r < 0)
                 return log_link_error_errno(link, r, "Failed to get gateway address from RA: %m");
 
-        if (address_exists(link, AF_INET6, &gateway)) {
+        if (link_has_ipv6_address(link, &gateway.in6) > 0) {
                 if (DEBUG_LOGGING) {
                         _cleanup_free_ char *buffer = NULL;