- // Was only a solicitation: mark binding for removal
- if (assigned && a->valid_until < now) {
- a->valid_until = (msg == DHCPV4_MSG_DISCOVER) ? 0 :
- (now + iface->dhcpv4_leasetime);
+ if ((*leasetime == 0) || (my_leasetime < *leasetime))
+ *leasetime = my_leasetime;
+
+ if (assigned) {
+ if (msg == DHCPV4_MSG_DISCOVER) {
+ a->flags &= ~OAF_BOUND;
+
+ if (!(a->flags & OAF_STATIC))
+ a->valid_until = now;
+ } else {
+ if (hostname_len > 0) {
+ a->hostname = realloc(a->hostname, hostname_len + 1);
+ if (a->hostname) {
+ memcpy(a->hostname, hostname, hostname_len);
+ a->hostname[hostname_len] = 0;
+ }
+ }
+
+ a->flags |= OAF_BOUND;
+
+ if (!(a->flags & OAF_STATIC))
+ a->valid_until = ((*leasetime == UINT32_MAX) ? 0 : (time_t)(now + *leasetime));
+ }