Skip to contentSkip to conversation

nf-next: reentrancy, new modules

PATCH Applied Jan Engelhardt 2 participants 22 messages Apr 13, 2010

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

Hi,

per request, the series reposted with fixes applied. I also tacked sysrq and condition on.

The following changes since commit 9f93ff5be54108066372d1c4100c515d9d9acc1b:
Alexey Dobriyan (1):
Restore __ALIGN_MASK()

are available in the git repository at:

git://dev.medozas.de/linux master

Jan Engelhardt (8):
netfilter: ipv6: move POSTROUTING invocation before fragmentation
netfilter: ipv6: add IPSKB_REROUTED exclusion to NF_HOOK/POSTROUTING invocation
netfilter: xtables: inclusion of xt_TEE
netfilter: xtables2: make ip_tables reentrant
netfilter: xt_TEE: have cloned packet travel through Xtables too
netfilter: xtables: remove old comments about reentrancy
netfilter: xtables: inclusion of xt_SYSRQ
netfilter: xtables: inclusion of xt_condition

 include/linux/netfilter/Kbuild         |    2 +
 include/linux/netfilter/x_tables.h     |    7 +
 include/linux/netfilter/xt_TEE.h       |    8 +
 include/linux/netfilter/xt_condition.h |   14 ++
 net/ipv4/netfilter/arp_tables.c        |    6 +-
 net/ipv4/netfilter/ip_tables.c         |   67 +++---
 net/ipv4/netfilter/ipt_REJECT.c        |    3 -
 net/ipv6/ip6_output.c                  |   50 +++---
 net/ipv6/netfilter/ip6_tables.c        |   58 ++----
 net/ipv6/netfilter/ip6t_REJECT.c       |    3 -
 net/netfilter/Kconfig                  |   27 +++
 net/netfilter/Makefile                 |    3 +
 net/netfilter/x_tables.c               |   77 +++++++
 net/netfilter/xt_SYSRQ.c               |  354 ++++++++++++++++++++++++++++++++
 net/netfilter/xt_TEE.c                 |  228 ++++++++++++++++++++
 net/netfilter/xt_condition.c           |  243 ++++++++++++++++++++++
 16 files changed, 1048 insertions(+), 102 deletions(-)
 create mode 100644 include/linux/netfilter/xt_TEE.h
 create mode 100644 include/linux/netfilter/xt_condition.h
 create mode 100644 net/netfilter/xt_SYSRQ.c
 create mode 100644 net/netfilter/xt_TEE.c
 create mode 100644 net/netfilter/xt_condition.c
#1 lore raw

PATCH 1/8 netfilter: ipv6: move POSTROUTING invocation before fragmentation

Patrick McHardy notes: "We used to invoke IPv4 POST_ROUTING after fragmentation as well just to defragment the packets in conntrack immediately afterwards, but that got changed during the netfilter-ipsec integration. Ideally IPv6 would behave like IPv4."

This patch makes it so. Sending an oversized frame (e.g. ping6 -s64000 -c1 ::1) will now show up in POSTROUTING as a single skb rather than multiple ones.

---
 net/ipv6/ip6_output.c |   49 +++++++++++++++++++++++--------------------------
 1 files changed, 23 insertions(+), 26 deletions(-)
net/ipv6/ip6_output.c +23 -26
index 4535b7a..f314ba4 100644
@@ -82,22 +82,6 @@ int ip6_local_out(struct sk_buff *skb)
 }
 EXPORT_SYMBOL_GPL(ip6_local_out);
 
-static int ip6_output_finish(struct sk_buff *skb)
-{
-	struct dst_entry *dst = skb_dst(skb);
-
-	if (dst->hh)
-		return neigh_hh_output(dst->hh, skb);
-	else if (dst->neighbour)
-		return dst->neighbour->output(skb);
-
-	IP6_INC_STATS_BH(dev_net(dst->dev),
-			 ip6_dst_idev(dst), IPSTATS_MIB_OUTNOROUTES);
-	kfree_skb(skb);
-	return -EINVAL;
-
-}
-
 /* dev_loopback_xmit for use with netfilter. */
 static int ip6_dev_loopback_xmit(struct sk_buff *newskb)
 {
@@ -111,8 +95,7 @@ static int ip6_dev_loopback_xmit(struct sk_buff *newskb)
 	return 0;
 }
 
-
-static int ip6_output2(struct sk_buff *skb)
+static int ip6_finish_output2(struct sk_buff *skb)
 {
 	struct dst_entry *dst = skb_dst(skb);
 	struct net_device *dev = dst->dev;
@@ -150,8 +133,15 @@ static int ip6_output2(struct sk_buff *skb)
 				skb->len);
 	}
 
-	return NF_HOOK(NFPROTO_IPV6, NF_INET_POST_ROUTING, skb, NULL, skb->dev,
-		       ip6_output_finish);
+	if (dst->hh)
+		return neigh_hh_output(dst->hh, skb);
+	else if (dst->neighbour)
+		return dst->neighbour->output(skb);
+
+	IP6_INC_STATS_BH(dev_net(dst->dev),
+			 ip6_dst_idev(dst), IPSTATS_MIB_OUTNOROUTES);
+	kfree_skb(skb);
+	return -EINVAL;
 }
 
 static inline int ip6_skb_dst_mtu(struct sk_buff *skb)
@@ -162,21 +152,28 @@ static inline int ip6_skb_dst_mtu(struct sk_buff *skb)
 	       skb_dst(skb)->dev->mtu : dst_mtu(skb_dst(skb));
 }
 
