Skip to contentSkip to conversation

macvlan: add NETIF_F_NETNS_LOCAL flag

PATCH In review Cong Wang 5 participants 12 messages Feb 11, 2014 – Feb 12, 2014

Subsystems (2)
lore
Share & tools
lore

Cong Wang

author
#0 lore raw

PATCH 1/1 macvlan: add NETIF_F_NETNS_LOCAL flag

From: Cong Wang <[email protected]>

BZ: https://bugzilla.kernel.org/show_bug.cgi?id=66691

There is no point to allow moving a macvlan device to another namespace while the lower device is still in this namespace. tunnels already set this flag.

Cc Patrick McHardy <[email protected]>
Cc David S. Miller <[email protected]>

---

drivers/net/macvlan.c +2 -2
index 8433de4..9bc3b13 100644
@@ -539,7 +539,7 @@ static int macvlan_init(struct net_device *dev)
 	dev->state		= (dev->state & ~MACVLAN_STATE_MASK) |
 				  (lowerdev->state & MACVLAN_STATE_MASK);
 	dev->features 		= lowerdev->features & MACVLAN_FEATURES;
-	dev->features		|= NETIF_F_LLTX;
+	dev->features		|= NETIF_F_LLTX | NETIF_F_NETNS_LOCAL;
 	dev->gso_max_size	= lowerdev->gso_max_size;
 	dev->iflink		= lowerdev->ifindex;
 	dev->hard_header_len	= lowerdev->hard_header_len;
@@ -699,7 +699,7 @@ static netdev_features_t macvlan_fix_features(struct net_device *dev,
 	features = netdev_increment_features(vlan->lowerdev->features,
 					     features,
 					     mask);
-	features |= NETIF_F_LLTX;
+	features |= NETIF_F_LLTX | NETIF_F_NETNS_LOCAL;
 
 	return features;
 }
#1 lore raw
Quoted 7 lines · Cong Wang

From: Cong Wang <[email protected]>

BZ: https://bugzilla.kernel.org/show_bug.cgi?id=66691

There is no point to allow moving a macvlan device to another namespace while the lower device is still in this namespace. tunnels already set this flag.

Can't we solve this somehow differently, like not showing anything at all etc.? I guess this is a feature some people use and haven't noticed yet.

Greetings,

Hannes

#2 lore raw
Quoted 12 lines · Hannes Frederic Sowa
Quoted 7 lines · Cong Wang

From: Cong Wang <[email protected]>

BZ: https://bugzilla.kernel.org/show_bug.cgi?id=66691

There is no point to allow moving a macvlan device to another namespace while the lower device is still in this namespace. tunnels already set this flag.

Can't we solve this somehow differently, like not showing anything at all etc.? I guess this is a feature some people use and haven't noticed yet.

I don't understand what you mean by "not showing anything at all". I assume you mean mac1@xxx, not matter whether we show xxx here, mac1 relies on xxx to function.

Please give a real use case rather than just guessing, I don't think there is any valid case until we support moving multiple devices into a netns atomically.

#3 lore raw
Quoted 11 lines · Cong Wang
Quoted 9 lines · Hannes Frederic Sowa
Quoted 7 lines · Cong Wang

From: Cong Wang <[email protected]>

BZ: https://bugzilla.kernel.org/show_bug.cgi?id=66691

There is no point to allow moving a macvlan device to another namespace while the lower device is still in this namespace. tunnels already set this flag.

Quoted 7 lines
Quoted 3 lines

Can't we solve this somehow differently, like not showing anything at all etc.? I guess this is a feature some people use and haven't noticed yet.

I don't understand what you mean by "not showing anything at all". I assume you mean mac1@xxx, not matter whether we show xxx here, mac1 relies on xxx to function.

Sorry, I have no idea how to resolve this easily, maybe set the ifindex to something generic. I'll try to think about it.

Maybe revserve an id and install a generic name for it, so old software doesn't get confused.

Quoted 3 lines

Please give a real use case rather than just guessing, I don't think there is any valid case until we support moving multiple devices into a netns atomically.

Setting up a macvlan and moving it into another namespace without moving the parent device is a nice feature. I am not an administrator, so I don't use that stuff often, but given you can easily spawn namespaces and put applications into them, one of the easiest things to connect those to local network without routing over veth and such is the macvlan interface.

Greetings,

Hannes

#4 lore raw
In reply to Hannes Frederic Sowa
Quoted 5 lines · Hannes Frederic Sowa

Setting up a macvlan and moving it into another namespace without moving the parent device is a nice feature. I am not an administrator, so I don't use that stuff often, but given you can easily spawn namespaces and put applications into them, one of the easiest things to connect those to local network without routing over veth and such is the macvlan interface.

Exactly.

#5 lore raw
Quoted 10 lines · Eric Dumazet
Quoted 5 lines · Hannes Frederic Sowa

