Skip to contentSkip to conversation

netns ct: per-netns expectations

PATCH Applied [email protected] 4 participants 173 messages Aug 21, 2008 – Oct 2, 2008 46 messages not in the archive Page 2 of 2

Subsystems (4)
lore
Share & tools
lore
#198 lore raw

PATCH 31/33 netns ct: fixup DNAT in netns

In reply to Patrick McHardy
net/ipv4/netfilter/nf_nat_rule.c +3 -3
index 0a02a8c..f929352 100644
@@ -91,13 +91,13 @@ static unsigned int ipt_snat_target(struct sk_buff *skb,
 }
 
 /* Before 2.6.11 we did implicit source NAT if required. Warn about change. */
-static void warn_if_extra_mangle(__be32 dstip, __be32 srcip)
+static void warn_if_extra_mangle(struct net *net, __be32 dstip, __be32 srcip)
 {
 	static int warned = 0;
 	struct flowi fl = { .nl_u = { .ip4_u = { .daddr = dstip } } };
 	struct rtable *rt;
 
-	if (ip_route_output_key(&init_net, &rt, &fl) != 0)
+	if (ip_route_output_key(net, &rt, &fl) != 0)
 		return;
 
 	if (rt->rt_src != srcip && !warned) {
@@ -130,7 +130,7 @@ static unsigned int ipt_dnat_target(struct sk_buff *skb,
 
 	if (hooknum == NF_INET_LOCAL_OUT &&
 	    mr->range[0].flags & IP_NAT_RANGE_MAP_IPS)
-		warn_if_extra_mangle(ip_hdr(skb)->daddr,
+		warn_if_extra_mangle(dev_net(out), ip_hdr(skb)->daddr,
 				     mr->range[0].min_ip);
 
 	return nf_nat_setup_info(ct, &mr->range[0], IP_NAT_MANIP_DST);
#199 lore raw

Re: [PATCH 31/33] netns ct: fixup DNAT in netns

Alexey Dobriyan wrote:

Applied.

A message that is not in the archive (sent off-list or not yet received): 1220842990-30500-31-git-send-email-adobriyan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#201 lore raw

Re: [PATCH 31/33] netns ct: fixup DNAT in netns

Alexey Dobriyan wrote:

Applied.

#202 lore raw

PATCH 32/33 netns nat: PPTP NAT in netns

In reply to Patrick McHardy
net/ipv4/netfilter/nf_nat_pptp.c +2 -1
index e4bdddc..9eb1710 100644
@@ -40,6 +40,7 @@ MODULE_ALIAS("ip_nat_pptp");
 static void pptp_nat_expected(struct nf_conn *ct,
 			      struct nf_conntrack_expect *exp)
 {
+	struct net *net = nf_ct_net(ct);
 	const struct nf_conn *master = ct->master;
 	struct nf_conntrack_expect *other_exp;
 	struct nf_conntrack_tuple t;
@@ -73,7 +74,7 @@ static void pptp_nat_expected(struct nf_conn *ct,
 
 	pr_debug("trying to unexpect other dir: ");
 	nf_ct_dump_tuple_ip(&t);
-	other_exp = nf_ct_expect_find_get(&init_net, &t);
+	other_exp = nf_ct_expect_find_get(net, &t);
 	if (other_exp) {
 		nf_ct_unexpect_related(other_exp);
 		nf_ct_expect_put(other_exp);
#203 lore raw

Re: [PATCH 32/33] netns nat: PPTP NAT in netns

Alexey Dobriyan wrote:

Applied.

A message that is not in the archive (sent off-list or not yet received): 1220842990-30500-32-git-send-email-adobriyan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#205 lore raw

Re: [PATCH 32/33] netns nat: PPTP NAT in netns

Alexey Dobriyan wrote:

Applied.

#206 lore raw

PATCH 33/33 Enable netfilter in netns

In reply to Patrick McHardy
Quoted 1 line

From kernel perspective, allow entrance in nf_hook_slow().

Stuff which uses nf_register_hook/nf_register_hooks, but otherwise not netns-ready:

DECnet netfilter
ipt_CLUSTERIP
nf_nat_standalone.c together with XFRM (?) IPVS
several individual match modules (like hashlimit) ctnetlink
NOTRACK
all sorts of queueing and reporting to userspace L3 and L4 protocol sysctls, bridge sysctls probably something else

Anyway critical mass has been achieved, there is no reason to hide netfilter any longer.

Quoted 1 line

From userspace perspective, allow to manipulate all sorts of

iptables/ip6tables/arptables rules.

net/netfilter/core.c +0 -8
index b16cd79..a90ac83 100644
@@ -165,14 +165,6 @@ int nf_hook_slow(u_int8_t pf, unsigned int hook, struct sk_buff *skb,
 	unsigned int verdict;
 	int ret = 0;
 
-#ifdef CONFIG_NET_NS
-	struct net *net;
-
-	net = indev == NULL ? dev_net(outdev) : dev_net(indev);
-	if (net != &init_net)
-		return 1;
-#endif
-
 	/* We may already have this, but read-locks nest anyway */
 	rcu_read_lock();
 
net/netfilter/nf_sockopt.c +0 -3
index f9b46de..8ab829f 100644
@@ -65,9 +65,6 @@ static struct nf_sockopt_ops *nf_sockopt_find(struct sock *sk, u_int8_t pf,
 {
 	struct nf_sockopt_ops *ops;
 
-	if (!net_eq(sock_net(sk), &init_net))
-		return ERR_PTR(-ENOPROTOOPT);
-
 	if (mutex_lock_interruptible(&nf_sockopt_mutex) != 0)
 		return ERR_PTR(-EINTR);
 
#207 lore raw

Re: [PATCH 33/33] Enable netfilter in netns

Quoted 15 lines · Alexey Dobriyan
Quoted 1 line

From kernel perspective, allow entrance in nf_hook_slow().

Stuff which uses nf_register_hook/nf_register_hooks, but otherwise not netns-ready:

DECnet netfilter
ipt_CLUSTERIP
nf_nat_standalone.c together with XFRM (?) IPVS
several individual match modules (like hashlimit) ctnetlink
NOTRACK
all sorts of queueing and reporting to userspace L3 and L4 protocol sysctls, bridge sysctls probably something else

Quoted 5 lines

Anyway critical mass has been achieved, there is no reason to hide netfilter any longer.

Quoted 1 line

From userspace perspective, allow to manipulate all sorts of

iptables/ip6tables/arptables rules.

Applied. thanks Alexey.

Is there an easy way to test all this stuff?

#208 lore raw

Re: [PATCH 33/33] Enable netfilter in netns

Quoted 21 lines · Patrick McHardy
Quoted 20 lines · Alexey Dobriyan
Quoted 1 line

From kernel perspective, allow entrance in nf_hook_slow().

Stuff which uses nf_register_hook/nf_register_hooks, but otherwise not netns-ready:

DECnet netfilter
ipt_CLUSTERIP
nf_nat_standalone.c together with XFRM (?) IPVS
several individual match modules (like hashlimit) ctnetlink
NOTRACK
all sorts of queueing and reporting to userspace L3 and L4 protocol sysctls, bridge sysctls probably something else

Anyway critical mass has been achieved, there is no reason to hide netfilter any longer.

Quoted 1 line

From userspace perspective, allow to manipulate all sorts of

Quoted 6 lines
Quoted 2 lines

iptables/ip6tables/arptables rules.

Applied. thanks Alexey.

Is there an easy way to test all this stuff?

I used the following:

0) netns is currently mutually exclusive with sysfs, so depending on sanity of distro initscripts booting sysfs-less kernel can be tricky.

In Gentoo, for example a) rm -rf /sys (sic!), b) RC_USE_FSTAB="yes",
c) RC_DEVICES="static" in /etc/conf.d/rc are needed.

1) netns creation tool (attached, some container guy posted it somewhere)

	# ns_exec -n /bin/sh

2) shutdown network in init_net

sudo /etc/init.d/ntpd stop
sudo /etc/init.d/sshd stop
sudo /etc/init.d/iptables stop
sudo /etc/init.d/ip6tables stop
sudo /etc/init.d/net.eth1 stop
sudo /etc/init.d/net.eth0 stop

3) move netdevices to netns

ip l s dev eth0 netns "$1"
ip l s dev eth1 netns "$1"

where $1 is PID of shell from 1)

4) in netns start everything back

sudo /etc/init.d/net.eth0 start
sudo /etc/init.d/net.eth1 start
sudo /etc/init.d/iptables start
sudo /etc/init.d/ip6tables start
sudo /etc/init.d/sshd start
sudo /etc/init.d/ntpd start

5) at this point my usual NAT setup is back working for me and everything should be like in init_net (modulo aforementioned exceptions) and independent from init_net.

