X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fodhcpd.git;a=blobdiff_plain;f=src%2Fdhcpv4.c;h=509b09230c5431d8582d1debc3415c082ccddd13;hp=5220edf61dd3f9f2d190632658403084224e13e4;hb=4c89614ccf5d72ee0c0824e5050a8814748a32c3;hpb=371a80c7257d9207e242db15e257b12d4c0238b2 diff --git a/src/dhcpv4.c b/src/dhcpv4.c index 5220edf..509b092 100644 --- a/src/dhcpv4.c +++ b/src/dhcpv4.c @@ -181,6 +181,8 @@ int setup_dhcpv4_interface(struct interface *iface, bool enable) a->addr = ntohl(lease->ipaddr.s_addr); memcpy(a->hwaddr, lease->mac.ether_addr_octet, sizeof(a->hwaddr)); memcpy(a->hostname, lease->hostname, hostlen); + /* Static assignment */ + a->flags |= OAF_STATIC; /* Infinite valid */ a->valid_until = 0; @@ -643,10 +645,17 @@ static struct dhcpv4_assignment* dhcpv4_lease(struct interface *iface, *leasetime = my_leasetime; if (assigned) { - 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) ? - 0 : (time_t)(now + *leasetime))); + if (msg == DHCPV4_MSG_DISCOVER) { + a->flags &= ~OAF_BOUND; + + if (!(a->flags & OAF_STATIC)) + a->valid_until = now; + } else { + a->flags |= OAF_BOUND; + + if (!(a->flags & OAF_STATIC)) + a->valid_until = ((*leasetime == UINT32_MAX) ? 0 : (time_t)(now + *leasetime)); + } } else if (!assigned && a) { // Cleanup failed assignment free(a); a = NULL; @@ -654,12 +663,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 (!(a->flags & OAF_STATIC)) 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 (!(a->flags & OAF_STATIC)) { + memset(a->hwaddr, 0, sizeof(a->hwaddr)); + a->valid_until = now + 3600; // Block address for 1h + } } dhcpv6_write_statefile();