+static int ip6_finish_output(struct sk_buff *skb)
+{
+	if ((skb->len > ip6_skb_dst_mtu(skb) && !skb_is_gso(skb)) ||
+				dst_allfrag(skb_dst(skb)))
+		return ip6_fragment(skb, ip6_finish_output2);
+	else
+		return ip6_finish_output2(skb);
+}
+
 int ip6_output(struct sk_buff *skb)
 {
+	struct net_device *dev = skb_dst(skb)->dev;
 	struct inet6_dev *idev = ip6_dst_idev(skb_dst(skb));
 	if (unlikely(idev->cnf.disable_ipv6)) {
-		IP6_INC_STATS(dev_net(skb_dst(skb)->dev), idev,
+		IP6_INC_STATS(dev_net(dev), idev,
 			      IPSTATS_MIB_OUTDISCARDS);
 		kfree_skb(skb);
 		return 0;
 	}
 
-	if ((skb->len > ip6_skb_dst_mtu(skb) && !skb_is_gso(skb)) ||
-				dst_allfrag(skb_dst(skb)))
-		return ip6_fragment(skb, ip6_output2);
-	else
-		return ip6_output2(skb);
+	return NF_HOOK(NFPROTO_IPV6, NF_INET_POST_ROUTING, skb, NULL, dev,
+		       ip6_finish_output);
 }
 
 /*
Signature · 1 line
1.7.0.4
#2 lore raw

Re: [PATCH 1/8] netfilter: ipv6: move POSTROUTING invocation before fragmentation

Quoted 8 lines · Jan Engelhardt

Patrick McHardy notes: "We used to invoke IPv4 POST_ROUTING after fragmentation as well just to defragment the packets in conntrack immediately afterwards, but that got changed during the netfilter-ipsec integration. Ideally IPv6 would behave like IPv4."

This patch makes it so. Sending an oversized frame (e.g. ping6 -s64000 -c1 ::1) will now show up in POSTROUTING as a single skb rather than multiple ones.

Applied, thanks. It seems you could now change the IPv6 conntrack LOCAL_OUT hook to skip defragmentation.

#3 lore raw

PATCH 2/8 netfilter: ipv6: add IPSKB_REROUTED exclusion to NF_HOOK/POSTROUTING invocation

In reply to Jan Engelhardt

Similar to how IPv4's ip_output.c works, have ip6_output also check the IPSKB_REROUTED flag. It will be set from xt_TEE for cloned packets since Xtables can currently only deal with a single packet in flight at a time.

---
 net/ipv6/ip6_output.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
net/ipv6/ip6_output.c +3 -2
index f314ba4..7e10f62 100644
@@ -172,8 +172,9 @@ int ip6_output(struct sk_buff *skb)
 		return 0;
 	}
 
-	return NF_HOOK(NFPROTO_IPV6, NF_INET_POST_ROUTING, skb, NULL, dev,
-		       ip6_finish_output);
+	return NF_HOOK_COND(NFPROTO_IPV6, NF_INET_POST_ROUTING, skb, NULL, dev,
+			    ip6_finish_output,
+			    !(IP6CB(skb)->flags & IPSKB_REROUTED));
 }
 
 /*
Signature · 1 line
1.7.0.4
Acked-by David S. Miller on v1 2/8
#4 lore raw

Re: [PATCH 2/8] netfilter: ipv6: add IPSKB_REROUTED exclusion to NF_HOOK/POSTROUTING invocation

Quoted 16 lines · Jan Engelhardt

Similar to how IPv4's ip_output.c works, have ip6_output also check the IPSKB_REROUTED flag. It will be set from xt_TEE for cloned packets since Xtables can currently only deal with a single packet in flight at a time.

---
 net/ipv6/ip6_output.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
net/ipv6/ip6_output.c +0 -0
index f314ba4..7e10f62 100644

net/ipv6/ip6_output.c int ip6_output(struct sk_buff *skb) · line 177

Quoted 8 lines
net/ipv6/ip6_output.c +3 -2
@@ -172,8 +172,9 @@ int ip6_output(struct sk_buff *skb)
 		return 0;
 	}
 
-	return NF_HOOK(NFPROTO_IPV6, NF_INET_POST_ROUTING, skb, NULL, dev,
-		       ip6_finish_output);
+	return NF_HOOK_COND(NFPROTO_IPV6, NF_INET_POST_ROUTING, skb, NULL, dev,
+			    ip6_finish_output,
+			    !(IP6CB(skb)->flags & IPSKB_REROUTED));

This needs to use an IP6SKB value to avoid clashes. I've fixed it up as follows:

I'll also fix up the TEE patch to use the proper value for IPv6.

commit 9c6eb28aca52d562f3ffbaebaa56385df9972a43

Author: Jan Engelhardt <[email protected]>
Date:   Tue Apr 13 15:32:16 2010 +0200

netfilter: ipv6: add IPSKB_REROUTED exclusion to NF_HOOK/POSTROUTING invocation

Similar to how IPv4's ip_output.c works, have ip6_output also check the IPSKB_REROUTED flag. It will be set from xt_TEE for cloned packets since Xtables can currently only deal with a single packet in flight at a time.

[Patrick: changed to use an IP6SKB value instead of IPSKB]
include/linux/ipv6.h +1 -0
index e0cc9a7..7bdf6ff 100644
@@ -250,6 +250,7 @@ struct inet6_skb_parm {
 
 #define IP6SKB_XFRM_TRANSFORMED	1
 #define IP6SKB_FORWARDED	2
+#define IP6SKB_REROUTED		4
 };
 
 #define IP6CB(skb)	((struct inet6_skb_parm*)((skb)->cb))
net/ipv6/ip6_output.c +3 -2
index 236ac78..c10a38a 100644
@@ -172,8 +172,9 @@ int ip6_output(struct sk_buff *skb)
 		return 0;
 	}
 
-	return NF_HOOK(NFPROTO_IPV6, NF_INET_POST_ROUTING, skb, NULL, dev,
-		       ip6_finish_output);
+	return NF_HOOK_COND(NFPROTO_IPV6, NF_INET_POST_ROUTING, skb, NULL, dev,
+			    ip6_finish_output,
+			    !(IP6CB(skb)->flags & IP6SKB_REROUTED));
 }
 
 /*
#5 lore raw

Re: [PATCH 2/8] netfilter: ipv6: add IPSKB_REROUTED exclusion to NF_HOOK/POSTROUTING invocation

Quoted 8 lines · Patrick McHardy
Quoted 8 lines
net/ipv6/ip6_output.c +0 -0
index f314ba4..7e10f62 100644
@@ -172,8 +172,9 @@ int ip6_output(struct sk_buff *skb)
 		return 0;
 	}
 
Quoted 8 lines

net/ipv6/ip6_output.c int ip6_output(struct sk_buff *skb)

Quoted 5 lines
net/ipv6/ip6_output.c +3 -2
-	return NF_HOOK(NFPROTO_IPV6, NF_INET_POST_ROUTING, skb, NULL, dev,
-		       ip6_finish_output);
+	return NF_HOOK_COND(NFPROTO_IPV6, NF_INET_POST_ROUTING, skb, NULL, dev,
+			    ip6_finish_output,
+			    !(IP6CB(skb)->flags & IPSKB_REROUTED));

This needs to use an IP6SKB value to avoid clashes. I've fixed it up as follows:

Would merging the IPSKB and IP6SKB flags be worth it?

#6 lore raw

Re: [PATCH 2/8] netfilter: ipv6: add IPSKB_REROUTED exclusion to NF_HOOK/POSTROUTING invocation

Quoted 17 lines · Jan Engelhardt
Quoted 8 lines · Patrick McHardy
Quoted 8 lines
net/ipv6/ip6_output.c +0 -0
index f314ba4..7e10f62 100644
@@ -172,8 +172,9 @@ int ip6_output(struct sk_buff *skb)
 		return 0;
 	}
 
Quoted 7 lines

net/ipv6/ip6_output.c int ip6_output(struct sk_buff *skb)

Quoted 5 lines
net/ipv6/ip6_output.c +3 -2
-	return NF_HOOK(NFPROTO_IPV6, NF_INET_POST_ROUTING, skb, NULL, dev,
-		       ip6_finish_output);
+	return NF_HOOK_COND(NFPROTO_IPV6, NF_INET_POST_ROUTING, skb, NULL, dev,
+			    ip6_finish_output,
+			    !(IP6CB(skb)->flags & IPSKB_REROUTED));

This needs to use an IP6SKB value to avoid clashes. I've fixed it up as follows:

Quoted 2 lines

Would merging the IPSKB and IP6SKB flags be worth it?

I don't think so, the CB is by definition private to each layer.

#7 lore raw

PATCH 3/8 netfilter: xtables: inclusion of xt_TEE

In reply to Jan Engelhardt

xt_TEE can be used to clone and reroute a packet. This can for example be used to copy traffic at a router for logging purposes to another dedicated machine.

References: http://www.gossamer-threads.com/lists/iptables/devel/68781

---
 include/linux/netfilter/Kbuild   |    1 +
 include/linux/netfilter/xt_TEE.h |    8 ++
 net/ipv4/ip_output.c             |    1 +
 net/ipv6/ip6_output.c            |    1 +
 net/netfilter/Kconfig            |    7 +
 net/netfilter/Makefile           |    1 +
 net/netfilter/xt_TEE.c           |  232 ++++++++++++++++++++++++++++++++++++++
 7 files changed, 251 insertions(+), 0 deletions(-)
 create mode 100644 include/linux/netfilter/xt_TEE.h
 create mode 100644 net/netfilter/xt_TEE.c
include/linux/netfilter/Kbuild +1 -0
index a5a63e4..48767cd 100644
@@ -16,6 +16,7 @@ header-y += xt_RATEEST.h
 header-y += xt_SECMARK.h
 header-y += xt_TCPMSS.h
 header-y += xt_TCPOPTSTRIP.h
+header-y += xt_TEE.h
 header-y += xt_TPROXY.h
 header-y += xt_comment.h
 header-y += xt_connbytes.h
include/linux/netfilter/xt_TEE.h new file +8 -0
new file mode 100644
index 0000000..83fa768
@@ -0,0 +1,8 @@
+#ifndef _XT_TEE_TARGET_H
+#define _XT_TEE_TARGET_H
+
+struct xt_tee_tginfo {
+	union nf_inet_addr gw;
+};
+
+#endif /* _XT_TEE_TARGET_H */
net/ipv4/ip_output.c +1 -0
index f09135e..0abfdde 100644
@@ -309,6 +309,7 @@ int ip_output(struct sk_buff *skb)
 			    ip_finish_output,
 			    !(IPCB(skb)->flags & IPSKB_REROUTED));
 }
+EXPORT_SYMBOL_GPL(ip_output);
 
 int ip_queue_xmit(struct sk_buff *skb, int ipfragok)
 {
net/ipv6/ip6_output.c +1 -0
index 7e10f62..307d8bf 100644
@@ -176,6 +176,7 @@ int ip6_output(struct sk_buff *skb)
 			    ip6_finish_output,
 			    !(IP6CB(skb)->flags & IPSKB_REROUTED));
 }
+EXPORT_SYMBOL_GPL(ip6_output);
 
 /*
  *	xmit an sk_buff (used by TCP)
net/netfilter/Kconfig +7 -0
index 8055786..673a6c8 100644
@@ -502,6 +502,13 @@ config NETFILTER_XT_TARGET_RATEEST
 
 	  To compile it as a module, choose M here.  If unsure, say N.
 
+config NETFILTER_XT_TARGET_TEE
+	tristate '"TEE" - packet cloning to alternate destiantion'
+	depends on NETFILTER_ADVANCED
+	---help---
+	This option adds a "TEE" target with which a packet can be cloned and
+	this clone be rerouted to another nexthop.
+
 config NETFILTER_XT_TARGET_TPROXY
 	tristate '"TPROXY" target support (EXPERIMENTAL)'
 	depends on EXPERIMENTAL
net/netfilter/Makefile +1 -0
index cd31afe..14e3a8f 100644
@@ -59,6 +59,7 @@ obj-$(CONFIG_NETFILTER_XT_TARGET_SECMARK) += xt_SECMARK.o
 obj-$(CONFIG_NETFILTER_XT_TARGET_TPROXY) += xt_TPROXY.o
 obj-$(CONFIG_NETFILTER_XT_TARGET_TCPMSS) += xt_TCPMSS.o
 obj-$(CONFIG_NETFILTER_XT_TARGET_TCPOPTSTRIP) += xt_TCPOPTSTRIP.o
+obj-$(CONFIG_NETFILTER_XT_TARGET_TEE) += xt_TEE.o
 obj-$(CONFIG_NETFILTER_XT_TARGET_TRACE) += xt_TRACE.o
 
 # matches
net/netfilter/xt_TEE.c new file +232 -0

232 lines not on this page · raw message

Signature · 6 lines
1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#8 lore raw

Re: [PATCH 3/8] netfilter: xtables: inclusion of xt_TEE

include/linux/netfilter/xt_TEE.h line 6

Quoted 8 lines · Jan Engelhardt

+++ b/include/linux/netfilter/xt_TEE.h

include/linux/netfilter/xt_TEE.h new file +6 -0
@@ -0,0 +1,8 @@
+#ifndef _XT_TEE_TARGET_H
+#define _XT_TEE_TARGET_H
+
+struct xt_tee_tginfo {
+	union nf_inet_addr gw;
+};

Mhh, quoting what I wrote earlier:

Quoted 4 lines

That might make it unnessarily complicated to use src-based routing when using TEE. I guess you'd usually have a host for logging or IDS somewhere on a private network and TEE packets there. So specifying oif and gateway seems most useful to me.

This really should support oif in my opinion. Please add this (and update to use IP6SKB while at it). I've pushed out the patches I've applied so far.

BTW, no need to resend the other patches unless there are clashes.

#9 lore raw

Re: [PATCH 3/8] netfilter: xtables: inclusion of xt_TEE

In reply to Jan Engelhardt

net/netfilter/xt_TEE.c line 49

Quoted 13 lines · Jan Engelhardt
net/netfilter/xt_TEE.c new file +13 -0
+static bool
+tee_tg_route4(struct sk_buff *skb, const struct xt_tee_tginfo *info)
+{
+	const struct iphdr *iph = ip_hdr(skb);
+	struct rtable *rt;
+	struct flowi fl;
+
+	memset(&fl, 0, sizeof(fl));
+	fl.nl_u.ip4_u.daddr = info->gw.ip;
+	fl.nl_u.ip4_u.tos   = RT_TOS(iph->tos);
+	fl.nl_u.ip4_u.scope = RT_SCOPE_UNIVERSE;
+
+	if (ip_route_output_key(dev_net(skb->dev), &rt, &fl) != 0) {

You can't use skb->dev in modules that are valid to use in LOCAL_OUT.

net/netfilter/xt_TEE.c line 81

Quoted 6 lines
net/netfilter/xt_TEE.c new file +6 -0
+#ifdef WITH_CONNTRACK
+	nf_conntrack_put(skb->nfct);
+	skb->nfct     = &tee_track.ct_general;
+	skb->nfctinfo = IP_CT_NEW;
+	nf_conntrack_get(skb->nfct);
+#endif

Why do we still need this? I thought the reentrancy-counter should take care of this?

#10 lore raw

Re: [PATCH 3/8] netfilter: xtables: inclusion of xt_TEE

Quoted 17 lines · Patrick McHardy

net/netfilter/xt_TEE.c line 49

Quoted 13 lines · Jan Engelhardt
net/netfilter/xt_TEE.c new file +13 -0
+static bool
+tee_tg_route4(struct sk_buff *skb, const struct xt_tee_tginfo *info)
+{
+	const struct iphdr *iph = ip_hdr(skb);
+	struct rtable *rt;
+	struct flowi fl;
+
+	memset(&fl, 0, sizeof(fl));
+	fl.nl_u.ip4_u.daddr = info->gw.ip;
+	fl.nl_u.ip4_u.tos   = RT_TOS(iph->tos);
+	fl.nl_u.ip4_u.scope = RT_SCOPE_UNIVERSE;
+
+	if (ip_route_output_key(dev_net(skb->dev), &rt, &fl) != 0) {

You can't use skb->dev in modules that are valid to use in LOCAL_OUT.

Quoted 9 lines

net/netfilter/xt_TEE.c line 81

Quoted 6 lines
net/netfilter/xt_TEE.c new file +6 -0
+#ifdef WITH_CONNTRACK
+	nf_conntrack_put(skb->nfct);
+	skb->nfct     = &tee_track.ct_general;
+	skb->nfctinfo = IP_CT_NEW;
+	nf_conntrack_get(skb->nfct);
+#endif

Why do we still need this? I thought the reentrancy-counter should take care of this?

Did I really delete that commit... it's done so that conntrack does not count the duplicated packets towards the original connection.

#11 lore raw

Re: [PATCH 3/8] netfilter: xtables: inclusion of xt_TEE

Quoted 11 lines · Jan Engelhardt
Quoted 10 lines

net/netfilter/xt_TEE.c line 81

Quoted 7 lines
net/netfilter/xt_TEE.c new file +6 -0
+#ifdef WITH_CONNTRACK
+	nf_conntrack_put(skb->nfct);
+	skb->nfct     = &tee_track.ct_general;
+	skb->nfctinfo = IP_CT_NEW;
+	nf_conntrack_get(skb->nfct);
+#endif

Why do we still need this? I thought the reentrancy-counter should take care of this?

Quoted 3 lines

Did I really delete that commit... it's done so that conntrack does not count the duplicated packets towards the original connection.

While at that, would retaining the old skb's nfctinfo make any sense?

#12 lore raw

Re: [PATCH 3/8] netfilter: xtables: inclusion of xt_TEE

Quoted 9 lines · Jan Engelhardt
Quoted 8 lines · Jan Engelhardt
Quoted 8 lines

net/netfilter/xt_TEE.c line 81

Quoted 6 lines
net/netfilter/xt_TEE.c new file +6 -0
+#ifdef WITH_CONNTRACK
+	nf_conntrack_put(skb->nfct);
+	skb->nfct     = &tee_track.ct_general;
+	skb->nfctinfo = IP_CT_NEW;
+	nf_conntrack_get(skb->nfct);
+#endif

Why do we still need this? I thought the reentrancy-counter should take care of this?

Quoted 5 lines
Quoted 3 lines

Did I really delete that commit... it's done so that conntrack does not count the duplicated packets towards the original connection.

While at that, would retaining the old skb's nfctinfo make any sense?

I don't think so.

#13 lore raw

Re: [PATCH 3/8] netfilter: xtables: inclusion of xt_TEE

In reply to Jan Engelhardt
Quoted 27 lines · Jan Engelhardt
Quoted 16 lines · Patrick McHardy

net/netfilter/xt_TEE.c line 49

Quoted 13 lines · Jan Engelhardt
net/netfilter/xt_TEE.c new file +13 -0
+static bool
+tee_tg_route4(struct sk_buff *skb, const struct xt_tee_tginfo *info)
+{
+	const struct iphdr *iph = ip_hdr(skb);
+	struct rtable *rt;
+	struct flowi fl;
+
+	memset(&fl, 0, sizeof(fl));
+	fl.nl_u.ip4_u.daddr = info->gw.ip;
+	fl.nl_u.ip4_u.tos   = RT_TOS(iph->tos);
+	fl.nl_u.ip4_u.scope = RT_SCOPE_UNIVERSE;
+
+	if (ip_route_output_key(dev_net(skb->dev), &rt, &fl) != 0) {

You can't use skb->dev in modules that are valid to use in LOCAL_OUT.

Quoted 8 lines

net/netfilter/xt_TEE.c line 81

Quoted 6 lines
net/netfilter/xt_TEE.c new file +6 -0
+#ifdef WITH_CONNTRACK
+	nf_conntrack_put(skb->nfct);
+	skb->nfct     = &tee_track.ct_general;
+	skb->nfctinfo = IP_CT_NEW;
+	nf_conntrack_get(skb->nfct);
+#endif

Why do we still need this? I thought the reentrancy-counter should take care of this?

Quoted 3 lines

Did I really delete that commit... it's done so that conntrack does not count the duplicated packets towards the original connection.

Simply untrack it perhaps?

#14 lore raw

Re: [PATCH 3/8] netfilter: xtables: inclusion of xt_TEE

Quoted 5 lines · Patrick McHardy
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
net/netfilter/xt_TEE.c new file +5 -0
+tee_tg_route4(struct sk_buff *skb, const struct xt_tee_tginfo *info)
+{
+	const struct iphdr *iph = ip_hdr(skb);
+	struct rtable *rt;
+	struct flowi fl;
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

net/netfilter/xt_TEE.c line 49

Quoted 7 lines
net/netfilter/xt_TEE.c new file +7 -0
+
+	memset(&fl, 0, sizeof(fl));
+	fl.nl_u.ip4_u.daddr = info->gw.ip;
+	fl.nl_u.ip4_u.tos   = RT_TOS(iph->tos);
+	fl.nl_u.ip4_u.scope = RT_SCOPE_UNIVERSE;
+
+	if (ip_route_output_key(dev_net(skb->dev), &rt, &fl) != 0) {

You can't use skb->dev in modules that are valid to use in LOCAL_OUT.

Let's use dev_net(skb_dst(skb)->dev). skb_dst seems fine, as __ip_local_out already makes use of it.

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines

net/netfilter/xt_TEE.c line 81

Quoted 6 lines
net/netfilter/xt_TEE.c new file +6 -0
+#ifdef WITH_CONNTRACK
+	nf_conntrack_put(skb->nfct);
+	skb->nfct     = &tee_track.ct_general;
+	skb->nfctinfo = IP_CT_NEW;
+	nf_conntrack_get(skb->nfct);
+#endif

Why do we still need this? I thought the reentrancy-counter should take care of this?

Quoted 5 lines
Quoted 3 lines

Did I really delete that commit... it's done so that conntrack does not count the duplicated packets towards the original connection.

Simply untrack it perhaps?

Well, that's what the four lines do, that's what NOTRACK does - assigning to a fake nfct, isn't it?

thanks,
Jan

#15 lore raw

Re: [PATCH 3/8] netfilter: xtables: inclusion of xt_TEE

Quoted 10 lines · Jan Engelhardt
Quoted 8 lines · Patrick McHardy
Quoted 8 lines
Quoted 8 lines

net/netfilter/xt_TEE.c line 81

Quoted 6 lines
net/netfilter/xt_TEE.c new file +6 -0
+#ifdef WITH_CONNTRACK
+	nf_conntrack_put(skb->nfct);
+	skb->nfct     = &tee_track.ct_general;
+	skb->nfctinfo = IP_CT_NEW;
+	nf_conntrack_get(skb->nfct);
+#endif

Why do we still need this? I thought the reentrancy-counter should take care of this?

Quoted 7 lines
Quoted 4 lines
Quoted 3 lines

Did I really delete that commit... it's done so that conntrack does not count the duplicated packets towards the original connection.

Simply untrack it perhaps?

Well, that's what the four lines do, that's what NOTRACK does - assigning to a fake nfct, isn't it?

Yeah, but a different one from the untracked conntrack, which is already explicitly checked for where necessary.

#16 lore raw

PATCH 4/8 netfilter: xtables2: make ip_tables reentrant

In reply to Jan Engelhardt

Currently, the table traverser stores return addresses in the ruleset itself (struct ip6t_entry->comefrom). This has a well-known drawback:
the jumpstack is overwritten on reentry, making it necessary for targets to return absolute verdicts. Also, the ruleset (which might be heavy memory-wise) needs to be replicated for each CPU that can possibly invoke ip6t_do_table.

This patch decouples the jumpstack from struct ip6t_entry and instead puts it into xt_table_info. Not being restricted by 'comefrom' anymore, we can set up a stack as needed. By default, there is room allocated for two entries into the traverser. The setting is configurable at runtime through sysfs and will take effect when a table is replaced by a new one.

arp_tables is not touched though, because there is just one/two modules and further patches seek to collapse the table traverser anyhow.

---
 include/linux/netfilter/x_tables.h |    7 +++
 net/ipv4/netfilter/arp_tables.c    |    6 ++-
 net/ipv4/netfilter/ip_tables.c     |   65 ++++++++++++++++--------------
 net/ipv6/netfilter/ip6_tables.c    |   56 ++++++++++----------------
 net/netfilter/x_tables.c           |   77 ++++++++++++++++++++++++++++++++++++
 5 files changed, 145 insertions(+), 66 deletions(-)
include/linux/netfilter/x_tables.h +7 -0
index 26ced0c..50c8672 100644
@@ -401,6 +401,13 @@ struct xt_table_info {
 	unsigned int hook_entry[NF_INET_NUMHOOKS];
 	unsigned int underflow[NF_INET_NUMHOOKS];
 
+	/*
+	 * Number of user chains. Since tables cannot have loops, at most
+	 * @stacksize jumps (number of user chains) can possibly be made.
+	 */
+	unsigned int stacksize;
+	unsigned int *stackptr;
+	void ***jumpstack;
 	/* ipt_entry tables: one per CPU */
 	/* Note : this field MUST be the last one, see XT_TABLE_INFO_SZ */
 	void *entries[1];
