Skip to content

Commit

Permalink
ifconfig: apply address lease priorities same as for routes
Browse files Browse the repository at this point in the history
This effectively allows dhcp6 to takeover addresses guessed
auto6, e.g. after restart and lifetime updates on renewal.
  • Loading branch information
mtomaschewski committed Sep 19, 2014
1 parent 8c370f8 commit ceb0b6a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/ifconfig.c
Expand Up @@ -3234,6 +3234,7 @@ __ni_netdev_update_addrs(ni_netdev_t *dev,
ni_addrconf_mode_t old_type = NI_ADDRCONF_NONE;
unsigned int family = AF_UNSPEC;
ni_address_t *ap, *next;
unsigned int minprio;
int rv;

do {
Expand Down Expand Up @@ -3269,6 +3270,8 @@ __ni_netdev_update_addrs(ni_netdev_t *dev,
* is ours now. */
ap->owner = old_type;
}
minprio = ni_addrconf_lease_get_priority(ni_netdev_get_lease(dev,
ap->family, ap->owner));

/* If the address was managed by us (ie its owned by a lease with
* the same family/addrconf mode), then we want to check whether
Expand All @@ -3279,7 +3282,7 @@ __ni_netdev_update_addrs(ni_netdev_t *dev,
if (ap->owner == old_type) {
ni_addrconf_lease_t *other;

if ((other = __ni_netdev_address_to_lease(dev, ap)) != NULL)
if ((other = __ni_netdev_address_to_lease(dev, ap, minprio)) != NULL)
ap->owner = other->type;
}

Expand Down
2 changes: 1 addition & 1 deletion src/iflist.c
Expand Up @@ -1838,7 +1838,7 @@ __ni_netdev_process_newaddr_event(ni_netdev_t *dev, struct nlmsghdr *h, struct i
if (ap->owner == NI_ADDRCONF_NONE) {
ni_addrconf_lease_t *lease;

if ((lease = __ni_netdev_address_to_lease(dev, ap)))
if ((lease = __ni_netdev_address_to_lease(dev, ap, 0)))
ap->owner = lease->type;
}

Expand Down
19 changes: 15 additions & 4 deletions src/netdev.c
Expand Up @@ -733,16 +733,27 @@ ni_netdev_get_lease_by_owner(ni_netdev_t *dev, const char *owner)
* Given an address, look up the lease owning it
*/
ni_addrconf_lease_t *
__ni_netdev_address_to_lease(ni_netdev_t *dev, const ni_address_t *ap)
__ni_netdev_address_to_lease(ni_netdev_t *dev, const ni_address_t *ap, unsigned int minprio)
{
ni_addrconf_lease_t *lease;
ni_addrconf_lease_t *found = NULL;
unsigned int prio;

for (lease = dev->leases; lease; lease = lease->next) {
if (__ni_lease_owns_address(lease, ap))
return lease;
if (ap->family != lease->family)
continue;

if ((prio = ni_addrconf_lease_get_priority(lease)) < minprio)
continue;

if (!__ni_lease_owns_address(lease, ap))
continue;

if (!found || prio > ni_addrconf_lease_get_priority(found))
found = lease;
}

return NULL;
return found;
}

ni_bool_t
Expand Down
2 changes: 1 addition & 1 deletion src/netinfo_priv.h
Expand Up @@ -45,7 +45,7 @@ extern ni_bool_t __ni_linkinfo_kind_to_type(const char *, ni_iftype_t *);
extern void __ni_netdev_list_append(ni_netdev_t **, ni_netdev_t *);
extern void __ni_netdev_list_destroy(ni_netdev_t **);
extern ni_addrconf_lease_t *__ni_netdev_find_lease(ni_netdev_t *, unsigned int, ni_addrconf_mode_t, int);
extern ni_addrconf_lease_t *__ni_netdev_address_to_lease(ni_netdev_t *, const ni_address_t *);
extern ni_addrconf_lease_t *__ni_netdev_address_to_lease(ni_netdev_t *, const ni_address_t *, unsigned int);
extern ni_addrconf_lease_t *__ni_netdev_route_to_lease(ni_netdev_t *, const ni_route_t *, unsigned int);
extern void __ni_netdev_track_ipv6_autoconf(ni_netdev_t *, int);
extern unsigned int __ni_netdev_translate_ifflags(unsigned int, unsigned int);
Expand Down

0 comments on commit ceb0b6a

Please sign in to comment.