config: cap ra_hoplimit to maximum and warn instead of logging an error
authorPaul Donald <[email protected]>
Fri, 10 Oct 2025 11:46:44 +0000 (13:46 +0200)
committerÁlvaro Fernández Rojas <[email protected]>
Mon, 13 Oct 2025 07:53:30 +0000 (09:53 +0200)
Signed-off-by: Paul Donald <[email protected]>
Link: https://github.com/openwrt/odhcpd/pull/225
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
src/config.c
src/router.h

index 0441b12fa62a1780ea2ca4f7a7d41d4b02a192f8..8cc43db9e68bfdc6aae3d7bb5f935c63ac98053c 100644 (file)
@@ -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])) {
index 2cd5469bb8a89e51bc92044db4741ab2e062385b..6358493782489262c60ddfcf699a2368a03934a4 100644 (file)
@@ -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)