All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next 0/2] Ease to follow an interface that moves to another netns
@ 2018-01-25 14:01 Nicolas Dichtel
  2018-01-25 14:01 ` [PATCH net-next 1/2] dev: always advertise the new nsid when the netns iface changes Nicolas Dichtel
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Nicolas Dichtel @ 2018-01-25 14:01 UTC (permalink / raw)
  To: davem; +Cc: netdev, jbenc, christian.brauner


The goal of this series is to ease the user to follow an interface that
moves to another netns.

After this series, with a patched iproute2:

$ ip netns
bar
foo
$ ip monitor link &
$ ip link set dummy0 netns foo
Deleted 5: dummy0: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN group default
    link/ether 6e:a7:82:35:96:46 brd ff:ff:ff:ff:ff:ff new-nsid 0 new-ifindex 6

=> new nsid: 0, new ifindex: 6 (was 5 in the previous netns)

$ ip link set eth1 netns bar
Deleted 3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default
    link/ether 52:54:01:12:34:57 brd ff:ff:ff:ff:ff:ff new-nsid 1 new-ifindex 3

=> new nsid: 1, new ifindex: 3 (same ifindex)

$ ip netns
bar (id: 1)
foo (id: 0)

 include/linux/rtnetlink.h    |  5 +++--
 include/uapi/linux/if_link.h |  1 +
 net/core/dev.c               | 22 ++++++++++++----------
 net/core/rtnetlink.c         | 31 ++++++++++++++++++++-----------
 4 files changed, 36 insertions(+), 23 deletions(-)

Comments are welcomed,
Regards,
Nicolas

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH net-next 1/2] dev: always advertise the new nsid when the netns iface changes
  2018-01-25 14:01 [PATCH net-next 0/2] Ease to follow an interface that moves to another netns Nicolas Dichtel
@ 2018-01-25 14:01 ` Nicolas Dichtel
  2018-01-25 22:32   ` Jiri Benc
  2018-01-25 14:01 ` [PATCH net-next 2/2] dev: advertise the new ifindex " Nicolas Dichtel
  2018-01-29 17:36 ` [PATCH net-next 0/2] Ease to follow an interface that moves to another netns David Miller
  2 siblings, 1 reply; 6+ messages in thread
From: Nicolas Dichtel @ 2018-01-25 14:01 UTC (permalink / raw)
  To: davem; +Cc: netdev, jbenc, christian.brauner, Nicolas Dichtel

The user should be able to follow any interface that moves to another
netns.  There is no reason to hide physical interfaces.

CC: Jiri Benc <jbenc@redhat.com>
CC: Christian Brauner <christian.brauner@ubuntu.com>
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
---
 net/core/dev.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/net/core/dev.c b/net/core/dev.c
index 4670ccabe23a..59987eb6511a 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -8529,10 +8529,7 @@ int dev_change_net_namespace(struct net_device *dev, struct net *net, const char
 	call_netdevice_notifiers(NETDEV_UNREGISTER, dev);
 	rcu_barrier();
 	call_netdevice_notifiers(NETDEV_UNREGISTER_FINAL, dev);
-	if (dev->rtnl_link_ops && dev->rtnl_link_ops->get_link_net)
-		new_nsid = peernet2id_alloc(dev_net(dev), net);
-	else
-		new_nsid = peernet2id(dev_net(dev), net);
+	new_nsid = peernet2id_alloc(dev_net(dev), net);
 	rtmsg_ifinfo_newnet(RTM_DELLINK, dev, ~0U, GFP_KERNEL, &new_nsid);
 
 	/*
-- 
2.15.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net-next 2/2] dev: advertise the new ifindex when the netns iface changes
  2018-01-25 14:01 [PATCH net-next 0/2] Ease to follow an interface that moves to another netns Nicolas Dichtel
  2018-01-25 14:01 ` [PATCH net-next 1/2] dev: always advertise the new nsid when the netns iface changes Nicolas Dichtel
@ 2018-01-25 14:01 ` Nicolas Dichtel
  2018-01-25 22:33   ` Jiri Benc
  2018-01-29 17:36 ` [PATCH net-next 0/2] Ease to follow an interface that moves to another netns David Miller
  2 siblings, 1 reply; 6+ messages in thread
From: Nicolas Dichtel @ 2018-01-25 14:01 UTC (permalink / raw)
  To: davem; +Cc: netdev, jbenc, christian.brauner, Nicolas Dichtel

The goal is to let the user follow an interface that moves to another
netns.

CC: Jiri Benc <jbenc@redhat.com>
CC: Christian Brauner <christian.brauner@ubuntu.com>
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
---
 include/linux/rtnetlink.h    |  5 +++--
 include/uapi/linux/if_link.h |  1 +
 net/core/dev.c               | 19 ++++++++++++-------
 net/core/rtnetlink.c         | 31 ++++++++++++++++++++-----------
 4 files changed, 36 insertions(+), 20 deletions(-)

diff --git a/include/linux/rtnetlink.h b/include/linux/rtnetlink.h
index 62d508b31f56..0514cc36ac34 100644
--- a/include/linux/rtnetlink.h
+++ b/include/linux/rtnetlink.h
@@ -19,10 +19,11 @@ extern int rtnl_put_cacheinfo(struct sk_buff *skb, struct dst_entry *dst,
 
 void rtmsg_ifinfo(int type, struct net_device *dev, unsigned change, gfp_t flags);
 void rtmsg_ifinfo_newnet(int type, struct net_device *dev, unsigned int change,
-			 gfp_t flags, int *new_nsid);
+			 gfp_t flags, int *new_nsid, int new_ifindex);
 struct sk_buff *rtmsg_ifinfo_build_skb(int type, struct net_device *dev,
 				       unsigned change, u32 event,
-				       gfp_t flags, int *new_nsid);
+				       gfp_t flags, int *new_nsid,
+				       int new_ifindex);
 void rtmsg_ifinfo_send(struct sk_buff *skb, struct net_device *dev,
 		       gfp_t flags);
 
diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h
index 8616131e2c61..6d9447700e18 100644
--- a/include/uapi/linux/if_link.h
+++ b/include/uapi/linux/if_link.h
@@ -163,6 +163,7 @@ enum {
 	IFLA_IF_NETNSID,
 	IFLA_CARRIER_UP_COUNT,
 	IFLA_CARRIER_DOWN_COUNT,
+	IFLA_NEW_IFINDEX,
 	__IFLA_MAX
 };
 
diff --git a/net/core/dev.c b/net/core/dev.c
index 59987eb6511a..858501b12869 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -7360,7 +7360,7 @@ static void rollback_registered_many(struct list_head *head)
 		if (!dev->rtnl_link_ops ||
 		    dev->rtnl_link_state == RTNL_LINK_INITIALIZED)
 			skb = rtmsg_ifinfo_build_skb(RTM_DELLINK, dev, ~0U, 0,
-						     GFP_KERNEL, NULL);
+						     GFP_KERNEL, NULL, 0);
 
 		/*
 		 *	Flush the unicast and multicast chains
@@ -8473,7 +8473,7 @@ EXPORT_SYMBOL(unregister_netdev);
 
 int dev_change_net_namespace(struct net_device *dev, struct net *net, const char *pat)
 {
-	int err, new_nsid;
+	int err, new_nsid, new_ifindex;
 
 	ASSERT_RTNL();
 
@@ -8529,8 +8529,16 @@ int dev_change_net_namespace(struct net_device *dev, struct net *net, const char
 	call_netdevice_notifiers(NETDEV_UNREGISTER, dev);
 	rcu_barrier();
 	call_netdevice_notifiers(NETDEV_UNREGISTER_FINAL, dev);
+
 	new_nsid = peernet2id_alloc(dev_net(dev), net);
-	rtmsg_ifinfo_newnet(RTM_DELLINK, dev, ~0U, GFP_KERNEL, &new_nsid);
+	/* If there is an ifindex conflict assign a new one */
+	if (__dev_get_by_index(net, dev->ifindex))
+		new_ifindex = dev_new_index(net);
+	else
+		new_ifindex = dev->ifindex;
+
+	rtmsg_ifinfo_newnet(RTM_DELLINK, dev, ~0U, GFP_KERNEL, &new_nsid,
+			    new_ifindex);
 
 	/*
 	 *	Flush the unicast and multicast chains
@@ -8544,10 +8552,7 @@ int dev_change_net_namespace(struct net_device *dev, struct net *net, const char
 
 	/* Actually switch the network namespace */
 	dev_net_set(dev, net);
-
-	/* If there is an ifindex conflict assign a new one */
-	if (__dev_get_by_index(net, dev->ifindex))
-		dev->ifindex = dev_new_index(net);
+	dev->ifindex = new_ifindex;
 
 	/* Send a netdev-add uevent to the new namespace */
 	kobject_uevent(&dev->dev.kobj, KOBJ_ADD);
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 97874daa1336..cdade82bb363 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -988,6 +988,7 @@ static noinline size_t if_nlmsg_size(const struct net_device *dev,
 	       + rtnl_xdp_size() /* IFLA_XDP */
 	       + nla_total_size(4)  /* IFLA_EVENT */
 	       + nla_total_size(4)  /* IFLA_NEW_NETNSID */
+	       + nla_total_size(4)  /* IFLA_NEW_IFINDEX */
 	       + nla_total_size(1)  /* IFLA_PROTO_DOWN */
 	       + nla_total_size(4)  /* IFLA_IF_NETNSID */
 	       + nla_total_size(4)  /* IFLA_CARRIER_UP_COUNT */
@@ -1511,7 +1512,8 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb,
 			    struct net_device *dev, struct net *src_net,
 			    int type, u32 pid, u32 seq, u32 change,
 			    unsigned int flags, u32 ext_filter_mask,
-			    u32 event, int *new_nsid, int tgt_netnsid)
+			    u32 event, int *new_nsid, int new_ifindex,
+			    int tgt_netnsid)
 {
 	struct ifinfomsg *ifm;
 	struct nlmsghdr *nlh;
@@ -1608,6 +1610,10 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb,
 	if (new_nsid &&
 	    nla_put_s32(skb, IFLA_NEW_NETNSID, *new_nsid) < 0)
 		goto nla_put_failure;
+	if (new_ifindex &&
+	    nla_put_s32(skb, IFLA_NEW_IFINDEX, new_ifindex) < 0)
+		goto nla_put_failure;
+
 
 	rcu_read_lock();
 	if (rtnl_fill_link_af(skb, dev, ext_filter_mask))
@@ -1853,7 +1859,7 @@ static int rtnl_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
 					       NETLINK_CB(cb->skb).portid,
 					       cb->nlh->nlmsg_seq, 0,
 					       flags,
-					       ext_filter_mask, 0, NULL,
+					       ext_filter_mask, 0, NULL, 0,
 					       netnsid);
 
 			if (err < 0) {
@@ -3034,7 +3040,7 @@ static int rtnl_getlink(struct sk_buff *skb, struct nlmsghdr *nlh,
 	err = rtnl_fill_ifinfo(nskb, dev, net,
 			       RTM_NEWLINK, NETLINK_CB(skb).portid,
 			       nlh->nlmsg_seq, 0, 0, ext_filter_mask,
-			       0, NULL, netnsid);
+			       0, NULL, 0, netnsid);
 	if (err < 0) {
 		/* -EMSGSIZE implies BUG in if_nlmsg_size */
 		WARN_ON(err == -EMSGSIZE);
@@ -3130,7 +3136,8 @@ static int rtnl_dump_all(struct sk_buff *skb, struct netlink_callback *cb)
 
 struct sk_buff *rtmsg_ifinfo_build_skb(int type, struct net_device *dev,
 				       unsigned int change,
-				       u32 event, gfp_t flags, int *new_nsid)
+				       u32 event, gfp_t flags, int *new_nsid,
+				       int new_ifindex)
 {
 	struct net *net = dev_net(dev);
 	struct sk_buff *skb;
@@ -3143,7 +3150,7 @@ struct sk_buff *rtmsg_ifinfo_build_skb(int type, struct net_device *dev,
 
 	err = rtnl_fill_ifinfo(skb, dev, dev_net(dev),
 			       type, 0, 0, change, 0, 0, event,
-			       new_nsid, -1);
+			       new_nsid, new_ifindex, -1);
 	if (err < 0) {
 		/* -EMSGSIZE implies BUG in if_nlmsg_size() */
 		WARN_ON(err == -EMSGSIZE);
@@ -3166,14 +3173,15 @@ void rtmsg_ifinfo_send(struct sk_buff *skb, struct net_device *dev, gfp_t flags)
 
 static void rtmsg_ifinfo_event(int type, struct net_device *dev,
 			       unsigned int change, u32 event,
-			       gfp_t flags, int *new_nsid)
+			       gfp_t flags, int *new_nsid, int new_ifindex)
 {
 	struct sk_buff *skb;
 
 	if (dev->reg_state != NETREG_REGISTERED)
 		return;
 
-	skb = rtmsg_ifinfo_build_skb(type, dev, change, event, flags, new_nsid);
+	skb = rtmsg_ifinfo_build_skb(type, dev, change, event, flags, new_nsid,
+				     new_ifindex);
 	if (skb)
 		rtmsg_ifinfo_send(skb, dev, flags);
 }
@@ -3181,14 +3189,15 @@ static void rtmsg_ifinfo_event(int type, struct net_device *dev,
 void rtmsg_ifinfo(int type, struct net_device *dev, unsigned int change,
 		  gfp_t flags)
 {
-	rtmsg_ifinfo_event(type, dev, change, rtnl_get_event(0), flags, NULL);
+	rtmsg_ifinfo_event(type, dev, change, rtnl_get_event(0), flags,
+			   NULL, 0);
 }
 
 void rtmsg_ifinfo_newnet(int type, struct net_device *dev, unsigned int change,
-			 gfp_t flags, int *new_nsid)
+			 gfp_t flags, int *new_nsid, int new_ifindex)
 {
 	rtmsg_ifinfo_event(type, dev, change, rtnl_get_event(0), flags,
-			   new_nsid);
+			   new_nsid, new_ifindex);
 }
 
 static int nlmsg_populate_fdb_fill(struct sk_buff *skb,
@@ -4588,7 +4597,7 @@ static int rtnetlink_event(struct notifier_block *this, unsigned long event, voi
 	case NETDEV_CHANGELOWERSTATE:
 	case NETDEV_CHANGE_TX_QUEUE_LEN:
 		rtmsg_ifinfo_event(RTM_NEWLINK, dev, 0, rtnl_get_event(event),
-				   GFP_KERNEL, NULL);
+				   GFP_KERNEL, NULL, 0);
 		break;
 	default:
 		break;
-- 
2.15.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next 1/2] dev: always advertise the new nsid when the netns iface changes
  2018-01-25 14:01 ` [PATCH net-next 1/2] dev: always advertise the new nsid when the netns iface changes Nicolas Dichtel
@ 2018-01-25 22:32   ` Jiri Benc
  0 siblings, 0 replies; 6+ messages in thread
From: Jiri Benc @ 2018-01-25 22:32 UTC (permalink / raw)
  To: Nicolas Dichtel; +Cc: davem, netdev, christian.brauner

On Thu, 25 Jan 2018 15:01:38 +0100, Nicolas Dichtel wrote:
> The user should be able to follow any interface that moves to another
> netns.  There is no reason to hide physical interfaces.
> 
> CC: Jiri Benc <jbenc@redhat.com>
> CC: Christian Brauner <christian.brauner@ubuntu.com>
> Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>

Reviewed-by: Jiri Benc <jbenc@redhat.com>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next 2/2] dev: advertise the new ifindex when the netns iface changes
  2018-01-25 14:01 ` [PATCH net-next 2/2] dev: advertise the new ifindex " Nicolas Dichtel
@ 2018-01-25 22:33   ` Jiri Benc
  0 siblings, 0 replies; 6+ messages in thread
From: Jiri Benc @ 2018-01-25 22:33 UTC (permalink / raw)
  To: Nicolas Dichtel; +Cc: davem, netdev, christian.brauner

On Thu, 25 Jan 2018 15:01:39 +0100, Nicolas Dichtel wrote:
> The goal is to let the user follow an interface that moves to another
> netns.
> 
> CC: Jiri Benc <jbenc@redhat.com>
> CC: Christian Brauner <christian.brauner@ubuntu.com>
> Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>

This is great, thanks, Nicolas!

Reviewed-by: Jiri Benc <jbenc@redhat.com>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next 0/2] Ease to follow an interface that moves to another netns
  2018-01-25 14:01 [PATCH net-next 0/2] Ease to follow an interface that moves to another netns Nicolas Dichtel
  2018-01-25 14:01 ` [PATCH net-next 1/2] dev: always advertise the new nsid when the netns iface changes Nicolas Dichtel
  2018-01-25 14:01 ` [PATCH net-next 2/2] dev: advertise the new ifindex " Nicolas Dichtel
@ 2018-01-29 17:36 ` David Miller
  2 siblings, 0 replies; 6+ messages in thread
