if type(v) == "boolean" then v = v and "1" or "0" end
return uci_r:set(c, s, o, v)
else
- return uci_r:del(c, s, o, v)
+ return uci_r:delete(c, s, o)
end
end
return (
x:match("^wmaster%d") or x:match("^wifi%d") or x:match("^hwsim%d") or
x:match("^imq%d") or x:match("^mon.wlan%d") or x:match("^6in4-%w") or
- x:match("^3g-%w") or x:match("^ppp-%w") or x:match("^pppoe-%w") or
- x:match("^pppoa-%w") or x == "lo"
+ x:match("^6to4-%w") or x:match("^3g-%w") or x:match("^ppp-%w") or
+ x:match("^pppoe-%w") or x:match("^pppoa-%w") or x == "sit0" or x == "lo"
)
end
function del_network(self, n)
local r = uci_r:delete("network", n)
if r then
- uci_r:foreach("network", "alias",
- function(s)
- if s.interface == n then
- uci_r:delete("network", s['.name'])
- end
- end)
+ uci_r:delete_all("network", "alias",
+ function(s) return (s.interface == n) end)
- uci_r:foreach("network", "route",
- function(s)
- if s.interface == n then
- uci_r:delete("network", s['.name'])
- end
- end)
+ uci_r:delete_all("network", "route",
+ function(s) return (s.interface == n) end)
- uci_r:foreach("network", "route6",
- function(s)
- if s.interface == n then
- uci_r:delete("network", s['.name'])
- end
- end)
+ uci_r:delete_all("network", "route6",
+ function(s) return (s.interface == n) end)
uci_r:foreach("wireless", "wifi-iface",
function(s)
uci_r:delete("wireless", s['.name'], "network")
end
end)
-
- uci_r:delete("network", n)
end
return r
end
function get_interfaces(self)
local iface
local ifaces = { }
+ local seen = { }
+ local nfs = { }
-- find normal interfaces
+ uci_r:foreach("network", "interface",
+ function(s)
+ for iface in utl.imatch(s.ifname) do
+ if not _iface_ignore(iface) and not _wifi_iface(iface) then
+ seen[iface] = true
+ nfs[iface] = interface(iface)
+ end
+ end
+ end)
+
for iface in utl.kspairs(ifs) do
- if not _iface_ignore(iface) and not _wifi_iface(iface) then
- ifaces[#ifaces+1] = interface(iface)
+ if not (seen[iface] or _iface_ignore(iface) or _wifi_iface(iface)) then
+ nfs[iface] = interface(iface)
end
end
+ for iface in utl.kspairs(nfs) do
+ ifaces[#ifaces+1] = nfs[iface]
+ end
+
-- find wifi interfaces
local num = { }
local wfs = { }
elseif self:is_virtual() then
return p .. "-" .. self.sid
else
+ local num = { }
local dev = self:_get("ifname") or
uci_r:get("network", self.sid, "ifname")
return self.sid
end
+function network.uptime(self)
+ local cnt = tonumber(uci_s:get("network", self.sid, "connect_time"))
+ if cnt ~= nil then
+ return nxo.sysinfo().uptime - cnt
+ else
+ return 0
+ end
+end
+
function network.is_bridge(self)
return (self:type() == "bridge")
end
function network.is_virtual(self)
local p = self:proto()
return (
- p == "3g" or p == "6in4" or p == "ppp" or
+ p == "3g" or p == "6in4" or p == "6to4" or p == "ppp" or
p == "pppoe" or p == "pppoa"
)
end
end
function wifinet.ifname(self)
- return self.iwinfo.ifname or self.wdev
+ local ifname = self.iwinfo.ifname
+ if not ifname or ifname:match("^wifi%d") or ifname:match("^radio%d") then
+ ifname = self.wdev
+ end
+ return ifname
end
function wifinet.get_device(self)