Atomically changing NIC dev name + namespace ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Another feature I'd like to provide in libvirt LXC is "hotplug" of NIC
devices to containers.

eg, I have a NIC eth1 in the host and I want to make it appear as eth0
in the container. There are two ways I can do this

  # ip link set eth1 name eth0
  # ip link set eth0 ns $PID

Or

  # ip link set eth1 ns $PID
  # setns --net $PID  (assume it opens /proc/$PID/ns/net & does setns(fd))
  # ip link set eth1 name eth0


Both these approaches suffer from flaws though. The first approach fails
on step one, if there is already another NIC in the host, that has the
same name as the target we want to use in the container. The second
approach fails on step 1 if there is already a NIC in the container
which has the same name as the original device on the host.

To get around this, we'd basically need to temporarily use a completely
random NIC name eg

  # ip link set eth1 name $RANDOMNAME
  # ip link set $RANDOMNAME ns $PID
  # setns --net $PID  (assume it opens /proc/$PID/ns/net & does setns(fd))
  # ip link set $RANDOMNAME name eth0

This is workable, but feels slightly unpleasant.  So IMHO if would be
desirable if the kernel allowed us to atomically change the NIC device
name and namespace at the same time. eg

  # ip link set eth1 name eth0 ns $PID

Although that 'ip' CLI syntax is allowed, it appears to implement it in
two steps, doing the rename first and then setting the namespace, so you
still hit the NIC name clash problem.

Regards,
Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
_______________________________________________
Containers mailing list
Containers@xxxxxxxxxxxxxxxxxxxxxxxxxx
https://lists.linuxfoundation.org/mailman/listinfo/containers


[Index of Archives]     [Cgroups]     [Netdev]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux