]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
networkd: address - factor out address_update()
authorTom Gundersen <teg@jklm.no>
Mon, 28 Sep 2015 15:16:12 +0000 (17:16 +0200)
committerTom Gundersen <teg@jklm.no>
Wed, 21 Oct 2015 00:35:31 +0000 (02:35 +0200)
Call back into link_check_ready() whenever an address state change may have
made a link ready.

src/network/networkd-address.c
src/network/networkd-address.h
src/network/networkd-dhcp4.c
src/network/networkd-dhcp6.c
src/network/networkd-manager.c

index f1b364f40ed91a3b0244ace0d6a4a06346026b9e..98ff027536ae7548b3e493e62a49b27c40b9cb5c 100644 (file)
@@ -282,6 +282,24 @@ static int address_release(Address *address, Link *link) {
         return 0;
 }
 
+int address_update(Address *address, unsigned char flags, unsigned char scope, struct ifa_cacheinfo *cinfo) {
+        bool ready;
+
+        assert(address);
+        assert(cinfo);
+
+        ready = address_is_ready(address);
+
+        address->flags = flags;
+        address->scope = scope;
+        address->cinfo = *cinfo;
+
+        if (!ready && address_is_ready(address) && address->link)
+                link_check_ready(address->link);
+
+        return 0;
+}
+
 int address_drop(Address *address) {
         Link *link;
         bool ready;
@@ -359,7 +377,7 @@ int address_remove(Address *address, Link *link,
         return 0;
 }
 
-int address_update(Address *address, Link *link,
+int address_change(Address *address, Link *link,
                    sd_netlink_message_handler_t callback) {
         _cleanup_netlink_message_unref_ sd_netlink_message *req = NULL;
         int r;
index 425344fe48e0cd9b62be1853ea4c164173b603a2..07a7ad20264eccbc1909e1305bc3bf0e2d76c792 100644 (file)
@@ -62,9 +62,10 @@ int address_new(Address **ret);
 void address_free(Address *address);
 int address_add(Link *link, int family, const union in_addr_union *in_addr, unsigned char prefixlen, Address **ret);
 int address_get(Link *link, int family, const union in_addr_union *in_addr, unsigned char prefixlen, Address **ret);
+int address_update(Address *address, unsigned char flags, unsigned char scope, struct ifa_cacheinfo *cinfo);
 int address_drop(Address *address);
 int address_configure(Address *address, Link *link, sd_netlink_message_handler_t callback);
-int address_update(Address *address, Link *link, sd_netlink_message_handler_t callback);
+int address_change(Address *address, Link *link, sd_netlink_message_handler_t callback);
 int address_remove(Address *address, Link *link, sd_netlink_message_handler_t callback);
 bool address_equal(Address *a1, Address *a2);
 bool address_is_ready(const Address *a);
index e2f7d696667b7ebc77a5775fbf74418e00853d09..5c91d9609fb14c87c40b9767c20a11e9e8ed708b 100644 (file)
@@ -299,9 +299,9 @@ static int dhcp4_update_address(Link *link,
         addr->prefixlen = prefixlen;
         addr->broadcast.s_addr = address->s_addr | ~netmask->s_addr;
 
-        /* use update rather than configure so that we will update the
+        /* use change rather than configure so that we will update the
          * lifetime of an existing address if it has already been configured */
-        r = address_update(addr, link, &dhcp4_address_handler);
+        r = address_change(addr, link, &dhcp4_address_handler);
         if (r < 0)
                 return r;
 
index 8115232e1da130749efd14570e547d8014a9d9af..95cdb80b0abb0448c8c4e24ab09e3eb61311c583 100644 (file)
@@ -63,7 +63,7 @@ static int dhcp6_address_handler(sd_netlink *rtnl, sd_netlink_message *m,
         return 1;
 }
 
-static int dhcp6_address_update(Link *link, struct in6_addr *ip6_addr,
+static int dhcp6_address_change(Link *link, struct in6_addr *ip6_addr,
                                 uint8_t prefixlen, uint32_t lifetime_preferred,
                                 uint32_t lifetime_valid) {
         int r;
@@ -87,7 +87,7 @@ static int dhcp6_address_update(Link *link, struct in6_addr *ip6_addr,
                       SD_ICMP6_ND_ADDRESS_FORMAT_VAL(addr->in_addr.in6),
                       addr->prefixlen, lifetime_preferred, lifetime_valid);
 
-        r = address_update(addr, link, dhcp6_address_handler);
+        r = address_change(addr, link, dhcp6_address_handler);
         if (r < 0)
                 log_link_warning_errno(link, r, "Could not assign DHCPv6 address: %m");
 
@@ -121,7 +121,7 @@ static int dhcp6_lease_address_acquired(sd_dhcp6_client *client, Link *link) {
                 if (r == -EADDRNOTAVAIL)
                         prefixlen = 128;
 
-                r = dhcp6_address_update(link, &ip6_addr, prefixlen,
+                r = dhcp6_address_change(link, &ip6_addr, prefixlen,
                                         lifetime_preferred, lifetime_valid);
                 if (r < 0)
                         return r;
@@ -300,7 +300,7 @@ static int dhcp6_prefix_expired(Link *link) {
 
                 log_link_info(link, "IPv6 prefix length updated "SD_ICMP6_ND_ADDRESS_FORMAT_STR"/%d", SD_ICMP6_ND_ADDRESS_FORMAT_VAL(ip6_addr), 128);
 
-                dhcp6_address_update(link, &ip6_addr, 128, lifetime_preferred, lifetime_valid);
+                dhcp6_address_change(link, &ip6_addr, 128, lifetime_preferred, lifetime_valid);
         }
 
         return 0;
index 2cd4f4fef7677efecabf3a1674704947d11a0d0b..9a7e71fce8082fff8e30351b655bf21388243731 100644 (file)
@@ -397,29 +397,19 @@ int manager_rtnl_process_address(sd_netlink *rtnl, sd_netlink_message *message,
 
         switch (type) {
         case RTM_NEWADDR:
-                if (address) {
+                if (address)
                         log_link_debug(link, "Updating address: %s/%u (valid for %s)", buf, prefixlen, valid_str);
-
-                        address->scope = scope;
-                        address->flags = flags;
-                        address->cinfo = cinfo;
-
-                        link_check_ready(link);
-                } else {
+                else {
                         r = address_add(link, family, &in_addr, prefixlen, &address);
                         if (r < 0) {
                                 log_link_warning_errno(link, r, "Failed to add address %s/%u: %m", buf, prefixlen);
                                 return 0;
                         } else
                                 log_link_debug(link, "Adding address: %s/%u (valid for %s)", buf, prefixlen, valid_str);
-
-                        address->scope = scope;
-                        address->flags = flags;
-                        address->cinfo = cinfo;
-
-                        link_check_ready(link);
                 }
 
+                address_update(address, scope, flags, &cinfo);
+
                 break;
 
         case RTM_DELADDR: