Skip to contentSkip to conversation

Extract SYNPROXY infrastructure

PATCH Superseded Fernando Fernandez Mancera 3 participants 11 messages May 18, 2019 – May 19, 2019

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

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:
nf_synproxy_ipv4       16384  1 ipt_SYNPROXY
nf_synproxy_core       16384  4 ipt_SYNPROXY,nf_synproxy_ipv4
nf_conntrack          159744  8 xt_conntrack,xt_state,ipt_SYNPROXY,nf_synproxy_ipv4,nf_synproxy_core,xt_CT

Only IPv6:

nf_synproxy_ipv6       16384  1 ip6t_SYNPROXY
nf_synproxy_core       16384  4 ip6t_SYNPROXY,nf_synproxy_ipv6
nf_conntrack          159744  8 ip6t_SYNPROXY,xt_conntrack,xt_state,nf_synproxy_ipv6,nf_synproxy_core,xt_CT

IPv4 and IPv6:

nf_synproxy_ipv6       16384  1 ip6t_SYNPROXY
nf_synproxy_ipv4       16384  1 ipt_SYNPROXY
nf_synproxy_core       16384  4 ip6t_SYNPROXY,nf_synproxy_ipv6,ipt_SYNPROXY,nf_synproxy_ipv4
nf_conntrack          159744  8 ip6t_SYNPROXY,xt_conntrack,xt_state,nf_synproxy_ipv6,ipt_SYNPROXY,nf_synproxy_ipv4,nf_synproxy_core,xt_CT

Fernando Fernandez Mancera (5):
netfilter: synproxy: add common uapi for SYNPROXY infrastructure
netfilter: synproxy: extract IPv4 SYNPROXY infrastructure from
ipt_SYNPROXY
netfilter: add NF_SYNPROXY_IPV4 symbol
netfilter: synproxy: extract IPv6 SYNPROXY infrastructure from
ip6t_SYNPROXY
netfilter: add NF_SYNPROXY_IPV6 symbol

 include/net/netfilter/ipv4/nf_synproxy_ipv4.h |  42 ++
 include/net/netfilter/ipv6/nf_synproxy_ipv6.h |  43 ++
 include/uapi/linux/netfilter/nf_SYNPROXY.h    |  19 +
 include/uapi/linux/netfilter/xt_SYNPROXY.h    |  18 +-
 net/ipv4/netfilter/Kconfig                    |   4 +
 net/ipv4/netfilter/Makefile                   |   3 +
 net/ipv4/netfilter/ipt_SYNPROXY.c             | 394 +---------------
 net/ipv4/netfilter/nf_synproxy_ipv4.c         | 393 ++++++++++++++++
 net/ipv6/netfilter/Kconfig                    |   4 +
 net/ipv6/netfilter/Makefile                   |   3 +
 net/ipv6/netfilter/ip6t_SYNPROXY.c            | 420 +-----------------
 net/ipv6/netfilter/nf_synproxy_ipv6.c         | 414 +++++++++++++++++
 12 files changed, 947 insertions(+), 810 deletions(-)
 create mode 100644 include/net/netfilter/ipv4/nf_synproxy_ipv4.h
 create mode 100644 include/net/netfilter/ipv6/nf_synproxy_ipv6.h
 create mode 100644 include/uapi/linux/netfilter/nf_SYNPROXY.h
 create mode 100644 net/ipv4/netfilter/nf_synproxy_ipv4.c
 create mode 100644 net/ipv6/netfilter/nf_synproxy_ipv6.c
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/5 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
new file mode 100644
index 000000000000..068d1b3a6f06
@@ -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
index ea5eba15d4c1..4d5611d647df 100644
@@ -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
#2 lore raw

PATCH 2/5 netfilter: synproxy: extract IPv4 SYNPROXY infrastructure from ipt_SYNPROXY

In reply to Fernando Fernandez Mancera

Add common functions into nf_synproxy_ipv4.c to prepare for nftables support.

