Skip to contentSkip to conversation

Extract SYNPROXY infrastructure

PATCH Superseded Fernando Fernandez Mancera 4 participants 15 messages May 19, 2019 – May 21, 2019

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 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            20480  1 ipt_SYNPROXY
nf_synproxy_core       16384  2 ipt_SYNPROXY,nf_synproxy
nf_conntrack          159744  5 xt_conntrack,xt_state,ipt_SYNPROXY,nf_synproxy_core,nf_synproxy

Only IPv6:

nf_synproxy            20480  1 ip6t_SYNPROXY
nf_synproxy_core       16384  2 ip6t_SYNPROXY,nf_synproxy
nf_conntrack          159744  5 ip6t_SYNPROXY,xt_conntrack,xt_state,nf_synproxy_core,nf_synproxy

IPv4 and IPv6:

nf_synproxy            20480  2 ip6t_SYNPROXY,ipt_SYNPROXY
nf_synproxy_core       16384  3 ip6t_SYNPROXY,ipt_SYNPROXY,nf_synproxy
nf_conntrack          159744  6 ip6t_SYNPROXY,xt_conntrack,xt_state,ipt_SYNPROXY,nf_synproxy_core,nf_synproxy

Fernando Fernandez Mancera (4):
netfilter: synproxy: add common uapi for SYNPROXY infrastructure
netfilter: synproxy: remove module dependency on IPv6 SYNPROXY
netfilter: synproxy: extract SYNPROXY infrastructure from

    {ipt,ip6t}_SYNPROXY

netfilter: add NF_SYNPROXY symbol

 include/linux/netfilter_ipv6.h             |   3 +
 include/net/netfilter/nf_synproxy.h        |  76 ++
 include/uapi/linux/netfilter/nf_SYNPROXY.h |  19 +
 include/uapi/linux/netfilter/xt_SYNPROXY.h |  18 +-
 net/ipv4/netfilter/Kconfig                 |   2 +-
 net/ipv4/netfilter/ipt_SYNPROXY.c          | 394 +---------
 net/ipv6/netfilter.c                       |   1 +
 net/ipv6/netfilter/Kconfig                 |   2 +-
 net/ipv6/netfilter/ip6t_SYNPROXY.c         | 420 +----------
 net/netfilter/Kconfig                      |   3 +
 net/netfilter/Makefile                     |   1 +
 net/netfilter/nf_synproxy.c                | 819 +++++++++++++++++++++
 12 files changed, 946 insertions(+), 812 deletions(-)
 create mode 100644 include/net/netfilter/nf_synproxy.h
 create mode 100644 include/uapi/linux/netfilter/nf_SYNPROXY.h
 create mode 100644 net/netfilter/nf_synproxy.c
Signature · 1 line
2.20.1
#1 lore raw

PATCH v2 1/4 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 v2 2/4 netfilter: synproxy: remove module dependency on IPv6 SYNPROXY

In reply to Fernando Fernandez Mancera

This is a prerequisite for the new infrastructure module NF_SYNPROXY. The new module is needed to avoid duplicated code for the SYNPROXY nftables support.

---
 include/linux/netfilter_ipv6.h | 3 +++
 net/ipv6/netfilter.c           | 1 +
 2 files changed, 4 insertions(+)
include/linux/netfilter_ipv6.h +3 -0
index 12113e502656..f440aaade612 100644
@@ -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,8 @@ struct nf_ipv6_ops {
 	int (*route)(struct net *net, struct dst_entry **dst, struct flowi *fl,
 		     bool strict);
 #endif
+	u32 (*cookie_init_sequence)(const struct ipv6hdr *iph,
+				    const struct tcphdr *th, u16 *mssp);
 	void (*route_input)(struct sk_buff *skb);
 	int (*fragment)(struct net *net, struct sock *sk, struct sk_buff *skb,
 			int (*output)(struct net *, struct sock *, struct sk_buff *));
net/ipv6/netfilter.c +1 -0
index 1240ccd57f39..c62eb5cdfbad 100644
@@ -116,6 +116,7 @@ static const struct nf_ipv6_ops ipv6ops = {
 	.dev_get_saddr		= ipv6_dev_get_saddr,
 	.route			= __nf_ip6_route,
 #endif
+	.cookie_init_sequence	= __cookie_v6_init_sequence,
 	.route_input		= ip6_route_input,
 	.fragment		= ip6_fragment,
 	.reroute		= nf_ip6_reroute,
Signature · 1 line
2.20.1
maintainer
#3 lore raw

Re: [PATCH nf-next v2 2/4] netfilter: synproxy: remove module dependency on IPv6 SYNPROXY

Quoted 22 lines · Fernando Fernandez Mancera

This is a prerequisite for the new infrastructure module NF_SYNPROXY. The new module is needed to avoid duplicated code for the SYNPROXY nftables support.

---
 include/linux/netfilter_ipv6.h | 3 +++
 net/ipv6/netfilter.c           | 1 +
 2 files changed, 4 insertions(+)
include/linux/netfilter_ipv6.h +1 -0
index 12113e502656..f440aaade612 100644
@@ -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.

include/linux/netfilter_ipv6.h struct nf_ipv6_ops { · line 40

Quoted 5 lines
include/linux/netfilter_ipv6.h +2 -0
@@ -35,6 +36,8 @@ struct nf_ipv6_ops {
 	int (*route)(struct net *net, struct dst_entry **dst, struct flowi *fl,
 		     bool strict);
 #endif
+	u32 (*cookie_init_sequence)(const struct ipv6hdr *iph,
+				    const struct tcphdr *th, u16 *mssp);

Could you place this above, in the #endif block?

You will need to create a helper as well:
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);
#else
	return __cookie_v6_init_sequence(iph, th, mssp);

#endif
}

This way, when ipv6 is built-in, then we don't have the indirection if netfilter uses the nf_ipv6_cookie_init_sequence() helper.

Also, can you check that if using CONFIG_IPV6=m then "modinfo nf_synproxy" won't list ipv6 as a a module depencency?

If it does, there is another symbol that pulls in ipv6 (depmod will say which one).

Thanks!

#4 lore raw

Re: [PATCH nf-next v2 2/4] netfilter: synproxy: remove module dependency on IPv6 SYNPROXY

Hi Florian,

Quoted 43 lines · Florian Westphal
Quoted 22 lines · Fernando Fernandez Mancera

This is a prerequisite for the new infrastructure module NF_SYNPROXY. The new module is needed to avoid duplicated code for the SYNPROXY nftables support.

---
 include/linux/netfilter_ipv6.h | 3 +++
 net/ipv6/netfilter.c           | 1 +
 2 files changed, 4 insertions(+)
include/linux/netfilter_ipv6.h +1 -0
index 12113e502656..f440aaade612 100644
@@ -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.

include/linux/netfilter_ipv6.h struct nf_ipv6_ops { · line 40

Quoted 5 lines
include/linux/netfilter_ipv6.h +2 -0
@@ -35,6 +36,8 @@ struct nf_ipv6_ops {
 	int (*route)(struct net *net, struct dst_entry **dst, struct flowi *fl,
 		     bool strict);
 #endif
+	u32 (*cookie_init_sequence)(const struct ipv6hdr *iph,
+				    const struct tcphdr *th, u16 *mssp);

Could you place this above, in the #endif block?

You will need to create a helper as well:
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);
#else
	return __cookie_v6_init_sequence(iph, th, mssp);
Quoted 3 lines

#endif
}

Sure, I am going to do it.

Quoted 6 lines

This way, when ipv6 is built-in, then we don't have the indirection if netfilter uses the nf_ipv6_cookie_init_sequence() helper.

Also, can you check that if using CONFIG_IPV6=m then "modinfo nf_synproxy" won't list ipv6 as a a module depencency?

Yes, I will check it. Also, I have some questions about the kbuild robot reports. Why are it reporting the following errors?

Quoted 10 lines

ERROR: "ipv4_synproxy_hook" [net/ipv6/netfilter/ip6t_SYNPROXY.ko] undefined!
ERROR: "synproxy_send_client_synack_ipv6" [net/ipv6/netfilter/ip6t_SYNPROXY.ko] undefined!
ERROR: "synproxy_recv_client_ack_ipv6" [net/ipv6/netfilter/ip6t_SYNPROXY.ko] undefined!
ERROR: "nf_synproxy_ipv6_init" [net/ipv6/netfilter/ip6t_SYNPROXY.ko] undefined!
ERROR: "nf_synproxy_ipv6_fini" [net/ipv6/netfilter/ip6t_SYNPROXY.ko] undefined!
ERROR: "ipv4_synproxy_hook" [net/ipv4/netfilter/ipt_SYNPROXY.ko] undefined!
ERROR: "synproxy_send_client_synack" [net/ipv4/netfilter/ipt_SYNPROXY.ko] undefined!
ERROR: "synproxy_recv_client_ack" [net/ipv4/netfilter/ipt_SYNPROXY.ko] undefined!
ERROR: "nf_synproxy_ipv4_init" [net/ipv4/netfilter/ipt_SYNPROXY.ko] undefined!
ERROR: "nf_synproxy_ipv4_fini" [net/ipv4/netfilter/ipt_SYNPROXY.ko] undefined!

Why undefined? I have exported them with EXPORT_SYMBOL_GPL(). What am I missing? Thanks!

Quoted 5 lines

If it does, there is another symbol that pulls in ipv6 (depmod will say which one).

Thanks!

maintainer
#5 lore raw

Re: [PATCH nf-next v2 2/4] netfilter: synproxy: remove module dependency on IPv6 SYNPROXY

Quoted 11 lines · Fernando Fernandez Mancera
Quoted 10 lines

ERROR: "ipv4_synproxy_hook" [net/ipv6/netfilter/ip6t_SYNPROXY.ko] undefined!
ERROR: "synproxy_send_client_synack_ipv6" [net/ipv6/netfilter/ip6t_SYNPROXY.ko] undefined!
ERROR: "synproxy_recv_client_ack_ipv6" [net/ipv6/netfilter/ip6t_SYNPROXY.ko] undefined!
ERROR: "nf_synproxy_ipv6_init" [net/ipv6/netfilter/ip6t_SYNPROXY.ko] undefined!
ERROR: "nf_synproxy_ipv6_fini" [net/ipv6/netfilter/ip6t_SYNPROXY.ko] undefined!
ERROR: "ipv4_synproxy_hook" [net/ipv4/netfilter/ipt_SYNPROXY.ko] undefined!
ERROR: "synproxy_send_client_synack" [net/ipv4/netfilter/ipt_SYNPROXY.ko] undefined!
ERROR: "synproxy_recv_client_ack" [net/ipv4/netfilter/ipt_SYNPROXY.ko] undefined!
ERROR: "nf_synproxy_ipv4_init" [net/ipv4/netfilter/ipt_SYNPROXY.ko] undefined!
ERROR: "nf_synproxy_ipv4_fini" [net/ipv4/netfilter/ipt_SYNPROXY.ko] undefined!

Quoted 2 lines

Why undefined? I have exported them with EXPORT_SYMBOL_GPL(). What am I missing? Thanks!

The only cases I can think of are these:

a) synproxy_send_client_synack_ipv6 etc. is not exported
b) synproxy_send_client_synack_ipv6 are exported, but not built (usually points to a dependency bug).
c) synproxy_send_client_synack_ipv6 are in a module, but foo.o is builtin