net/ipv4/netfilter/arp_tables.c +4 -2
index e8e363d..07a6990 100644
@@ -649,6 +649,9 @@ static int translate_table(struct xt_table_info *newinfo, void *entry0,
 		if (ret != 0)
 			break;
 		++i;
+		if (strcmp(arpt_get_target(iter)->u.user.name,
+		    XT_ERROR_TARGET) == 0)
+			++newinfo->stacksize;
 	}
 	duprintf("translate_table: ARPT_ENTRY_ITERATE gives %d\n", ret);
 	if (ret != 0)
@@ -1774,8 +1777,7 @@ struct xt_table *arpt_register_table(struct net *net,
 {
 	int ret;
 	struct xt_table_info *newinfo;
-	struct xt_table_info bootstrap
-		= { 0, 0, 0, { 0 }, { 0 }, { } };
+	struct xt_table_info bootstrap = {0};
 	void *loc_cpu_entry;
 	struct xt_table *new_table;
 
net/ipv4/netfilter/ip_tables.c +35 -30

133 lines not on this page · raw message

net/ipv6/netfilter/ip6_tables.c +22 -34

124 lines not on this page · raw message

net/netfilter/x_tables.c +77 -0

113 lines not on this page · raw message

Signature · 1 line
1.7.0.4
#17 lore raw

PATCH 5/8 netfilter: xt_TEE: have cloned packet travel through Xtables too

In reply to Jan Engelhardt

Since Xtables is now reentrant/nestable, the cloned packet can also go through Xtables and be subject to rules itself.

---
 net/ipv4/ip_output.c   |    1 -
 net/ipv6/ip6_output.c  |    1 -
 net/netfilter/xt_TEE.c |   38 +++++++++++++++++---------------------
 3 files changed, 17 insertions(+), 23 deletions(-)
net/ipv4/ip_output.c +0 -1
index 0abfdde..f09135e 100644
@@ -309,7 +309,6 @@ int ip_output(struct sk_buff *skb)
 			    ip_finish_output,
 			    !(IPCB(skb)->flags & IPSKB_REROUTED));
 }
-EXPORT_SYMBOL_GPL(ip_output);
 
 int ip_queue_xmit(struct sk_buff *skb, int ipfragok)
 {
net/ipv6/ip6_output.c +0 -1
index 307d8bf..7e10f62 100644
@@ -176,7 +176,6 @@ int ip6_output(struct sk_buff *skb)
 			    ip6_finish_output,
 			    !(IP6CB(skb)->flags & IPSKB_REROUTED));
 }
-EXPORT_SYMBOL_GPL(ip6_output);
 
 /*
  *	xmit an sk_buff (used by TCP)
net/netfilter/xt_TEE.c +17 -21
index 79c5bf9..8ff8db4 100644
@@ -12,6 +12,7 @@
  */
 #include <linux/ip.h>
 #include <linux/module.h>
+#include <linux/percpu.h>
 #include <linux/route.h>
 #include <linux/skbuff.h>
 #include <net/checksum.h>
@@ -33,6 +34,7 @@ static struct nf_conn tee_track;
 #endif
 
 static const union nf_inet_addr tee_zero_address;
+static DEFINE_PER_CPU(bool, tee_active);
 
 static bool
 tee_tg_route4(struct sk_buff *skb, const struct xt_tee_tginfo *info)
@@ -63,13 +65,15 @@ tee_tg4(struct sk_buff *skb, const struct xt_target_param *par)
 	const struct xt_tee_tginfo *info = par->targinfo;
 	struct iphdr *iph;
 
