Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

network.lua throws an error when owrt_device_parser cannot find ifname #944

Closed
ilario opened this issue Nov 6, 2022 · 6 comments · Fixed by #948
Closed

network.lua throws an error when owrt_device_parser cannot find ifname #944

ilario opened this issue Nov 6, 2022 · 6 comments · Fixed by #948

Comments

@ilario
Copy link
Member

ilario commented Nov 6, 2022

Running lime-config on a YouHua WR1200JS with OpenWrt 22.03 I got the following error:

root@OpenWrt:~# lime-config 
Mac-config: lime-d45f25eb7eac
Clearing wireless config...
Clearing network config...
Disabling odhcpd
Cleaning dnsmasq
Disabling 6relayd...
network.scandevices.owrt_ifname_parser found ifname wlan0-ap
network.scandevices.dev_parser found WiFi device wlan0-ap
network.scandevices.owrt_ifname_parser found ifname wlan0-apname
network.scandevices.dev_parser found WiFi device wlan0-apname
network.scandevices.owrt_ifname_parser found ifname wlan0-mesh
network.scandevices.dev_parser found WiFi device wlan0-mesh
network.scandevices.owrt_ifname_parser found ifname wlan1-ap
network.scandevices.dev_parser found WiFi device wlan1-ap
network.scandevices.owrt_ifname_parser found ifname wlan1-apname
network.scandevices.dev_parser found WiFi device wlan1-apname
network.scandevices.owrt_ifname_parser found ifname wlan1-mesh
network.scandevices.dev_parser found WiFi device wlan1-mesh
/usr/lib/lua/lime/utils.lua:17: bad argument #2 to 'format' (string expected, got nil)
stack traceback:
	/usr/lib/lua/lime/config.lua:214: in function </usr/lib/lua/lime/config.lua:214>
	[C]: in function 'foreach'
	/usr/lib/lua/lime/network.lua:288: in function 'scandevices'
	/usr/lib/lua/lime/network.lua:316: in function </usr/lib/lua/lime/network.lua:307>
	[C]: in function 'xpcall'
	/usr/lib/lua/lime/config.lua:214: in function 'main'
	/usr/bin/lime-config:55: in main chunk
	[C]: ?
Configuring system...
Let uhttpd listen on IPv4/IPv6
Applying generic configs:
 uhttpd_https
 Error on generic config uci_set: uhttpd.main.redirect_https=0
Done applying generic configs.
Copying assets:
Done copying assets.
Running assets on ATCONFIG :
Done running assets.

The value for ifname here is missing:

local base_interface = section["ifname"]

This happens due to the changes introduced in OpenWrt 21.02 with the DSA system for configuring bridges, instead of the old swconfig, see the most important changes here
https://openwrt.org/releases/21.02/notes-21.02.0#new_network_configuration_syntax_and_boardjson_change
specifically the point "in config device of type bridge, ifname has been renamed to ports".

Additionally, its content changed from a string containing the ports to a table, so that a change in the code is needed.

Also, the parsing in dev_parser needs to be adapted to the new naming like lan1 in these lines:

@ilario
Copy link
Member Author

ilario commented Nov 6, 2022

Do we need to keep compatibility with devices not supported by DSA?
Most targets have already been migrated, see here and here.

If we want to keep retrocompatibility with OpenWrt 19.07 (or compatibility with the few targets that have not been ported to DSA), we can check if DSA is in place with these lines from Jow:

