From: Roy Marples Date: Mon, 22 Jul 2019 12:34:10 +0000 (+0100) Subject: DHCP: Always add the leased address X-Git-Tag: v8.0.0~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=408059968c2ecee027ecfee90de592554fe4990f;p=thirdparty%2Fdhcpcd.git DHCP: Always add the leased address This is needed so that the lifetimes are refreshed. While here, set the pltime to the renewal time. --- diff --git a/src/dhcp.c b/src/dhcp.c index 812651a3..474f60c3 100644 --- a/src/dhcp.c +++ b/src/dhcp.c @@ -2347,7 +2347,7 @@ dhcp_arp_address(struct interface *ifp) get_lease(ifp, &l, state->offer, state->offer_len); /* Add the address now, let the kernel handle DAD. */ ipv4_addaddr(ifp, &l.addr, &l.mask, &l.brd, - l.leasetime, l.leasetime); + l.leasetime, l.renewaltime); } else loginfox("%s: waiting for DAD on %s", ifp->name, inet_ntoa(addr)); diff --git a/src/ipv4.c b/src/ipv4.c index 06a5dabf..793828cd 100644 --- a/src/ipv4.c +++ b/src/ipv4.c @@ -685,7 +685,7 @@ ipv4_daddaddr(struct interface *ifp, const struct dhcp_lease *lease) struct ipv4_addr *ia; ia = ipv4_addaddr(ifp, &lease->addr, &lease->mask, &lease->brd, - lease->leasetime, lease->leasetime); + lease->leasetime, lease->renewaltime); if (ia == NULL) return -1; @@ -703,7 +703,6 @@ ipv4_applyaddr(void *arg) struct dhcp_lease *lease; struct if_options *ifo = ifp->options; struct ipv4_addr *ia; - int r; if (state == NULL) return; @@ -728,25 +727,16 @@ ipv4_applyaddr(void *arg) return; } +#if __linux__ /* If the netmask or broadcast is different, re-add the addresss */ ia = ipv4_iffindaddr(ifp, &lease->addr, NULL); - if (ia && - ia->mask.s_addr == lease->mask.s_addr && - ia->brd.s_addr == lease->brd.s_addr) - logdebugx("%s: IP address %s already exists", - ifp->name, ia->saddr); - else { -#if __linux__ - /* Linux does not change netmask/broadcast address - * for re-added addresses, so we need to delete the old one - * first. */ - if (ia != NULL) - ipv4_deladdr(ia, 0); + if (ia != NULL && + (ia->mask.s_addr != lease->mask.s_addr || + ia->brd.s_addr != lease->brd.s_addr)) + ipv4_deladdr(ia, 0); #endif - r = ipv4_daddaddr(ifp, lease); - if (r == -1 && errno != EEXIST) - return; - } + if (ipv4_daddaddr(ifp, lease) == -1 && errno != EEXIST) + return; ia = ipv4_iffindaddr(ifp, &lease->addr, NULL); if (ia == NULL) {