Skip to contentSkip to conversation

netfilter: xt_TEE: get rid of WITH_CONNTRACK definition

PATCH In review Pablo Neira Ayuso 2 participants 5 messages Aug 4, 2015

Subsystems (2)
lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/3 netfilter: xt_TEE: get rid of WITH_CONNTRACK definition

Use IS_ENABLED(CONFIG_NF_CONNTRACK) instead.

---
 net/netfilter/xt_TEE.c |    8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
net/netfilter/xt_TEE.c +3 -5
index c5d6556..0ed9fb6 100644
@@ -24,10 +24,8 @@
 #include <net/route.h>
 #include <linux/netfilter/x_tables.h>
 #include <linux/netfilter/xt_TEE.h>
-
 #if IS_ENABLED(CONFIG_NF_CONNTRACK)
-#	define WITH_CONNTRACK 1
-#	include <net/netfilter/nf_conntrack.h>
+#include <net/netfilter/nf_conntrack.h>
 #endif
 
 struct xt_tee_priv {
@@ -99,7 +97,7 @@ tee_tg4(struct sk_buff *skb, const struct xt_action_param *par)
 	if (skb == NULL)
 		return XT_CONTINUE;
 
-#ifdef WITH_CONNTRACK
+#if IS_ENABLED(CONFIG_NF_CONNTRACK)
 	/* Avoid counting cloned packets towards the original connection. */
 	nf_conntrack_put(skb->nfct);
 	skb->nfct     = &nf_ct_untracked_get()->ct_general;
@@ -175,7 +173,7 @@ tee_tg6(struct sk_buff *skb, const struct xt_action_param *par)
 	if (skb == NULL)
 		return XT_CONTINUE;
 
-#ifdef WITH_CONNTRACK
+#if IS_ENABLED(CONFIG_NF_CONNTRACK)
 	nf_conntrack_put(skb->nfct);
 	skb->nfct     = &nf_ct_untracked_get()->ct_general;
 	skb->nfctinfo = IP_CT_NEW;
Signature · 1 line
1.7.10.4
author maintainer
#1 lore raw

=?y?q?=5BPATCH=20nf-next=202/3=5D=20netfilter=3A=20factor=20out=20packet=20duplication=20for=20IPv4/IPv6?=

Extracted from the xtables TEE target. This creates two new modules for IPv4 and IPv6 that are shared between the TEE target and the new nf_tables dup expressions.

---
 include/net/netfilter/ipv4/nf_dup_ipv4.h |    7 ++
 include/net/netfilter/ipv6/nf_dup_ipv6.h |    7 ++
 net/ipv4/netfilter/Kconfig               |    6 ++
 net/ipv4/netfilter/Makefile              |    2 +
 net/ipv4/netfilter/nf_dup_ipv4.c         |  121 ++++++++++++++++++++++
 net/ipv6/netfilter/Kconfig               |    6 ++
 net/ipv6/netfilter/Makefile              |    2 +
 net/ipv6/netfilter/nf_dup_ipv6.c         |   97 ++++++++++++++++++
 net/netfilter/Kconfig                    |    2 +
 net/netfilter/xt_TEE.c                   |  162 ++----------------------------
 10 files changed, 256 insertions(+), 156 deletions(-)
 create mode 100644 include/net/netfilter/ipv4/nf_dup_ipv4.h
 create mode 100644 include/net/netfilter/ipv6/nf_dup_ipv6.h
 create mode 100644 net/ipv4/netfilter/nf_dup_ipv4.c
 create mode 100644 net/ipv6/netfilter/nf_dup_ipv6.c
include/net/netfilter/ipv4/nf_dup_ipv4.h new file +7 -0
new file mode 100644
index 0000000..dc54e30
@@ -0,0 +1,7 @@
+#ifndef _NF_DUP_IPV4_H_
+#define _NF_DUP_IPV4_H_
+
+unsigned int nf_dup_ipv4(struct sk_buff *skb, unsigned int hooknum,
+			 const struct in_addr *gw, int oif);
+
+#endif /* _NF_DUP_IPV4_H_ */
include/net/netfilter/ipv6/nf_dup_ipv6.h new file +7 -0
new file mode 100644
index 0000000..37b598a
@@ -0,0 +1,7 @@
+#ifndef _NF_DUP_IPV6_H_
+#define _NF_DUP_IPV6_H_
+
+unsigned int nf_dup_ipv6(struct sk_buff *skb, unsigned int hooknum,
+			 const struct in6_addr *gw, int oif);
+
+#endif /* _NF_DUP_IPV6_H_ */
net/ipv4/netfilter/Kconfig +6 -0
index 2199a5d..0142ea2 100644
@@ -67,6 +67,12 @@ config NF_TABLES_ARP
 
 endif # NF_TABLES
 
+config NF_DUP_IPV4
+	tristate "Netfilter IPv4 packet duplication to alternate destination"
+	help
+	  This option enables the nf_dup_ipv4 core, which duplicates an IPv4
+	  packet to be rerouted to another destination.
+
 config NF_LOG_ARP
 	tristate "ARP packet logging"
 	default m if NETFILTER_ADVANCED=n
net/ipv4/netfilter/Makefile +2 -0
index 7fe6c70..9136ffc 100644
@@ -70,3 +70,5 @@ obj-$(CONFIG_IP_NF_ARP_MANGLE) += arpt_mangle.o
 
 # just filtering instance of ARP tables for now
 obj-$(CONFIG_IP_NF_ARPFILTER) += arptable_filter.o
+
+obj-$(CONFIG_NF_DUP_IPV4) += nf_dup_ipv4.o
net/ipv4/netfilter/nf_dup_ipv4.c new file +121 -0

121 lines not on this page · raw message

net/ipv6/netfilter/Kconfig +6 -0
index b552cf0..298daf3 100644
@@ -50,6 +50,12 @@ config NFT_REJECT_IPV6
 endif # NF_TABLES_IPV6
 endif # NF_TABLES
 
+config NF_DUP_IPV6
+	tristate "Netfilter IPv6 packet duplication to alternate destination"
+	help
+	  This option enables the nf_dup_ipv6 core, which duplicates an IPv6
+	  packet to be rerouted to another destination.
+
 config NF_REJECT_IPV6
 	tristate "IPv6 packet rejection"
 	default m if NETFILTER_ADVANCED=n
net/ipv6/netfilter/Makefile +2 -0
index c36e0a5..dc6c732 100644
@@ -30,6 +30,8 @@ obj-$(CONFIG_NF_LOG_IPV6) += nf_log_ipv6.o
 # reject
 obj-$(CONFIG_NF_REJECT_IPV6) += nf_reject_ipv6.o
 
+obj-$(CONFIG_NF_DUP_IPV6) += nf_dup_ipv6.o
+
 # nf_tables
 obj-$(CONFIG_NF_TABLES_IPV6) += nf_tables_ipv6.o
 obj-$(CONFIG_NFT_CHAIN_ROUTE_IPV6) += nft_chain_route_ipv6.o
net/ipv6/netfilter/nf_dup_ipv6.c new file +97 -0

97 lines not on this page · raw message

net/netfilter/Kconfig +2 -0
index 6eae69a..3e1b4ab 100644
@@ -867,6 +867,8 @@ config NETFILTER_XT_TARGET_TEE
 	depends on NETFILTER_ADVANCED
 	depends on IPV6 || IPV6=n
 	depends on !NF_CONNTRACK || NF_CONNTRACK
+	select NF_DUP_IPV4
+	select NF_DUP_IPV6 if IP6_NF_IPTABLES
 	---help---
 	This option adds a "TEE" target with which a packet can be cloned and
 	this clone be rerouted to another nexthop.
net/netfilter/xt_TEE.c +6 -156

191 lines not on this page · raw message

Signature · 6 lines
1.7.10.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
maintainer
#2 lore raw

Re: [PATCH nf-next 2/3] netfilter: factor out packet duplication for IPv4/IPv6

Quoted 9 lines · Pablo Neira Ayuso

Extracted from the xtables TEE target. This creates two new modules for IPv4 and IPv6 that are shared between the TEE target and the new nf_tables dup expressions.

net/ipv4/netfilter/nf_dup_ipv4.c new file +0 -0
new file mode 100644
index 0000000..feba24a

net/ipv4/netfilter/nf_dup_ipv4.c line 73

Quoted 7 lines
net/ipv4/netfilter/nf_dup_ipv4.c new file +7 -0
+unsigned int nf_dup_ipv4(struct sk_buff *skb, unsigned int hooknum,
+			 const struct in_addr *gw, int oif)
+{
+	struct iphdr *iph;
+
+	if (__this_cpu_read(nf_skb_duplicated))
+		return XT_CONTINUE;

Nit: seems function doesn't need to return anything. So the use of XT_* outisde xt core can be avoided.

author maintainer
#3 lore raw

Re: [PATCH nf-next 2/3] netfilter: factor out packet duplication for IPv4/IPv6

Quoted 5 lines · Florian Westphal
Quoted 3 lines · Pablo Neira Ayuso

Extracted from the xtables TEE target. This creates two new modules for IPv4 and IPv6 that are shared between the TEE target and the new nf_tables dup expressions.

Quoted 15 lines

net/ipv4/netfilter/nf_dup_ipv4.c line 73

Quoted 12 lines
net/ipv4/netfilter/nf_dup_ipv4.c new file +7 -0
new file mode 100644
index 0000000..feba24a
+unsigned int nf_dup_ipv4(struct sk_buff *skb, unsigned int hooknum,
+			 const struct in_addr *gw, int oif)
+{
+	struct iphdr *iph;
+
+	if (__this_cpu_read(nf_skb_duplicated))
+		return XT_CONTINUE;

Nit: seems function doesn't need to return anything. So the use of XT_* outisde xt core can be avoided.

Unless someone else finds any other problem, I'll fix this nit here and apply. Thanks for spotting this Florian.

author maintainer
#4 lore raw

PATCH 3/3 netfilter: nf_tables: add nft_dup expression

In reply to Pablo Neira Ayuso

This new expression uses the nf_dup engine to clone packets to a given gateway. Unlike xt_TEE, we use an index to indicate output interface which should be fine at this stage.

Moreover, change to the preemtion-safe this_cpu_read(nf_skb_duplicated) from nf_dup_ipv{4,6} to silence a lockdep splat.

Based on the original tee expression from Arturo Borrero Gonzalez, although this patch has diverted quite a bit from this initial effort due to the change to support maps.

---
 include/net/netfilter/nft_dup.h          |    9 +++
 include/uapi/linux/netfilter/nf_tables.h |   14 ++++
 net/ipv4/netfilter/Kconfig               |    6 ++
 net/ipv4/netfilter/Makefile              |    1 +
 net/ipv4/netfilter/nf_dup_ipv4.c         |    2 +-
 net/ipv4/netfilter/nft_dup_ipv4.c        |  110 ++++++++++++++++++++++++++++++
 net/ipv6/netfilter/Kconfig               |    6 ++
 net/ipv6/netfilter/Makefile              |    1 +
 net/ipv6/netfilter/nf_dup_ipv6.c         |    2 +-
 net/ipv6/netfilter/nft_dup_ipv6.c        |  108 +++++++++++++++++++++++++++++
 10 files changed, 257 insertions(+), 2 deletions(-)
 create mode 100644 include/net/netfilter/nft_dup.h
 create mode 100644 net/ipv4/netfilter/nft_dup_ipv4.c
 create mode 100644 net/ipv6/netfilter/nft_dup_ipv6.c
include/net/netfilter/nft_dup.h new file +9 -0
new file mode 100644
index 0000000..6b84cf6
@@ -0,0 +1,9 @@
+#ifndef _NFT_DUP_H_
+#define _NFT_DUP_H_
+
+struct nft_dup_inet {
+	enum nft_registers	sreg_addr:8;
+	enum nft_registers	sreg_dev:8;
+};
+
+#endif /* _NFT_DUP_H_ */
include/uapi/linux/netfilter/nf_tables.h +14 -0
index a99e6a9..059ed29 100644
@@ -936,6 +936,20 @@ enum nft_redir_attributes {
 #define NFTA_REDIR_MAX		(__NFTA_REDIR_MAX - 1)
 
 /**
+ * enum nft_tee_attributes - nf_tables tee expression netlink attributes
+ *
+ * @NFTA_DUP_SREG_ADDR: source register of address (NLA_U32: nft_registers)
+ * @NFTA_DUP_SREG_DEV: source register of output interface (NLA_U32: nft_register)
+ */
+enum nft_tee_attributes {
+	NFTA_DUP_UNSPEC,
+	NFTA_DUP_SREG_ADDR,
+	NFTA_DUP_SREG_DEV,
+	__NFTA_DUP_MAX
+};
+#define NFTA_DUP_MAX		(__NFTA_DUP_MAX - 1)
+
+/**
  * enum nft_gen_attributes - nf_tables ruleset generation attributes
  *
  * @NFTA_GEN_ID: Ruleset generation ID (NLA_U32)
net/ipv4/netfilter/Kconfig +6 -0
index 0142ea2..799fb2b 100644
@@ -58,6 +58,12 @@ config NFT_REJECT_IPV4
 	default NFT_REJECT
 	tristate
 
+config NFT_DUP_IPV4
+	tristate "IPv4 tee suport for nf_tables"
+	select NF_DUP_IPV4
+	help
+	  This is the module that provides IPv4 tee support for nf_tables.
+
 endif # NF_TABLES_IPV4
 
 config NF_TABLES_ARP
net/ipv4/netfilter/Makefile +1 -0
index 9136ffc..87b073d 100644
@@ -41,6 +41,7 @@ obj-$(CONFIG_NFT_CHAIN_NAT_IPV4) += nft_chain_nat_ipv4.o
 obj-$(CONFIG_NFT_REJECT_IPV4) += nft_reject_ipv4.o
 obj-$(CONFIG_NFT_MASQ_IPV4) += nft_masq_ipv4.o
 obj-$(CONFIG_NFT_REDIR_IPV4) += nft_redir_ipv4.o
+obj-$(CONFIG_NFT_DUP_IPV4) += nft_dup_ipv4.o
 obj-$(CONFIG_NF_TABLES_ARP) += nf_tables_arp.o
 
 # generic IP tables 
net/ipv4/netfilter/nf_dup_ipv4.c +1 -1
index feba24a..5a9cf5e 100644
@@ -69,7 +69,7 @@ unsigned int nf_dup_ipv4(struct sk_buff *skb, unsigned int hooknum,
 {
 	struct iphdr *iph;
 
-	if (__this_cpu_read(nf_skb_duplicated))
+	if (this_cpu_read(nf_skb_duplicated))
 		return XT_CONTINUE;
 	/*
 	 * Copy the skb, and route the copy. Will later return %XT_CONTINUE for
net/ipv4/netfilter/nft_dup_ipv4.c new file +110 -0

110 lines not on this page · raw message

net/ipv6/netfilter/Kconfig +6 -0
index 298daf3..496ad16 100644
@@ -47,6 +47,12 @@ config NFT_REJECT_IPV6
 	default NFT_REJECT
 	tristate
 
+config NFT_DUP_IPV6
+	tristate "IPv6 tee support for nf_tables"
+	select NF_DUP_IPV6
+	help
+	  This is the module that provides IPv6 tee support for nf_tables.
+
 endif # NF_TABLES_IPV6
 endif # NF_TABLES
 
net/ipv6/netfilter/Makefile +1 -0
index dc6c732..b4f7d0b 100644
@@ -39,6 +39,7 @@ obj-$(CONFIG_NFT_CHAIN_NAT_IPV6) += nft_chain_nat_ipv6.o
 obj-$(CONFIG_NFT_REJECT_IPV6) += nft_reject_ipv6.o
 obj-$(CONFIG_NFT_MASQ_IPV6) += nft_masq_ipv6.o
 obj-$(CONFIG_NFT_REDIR_IPV6) += nft_redir_ipv6.o
+obj-$(CONFIG_NFT_DUP_IPV6) += nft_dup_ipv6.o
 
 # matches
 obj-$(CONFIG_IP6_NF_MATCH_AH) += ip6t_ah.o
net/ipv6/netfilter/nf_dup_ipv6.c +1 -1
index ca7e867..a4b72ad 100644
@@ -63,7 +63,7 @@ static bool nf_dup_ipv6_route(struct sk_buff *skb, const struct in6_addr *gw,
 unsigned int nf_dup_ipv6(struct sk_buff *skb, unsigned int hooknum,
 			 const struct in6_addr *gw, int oif)
 {
-	if (__this_cpu_read(nf_skb_duplicated))
+	if (this_cpu_read(nf_skb_duplicated))
 		return XT_CONTINUE;
 	skb = pskb_copy(skb, GFP_ATOMIC);
 	if (skb == NULL)
net/ipv6/netfilter/nft_dup_ipv6.c new file +108 -0

108 lines not on this page · raw message

Signature · 1 line
1.7.10.4