diff options
author | Nick Hainke <vincent@systemli.org> | 2021-01-02 23:27:03 +0100 |
---|---|---|
committer | Hans Dedecker <dedeckeh@gmail.com> | 2021-01-03 15:42:49 +0100 |
commit | 3bda90079ec5574ef469e2a7804808302f17769d (patch) | |
tree | a3a7e8ce9f1f25d211838631b31d587f9f293205 /src/dhcpv6-ia.c | |
parent | b75bcad7bd5fd03f64011a532b9960d78e4aac22 (diff) |
odhcpd: add option for setting preferred lifetime
"valid_lft" and "preferred_lft" are different. If the "preferred_lft"
is expired the prefix should be avoided in source prefix selection.
However, the interface is allowed to still receive downstream traffic.
preferred_lfetime:
Limit for preferred lifetime of a prefix
If you want the old behavior, you have to set preferred_lifetime to
the same value as leasetime.
Signed-off-by: Nick Hainke <vincent@systemli.org>
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
Diffstat (limited to 'src/dhcpv6-ia.c')
-rw-r--r-- | src/dhcpv6-ia.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/dhcpv6-ia.c b/src/dhcpv6-ia.c index d7848de..a59fc20 100644 --- a/src/dhcpv6-ia.c +++ b/src/dhcpv6-ia.c @@ -247,6 +247,9 @@ void dhcpv6_ia_enum_addrs(struct interface *iface, struct dhcp_assignment *c, addr.s6_addr32[2] = addr.s6_addr32[3] = 0; } + if (pref > (uint32_t)c->preferred_until) + pref = c->preferred_until; + if (pref > (uint32_t)c->valid_until) pref = c->valid_until; @@ -827,14 +830,16 @@ static size_t build_ia(uint8_t *buf, size_t buflen, uint16_t status, } if (a) { - uint32_t leasetime; + uint32_t leasetime, pref; - if (a->leasetime) + if (a->leasetime) { leasetime = a->leasetime; - else + pref = a->leasetime; + } else { leasetime = iface->dhcp_leasetime; + pref = iface->preferred_lifetime; + } - uint32_t pref = leasetime; uint32_t valid = leasetime; struct odhcpd_ipaddr *addrs = (a->managed) ? a->managed : iface->addr6; @@ -851,8 +856,8 @@ 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_pref > pref) + prefix_pref = pref; if (prefix_valid != UINT32_MAX) prefix_valid -= now; @@ -918,6 +923,10 @@ static size_t build_ia(uint8_t *buf, size_t buflen, uint16_t status, /* UINT32_MAX is considered as infinite leasetime */ a->valid_until = (valid == UINT32_MAX) ? 0 : valid + now; + if (!INFINITE_VALID(a->preferred_until)) + /* UINT32_MAX is considered as infinite leasetime */ + a->preferred_until = (pref == UINT32_MAX) ? 0 : pref + now; + o_ia.t1 = htonl((pref == UINT32_MAX) ? pref : pref * 5 / 10); o_ia.t2 = htonl((pref == UINT32_MAX) ? pref : pref * 8 / 10); @@ -1261,6 +1270,7 @@ ssize_t dhcpv6_ia_handle_IAs(uint8_t *buf, size_t buflen, struct interface *ifac a->peer = *addr; a->assigned = is_na && l ? l->hostid : reqhint; a->valid_until = now; + a->preferred_until = now; a->dhcp_free_cb = dhcpv6_ia_free_assignment; a->iface = iface; a->flags = (is_pd ? OAF_DHCPV6_PD : OAF_DHCPV6_NA); |