diff options
author | Jo-Philipp Wich <jo@mein.io> | 2018-12-13 11:57:16 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2018-12-13 11:57:16 +0100 |
commit | 11b271d4a9e2d4efcc42c4d65b778b3c3c37ea72 (patch) | |
tree | 000c1bb909c23a2cef4a411caa7ca257aa8b75bb /modules/luci-base/luasrc/model | |
parent | 67c34c5f5f414f25a6aa3d4a92a9a78cce2c86c5 (diff) |
luci-base: properly option ipaddr in single cidr string notation as well
When an interface configuration specifies both "option ipaddr 1.2.3.4/24"
and "option netmask", then netifd will ignore the netmask in favor to the
prefix encoded in the cidr string.
Support this variant as well by treating a sole cidr string value as
singöe-item cidr list.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'modules/luci-base/luasrc/model')
-rw-r--r-- | modules/luci-base/luasrc/model/cbi/admin_network/proto_static.lua | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/modules/luci-base/luasrc/model/cbi/admin_network/proto_static.lua b/modules/luci-base/luasrc/model/cbi/admin_network/proto_static.lua index 242dc59b5e..3c5751744a 100644 --- a/modules/luci-base/luasrc/model/cbi/admin_network/proto_static.lua +++ b/modules/luci-base/luasrc/model/cbi/admin_network/proto_static.lua @@ -8,12 +8,16 @@ local netmask, gateway, broadcast, dns, accept_ra, send_rs, ip6addr, ip6gw local mtu, metric, usecidr, ipaddr_single, ipaddr_multi +local function is_cidr(s) + return (type(s) == "string" and luci.ip.IPv4(s) and s:find("/")) +end + usecidr = section:taboption("general", Value, "ipaddr_usecidr") usecidr.forcewrite = true usecidr.cfgvalue = function(self, section) local cfgvalue = self.map:get(section, "ipaddr") - return (type(cfgvalue) == "table") and "1" or "0" + return (type(cfgvalue) == "table" or is_cidr(cfgvalue)) and "1" or "0" end usecidr.render = function(self, section, scope) @@ -62,9 +66,11 @@ ipaddr_multi.cfgvalue = function(self, section) local addr = self.map:get(section, "ipaddr") local mask = self.map:get(section, "netmask") - if type(addr) == "string" and - type(mask) == "string" and - #addr > 0 and #mask > 0 + if is_cidr(addr) then + return { addr } + elseif type(addr) == "string" and + type(mask) == "string" and + #addr > 0 and #mask > 0 then return { "%s/%s" %{ addr, mask } } elseif type(addr) == "table" then |