---
 include/net/netfilter/ipv4/nf_synproxy_ipv4.h |  42 ++
 net/ipv4/netfilter/ipt_SYNPROXY.c             | 394 +-----------------
 net/ipv4/netfilter/nf_synproxy_ipv4.c         | 393 +++++++++++++++++
 3 files changed, 441 insertions(+), 388 deletions(-)
 create mode 100644 include/net/netfilter/ipv4/nf_synproxy_ipv4.h
 create mode 100644 net/ipv4/netfilter/nf_synproxy_ipv4.c
include/net/netfilter/ipv4/nf_synproxy_ipv4.h new file +42 -0
new file mode 100644
index 000000000000..3a8dff2e58e7
@@ -0,0 +1,42 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _NF_SYNPROXY_IPV4_H
+#define _NF_SYNPROXY_IPV4_H
+
+#include <linux/module.h>
+#include <linux/skbuff.h>
+#include <net/tcp.h>
+
+#include <net/netfilter/nf_conntrack_seqadj.h>
+#include <net/netfilter/nf_conntrack_synproxy.h>
+
+void synproxy_send_client_synack(struct net *net, const struct sk_buff *skb,
+				 const struct tcphdr *th,
+				 const struct synproxy_options *opts);
+
+bool synproxy_recv_client_ack(struct net *net,
+			      const struct sk_buff *skb,
+			      const struct tcphdr *th,
+			      struct synproxy_options *opts, u32 recv_seq);
+
+unsigned int ipv4_synproxy_hook(void *priv, struct sk_buff *skb,
+				const struct nf_hook_state *nhs);
+int nf_synproxy_ipv4_init(struct synproxy_net *snet, struct net *net);
+void nf_synproxy_ipv4_fini(struct synproxy_net *snet, struct net *net);
+
+/* Hook operations used by {ip,nf}tables SYNPROXY support */
+const struct nf_hook_ops ipv4_synproxy_ops[] = {
+	{
+		.hook		= ipv4_synproxy_hook,
+		.pf		= NFPROTO_IPV4,
+		.hooknum	= NF_INET_LOCAL_IN,
+		.priority	= NF_IP_PRI_CONNTRACK_CONFIRM - 1,
+	},
+	{
+		.hook		= ipv4_synproxy_hook,
+		.pf		= NFPROTO_IPV4,
+		.hooknum	= NF_INET_POST_ROUTING,
+		.priority	= NF_IP_PRI_CONNTRACK_CONFIRM - 1,
+	},
+};
+
+#endif /* _NF_SYNPROXY_IPV4_H */
net/ipv4/netfilter/ipt_SYNPROXY.c +6 -388

422 lines not on this page · raw message

net/ipv4/netfilter/nf_synproxy_ipv4.c new file +393 -0

393 lines not on this page · raw message

Signature · 1 line
2.20.1
#3 lore raw

PATCH 3/5 netfilter: add NF_SYNPROXY_IPV4 symbol

In reply to Fernando Fernandez Mancera
---
 net/ipv4/netfilter/Kconfig  | 4 ++++
 net/ipv4/netfilter/Makefile | 3 +++
 2 files changed, 7 insertions(+)
net/ipv4/netfilter/Kconfig +4 -0
index 1412b029f37f..5038bb95dbf2 100644
@@ -18,6 +18,9 @@ config NF_SOCKET_IPV4
 config NF_TPROXY_IPV4
 	tristate "IPv4 tproxy support"
 
+config NF_SYNPROXY_IPV4
+	tristate
+
 if NF_TABLES
 
 config NF_TABLES_IPV4
@@ -196,6 +199,7 @@ config IP_NF_TARGET_REJECT
 config IP_NF_TARGET_SYNPROXY
 	tristate "SYNPROXY target support"
 	depends on NF_CONNTRACK && NETFILTER_ADVANCED
+	select NF_SYNPROXY_IPV4
 	select NETFILTER_SYNPROXY
 	select SYN_COOKIES
 	help
net/ipv4/netfilter/Makefile +3 -0
index c50e0ec095d2..01267eea7c4e 100644
@@ -6,6 +6,9 @@
 # defrag
 obj-$(CONFIG_NF_DEFRAG_IPV4) += nf_defrag_ipv4.o
 
+#synproxy
+obj-$(CONFIG_NF_SYNPROXY_IPV4) += nf_synproxy_ipv4.o
+
 obj-$(CONFIG_NF_SOCKET_IPV4) += nf_socket_ipv4.o
 obj-$(CONFIG_NF_TPROXY_IPV4) += nf_tproxy_ipv4.o
 
Signature · 1 line
2.20.1
#4 lore raw

PATCH 4/5 netfilter: synproxy: extract IPv6 SYNPROXY infrastructure from ip6t_SYNPROXY

In reply to Fernando Fernandez Mancera

Add common functions into nf_synproxy_ipv6.c to prepare for nftables support.

---
 include/net/netfilter/ipv6/nf_synproxy_ipv6.h |  43 ++
 net/ipv6/netfilter/ip6t_SYNPROXY.c            | 420 +-----------------
 net/ipv6/netfilter/nf_synproxy_ipv6.c         | 414 +++++++++++++++++
 3 files changed, 466 insertions(+), 411 deletions(-)
 create mode 100644 include/net/netfilter/ipv6/nf_synproxy_ipv6.h
 create mode 100644 net/ipv6/netfilter/nf_synproxy_ipv6.c
include/net/netfilter/ipv6/nf_synproxy_ipv6.h new file +43 -0
new file mode 100644
index 000000000000..afcbbfa5bc17
@@ -0,0 +1,43 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _NF_SYNPROXY_IPV6_H
+#define _NF_SYNPROXY_IPV6_H
+
+#include <linux/module.h>
+#include <linux/skbuff.h>
+#include <net/ip6_checksum.h>
+#include <net/ip6_route.h>
+#include <net/tcp.h>
+
+#include <net/netfilter/nf_conntrack_seqadj.h>
+#include <net/netfilter/nf_conntrack_synproxy.h>
+
+void synproxy_send_client_synack_ipv6(struct net *net, const struct sk_buff *skb,
+				      const struct tcphdr *th,
+				      const struct synproxy_options *opts);
+
+bool synproxy_recv_client_ack_ipv6(struct net *net, const struct sk_buff *skb,
+				   const struct tcphdr *th,
+				   struct synproxy_options *opts, u32 recv_seq);
+
+unsigned int ipv6_synproxy_hook(void *priv, struct sk_buff *skb,
+				const struct nf_hook_state *nhs);
+
+int nf_synproxy_ipv6_init(struct synproxy_net *snet, struct net *net);
+void nf_synproxy_ipv6_fini(struct synproxy_net *snet, struct net *net);
+
+static const struct nf_hook_ops ipv6_synproxy_ops[] = {
+	{
+		.hook		= ipv6_synproxy_hook,
+		.pf		= NFPROTO_IPV6,
+		.hooknum	= NF_INET_LOCAL_IN,
+		.priority	= NF_IP_PRI_CONNTRACK_CONFIRM - 1,
+	},
+	{
+		.hook		= ipv6_synproxy_hook,
+		.pf		= NFPROTO_IPV6,
+		.hooknum	= NF_INET_POST_ROUTING,
+		.priority	= NF_IP_PRI_CONNTRACK_CONFIRM - 1,
+	},
+};
+
+#endif /* _NF_SYNPROXY_IPV6_H */
net/ipv6/netfilter/ip6t_SYNPROXY.c +9 -411

461 lines not on this page · raw message

net/ipv6/netfilter/nf_synproxy_ipv6.c new file +414 -0

414 lines not on this page · raw message

Signature · 1 line
2.20.1
maintainer
#5 lore raw

Re: [PATCH 4/5 nf-next] netfilter: synproxy: extract IPv6 SYNPROXY infrastructure from ip6t_SYNPROXY

Fernando Fernandez Mancera <[email protected]> wrote:

Hi Fernando

Quoted 5 lines
net/ipv6/netfilter/nf_synproxy_ipv6.c new file +5 -0
+void
+synproxy_send_client_synack_ipv6(struct net *net,
+				 const struct sk_buff *skb,
+				 const struct tcphdr *th,
+				 const struct synproxy_options *opts)

[..]

net/ipv6/netfilter/nf_synproxy_ipv6.c line 99

