Skip to content

Commit

Permalink
Merge pull request #1061 from pony1k/issue/1060
Browse files Browse the repository at this point in the history
Fix bridge device section confusion
  • Loading branch information
spiccinini authored Oct 22, 2023
2 parents 4c51c7e + 0bf768e commit d0c498f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
21 changes: 16 additions & 5 deletions packages/lime-system/files/usr/lib/lua/lime/proto/lan.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,21 @@ function lan.setup_interface(ifname, args)

local uci = config.get_uci_cursor()
local bridgedIfs = {}
-- here we bet that the first device section is the bridge one,
-- as it does not have a name for addressing it
local oldIfs = uci:get("network", "@device[0]", "ports") or {}
-- 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 {}
-- 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 @@ -59,8 +71,7 @@ function lan.setup_interface(ifname, args)
end
end
table.insert(bridgedIfs, ifname)
uci:set("network", "@device[0]", "device")
uci:set("network", "@device[0]", "ports", bridgedIfs)
uci:set("network", bridge_section, "ports", bridgedIfs)
uci:save("network")
end

Expand Down
5 changes: 5 additions & 0 deletions packages/lime-system/tests/test_lime_network.lua
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ describe('LiMe Network tests', function()
stub(utils, "getBoardAsTable", function () return BOARD end)
stub(network, "assert_interface_exists", function () return true end)

bridge_section = uci:add("network", "device")
uci:set("network", bridge_section, "type", "bridge")
uci:set("network", bridge_section, "name", "br-lan")
uci:commit("network")

network.configure()

assert.is.equal("1500", uci:get("network", "lan", "mtu"))
Expand Down

0 comments on commit d0c498f

Please sign in to comment.