[1/4] batman-adv: NETIF_F_NETNS_LOCAL feature to prevent netns moves

Message ID 1453312110-32683-2-git-send-email-andrew@lunn.ch (mailing list archive)
State Superseded, archived
Delegated to: Marek Lindner
Headers

Commit Message

Andrew Lunn Jan. 20, 2016, 5:48 p.m. UTC
  The batX soft interface should not be moved between network name
spaces. This is similar to bridges, bonds, tunnels, which are not
allowed to move between network namespaces.

Suggested-by: Daniel Ehlers <danielehlers@mindeye.net>
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
 net/batman-adv/soft-interface.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Antonio Quartulli Jan. 23, 2016, 2:06 a.m. UTC | #1
On Wed, Jan 20, 2016 at 06:48:27PM +0100, Andrew Lunn wrote:
> The batX soft interface should not be moved between network name
> spaces. This is similar to bridges, bonds, tunnels, which are not
> allowed to move between network namespaces.
> 

Andrew,
I understand bridges and other similar interfaces do the same, but what
is the real reason for preventing a batman soft-interface from moving
between namespaces? I tried to figure this put myself, but I couldn't
find a real technical reason for that

(note - I am not a namespace expert as I am just learning now how they
work)

Cheers,
  
Andrew Lunn Jan. 23, 2016, 5:20 p.m. UTC | #2
On Sat, Jan 23, 2016 at 10:06:37AM +0800, Antonio Quartulli wrote:
> On Wed, Jan 20, 2016 at 06:48:27PM +0100, Andrew Lunn wrote:
> > The batX soft interface should not be moved between network name
> > spaces. This is similar to bridges, bonds, tunnels, which are not
> > allowed to move between network namespaces.
> > 
> 
> Andrew,
> I understand bridges and other similar interfaces do the same, but what
> is the real reason for preventing a batman soft-interface from moving
> between namespaces?

Humm, actually, a good question. I blindly copied this code without
thinking about it.

One clear answer is the notification mechanism, used by
batadv_hard_if_event(). As far as i can see, such events are only sent
within the interfaces namespace. So for example you hot unplug a hard
interface which the soft interface is using, you would not get the
NETDEV_DOWN event if the soft interface is in a different namespace.

Now that i think of it, there are a few other reasons. All the
interface management calls, and displaying of interface names would
have to contains the namespace. Otherwise you look at the output for
'batctl o' and have no idea which namespace that wlan0 interface is
from. Remember, interface names are only unique within a namespace,
not across namespaces.

namespaces are supposed to be as transparent as possible. Applications
are not supposed to know they are in a name space. That goes right out
the window as soon as you need to include a namespace into every
interface name.

	  Andrew
  
Antonio Quartulli Jan. 24, 2016, 6:19 a.m. UTC | #3
On Sat, Jan 23, 2016 at 06:20:06PM +0100, Andrew Lunn wrote:
> On Sat, Jan 23, 2016 at 10:06:37AM +0800, Antonio Quartulli wrote:
> > On Wed, Jan 20, 2016 at 06:48:27PM +0100, Andrew Lunn wrote:
> > > The batX soft interface should not be moved between network name
> > > spaces. This is similar to bridges, bonds, tunnels, which are not
> > > allowed to move between network namespaces.
> > > 
> > 
> > Andrew,
> > I understand bridges and other similar interfaces do the same, but what
> > is the real reason for preventing a batman soft-interface from moving
> > between namespaces?
> 
> Humm, actually, a good question. I blindly copied this code without
> thinking about it.
> 
> One clear answer is the notification mechanism, used by
> batadv_hard_if_event(). As far as i can see, such events are only sent
> within the interfaces namespace. So for example you hot unplug a hard
> interface which the soft interface is using, you would not get the
> NETDEV_DOWN event if the soft interface is in a different namespace.

This raises another question (maybe addressed by another of your patch?): what
happens if an hard-interface currently enslaved in bat0 changes namespace?
Will this result in an UNREGISTER event like when the interface gets destroyed?
If not, I am not sure how the whole situation can still be consistent.

