summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorHans Dedecker <dedeckeh@gmail.com>2017-02-19 22:00:38 +0100
committerHans Dedecker <dedeckeh@gmail.com>2017-02-19 22:15:57 +0100
commite437ce9422c2f92752be5b6b3fd453e099a98a7e (patch)
treed9a87c78ad54ad215c6bfb9210f73cd2c1d0a3a7
parent942fb33d3017e8769a7354ee008daf0f31a40fe2 (diff)
treewide: simplify dhcp leasetime checking
Set dhcp leasetim to 43200 seconds for all interfaces independant if dhcpv4 is enabled for an interface. Minimum allowed leasetime is 60 seconds when parsing leastime configuration; this allows to clean up the awkward leasetime checks on different places in the code Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
-rw-r--r--src/config.c13
-rw-r--r--src/dhcpv4.c9
-rw-r--r--src/dhcpv6-ia.c10
3 files changed, 10 insertions, 22 deletions
diff --git a/src/config.c b/src/config.c
index b621c75..df0cbc4 100644
--- a/src/config.c
+++ b/src/config.c
@@ -192,6 +192,7 @@ static void set_interface_defaults(struct interface *iface)
{
iface->managed = 1;
iface->learn_routes = 1;
+ iface->dhcpv4_leasetime = 43200;
iface->ra_maxinterval = 600;
iface->ra_mininterval = iface->ra_maxinterval/3;
iface->ra_lifetime = -1;
@@ -288,10 +289,10 @@ static double parse_leasetime(struct blob_attr *c) {
goto err;
}
- if (time >= 60)
- return time;
+ if (time < 60)
+ time = 60;
- return 0;
+ return time;
err:
return -1;
@@ -351,8 +352,7 @@ static int set_lease(struct uci_section *s)
if (time < 0)
goto err;
- if (time >= 60)
- lease->dhcpv4_leasetime = time;
+ lease->dhcpv4_leasetime = time;
}
list_add(&lease->head, &leases);
@@ -425,8 +425,7 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr
if (time < 0)
goto err;
- if (time >= 60)
- iface->dhcpv4_leasetime = time;
+ iface->dhcpv4_leasetime = time;
}
if ((c = tb[IFACE_ATTR_START])) {
diff --git a/src/dhcpv4.c b/src/dhcpv4.c
index 5ef99b1..81e537d 100644
--- a/src/dhcpv4.c
+++ b/src/dhcpv4.c
@@ -153,8 +153,7 @@ int setup_dhcpv4_interface(struct interface *iface, bool enable)
return -1;
}
- if (lease->dhcpv4_leasetime >= 60)
- a->leasetime = lease->dhcpv4_leasetime;
+ a->leasetime = lease->dhcpv4_leasetime;
a->addr = ntohl(lease->ipaddr.s_addr);
memcpy(a->hwaddr, lease->mac.ether_addr_octet, sizeof(a->hwaddr));
@@ -194,10 +193,6 @@ int setup_dhcpv4_interface(struct interface *iface, bool enable)
free_dhcpv4_assignment(a);
}
-
- if (iface->dhcpv4_leasetime < 60)
- iface->dhcpv4_leasetime = 43200;
-
iface->dhcpv4_event.uloop.fd = sock;
iface->dhcpv4_event.handle_dgram = handle_dhcpv4;
odhcpd_register(&iface->dhcpv4_event);
@@ -627,7 +622,7 @@ static struct dhcpv4_assignment* dhcpv4_lease(struct interface *iface,
assigned = dhcpv4_assign(iface, a, raddr);
}
- if (a->leasetime >= 60)
+ if (a->leasetime)
my_leasetime = a->leasetime;
else
my_leasetime = iface->dhcpv4_leasetime;
diff --git a/src/dhcpv6-ia.c b/src/dhcpv6-ia.c
index 84f368e..888634f 100644
--- a/src/dhcpv6-ia.c
+++ b/src/dhcpv6-ia.c
@@ -88,8 +88,7 @@ int setup_dhcpv6_ia_interface(struct interface *iface, bool enable)
return -1;
}
- if (lease->dhcpv4_leasetime > 0)
- a->leasetime = lease->dhcpv4_leasetime;
+ a->leasetime = lease->dhcpv4_leasetime;
a->clid_len = duid_len;
a->length = 128;
@@ -719,16 +718,11 @@ static size_t append_reply(uint8_t *buf, size_t buflen, uint16_t status,
} else {
if (a) {
uint32_t leasetime;
- if (a->leasetime > 0)
+ if (a->leasetime)
leasetime = a->leasetime;
else
leasetime = iface->dhcpv4_leasetime;
- if (leasetime == 0)
- leasetime = 3600;
- else if (leasetime < 60)
- leasetime = 60;
-
uint32_t pref = leasetime;
uint32_t valid = leasetime;