Above errors would hint at b). You can check the .config if thats the case or not.

#6 lore raw

Re: [PATCH nf-next v2 2/4] netfilter: synproxy: remove module dependency on IPv6 SYNPROXY

Quoted 28 lines · Florian Westphal
Quoted 1 line · Fernando Fernandez Mancera
Quoted 1 line

ERROR: "ipv4_synproxy_hook" [net/ipv6/netfilter/ip6t_SYNPROXY.ko]

undefined!

Quoted 1 line
Quoted 1 line

ERROR: "synproxy_send_client_synack_ipv6"

[net/ipv6/netfilter/ip6t_SYNPROXY.ko] undefined!

Quoted 1 line
Quoted 1 line

ERROR: "synproxy_recv_client_ack_ipv6"

[net/ipv6/netfilter/ip6t_SYNPROXY.ko] undefined!

Quoted 1 line
Quoted 1 line

ERROR: "nf_synproxy_ipv6_init"

[net/ipv6/netfilter/ip6t_SYNPROXY.ko] undefined!

Quoted 1 line
Quoted 1 line

ERROR: "nf_synproxy_ipv6_fini"

[net/ipv6/netfilter/ip6t_SYNPROXY.ko] undefined!

Quoted 1 line
Quoted 1 line

ERROR: "ipv4_synproxy_hook" [net/ipv4/netfilter/ipt_SYNPROXY.ko]

