diff --git a/packages/lime-hwd-openwrt-wan/files/usr/lib/lua/lime/hwd/openwrt_wan.lua b/packages/lime-hwd-openwrt-wan/files/usr/lib/lua/lime/hwd/openwrt_wan.lua index 104886f99..ba4eea979 100644 --- a/packages/lime-hwd-openwrt-wan/files/usr/lib/lua/lime/hwd/openwrt_wan.lua +++ b/packages/lime-hwd-openwrt-wan/files/usr/lib/lua/lime/hwd/openwrt_wan.lua @@ -1,5 +1,13 @@ #!/usr/bin/lua +--! LibreMesh community mesh networks meta-firmware +--! +--! Copyright (C) 2014-2023 Gioacchino Mazzurco +--! Copyright (C) 2023 Asociación Civil Altermundi +--! +--! SPDX-License-Identifier: AGPL-3.0-only + + local hardware_detection = require("lime.hardware_detection") local config = require("lime.config") local utils = require("lime.utils") @@ -22,7 +30,7 @@ function openwrt_wan.detect_hardware() if networkTable then local wanTable = networkTable['wan'] if wanTable then - ifname = wanTable['ifname'] + ifname = wanTable['device'] end end if ifname and ifname ~= "" then @@ -47,8 +55,10 @@ function openwrt_wan.detect_hardware() config.set(openwrt_wan.sectionName, "protocols", protos) config.set(openwrt_wan.sectionName, "linux_name", ifname) config.end_batch() + + utils.dbg("WAN interface:", ifname) else - utils.log("No wan interface detected") + utils.dbg("WAN interface not found") end end end diff --git a/packages/lime-proto-wan/files/usr/lib/lua/lime/proto/wan.lua b/packages/lime-proto-wan/files/usr/lib/lua/lime/proto/wan.lua index 40ffd703a..90c17c282 100644 --- a/packages/lime-proto-wan/files/usr/lib/lua/lime/proto/wan.lua +++ b/packages/lime-proto-wan/files/usr/lib/lua/lime/proto/wan.lua @@ -1,5 +1,12 @@ #!/usr/bin/lua +--! LibreMesh community mesh networks meta-firmware +--! +--! Copyright (C) 2014-2023 Gioacchino Mazzurco +--! Copyright (C) 2023 Asociación Civil Altermundi +--! +--! SPDX-License-Identifier: AGPL-3.0-only + local libuci = require("uci") local fs = require("nixio.fs") local utils = require("lime.utils") @@ -20,7 +27,7 @@ end function wan.setup_interface(ifname, args) local uci = libuci:cursor() - uci:set("network", "wan", "ifname", ifname) + uci:set("network", "wan", "device", ifname) uci:save("network") if utils.is_installed('firewall') then 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 1766157fc..8133646a9 100644 --- a/packages/lime-system/files/usr/lib/lua/lime/network.lua +++ b/packages/lime-system/files/usr/lib/lua/lime/network.lua @@ -1,5 +1,12 @@ #!/usr/bin/lua +--! LibreMesh community mesh networks meta-firmware +--! +--! Copyright (C) 2013-2023 Gioacchino Mazzurco +--! Copyright (C) 2023 Asociación Civil Altermundi +--! +--! SPDX-License-Identifier: AGPL-3.0-only + network = {} local ip = require("luci.ip") @@ -228,6 +235,26 @@ function network.scandevices() utils.log( "network.scandevices.dev_parser found vlan device %s " .. "and marking %s as nobridge", dev, rawif ) end + --! With DSA, the LAN ports are not anymore eth0.1 but lan1, lan2... + if dev:match("^lan%d+$") then + local lower_if_path = utils.unsafe_shell("ls -d /sys/class/net/" .. dev .. "/lower*") + local lower_if_table = utils.split(lower_if_path, "_") + local lower_if = lower_if_table[#lower_if_table]:gsub("\n", "") + devices[lower_if] = { nobridge = true } + devices[dev] = {} + utils.log( "network.scandevices.dev_parser found LAN port %s " .. + "and marking %s as nobridge", dev, lower_if ) + end + --! With DSA, the WAN is named wan. Copying the code from the lan case. + if dev:match("^wan$") then + local lower_if_path = utils.unsafe_shell("ls -d /sys/class/net/" .. dev .. "/lower*") + local lower_if_table = utils.split(lower_if_path, "_") + local lower_if = lower_if_table[#lower_if_table]:gsub("\n", "") + devices[lower_if] = { nobridge = true } + devices[dev] = {} + utils.log( "network.scandevices.dev_parser found WAN port %s " .. + "and marking %s as nobridge", dev, lower_if ) + end if dev:match("^wlan%d+"..wireless.wifiModeSeparator.."%w+$") then devices[dev] = {} @@ -260,6 +287,16 @@ function network.scandevices() created_device or "not_found") dev_parser(created_device) dev_parser(base_interface) + --! With DSA switch config, lan* ports are included in br-lan as "ports" + local ports = section["ports"] + if ports ~= "" and ports ~= nil then + for _,port in pairs(ports) do + utils.log( "network.scandevices.owrt_device_parser found ".. + "interface %s with port %s", + created_device or "not_found", port or "not_found") + dev_parser(port) + end + end end function owrt_switch_vlan_parser(section) @@ -422,6 +459,7 @@ function network.createVlanIface(linuxBaseIfname, vid, openwrtNameSuffix, vlanPr uci:set("network", owrtDeviceName, "device") uci:set("network", owrtDeviceName, "type", vlanProtocol) uci:set("network", owrtDeviceName, "name", linux802adIfName) + --! This is ifname also on current OpenWrt uci:set("network", owrtDeviceName, "ifname", linuxBaseIfname) uci:set("network", owrtDeviceName, "vid", vlanId) end @@ -438,7 +476,7 @@ function network.createVlanIface(linuxBaseIfname, vid, openwrtNameSuffix, vlanPr --! ifname in network because it is already set in wireless, because --! setting ifname on both places cause a netifd race condition if vid ~= 0 or not linux802adIfName:match("^wlan") then - uci:set("network", owrtInterfaceName, "ifname", linux802adIfName) + uci:set("network", owrtInterfaceName, "device", linux802adIfName) end uci:save("network") @@ -465,14 +503,16 @@ function network.createMacvlanIface(baseIfname, linuxName, argsDev, argsIf) local owrtDeviceName = network.limeIfNamePrefix..baseIfname.."_"..linuxName.."_dev" local owrtInterfaceName = network.limeIfNamePrefix..baseIfname.."_"..linuxName.."_if" - owrtDeviceName = owrtDeviceName:gsub("[^%w_]", "_") -- sanitize uci section name - owrtInterfaceName = owrtInterfaceName:gsub("[^%w_]", "_") -- sanitize uci section name + --! sanitize uci sections name + owrtDeviceName = owrtDeviceName:gsub("[^%w_]", "_") + owrtInterfaceName = owrtInterfaceName:gsub("[^%w_]", "_") local uci = config.get_uci_cursor() uci:set("network", owrtDeviceName, "device") uci:set("network", owrtDeviceName, "type", "macvlan") uci:set("network", owrtDeviceName, "name", linuxName) + --! This is ifname also on current OpenWrt uci:set("network", owrtDeviceName, "ifname", baseIfname) for k,v in pairs(argsDev) do uci:set("network", owrtDeviceName, k, v) @@ -480,7 +520,7 @@ function network.createMacvlanIface(baseIfname, linuxName, argsDev, argsIf) uci:set("network", owrtInterfaceName, "interface") uci:set("network", owrtInterfaceName, "proto", "none") - uci:set("network", owrtInterfaceName, "ifname", linuxName) + uci:set("network", owrtInterfaceName, "device", linuxName) uci:set("network", owrtInterfaceName, "auto", "1") for k,v in pairs(argsIf) do uci:set("network", owrtInterfaceName, k, v) 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 e68c4b55a..3c93a5126 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 @@ -48,7 +48,10 @@ function lan.setup_interface(ifname, args) local uci = config.get_uci_cursor() local bridgedIfs = {} - local oldIfs = uci:get("network", "lan", "ifname") or {} + -- 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 {} + -- 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 if iface ~= ifname then @@ -56,7 +59,7 @@ function lan.setup_interface(ifname, args) end end table.insert(bridgedIfs, ifname) - uci:set("network", "lan", "ifname", bridgedIfs) + uci:set("network", "@device[0]", "ports", bridgedIfs) uci:save("network") end 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 00beac335..4d9111fd4 100644 --- a/packages/lime-system/files/usr/lib/lua/lime/utils.lua +++ b/packages/lime-system/files/usr/lib/lua/lime/utils.lua @@ -1,5 +1,12 @@ #!/usr/bin/lua +--! LibreMesh community mesh networks meta-firmware +--! +--! Copyright (C) 2014-2023 Gioacchino Mazzurco +--! Copyright (C) 2023 Asociación Civil Altermundi +--! +--! SPDX-License-Identifier: AGPL-3.0-only + utils = {} local config = require("lime.config") @@ -11,6 +18,22 @@ utils.BOARD_JSON_PATH = "/etc/board.json" utils.SHADOW_FILENAME = "/etc/shadow" utils.KEEP_ON_UPGRADE_FILES_BASE_PATH = '/lib/upgrade/keep.d/' +function utils.dbg(...) + local ofd = io.stderr + + ofd:write( debug.getinfo(2, 'S').source, ":", + debug.getinfo(2, 'l').currentline, " ", + debug.getinfo(2, 'n').name ) + + for n=1, select('#', ...) do + --! Assigantion needed to take only the Nth element discarding the rest + local nE = select(n, ...) + ofd:write(" ", nE) + end + + ofd:write("\n") +end + function utils.log(...) if DISABLE_LOGGING ~= nil then return end if os.getenv("LUA_DISABLE_LOGGING") ~= nil and os.getenv("LUA_ENABLE_LOGGING") == nil then return end @@ -568,4 +591,13 @@ function utils.deepcompare(t1,t2) return true end +function utils.is_dsa() + --! Code adapted from Jow https://forum.openwrt.org/t/how-to-detect-dsa/111868/4 + local shell_output = utils.unsafe_shell("grep -s DEVTYPE=dsa /sys/class/net/*/uevent") + if shell_output ~= "" and shell_output ~= nil then + return true + end + return false +end + return utils