Subject: Re: [vserver] Assigning a specific network interface to a specific guest
From: Tor Rune Skoglund <trs@swi.no>
Date: Sat, 1 Oct 2016 20:06:37 +0200

Den 17. mars 2016 09:20, skrev Ghislain:
>  you will have to setup network namespace in the vserver util for this 
> guest and you should be able to. Do not know if there is detailled 
> docs but the vserver flower page has the config files needed.

Thanks Ghislain. I have finally had time to follow-up on this old'ish 
thread....

I have lately been trying to get network namespaces to work with 
linux-vserver. This is kernel 4.1.12-vs2.3.8.3 (also tested on 4.1.18) 
and util-vserver 0.30.216_pre3120.

Short story:
I want to let a guest have full control over one single wireless 
interface. Plan A was to let util-vserver set up the namespace, and then 
add the wifi phy to the container.

Setup:
* Added /etc/vserver/pwifi/netns/name      => contents: n2
* Touched /etc/vservers/pwifi/noncontect

I my head, this should be enough in order to let util-vserver create the 
n2 namespace for itself when the guest is started:

amd64 ~ # ip -a netns delete
amd64 ~ # vserver pwifi start
amd64 ~ # vserver-stat
CTX   PROC    VSZ    RSS  userTIME   sysTIME    UPTIME NAME
2        1   2.2G   100K   0m05s40   0m07s27   0m14s48 pwifi
amd64 ~ # ip netns list
RTNETLINK answers: Invalid argument
RTNETLINK answers: Invalid argument
n2
amd64 ~ # iw phy phy0 set netns name n2
command failed: Invalid argument (-22)
amd64 ~ # ip netns exec n2 ip a
RTNETLINK answers: Invalid argument
setting the network namespace "n2" failed: Invalid argument

I'm not sure what happens. I have also been trying to get the guest not 
to create the namespace, but then with other problems. Did not work.

When doing "manual" network namespaces, they seem to work as expected, 
though:

amd64 ~ # ip -a netns delete
amd64 ~ # ip netns add n2
amd64 ~ # ip netns list
n2
amd64 ~ # iw phy phy0 set netns name n2
amd64 ~ # ip netns exec n2 ip a
1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN group default
     link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
3: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group 
default qlen 1000
     link/ether e8:94:f6:1e:ae:4e brd ff:ff:ff:ff:ff:ff

Anyone have a how-to on getting network namespaces to work reliably?

Any other hints?

BR,
Tor Rune Skoglund, trs@swi.no