netfilter: xt_TEE: get rid of WITH_CONNTRACK definition
Subsystems (2)
Pablo Neira Ayuso
maintainerPATCH 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
@@ -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
Pablo Neira Ayuso
maintainer=?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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
Florian Westphal
maintainerRe: [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_tablesdup expressions.net/ipv4/netfilter/nf_dup_ipv4.c new file +0
-0
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.
Pablo Neira Ayuso
maintainerRe: [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_tablesdup 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+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.
Pablo Neira Ayuso
maintainerPATCH 3/3 netfilter: nf_tables: add nft_dup expression
In reply to Pablo Neira AyusoThis 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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