Skip to contentSkip to conversation

ipvlan: use pernet operations and restrict l3s hooks to master netns

PATCH Applied Florian Westphal 2 participants 2 messages Apr 20, 2017 – Apr 25, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ipvlan: use pernet operations and restrict l3s hooks to master netns

commit 4fbae7d83c98c30efc ("ipvlan: Introduce l3s mode") added registration of netfilter hooks via nf_register_hooks().

This API provides the illusion of 'global' netfilter hooks by placing the hooks in all current and future network namespaces.

In case of ipvlan the hook appears to be only needed in the namespace that contains the ipvlan master device (i.e., usually init_net), so placing them in all namespaces is not needed.

This switches ipvlan driver to pernet operations, and then only registers hooks in namespaces where a ipvlan master device is set to l3s mode.

Extra care has to be taken when the master device is moved to another namespace, as we might have to 'move' the netfilter hooks too.

This is done by storing the namespace the ipvlan port was created in. On REGISTER event, do (un)register operations in the old/new namespaces.

This will also allow removal of the nf_register_hooks() in a future patch.

---
 drivers/net/ipvlan/ipvlan.h      |  2 +
 drivers/net/ipvlan/ipvlan_main.c | 83 ++++++++++++++++++++++++++++++++--------
 2 files changed, 70 insertions(+), 15 deletions(-)
drivers/net/ipvlan/ipvlan.h +2 -0
index 800a46c8d26c..7919369c0a72 100644
@@ -26,6 +26,7 @@
 #include <linux/netfilter.h>
 #include <net/ip.h>
 #include <net/ip6_route.h>
+#include <net/netns/generic.h>
 #include <net/rtnetlink.h>
 #include <net/route.h>
 #include <net/addrconf.h>
@@ -91,6 +92,7 @@ struct ipvl_addr {
 
 struct ipvl_port {
 	struct net_device	*dev;
+	possible_net_t		pnet;
 	struct hlist_head	hlhead[IPVLAN_HASH_SIZE];
 	struct list_head	ipvlans;
 	u16			mode;
drivers/net/ipvlan/ipvlan_main.c +68 -15

158 lines not on this page · raw message

Signature · 1 line
2.10.2
maintainer Applied
#1 lore raw

From: Florian Westphal <[email protected]>
Date: Thu, 20 Apr 2017 18:08:15 +0200

Quoted 16 lines

commit 4fbae7d83c98c30efc ("ipvlan: Introduce l3s mode") added registration of netfilter hooks via nf_register_hooks().

This API provides the illusion of 'global' netfilter hooks by placing the hooks in all current and future network namespaces.

In case of ipvlan the hook appears to be only needed in the namespace that contains the ipvlan master device (i.e., usually init_net), so placing them in all namespaces is not needed.

This switches ipvlan driver to pernet operations, and then only registers hooks in namespaces where a ipvlan master device is set to l3s mode.

Extra care has to be taken when the master device is moved to another namespace, as we might have to 'move' the netfilter hooks too.

Quoted 7 lines

This is done by storing the namespace the ipvlan port was created in. On REGISTER event, do (un)register operations in the old/new namespaces.

This will also allow removal of the nf_register_hooks() in a future patch.

Applied, thanks Florian.