# ip link set wlan0 netns 1
RTNETLINK answers: Invalid argument
It works for usual ethernet. It also works for proprietary broadcom "wl" driver.
How to do it for usual mac80211-based driver?
# ip link set wlan0 netns 1
RTNETLINK answers: Invalid argument
It works for usual ethernet. It also works for proprietary broadcom "wl" driver.
How to do it for usual mac80211-based driver?
You need to move the PHY:
iw phy phy0 set netns 666
Where 666 is the pid of some process running in that network namespace; for netspaces created by iproute2 tools (with ip netns), you can create a short-lived process in there and get its pid:
iw phy phy0 set netns "$(ip netns exec mynetns sh -c '
sleep 1 >&- & echo "$!"')"
To move it back to the root namespace:
ip netns exec mynetns iw phy phy0 set netns 1
For wifi get the physical address of your interface first (in case your have more than 1 wireless card):
iw dev
The result will be somehting like this:
phy#0
Interface wlp58s0
ifindex 3
wdev 0x1
...
So the name is phy0
now use that to assign your wifi to the namespace:
# iw phy phy0 set netns name <MyNamespace>
From the help of iw:
phy <phyname> set netns { <pid> | name <nsname> }
Put this wireless device into a different network namespace:
<pid> - change network namespace by process id
<nsname> - change network namespace by name from /var/run/netns
or by absolute path (man ip-netns)
Implemented my own workaround: vethify
ip link add type veth; ip link set veth1 netns <some_pid>; vethify wlan0 veth0 on host network namespace. It will copy all captured on wlan0 to veth0 and back;ethtool --offload veth1 rx off tx off && ethtool -K veth1 gso off.Note: vethify sees all packets in the network namespace, not only wlan0's and veth0's. It will add latency and cause additional overhead.