+	if (percpu_read(tee_active))
+		return XT_CONTINUE;
 	/*
 	 * Copy the skb, and route the copy. Will later return %XT_CONTINUE for
 	 * the original skb, which should continue on its way as if nothing has
 	 * happened. The copy should be independently delivered to the TEE
 	 * --gateway.
 	 */
-	skb = skb_copy(skb, GFP_ATOMIC);
+	skb = pskb_copy(skb, GFP_ATOMIC);
 	if (skb == NULL)
 		return XT_CONTINUE;
 
@@ -96,22 +100,11 @@ tee_tg4(struct sk_buff *skb, const struct xt_target_param *par)
 		--iph->ttl;
 	ip_send_check(iph);
 
-	/*
-	 * Xtables is not reentrant currently, so a choice has to be made:
-	 * 1. return absolute verdict for the original and let the cloned
-	 *    packet travel through the chains
-	 * 2. let the original continue travelling and not pass the clone
-	 *    to Xtables.
-	 * #2 is chosen. Normally, we would use ip_local_out for the clone.
-	 * Because iph->check is already correct and we don't pass it to
-	 * Xtables anyway, a shortcut to dst_output [forwards to ip_output] can
-	 * be taken. %IPSKB_REROUTED needs to be set so that ip_output does not
-	 * invoke POSTROUTING on the cloned packet.
-	 */
-	IPCB(skb)->flags |= IPSKB_REROUTED;
-	if (tee_tg_route4(skb, info))
-		ip_output(skb);
-
+	if (tee_tg_route4(skb, info)) {
+		percpu_write(tee_active, true);
+		ip_local_out(skb);
+		percpu_write(tee_active, false);
+	}
 	return XT_CONTINUE;
 }
 
