Skip to contentSkip to conversation

netfilter: refactor xt_TEE code

RFC PATCH New Arturo Borrero Gonzalez 1 participant 2 messages Feb 11, 2015

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

RFC PATCH 1/2 netfilter: refactor xt_TEE code

Refactor xt_TEE code so it can be used outside of the xtables context (nf_tables).

---
 include/net/netfilter/ipv4/nf_tee_ipv4.h |    8 +
 include/net/netfilter/ipv6/nf_tee_ipv6.h |    8 +
 include/net/netfilter/nf_tee.h           |   20 +++
 net/ipv4/netfilter/Kconfig               |    8 +
 net/ipv4/netfilter/Makefile              |    2 
 net/ipv4/netfilter/nf_tee_ipv4.c         |  115 +++++++++++++++
 net/ipv6/netfilter/Kconfig               |    8 +
 net/ipv6/netfilter/Makefile              |    2 
 net/ipv6/netfilter/nf_tee_ipv6.c         |   89 ++++++++++++
 net/netfilter/Kconfig                    |    8 +
 net/netfilter/Makefile                   |    2 
 net/netfilter/nf_tee.c                   |  115 +++++++++++++++
 net/netfilter/xt_TEE.c                   |  232 ++----------------------------
 13 files changed, 400 insertions(+), 217 deletions(-)
 create mode 100644 include/net/netfilter/ipv4/nf_tee_ipv4.h
 create mode 100644 include/net/netfilter/ipv6/nf_tee_ipv6.h
 create mode 100644 include/net/netfilter/nf_tee.h
 create mode 100644 net/ipv4/netfilter/nf_tee_ipv4.c
 create mode 100644 net/ipv6/netfilter/nf_tee_ipv6.c
 create mode 100644 net/netfilter/nf_tee.c
include/net/netfilter/ipv4/nf_tee_ipv4.h new file +8 -0
new file mode 100644
index 0000000..202ad75
@@ -0,0 +1,8 @@
+#ifndef _NF_TEE_IPV4_H_
+#define _NF_TEE_IPV4_H_
+
+#include <net/netfilter/nf_tee.h>
+
+unsigned int nf_tee_ipv4(struct sk_buff *skb, const struct nf_tee *tee);
+
+#endif /* _NF_TEE_IPV4_H_ */
include/net/netfilter/ipv6/nf_tee_ipv6.h new file +8 -0
new file mode 100644
index 0000000..fe4c5a1
@@ -0,0 +1,8 @@
+#ifndef _NF_TEE_IPV6_H_
+#define _NF_TEE_IPV6_H_
+
+#include <net/netfilter/nf_tee.h>
+
+unsigned int nf_tee_ipv6(struct sk_buff *skb, const struct nf_tee *tee);
+
+#endif /* _NF_TEE_IPV6_H_ */
include/net/netfilter/nf_tee.h new file +20 -0
new file mode 100644
index 0000000..2bd6d56
@@ -0,0 +1,20 @@
+#ifndef _NF_TEE_H_
+#define _NF_TEE_H_
+
+#include <linux/netfilter.h>
+#include <linux/if.h>
+
+struct nf_tee {
+	union nf_inet_addr	gw;
+	char			oif_str[IFNAMSIZ];
+	int			oif;
+	unsigned int		hooknum;
+	struct notifier_block	notifier;
+};
+
+struct net *nf_tee_pick_net(struct sk_buff *skb);
+struct nf_tee *nf_tee_new(union nf_inet_addr gw, const char *oif_str);
+bool nf_tee_has_notifier(const struct nf_tee *tee);
+void nf_tee_destroy(struct nf_tee *tee);
+
+#endif
net/ipv4/netfilter/Kconfig +8 -0
index 59f883d..d71dbdf 100644
@@ -36,6 +36,14 @@ config NF_CONNTRACK_PROC_COMPAT
 
 	  If unsure, say Y.
 
+config NF_TEE_IPV4
+	tristate "Netfilter IPv4 packet cloning to alternate destination"
+	depends on !NF_CONNTRACK || NF_CONNTRACK
+	depends on NF_TEE
+	help
+	  This optiones enables the nf_tee_ipv4 engine, which can clone a
+	  packet and this clone be rerouted to another nexthop.
+
 config NF_LOG_ARP
 	tristate "ARP packet logging"
 	default m if NETFILTER_ADVANCED=n
net/ipv4/netfilter/Makefile +2 -0
index 7fe6c70..6b492de 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_TEE_IPV4) += nf_tee_ipv4.o
net/ipv4/netfilter/nf_tee_ipv4.c new file +115 -0

115 lines not on this page · raw message

net/ipv6/netfilter/Kconfig +8 -0
index a069822..fefd1bb 100644
@@ -55,6 +55,14 @@ config NF_LOG_IPV6
 	default m if NETFILTER_ADVANCED=n
 	select NF_LOG_COMMON
 
+config NF_TEE_IPV6
+	tristate "Netfilter IPv6 packet cloning to alternate destination"
+	depends on !NF_CONNTRACK || NF_CONNTRACK
+	depends on NF_TEE
+	help
+	  This optiones enables the nf_tee_ipv6 engine, which can clone a
+	  packet and this clone be rerouted to another nexthop.
+
 config NF_NAT_IPV6
 	tristate "IPv6 NAT"
 	depends on NF_CONNTRACK_IPV6
net/ipv6/netfilter/Makefile +2 -0
index c36e0a5..b3a2946 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_TEE_IPV6) += nf_tee_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_tee_ipv6.c new file +89 -0

89 lines not on this page · raw message

net/netfilter/Kconfig +8 -0
index b02660f..f0a0712 100644
@@ -562,6 +562,13 @@ config NFT_COMPAT
 	  x_tables match/target extensions over the nf_tables
 	  framework.
 
+config NF_TEE
+	tristate "Netfilter nf_tee module"
+	help
+	  This module is the core nf_tee engine, which allows you
+	  to copy and redirect packets to another gateway.
+
+
 config NETFILTER_XTABLES
 	tristate "Netfilter Xtables support (required for ip_tables)"
 	default m if NETFILTER_ADVANCED=n
@@ -863,6 +870,7 @@ config NETFILTER_XT_TARGET_REDIRECT
 config NETFILTER_XT_TARGET_TEE
 	tristate '"TEE" - packet cloning to alternate destination'
 	depends on NETFILTER_ADVANCED
+	depends on NF_TEE_IPV4 || NF_TEE_IPV6
 	depends on (IPV6 || IPV6=n)
 	depends on !NF_CONNTRACK || NF_CONNTRACK
 	---help---
net/netfilter/Makefile +2 -0
index 89f73a9..0cd2f03 100644
@@ -47,6 +47,8 @@ obj-$(CONFIG_NF_CONNTRACK_TFTP) += nf_conntrack_tftp.o
 nf_nat-y	:= nf_nat_core.o nf_nat_proto_unknown.o nf_nat_proto_common.o \
 		   nf_nat_proto_udp.o nf_nat_proto_tcp.o nf_nat_helper.o
 
+obj-$(CONFIG_NF_TEE) += nf_tee.o
+
 # generic transport layer logging
 obj-$(CONFIG_NF_LOG_COMMON) += nf_log_common.o
 
net/netfilter/nf_tee.c new file +115 -0

115 lines not on this page · raw message

net/netfilter/xt_TEE.c +15 -217

272 lines not on this page · raw message

--
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

#1 lore raw

RFC PATCH 2/2 netfilter: nf_tables: add nft_tee expression

This new expression uses the nf_tee engine to redirect packets to a given gateway.

---
 include/net/netfilter/nft_tee.h          |   22 ++++++++
 include/uapi/linux/netfilter/nf_tables.h |   14 +++++
 net/ipv4/netfilter/Kconfig               |    8 +++
 net/ipv4/netfilter/Makefile              |    1 
 net/ipv4/netfilter/nft_tee_ipv4.c        |   65 +++++++++++++++++++++++
 net/ipv6/netfilter/Kconfig               |    8 +++
 net/ipv6/netfilter/Makefile              |    1 
 net/ipv6/netfilter/nft_tee_ipv6.c        |   65 +++++++++++++++++++++++
 net/netfilter/Kconfig                    |    8 +++
 net/netfilter/Makefile                   |    1 
 net/netfilter/nft_tee.c                  |   85 ++++++++++++++++++++++++++++++
 11 files changed, 278 insertions(+)
 create mode 100644 include/net/netfilter/nft_tee.h
 create mode 100644 net/ipv4/netfilter/nft_tee_ipv4.c
 create mode 100644 net/ipv6/netfilter/nft_tee_ipv6.c
 create mode 100644 net/netfilter/nft_tee.c
include/net/netfilter/nft_tee.h new file +22 -0
new file mode 100644
index 0000000..5a8e70a
@@ -0,0 +1,22 @@
+#ifndef _NFT_TEE_H_
+#define _NFT_TEE_H_
+
+#include <net/netfilter/nf_tee.h>
+
+struct nft_tee {
+	struct nf_tee		*tee;
+	struct nft_data		data; /* gw */
+	u8			dlen; /* gw len */
+};
+
+extern const struct nla_policy nft_tee_policy[];
+
+int nft_tee_init(const struct nft_ctx *ctx,
+		 const struct nft_expr *expr,
+		 const struct nlattr * const tb[]);
+
+void nft_tee_destroy(const struct nft_ctx *ctx, const struct nft_expr *expr);
+
+int nft_tee_dump(struct sk_buff *skb, const struct nft_expr *expr);
+
+#endif /* _NFT_TEE_H_ */
include/uapi/linux/netfilter/nf_tables.h +14 -0
index 832bc46..8dade0a 100644
@@ -856,6 +856,20 @@ enum nft_redir_attributes {
 #define NFTA_REDIR_MAX		(__NFTA_REDIR_MAX - 1)
 
 /**
+ * enum nft_tee_attributes - nf_tables tee expression netlink attributes
+ *
+ * @NFTA_TEE_GW: tee gateway (NLA_NESTED: nft_data_attributes)
+ * @NFTA_TEE_OIF: tee output interface name (NLA_STRING)
+ */
+enum nft_tee_attributes {
+	NFTA_TEE_UNSPEC,
+	NFTA_TEE_GW,
+	NFTA_TEE_OIF,
+	__NFTA_TEE_MAX
+};
+#define NFTA_TEE_MAX		(__NFTA_TEE_MAX - 1)
+
+/**
  * enum nft_gen_attributes - nf_tables ruleset generation attributes
  *
  * @NFTA_GEN_ID: Ruleset generation ID (NLA_U32)
net/ipv4/netfilter/Kconfig +8 -0
index d71dbdf..a21865d 100644
@@ -130,6 +130,14 @@ config NFT_REDIR_IPV4
 	  This is the expression that provides IPv4 redirect support for
 	  nf_tables.
 
+config NFT_TEE_IPV4
+	tristate "IPv4 tee suport for nf_tables"
+	depends on NF_TABLES_IPV4
+	depends on NFT_TEE
+	select NF_TEE_IPV4
+	help
+	  This is the module that provides IPv4 tee support for nf_tables.
+
 config NF_NAT_SNMP_BASIC
 	tristate "Basic SNMP-ALG support"
 	depends on NF_CONNTRACK_SNMP
net/ipv4/netfilter/Makefile +1 -0
index 6b492de..08a008c 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_TEE_IPV4) += nft_tee_ipv4.o
 obj-$(CONFIG_NF_TABLES_ARP) += nf_tables_arp.o
 
 # generic IP tables 
net/ipv4/netfilter/nft_tee_ipv4.c new file +65 -0

65 lines not on this page · raw message

net/ipv6/netfilter/Kconfig +8 -0
index fefd1bb..2530e2c 100644
@@ -110,6 +110,14 @@ config NFT_REDIR_IPV6
 
 endif # NF_NAT_IPV6
 
+config NFT_TEE_IPV6
+	tristate "IPv6 tee support for nf_tables"
+	depends on NF_TABLES_IPV6
+	depends on NFT_TEE
+	select NF_TEE_IPV6
+	help
+	  This is the module that provides IPv6 tee support for nf_tables.
+
 config IP6_NF_IPTABLES
 	tristate "IP6 tables support (required for filtering)"
 	depends on INET && IPV6
net/ipv6/netfilter/Makefile +1 -0
index b3a2946..da871e8 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_TEE_IPV6) += nft_tee_ipv6.o
 
 # matches
 obj-$(CONFIG_IP6_NF_MATCH_AH) += ip6t_ah.o
net/ipv6/netfilter/nft_tee_ipv6.c new file +65 -0

65 lines not on this page · raw message

net/netfilter/Kconfig +8 -0
index f0a0712..1606b44 100644
@@ -562,6 +562,14 @@ config NFT_COMPAT
 	  x_tables match/target extensions over the nf_tables
 	  framework.
 
+config NFT_TEE
+	depends on NF_TABLES
+	depends on NF_TEE
+	tristate "Netfilter nf_tables nf_tee support"
+	help
+	  This option adds the "tee" expression to nf_tables which you can use
+	  to copy and redirect packets to another gateway.
+
 config NF_TEE
 	tristate "Netfilter nf_tee module"
 	help
net/netfilter/Makefile +1 -0
index 0cd2f03..22a2b77 100644
@@ -92,6 +92,7 @@ obj-$(CONFIG_NFT_COUNTER)	+= nft_counter.o
 obj-$(CONFIG_NFT_LOG)		+= nft_log.o
 obj-$(CONFIG_NFT_MASQ)		+= nft_masq.o
 obj-$(CONFIG_NFT_REDIR)		+= nft_redir.o
+obj-$(CONFIG_NFT_TEE)		+= nft_tee.o
 
 # generic X tables 
 obj-$(CONFIG_NETFILTER_XTABLES) += x_tables.o xt_tcpudp.o
net/netfilter/nft_tee.c new file +85 -0

85 lines not on this page · raw message