X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fodhcpd.git;a=blobdiff_plain;f=src%2Fdhcpv4.c;h=7695d6801a62b617d0eb63c2c59c995b15de510c;hp=5220edf61dd3f9f2d190632658403084224e13e4;hb=e05553099c47b92420c21ff30b07709dfa40a84a;hpb=3af23ad72888393a863d7be545d1bd5af99ca442;ds=sidebyside diff --git a/src/dhcpv4.c b/src/dhcpv4.c index 5220edf..7695d68 100644 --- a/src/dhcpv4.c +++ b/src/dhcpv4.c @@ -643,10 +643,17 @@ static struct dhcpv4_assignment* dhcpv4_lease(struct interface *iface, *leasetime = my_leasetime; if (assigned) { + bool is_discover = (msg == DHCPV4_MSG_DISCOVER); + if (!INFINITE_VALID(a->valid_until)) // Was only a discover; mark binding for removal - a->valid_until = ((msg == DHCPV4_MSG_DISCOVER) ? now : ((*leasetime == UINT32_MAX) ? + a->valid_until = (is_discover ? now : ((*leasetime == UINT32_MAX) ? 0 : (time_t)(now + *leasetime))); + + /* Mark assignment as bound */ + if (!is_discover) + a->flags |= OAF_BOUND; + } else if (!assigned && a) { // Cleanup failed assignment free(a); a = NULL; @@ -654,12 +661,19 @@ static struct dhcpv4_assignment* dhcpv4_lease(struct interface *iface, if (assigned && a) lease = a; - } else if (msg == DHCPV4_MSG_RELEASE) { - if (a && !INFINITE_VALID(a->valid_until)) + } else if (msg == DHCPV4_MSG_RELEASE && a) { + a->flags &= ~OAF_BOUND; + + if (!INFINITE_VALID(a->valid_until)) a->valid_until = now - 1; - } else if (msg == DHCPV4_MSG_DECLINE && a && !INFINITE_VALID(a->valid_until)) { - memset(a->hwaddr, 0, sizeof(a->hwaddr)); - a->valid_until = now + 3600; // Block address for 1h + + } else if (msg == DHCPV4_MSG_DECLINE && a) { + a->flags &= ~OAF_BOUND; + + if (!INFINITE_VALID(a->valid_until)) { + memset(a->hwaddr, 0, sizeof(a->hwaddr)); + a->valid_until = now + 3600; // Block address for 1h + } } dhcpv6_write_statefile();