luci-base: add IPv6 LL and ULA validation
authorPaul Donald <redacted>
Fri, 23 Jan 2026 18:46:58 +0000 (19:46 +0100)
committerPaul Donald <redacted>
Fri, 23 Jan 2026 21:40:30 +0000 (22:40 +0100)
Also fix a bug in apply that assigned undefined to a value if
this.apply was used multiple times in the same caller.

Signed-off-by: Paul Donald <redacted>
modules/luci-base/htdocs/luci-static/resources/validation.js

index d3208c9b792dbfab9c8c6fb1cd4a539becb1c7f2..5959338bf43d57ac699921bc732c2fb3a850016f 100644 (file)
@@ -51,7 +51,7 @@ const Validator = baseclass.extend({
                else
                        return false;
 
-               if (value != null)
+               if (value != null && value != undefined)
                        this.value = value;
 
                return func.apply(this, args);
@@ -287,6 +287,24 @@ const ValidatorFactory = baseclass.extend({
                                nomask ? _('valid IPv6 address') : _('valid IPv6 address or prefix'));
                },
 
+               ip6ll(nomask) {
+                       /* fe80::/10  -> 0xfe80 .. 0xfebf */
+                       const x = parseInt(this.value, 16) | 0;
+                       const isll = (((x & 0xffc0) ^ 0xfe80) === 0);
+
+                       return this.assert(isll && this.apply('ip6addr', nomask),
+                               _('valid IPv6 Link Local address'));
+               },
+
+               ip6ula(nomask) {
+                       /* fd00::/8  -> 0xfd00 .. 0xfdff */
+                       const x = parseInt(this.value, 16) | 0;
+                       const isula = (((x & 0xfe00) ^ 0xfc00) === 0);
+
+                       return this.assert(isula && this.apply('ip6addr', nomask),
+                               _('valid IPv6 ULA address'));
+               },
+
                ip4prefix() {
                        return this.assert(!isNaN(this.value) && this.value >= 0 && this.value <= 32,
                                _('valid IPv4 prefix value (0-32)'));
git clone https://git.99rst.org/PROJECT