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)
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