Setting up a macvlan and moving it into another namespace without moving the parent device is a nice feature. I am not an administrator, so I don't use that stuff often, but given you can easily spawn namespaces and put applications into them, one of the easiest things to connect those to local network without routing over veth and such is the macvlan interface.

Exactly.

Exactly broken by design.

IFA_LINK is an ifindex, ifindex is per-netns. macvlan should not use IFA_LINK.

#6 lore raw
Quoted 1 line · Cong Wang

Exactly broken by design.

Design of what ? Do you have a pointer to a document about this 'design' ?

Quoted 2 lines

IFA_LINK is an ifindex, ifindex is per-netns. macvlan should not use IFA_LINK.

When this was 'designed', ifindex were not per netns.

Apparently nobody spotted this when ifindexes become per netns.

I am sure we can find a solution, keeping this very useful functionality.

BTW, are Cong Wang <[email protected]> and Cong Wang <[email protected]> different persons ?

#7 lore raw
Quoted 8 lines · Eric Dumazet
Quoted 1 line · Cong Wang

Exactly broken by design.

Design of what ? Do you have a pointer to a document about this 'design' ?

Quoted 1 line
Quoted 8 lines
Quoted 1 line

IFA_LINK is an ifindex, ifindex is per-netns. macvlan should not use IFA_LINK.

When this was 'designed', ifindex were not per netns.

Apparently nobody spotted this when ifindexes become per netns.

I am sure we can find a solution, keeping this very useful functionality.

Simple patch would be :

net/core/rtnetlink.c +1 -0
index 048dc8d183aa..31bbba34fd1e 100644
@@ -963,6 +963,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
 	    nla_put_u32(skb, IFLA_NUM_RX_QUEUES, dev->num_rx_queues) ||
 #endif
 	    (dev->ifindex != dev->iflink &&
+	     __dev_get_by_index(dev_net(dev), dev->iflink) &&
 	     nla_put_u32(skb, IFLA_LINK, dev->iflink)) ||
 	    (upper_dev &&
 	     nla_put_u32(skb, IFLA_MASTER, upper_dev->ifindex)) ||
#8 lore raw
Quoted 9 lines · Eric Dumazet

Simple patch would be :

net/core/rtnetlink.c +0 -0
index 048dc8d183aa..31bbba34fd1e 100644

net/core/rtnetlink.c static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev, · line 969

Quoted 7 lines
net/core/rtnetlink.c +1 -0
@@ -963,6 +963,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
 	    nla_put_u32(skb, IFLA_NUM_RX_QUEUES, dev->num_rx_queues) ||
 #endif
 	    (dev->ifindex != dev->iflink &&
+	     __dev_get_by_index(dev_net(dev), dev->iflink) &&
 	     nla_put_u32(skb, IFLA_LINK, dev->iflink)) ||
 	    (upper_dev &&
 	     nla_put_u32(skb, IFLA_MASTER, upper_dev->ifindex)) ||

Hmm, not enough.

We probably need to keep a pointer to iflink net structure.

#10 lore raw
In reply to Eric Dumazet
Quoted 9 lines · Eric Dumazet
Quoted 5 lines · Hannes Frederic Sowa

Setting up a macvlan and moving it into another namespace without moving the parent device is a nice feature. I am not an administrator, so I don't use that stuff often, but given you can easily spawn namespaces and put applications into them, one of the easiest things to connect those to local network without routing over veth and such is the macvlan interface.

Exactly.

I also agree.

#9 lore raw
In reply to Eric Dumazet
Quoted 21 lines · Eric Dumazet
Quoted 9 lines · Eric Dumazet

Simple patch would be :

net/core/rtnetlink.c +0 -0
index 048dc8d183aa..31bbba34fd1e 100644

net/core/rtnetlink.c static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev, · line 969

Quoted 7 lines
net/core/rtnetlink.c +1 -0
@@ -963,6 +963,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
  	    nla_put_u32(skb, IFLA_NUM_RX_QUEUES, dev->num_rx_queues) ||
  #endif
  	    (dev->ifindex != dev->iflink &&
+	     __dev_get_by_index(dev_net(dev), dev->iflink) &&
  	     nla_put_u32(skb, IFLA_LINK, dev->iflink)) ||
  	    (upper_dev &&
  	     nla_put_u32(skb, IFLA_MASTER, upper_dev->ifindex)) ||

Hmm, not enough.

Quoted 1 line

We probably need to keep a pointer to iflink net structure.

This is also used in ip tunnels, but when i/o device is not in the same netns that the tunnel device, the userland can not interpret that IFLA_LINK attribute (userland don't have necessary information to access another netns, maybe they will be able to do it in the future ;-)).

The goal of your patch was to avoid filling this attribute when iflink is into a netns != from dev_net(dev)?

If yes, I agree that we need to keep a pointer to the net structure of iflink. This information is already available in ip tunnels (struct ip_tunnel->net, struct ip6_tnl->net) but is not generic. Maybe we can move it to struct net_device?