@@ -145,6 +138,8 @@ tee_tg6(struct sk_buff *skb, const struct xt_target_param *par)
 {
 	const struct xt_tee_tginfo *info = par->targinfo;
 
+	if (percpu_read(tee_active))
+		return XT_CONTINUE;
 	if ((skb = skb_copy(skb, GFP_ATOMIC)) == NULL)
 		return XT_CONTINUE;
 
@@ -159,10 +154,11 @@ tee_tg6(struct sk_buff *skb, const struct xt_target_param *par)
 		struct ipv6hdr *iph = ipv6_hdr(skb);
 		--iph->hop_limit;
 	}
-	IP6CB(skb)->flags |= IPSKB_REROUTED;
-	if (tee_tg_route6(skb, info))
-		ip6_output(skb);
-
+	if (tee_tg_route6(skb, info)) {
+		percpu_write(tee_active, true);
+		ip6_local_out(skb);
+		percpu_write(tee_active, false);
+	}
 	return XT_CONTINUE;
 }
 #endif /* WITH_IPV6 */
Signature · 1 line
1.7.0.4
#18 lore raw

PATCH 6/8 netfilter: xtables: remove old comments about reentrancy

In reply to Jan Engelhardt
---
 net/ipv4/netfilter/ip_tables.c   |    2 --
 net/ipv4/netfilter/ipt_REJECT.c  |    3 ---
 net/ipv6/netfilter/ip6_tables.c  |    2 --
 net/ipv6/netfilter/ip6t_REJECT.c |    3 ---
 4 files changed, 0 insertions(+), 10 deletions(-)
net/ipv4/netfilter/ip_tables.c +0 -2
index 70900ec..bb5e0d9 100644
@@ -434,8 +434,6 @@ ipt_do_table(struct sk_buff *skb,
 			continue;
 		}
 
-		/* Targets which reenter must return
-		   abs. verdicts */
 		tgpar.target   = t->u.kernel.target;
 		tgpar.targinfo = t->data;
 
