X-Git-Url: https://git.archive.openwrt.org/?a=blobdiff_plain;f=modules%2Fluci-base%2Fluasrc%2Fcbi%2Fdatatypes.lua;h=626ad91c756dac87272f5bcf3094b4105cfac087;hb=c481f3f34325b9c1cf817b16a567a6b10fdd1f2e;hp=95d19d88e0562aa2d1de71e5c24a868eb2fa068a;hpb=bbcfad7953489ed87336e3a1981c9cb19e390cdb;p=project%2Fluci.git diff --git a/modules/luci-base/luasrc/cbi/datatypes.lua b/modules/luci-base/luasrc/cbi/datatypes.lua index 95d19d88e..626ad91c7 100644 --- a/modules/luci-base/luasrc/cbi/datatypes.lua +++ b/modules/luci-base/luasrc/cbi/datatypes.lua @@ -176,17 +176,22 @@ function hostname(val) return false end -function host(val) - return hostname(val) or ipaddr(val) +function host(val, ipv4only) + return hostname(val) or ((ipv4only == 1) and ip4addr(val)) or ((not (ipv4only == 1)) and ipaddr(val)) end function network(val) return uciname(val) or host(val) end -function hostport(val) +function hostport(val, ipv4only) local h, p = val:match("^([^:]+):([^:]+)$") - return not not (h and p and host(h) and port(p)) + return not not (h and p and host(h, ipv4only) and port(p)) +end + +function ip4addrport(val, bracket) + local h, p = val:match("^([^:]+):([^:]+)$") + return (h and p and ip4addr(h) and port(p)) end function ip4addrport(val) @@ -199,7 +204,7 @@ function ipaddrport(val, bracket) if (h and p and ip4addr(h) and port(p)) then return true elseif (bracket == 1) then - h, p = val:match("^(%[.+%]):([^:]+)$") + h, p = val:match("^%[(.+)%]:([^:]+)$") if (h and p and ip6addr(h) and port(p)) then return true end