Skip to content

Commit

Permalink
Merge pull request #1084 from pony1k/issue/1083
Browse files Browse the repository at this point in the history
Fix removing ports from br-lan
  • Loading branch information
G10h4ck authored Feb 21, 2024
2 parents 63242c2 + 7bf4777 commit ebf4b7b
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions packages/lime-system/files/usr/lib/lua/lime/proto/lan.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,24 @@ local utils = require("lime.utils")

lan.configured = false

--! Find a device section in network with
--! option name 'br-lan'
--! option type 'bridge'
local function find_br_lan(uci)
local br_lan_section = nil
uci:foreach("network", "device",
function(s)
if br_lan_section then return end
local dev_type = uci:get("network", s[".name"], "type")
local dev_name = uci:get("network", s[".name"], "name")
if not (dev_type == 'bridge') then return end
if not (dev_name == 'br-lan') then return end
br_lan_section = s[".name"]
end
)
return br_lan_section
end

function lan.configure(args)
if lan.configured then return end
lan.configured = true
Expand All @@ -20,15 +38,16 @@ function lan.configure(args)
uci:set("network", "lan", "netmask", ipv4:mask():string())
uci:set("network", "lan", "proto", "static")
uci:set("network", "lan", "mtu", "1500")
uci:delete("network", "lan", "ifname")
local br_lan_section = find_br_lan(uci)
if br_lan_section then uci:delete("network", br_lan_section, "ports") end
uci:save("network")

-- disable bat0 on alfred if batadv not enabled
if utils.is_installed("alfred") then
local is_batadv_enabled = false
local generalProtocols = config.get("network", "protocols")
for _,protocol in pairs(generalProtocols) do
local protoModule = "lime.proto."..utils.split(protocol,":")[1]
for _,protocol in pairs(generalProtocols) do
local protoModule = "lime.proto."..utils.split(protocol,":")[1]
if protoModule == "lime.proto.batadv" then
is_batadv_enabled = true
break
Expand All @@ -48,21 +67,9 @@ function lan.setup_interface(ifname, args)

local uci = config.get_uci_cursor()
local bridgedIfs = {}
-- here we bet that there is a device section of type bridge named
-- br-lan
local bridge_section = nil
uci:foreach("network", "device",
function(s)
if bridge_section then return end
local dev_type = uci:get("network", s[".name"], "type")
local dev_name = uci:get("network", s[".name"], "name")
if not (dev_type == 'bridge') then return end
if not (dev_name == 'br-lan') then return end
bridge_section = s[".name"]
end
)
if not bridge_section then return end
local oldIfs = uci:get("network", bridge_section, "ports") or {}
local br_lan_section = find_br_lan(uci)
if not br_lan_section then return end
local oldIfs = uci:get("network", br_lan_section, "ports") or {}
-- it should be a table, it was a string in old OpenWrt releases
if type(oldIfs) == "string" then oldIfs = utils.split(oldIfs, " ") end
for _,iface in pairs(oldIfs) do
Expand All @@ -71,7 +78,7 @@ function lan.setup_interface(ifname, args)
end
end
table.insert(bridgedIfs, ifname)
uci:set("network", bridge_section, "ports", bridgedIfs)
uci:set("network", br_lan_section, "ports", bridgedIfs)
uci:save("network")
end

Expand Down

0 comments on commit ebf4b7b

Please sign in to comment.