summaryrefslogtreecommitdiffhomepage
path: root/modules/luci-base/luasrc/cbi
diff options
context:
space:
mode:
authorDaniel Dickinson <openwrt@daniel.thecshore.com>2015-12-14 07:38:31 -0500
committerDaniel Dickinson <openwrt@daniel.thecshore.com>2015-12-15 20:40:14 -0500
commitbbcfad7953489ed87336e3a1981c9cb19e390cdb (patch)
tree9a319b276e604b17316d449de10046a2aa8b261a /modules/luci-base/luasrc/cbi
parentf25c4e07bc9642e0491d3a4ab3942a69545891e9 (diff)
modules/luci-base: Fix ipaddrport validator to support ipv6
The previous versiono of ipaddrport validator only worked for ipv4 due to disallowing colons (:) in ip address which obvious fails for ipv6. We now instead allow either ipv4 address or an ipv6 address of the form [<ipv6address>]:port
Diffstat (limited to 'modules/luci-base/luasrc/cbi')
-rw-r--r--modules/luci-base/luasrc/cbi/datatypes.lua18
1 files changed, 16 insertions, 2 deletions
diff --git a/modules/luci-base/luasrc/cbi/datatypes.lua b/modules/luci-base/luasrc/cbi/datatypes.lua
index 4c003be2a..95d19d88e 100644
--- a/modules/luci-base/luasrc/cbi/datatypes.lua
+++ b/modules/luci-base/luasrc/cbi/datatypes.lua
@@ -189,9 +189,23 @@ function hostport(val)
return not not (h and p and host(h) and port(p))
end
-function ipaddrport(val)
+function ip4addrport(val)
local h, p = val:match("^([^:]+):([^:]+)$")
- return not not (h and p and ipaddr(h) and port(p))
+ return (h and p and ip4addr(h) and port(p))
+end
+
+function ipaddrport(val, bracket)
+ local h, p = val:match("^([^%[%]:]+):([^:]+)$")
+ if (h and p and ip4addr(h) and port(p)) then
+ return true
+ elseif (bracket == 1) then
+ h, p = val:match("^(%[.+%]):([^:]+)$")
+ if (h and p and ip6addr(h) and port(p)) then
+ return true
+ end
+ end
+ h, p = val:match("^([^%[%]]+):([^:]+)$")
+ return (h and p and ip6addr(h) and port(p))
end
function wpakey(val)