Issue with physical wlan interface

Hi, I met an issue with physical wlan interface, when container is stopped by lxc-stop the interface is not returned to the host namespace, also preventing container restart.

A part from unbind/bind the driver is there a standard way ?

lxc 6.0.3; 6.13.2-arch1-1

It’s configured as:

lxc.net.1.type = phys
lxc.net.1.link = wlan0
lxc.net.1.flags = up
lxc.net.1.name = wlan0

If I restart the container:

sudo lxc-start -n deb12 -F
lxc-start: deb12: ../src/lxc/network.c: netdev_configure_server_phys: 1203 No such device - Failed to retrieve ifindex for "wlan0"
lxc-start: deb12: ../src/lxc/network.c: lxc_create_network_priv: 3466 No such device - Failed to create network device
lxc-start: deb12: ../src/lxc/start.c: lxc_spawn: 1847 Failed to create the network
lxc-start: deb12: ../src/lxc/start.c: __lxc_start: 2114 Failed to spawn container "deb12"
lxc-start: deb12: ../src/lxc/tools/lxc_start.c: lxc_start_main: 307 The container failed to start
lxc-start: deb12: ../src/lxc/tools/lxc_start.c: lxc_start_main: 312 Additional information can be obtained by setting the --logfile and --logpriority options

Do you have access to the iw command?

Yes I’ve access to iw, it’s output corresponding to other utils like ip a, wlan0 is shown initially until lxc start.

Okay, I think this may be a tricky issue to handle.

Basically wifi cards have interface names like wlan0 which is what you normally interface with, but the kernel instead deals with phy devices like phy0.

When you ask liblxc to move wlan0 in the container, it goes to check /sys/class/net/wlan/phy80211/name for the phy name and then moves that into the container which effectively drags wlan0 along with it.

When the container stops, the kernel likely correctly relocated phy0 back to the host by wlan0 gets destroyed rather than moved alongside it.

You may be able to re-create it with:

iw phy0 interface add wlan0 type managed

Seems iw failed also:

iw phy phy1 interface add wlan0 type managed
command failed: No such file or directory (-2)