net/ipv4/netfilter/ipt_REJECT.c +0 -3
index b026014..038fa0b 100644
@@ -139,9 +139,6 @@ reject_tg(struct sk_buff *skb, const struct xt_target_param *par)
 {
 	const struct ipt_reject_info *reject = par->targinfo;
 
-	/* WARNING: This code causes reentry within iptables.
-	   This means that the iptables jump stack is now crap.  We
-	   must return an absolute verdict. --RR */
 	switch (reject->with) {
 	case IPT_ICMP_NET_UNREACHABLE:
 		send_unreach(skb, ICMP_NET_UNREACH);
net/ipv6/netfilter/ip6_tables.c +0 -2
index 2a2770b..7afa117 100644
@@ -451,8 +451,6 @@ ip6t_do_table(struct sk_buff *skb,
 			continue;
 		}
 
-		/* Targets which reenter must return
-		   abs. verdicts */
 		tgpar.target   = t->u.kernel.target;
 		tgpar.targinfo = t->data;
 
net/ipv6/netfilter/ip6t_REJECT.c +0 -3
index 55b9b2d..dad9762 100644
@@ -179,9 +179,6 @@ reject_tg6(struct sk_buff *skb, const struct xt_target_param *par)
 	struct net *net = dev_net((par->in != NULL) ? par->in : par->out);
 
 	pr_debug("%s: medium point\n", __func__);
-	/* WARNING: This code causes reentry within ip6tables.
-	   This means that the ip6tables jump stack is now crap.  We
-	   must return an absolute verdict. --RR */
 	switch (reject->with) {
 	case IP6T_ICMP6_NO_ROUTE:
 		send_unreach(net, skb, ICMPV6_NOROUTE, par->hooknum);
Signature · 1 line
1.7.0.4
#19 lore raw

PATCH 7/8 netfilter: xtables: inclusion of xt_SYSRQ

In reply to Jan Engelhardt

The SYSRQ target will allow to remotely invoke sysrq on the local machine. Authentication is by means of a pre-shared key that can either be transmitted plaintext or digest-secured.

---
 net/netfilter/Kconfig    |   12 ++
 net/netfilter/Makefile   |    1 +
 net/netfilter/xt_SYSRQ.c |  354 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 367 insertions(+), 0 deletions(-)
 create mode 100644 net/netfilter/xt_SYSRQ.c
net/netfilter/Kconfig +12 -0
index 673a6c8..bfd9b6f 100644
@@ -502,6 +502,18 @@ config NETFILTER_XT_TARGET_RATEEST
 
 	  To compile it as a module, choose M here.  If unsure, say N.
 
+config NETFILTER_XT_TARGET_SYSRQ
+	tristate '"SYSRQ" - remote sysrq invocation'
+	depends on NETFILTER_ADVANCED
+	---help---
+	This option enables the "SYSRQ" target which can be used to trigger
+	sysrq from a remote machine using a magic UDP packet with a pre-shared
+	password. This is useful when the receiving host has locked up in an
+	Oops yet still can process incoming packets.
+
+	Besides plaintext packets, digest-secured SYSRQ requests will be
+	supported when CONFIG_CRYPTO is enabled.
+
 config NETFILTER_XT_TARGET_TEE
 	tristate '"TEE" - packet cloning to alternate destiantion'
 	depends on NETFILTER_ADVANCED
net/netfilter/Makefile +1 -0
index 14e3a8f..f032195 100644
@@ -56,6 +56,7 @@ obj-$(CONFIG_NETFILTER_XT_TARGET_NFQUEUE) += xt_NFQUEUE.o
 obj-$(CONFIG_NETFILTER_XT_TARGET_NOTRACK) += xt_NOTRACK.o
 obj-$(CONFIG_NETFILTER_XT_TARGET_RATEEST) += xt_RATEEST.o
 obj-$(CONFIG_NETFILTER_XT_TARGET_SECMARK) += xt_SECMARK.o
+obj-$(CONFIG_NETFILTER_XT_TARGET_SYSRQ) += xt_SYSRQ.o
 obj-$(CONFIG_NETFILTER_XT_TARGET_TPROXY) += xt_TPROXY.o
 obj-$(CONFIG_NETFILTER_XT_TARGET_TCPMSS) += xt_TCPMSS.o
 obj-$(CONFIG_NETFILTER_XT_TARGET_TCPOPTSTRIP) += xt_TCPOPTSTRIP.o
net/netfilter/xt_SYSRQ.c new file +354 -0

354 lines not on this page · raw message

Signature · 6 lines
1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#20 lore raw

PATCH 8/8 netfilter: xtables: inclusion of xt_condition

In reply to Jan Engelhardt

xt_condition can be used by userspace to influence decisions in rules by means of togglable variables without having to reload the entire ruleset.

---
 include/linux/netfilter/Kbuild         |    1 +
 include/linux/netfilter/xt_condition.h |   14 ++
 net/netfilter/Kconfig                  |    8 +
 net/netfilter/Makefile                 |    1 +
 net/netfilter/xt_condition.c           |  243 ++++++++++++++++++++++++++++++++
 5 files changed, 267 insertions(+), 0 deletions(-)
 create mode 100644 include/linux/netfilter/xt_condition.h
 create mode 100644 net/netfilter/xt_condition.c
include/linux/netfilter/Kbuild +1 -0
index 48767cd..6b67603 100644
@@ -19,6 +19,7 @@ header-y += xt_TCPOPTSTRIP.h
 header-y += xt_TEE.h
 header-y += xt_TPROXY.h
 header-y += xt_comment.h
+header-y += xt_condition.h
 header-y += xt_connbytes.h
 header-y += xt_connlimit.h
 header-y += xt_connmark.h
include/linux/netfilter/xt_condition.h new file +14 -0
new file mode 100644
index 0000000..4faf3ca
@@ -0,0 +1,14 @@
+#ifndef _XT_CONDITION_H
+#define _XT_CONDITION_H
+
+#include <linux/types.h>
+
+struct xt_condition_mtinfo {
+	char name[31];
+	__u8 invert;
+
+	/* Used internally by the kernel */
+	void *condvar __attribute__((aligned(8)));
+};
+
+#endif /* _XT_CONDITION_H */
net/netfilter/Kconfig +8 -0
index bfd9b6f..dd74e7d 100644
@@ -624,6 +624,14 @@ config NETFILTER_XT_MATCH_COMMENT
 	  If you want to compile it as a module, say M here and read
 	  <file:Documentation/kbuild/modules.txt>.  If unsure, say `N'.
 
+config NETFILTER_XT_MATCH_CONDITION
+	tristate '"condition" match support'
+	depends on NETFILTER_ADVANCED
+	depends on PROC_FS
+	---help---
+	This option allows you to match firewall rules against condition
+	variables stored in the /proc/net/nf_condition directory.
+
 config NETFILTER_XT_MATCH_CONNBYTES
 	tristate  '"connbytes" per-connection counter match support'
 	depends on NF_CONNTRACK
net/netfilter/Makefile +1 -0
index f032195..e75d5fa 100644
@@ -66,6 +66,7 @@ obj-$(CONFIG_NETFILTER_XT_TARGET_TRACE) += xt_TRACE.o
 # matches
 obj-$(CONFIG_NETFILTER_XT_MATCH_CLUSTER) += xt_cluster.o
 obj-$(CONFIG_NETFILTER_XT_MATCH_COMMENT) += xt_comment.o
+obj-$(CONFIG_NETFILTER_XT_MATCH_CONDITION) += xt_condition.o
 obj-$(CONFIG_NETFILTER_XT_MATCH_CONNBYTES) += xt_connbytes.o
 obj-$(CONFIG_NETFILTER_XT_MATCH_CONNLIMIT) += xt_connlimit.o
 obj-$(CONFIG_NETFILTER_XT_MATCH_CONNTRACK) += xt_conntrack.o
net/netfilter/xt_condition.c new file +243 -0

243 lines not on this page · raw message

Signature · 1 line
1.7.0.4
#21 lore raw
In reply to Jan Engelhardt
Quoted 2 lines · Jan Engelhardt

per request, the series reposted with fixes applied. I also tacked sysrq and condition on.

One thing at a time. Generally, I don't want series that we were just finished discussing extended but seperate submissions for new stuff.