diff options
author | Jo-Philipp Wich <jo@mein.io> | 2018-02-13 14:29:21 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2018-02-16 17:05:48 +0100 |
commit | 3e1e4d5eb6b1cbb3125dbd33f6636337c6070784 (patch) | |
tree | a1ef150c0a7d53cea73915703f474086f3b02067 /modules/luci-base/luasrc | |
parent | 76f9f5e94d4fdccb4bc59333d89368cb8d264805 (diff) |
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>
Diffstat (limited to 'modules/luci-base/luasrc')
-rw-r--r-- | modules/luci-base/luasrc/cbi/datatypes.lua | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/modules/luci-base/luasrc/cbi/datatypes.lua b/modules/luci-base/luasrc/cbi/datatypes.lua index df23aaf135..a7e02f350a 100644 --- a/modules/luci-base/luasrc/cbi/datatypes.lua +++ b/modules/luci-base/luasrc/cbi/datatypes.lua @@ -169,8 +169,13 @@ function ipmask6(val) end function ip6hostid(val) - if val and val:match("^[a-fA-F0-9:]+$") and (#val > 2) then - return (ip6addr("2001:db8:0:0" .. val) or ip6addr("2001:db8:0:0:" .. val)) + if val == "eui64" or val == "random" then + 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 return false |