Mercurial > hg > dhcpcd
changeset 4561:0c069664f375 draft
DHCP: Always add the leased address
This is needed so that the lifetimes are refreshed.
While here, set the pltime to the renewal time.
| author | Roy Marples <roy@marples.name> |
|---|---|
| date | Mon, 22 Jul 2019 13:34:10 +0100 |
| parents | 9745c72fc2eb |
| children | 559c1ce40f54 |
| files | src/dhcp.c src/ipv4.c |
| diffstat | 2 files changed, 9 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/src/dhcp.c Mon Jul 22 12:44:20 2019 +0100 +++ b/src/dhcp.c Mon Jul 22 13:34:10 2019 +0100 @@ -2347,7 +2347,7 @@ 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));
--- a/src/ipv4.c Mon Jul 22 12:44:20 2019 +0100 +++ b/src/ipv4.c Mon Jul 22 13:34:10 2019 +0100 @@ -685,7 +685,7 @@ 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 @@ struct dhcp_lease *lease; struct if_options *ifo = ifp->options; struct ipv4_addr *ia; - int r; if (state == NULL) return; @@ -728,25 +727,16 @@ 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) {
