]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: introduce callback called when an address becomes ready
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 21 Jul 2020 14:02:35 +0000 (23:02 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 28 Jul 2020 17:05:00 +0000 (02:05 +0900)
src/network/networkd-address.c
src/network/networkd-address.h

index 048d3ff183e82341234f953c6f253f3d453c4032..216c425b3432cfa3e40848b519ca748591c9032e 100644 (file)
@@ -359,15 +359,21 @@ int address_update(
         link_update_operstate(address->link, true);
         link_check_ready(address->link);
 
-        if (!ready &&
-            address_is_ready(address) &&
-            address->family == AF_INET6 &&
-            in_addr_is_link_local(AF_INET6, &address->in_addr) > 0 &&
-            in_addr_is_null(AF_INET6, (const union in_addr_union*) &address->link->ipv6ll_address) > 0) {
+        if (!ready && address_is_ready(address)) {
+                if (address->callback) {
+                        r = address->callback(address);
+                        if (r < 0)
+                                return r;
+                }
 
-                r = link_ipv6ll_gained(address->link, &address->in_addr.in6);
-                if (r < 0)
-                        return r;
+                if (address->family == AF_INET6 &&
+                    in_addr_is_link_local(AF_INET6, &address->in_addr) > 0 &&
+                    IN6_IS_ADDR_UNSPECIFIED(&address->link->ipv6ll_address) > 0) {
+
+                        r = link_ipv6ll_gained(address->link, &address->in_addr.in6);
+                        if (r < 0)
+                                return r;
+                }
         }
 
         return 0;
index d55059ee252edfbddf65a0fad5bb56bef51fd5de..18d25465530075db24fa39425b1c4a160d94ed79 100644 (file)
@@ -20,6 +20,7 @@ typedef struct Address Address;
 typedef struct Network Network;
 typedef struct Link Link;
 typedef struct NetworkConfigSection NetworkConfigSection;
+typedef int (*address_ready_callback_t)(Address *address);
 
 struct Address {
         Network *network;
@@ -47,6 +48,9 @@ struct Address {
         bool autojoin:1;
         AddressFamily duplicate_address_detection;
 
+        /* Called when address become ready */
+        address_ready_callback_t callback;
+
         sd_ipv4acd *acd;
 
         LIST_FIELDS(Address, addresses);