if grep -sq DEVTYPE=dsa /sys/class/net/*/uevent; then 
  echo "Is DSA"
fi

@ilario ilario added the epic label Nov 7, 2022
@spiccinini
Copy link
Contributor

I believe that we can first work in supporting 22.03 and then check if adding backwards compatibility is needed. What we will have to do is to work in some migration script so an upgrade from 19.07 is viable. Some work is being done here openwrt/openwrt#10796

@ilario
Copy link
Member Author

ilario commented Nov 22, 2022

I just tried with OpenWrt 19.07 and I got the same error but for another interface.

network.scandevices.owrt_ifname_parser found ifname wlan0-ap
network.scandevices.dev_parser found WiFi device wlan0-ap
network.scandevices.owrt_ifname_parser found ifname wlan0-apname
network.scandevices.dev_parser found WiFi device wlan0-apname
network.scandevices.owrt_ifname_parser found ifname wlan0-mesh
network.scandevices.dev_parser found WiFi device wlan0-mesh
network.scandevices.owrt_ifname_parser found ifname wlan1-ap
network.scandevices.dev_parser found WiFi device wlan1-ap
network.scandevices.owrt_ifname_parser found ifname wlan1-apname
network.scandevices.dev_parser found WiFi device wlan1-apname
network.scandevices.owrt_ifname_parser found ifname wlan1-mesh
network.scandevices.dev_parser found WiFi device wlan1-mesh
network.scandevices.owrt_ifname_parser found ifname lo
network.scandevices.owrt_ifname_parser found ifname eth0.1
network.scandevices.dev_parser found vlan device eth0.1 and marking eth0 as nobridge
network.scandevices.owrt_ifname_parser found ifname eth0.2
network.scandevices.dev_parser found vlan device eth0.2 and marking eth0 as nobridge
network.scandevices.owrt_ifname_parser found ifname eth0.2
network.scandevices.dev_parser found vlan device eth0.2 and marking eth0 as nobridge
/usr/lib/lua/lime/utils.lua:17: bad argument #2 to 'format' (string expected, got nil)
stack traceback:
	/usr/lib/lua/lime/config.lua:214: in function </usr/lib/lua/lime/config.lua:214>
	[C]: in function 'foreach'
	/usr/lib/lua/lime/network.lua:288: in function 'scandevices'
	/usr/lib/lua/lime/network.lua:316: in function </usr/lib/lua/lime/network.lua:307>
	[C]: in function 'xpcall'
	/usr/lib/lua/lime/config.lua:214: in function 'main'
	/usr/bin/lime-config:55: in main chunk
	[C]: ?

And it was caused by this entry in /etc/config/network:

config device 'lan_eth0_1_dev'
	option name 'eth0.1'
	option macaddr 'd4:5f:25:eb:7e:ac'

This is very weird. I am going to try to see why this happens when installing packages one by one but not when flashing the whole thing together.

@ilario
Copy link
Member Author

ilario commented Nov 22, 2022

PS it happens because this entry in /etc/config/network does not have the ifname field required here:

local base_interface = section["ifname"]

@ilario
Copy link
Member Author

ilario commented Nov 22, 2022

Waaaait, this whole thing has not been caused by DSA but by this commit: 3bafc4d merged in #900 on the 15th of September.

Specifically, if something has a nil value, it gets skipped here (and this was happening also before that commit):

function dev_parser(dev)
if dev == nil then
utils.log("network.scandevices.dev_parser got nil device")
return
end

what changed in that commit is that before skipping the nil interface, a log message is printed and the nil value causes an error:

function owrt_device_parser(section)
local created_device = section["name"]
local base_interface = section["ifname"]
utils.log( "network.scandevices.owrt_device_parser found base "..
"interface %s and derived device %s", base_interface,
created_device )
dev_parser(created_device)
dev_parser(base_interface)
end

So this is NOT related to DSA.

@ilario ilario changed the title Bridge config changes due to DSA network.lua throws an error when owrt_device_parser cannot find ifname Nov 23, 2022
@ilario
Copy link
Member Author

ilario commented Dec 10, 2022

What we will have to do is to work in some migration script so an upgrade from 19.07 is viable.

Thinking about the migration: sysupgrade complains when doing the upgrade and asks for forcing the upgrade with -F and this usually means that -n is needed. If we do the migration script, then we should upgrade with -F but without -n?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants