From c0f5518bdb9aebe8c9ea66aef79fe143abe9f91a Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Sat, 30 Oct 2010 04:48:55 +0000 Subject: [PATCH] libs/core: reuse existing uci context in network model if possible. fix some bugs --- libs/core/luasrc/model/network.lua | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/libs/core/luasrc/model/network.lua b/libs/core/luasrc/model/network.lua index 101bba38d..ed40dc2ff 100644 --- a/libs/core/luasrc/model/network.lua +++ b/libs/core/luasrc/model/network.lua @@ -93,6 +93,16 @@ function _stror(s1, s2) end end +function _strlist(x) + if x == nil then + x = "" + elseif type(x) == "table" then + x = table.concat(x, " ") + end + + return x:gmatch("%S+") +end + function _get(c, s, o) return uci_r:get(c, s, o) end @@ -161,7 +171,7 @@ end function init(cursor) - uci_r = cursor or uci.cursor() + uci_r = cursor or uci_r or uci.cursor() uci_s = uci_r:substate() ifs = { } @@ -609,7 +619,7 @@ function network.get_interfaces(self) ifaces = { interface(ifn) } else local nfs = { } - for ifn in self:_get("ifname"):gmatch("%S+") do + for ifn in _strlist(self:get("ifname")) do ifn = ifn:match("[^:]+") nfs[ifn] = interface(ifn) end @@ -651,7 +661,7 @@ function network.contains_interface(self, ifname) ifn = self:proto() .. "-" .. self.sid return ifname == ifn else - for ifn in self:_get("ifname"):gmatch("%S+") do + for ifn in _strlist(self:get("ifname")) do ifn = ifn:match("[^:]+") if ifn == ifname then return true @@ -686,7 +696,7 @@ function interface.name(self) end function interface.mac(self) - return self.dev and self.dev or "00:00:00:00:00:00" + return self.dev and self.dev.macaddr or "00:00:00:00:00:00" end function interface.ipaddrs(self) -- 2.25.1