-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Nicholas Sun <nicholas-sun@outlook.com>
- Loading branch information
1 parent
cc33831
commit 3e08e24
Showing
4 changed files
with
163 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
145 changes: 145 additions & 0 deletions
145
PATCH/odhcpd/001-config-allow-configuring-limit-of-min-and-max-value.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
From 4c2bb6b71b0b7d4d9a2ca5796b320aaa4516c1bb Mon Sep 17 00:00:00 2001 | ||
Date: Sat, 16 Sep 2023 15:04:12 +0000 | ||
Subject: [PATCH] config: allow configuring limit of min and max value for | ||
preferred and valid lifetime | ||
|
||
--- | ||
src/config.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ | ||
src/dhcpv6-ia.c | 16 ++++++++++++++++ | ||
src/odhcpd.h | 4 ++++ | ||
src/router.c | 16 ++++++++++++++++ | ||
4 files changed, 83 insertions(+) | ||
|
||
--- a/src/config.c | ||
+++ b/src/config.c | ||
@@ -92,6 +92,10 @@ enum { | ||
IFACE_ATTR_NDPROXY_SLAVE, | ||
IFACE_ATTR_PREFIX_FILTER, | ||
IFACE_ATTR_PREFERRED_LIFETIME, | ||
+ IFACE_ATTR_MIN_PREFERRED_LIFETIME, | ||
+ IFACE_ATTR_MAX_PREFERRED_LIFETIME, | ||
+ IFACE_ATTR_MIN_VALID_LIFETIME, | ||
+ IFACE_ATTR_MAX_VALID_LIFETIME, | ||
IFACE_ATTR_NTP, | ||
IFACE_ATTR_MAX | ||
}; | ||
@@ -145,6 +149,10 @@ static const struct blobmsg_policy iface | ||
[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_MIN_PREFERRED_LIFETIME] = { .name = "min_preferred_lifetime", .type = BLOBMSG_TYPE_STRING }, | ||
+ [IFACE_ATTR_MAX_PREFERRED_LIFETIME] = { .name = "max_preferred_lifetime", .type = BLOBMSG_TYPE_STRING }, | ||
+ [IFACE_ATTR_MIN_VALID_LIFETIME] = { .name = "min_valid_lifetime", .type = BLOBMSG_TYPE_STRING }, | ||
+ [IFACE_ATTR_MAX_VALID_LIFETIME] = { .name = "max_valid_lifetime", .type = BLOBMSG_TYPE_STRING }, | ||
[IFACE_ATTR_NTP] = { .name = "ntp", .type = BLOBMSG_TYPE_ARRAY }, | ||
}; | ||
|
||
@@ -648,6 +656,45 @@ int config_parse_interface(void *data, s | ||
|
||
} | ||
|
||
+ if ((c = tb[IFACE_ATTR_MIN_PREFERRED_LIFETIME])) { | ||
+ double time = parse_leasetime(c); | ||
+ | ||
+ if (time >= 0) | ||
+ iface->min_preferred_lifetime = time; | ||
+ else | ||
+ syslog(LOG_ERR, "Invalid %s value configured for interface '%s'", | ||
+ iface_attrs[IFACE_ATTR_MIN_PREFERRED_LIFETIME].name, iface->name); | ||
+ } | ||
+ | ||
+ if ((c = tb[IFACE_ATTR_MAX_PREFERRED_LIFETIME])) { | ||
+ double time = parse_leasetime(c); | ||
+ | ||
+ if (time >= 0) | ||
+ iface->max_preferred_lifetime = time; | ||
+ else | ||
+ syslog(LOG_ERR, "Invalid %s value configured for interface '%s'", | ||
+ iface_attrs[IFACE_ATTR_MAX_PREFERRED_LIFETIME].name, iface->name); | ||
+ } | ||
+ if ((c = tb[IFACE_ATTR_MIN_VALID_LIFETIME])) { | ||
+ double time = parse_leasetime(c); | ||
+ | ||
+ if (time >= 0) | ||
+ iface->min_valid_lifetime = time; | ||
+ else | ||
+ syslog(LOG_ERR, "Invalid %s value configured for interface '%s'", | ||
+ iface_attrs[IFACE_ATTR_MIN_VALID_LIFETIME].name, iface->name); | ||
+ } | ||
+ | ||
+ if ((c = tb[IFACE_ATTR_MAX_VALID_LIFETIME])) { | ||
+ double time = parse_leasetime(c); | ||
+ | ||
+ if (time >= 0) | ||
+ iface->max_valid_lifetime = time; | ||
+ else | ||
+ syslog(LOG_ERR, "Invalid %s value configured for interface '%s'", | ||
+ iface_attrs[IFACE_ATTR_MAX_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) + | ||
--- a/src/dhcpv6-ia.c | ||
+++ b/src/dhcpv6-ia.c | ||
@@ -1027,6 +1027,22 @@ static size_t build_ia(uint8_t *buf, siz | ||
} | ||
} | ||
|
||
+ if (pref) { | ||
+ if (iface->min_preferred_lifetime) | ||
+ pref = max(pref, iface->min_preferred_lifetime); | ||
+ if (iface->max_preferred_lifetime) | ||
+ pref = min(pref, iface->max_preferred_lifetime); | ||
+ } | ||
+ if (valid) { | ||
+ if (iface->min_valid_lifetime) | ||
+ valid = max(valid, iface->min_valid_lifetime); | ||
+ if (iface->max_valid_lifetime) | ||
+ valid = min(valid, iface->max_valid_lifetime); | ||
+ | ||
+ if (!pref) | ||
+ pref = valid; | ||
+ } | ||
+ | ||
if (!INFINITE_VALID(a->valid_until)) | ||
/* UINT32_MAX is considered as infinite leasetime */ | ||
a->valid_until = (valid == UINT32_MAX) ? 0 : valid + now; | ||
--- a/src/odhcpd.h | ||
+++ b/src/odhcpd.h | ||
@@ -319,6 +319,10 @@ struct interface { | ||
uint32_t ra_hoplimit; | ||
int ra_mtu; | ||
uint32_t preferred_lifetime; | ||
+ uint32_t min_preferred_lifetime; | ||
+ uint32_t max_preferred_lifetime; | ||
+ uint32_t min_valid_lifetime; | ||
+ uint32_t max_valid_lifetime; | ||
|
||
// DHCP | ||
uint32_t dhcp_leasetime; | ||
--- a/src/router.c | ||
+++ b/src/router.c | ||
@@ -600,6 +600,22 @@ static int send_router_advert(struct int | ||
|
||
if (iface->ra_useleasetime && valid > iface->dhcp_leasetime) | ||
valid = iface->dhcp_leasetime; | ||
+ | ||
+ if (!preferred) | ||
+ preferred = valid; | ||
+ } | ||
+ | ||
+ if (preferred) { | ||
+ if (iface->min_preferred_lifetime) | ||
+ preferred = max(preferred, iface->min_preferred_lifetime); | ||
+ if (iface->max_preferred_lifetime) | ||
+ preferred = min(preferred, iface->max_preferred_lifetime); | ||
+ } | ||
+ if (valid) { | ||
+ if (iface->min_valid_lifetime) | ||
+ valid = max(valid, iface->min_valid_lifetime); | ||
+ if (iface->max_valid_lifetime) | ||
+ valid = min(valid, iface->max_valid_lifetime); | ||
} | ||
|
||
if (minvalid > valid) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters