summaryrefslogtreecommitdiffhomepage
path: root/modules/luci-base/luasrc
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 13:10:15 -0500
commit38880407aa6c0246bc9af52073a79ff4a2096a6e (patch)
tree340fa7fe332077526fdd8fdc487330394c3d9e24 /modules/luci-base/luasrc
parentd83642c20519692c5d3883e23d01bb84a48dd85a (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')
-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 52f90afee6..aafdc5c3c6 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)