Extract SYNPROXY infrastructure
Subsystems (2)
v4 cover Extract SYNPROXY infrastructure
The patch series have been tested by enabling iptables and ip6tables SYNPROXY. All the modules loaded as expected.
$ lsmod | grep synproxy Only IPv4: ipt_SYNPROXY 16384 1 nf_synproxy_core 24576 1 ipt_SYNPROXY nf_conntrack 159744 5 xt_conntrack,xt_state,ipt_SYNPROXY,nf_synproxy_core,xt_CT x_tables 49152 7 xt_conntrack,nft_compat,xt_state,xt_tcpudp,ipt_SYNPROXY,xt_CT,ip_tables
Only IPv6:
ip6t_SYNPROXY 16384 1 nf_synproxy_core 24576 1 ip6t_SYNPROXY nf_conntrack 159744 4 ip6t_SYNPROXY,xt_conntrack,xt_state,nf_synproxy_core x_tables 49152 6 ip6t_SYNPROXY,xt_conntrack,nft_compat,xt_state,xt_tcpudp,ip_tables
IPv4 and IPv6:
ip6t_SYNPROXY 16384 1 ipt_SYNPROXY 16384 1 nf_synproxy_core 24576 2 ip6t_SYNPROXY,ipt_SYNPROXY nf_conntrack 159744 6 ip6t_SYNPROXY,xt_conntrack,xt_state,ipt_SYNPROXY,nf_synproxy_core,xt_CT x_tables 49152 8 ip6t_SYNPROXY,xt_conntrack,nft_compat,xt_state,xt_tcpudp,ipt_SYNPROXY,xt_CT,ip_tables
v1: Initial patch
v2: Unify nf_synproxy_ipv4 and nf_synproxy_ipv6 into nf_synproxy
v3: Remove synproxy_cookie dependency
v4: Remove another synproxy_cookie, unify nf_synproxy into nf_synproxy_core so now we are using a single module.
Fernando Fernandez Mancera (3):
netfilter: synproxy: add common uapi for SYNPROXY infrastructure
netfilter: synproxy: remove module dependency on IPv6 SYNPROXY
netfilter: synproxy: extract SYNPROXY infrastructure from
{ipt,ip6t}_SYNPROXYinclude/linux/netfilter_ipv6.h | 36 + include/net/netfilter/nf_conntrack_synproxy.h | 13 +- include/net/netfilter/nf_synproxy.h | 46 + include/uapi/linux/netfilter/nf_SYNPROXY.h | 19 + include/uapi/linux/netfilter/xt_SYNPROXY.h | 18 +- net/ipv4/netfilter/ipt_SYNPROXY.c | 394 +------- net/ipv6/netfilter.c | 2 + net/ipv6/netfilter/ip6t_SYNPROXY.c | 420 +------- net/netfilter/nf_synproxy_core.c | 897 +++++++++++++++++- 9 files changed, 987 insertions(+), 858 deletions(-) create mode 100644 include/net/netfilter/nf_synproxy.h create mode 100644 include/uapi/linux/netfilter/nf_SYNPROXY.h
Signature · 1 line
2.20.1
PATCH v4 1/3 netfilter: synproxy: add common uapi for SYNPROXY infrastructure
This new UAPI file is going to be used by the xt and nft common SYNPROXY infrastructure. It is needed to avoid duplicated code.
--- include/uapi/linux/netfilter/nf_SYNPROXY.h | 19 +++++++++++++++++++ include/uapi/linux/netfilter/xt_SYNPROXY.h | 18 +++++++----------- 2 files changed, 26 insertions(+), 11 deletions(-) create mode 100644 include/uapi/linux/netfilter/nf_SYNPROXY.h
include/uapi/linux/netfilter/nf_SYNPROXY.h new file +19 -0
@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _NF_SYNPROXY_H +#define _NF_SYNPROXY_H + +#include <linux/types.h> + +#define NF_SYNPROXY_OPT_MSS 0x01 +#define NF_SYNPROXY_OPT_WSCALE 0x02 +#define NF_SYNPROXY_OPT_SACK_PERM 0x04 +#define NF_SYNPROXY_OPT_TIMESTAMP 0x08 +#define NF_SYNPROXY_OPT_ECN 0x10 + +struct nf_synproxy_info { +__u8 options; +__u8 wscale; +__u16 mss; +}; + +#endif /* _NF_SYNPROXY_H */
include/uapi/linux/netfilter/xt_SYNPROXY.h +7 -11
@@ -2,18 +2,14 @@#ifndef _XT_SYNPROXY_H#define _XT_SYNPROXY_H -#include <linux/types.h> +#include <linux/netfilter/nf_SYNPROXY.h> -#define XT_SYNPROXY_OPT_MSS 0x01 -#define XT_SYNPROXY_OPT_WSCALE 0x02 -#define XT_SYNPROXY_OPT_SACK_PERM 0x04 -#define XT_SYNPROXY_OPT_TIMESTAMP 0x08 -#define XT_SYNPROXY_OPT_ECN 0x10 +#define XT_SYNPROXY_OPT_MSS NF_SYNPROXY_OPT_MSS +#define XT_SYNPROXY_OPT_WSCALE NF_SYNPROXY_OPT_WSCALE +#define XT_SYNPROXY_OPT_SACK_PERM NF_SYNPROXY_OPT_SACK_PERM +#define XT_SYNPROXY_OPT_TIMESTAMP NF_SYNPROXY_OPT_TIMESTAMP +#define XT_SYNPROXY_OPT_ECN NF_SYNPROXY_OPT_ECN -struct xt_synproxy_info { -__u8 options; -__u8 wscale; -__u16 mss; -}; +#define xt_synproxy_info nf_synproxy_info#endif /* _XT_SYNPROXY_H */
Signature · 1 line
2.20.1
PATCH v4 2/3 netfilter: synproxy: remove module dependency on IPv6 SYNPROXY
In reply to Fernando Fernandez ManceraThis is a prerequisite for the infrastructure module NETFILTER_SYNPROXY. The new module is needed to avoid duplicated code for the SYNPROXY nftables support.
--- include/linux/netfilter_ipv6.h | 36 ++++++++++++++++++++++++++++++++++ net/ipv6/netfilter.c | 2 ++ 2 files changed, 38 insertions(+)
include/linux/netfilter_ipv6.h +36 -0
@@ -8,6 +8,7 @@#define __LINUX_IP6_NETFILTER_H#include <uapi/linux/netfilter_ipv6.h> +#include <net/tcp.h> /* Extra routing may needed on local out, as the QUEUE target never returns * control to the table.
@@ -35,6 +36,10 @@ struct nf_ipv6_ops { struct in6_addr *saddr);int (*route)(struct net *net,struct dst_entry **dst,struct flowi *fl,bool strict); +u32 (*cookie_init_sequence)(const struct ipv6hdr *iph, +const struct tcphdr *th,u16 *mssp); +int (*cookie_v6_check)(const struct ipv6hdr *iph, +const struct tcphdr *th,__32 cookie);#endif void (*route_input)(struct sk_buff *skb); int (*fragment)(struct net *net, struct sock *sk, struct sk_buff *skb,
@@ -154,6 +159,37 @@ static inline int nf_ip6_route_me_harder(struct net *net, struct sk_buff *skb)#endif } +static inline u32 nf_ipv6_cookie_init_sequence (const struct ipv6hdr *iph, +const struct tcphdr *th, +u16 *mssp) +{ +#if IS_MODULE (CONFIG_IPV6 ) +const struct nf_ipv6_ops *v6_ops =nf_get_ipv6_ops (); + +if (v6_ops) +return v6_ops->cookie_init_sequence (iph, th, mssp); + +return 0 ; +#else +return __cookie_v6_init_sequence (iph, th, mssp); +#endif +} + +static inline int nf_cookie_v6_check (const struct ipv6hdr *iph, +const struct tcphdr *th,__u32 cookie) +{ +#if IS_MODULE (CONFIG_IPV6 ) +const struct nf_ipv6_ops *v6_ops =nf_get_ipv6_ops (); + +if (v6_ops) +return v6_ops->cookie_v6_check (iph, th, cookie); + +return 0 ; +#else +return __cookie_v6_check (iph, th, cookie); +#endif +} +__sum16 nf_ip6_checksum (struct sk_buff *skb,unsigned int hook,unsigned int dataoff,u_int8_t protocol);
net/ipv6/netfilter.c +2 -0
@@ -234,6 +234,8 @@ static const struct nf_ipv6_ops ipv6ops = { .route_me_harder = ip6_route_me_harder, .dev_get_saddr = ipv6_dev_get_saddr, .route = __nf_ip6_route, + .cookie_init_sequence = __cookie_v6_init_sequence, + .cookie_v6_check = __cookie_v6_check, #endif .route_input = ip6_route_input, .fragment = ip6_fragment,
Signature · 1 line
2.20.1
PATCH v4 3/3 netfilter: synproxy: extract SYNPROXY infrastructure from {ipt,ip6t}_SYNPROXY
In reply to Fernando Fernandez ManceraAdd common functions into nf_synproxy_core.c to prepare for nftables support. The prototypes of the functions used by {ipt, ip6t}_SYNPROXY are in the new file nf_synproxy.h
--- include/net/netfilter/nf_conntrack_synproxy.h | 13 +- include/net/netfilter/nf_synproxy.h | 46 + net/ipv4/netfilter/ipt_SYNPROXY.c | 394 +------- net/ipv6/netfilter/ip6t_SYNPROXY.c | 420 +------- net/netfilter/nf_synproxy_core.c | 897 +++++++++++++++++- 5 files changed, 923 insertions(+), 847 deletions(-) create mode 100644 include/net/netfilter/nf_synproxy.h
include/net/netfilter/nf_conntrack_synproxy.h +2 -11
@@ -72,21 +72,12 @@ struct synproxy_options { };struct tcphdr ; -struct xt_synproxy_info ; +struct nf_synproxy_info ;bool synproxy_parse_options (const struct sk_buff *skb,unsigned int doff,const struct tcphdr *th,struct synproxy_options *opts); -unsigned int synproxy_options_size (const struct synproxy_options *opts); -void synproxy_build_options (struct tcphdr *th, -const struct synproxy_options *opts); -void synproxy_init_timestamp_cookie (const struct xt_synproxy_info *info, +void synproxy_init_timestamp_cookie (const struct nf_synproxy_info *info,struct synproxy_options *opts); -void synproxy_check_timestamp_cookie (struct synproxy_options *opts); - -unsigned int synproxy_tstamp_adjust (struct sk_buff *skb,unsigned int protoff, -struct tcphdr *th,struct nf_conn *ct, -enum ip_conntrack_info ctinfo, -const struct nf_conn_synproxy *synproxy);#endif /* _NF_CONNTRACK_SYNPROXY_H */
include/net/netfilter/nf_synproxy.h new file +46 -0
46 lines not on this page · raw message
net/ipv4/netfilter/ipt_SYNPROXY.c +6 -388
422 lines not on this page · raw message
net/ipv6/netfilter/ip6t_SYNPROXY.c +9 -411
461 lines not on this page · raw message
net/netfilter/nf_synproxy_core.c +860 -37
1,008 lines not on this page · raw message
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerQuoted 2 lines · Fernando Fernandez Mancera
The patch series have been tested by enabling iptables and ip6tables SYNPROXY. All the modules loaded as expected.
Series applied, thanks Fernando.