From: Jo-Philipp Wich Date: Mon, 1 Nov 2010 01:51:26 +0000 (+0000) Subject: libs/core: several fixes for firewall model X-Git-Tag: 0.10.0~534 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=aab6378bc31be9b50c34135d4d3bbca00fcd732d;p=oweals%2Fluci.git libs/core: several fixes for firewall model --- diff --git a/libs/core/luasrc/model/firewall.lua b/libs/core/luasrc/model/firewall.lua index 1251feaa9..160995c26 100644 --- a/libs/core/luasrc/model/firewall.lua +++ b/libs/core/luasrc/model/firewall.lua @@ -339,11 +339,8 @@ function zone.add_network(self, net) nets[#nets+1] = net - if #nets > 0 then - self:set("network", table.concat(nets, " ")) - else - self:set("network", " ") - end + _M:del_network(net) + self:set("network", table.concat(nets, " ")) end end @@ -375,6 +372,10 @@ function zone.get_networks(self) return nets end +function zone.clear_networks(self) + self:set("network", " ") +end + function zone.get_forwardings_by(self, what) local name = self:name() local forwards = { } @@ -399,7 +400,7 @@ function zone.add_forwarding_to(self, dest) end end - if not exist and dest ~= self:name() then + if not exist and dest ~= self:name() and _valid_id(dest) then local s = uci_r:section("firewall", "forwarding", nil, { src = self:name(), dest = dest @@ -419,7 +420,7 @@ function zone.add_forwarding_from(self, src) end end - if not exist and src ~= self:name() then + if not exist and src ~= self:name() and _valid_id(src) then local s = uci_r:section("firewall", "forwarding", nil, { src = src, dest = self:name() @@ -432,11 +433,9 @@ end function zone.del_forwardings_by(self, what) local name = self:name() - uci_r:foreach("firewall", "forwarding", + uci_r:delete_all("firewall", "forwarding", function(s) - if s.src and s.dest and s[what] == name then - uci_r:delete("firewall", s['.name']) - end + return (s.src and s.dest and s[what] == name) end) end