Leaked netns are in /proc/slabinfo under "net_namespace".

Some IPv6 printks can be annoying, so mute them.

Object poisoning with SLUB won't work for irrelevant reasons, so use SLAB.

Something like that.

#209 lore raw

Re: [PATCH 33/33] Enable netfilter in netns

Quoted 46 lines · Alexey Dobriyan
Quoted 2 lines · Patrick McHardy

Is there an easy way to test all this stuff?

I used the following:

0) netns is currently mutually exclusive with sysfs, so depending on sanity of distro initscripts booting sysfs-less kernel can be tricky.

In Gentoo, for example a) rm -rf /sys (sic!), b) RC_USE_FSTAB="yes",
c) RC_DEVICES="static" in /etc/conf.d/rc are needed.

1) netns creation tool (attached, some container guy posted it somewhere)

	# ns_exec -n /bin/sh

2) shutdown network in init_net

sudo /etc/init.d/ntpd stop
sudo /etc/init.d/sshd stop
sudo /etc/init.d/iptables stop
sudo /etc/init.d/ip6tables stop
sudo /etc/init.d/net.eth1 stop
sudo /etc/init.d/net.eth0 stop

3) move netdevices to netns

ip l s dev eth0 netns "$1"
ip l s dev eth1 netns "$1"

where $1 is PID of shell from 1)

4) in netns start everything back

sudo /etc/init.d/net.eth0 start
sudo /etc/init.d/net.eth1 start
sudo /etc/init.d/iptables start
sudo /etc/init.d/ip6tables start
sudo /etc/init.d/sshd start
sudo /etc/init.d/ntpd start

5) at this point my usual NAT setup is back working for me and everything should be like in init_net (modulo aforementioned exceptions) and independent from init_net.

Quoted 8 lines

Leaked netns are in /proc/slabinfo under "net_namespace".

Some IPv6 printks can be annoying, so mute them.

Object poisoning with SLUB won't work for irrelevant reasons, so use SLAB.

Something like that.

Thanks, I'll give it a try.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#211 lore raw

Re: [PATCH 33/33] Enable netfilter in netns

Quoted 46 lines · Alexey Dobriyan
Quoted 2 lines · Patrick McHardy

Is there an easy way to test all this stuff?

I used the following:

0) netns is currently mutually exclusive with sysfs, so depending on sanity of distro initscripts booting sysfs-less kernel can be tricky.

In Gentoo, for example a) rm -rf /sys (sic!), b) RC_USE_FSTAB="yes",
c) RC_DEVICES="static" in /etc/conf.d/rc are needed.

1) netns creation tool (attached, some container guy posted it somewhere)

	# ns_exec -n /bin/sh

2) shutdown network in init_net

sudo /etc/init.d/ntpd stop
sudo /etc/init.d/sshd stop
sudo /etc/init.d/iptables stop
sudo /etc/init.d/ip6tables stop
sudo /etc/init.d/net.eth1 stop
sudo /etc/init.d/net.eth0 stop

3) move netdevices to netns

ip l s dev eth0 netns "$1"
ip l s dev eth1 netns "$1"

where $1 is PID of shell from 1)

4) in netns start everything back

sudo /etc/init.d/net.eth0 start
sudo /etc/init.d/net.eth1 start
sudo /etc/init.d/iptables start
sudo /etc/init.d/ip6tables start
sudo /etc/init.d/sshd start
sudo /etc/init.d/ntpd start

5) at this point my usual NAT setup is back working for me and everything should be like in init_net (modulo aforementioned exceptions) and independent from init_net.

Quoted 8 lines

Leaked netns are in /proc/slabinfo under "net_namespace".

Some IPv6 printks can be annoying, so mute them.

Object poisoning with SLUB won't work for irrelevant reasons, so use SLAB.

