Skip to content

Commit bd10dcc

Browse files
Refresh IPv6 PATCH
Signed-off-by: Nicholas Sun <nicholas-sun@outlook.com>
1 parent de41a54 commit bd10dcc

2 files changed

Lines changed: 59 additions & 48 deletions

File tree

PATCH/odhcpd/0001-config-allow-configuring-max-limit-for-preferred-and.patch renamed to PATCH/odhcpd/001-odhcpd-RFC-9096-compliance.patch

Lines changed: 58 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
1-
From 9ee21c537eea6321ed644e284a1d9c13de342fef Mon Sep 17 00:00:00 2001
2-
From: skbeh <60107333+skbeh@users.noreply.github.com>
1+
From 62a8c0e6db9de52493842c982a723dd155ac7736 Mon Sep 17 00:00:00 2001
32
Date: Sat, 16 Sep 2023 15:04:12 +0000
4-
Subject: [PATCH] config: allow configuring max limit for preferred and valid
5-
lifetime
3+
Subject: [PATCH] odhcpd: RFC 9096 compliance
64

5+
and allow configuring upper limit for preferred and valid lifetime.
76
---
8-
README | 5 +++--
9-
src/config.c | 32 ++++++++++++++++++++++++++++++++
7+
README | 9 +++++----
8+
src/config.c | 34 +++++++++++++++++++++++++++++++++-
109
src/dhcpv6-ia.c | 9 +++++++++
1110
src/odhcpd.h | 6 ++++++
12-
src/router.c | 37 +++++++++++++++++++++++++++++--------
13-
5 files changed, 79 insertions(+), 10 deletions(-)
11+
src/router.c | 23 +++++++++++++++++------
12+
src/router.h | 2 +-
13+
6 files changed, 71 insertions(+), 12 deletions(-)
1414

1515
diff --git a/README b/README
16-
index 8f0e6a4..ddf8534 100644
16+
index 8f0e6a4..c899cd5 100644
1717
--- a/README
1818
+++ b/README
19-
@@ -130,8 +130,9 @@ ra_maxinterval integer 600 Maximum time allowed between
19+
@@ -126,12 +126,13 @@ ra_slaac bool 1 Announce slaac for a prefix
20+
ra_offlink bool 0 Announce prefixes off-link
21+
ra_preference string medium Route(r) preference
22+
[medium|high|low]
23+
-ra_maxinterval integer 600 Maximum time allowed between
24+
+ra_maxinterval integer 900 Maximum time allowed between
2025
sending unsolicited RA
21-
ra_mininterval integer 200 Minimum time allowed between
26+
-ra_mininterval integer 200 Minimum time allowed between
27+
+ra_mininterval integer 300 Minimum time allowed between
2228
sending unsolicited RA
2329
-ra_lifetime integer 1800 Value to be placed in Router
2430
- Lifetime field of RA
@@ -29,7 +35,7 @@ index 8f0e6a4..ddf8534 100644
2935
limit for the preferred and
3036
valid lifetime of a prefix
3137
diff --git a/src/config.c b/src/config.c
32-
index e631814..3281b5f 100644
38+
index e631814..d8ff6f7 100644
3339
--- a/src/config.c
3440
+++ b/src/config.c
3541
@@ -92,6 +92,8 @@ enum {
@@ -50,6 +56,15 @@ index e631814..3281b5f 100644
5056
[IFACE_ATTR_NTP] = { .name = "ntp", .type = BLOBMSG_TYPE_ARRAY },
5157
};
5258

59+
@@ -224,7 +228,7 @@ static void set_interface_defaults(struct interface *iface)
60+
iface->dns_service = true;
61+
iface->ra_flags = ND_RA_FLAG_OTHER;
62+
iface->ra_slaac = true;
63+
- iface->ra_maxinterval = 600;
64+
+ iface->ra_maxinterval = 900;
65+
iface->ra_mininterval = iface->ra_maxinterval/3;
66+
iface->ra_lifetime = -1;
67+
iface->ra_dns = true;
5368
@@ -648,6 +652,34 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr
5469

