From 11b271d4a9e2d4efcc42c4d65b778b3c3c37ea72 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Thu, 13 Dec 2018 11:57:16 +0100 Subject: luci-base: properly option ipaddr in single cidr string notation as well MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../luasrc/model/cbi/admin_network/proto_static.lua | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'modules/luci-base/luasrc/model/cbi') 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 -- cgit v1.2.3