networkd: address - factor out address_update()

Call back into link_check_ready() whenever an address state change may have
made a link ready.
This commit is contained in:
Tom Gundersen 2015-09-28 17:16:12 +02:00
parent 8012cd3919
commit 36c32f6120
5 changed files with 31 additions and 22 deletions

View 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;

View 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);

View 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;

View 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;

View 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: