summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorHans Dedecker <dedeckeh@gmail.com>2020-01-14 21:16:48 +0100
committerHans Dedecker <dedeckeh@gmail.com>2020-01-16 20:29:53 +0100
commit6db312a698e920ff61505ef1f42469880829774d (patch)
treed127942181b46c8c4efc6ff7dcc63acbef6731c7
parent2520c483781339f6c7feae617b7e5c0137e3534d (diff)
dhcpv6-ia: use dhcp leasetime to set preferred/valid statefull lifetimes
Allow to set the preferred/valid lifetimes of IA_NA/IA_PD options based on the configured dhcp leasetime. DHCP leqasetime will be used to set the preferred/valid lifetimes in the IA_NA/IA_PD options unless the preferred/valid lifetimes of the IPv6 address are smaller then the DHCP leasetime. This will avoid IA_NA/IA_PD options being sent with infinite lifetimes due to the IPv6 address having infinite preferred/valid lifetimes like IPv6 ULA addresses. While at it rename dhcpv4_leasetime into dhcp_leasetime as the leasetime is used both for DHCPv4 and DHCPv6 Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
-rw-r--r--src/config.c4
-rw-r--r--src/dhcpv4.c2
-rw-r--r--src/dhcpv6-ia.c8
-rw-r--r--src/odhcpd.h4
-rw-r--r--src/router.c8
5 files changed, 17 insertions, 9 deletions
diff --git a/src/config.c b/src/config.c
index f3ba3e8..3d41e13 100644
--- a/src/config.c
+++ b/src/config.c
@@ -229,7 +229,7 @@ static void set_interface_defaults(struct interface *iface)
iface->ra = MODE_DISABLED;
iface->ndp = MODE_DISABLED;
iface->learn_routes = 1;
- iface->dhcpv4_leasetime = 43200;
+ iface->dhcp_leasetime = 43200;
iface->dhcpv4_start.s_addr = htonl(START_DEFAULT);
iface->dhcpv4_end.s_addr = htonl(START_DEFAULT + LIMIT_DEFAULT - 1);
iface->dhcpv6_assignall = true;
@@ -547,7 +547,7 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr
if (time < 0)
goto err;
- iface->dhcpv4_leasetime = time;
+ iface->dhcp_leasetime = time;
}
if ((c = tb[IFACE_ATTR_START])) {
diff --git a/src/dhcpv4.c b/src/dhcpv4.c
index 1deb097..24a4fea 100644
--- a/src/dhcpv4.c
+++ b/src/dhcpv4.c
@@ -1072,7 +1072,7 @@ dhcpv4_lease(struct interface *iface, enum dhcpv4_msg msg, const uint8_t *mac,
if (a->leasetime)
my_leasetime = a->leasetime;
else
- my_leasetime = iface->dhcpv4_leasetime;
+ my_leasetime = iface->dhcp_leasetime;
if ((*leasetime == 0) || (my_leasetime < *leasetime))
*leasetime = my_leasetime;
diff --git a/src/dhcpv6-ia.c b/src/dhcpv6-ia.c
index ee0acaf..d8187ff 100644
--- a/src/dhcpv6-ia.c
+++ b/src/dhcpv6-ia.c
@@ -823,7 +823,7 @@ static size_t build_ia(uint8_t *buf, size_t buflen, uint16_t status,
if (a->leasetime)
leasetime = a->leasetime;
else
- leasetime = iface->dhcpv4_leasetime;
+ leasetime = iface->dhcp_leasetime;
uint32_t pref = leasetime;
uint32_t valid = leasetime;
@@ -842,9 +842,15 @@ static size_t build_ia(uint8_t *buf, size_t buflen, uint16_t status,
if (prefix_pref != UINT32_MAX)
prefix_pref -= now;
+ if (prefix_pref > leasetime)
+ prefix_pref = leasetime;
+
if (prefix_valid != UINT32_MAX)
prefix_valid -= now;
+ if (prefix_valid > leasetime)
+ prefix_valid = leasetime;
+
if (a->flags & OAF_DHCPV6_PD) {
struct dhcpv6_ia_prefix o_ia_p = {
.type = htons(DHCPV6_OPT_IA_PREFIX),
diff --git a/src/odhcpd.h b/src/odhcpd.h
index ae4826e..072a148 100644
--- a/src/odhcpd.h
+++ b/src/odhcpd.h
@@ -272,6 +272,9 @@ struct interface {
uint32_t ra_hoplimit;
int ra_mtu;
+ // DHCP
+ uint32_t dhcp_leasetime;
+
// DHCPv4
struct in_addr dhcpv4_start;
struct in_addr dhcpv4_end;
@@ -284,7 +287,6 @@ struct interface {
size_t dhcpv4_router_cnt;
struct in_addr *dhcpv4_dns;
size_t dhcpv4_dns_cnt;
- uint32_t dhcpv4_leasetime;
bool dhcpv4_forcereconf;
// DNS
diff --git a/src/router.c b/src/router.c
index 7c97672..295bdfb 100644
--- a/src/router.c
+++ b/src/router.c
@@ -552,13 +552,13 @@ static int send_router_advert(struct interface *iface, const struct in6_addr *fr
preferred = TIME_LEFT(addr->preferred, now);
if (iface->ra_useleasetime &&
- preferred > iface->dhcpv4_leasetime)
- preferred = iface->dhcpv4_leasetime;
+ preferred > iface->dhcp_leasetime)
+ preferred = iface->dhcp_leasetime;
}
valid = TIME_LEFT(addr->valid, now);
- if (iface->ra_useleasetime && valid > iface->dhcpv4_leasetime)
- valid = iface->dhcpv4_leasetime;
+ if (iface->ra_useleasetime && valid > iface->dhcp_leasetime)
+ valid = iface->dhcp_leasetime;
if (minvalid > valid)
minvalid = valid;