undefined!

Quoted 1 line
Quoted 1 line

ERROR: "synproxy_send_client_synack"

[net/ipv4/netfilter/ipt_SYNPROXY.ko] undefined!

Quoted 1 line
Quoted 1 line

ERROR: "synproxy_recv_client_ack"

[net/ipv4/netfilter/ipt_SYNPROXY.ko] undefined!

Quoted 1 line
Quoted 1 line

ERROR: "nf_synproxy_ipv4_init"

[net/ipv4/netfilter/ipt_SYNPROXY.ko] undefined!

Quoted 1 line
Quoted 1 line

ERROR: "nf_synproxy_ipv4_fini"

[net/ipv4/netfilter/ipt_SYNPROXY.ko] undefined!

Quoted 2 lines

Why undefined? I have exported them with EXPORT_SYMBOL_GPL(). What am

I

Quoted 1 line

missing? Thanks!

The only cases I can think of are these:

Quoted 8 lines

a) synproxy_send_client_synack_ipv6 etc. is not exported
b) synproxy_send_client_synack_ipv6 are exported, but not built (usually points to a dependency bug).
c) synproxy_send_client_synack_ipv6 are in a module, but foo.o is builtin

Above errors would hint at b). You can check the .config if thats the case or not.

Thanks Florian, I will check them :-)

#7 lore raw

Re: [PATCH nf-next v2 2/4] netfilter: synproxy: remove module dependency on IPv6 SYNPROXY

In reply to Fernando Fernandez Mancera
Thank you for the patch! Yet something to improve:

Hi Fernando,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on nf-next/master]

url:    https://github.com/0day-ci/linux/commits/Fernando-Fernandez-Mancera/Extract-SYNPROXY-infrastructure/20190520-153903
base:   https://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git master
config: i386-randconfig-x002-201920 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

If you fix the issue, kindly add following tag

All errors (new ones prefixed by >>):

>> net/ipv6/netfilter.c:119:26: error: '__cookie_v6_init_sequence' undeclared here (not in a function); did you mean 'cookie_init_sequence'?

.cookie_init_sequence = __cookie_v6_init_sequence,
^~~~~~~~~~~~~~~~~~~~~~~~~ cookie_init_sequence

vim +119 net/ipv6/netfilter.c

111
112 static const struct nf_ipv6_ops ipv6ops = {
113 #if IS_MODULE(CONFIG_IPV6)
114 .chk_addr = ipv6_chk_addr,
115 .route_me_harder = ip6_route_me_harder,
116 .dev_get_saddr = ipv6_dev_get_saddr,
117 .route = __nf_ip6_route,
118 #endif

 > 119		.cookie_init_sequence	= __cookie_v6_init_sequence,

120 .route_input = ip6_route_input,
121 .fragment = ip6_fragment,
122 .reroute = nf_ip6_reroute,
123 };
124

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#8 lore raw

PATCH v2 3/4 netfilter: synproxy: extract SYNPROXY infrastructure from {ipt,ip6t}_SYNPROXY

In reply to Fernando Fernandez Mancera

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

---
 include/net/netfilter/nf_synproxy.h |  76 +++
 net/ipv4/netfilter/ipt_SYNPROXY.c   | 394 +------------
 net/ipv6/netfilter/ip6t_SYNPROXY.c  | 420 +-------------
 net/netfilter/nf_synproxy.c         | 819 ++++++++++++++++++++++++++++
 4 files changed, 910 insertions(+), 799 deletions(-)
 create mode 100644 include/net/netfilter/nf_synproxy.h
 create mode 100644 net/netfilter/nf_synproxy.c
include/net/netfilter/nf_synproxy.h new file +76 -0
new file mode 100644
index 000000000000..97fb12ea5092
@@ -0,0 +1,76 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _NF_SYNPROXY_SHARED_H
+#define _NF_SYNPROXY_SHARED_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>
+
+/* IPv4 support */
+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,
+	},
+};
+
+#if IS_ENABLED(CONFIG_IPV6) /* IPv6 support */
+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 /* IPv6 support */
+
+#endif /* _NF_SYNPROXY_SHARED_H */
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.c new file +819 -0

819 lines not on this page · raw message

Signature · 1 line
2.20.1
maintainer
#9 lore raw

Re: [PATCH nf-next v2 3/4] netfilter: synproxy: extract SYNPROXY infrastructure from {ipt,ip6t}_SYNPROXY

Quoted 19 lines · Fernando Fernandez Mancera
---
 include/net/netfilter/nf_synproxy.h |  76 +++
 net/ipv4/netfilter/ipt_SYNPROXY.c   | 394 +------------
 net/ipv6/netfilter/ip6t_SYNPROXY.c  | 420 +-------------
 net/netfilter/nf_synproxy.c         | 819 ++++++++++++++++++++++++++++
 4 files changed, 910 insertions(+), 799 deletions(-)
 create mode 100644 include/net/netfilter/nf_synproxy.h
 create mode 100644 net/netfilter/nf_synproxy.c
include/net/netfilter/nf_synproxy.h new file +5 -0
new file mode 100644
index 000000000000..97fb12ea5092
+/* Hook operations used by {ip,nf}tables SYNPROXY support */
+const struct nf_hook_ops ipv4_synproxy_ops[] = {
+	{
+		.hook		= ipv4_synproxy_hook,
+		.pf		= NFPROTO_IPV4,

include/net/netfilter/nf_synproxy.h line 43

Quoted 10 lines
include/net/netfilter/nf_synproxy.h new file +10 -0
+		.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,
+	},
+};

Can this be avoided?

This should only be placed in a single .c file, not in a header. I also suspect this should be 'static const'.

Seems you can just move it to nf_synproxy.c, where its used.

Quoted 1 line