Something like that.

Thanks, I'll give it a try.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#213 lore raw

Re: [PATCH 33/33] Enable netfilter in netns

Quoted 21 lines · Patrick McHardy
Quoted 20 lines · Alexey Dobriyan
Quoted 1 line

From kernel perspective, allow entrance in nf_hook_slow().

Stuff which uses nf_register_hook/nf_register_hooks, but otherwise not netns-ready:

DECnet netfilter
ipt_CLUSTERIP
nf_nat_standalone.c together with XFRM (?) IPVS
several individual match modules (like hashlimit) ctnetlink
NOTRACK
all sorts of queueing and reporting to userspace L3 and L4 protocol sysctls, bridge sysctls probably something else

Anyway critical mass has been achieved, there is no reason to hide netfilter any longer.

Quoted 1 line

From userspace perspective, allow to manipulate all sorts of

Quoted 6 lines
Quoted 2 lines

iptables/ip6tables/arptables rules.

Applied. thanks Alexey.

Is there an easy way to test all this stuff?

I used the following:

0) netns is currently mutually exclusive with sysfs, so depending on sanity of distro initscripts booting sysfs-less kernel can be tricky.

In Gentoo, for example a) rm -rf /sys (sic!), b) RC_USE_FSTAB="yes",
c) RC_DEVICES="static" in /etc/conf.d/rc are needed.

1) netns creation tool (attached, some container guy posted it somewhere)

	# ns_exec -n /bin/sh

2) shutdown network in init_net

sudo /etc/init.d/ntpd stop
sudo /etc/init.d/sshd stop
sudo /etc/init.d/iptables stop
sudo /etc/init.d/ip6tables stop
sudo /etc/init.d/net.eth1 stop
sudo /etc/init.d/net.eth0 stop

3) move netdevices to netns

ip l s dev eth0 netns "$1"
ip l s dev eth1 netns "$1"

where $1 is PID of shell from 1)

4) in netns start everything back

sudo /etc/init.d/net.eth0 start
sudo /etc/init.d/net.eth1 start
sudo /etc/init.d/iptables start
sudo /etc/init.d/ip6tables start
sudo /etc/init.d/sshd start
sudo /etc/init.d/ntpd start

5) at this point my usual NAT setup is back working for me and everything should be like in init_net (modulo aforementioned exceptions) and independent from init_net.

Leaked netns are in /proc/slabinfo under "net_namespace".

Some IPv6 printks can be annoying, so mute them.

Object poisoning with SLUB won't work for irrelevant reasons, so use SLAB.

Something like that.

A message that is not in the archive (sent off-list or not yet received): 1220842990-30500-33-git-send-email-adobriyan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#216 lore raw

Re: [PATCH 33/33] Enable netfilter in netns

Quoted 15 lines · Alexey Dobriyan
Quoted 1 line

From kernel perspective, allow entrance in nf_hook_slow().

Stuff which uses nf_register_hook/nf_register_hooks, but otherwise not netns-ready:

DECnet netfilter
ipt_CLUSTERIP
nf_nat_standalone.c together with XFRM (?) IPVS
several individual match modules (like hashlimit) ctnetlink
NOTRACK
all sorts of queueing and reporting to userspace L3 and L4 protocol sysctls, bridge sysctls probably something else

Quoted 5 lines

Anyway critical mass has been achieved, there is no reason to hide netfilter any longer.

Quoted 1 line

From userspace perspective, allow to manipulate all sorts of

iptables/ip6tables/arptables rules.

Applied. thanks Alexey.

Is there an easy way to test all this stuff?

A message that is not in the archive (sent off-list or not yet received): [email protected]

#218 lore raw
Quoted 7 lines · [email protected] wrote:

Make per-netns expectation hash and expectation count.

Expectation always belongs to netns to which it's master conntrack belongs. This is natural and allows to not bloat expectations.

Proc files and leaf users in protocol modules are stubbed to init_net, this is temporary.

This one again introduces overly long lines, please fix up the remaining patches yourself and resend.

I'll upload my current tree to kernel.org so you can use it as a base (will take a couple of minutes):

git://git.kernel.org/pub/scm/linux/kernel/git/kaber/nf-next-2.6.git