Netfilter/IPVS updates for net-next
Subsystems (5)
Pablo Neira Ayuso
maintainercover Netfilter/IPVS updates for net-next
Hi David,
The following batch contains Netfilter/IPVS updates for your net-next tree. More specifically, they are:
* Trivial typo fix in xt_addrtype, from Phil Oester.
* Remove net_ratelimit in the conntrack logging for consistency with other logging subsystem, from Patrick McHardy.
* Remove unneeded includes from the recently added xt_connlabel support, from Florian Westphal.
* Allow to update conntracks via nfqueue, don't need NFQA_CFG_F_CONNTRACK for this, from Florian Westphal.
* Remove tproxy core, now that we have socket early demux, from Florian Westphal.
* A couple of patches to refactor conntrack event reporting to save a good bunch of lines, from Florian Westphal.
* Fix missing locking in NAT sequence adjustment, it did not manifested in any known bug so far, from Patrick McHardy.
* Change sequence number adjustment variable to 32 bits, to delay the possible early overflow in long standing connections, also from Patrick.
* Comestic cleanups for IPVS, from Dragos Foianu.
* Fix possible null dereference in IPVS in the SH scheduler, from Daniel Borkmann.
* Allow to attach conntrack expectations via nfqueue. Before this patch, you had to use ctnetlink instead, thus, we save the conntrack lookup.
* Export xt_rpfilter and xt_HMARK header files, from Nicolas Dichtel.
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git master
Thanks!
----------------------------------------------------------------
The following changes since commit 9025c8e253369d324111c041032018955b80dd55:
drivers/net/ethernet/stmicro/stmmac: don't check resource with devm_ioremap_resource (2013-07-24 23:59:33 -0700)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git master
for you to fetch changes up to 38c67328ac79cb9eaf61b5d4750fe3b9cff0dd15:
netfilter: export xt_HMARK.h to userland (2013-08-14 10:48:05 +0200)
----------------------------------------------------------------
Daniel Borkmann (1):
ipvs: ip_vs_sh: ip_vs_sh_get_port: check skb_header_pointer for NULL
Dragos Foianu (1):
ipvs: fixed spacing at for statements
Florian Westphal (7):
netfilter: connlabels: remove unneeded includes
netfilter: nf_queue: relax NFQA_CT attribute check
netfilter: tproxy: remove nf_tproxy_core, keep tw sk assigned to skb
netfilter: tproxy: remove nf_tproxy_core.h
netfilter: nf_conntrack: remove duplicate code in ctnetlink
netfilter: tproxy: fix build with IP6_NF_IPTABLES=n
netfilter: nf_conntrack: don't send destroy events from iterator
Nicolas Dichtel (2):
netfilter: export xt_rpfilter.h to userland
netfilter: export xt_HMARK.h to userland
Pablo Neira Ayuso (2):
netfilter: ctnetlink: refactor ctnetlink_create_expect
netfilter: nfnetlink_queue: allow to attach expectations to conntracks
Patrick McHardy (5):
netfilter: nf_conntrack: remove net_ratelimit() for LOG_INVALID()
netfilter: nf_conntrack: constify sk_buff argument to nf_ct_attach()
netfilter: nf_nat: fix locking in nf_nat_seq_adjust()
netfilter: nf_nat: change sequence number adjustments to 32 bits
netfilter: nf_nat: use per-conntrack locking for sequence number adjustments
Phil Oester (1):
netfilter: xt_addrtype: fix trivial typo
Documentation/networking/tproxy.txt | 5 +-
include/linux/netfilter.h | 8 +-
include/net/netfilter/nf_conntrack.h | 9 +-
include/net/netfilter/nf_conntrack_l4proto.h | 7 -
include/net/netfilter/nf_nat.h | 2 +-
include/net/netfilter/nf_nat_helper.h | 6 +-
include/net/netfilter/nf_tproxy_core.h | 210 -----------------
include/net/netfilter/nfnetlink_queue.h | 8 +
include/uapi/linux/netfilter/Kbuild | 2 +
include/uapi/linux/netfilter/nfnetlink_queue.h | 1 +
include/{ => uapi}/linux/netfilter/xt_HMARK.h | 0
include/{ => uapi}/linux/netfilter/xt_rpfilter.h | 0
net/ipv4/netfilter/ipt_MASQUERADE.c | 2 +-
net/ipv6/netfilter/ip6t_MASQUERADE.c | 2 +-
net/netfilter/Kconfig | 22 +-
net/netfilter/Makefile | 3 -
net/netfilter/core.c | 7 +-
net/netfilter/ipvs/ip_vs_lblcr.c | 8 +-
net/netfilter/ipvs/ip_vs_sh.c | 6 +
net/netfilter/nf_conntrack_core.c | 69 ++----
net/netfilter/nf_conntrack_labels.c | 4 -
net/netfilter/nf_conntrack_netlink.c | 269 ++++++++++++++--------
net/netfilter/nf_conntrack_proto.c | 4 +-
net/netfilter/nf_conntrack_proto_tcp.c | 4 +-
net/netfilter/nf_nat_core.c | 6 +-
net/netfilter/nf_nat_helper.c | 28 ++-
net/netfilter/nf_tproxy_core.c | 62 -----
net/netfilter/nfnetlink_queue_core.c | 11 +-
net/netfilter/nfnetlink_queue_ct.c | 15 ++
net/netfilter/xt_TPROXY.c | 169 +++++++++++++-
net/netfilter/xt_addrtype.c | 2 +-
net/netfilter/xt_socket.c | 66 +++++-
32 files changed, 513 insertions(+), 504 deletions(-)
delete mode 100644 include/net/netfilter/nf_tproxy_core.h
rename include/{ => uapi}/linux/netfilter/xt_HMARK.h (100%)
rename include/{ => uapi}/linux/netfilter/xt_rpfilter.h (100%)
delete mode 100644 net/netfilter/nf_tproxy_core.cPablo Neira Ayuso
maintainerPATCH 1/19 netfilter: xt_addrtype: fix trivial typo
From: Phil Oester <[email protected]>
Fix typo in error message.
--- net/netfilter/xt_addrtype.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/xt_addrtype.c +1 -1
@@ -202,7 +202,7 @@ static int addrtype_mt_checkentry_v1(const struct xt_mtchk_param *par)return -EINVAL ; }if ((info->source | info->dest) >=XT_ADDRTYPE_PROHIBIT ) { -pr_err ("ipv6 PROHIBT (THROW, NAT ..) matching not supported\n" ); +pr_err ("ipv6 PROHIBIT (THROW, NAT ..) matching not supported\n" );return -EINVAL ; }if ((info->source | info->dest) &XT_ADDRTYPE_BROADCAST ) {
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 2/19 netfilter: nf_conntrack: remove net_ratelimit() for LOG_INVALID()
In reply to Pablo Neira AyusoFrom: Patrick McHardy <[email protected]>
Logging of invalid packets has to be explicitly enabled. Rate-limiting these messages is inconsistent with other netfilter logging features and makes debugging harder.
--- include/net/netfilter/nf_conntrack_l4proto.h | 7 ------- 1 file changed, 7 deletions(-)
include/net/netfilter/nf_conntrack_l4proto.h +0 -7
@@ -148,17 +148,10 @@ extern int nf_ct_port_nlattr_tuple_size(void);extern const struct nla_policy nf_ct_port_nla_policy[];#ifdef CONFIG_SYSCTL -#ifdef DEBUG_INVALID_PACKETS #define LOG_INVALID (net, proto) \ ((net)->ct.sysctl_log_invalid == (proto) || \ (net)->ct.sysctl_log_invalid == IPPROTO_RAW)#else -#define LOG_INVALID (net, proto) \ - (((net)->ct.sysctl_log_invalid == (proto) || \ - (net)->ct.sysctl_log_invalid == IPPROTO_RAW) \ - && net_ratelimit()) -#endif -#else static inline int LOG_INVALID (struct net *net,int proto) {return 0 ; }#endif /* CONFIG_SYSCTL */
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 3/19 netfilter: nf_conntrack: constify sk_buff argument to nf_ct_attach()
In reply to Pablo Neira AyusoFrom: Patrick McHardy <[email protected]>
--- include/linux/netfilter.h | 4 ++-- net/netfilter/core.c | 7 ++++--- net/netfilter/nf_conntrack_core.c | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-)
include/linux/netfilter.h +2 -2
@@ -314,8 +314,8 @@ nf_nat_decode_session(struct sk_buff *skb, struct flowi *fl, u_int8_t family)#endif /*CONFIG_NETFILTER*/ #if defined(CONFIG_NF_CONNTRACK ) || defined(CONFIG_NF_CONNTRACK_MODULE ) -extern void (*ip_ct_attach)(struct sk_buff *,struct sk_buff *)__rcu ; -extern void nf_ct_attach (struct sk_buff *,struct sk_buff *); +extern void (*ip_ct_attach)(struct sk_buff *,const struct sk_buff *)__rcu ; +extern void nf_ct_attach (struct sk_buff *,const struct sk_buff *);extern void (*nf_ct_destroy)(struct nf_conntrack *)__rcu ;struct nf_conn ;
net/netfilter/core.c +4 -3
@@ -234,12 +234,13 @@ EXPORT_SYMBOL(skb_make_writable);/* This does not belong here, but locally generated errors need it if connection tracking in use: without this, connection may not be in hash table, and hence manufactured ICMP or RST packets will not be associated with it. */ -void (*ip_ct_attach)(struct sk_buff *,struct sk_buff *)__rcu __read_mostly ; +void (*ip_ct_attach)(struct sk_buff *,const struct sk_buff *) +__rcu __read_mostly ;EXPORT_SYMBOL (ip_ct_attach); -void nf_ct_attach (struct sk_buff *new,struct sk_buff *skb) +void nf_ct_attach (struct sk_buff *new,const struct sk_buff *skb) { -void (*attach)(struct sk_buff *,struct sk_buff *); +void (*attach)(struct sk_buff *,const struct sk_buff *);if (skb->nfct) {rcu_read_lock ();
net/netfilter/nf_conntrack_core.c +1 -1
@@ -1192,7 +1192,7 @@ EXPORT_SYMBOL_GPL(nf_ct_port_nlattr_tuple_size);#endif /* Used by ipt_REJECT and ip6t_REJECT. */ -static void nf_conntrack_attach (struct sk_buff *nskb,struct sk_buff *skb) +static void nf_conntrack_attach (struct sk_buff *nskb,const struct sk_buff *skb) {struct nf_conn *ct;enum ip_conntrack_info ctinfo;
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 4/19 netfilter: connlabels: remove unneeded includes
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
leftovers from the (never merged) v1 patch.
--- net/netfilter/nf_conntrack_labels.c | 4 ---- 1 file changed, 4 deletions(-)
net/netfilter/nf_conntrack_labels.c +0 -4
@@ -8,12 +8,8 @@* published by the Free Software Foundation. */ -#include <linux/ctype.h> #include <linux/export.h> -#include <linux/jhash.h> -#include <linux/spinlock.h> #include <linux/types.h> -#include <linux/slab.h> #include <net/netfilter/nf_conntrack_ecache.h> #include <net/netfilter/nf_conntrack_labels.h>
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 5/19 netfilter: nf_queue: relax NFQA_CT attribute check
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Allow modifying attributes of the conntrack associated with a packet without first requesting ct data via CFG_F_CONNTRACK or extra nfnetlink_conntrack socket.
Also remove unneded rcu_read_lock; the entire function is already protected by rcu.
--- net/netfilter/nfnetlink_queue_core.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
net/netfilter/nfnetlink_queue_core.c +1 -3
@@ -987,8 +987,7 @@ nfqnl_recv_verdict(struct sock *ctnl, struct sk_buff *skb,if (entry ==NULL )return -ENOENT ; -rcu_read_lock (); -if (nfqa[NFQA_CT ] && (queue->flags &NFQA_CFG_F_CONNTRACK )) +if (nfqa[NFQA_CT ]) ct =nfqnl_ct_parse (entry->skb, nfqa[NFQA_CT ], &ctinfo);if (nfqa[NFQA_PAYLOAD ]) {
@@ -1002,7 +1001,6 @@ nfqnl_recv_verdict(struct sock *ctnl, struct sk_buff *skb,if (ct)nfqnl_ct_seq_adjust (skb, ct, ctinfo, diff); } -rcu_read_unlock ();if (nfqa[NFQA_MARK ]) entry->skb->mark =ntohl (nla_get_be32 (nfqa[NFQA_MARK ]));
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 6/19 netfilter: tproxy: remove nf_tproxy_core, keep tw sk assigned to skb
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
The module was "permanent", due to the special tproxy skb->destructor. Nowadays we have tcp early demux and its sock_edemux destructor in networking core which can be used instead.
Thanks to early demux changes the input path now also handles "skb->sk is tw socket" correctly, so this no longer needs the special handling introduced with commit d503b30bd648b3cb4e5f50b65d27e389960cc6d9 (netfilter: tproxy: do not assign timewait sockets to skb->sk).
Thus:
- move assign_sock function to where its needed
- don't prevent timewait sockets from being assigned to the skb
- remove nf_tproxy_core.
--- Documentation/networking/tproxy.txt | 5 ++- include/net/netfilter/nf_tproxy_core.h | 4 --- net/netfilter/Kconfig | 22 +++--------- net/netfilter/Makefile | 3 -- net/netfilter/nf_tproxy_core.c | 62 -------------------------------- net/netfilter/xt_TPROXY.c | 9 +++++ 6 files changed, 16 insertions(+), 89 deletions(-) delete mode 100644 net/netfilter/nf_tproxy_core.c
Documentation/networking/tproxy.txt +2 -3
@@ -2,9 +2,8 @@ Transparent proxy support ========================= This feature adds Linux 2.2-like transparent proxy support to current kernels. -To use it, enable NETFILTER_TPROXY, the socket match and the TPROXY target in -your kernel config. You will need policy routing too, so be sure to enable that -as well. +To use it, enable the socket match and the TPROXY target in your kernel config. +You will need policy routing too, so be sure to enable that as well. 1. Making non-local sockets work
include/net/netfilter/nf_tproxy_core.h +0 -4
@@ -203,8 +203,4 @@ nf_tproxy_get_sock_v6(struct net *net, const u8 protocol, }#endif -/* assign a socket to the skb -- consumes sk */ -void -nf_tproxy_assign_sock (struct sk_buff *skb,struct sock *sk); -#endif
net/netfilter/Kconfig +5 -17
@@ -410,20 +410,6 @@ config NF_NAT_TFTP endif # NF_CONNTRACK -# transparent proxy support -config NETFILTER_TPROXY - tristate "Transparent proxying support" - depends on IP_NF_MANGLE - depends on NETFILTER_ADVANCED - help - This option enables transparent proxying support, that is, - support for handling non-locally bound IPv4 TCP and UDP sockets. - For it to work you will have to configure certain iptables rules - and use policy routing. For more information on how to set it up - see Documentation/networking/tproxy.txt. - - To compile it as a module, choose M here. If unsure, say N. - config NETFILTER_XTABLES tristate "Netfilter Xtables support (required for ip_tables)" default m if NETFILTER_ADVANCED=n
@@ -720,10 +706,10 @@ config NETFILTER_XT_TARGET_TEE this clone be rerouted to another nexthop. config NETFILTER_XT_TARGET_TPROXY - tristate '"TPROXY" target support' - depends on NETFILTER_TPROXY + tristate '"TPROXY" target transparent proxying support' depends on NETFILTER_XTABLES depends on NETFILTER_ADVANCED + depends on IP_NF_MANGLE select NF_DEFRAG_IPV4 select NF_DEFRAG_IPV6 if IP6_NF_IPTABLES help
@@ -731,6 +717,9 @@ config NETFILTER_XT_TARGET_TPROXY REDIRECT. It can only be used in the mangle table and is useful to redirect traffic to a transparent proxy. It does _not_ depend on Netfilter connection tracking and NAT, unlike REDIRECT. + For it to work you will have to configure certain iptables rules + and use policy routing. For more information on how to set it up + see Documentation/networking/tproxy.txt. To compile it as a module, choose M here. If unsure, say N.
@@ -1180,7 +1169,6 @@ config NETFILTER_XT_MATCH_SCTP config NETFILTER_XT_MATCH_SOCKET tristate '"socket" match support' - depends on NETFILTER_TPROXY depends on NETFILTER_XTABLES depends on NETFILTER_ADVANCED depends on !NF_CONNTRACK || NF_CONNTRACK
net/netfilter/Makefile +0 -3
@@ -61,9 +61,6 @@ obj-$(CONFIG_NF_NAT_IRC) += nf_nat_irc.o obj-$(CONFIG_NF_NAT_SIP) += nf_nat_sip.o obj-$(CONFIG_NF_NAT_TFTP) += nf_nat_tftp.o -# transparent proxy support -obj-$(CONFIG_NETFILTER_TPROXY) += nf_tproxy_core.o - # generic X tables obj-$(CONFIG_NETFILTER_XTABLES) += x_tables.o xt_tcpudp.o
net/netfilter/nf_tproxy_core.c deleted +0 -62
62 lines not on this page · raw message
net/netfilter/xt_TPROXY.c +9 -0
@@ -117,6 +117,15 @@ tproxy_handle_time_wait4(struct sk_buff *skb, __be32 laddr, __be16 lport,return sk; } +/* assign a socket to the skb -- consumes sk */ +static void +nf_tproxy_assign_sock (struct sk_buff *skb,struct sock *sk) +{ +skb_orphan (skb); + skb->sk = sk; + skb->destructor = sock_edemux; +} +static unsigned int tproxy_tg4 (struct sk_buff *skb,__be32 laddr,__be16 lport,u_int32_t mark_mask,u_int32_t mark_value)
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 7/19 netfilter: tproxy: remove nf_tproxy_core.h
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
We've removed nf_tproxy_core.ko, so also remove its header. The lookup helpers are split and then moved to tproxy target/socket match.
--- include/net/netfilter/nf_tproxy_core.h | 206 -------------------------------- net/netfilter/xt_TPROXY.c | 160 ++++++++++++++++++++++++- net/netfilter/xt_socket.c | 66 +++++++++- 3 files changed, 220 insertions(+), 212 deletions(-) delete mode 100644 include/net/netfilter/nf_tproxy_core.h
include/net/netfilter/nf_tproxy_core.h deleted +0 -206
@@ -1,206 +0,0 @@ -#ifndef _NF_TPROXY_CORE_H -#define _NF_TPROXY_CORE_H - -#include <linux/types.h> -#include <linux/in.h> -#include <linux/skbuff.h> -#include <net/sock.h> -#include <net/inet_hashtables.h> -#include <net/inet6_hashtables.h> -#include <net/tcp.h> - -#define NFT_LOOKUP_ANY 0 -#define NFT_LOOKUP_LISTENER 1 -#define NFT_LOOKUP_ESTABLISHED 2 - -/* look up and get a reference to a matching socket */ - - -/* This function is used by the 'TPROXY' target and the 'socket' -* match. The following lookups are supported: -* -* Explicit TProxy target rule -* =========================== -* -* This is used when the user wants to intercept a connection matching -* an explicit iptables rule. In this case the sockets are assumed -* matching in preference order: -* -* - match: if there's a fully established connection matching the -* _packet_ tuple, it is returned, assuming the redirection -* already took place and we process a packet belonging to an -* established connection -* -* - match: if there's a listening socket matching the redirection -* (e.g. on-port & on-ip of the connection), it is returned, -* regardless if it was bound to 0.0.0.0 or an explicit -* address. The reasoning is that if there's an explicit rule, it -* does not really matter if the listener is bound to an interface -* or to 0. The user already stated that he wants redirection -* (since he added the rule). -* -* "socket" match based redirection (no specific rule) -* =================================================== -* -* There are connections with dynamic endpoints (e.g. FTP data -* connection) that the user is unable to add explicit rules -* for. These are taken care of by a generic "socket" rule. It is -* assumed that the proxy application is trusted to open such -* connections without explicit iptables rule (except of course the -* generic 'socket' rule). In this case the following sockets are -* matched in preference order: -* -* - match: if there's a fully established connection matching the -* _packet_ tuple -* -* - match: if there's a non-zero bound listener (possibly with a -* non-local address) We don't accept zero-bound listeners, since -* then local services could intercept traffic going through the -* box. -* -* Please note that there's an overlap between what a TPROXY target -* and a socket match will match. Normally if you have both rules the -* "socket" match will be the first one, effectively all packets -* belonging to established connections going through that one. -*/ -static inline struct sock * -nf_tproxy_get_sock_v4 (struct net *net,const u8 protocol, -const __be32 saddr,const __be32 daddr, -const __be16 sport,const __be16 dport, -const struct net_device *in,int lookup_type) -{ -struct sock *sk; - -/* look up socket */ -switch (protocol) { -case IPPROTO_TCP : -switch (lookup_type) { -case NFT_LOOKUP_ANY : - sk =__inet_lookup (net, &tcp_hashinfo, - saddr, sport, daddr, dport, - in->ifindex); -break ; -case NFT_LOOKUP_LISTENER : - sk =inet_lookup_listener (net, &tcp_hashinfo, - saddr, sport, - daddr, dport, - in->ifindex); - -/* NOTE: we return listeners even if bound to -* 0.0.0.0, those are filtered out in -* xt_socket, since xt_TPROXY needs 0 bound -* listeners too */ - -break ; -case NFT_LOOKUP_ESTABLISHED : - sk =inet_lookup_established (net, &tcp_hashinfo, - saddr, sport, daddr, dport, - in->ifindex); -break ; -default : -WARN_ON (1 ); - sk =NULL ; -break ; - } -break ; -case IPPROTO_UDP : - sk =udp4_lib_lookup (net, saddr, sport, daddr, dport, - in->ifindex); -if (sk && lookup_type !=NFT_LOOKUP_ANY ) { -int connected = (sk->sk_state ==TCP_ESTABLISHED ); -int wildcard = (inet_sk (sk)->inet_rcv_saddr ==0 ); - -/* NOTE: we return listeners even if bound to -* 0.0.0.0, those are filtered out in -* xt_socket, since xt_TPROXY needs 0 bound -* listeners too */ -if ((lookup_type ==NFT_LOOKUP_ESTABLISHED && (!connected || wildcard)) || - (lookup_type ==NFT_LOOKUP_LISTENER && connected)) { -sock_put (sk); - sk =NULL ; - } - } -break ; -default : -WARN_ON (1 ); - sk =NULL ; - } - -pr_debug ("tproxy socket lookup: proto %u %08x:%u -> %08x:%u, lookup type: %d, sock %p\n" , - protocol,ntohl (saddr),ntohs (sport),ntohl (daddr),ntohs (dport), lookup_type, sk); - -return sk; -} - -#if IS_ENABLED (CONFIG_IPV6 ) -static inline struct sock * -nf_tproxy_get_sock_v6 (struct net *net,const u8 protocol, -const struct in6_addr *saddr,const struct in6_addr *daddr, -const __be16 sport,const __be16 dport, -const struct net_device *in,int lookup_type) -{ -struct sock *sk; - -/* look up socket */ -switch (protocol) { -case IPPROTO_TCP : -switch (lookup_type) { -case NFT_LOOKUP_ANY : - sk =inet6_lookup (net, &tcp_hashinfo, - saddr, sport, daddr, dport, - in->ifindex); -break ; -case NFT_LOOKUP_LISTENER : - sk =inet6_lookup_listener (net, &tcp_hashinfo, - saddr, sport, - daddr,ntohs (dport), - in->ifindex); - -/* NOTE: we return listeners even if bound to -* 0.0.0.0, those are filtered out in -* xt_socket, since xt_TPROXY needs 0 bound -* listeners too */ - -break ; -case NFT_LOOKUP_ESTABLISHED : - sk =__inet6_lookup_established (net, &tcp_hashinfo, - saddr, sport, daddr,ntohs (dport), - in->ifindex); -break ; -default : -WARN_ON (1 ); - sk =NULL ; -break ; - } -break ; -case IPPROTO_UDP : - sk =udp6_lib_lookup (net, saddr, sport, daddr, dport, - in->ifindex); -if (sk && lookup_type !=NFT_LOOKUP_ANY ) { -int connected = (sk->sk_state ==TCP_ESTABLISHED ); -int wildcard =ipv6_addr_any (&inet6_sk (sk)->rcv_saddr); - -/* NOTE: we return listeners even if bound to -* 0.0.0.0, those are filtered out in -* xt_socket, since xt_TPROXY needs 0 bound -* listeners too */ -if ((lookup_type ==NFT_LOOKUP_ESTABLISHED && (!connected || wildcard)) || - (lookup_type ==NFT_LOOKUP_LISTENER && connected)) { -sock_put (sk); - sk =NULL ; - } - } -break ; -default : -WARN_ON (1 ); - sk =NULL ; - } - -pr_debug ("tproxy socket lookup: proto %u %pI6:%u -> %pI6:%u, lookup type: %d, sock %p\n" , - protocol, saddr,ntohs (sport), daddr,ntohs (dport), lookup_type, sk); - -return sk; -} -#endif - -#endif
net/netfilter/xt_TPROXY.c +159 -1
185 lines not on this page · raw message
net/netfilter/xt_socket.c +61 -5
103 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 8/19 netfilter: nf_conntrack: remove duplicate code in ctnetlink
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
ctnetlink contains copy-paste code from death_by_timeout. In order to avoid changing both places in upcoming event delivery patch, export death_by_timeout functionality and use it in the ctnetlink code.
Based on earlier patch from Pablo Neira.
--- include/net/netfilter/nf_conntrack.h | 3 +-- net/netfilter/nf_conntrack_core.c | 29 ++++++++++++++++------------- net/netfilter/nf_conntrack_netlink.c | 18 +++--------------- 3 files changed, 20 insertions(+), 30 deletions(-)
include/net/netfilter/nf_conntrack.h +1 -2
@@ -181,8 +181,7 @@ __nf_conntrack_find(struct net *net, u16 zone, const struct nf_conntrack_tuple *tuple);extern int nf_conntrack_hash_check_insert (struct nf_conn *ct); -extern void nf_ct_delete_from_lists (struct nf_conn *ct); -extern void nf_ct_dying_timeout (struct nf_conn *ct); +bool nf_ct_delete (struct nf_conn *ct,u32 pid,int report);extern void nf_conntrack_flush_report (struct net *net,u32 portid,int report);
net/netfilter/nf_conntrack_core.c +16 -13
@@ -238,7 +238,7 @@ destroy_conntrack(struct nf_conntrack *nfct)nf_conntrack_free (ct); } -void nf_ct_delete_from_lists (struct nf_conn *ct) +static void nf_ct_delete_from_lists (struct nf_conn *ct) {struct net *net =nf_ct_net (ct);
@@ -253,7 +253,6 @@ void nf_ct_delete_from_lists(struct nf_conn *ct) &net->ct.dying);spin_unlock_bh (&nf_conntrack_lock); } -EXPORT_SYMBOL_GPL (nf_ct_delete_from_lists);static void death_by_event (unsigned long ul_conntrack) {
@@ -275,7 +274,7 @@ static void death_by_event(unsigned long ul_conntrack)nf_ct_put (ct); } -void nf_ct_dying_timeout (struct nf_conn *ct) +static void nf_ct_dying_timeout (struct nf_conn *ct) {struct net *net =nf_ct_net (ct);struct nf_conntrack_ecache *ecache =nf_ct_ecache_find (ct);
@@ -288,27 +287,33 @@ void nf_ct_dying_timeout(struct nf_conn *ct) (prandom_u32 () % net->ct.sysctl_events_retry_timeout);add_timer (&ecache->timeout); } -EXPORT_SYMBOL_GPL (nf_ct_dying_timeout); -static void death_by_timeout (unsigned long ul_conntrack) +bool nf_ct_delete (struct nf_conn *ct,u32 portid,int report) { -struct nf_conn *ct = (void *)ul_conntrack;struct nf_conn_tstamp *tstamp; tstamp =nf_conn_tstamp_find (ct);if (tstamp && tstamp->stop ==0 ) tstamp->stop =ktime_to_ns (ktime_get_real ()); -if (!test_bit (IPS_DYING_BIT , &ct->status) && -unlikely (nf_conntrack_event (IPCT_DESTROY , ct) <0 )) { +if (!nf_ct_is_dying (ct) && +unlikely (nf_conntrack_event_report (IPCT_DESTROY , ct, + portid, report) <0 )) {/* destroy event was not delivered */ nf_ct_delete_from_lists (ct);nf_ct_dying_timeout (ct); -return ; +return false; }set_bit (IPS_DYING_BIT , &ct->status);nf_ct_delete_from_lists (ct);nf_ct_put (ct); +return true; +} +EXPORT_SYMBOL_GPL (nf_ct_delete); + +static void death_by_timeout (unsigned long ul_conntrack) +{ +nf_ct_delete ((struct nf_conn *)ul_conntrack,0 ,0 ); }/*
@@ -643,10 +648,7 @@ static noinline int early_drop(struct net *net, unsigned int hash)return dropped;if (del_timer (&ct->timeout)) { -death_by_timeout ((unsigned long )ct); -/* Check if we indeed killed this entry. Reliable event -delivery may have inserted it into the dying list. */ -if (test_bit (IPS_DYING_BIT , &ct->status)) { +if (nf_ct_delete (ct,0 ,0 )) { dropped =1 ;NF_CT_STAT_INC_ATOMIC (net, early_drop); }
@@ -1253,6 +1255,7 @@ void nf_ct_iterate_cleanup(struct net *net,/* Time to push up daises... */ if (del_timer (&ct->timeout))death_by_timeout ((unsigned long )ct); +/* ... else the timer will get him soon. */ nf_ct_put (ct);
net/netfilter/nf_conntrack_netlink.c +3 -15
@@ -1038,21 +1038,9 @@ ctnetlink_del_conntrack(struct sock *ctnl, struct sk_buff *skb, } } -if (del_timer (&ct->timeout)) { -if (nf_conntrack_event_report (IPCT_DESTROY , ct, -NETLINK_CB (skb).portid, -nlmsg_report (nlh)) <0 ) { -nf_ct_delete_from_lists (ct); -/* we failed to report the event, try later */ -nf_ct_dying_timeout (ct); -nf_ct_put (ct); -return 0 ; - } -/* death_by_timeout would report the event again */ -set_bit (IPS_DYING_BIT , &ct->status); -nf_ct_delete_from_lists (ct); -nf_ct_put (ct); - } +if (del_timer (&ct->timeout)) +nf_ct_delete (ct,NETLINK_CB (skb).portid,nlmsg_report (nlh)); +nf_ct_put (ct);return 0 ;
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 9/19 netfilter: nf_nat: fix locking in nf_nat_seq_adjust()
In reply to Pablo Neira AyusoFrom: Patrick McHardy <[email protected]>
nf_nat_seq_adjust() needs to grab nf_nat_seqofs_lock to protect against concurrent changes to the sequence adjustment data.
--- net/netfilter/nf_nat_helper.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
net/netfilter/nf_nat_helper.c +6 -1
@@ -373,6 +373,7 @@ nf_nat_seq_adjust(struct sk_buff *skb,s16 seqoff, ackoff;struct nf_conn_nat *nat =nfct_nat (ct);struct nf_nat_seq *this_way, *other_way; +int res; dir =CTINFO2DIR (ctinfo);
@@ -383,6 +384,7 @@ nf_nat_seq_adjust(struct sk_buff *skb,return 0 ; tcph = (void *)skb->data + protoff; +spin_lock_bh (&nf_nat_seqofs_lock);if (after (ntohl (tcph->seq), this_way->correction_pos)) seqoff = this_way->offset_after;else
@@ -407,7 +409,10 @@ nf_nat_seq_adjust(struct sk_buff *skb, tcph->seq = newseq; tcph->ack_seq = newack; -return nf_nat_sack_adjust (skb, protoff, tcph, ct, ctinfo); + res =nf_nat_sack_adjust (skb, protoff, tcph, ct, ctinfo); +spin_unlock_bh (&nf_nat_seqofs_lock); + +return res; }/* Setup NAT on this expected conntrack so it follows master. */
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 10/19 netfilter: nf_nat: change sequence number adjustments to 32 bits
In reply to Pablo Neira AyusoFrom: Patrick McHardy <[email protected]>
Using 16 bits is too small, when many adjustments happen the offsets might overflow and break the connection.
--- include/linux/netfilter.h | 2 +- include/net/netfilter/nf_conntrack.h | 2 +- include/net/netfilter/nf_nat.h | 2 +- include/net/netfilter/nf_nat_helper.h | 6 +++--- net/netfilter/nf_conntrack_core.c | 2 +- net/netfilter/nf_conntrack_proto_tcp.c | 4 ++-- net/netfilter/nf_nat_helper.c | 8 ++++---- 7 files changed, 13 insertions(+), 13 deletions(-)
include/linux/netfilter.h +1 -1
@@ -330,7 +330,7 @@ extern struct nfq_ct_hook __rcu *nfq_ct_hook;struct nfq_ct_nat_hook {void (*seq_adjust)(struct sk_buff *skb,struct nf_conn *ct, -u32 ctinfo,int off); +u32 ctinfo,s32 off); };extern struct nfq_ct_nat_hook __rcu *nfq_ct_nat_hook;#else
include/net/netfilter/nf_conntrack.h +1 -1
@@ -234,7 +234,7 @@ static inline bool nf_ct_kill(struct nf_conn *ct) }/* These are for NAT. Icky. */ -extern s16 (*nf_ct_nat_offset)(const struct nf_conn *ct, +extern s32 (*nf_ct_nat_offset)(const struct nf_conn *ct,enum ip_conntrack_dir dir,u32 seq);
include/net/netfilter/nf_nat.h +1 -1
@@ -19,7 +19,7 @@ struct nf_nat_seq {u_int32_t correction_pos;/* sequence number offset before and after last modification */ -int16_t offset_before, offset_after; +int32_t offset_before, offset_after; };#include <linux/list.h>
include/net/netfilter/nf_nat_helper.h +3 -3
@@ -41,7 +41,7 @@ extern int nf_nat_mangle_udp_packet(struct sk_buff *skb,extern void nf_nat_set_seq_adjust (struct nf_conn *ct,enum ip_conntrack_info ctinfo, -__be32 seq,s16 off); +__be32 seq,s32 off); extern int nf_nat_seq_adjust(struct sk_buff *skb, struct nf_conn *ct, enum ip_conntrack_info ctinfo,
@@ -56,11 +56,11 @@ extern int (*nf_nat_seq_adjust_hook)(struct sk_buff *skb,extern void nf_nat_follow_master (struct nf_conn *ct,struct nf_conntrack_expect *this); -extern s16 nf_nat_get_offset (const struct nf_conn *ct, +extern s32 nf_nat_get_offset (const struct nf_conn *ct,enum ip_conntrack_dir dir,u32 seq);extern void nf_nat_tcp_seq_adjust (struct sk_buff *skb,struct nf_conn *ct, -u32 dir,int off); +u32 dir,s32 off);#endif
net/netfilter/nf_conntrack_core.c +1 -1
@@ -1695,7 +1695,7 @@ err_stat:return ret; } -s16 (*nf_ct_nat_offset)(const struct nf_conn *ct, +s32 (*nf_ct_nat_offset)(const struct nf_conn *ct,enum ip_conntrack_dir dir,u32 seq);EXPORT_SYMBOL_GPL (nf_ct_nat_offset);
net/netfilter/nf_conntrack_proto_tcp.c +2 -2
@@ -496,7 +496,7 @@ static void tcp_sack(const struct sk_buff *skb, unsigned int dataoff, }#ifdef CONFIG_NF_NAT_NEEDED -static inline s16 nat_offset (const struct nf_conn *ct, +static inline s32 nat_offset (const struct nf_conn *ct,enum ip_conntrack_dir dir,u32 seq) {
@@ -525,7 +525,7 @@ static bool tcp_in_window(const struct nf_conn *ct,struct ip_ct_tcp_state *receiver = &state->seen[!dir];const struct nf_conntrack_tuple *tuple = &ct->tuplehash[dir].tuple;__u32 seq, ack, sack, end, win, swin; -s16 receiver_offset; +s32 receiver_offset;bool res;/*
net/netfilter/nf_nat_helper.c +4 -4
@@ -68,13 +68,13 @@ adjust_tcp_sequence(u32 seq, }/* Get the offset value, for conntrack */ -s16 nf_nat_get_offset (const struct nf_conn *ct, +s32 nf_nat_get_offset (const struct nf_conn *ct,enum ip_conntrack_dir dir,u32 seq) {struct nf_conn_nat *nat =nfct_nat (ct);struct nf_nat_seq *this_way; -s16 offset; +s32 offset;if (!nat)return 0 ;
@@ -143,7 +143,7 @@ static int enlarge_skb(struct sk_buff *skb, unsigned int extra) }void nf_nat_set_seq_adjust (struct nf_conn *ct,enum ip_conntrack_info ctinfo, -__be32 seq,s16 off) +__be32 seq,s32 off) {if (!off)return ;
@@ -370,7 +370,7 @@ nf_nat_seq_adjust(struct sk_buff *skb,struct tcphdr *tcph;int dir;__be32 newseq, newack; -s16 seqoff, ackoff; +s32 seqoff, ackoff;struct nf_conn_nat *nat =nfct_nat (ct);struct nf_nat_seq *this_way, *other_way;int res;
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 11/19 netfilter: nf_nat: use per-conntrack locking for sequence number adjustments
In reply to Pablo Neira AyusoFrom: Patrick McHardy <[email protected]>
Get rid of the global lock and use per-conntrack locks for protecting the sequencen number adjustment data. Additionally saves one lock/unlock operation for every TCP packet.
--- net/netfilter/nf_nat_helper.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-)
net/netfilter/nf_nat_helper.c +6 -13
@@ -30,8 +30,6 @@pr_debug ("offset_before=%d, offset_after=%d, correction_pos=%u\n" , \ x->offset_before, x->offset_after, x->correction_pos); -static DEFINE_SPINLOCK (nf_nat_seqofs_lock); -/* Setup TCP sequence correction given this change at this sequence */ static inline void adjust_tcp_sequence(u32 seq,
@@ -49,7 +47,7 @@ adjust_tcp_sequence(u32 seq,pr_debug ("adjust_tcp_sequence: Seq_offset before: " );DUMP_OFFSET (this_way); -spin_lock_bh (&nf_nat_seqofs_lock); +spin_lock_bh (&ct->lock);/* SYN adjust. If it's uninitialized, or this is after last * correction, record it: we don't handle more than one
@@ -61,31 +59,26 @@ adjust_tcp_sequence(u32 seq, this_way->offset_before = this_way->offset_after; this_way->offset_after += sizediff; } -spin_unlock_bh (&nf_nat_seqofs_lock); +spin_unlock_bh (&ct->lock);pr_debug ("adjust_tcp_sequence: Seq_offset after: " );DUMP_OFFSET (this_way); } -/* Get the offset value, for conntrack */ +/* Get the offset value, for conntrack. Caller must have the conntrack locked */ s32 nf_nat_get_offset (const struct nf_conn *ct,enum ip_conntrack_dir dir,u32 seq) {struct nf_conn_nat *nat =nfct_nat (ct);struct nf_nat_seq *this_way; -s32 offset;if (!nat)return 0 ; this_way = &nat->seq[dir]; -spin_lock_bh (&nf_nat_seqofs_lock); - offset =after (seq, this_way->correction_pos) +return after (seq, this_way->correction_pos) ? this_way->offset_after : this_way->offset_before; -spin_unlock_bh (&nf_nat_seqofs_lock); - -return offset; }/* Frobs data inside this packet, which is linear. */
@@ -384,7 +377,7 @@ nf_nat_seq_adjust(struct sk_buff *skb,return 0 ; tcph = (void *)skb->data + protoff; -spin_lock_bh (&nf_nat_seqofs_lock); +spin_lock_bh (&ct->lock);if (after (ntohl (tcph->seq), this_way->correction_pos)) seqoff = this_way->offset_after;else
@@ -410,7 +403,7 @@ nf_nat_seq_adjust(struct sk_buff *skb, tcph->ack_seq = newack; res =nf_nat_sack_adjust (skb, protoff, tcph, ct, ctinfo); -spin_unlock_bh (&nf_nat_seqofs_lock); +spin_unlock_bh (&ct->lock);return res; }
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 12/19 netfilter: tproxy: fix build with IP6_NF_IPTABLES=n
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
after commit 93742cf (netfilter: tproxy: remove nf_tproxy_core.h)
CONFIG_IPV6=yCONFIG_IP6_NF_IPTABLES=n
gives us:
net/netfilter/xt_TPROXY.c: In function 'nf_tproxy_get_sock_v6':net/netfilter/xt_TPROXY.c:178:4: error: implicit declaration of function 'inet6_lookup_listener'
--- net/netfilter/xt_TPROXY.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/xt_TPROXY.c +1 -1
@@ -161,7 +161,7 @@ nf_tproxy_get_sock_v4(struct net *net, const u8 protocol,return sk; } -#if IS_ENABLED (CONFIG_IPV6 ) +#ifdef XT_TPROXY_HAVE_IPV6 static inline struct sock * nf_tproxy_get_sock_v6(struct net *net, const u8 protocol, const struct in6_addr *saddr, const struct in6_addr *daddr,
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 13/19 ipvs: fixed spacing at for statements
In reply to Pablo Neira AyusoFrom: Dragos Foianu <[email protected]>
found using checkpatch.pl
--- net/netfilter/ipvs/ip_vs_lblcr.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
net/netfilter/ipvs/ip_vs_lblcr.c +4 -4
@@ -414,7 +414,7 @@ static void ip_vs_lblcr_flush(struct ip_vs_service *svc)spin_lock_bh (&svc->sched_lock); tbl->dead =1 ; -for (i=0 ; i<IP_VS_LBLCR_TAB_SIZE ; i++) { +for (i =0 ; i <IP_VS_LBLCR_TAB_SIZE ; i++) {hlist_for_each_entry_safe (en, next, &tbl->bucket[i], list) {ip_vs_lblcr_free (en); }
@@ -440,7 +440,7 @@ static inline void ip_vs_lblcr_full_check(struct ip_vs_service *svc)struct ip_vs_lblcr_entry *en;struct hlist_node *next; -for (i=0 , j=tbl->rover; i<IP_VS_LBLCR_TAB_SIZE ; i++) { +for (i =0 , j = tbl->rover; i <IP_VS_LBLCR_TAB_SIZE ; i++) { j = (j +1 ) &IP_VS_LBLCR_TAB_MASK ;spin_lock (&svc->sched_lock);
@@ -495,7 +495,7 @@ static void ip_vs_lblcr_check_expire(unsigned long data)if (goal > tbl->max_size/2 ) goal = tbl->max_size/2 ; -for (i=0 , j=tbl->rover; i<IP_VS_LBLCR_TAB_SIZE ; i++) { +for (i =0 , j = tbl->rover; i <IP_VS_LBLCR_TAB_SIZE ; i++) { j = (j +1 ) &IP_VS_LBLCR_TAB_MASK ;spin_lock (&svc->sched_lock);
@@ -536,7 +536,7 @@ static int ip_vs_lblcr_init_svc(struct ip_vs_service *svc)/* * Initialize the hash buckets */ -for (i=0 ; i<IP_VS_LBLCR_TAB_SIZE ; i++) { +for (i =0 ; i <IP_VS_LBLCR_TAB_SIZE ; i++) {INIT_HLIST_HEAD (&tbl->bucket[i]); } tbl->max_size =IP_VS_LBLCR_TAB_SIZE *16 ;
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 14/19 ipvs: ip_vs_sh: ip_vs_sh_get_port: check skb_header_pointer for NULL
In reply to Pablo Neira AyusoFrom: Daniel Borkmann <[email protected]>
skb_header_pointer could return NULL, so check for it as we do it everywhere else in ipvs code. This fixes a coverity warning.
--- net/netfilter/ipvs/ip_vs_sh.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/netfilter/ipvs/ip_vs_sh.c +6 -0
@@ -269,14 +269,20 @@ ip_vs_sh_get_port(const struct sk_buff *skb, struct ip_vs_iphdr *iph)switch (iph->protocol) {case IPPROTO_TCP : th =skb_header_pointer (skb, iph->len,sizeof (_tcph), &_tcph); +if (unlikely (th ==NULL )) +return 0 ; port = th->source;break ;case IPPROTO_UDP : uh =skb_header_pointer (skb, iph->len,sizeof (_udph), &_udph); +if (unlikely (uh ==NULL )) +return 0 ; port = uh->source;break ;case IPPROTO_SCTP : sh =skb_header_pointer (skb, iph->len,sizeof (_sctph), &_sctph); +if (unlikely (sh ==NULL )) +return 0 ; port = sh->source;break ;default :
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 15/19 netfilter: nf_conntrack: don't send destroy events from iterator
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Let nf_ct_delete handle delivery of the DESTROY event.
Based on earlier patch from Pablo Neira.
--- include/net/netfilter/nf_conntrack.h | 4 +++- net/ipv4/netfilter/ipt_MASQUERADE.c | 2 +- net/ipv6/netfilter/ip6t_MASQUERADE.c | 2 +- net/netfilter/nf_conntrack_core.c | 36 ++++------------------------------ net/netfilter/nf_conntrack_proto.c | 4 ++-- net/netfilter/nf_nat_core.c | 6 +++--- 6 files changed, 14 insertions(+), 40 deletions(-)
include/net/netfilter/nf_conntrack.h +3 -1
@@ -248,7 +248,9 @@ extern void nf_ct_untracked_status_or(unsigned long bits);/* Iterate over all conntracks: if iter returns true, it's deleted. */ extern void -nf_ct_iterate_cleanup (struct net *net,int (*iter)(struct nf_conn *i,void *data),void *data); +nf_ct_iterate_cleanup (struct net *net, +int (*iter)(struct nf_conn *i,void *data), +void *data,u32 portid,int report);extern void nf_conntrack_free (struct nf_conn *ct);extern struct nf_conn * nf_conntrack_alloc(struct net *net, u16 zone,
net/ipv4/netfilter/ipt_MASQUERADE.c +1 -1
@@ -118,7 +118,7 @@ static int masq_device_event(struct notifier_block *this,NF_CT_ASSERT (dev->ifindex !=0 );nf_ct_iterate_cleanup (net, device_cmp, - (void *)(long )dev->ifindex); + (void *)(long )dev->ifindex,0 ,0 ); }return NOTIFY_DONE ;
net/ipv6/netfilter/ip6t_MASQUERADE.c +1 -1
@@ -76,7 +76,7 @@ static int masq_device_event(struct notifier_block *this,if (event ==NETDEV_DOWN )nf_ct_iterate_cleanup (net, device_cmp, - (void *)(long )dev->ifindex); + (void *)(long )dev->ifindex,0 ,0 );return NOTIFY_DONE ; }
net/netfilter/nf_conntrack_core.c +4 -32
@@ -1246,7 +1246,7 @@ found:void nf_ct_iterate_cleanup (struct net *net,int (*iter)(struct nf_conn *i,void *data), -void *data) +void *data,u32 portid,int report) {struct nf_conn *ct;unsigned int bucket =0 ;
@@ -1254,7 +1254,7 @@ void nf_ct_iterate_cleanup(struct net *net,while ((ct =get_next_corpse (net, iter, data, &bucket)) !=NULL ) {/* Time to push up daises... */ if (del_timer (&ct->timeout)) -death_by_timeout ((unsigned long )ct); +nf_ct_delete (ct, portid, report);/* ... else the timer will get him soon. */
@@ -1263,30 +1263,6 @@ void nf_ct_iterate_cleanup(struct net *net, }EXPORT_SYMBOL_GPL (nf_ct_iterate_cleanup); -struct __nf_ct_flush_report { -u32 portid; -int report; -}; - -static int kill_report (struct nf_conn *i,void *data) -{ -struct __nf_ct_flush_report *fr = (struct __nf_ct_flush_report *)data; -struct nf_conn_tstamp *tstamp; - - tstamp =nf_conn_tstamp_find (i); -if (tstamp && tstamp->stop ==0 ) - tstamp->stop =ktime_to_ns (ktime_get_real ()); - -/* If we fail to deliver the event, death_by_timeout() will retry */ -if (nf_conntrack_event_report (IPCT_DESTROY , i, - fr->portid, fr->report) <0 ) -return 1 ; - -/* Avoid the delivery of the destroy event in death_by_timeout(). */ -set_bit (IPS_DYING_BIT , &i->status); -return 1 ; -} -static int kill_all (struct nf_conn *i,void *data) {return 1 ;
@@ -1304,11 +1280,7 @@ EXPORT_SYMBOL_GPL(nf_ct_free_hashtable);void nf_conntrack_flush_report (struct net *net,u32 portid,int report) { -struct __nf_ct_flush_report fr = { - .portid = portid, - .report = report, - }; -nf_ct_iterate_cleanup (net, kill_report, &fr); +nf_ct_iterate_cleanup (net, kill_all,NULL , portid, report); }EXPORT_SYMBOL_GPL (nf_conntrack_flush_report);
@@ -1389,7 +1361,7 @@ void nf_conntrack_cleanup_net_list(struct list_head *net_exit_list) i_see_dead_people: busy =0 ;list_for_each_entry (net, net_exit_list, exit_list) { -nf_ct_iterate_cleanup (net, kill_all,NULL ); +nf_ct_iterate_cleanup (net, kill_all,NULL ,0 ,0 );nf_ct_release_dying_list (net);if (atomic_read (&net->ct.count) !=0 ) busy =1 ;
net/netfilter/nf_conntrack_proto.c +2 -2
@@ -281,7 +281,7 @@ void nf_ct_l3proto_pernet_unregister(struct net *net,nf_ct_l3proto_unregister_sysctl (net, proto);/* Remove all contrack entries for this protocol */ -nf_ct_iterate_cleanup (net, kill_l3proto, proto); +nf_ct_iterate_cleanup (net, kill_l3proto, proto,0 ,0 ); }EXPORT_SYMBOL_GPL (nf_ct_l3proto_pernet_unregister);
@@ -476,7 +476,7 @@ void nf_ct_l4proto_pernet_unregister(struct net *net,nf_ct_l4proto_unregister_sysctl (net, pn, l4proto);/* Remove all contrack entries for this protocol */ -nf_ct_iterate_cleanup (net, kill_l4proto, l4proto); +nf_ct_iterate_cleanup (net, kill_l4proto, l4proto,0 ,0 ); }EXPORT_SYMBOL_GPL (nf_ct_l4proto_pernet_unregister);
net/netfilter/nf_nat_core.c +3 -3
@@ -497,7 +497,7 @@ static void nf_nat_l4proto_clean(u8 l3proto, u8 l4proto)rtnl_lock ();for_each_net (net) -nf_ct_iterate_cleanup (net, nf_nat_proto_remove, &clean); +nf_ct_iterate_cleanup (net, nf_nat_proto_remove, &clean,0 ,0 );rtnl_unlock (); }
@@ -511,7 +511,7 @@ static void nf_nat_l3proto_clean(u8 l3proto)rtnl_lock ();for_each_net (net) -nf_ct_iterate_cleanup (net, nf_nat_proto_remove, &clean); +nf_ct_iterate_cleanup (net, nf_nat_proto_remove, &clean,0 ,0 );rtnl_unlock (); }
@@ -749,7 +749,7 @@ static void __net_exit nf_nat_net_exit(struct net *net) {struct nf_nat_proto_clean clean = {}; -nf_ct_iterate_cleanup (net, &nf_nat_proto_remove, &clean); +nf_ct_iterate_cleanup (net, &nf_nat_proto_remove, &clean,0 ,0 );synchronize_rcu ();nf_ct_free_hashtable (net->ct.nat_bysource, net->ct.nat_htable_size); }
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 16/19 netfilter: ctnetlink: refactor ctnetlink_create_expect
In reply to Pablo Neira AyusoThis patch refactors ctnetlink_create_expect by spliting it in two chunks. As a result, we have a new function ctnetlink_alloc_expect to allocate and to setup the expectation from ctnetlink.
--- net/netfilter/nf_conntrack_netlink.c | 156 +++++++++++++++++++--------------- 1 file changed, 87 insertions(+), 69 deletions(-)
net/netfilter/nf_conntrack_netlink.c +87 -69
@@ -2735,76 +2735,26 @@ ctnetlink_parse_expect_nat(const struct nlattr *attr,#endif } -static int -ctnetlink_create_expect (struct net *net,u16 zone, -const struct nlattr *const cda[], -u_int8_t u3, -u32 portid,int report) +static struct nf_conntrack_expect * +ctnetlink_alloc_expect (const struct nlattr *const cda[],struct nf_conn *ct, +struct nf_conntrack_helper *helper, +struct nf_conntrack_tuple *tuple, +struct nf_conntrack_tuple *mask) { -struct nf_conntrack_tuple tuple, mask, master_tuple; -struct nf_conntrack_tuple_hash *h =NULL ; +u_int32_t class =0 ;struct nf_conntrack_expect *exp; -struct nf_conn *ct;struct nf_conn_help *help; -struct nf_conntrack_helper *helper =NULL ; -u_int32_t class =0 ; -int err =0 ; - -/* caller guarantees that those three CTA_EXPECT_* exist */ - err =ctnetlink_parse_tuple (cda, &tuple,CTA_EXPECT_TUPLE , u3); -if (err <0 ) -return err; - err =ctnetlink_parse_tuple (cda, &mask,CTA_EXPECT_MASK , u3); -if (err <0 ) -return err; - err =ctnetlink_parse_tuple (cda, &master_tuple,CTA_EXPECT_MASTER , u3); -if (err <0 ) -return err; - -/* Look for master conntrack of this expectation */ - h =nf_conntrack_find_get (net, zone, &master_tuple); -if (!h) -return -ENOENT ; - ct =nf_ct_tuplehash_to_ctrack (h); - -/* Look for helper of this expectation */ -if (cda[CTA_EXPECT_HELP_NAME ]) { -const char *helpname =nla_data (cda[CTA_EXPECT_HELP_NAME ]); - - helper =__nf_conntrack_helper_find (helpname,nf_ct_l3num (ct), -nf_ct_protonum (ct)); -if (helper ==NULL ) { -#ifdef CONFIG_MODULES -if (request_module ("nfct-helper-%s" , helpname) <0 ) { - err = -EOPNOTSUPP ; - goto out; - } - - helper =__nf_conntrack_helper_find (helpname, -nf_ct_l3num (ct), -nf_ct_protonum (ct)); -if (helper) { - err = -EAGAIN ; - goto out; - } -#endif - err = -EOPNOTSUPP ; - goto out; - } - } +int err;if (cda[CTA_EXPECT_CLASS ] && helper) { class =ntohl (nla_get_be32 (cda[CTA_EXPECT_CLASS ])); -if (class > helper->expect_class_max) { - err = -EINVAL ; - goto out; - } +if (class > helper->expect_class_max) +return ERR_PTR (-EINVAL ); } exp =nf_ct_expect_alloc (ct); -if (!exp) { - err = -ENOMEM ; - goto out; - } +if (!exp) +return ERR_PTR (-ENOMEM ); + help =nfct_help (ct);if (!help) {if (!cda[CTA_EXPECT_TIMEOUT ]) {
@@ -2842,21 +2792,89 @@ ctnetlink_create_expect(struct net *net, u16 zone, exp->class = class; exp->master = ct; exp->helper = helper; -memcpy (&exp->tuple, &tuple,sizeof (struct nf_conntrack_tuple )); -memcpy (&exp->mask.src.u3, &mask.src.u3,sizeof (exp->mask.src.u3)); - exp->mask.src.u.all = mask.src.u.all; + exp->tuple = *tuple; + exp->mask.src.u3 = mask->src.u3; + exp->mask.src.u.all = mask->src.u.all;if (cda[CTA_EXPECT_NAT ]) { err =ctnetlink_parse_expect_nat (cda[CTA_EXPECT_NAT ], - exp, u3); + exp,nf_ct_l3num (ct));if (err <0 ) goto err_out; } - err =nf_ct_expect_related_report (exp, portid, report); +return exp; err_out:nf_ct_expect_put (exp); -out: -nf_ct_put (nf_ct_tuplehash_to_ctrack (h)); +return ERR_PTR (err); +} + +static int +ctnetlink_create_expect (struct net *net,u16 zone, +const struct nlattr *const cda[], +u_int8_t u3,u32 portid,int report) +{ +struct nf_conntrack_tuple tuple, mask, master_tuple; +struct nf_conntrack_tuple_hash *h =NULL ; +struct nf_conntrack_helper *helper =NULL ; +struct nf_conntrack_expect *exp; +struct nf_conn *ct; +int err; + +/* caller guarantees that those three CTA_EXPECT_* exist */ + err =ctnetlink_parse_tuple (cda, &tuple,CTA_EXPECT_TUPLE , u3); +if (err <0 ) +return err; + err =ctnetlink_parse_tuple (cda, &mask,CTA_EXPECT_MASK , u3); +if (err <0 ) +return err; + err =ctnetlink_parse_tuple (cda, &master_tuple,CTA_EXPECT_MASTER , u3); +if (err <0 ) +return err; + +/* Look for master conntrack of this expectation */ + h =nf_conntrack_find_get (net, zone, &master_tuple); +if (!h) +return -ENOENT ; + ct =nf_ct_tuplehash_to_ctrack (h); + +if (cda[CTA_EXPECT_HELP_NAME ]) { +const char *helpname =nla_data (cda[CTA_EXPECT_HELP_NAME ]); + + helper =__nf_conntrack_helper_find (helpname, u3, +nf_ct_protonum (ct)); +if (helper ==NULL ) { +#ifdef CONFIG_MODULES +if (request_module ("nfct-helper-%s" , helpname) <0 ) { + err = -EOPNOTSUPP ; + goto err_ct; + } + helper =__nf_conntrack_helper_find (helpname, u3, +nf_ct_protonum (ct)); +if (helper) { + err = -EAGAIN ; + goto err_ct; + } +#endif + err = -EOPNOTSUPP ; + goto err_ct; + } + } + + exp =ctnetlink_alloc_expect (cda, ct, helper, &tuple, &mask); +if (IS_ERR (exp)) { + err =PTR_ERR (exp); + goto err_ct; + } + + err =nf_ct_expect_related_report (exp, portid, report); +if (err <0 ) + goto err_exp; + +return 0 ; +err_exp: +nf_ct_expect_put (exp); +err_ct: +nf_ct_put (ct);return err; }
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 17/19 netfilter: nfnetlink_queue: allow to attach expectations to conntracks
In reply to Pablo Neira AyusoThis patch adds the capability to attach expectations via nfnetlink_queue. This is required by conntrack helpers that trigger expectations based on the first packet seen like the TFTP and the DHCPv6 user-space helpers.
--- include/linux/netfilter.h | 2 + include/net/netfilter/nfnetlink_queue.h | 8 ++ include/uapi/linux/netfilter/nfnetlink_queue.h | 1 + net/netfilter/nf_conntrack_netlink.c | 95 ++++++++++++++++++++---- net/netfilter/nfnetlink_queue_core.c | 9 ++- net/netfilter/nfnetlink_queue_ct.c | 15 ++++ 6 files changed, 114 insertions(+), 16 deletions(-)
include/linux/netfilter.h +2 -0
@@ -325,6 +325,8 @@ struct nfq_ct_hook {size_t (*build_size)(const struct nf_conn *ct);int (*build)(struct sk_buff *skb,struct nf_conn *ct);int (*parse)(const struct nlattr *attr,struct nf_conn *ct); +int (*attach_expect)(const struct nlattr *attr,struct nf_conn *ct, +u32 portid,u32 report); };extern struct nfq_ct_hook __rcu *nfq_ct_hook;
include/net/netfilter/nfnetlink_queue.h +8 -0
@@ -15,6 +15,8 @@ int nfqnl_ct_put(struct sk_buff *skb, struct nf_conn *ct, enum ip_conntrack_info ctinfo);void nfqnl_ct_seq_adjust (struct sk_buff *skb,struct nf_conn *ct,enum ip_conntrack_info ctinfo,int diff); +int nfqnl_attach_expect (struct nf_conn *ct,const struct nlattr *attr, +u32 portid,u32 report);#else inline struct nf_conn *nfqnl_ct_get (struct sk_buff *entskb,size_t *size,enum ip_conntrack_info *ctinfo)
@@ -39,5 +41,11 @@ inline void nfqnl_ct_seq_adjust(struct sk_buff *skb, struct nf_conn *ct, enum ip_conntrack_info ctinfo, int diff) { } + +inline int nfqnl_attach_expect (struct nf_conn *ct,const struct nlattr *attr, +u32 portid,u32 report) +{ +return 0 ; +}#endif /* NF_CONNTRACK */ #endif
include/uapi/linux/netfilter/nfnetlink_queue.h +1 -0
@@ -46,6 +46,7 @@ enum nfqnl_attr_type {NFQA_CT_INFO ,/* enum ip_conntrack_info */ NFQA_CAP_LEN ,/* __u32 length of captured packet */ NFQA_SKB_INFO ,/* __u32 skb meta information */ +NFQA_EXP ,/* nf_conntrack_netlink.h */ __NFQA_MAX };
net/netfilter/nf_conntrack_netlink.c +80 -15
117 lines not on this page · raw message
net/netfilter/nfnetlink_queue_core.c +8 -1
@@ -859,6 +859,7 @@ static const struct nla_policy nfqa_verdict_policy[NFQA_MAX+1] = { [NFQA_MARK] = { .type = NLA_U32 }, [NFQA_PAYLOAD] = { .type = NLA_UNSPEC }, [NFQA_CT] = { .type = NLA_UNSPEC }, + [NFQA_EXP] = { .type = NLA_UNSPEC }, };static const struct nla_policy nfqa_verdict_batch_policy[NFQA_MAX +1 ] = {
@@ -987,8 +988,14 @@ nfqnl_recv_verdict(struct sock *ctnl, struct sk_buff *skb,if (entry ==NULL )return -ENOENT ; -if (nfqa[NFQA_CT ]) +if (nfqa[NFQA_CT ]) { ct =nfqnl_ct_parse (entry->skb, nfqa[NFQA_CT ], &ctinfo); +if (ct && nfqa[NFQA_EXP ]) { +nfqnl_attach_expect (ct, nfqa[NFQA_EXP ], +NETLINK_CB (skb).portid, +nlmsg_report (nlh)); + } + }if (nfqa[NFQA_PAYLOAD ]) {u16 payload_len =nla_len (nfqa[NFQA_PAYLOAD ]);
net/netfilter/nfnetlink_queue_ct.c +15 -0
@@ -96,3 +96,18 @@ void nfqnl_ct_seq_adjust(struct sk_buff *skb, struct nf_conn *ct,if ((ct->status &IPS_NAT_MASK ) && diff) nfq_nat_ct->seq_adjust (skb, ct, ctinfo, diff); } + +int nfqnl_attach_expect (struct nf_conn *ct,const struct nlattr *attr, +u32 portid,u32 report) +{ +struct nfq_ct_hook *nfq_ct; + +if (nf_ct_is_untracked (ct)) +return 0 ; + + nfq_ct =rcu_dereference (nfq_ct_hook); +if (nfq_ct ==NULL ) +return -EOPNOTSUPP ; + +return nfq_ct->attach_expect (attr, ct, portid, report); +}
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 18/19 netfilter: export xt_rpfilter.h to userland
In reply to Pablo Neira AyusoFrom: Nicolas Dichtel <[email protected]>
This file contains the API for the match "rpfilter", hence it should be exported to userland.
---
include/uapi/linux/netfilter/Kbuild | 1 +
include/{ => uapi}/linux/netfilter/xt_rpfilter.h | 0
2 files changed, 1 insertion(+)
rename include/{ => uapi}/linux/netfilter/xt_rpfilter.h (100%)include/uapi/linux/netfilter/Kbuild +1 -0
@@ -68,6 +68,7 @@ header-y += xt_quota.h header-y += xt_rateest.h header-y += xt_realm.h header-y += xt_recent.h +header-y += xt_rpfilter.h header-y += xt_sctp.h header-y += xt_set.h header-y += xt_socket.h
include/uapi/linux/netfilter/xt_rpfilter.h renamed from include/linux/netfilter/xt_rpfilter.h +0 -0
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 19/19 netfilter: export xt_HMARK.h to userland
In reply to Pablo Neira AyusoFrom: Nicolas Dichtel <[email protected]>
This file contains the API for the target "HMARK", hence it should be exported to userland.
---
include/uapi/linux/netfilter/Kbuild | 1 +
include/{ => uapi}/linux/netfilter/xt_HMARK.h | 0
2 files changed, 1 insertion(+)
rename include/{ => uapi}/linux/netfilter/xt_HMARK.h (100%)include/uapi/linux/netfilter/Kbuild +1 -0
@@ -22,6 +22,7 @@ header-y += xt_CONNMARK.h header-y += xt_CONNSECMARK.h header-y += xt_CT.h header-y += xt_DSCP.h +header-y += xt_HMARK.h header-y += xt_IDLETIMER.h header-y += xt_LED.h header-y += xt_LOG.h
include/uapi/linux/netfilter/xt_HMARK.h renamed from include/linux/netfilter/xt_HMARK.h +0 -0
Signature · 1 line
1.7.10.4
David Miller
maintainerFrom: Pablo Neira Ayuso <[email protected]>
Date: Tue, 20 Aug 2013 12:54:32 +0200
Quoted 2 lines
The following batch contains Netfilter/IPVS updates for your net-next tree. More specifically, they are:
Pulled, but I had to resolve a conflict in the TCP conntrack code wrt. changing the type of a local variable to "s32" in net which I merged into net-next the other day.
Look at the merge commit I pushed out, you'll see :-)