5570
}
@@ -130,27 +145,28 @@ index 08b4920..58ab155 100644
130145
// DHCP
131146
uint32_t dhcp_leasetime;
132147
diff --git a/src/router.c b/src/router.c
133-
index d5ef7f8..55eaa6d 100644
148+
index d5ef7f8..b4d52aa 100644
134149
--- a/src/router.c
135150
+++ b/src/router.c
136-
@@ -452,7 +452,8 @@ static int send_router_advert(struct interface *iface, const struct in6_addr *fr
151+
@@ -371,7 +371,7 @@ static int calc_adv_interval(struct interface *iface, uint32_t minvalid,
152+
153+
static uint32_t calc_ra_lifetime(struct interface *iface, uint32_t maxival)
154+
{
155+
- uint32_t lifetime = 3*maxival;
156+
+ uint32_t lifetime = maxival * 3;
157+
158+
if (iface->ra_lifetime >= 0) {
159+
lifetime = iface->ra_lifetime;
160+
@@ -452,7 +452,7 @@ static int send_router_advert(struct interface *iface, const struct in6_addr *fr
137161
size_t dns_sz = 0, search_sz = 0, pref64_sz = 0;
138162
size_t pfxs_cnt = 0, routes_cnt = 0;
139163
ssize_t valid_addr_cnt = 0, invalid_addr_cnt = 0;
140164
- uint32_t minvalid = UINT32_MAX, maxival, lifetime;
141-
+ uint32_t minvalid = UINT32_MAX, maxival, lifetime, max_prefix_vlt = ND_VALID_LIMIT;
142-
+ uint32_t calculated_ra_lifetime;
165+
+ uint32_t minvalid = ND_VALID_LIMIT, maxival, lifetime;
143166
int msecs, mtu = iface->ra_mtu, hlim = iface->ra_hoplimit;
144167
bool default_route = false;
145168
bool valid_prefix = false;
146-
@@ -598,10 +599,24 @@ static int send_router_advert(struct interface *iface, const struct in6_addr *fr
147-
if (addr->valid > (uint32_t)now) {
148-
valid = TIME_LEFT(addr->valid, now);
149-
150-
+ if (valid < max_prefix_vlt)
151-
+ max_prefix_vlt = valid;
152-
+
153-
if (iface->ra_useleasetime && valid > iface->dhcp_leasetime)
169+
@@ -602,6 +602,17 @@ static int send_router_advert(struct interface *iface, const struct in6_addr *fr
154170
valid = iface->dhcp_leasetime;
155171
}
156172

@@ -168,25 +184,13 @@ index d5ef7f8..55eaa6d 100644
168184
if (minvalid > valid)
169185
minvalid = valid;
170186

171-
@@ -629,24 +644,30 @@ static int send_router_advert(struct interface *iface, const struct in6_addr *fr
172-
173-
/* Calculate periodic transmit */
174-
msecs = calc_adv_interval(iface, minvalid, &maxival);
175-
- lifetime = calc_ra_lifetime(iface, maxival);
176-
+ calculated_ra_lifetime = min(calc_ra_lifetime(iface, maxival), UINT16_MAX);
177-
+ lifetime = min(calculated_ra_lifetime, max_prefix_vlt);
178-
179-
if (!iface->have_link_local) {
180-
syslog(LOG_NOTICE, "Skip sending a RA on %s as no link local address is available", iface->name);
181-
goto out;
187+
@@ -637,15 +648,15 @@ static int send_router_advert(struct interface *iface, const struct in6_addr *fr
182188
}
183189

184-
- if (default_route && valid_prefix) {
190+
if (default_route && valid_prefix) {
185191
- adv.h.nd_ra_router_lifetime = htons(lifetime < UINT16_MAX ? lifetime : UINT16_MAX);
186-
- } else {
187-
+ /* RFC9096: CE routers SHOULD set the "Router Lifetime" of Router Advertisement (RA) messages to ND_PREFERRED_LIMIT. */
188-
+ adv.h.nd_ra_router_lifetime = htons(ND_PREFERRED_LIMIT);
189-
+ if (!(default_route && valid_prefix)) {
192+
+ adv.h.nd_ra_router_lifetime = htons(lifetime);
193+
} else {
190194
adv.h.nd_ra_router_lifetime = 0;
191195

192196
if (default_route) {
@@ -197,15 +201,9 @@ index d5ef7f8..55eaa6d 100644
197201
- syslog(LOG_WARNING, "No default route present, overriding ra_lifetime!");
198202
+ syslog(LOG_WARNING, "No default route present, setting ra_lifetime to zero!");
199203
}
200-
+ } else if (iface->ra_lifetime >= 0) {
201-
+ adv.h.nd_ra_router_lifetime = htons(calculated_ra_lifetime);
202-
+ if (calculated_ra_lifetime == 0)
203-
+ syslog(LOG_WARNING, "A default route is present and there is public prefix "
204-
+ "but ra_lifetime on iface was set to zero, setting ra_lifetime to zero!");
205204
}
206205

207-
syslog(LOG_DEBUG, "Using a RA lifetime of %d seconds on %s", ntohs(adv.h.nd_ra_router_lifetime), iface->name);
208-
@@ -710,7 +731,7 @@ static int send_router_advert(struct interface *iface, const struct in6_addr *fr
206+
@@ -710,7 +721,7 @@ static int send_router_advert(struct interface *iface, const struct in6_addr *fr
209207

210208
if (iface->pref64_length) {
211209
/* RFC 8781 § 4.1 rounding up lifetime to multiply of 8 */
@@ -214,5 +212,18 @@ index d5ef7f8..55eaa6d 100644
214212
uint8_t prefix_length_code;
215213
uint32_t mask_a1, mask_a2;
216214

215+
diff --git a/src/router.h b/src/router.h
216+
index 0444da8..a994892 100644
217+
--- a/src/router.h
218+
+++ b/src/router.h
219+
@@ -32,7 +32,7 @@ struct icmpv6_opt {
220+
221+
#define MaxInitialRtrAdvInterval 16
222+
#define MaxInitialRtAdvs 3
223+
-#define MaxRtrAdvInterval 1800
224+
+#define MaxRtrAdvInterval 2700
225+
#define MinRtrAdvInterval 3
226+
227+
#define ND_RA_FLAG_PROXY 0x4
217228
--
218229
2.42.0

SCRIPTS/02_prepare_package.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ git clone --depth 1 https://github.com/fullcone-nat-nftables/nft-fullcone packag
4242
# Odhcp
4343
patch -p1 <../PATCH/odhcp6c/1002-odhcp6c-support-dhcpv6-hotplug.patch
4444
mkdir -p package/network/services/odhcpd/patches
45-
cp -f ../PATCH/odhcpd/0001-config-allow-configuring-max-limit-for-preferred-and.patch ./package/network/services/odhcpd/patches/0001-config-allow-configuring-max-limit-for-preferred-and.patch
45+
cp -f ../PATCH/odhcpd/001-odhcpd-RFC-9096-compliance.patch ./package/network/services/odhcpd/patches/001-odhcpd-RFC-9096-compliance.patch
4646
# Remove obsolete options
4747
sed -i 's/syn_flood/synflood_protect/g' package/network/config/firewall/files/firewall.config
4848
# BBRv3

0 commit comments

Comments
 (0)