Wireless NIC bridge for KVM

Hello, a bit of evolution, with 2 setup points discovered.

I found that, for bridging, the wifi card and its driver must support 4addr. Fortunately, mine does, and I was able to set it automatically at boot using a oneshot service:

Create /etc/systemd/system folder, if not already existing:

sudo mkdir /etc/systemd/system

Create a service file in this folder:

sudo nano /etc/systemd/system/4addr.service

The file has this content, replace wlp2s0 with your wifi card id, if that’s the case:

[Unit]
Description=wlan-4addr
Wants=network.target
Before=network.target systemd-networkd.service
BindsTo=sys-subsystem-net-devices-wlp2s0.device
After=sys-subsystem-net-devices-wlp2s0.device

[Service]
Type=oneshot
ExecStart=/usr/sbin/iw dev wlp2s0 set 4addr on
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

Enable this service at boot:

sudo systemctl enable 4addr.service

After reboot, iw dev wlp2s0 info command (from the network-basic bundle) should output something like this:

Interface wlp2s0
ifindex 3
wdev 0x1
addr xx:xx:xx:xx:xx:xx
ssid xxxxxxxxxxxxxxx
type managed
wiphy 0
channel 10 (2457 MHz), width: 40 MHz, center1: 2447 MHz
txpower 20.00 dBm
multicast TXQ:
qsz-byt qsz-pkt flows drops marks overlmt hashcol tx-bytes tx-packets
0 0 0 0 0 0 0 0 0
4addr: on

Second setup point, as per Clear Linux wireless manual setup instructions, the filename to use for wifi should be 25-wireless-$INTERFACE_NAME.network, where $INTERFACE_NAME is wlp2s0 in my case. So, I created /etc/systemd/network/25-wireless-wlp2s0.network with this content:

[Match]
Name=wlp2s0

[Network]
Bridge=br1

The other 2 files are similar to the ones for ethernet, except br0 is replaced with br1 everywhere.

If i do sudo systemctl restart systemd-networkd.service, the bridge works, and I get the following from networkctl (copy-paste only relevant lines, I have several docker networks also):

IDX LINK TYPE OPERATIONAL SETUP
3 wlp2s0 wlan enslaved configured
4 br1 bridge routable configured

But, after reboot, wireless works but the bridge doesn’t even appear in the list - it is enabled only after I restart systemd-network. I guess is this issue: systemd-networkd wireless bridging - need to wait for carrier · Issue #936 · systemd/systemd · GitHub ?. This is where I took the oneshot service from…

Second, if wifi drops (router restart, signal loss etc), the bridge doesn’t manage to reconnect by itself, need to restart systemd-network again:

3 wlp2s0 wlan no-carrier configuring
4 br1 bridge no-carrier configuring

Still looking forward…

1 Like