From e5f58a90a14752ec772cbc20996e32521b4d5d1b Mon Sep 17 00:00:00 2001 From: Paul Donald Date: Fri, 10 Oct 2025 13:46:44 +0200 Subject: [PATCH] config: cap ra_hoplimit to maximum and warn instead of logging an error MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Paul Donald Link: https://github.com/openwrt/odhcpd/pull/225 Signed-off-by: Álvaro Fernández Rojas --- src/config.c | 11 ++++++----- src/router.h | 8 ++++++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/config.c b/src/config.c index 0441b12..8cc43db 100644 --- a/src/config.c +++ b/src/config.c @@ -1381,11 +1381,12 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr if ((c = tb[IFACE_ATTR_RA_HOPLIMIT])) { uint32_t ra_hoplimit = blobmsg_get_u32(c); - if (ra_hoplimit <= 255) - iface->ra_hoplimit = ra_hoplimit; - else - syslog(LOG_ERR, "Invalid %s value configured for interface '%s'", - iface_attrs[IFACE_ATTR_RA_HOPLIMIT].name, iface->name); + /* RFC4861 §6.2.1 : AdvCurHopLimit */ + iface->ra_hoplimit = ra_hoplimit <= AdvCurHopLimit ? ra_hoplimit : AdvCurHopLimit; + if(ra_hoplimit > AdvCurHopLimit) + syslog(LOG_WARNING, "Clamped invalid %s value configured for interface '%s' to %d", + iface_attrs[IFACE_ATTR_RA_HOPLIMIT].name, iface->name, iface->ra_hoplimit); + } if ((c = tb[IFACE_ATTR_RA_MTU])) { diff --git a/src/router.h b/src/router.h index 2cd5469..6358493 100644 --- a/src/router.h +++ b/src/router.h @@ -70,6 +70,14 @@ struct icmpv6_opt { * MUST be no greater than 3,600,000 msec */ #define AdvReachableTime 3600000 +/* RFC4861 §6.2.1 : AdvCurHopLimit + The value should be set to the current + diameter of the Internet. The value zero means + unspecified (by this router). + + Note: this value is an 8 bit int, so max 255. +*/ +#define AdvCurHopLimit 255 #define ND_RA_FLAG_PROXY 0x4 #define ND_RA_PREF_HIGH (1 << 3) -- 2.30.2