+static const struct nf_hook_ops ipv6_synproxy_ops[] = {

likewise.

#10 lore raw

Re: [PATCH nf-next v2 3/4] netfilter: synproxy: extract SYNPROXY infrastructure from {ipt,ip6t}_SYNPROXY

Hi Florian,

Quoted 33 lines · Florian Westphal
Quoted 19 lines · Fernando Fernandez Mancera
---
 include/net/netfilter/nf_synproxy.h |  76 +++
 net/ipv4/netfilter/ipt_SYNPROXY.c   | 394 +------------
 net/ipv6/netfilter/ip6t_SYNPROXY.c  | 420 +-------------
 net/netfilter/nf_synproxy.c         | 819 ++++++++++++++++++++++++++++
 4 files changed, 910 insertions(+), 799 deletions(-)
 create mode 100644 include/net/netfilter/nf_synproxy.h
 create mode 100644 net/netfilter/nf_synproxy.c
include/net/netfilter/nf_synproxy.h new file +5 -0
new file mode 100644
index 000000000000..97fb12ea5092
+/* Hook operations used by {ip,nf}tables SYNPROXY support */
+const struct nf_hook_ops ipv4_synproxy_ops[] = {
+	{
+		.hook		= ipv4_synproxy_hook,
+		.pf		= NFPROTO_IPV4,

include/net/netfilter/nf_synproxy.h line 43

Quoted 10 lines
include/net/netfilter/nf_synproxy.h new file +10 -0
+		.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,
+	},
+};

Can this be avoided?

Quoted 5 lines

This should only be placed in a single .c file, not in a header. I also suspect this should be 'static const'.

Seems you can just move it to nf_synproxy.c, where its used.

My fault, I thought it was used in ipt_SYNPROXY.c and ip6t_SYNPROXY.c. Sorry I am going to change this in a v3 among others changes suggested after reviews. Thanks!

Quoted 4 lines
Quoted 1 line

+static const struct nf_hook_ops ipv6_synproxy_ops[] = {

likewise.

#11 lore raw

Re: [PATCH nf-next v2 3/4] netfilter: synproxy: extract SYNPROXY infrastructure from {ipt,ip6t}_SYNPROXY

In reply to Fernando Fernandez Mancera
Thank you for the patch! Yet something to improve:

Hi Fernando,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on nf-next/master]

url:    https://github.com/0day-ci/linux/commits/Fernando-Fernandez-Mancera/Extract-SYNPROXY-infrastructure/20190520-153903
base:   https://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git master
config: x86_64-rhel (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

If you fix the issue, kindly add following tag

Note: the linux-review/Fernando-Fernandez-Mancera/Extract-SYNPROXY-infrastructure/20190520-153903 HEAD 6e2622e666e78f7a08abe688716a3edcc2b7e285 builds fine.
It only hurts bisectibility.

All errors (new ones prefixed by >>):

>> ERROR: "ipv4_synproxy_hook" [net/ipv6/netfilter/ip6t_SYNPROXY.ko] undefined!

ERROR: "synproxy_send_client_synack_ipv6" [net/ipv6/netfilter/ip6t_SYNPROXY.ko] undefined!
ERROR: "synproxy_recv_client_ack_ipv6" [net/ipv6/netfilter/ip6t_SYNPROXY.ko] undefined!
ERROR: "nf_synproxy_ipv6_init" [net/ipv6/netfilter/ip6t_SYNPROXY.ko] undefined!
ERROR: "nf_synproxy_ipv6_fini" [net/ipv6/netfilter/ip6t_SYNPROXY.ko] undefined!
ERROR: "ipv4_synproxy_hook" [net/ipv4/netfilter/ipt_SYNPROXY.ko] undefined!
ERROR: "synproxy_send_client_synack" [net/ipv4/netfilter/ipt_SYNPROXY.ko] undefined!
ERROR: "synproxy_recv_client_ack" [net/ipv4/netfilter/ipt_SYNPROXY.ko] undefined!
ERROR: "nf_synproxy_ipv4_init" [net/ipv4/netfilter/ipt_SYNPROXY.ko] undefined!
ERROR: "nf_synproxy_ipv4_fini" [net/ipv4/netfilter/ipt_SYNPROXY.ko] undefined!

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#12 lore raw

PATCH v2 4/4 netfilter: add NF_SYNPROXY symbol

In reply to Fernando Fernandez Mancera
---
 net/ipv4/netfilter/Kconfig | 2 +-
 net/ipv6/netfilter/Kconfig | 2 +-
 net/netfilter/Kconfig      | 3 +++
 net/netfilter/Makefile     | 1 +
 4 files changed, 6 insertions(+), 2 deletions(-)
net/ipv4/netfilter/Kconfig +1 -1
index 1412b029f37f..87f6ec800e54 100644
@@ -197,7 +197,7 @@ config IP_NF_TARGET_SYNPROXY
 	tristate "SYNPROXY target support"
 	depends on NF_CONNTRACK && NETFILTER_ADVANCED
 	select NETFILTER_SYNPROXY
-	select SYN_COOKIES
+	select NF_SYNPROXY
 	help
 	  The SYNPROXY target allows you to intercept TCP connections and
 	  establish them using syncookies before they are passed on to the
net/ipv6/netfilter/Kconfig +1 -1
index 086fc669279e..79fb64706017 100644
@@ -212,8 +212,8 @@ config IP6_NF_TARGET_REJECT
 config IP6_NF_TARGET_SYNPROXY
 	tristate "SYNPROXY target support"
 	depends on NF_CONNTRACK && NETFILTER_ADVANCED
+	select NF_SYNPROXY
 	select NETFILTER_SYNPROXY
-	select SYN_COOKIES
 	help
 	  The SYNPROXY target allows you to intercept TCP connections and
 	  establish them using syncookies before they are passed on to the
net/netfilter/Kconfig +3 -0
index 02b281d3c167..951e8daa896b 100644
@@ -435,6 +435,9 @@ config NF_NAT_REDIRECT
 config NF_NAT_MASQUERADE
 	bool
 
+config NF_SYNPROXY
+	tristate
+
 config NETFILTER_SYNPROXY
 	tristate
 
net/netfilter/Makefile +1 -0
index 72cca6b48960..7a6067513eee 100644
@@ -67,6 +67,7 @@ obj-$(CONFIG_NF_NAT_TFTP) += nf_nat_tftp.o
 
 # SYNPROXY
 obj-$(CONFIG_NETFILTER_SYNPROXY) += nf_synproxy_core.o
+obj-$(CONFIG_NF_SYNPROXY) += nf_synproxy.o
 
 obj-$(CONFIG_NETFILTER_CONNCOUNT) += nf_conncount.o
 
Signature · 1 line
2.20.1
#13 lore raw

Re: [PATCH nf-next v2 4/4] netfilter: add NF_SYNPROXY symbol

Thank you for the patch! Yet something to improve:

Hi Fernando,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on nf-next/master]

url:    https://github.com/0day-ci/linux/commits/Fernando-Fernandez-Mancera/Extract-SYNPROXY-infrastructure/20190520-153903
base:   https://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git master
config: i386-randconfig-l3-201920 (attached as .config)
compiler: gcc-5 (Debian 5.5.0-3) 5.4.1 20171010
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

If you fix the issue, kindly add following tag

All errors (new ones prefixed by >>):

>> ld: net/ipv4/netfilter/ipt_SYNPROXY.o:include/net/netfilter/nf_synproxy.h:30: multiple definition of `ipv4_synproxy_ops'; net/netfilter/nf_synproxy.o:include/net/netfilter/nf_synproxy.h:30: first defined here

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#14 lore raw

Re: [PATCH nf-next v2 4/4] netfilter: add NF_SYNPROXY symbol

In reply to Fernando Fernandez Mancera

Hi Fernando,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on nf-next/master]

url:    https://github.com/0day-ci/linux/commits/Fernando-Fernandez-Mancera/Extract-SYNPROXY-infrastructure/20190520-153903
base:   https://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git master

If you fix the issue, kindly add following tag

smatch warnings:
net/netfilter/nf_synproxy.c:380 nf_synproxy_ipv4_init() error: uninitialized symbol 'err'. net/netfilter/nf_synproxy.c:803 nf_synproxy_ipv6_init() error: uninitialized symbol 'err'.

# https://github.com/0day-ci/linux/commit/6e2622e666e78f7a08abe688716a3edcc2b7e285
git remote add linux-review https://github.com/0day-ci/linux
git remote update linux-review
git checkout 6e2622e666e78f7a08abe688716a3edcc2b7e285
vim +/err +380 net/netfilter/nf_synproxy.c

d918090b Fernando Fernandez Mancera 2019-05-19  367  
d918090b Fernando Fernandez Mancera 2019-05-19  368  int nf_synproxy_ipv4_init(struct synproxy_net *snet, struct net *net)
d918090b Fernando Fernandez Mancera 2019-05-19  369  {
d918090b Fernando Fernandez Mancera 2019-05-19  370  	int err;
                                                        ^^^^^^^
d918090b Fernando Fernandez Mancera 2019-05-19  371  
d918090b Fernando Fernandez Mancera 2019-05-19  372  	if (snet->hook_ref4 == 0) {
                                                            ^^^^^^^^^^^^^^^^^^^^

Assume this is false.

d918090b Fernando Fernandez Mancera 2019-05-19  373  		err = nf_register_net_hooks(net, ipv4_synproxy_ops,
d918090b Fernando Fernandez Mancera 2019-05-19  374  					    ARRAY_SIZE(ipv4_synproxy_ops));
d918090b Fernando Fernandez Mancera 2019-05-19  375  		if (err)
d918090b Fernando Fernandez Mancera 2019-05-19  376  			return err;
d918090b Fernando Fernandez Mancera 2019-05-19  377  	}
d918090b Fernando Fernandez Mancera 2019-05-19  378  
d918090b Fernando Fernandez Mancera 2019-05-19  379  	snet->hook_ref4++;
d918090b Fernando Fernandez Mancera 2019-05-19 @380  	return err;
                                                               ^^^
d918090b Fernando Fernandez Mancera 2019-05-19  381  }
d918090b Fernando Fernandez Mancera 2019-05-19  382  EXPORT_SYMBOL_GPL(nf_synproxy_ipv4_init);
d918090b Fernando Fernandez Mancera 2019-05-19  383  

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation