diff options
author | Serge Hallyn <serge.hallyn@canonical.com> | 2012-12-03 11:17:12 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2012-12-04 13:25:57 -0500 |
commit | 4e66ae2ea371cf431283e2cb95480eb860432856 (patch) | |
tree | 4d4c2312e3df21fe515fdde5c77440b34b75be67 /net/core/dev.c | |
parent | 008d845cf65c3153bbcfa2f1cb3369a99e12de02 (diff) |
net: dev_change_net_namespace: send a KOBJ_REMOVED/KOBJ_ADD
When a new nic is created in namespace ns1, the kernel sends a KOBJ_ADD uevent
to ns1. When the nic is moved to ns2, we only send a KOBJ_MOVE to ns2, and
nothing to ns1.
This patch changes that behavior so that when moving a nic from ns1 to ns2, we
send a KOBJ_REMOVED to ns1 and KOBJ_ADD to ns2. (The KOBJ_MOVE is still
sent to ns2).
The effects of this can be seen when starting and stopping containers in
an upstart based host. Lxc will create a pair of veth nics, the kernel
sends KOBJ_ADD, and upstart starts network-instance jobs for each. When
one nic is moved to the container, because no KOBJ_REMOVED event is
received, the network-instance job for that veth never goes away. This
was reported at https://bugs.launchpad.net/ubuntu/+source/lxc/+bug/1065589
With this patch the networ-instance jobs properly go away.
The other oddness solved here is that if a nic is passed into a running
upstart-based container, without this patch no network-instance job is
started in the container. But when the container creates a new nic
itself (ip link add new type veth) then network-interface jobs are
created. With this patch, behavior comes in line with a regular host.
v2: also send KOBJ_ADD to new netns. There will then be a
_MOVE event from the device_rename() call, but that should
be innocuous.
Signed-off-by: Serge Hallyn <serge.hallyn@canonical.com>
Acked-by: "Eric W. Biederman" <ebiederm@xmission.com>
Acked-by: Daniel Lezcano <daniel.lezcano@free.fr>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core/dev.c')
-rw-r--r-- | net/core/dev.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/net/core/dev.c b/net/core/dev.c index 2f94df257e5a..0aea3fee7f6d 100644 --- a/net/core/dev.c +++ b/net/core/dev.c | |||
@@ -6418,6 +6418,9 @@ int dev_change_net_namespace(struct net_device *dev, struct net *net, const char | |||
6418 | dev_uc_flush(dev); | 6418 | dev_uc_flush(dev); |
6419 | dev_mc_flush(dev); | 6419 | dev_mc_flush(dev); |
6420 | 6420 | ||
6421 | /* Send a netdev-removed uevent to the old namespace */ | ||
6422 | kobject_uevent(&dev->dev.kobj, KOBJ_REMOVE); | ||
6423 | |||
6421 | /* Actually switch the network namespace */ | 6424 | /* Actually switch the network namespace */ |
6422 | dev_net_set(dev, net); | 6425 | dev_net_set(dev, net); |
6423 | 6426 | ||
@@ -6429,6 +6432,9 @@ int dev_change_net_namespace(struct net_device *dev, struct net *net, const char | |||
6429 | dev->iflink = dev->ifindex; | 6432 | dev->iflink = dev->ifindex; |
6430 | } | 6433 | } |
6431 | 6434 | ||
6435 | /* Send a netdev-add uevent to the new namespace */ | ||
6436 | kobject_uevent(&dev->dev.kobj, KOBJ_ADD); | ||
6437 | |||
6432 | /* Fixup kobjects */ | 6438 | /* Fixup kobjects */ |
6433 | err = device_rename(&dev->dev, dev->name); | 6439 | err = device_rename(&dev->dev, dev->name); |
6434 | WARN_ON(err); | 6440 | WARN_ON(err); |