Quoted 1 line
net/ipv6/netfilter/nf_synproxy_ipv6.c new file +1 -0
+	nth->seq	= htonl(__cookie_v6_init_sequence(iph, th, &mss));

It seems that __cookie_v6_init_sequence() is the only dependency of this module on ipv6.

If we would make it accessible via nf_ipv6_ops struct, then the dependency goes away and we could place ipv4 and ipv6 parts in a single module.

Just saying, it would avoid adding extra modules.
We could then have

nf_synproxy.ko # shared code
nft_synproxy.ko # nftables frontend
xt_SYNPROXY.ko # ip(6)tables frontends

#6 lore raw

Re: [PATCH 4/5 nf-next] netfilter: synproxy: extract IPv6 SYNPROXY infrastructure from ip6t_SYNPROXY

Hi Florian,

Quoted 17 lines · Florian Westphal

Fernando Fernandez Mancera <[email protected]> wrote:

Hi Fernando

Quoted 5 lines
net/ipv6/netfilter/nf_synproxy_ipv6.c new file +5 -0
+void
+synproxy_send_client_synack_ipv6(struct net *net,
+				 const struct sk_buff *skb,
+				 const struct tcphdr *th,
+				 const struct synproxy_options *opts)

[..]

net/ipv6/netfilter/nf_synproxy_ipv6.c line 99

Quoted 1 line
net/ipv6/netfilter/nf_synproxy_ipv6.c new file +1 -0
+	nth->seq	= htonl(__cookie_v6_init_sequence(iph, th, &mss));

It seems that __cookie_v6_init_sequence() is the only dependency of this module on ipv6.

Quoted 5 lines

If we would make it accessible via nf_ipv6_ops struct, then the dependency goes away and we could place ipv4 and ipv6 parts in a single module.

Just saying, it would avoid adding extra modules.

This would be awesome but I am not sure if it is possible right now. I am going to try it and send a new patch series. Thank you about this!

Quoted 5 lines

We could then have

nf_synproxy.ko # shared code
nft_synproxy.ko # nftables frontend
xt_SYNPROXY.ko # ip(6)tables frontends

In this case, ip6t_synproxy wouldn't need to select IPV6 Cookie module right? Thanks!

maintainer
#7 lore raw

Re: [PATCH 4/5 nf-next] netfilter: synproxy: extract IPv6 SYNPROXY infrastructure from ip6t_SYNPROXY

Quoted 7 lines · Fernando Fernandez Mancera
Quoted 5 lines

If we would make it accessible via nf_ipv6_ops struct, then the dependency goes away and we could place ipv4 and ipv6 parts in a single module.

Just saying, it would avoid adding extra modules.

This would be awesome but I am not sure if it is possible right now. I am going to try it and send a new patch series. Thank you about this!

You would need to make something similar as commit 960587285a56ec3cafb4d1e6b25c19eced4d0bce first.

Let me know if you need help.

Quoted 7 lines
Quoted 5 lines

We could then have

nf_synproxy.ko # shared code
nft_synproxy.ko # nftables frontend
xt_SYNPROXY.ko # ip(6)tables frontends

In this case, ip6t_synproxy wouldn't need to select IPV6 Cookie module right? Thanks!

No, it would not need to do this.

Basically all the .c code would have

#if IS_ENABLED(CONFIG_IPV6)
ipv6-code here
#endif

where needed, so in case the kernel is built with CONFIG_IPV6=m|y, the functionality is available.

#8 lore raw

PATCH 5/5 netfilter: add NF_SYNPROXY_IPV6 symbol

In reply to Fernando Fernandez Mancera
---
 net/ipv6/netfilter/Kconfig  | 4 ++++
 net/ipv6/netfilter/Makefile | 3 +++
 2 files changed, 7 insertions(+)
net/ipv6/netfilter/Kconfig +4 -0
index 086fc669279e..60146a0d390d 100644
@@ -5,6 +5,9 @@
 menu "IPv6: Netfilter Configuration"
 	depends on INET && IPV6 && NETFILTER
 
