LEASE_ATTR_MAC,
LEASE_ATTR_DUID,
LEASE_ATTR_HOSTID,
+ LEASE_ATTR_LEASETIME,
LEASE_ATTR_NAME,
LEASE_ATTR_MAX
};
[LEASE_ATTR_MAC] = { .name = "mac", .type = BLOBMSG_TYPE_STRING },
[LEASE_ATTR_DUID] = { .name = "duid", .type = BLOBMSG_TYPE_STRING },
[LEASE_ATTR_HOSTID] = { .name = "hostid", .type = BLOBMSG_TYPE_STRING },
+ [LEASE_ATTR_LEASETIME] = { .name = "leasetime", .type = BLOBMSG_TYPE_STRING },
[LEASE_ATTR_NAME] = { .name = "name", .type = BLOBMSG_TYPE_STRING },
};
}
}
+static double parse_leasetime(struct blob_attr *c) {
+ char *val = blobmsg_get_string(c), *endptr;
+ double time = strtod(val, &endptr);
+ if (time && endptr[0]) {
+ if (endptr[0] == 's')
+ time *= 1;
+ else if (endptr[0] == 'm')
+ time *= 60;
+ else if (endptr[0] == 'h')
+ time *= 3600;
+ else if (endptr[0] == 'd')
+ time *= 24 * 3600;
+ else if (endptr[0] == 'w')
+ time *= 7 * 24 * 3600;
+ else
+ goto err;
+ }
+
+ if (time >= 60)
+ return time;
+
+ return 0;
+
+err:
+ return -1;
+}
static int set_lease(struct uci_section *s)
{
goto err;
}
+ if ((c = tb[LEASE_ATTR_LEASETIME])) {
+ double time = parse_leasetime(c);
+ if (time < 0)
+ goto err;
+
+ if (time >= 60)
+ lease->dhcpv4_leasetime = time;
+ }
+
list_add(&lease->head, &leases);
return 0;
iface->ignore = blobmsg_get_bool(c);
if ((c = tb[IFACE_ATTR_LEASETIME])) {
- char *val = blobmsg_get_string(c), *endptr;
- double time = strtod(val, &endptr);
- if (time && endptr[0]) {
- if (endptr[0] == 's')
- time *= 1;
- else if (endptr[0] == 'm')
- time *= 60;
- else if (endptr[0] == 'h')
- time *= 3600;
- else if (endptr[0] == 'd')
- time *= 24 * 3600;
- else if (endptr[0] == 'w')
- time *= 7 * 24 * 3600;
- else
- goto err;
- }
+ double time = parse_leasetime(c);
+ if (time < 0)
+ goto err;
if (time >= 60)
iface->dhcpv4_leasetime = time;
iface->ifname);
return -1;
}
+ if (lease->dhcpv4_leasetime >= 60)
+ a->leasetime = lease->dhcpv4_leasetime;
a->addr = ntohl(lease->ipaddr.s_addr);
memcpy(a->hwaddr, lease->mac.ether_addr_octet, sizeof(a->hwaddr));
memcpy(a->hostname, lease->hostname, hostlen);
if (lease) {
reply.yiaddr.s_addr = htonl(lease->addr);
- uint32_t val = htonl(iface->dhcpv4_leasetime);
+ uint32_t val;
+ uint32_t leasetime;
+
+ if (lease->leasetime >= 60) {
+ leasetime = lease->leasetime;
+ } else {
+ leasetime = iface->dhcpv4_leasetime;
+ }
+
+ val = htonl(leasetime);
dhcpv4_put(&reply, &cookie, DHCPV4_OPT_LEASETIME, 4, &val);
- val = htonl(500 * iface->dhcpv4_leasetime / 1000);
+ val = htonl(500 * leasetime / 1000);
dhcpv4_put(&reply, &cookie, DHCPV4_OPT_RENEW, 4, &val);
- val = htonl(875 * iface->dhcpv4_leasetime / 1000);
+ val = htonl(875 * leasetime / 1000);
dhcpv4_put(&reply, &cookie, DHCPV4_OPT_REBIND, 4, &val);
dhcpv4_put(&reply, &cookie, DHCPV4_OPT_NETMASK, 4, &ifnetmask.sin_addr);
a->head.prev->next = &a->head;
}
+ uint32_t leasetime;
+ if (a->leasetime) {
+ leasetime = a->leasetime;
+ } else {
+ leasetime = iface->dhcpv4_leasetime;
+ }
+
// 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);
+ (now + leasetime);
} else if (!assigned && a) { // Cleanup failed assignment
free(a);
a = NULL;
uint32_t addr;
time_t valid_until;
uint8_t hwaddr[6];
+ uint32_t leasetime;
char hostname[];
};
return -1;
}
+ if (lease->dhcpv4_leasetime > 0)
+ a->leasetime = lease->dhcpv4_leasetime;
+
a->clid_len = duid_len;
a->length = 128;
if (lease->hostid) {
datalen += sizeof(stat);
} else {
if (a) {
- uint32_t leasetime = iface->dhcpv4_leasetime;
+ uint32_t leasetime;
+ if (a->leasetime > 0) {
+ leasetime = a->leasetime;
+ } else {
+ leasetime = iface->dhcpv4_leasetime;
+ }
if (leasetime == 0)
leasetime = 3600;
else if (leasetime < 60)
ssize_t managed_size;
struct ustream_fd managed_sock;
+ uint32_t leasetime;
+
uint8_t clid_len;
uint8_t clid_data[];
};
struct ether_addr mac;
uint16_t duid_len;
uint8_t *duid;
+ uint32_t dhcpv4_leasetime;
char hostname[];
};