You are not logged in.

#1 2018-05-08 16:47:02

sdong
Member
Registered: 2018-05-08
Posts: 2

How to create virtual wireless interface in systemd networkd

Hello,

We are doing concurrent WiFi access point and client. Therefore, we need to use iw command to create/add a virtual wireless interface over the primary wireless interface (wlan0).
For example, to create a virtual wireless interface bcm0: iw dev wlan0 interface add bcm0 type managed.

I found out a solution by using udev rule. I created :/etc/udev/rules.d/90-wireless.rules" as:
ACTION=="add", SUBSYSTEM=="net", KERNEL=="wlan0", RUN+="/sbin/ifconfig wlan0 up", RUN+="/usr/sbin/iw dev wlan0 interface add bcm0 type managed"
Then I setup hostapd.conf and wpa_supplicant.conf and enables hostapd and wpa_supplicant. (hostapd runs over bcm0, and wpa_supplicant runs over wlan0).
Now, I got both wireless access point and client working.

However, instead of creating virtual wireleess interface in udev rule, is there any way to do it in systemd networkd (netdev) config? I looked at systemd-networkd tutorial, and systemd.netdev. But I couldn't found any solution.
Alternatively, is there any way to specify network pre-init command/script?

Regards,
Shuo

Offline

#2 2018-05-09 22:53:07

gerdesj
Member
Registered: 2016-04-17
Posts: 13

Re: How to create virtual wireless interface in systemd networkd

Off the top of my head: Write a script to start and stop the *thing*.  Create a systemd unit in /etc/systemd/system with suitable Requires= and After= under [Unit].  There is probably a better way but that will get you started.  You can refine it later.

Offline

#3 2018-05-10 22:26:25

sdong
Member
Registered: 2018-05-08
Posts: 2

Re: How to create virtual wireless interface in systemd networkd

Hi,

I got it working using a systemd unit file as you suggested.

I created a unit (service) file as /lib/systemd/system/wireless-device@.service:
[Unit]
Description=Template to create virtual wireless interface
Requires=sys-subsystem-net-devices-wlan0.device
After=sys-subsystem-net-devices-wlan0.device
[Service]
Type=oneshot
ExecStart=/usr/sbin/iw dev wlan0 interface add %I type managed
[Install]
WantedBy=multi-user.target

Then I did "systemctl enable wireless-device@bcm0.service".
After reboot, it create bcm0 interface. hostapd and wpa_supplocant both run as expected.
So, all works as expected.

For my wireless-device@.service file, is it all correct? The Type has to be oneshot, correct? And since it has to make sure wlan0 is up when doing iw command, I have to add Requires=sys-subsystem-net-devices-wlan0.device and After=sys-subsystem-net-devices-wlan0.device, correct?

Regards,
Shuo

Offline

#4 2023-10-15 22:59:50

RoH
Member
Registered: 2023-10-15
Posts: 1

Re: How to create virtual wireless interface in systemd networkd

Hello, I was also looking for a solution, after reading the manpage systemd.netdev I found it.

It is enough to create a *.netdev file under /etc/systemd/network to create a virtual interface.

In my case, it looks like this:

# cat /etc/systemd/network/ap0.netdev
[NetDev]
Name=ap0
Kind=wlan

[WLAN]
PhysicalDevice=0
Type=ap

And it works for me. leave this here now because, I haven't found anything anywhere on the net that isn't just a workaround.

Last edited by RoH (2023-10-15 23:03:13)

Offline

Board footer

Powered by FluxBB