luci-base: fix Lua-side ip6hostid() datatype validation

A valid host ID as accepted by netifd must meet the following criteria:

 - Is either one of the two special "random" or "eui64" strings
 - Or is a valid IPv6 address according to inet_pton(AF_INET6)
 - Has the first 64 bit set to zero

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
Jo-Philipp Wich 2018-02-13 14:29:21 +01:00
parent 76f9f5e94d
commit 3e1e4d5eb6

View file

@ -169,8 +169,13 @@ function ipmask6(val)
end end
function ip6hostid(val) function ip6hostid(val)
if val and val:match("^[a-fA-F0-9:]+$") and (#val > 2) then if val == "eui64" or val == "random" then
return (ip6addr("2001:db8:0:0" .. val) or ip6addr("2001:db8:0:0:" .. val)) return true
else
local addr = ip.IPv6(val)
if addr and addr:prefix() == 128 and addr:lower("::1:0:0:0:0") then
return true
end
end end
return false return false