From: David Miller @ 2018-01-29 17:36 UTC (permalink / raw)
  To: nicolas.dichtel; +Cc: netdev, jbenc, christian.brauner

From: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Date: Thu, 25 Jan 2018 15:01:37 +0100

> The goal of this series is to ease the user to follow an interface that
> moves to another netns.
> 
> After this series, with a patched iproute2:
> 
> $ ip netns
> bar
> foo
> $ ip monitor link &
> $ ip link set dummy0 netns foo
> Deleted 5: dummy0: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN group default
>     link/ether 6e:a7:82:35:96:46 brd ff:ff:ff:ff:ff:ff new-nsid 0 new-ifindex 6
> 
> => new nsid: 0, new ifindex: 6 (was 5 in the previous netns)
> 
> $ ip link set eth1 netns bar
> Deleted 3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default
>     link/ether 52:54:01:12:34:57 brd ff:ff:ff:ff:ff:ff new-nsid 1 new-ifindex 3
> 
> => new nsid: 1, new ifindex: 3 (same ifindex)
> 
> $ ip netns
> bar (id: 1)
> foo (id: 0)

Series applied, thanks Nicolas.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-01-29 17:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-25 14:01 [PATCH net-next 0/2] Ease to follow an interface that moves to another netns Nicolas Dichtel
2018-01-25 14:01 ` [PATCH net-next 1/2] dev: always advertise the new nsid when the netns iface changes Nicolas Dichtel
2018-01-25 22:32   ` Jiri Benc
2018-01-25 14:01 ` [PATCH net-next 2/2] dev: advertise the new ifindex " Nicolas Dichtel
2018-01-25 22:33   ` Jiri Benc
2018-01-29 17:36 ` [PATCH net-next 0/2] Ease to follow an interface that moves to another netns David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.