diff --git a/packages/lime-system/files/usr/lib/lua/lime/network.lua b/packages/lime-system/files/usr/lib/lua/lime/network.lua index 2c5078fd8..0c0710a96 100644 --- a/packages/lime-system/files/usr/lib/lua/lime/network.lua +++ b/packages/lime-system/files/usr/lib/lua/lime/network.lua @@ -232,6 +232,72 @@ function network._is_dsa_conduit(dev) return "reg" == fs.stat("/sys/class/net/" .. dev .. "/dsa/tagging", "type") end +--! Create a bridge for each dsa_cpu port: i.e. eth0 -> br0 +function network.create_dsa_bridge(dsa_cpu, board) + local uci = config.get_uci_cursor() + local ports + br_name = "br" .. string.match(dsa_cpu, "%d+") + + --! Get br-lan section name + local br_lan_section = utils.find_br_lan() + + --! Get brX section name if exist + local br_section = utils.find_bridge_cfgid(br_name) + + --! Add all dsa user ports in brX by default + for role, role_table in pairs(board["network"] or {}) do + --! "ports" and "device" fields may be specified at the same time. + --! In this case, "ports" must be used. + ports = role_table["ports"] + if ports == nil then + ports = { role_table["device"] } + end + end + + --! Create brX if not exist + if br_section == nil then + br_section = uci:add("network", "device") + utils.log('Create non existing bridge: ' .. br_name ) + uci:set("network", br_section, "name", br_name) + uci:set("network", br_section, "type", "bridge") + uci:save("network") + end + + for _,port in pairs(ports) do + utils.log('Evaluating port' .. port) + utils.log('Bridge lan section: ' .. br_lan_section) + + local br_lan_ports = uci:get('network', br_lan_section, 'ports') + local brX_ports = uci:get('network', br_section, 'ports') + + if brX_ports == nil then + utils.unsafe_shell('uci add_list network.' .. br_section .. '.ports=' .. port) + else + --! Remove the ports from br-lan and add it to brX + for _, br_port in pairs(brX_ports) do + utils.log('Add ' .. br_port .. ' to the bridge ' .. br_name .. ' if not present' ) + if not br_port == port then + utils.log('Add port ' .. port .. 'to the bridge ' .. br_name) + utils.unsafe_shell('uci add_list network.' .. br_section .. '.ports=' .. port) + end + end + end + + --! Readd the ports br-lan + for _,br_lan_port in pairs(br_lan_ports) do + utils.log('Bridge lan port: ' .. br_lan_port) + if not br_lan_port == port then + utils.log('Add port ' .. port .. 'to br-lan ') + uci:add("network", br_lan_section, "ports", br_lan_port) + end + end + + end + + uci:save("network") + --! utils.log(utils.unsafe_shell('uci show network')) + +end function network.scandevices(specificIfaces) local devices = {} @@ -251,6 +317,8 @@ function network.scandevices(specificIfaces) if network._is_dsa_conduit(dev) then utils.log( "network.scandevices.dev_parser ignored DSA conduit " .. "device %s", dev ) + network.create_dsa_bridge(dev, board) + devices["br0"] = devices["br0"] or {} return end @@ -387,7 +455,7 @@ function network.configure() if protoName == "manual" then break end -- If manual is specified do not configure interface local protoModule = "lime.proto."..protoName local needsConfig = utils.isModuleAvailable(protoModule) - if protoName ~= 'lan' and not flags["specific"] then + if not flags["specific"] then --! Work around issue 1121. Do not configure any other --! protocols than lime.proto.lan on dsa devices unless there --! is a config net section for the device. @@ -634,3 +702,4 @@ function network.runProtocols(linuxBaseIfname) end return network + diff --git a/packages/lime-system/files/usr/lib/lua/lime/proto/lan.lua b/packages/lime-system/files/usr/lib/lua/lime/proto/lan.lua index c705dbbd5..571d64909 100644 --- a/packages/lime-system/files/usr/lib/lua/lime/proto/lan.lua +++ b/packages/lime-system/files/usr/lib/lua/lime/proto/lan.lua @@ -8,24 +8,6 @@ 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 @@ -38,7 +20,7 @@ function lan.configure(args) uci:set("network", "lan", "netmask", ipv4:mask():string()) uci:set("network", "lan", "proto", "static") uci:set("network", "lan", "mtu", "1500") - local br_lan_section = find_br_lan(uci) + local br_lan_section = utils.find_br_lan() if br_lan_section then uci:delete("network", br_lan_section, "ports") end uci:save("network") @@ -66,7 +48,7 @@ function lan.setup_interface(ifname, args) local uci = config.get_uci_cursor() local bridgedIfs = {} - local br_lan_section = find_br_lan(uci) + local br_lan_section = utils.find_br_lan() 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 diff --git a/packages/lime-system/files/usr/lib/lua/lime/utils.lua b/packages/lime-system/files/usr/lib/lua/lime/utils.lua index f453dff9a..21cefd6ec 100644 --- a/packages/lime-system/files/usr/lib/lua/lime/utils.lua +++ b/packages/lime-system/files/usr/lib/lua/lime/utils.lua @@ -615,4 +615,27 @@ function utils.dumptable(table, nesting) end end +function utils.find_bridge_cfgid(bridge_name) + local uci = config.get_uci_cursor() + local br_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 == bridge_name) then return end + br_section = s[".name"] + end + ) + return br_section +end + +--! Find a device section in network with +--! option name 'br-lan' +--! option type 'bridge' +function utils.find_br_lan() + return utils.find_bridge_cfgid("br-lan") +end + return utils