+config NF_SYNPROXY_IPV6
+	tristate
+
 config NF_SOCKET_IPV6
 	tristate "IPv6 socket lookup support"
 	help
@@ -212,6 +215,7 @@ config IP6_NF_TARGET_REJECT
 config IP6_NF_TARGET_SYNPROXY
 	tristate "SYNPROXY target support"
 	depends on NF_CONNTRACK && NETFILTER_ADVANCED
+	select NF_SYNPROXY_IPV6
 	select NETFILTER_SYNPROXY
 	select SYN_COOKIES
 	help
net/ipv6/netfilter/Makefile +3 -0
index 731a74c60dca..d9ee2f8c9ae2 100644
@@ -15,6 +15,9 @@ obj-$(CONFIG_IP6_NF_NAT) += ip6table_nat.o
 nf_defrag_ipv6-y := nf_defrag_ipv6_hooks.o nf_conntrack_reasm.o
 obj-$(CONFIG_NF_DEFRAG_IPV6) += nf_defrag_ipv6.o
 
+#synproxy
+obj-$(CONFIG_NF_SYNPROXY_IPV6) += nf_synproxy_ipv6.o
+
 obj-$(CONFIG_NF_SOCKET_IPV6) += nf_socket_ipv6.o
 obj-$(CONFIG_NF_TPROXY_IPV6) += nf_tproxy_ipv6.o
 
Signature · 1 line
2.20.1
#9 lore raw
In reply to Fernando Fernandez Mancera
Quoted 2 lines · Fernando Fernandez Mancera

The patch series have been tested by enabling iptables and ip6tables SYNPROXY. All the modules loaded as expected.

What is the subsequent plan? Making new modules brings the usual module overhead (16K it seems), and if there is just one user, that seems wasteful.

Quoted 9 lines
$ lsmod | grep synproxy
IPv4 and IPv6:
nf_synproxy_ipv6       16384  1 ip6t_SYNPROXY
nf_synproxy_ipv4       16384  1 ipt_SYNPROXY
nf_synproxy_core       16384  4 ip6t_SYNPROXY,nf_synproxy_ipv6,ipt_SYNPROXY,nf_synproxy_ipv4
nf_conntrack          159744  8 ip6t_SYNPROXY,xt_conntrack,xt_state,nf_synproxy_ipv6,ipt_SYNPROXY,nf_synproxy_ipv4,nf_synproxy_core,xt_CT

net/ipv4/netfilter/nf_synproxy_ipv4.c | 393 ++++++++++++++++
net/ipv6/netfilter/nf_synproxy_ipv6.c | 414 +++++++++++++++++

#10 lore raw

Hi Jan,

Quoted 9 lines · Jan Engelhardt
Quoted 2 lines · Fernando Fernandez Mancera

The patch series have been tested by enabling iptables and ip6tables SYNPROXY. All the modules loaded as expected.

What is the subsequent plan? Making new modules brings the usual module overhead (16K it seems), and if there is just one user, that seems wasteful.

The idea is to simplify these two modules in a single one (as Florian suggested and it have be done in the v2). At this point, we only need to implement the nft_synproxy module which is going to be the frontend module for the nftables support.

In my opinion, SYNPROXY still being useful and it would be nice to support it in nftables, furthermore there are some improvements planned to do for the SYNPROXY nftables module. Thank you!

Quoted 9 lines
Quoted 9 lines
$ lsmod | grep synproxy
IPv4 and IPv6:
nf_synproxy_ipv6       16384  1 ip6t_SYNPROXY
nf_synproxy_ipv4       16384  1 ipt_SYNPROXY
nf_synproxy_core       16384  4 ip6t_SYNPROXY,nf_synproxy_ipv6,ipt_SYNPROXY,nf_synproxy_ipv4
nf_conntrack          159744  8 ip6t_SYNPROXY,xt_conntrack,xt_state,nf_synproxy_ipv6,ipt_SYNPROXY,nf_synproxy_ipv4,nf_synproxy_core,xt_CT

net/ipv4/netfilter/nf_synproxy_ipv4.c | 393 ++++++++++++++++
net/ipv6/netfilter/nf_synproxy_ipv6.c | 414 +++++++++++++++++