> 
> Now that i think of it, there are a few other reasons. All the
> interface management calls, and displaying of interface names would
> have to contains the namespace. Otherwise you look at the output for
> 'batctl o' and have no idea which namespace that wlan0 interface is
> from. Remember, interface names are only unique within a namespace,
> not across namespaces.

Yeah, it make sense. If the softif is in the same ns as the hardifs, it is
definitely necessary to prevent bat0 from jumping from a namespace to another.

Cheers,
  
Antonio Quartulli Jan. 24, 2016, 10:42 a.m. UTC | #4
On Sun, Jan 24, 2016 at 02:19:59PM +0800, Antonio Quartulli wrote:
> On Sat, Jan 23, 2016 at 06:20:06PM +0100, Andrew Lunn wrote:
> > On Sat, Jan 23, 2016 at 10:06:37AM +0800, Antonio Quartulli wrote:
> > > On Wed, Jan 20, 2016 at 06:48:27PM +0100, Andrew Lunn wrote:
> > > > The batX soft interface should not be moved between network name
> > > > spaces. This is similar to bridges, bonds, tunnels, which are not
> > > > allowed to move between network namespaces.
> > > > 
> > > 
> > > Andrew,
> > > I understand bridges and other similar interfaces do the same, but what
> > > is the real reason for preventing a batman soft-interface from moving
> > > between namespaces?
> > 
> > Humm, actually, a good question. I blindly copied this code without
> > thinking about it.
> > 
> > One clear answer is the notification mechanism, used by
> > batadv_hard_if_event(). As far as i can see, such events are only sent
> > within the interfaces namespace. So for example you hot unplug a hard
> > interface which the soft interface is using, you would not get the
> > NETDEV_DOWN event if the soft interface is in a different namespace.
> 
> This raises another question (maybe addressed by another of your patch?): what
> happens if an hard-interface currently enslaved in bat0 changes namespace?
> Will this result in an UNREGISTER event like when the interface gets destroyed?
> If not, I am not sure how the whole situation can still be consistent.

It seems that an UNREGISTER event is broadcasted when an hardif goes to another
namespace. At net/dev/core.c:4915

Therefore batman-adv will do the right thing :)

Cheers,
  
Antonio Quartulli Jan. 24, 2016, 11:01 a.m. UTC | #5
On Wed, Jan 20, 2016 at 06:48:27PM +0100, Andrew Lunn wrote:
> The batX soft interface should not be moved between network name
> spaces. This is similar to bridges, bonds, tunnels, which are not
> allowed to move between network namespaces.
> 
> Suggested-by: Daniel Ehlers <danielehlers@mindeye.net>
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>

Acked-by: Antonio Quartulli <a@unstable.cc>
  
Andrew Lunn Jan. 24, 2016, 4:46 p.m. UTC | #6
> > This raises another question (maybe addressed by another of your patch?): what
> > happens if an hard-interface currently enslaved in bat0 changes namespace?
> > Will this result in an UNREGISTER event like when the interface gets destroyed?
> > If not, I am not sure how the whole situation can still be consistent.
> 
> It seems that an UNREGISTER event is broadcasted when an hardif goes to another
> namespace. At net/dev/core.c:4915
> 
> Therefore batman-adv will do the right thing :)

Correct. An interface is effectively hotplugged from one namespace to
another.

	Andrew
  

Patch

diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
index ac4d08d..f3f096c0 100644
--- a/net/batman-adv/soft-interface.c
+++ b/net/batman-adv/soft-interface.c
@@ -940,7 +940,7 @@  static void batadv_softif_init_early(struct net_device *dev)
 
 	dev->netdev_ops = &batadv_netdev_ops;
 	dev->destructor = batadv_softif_free;
-	dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
+	dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_NETNS_LOCAL;
 	dev->priv_flags |= IFF_NO_QUEUE;
 
 	/* can't call min_mtu, because the needed variables