mirror of
https://github.com/openwrt/luci.git
synced 2026-02-04 12:06:01 +08:00
luci-base: add IPv6 LL and ULA validation
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 <newtwen+github@gmail.com>
This commit is contained in:
@@ -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)'));
|
||||
|
||||
Reference in New Issue
Block a user