diff mbox series

[RFC,06/14] config: implement RFC4861 AdvValidLifetime (make configurable)

Message ID 20240509223213.97389-7-newtwen+github@gmail.com
State New
Headers show
Series odhcpd config value clamping | expand

Commit Message

Paul Donald May 9, 2024, 10:30 p.m. UTC
From: Paul Donald <newtwen@gmail.com>

In accordance with RFC4861. Enables control of ULA.

The new config variable is valid_lifetime. e.g.:

config dhcp 'lan'
        ...
        option valid_lifetime '6h'

Signed-off-by: Paul Donald <newtwen@gmail.com>
---
 README       |  2 ++
 src/config.c | 14 ++++++++++++++
 src/odhcpd.h |  1 +
 3 files changed, 17 insertions(+)
diff mbox series

Patch

diff --git a/README b/README
index c8f2eb4..4d1956c 100644
--- a/README
+++ b/README
@@ -155,6 +155,8 @@  prefix_filter		string	::/0			Only advertise on-link prefixes within
 							filtered out.
 ntp			list	<local address>		NTP servers to announce
 							accepts IPv4 and IPv6
+valid_lifetime		string	30d			Value for the valid lifetime
+							for a prefix
 
 
 Sections of type host (static leases)
diff --git a/src/config.c b/src/config.c
index a3bf1ba..285e3a1 100644
--- a/src/config.c
+++ b/src/config.c
@@ -93,6 +93,7 @@  enum {
 	IFACE_ATTR_NDPROXY_SLAVE,
 	IFACE_ATTR_PREFIX_FILTER,
 	IFACE_ATTR_PREFERRED_LIFETIME,
+	IFACE_ATTR_VALID_LIFETIME,
 	IFACE_ATTR_NTP,
 	IFACE_ATTR_MAX
 };
@@ -146,6 +147,7 @@  static const struct blobmsg_policy iface_attrs[IFACE_ATTR_MAX] = {
 	[IFACE_ATTR_NDPROXY_SLAVE] = { .name = "ndproxy_slave", .type = BLOBMSG_TYPE_BOOL },
 	[IFACE_ATTR_PREFIX_FILTER] = { .name = "prefix_filter", .type = BLOBMSG_TYPE_STRING },
 	[IFACE_ATTR_PREFERRED_LIFETIME] = { .name = "preferred_lifetime", .type = BLOBMSG_TYPE_STRING },
+	[IFACE_ATTR_VALID_LIFETIME] = { .name = "valid_lifetime", .type = BLOBMSG_TYPE_STRING },
 	[IFACE_ATTR_NTP] = { .name = "ntp", .type = BLOBMSG_TYPE_ARRAY },
 };
 
@@ -217,6 +219,7 @@  static void set_interface_defaults(struct interface *iface)
 	iface->learn_routes = 1;
 	iface->dhcp_leasetime = 43200;
 	iface->preferred_lifetime = 604800; /* rfc4861#section-6.2.1: AdvPreferredLifetime 7 days */
+	iface->valid_lifetime = 2592000; /* rfc4861#section-6.2.1: AdvValidLifetime 30 days */
 	iface->dhcpv4_start.s_addr = htonl(START_DEFAULT);
 	iface->dhcpv4_end.s_addr = htonl(START_DEFAULT + LIMIT_DEFAULT - 1);
 	iface->dhcpv6_assignall = true;
@@ -659,6 +662,17 @@  int config_parse_interface(void *data, size_t len, const char *name, bool overwr
 
 	}
 
+	if ((c = tb[IFACE_ATTR_VALID_LIFETIME])) {
+		uint32_t time = (uint32_t)parse_leasetime(c);
+
+		if (time >= 0)
+			iface->valid_lifetime = time;
+		else
+			syslog(LOG_ERR, "Invalid %s value configured for interface '%s'",
+				   iface_attrs[IFACE_ATTR_VALID_LIFETIME].name, iface->name);
+
+	}
+
 	if ((c = tb[IFACE_ATTR_START])) {
 		iface->dhcpv4_start.s_addr = htonl(blobmsg_get_u32(c));
 		iface->dhcpv4_end.s_addr = htonl(ntohl(iface->dhcpv4_start.s_addr) +
diff --git a/src/odhcpd.h b/src/odhcpd.h
index fecd77e..ddbc6b3 100644
--- a/src/odhcpd.h
+++ b/src/odhcpd.h
@@ -320,6 +320,7 @@  struct interface {
 	uint32_t ra_hoplimit;
 	int ra_mtu;
 	uint32_t preferred_lifetime;
+	uint32_t valid_lifetime;
 
 	// DHCP
 	uint32_t dhcp_leasetime;