netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: davem@davemloft.net, netdev@vger.kernel.org
Subject: [PATCH 09/10] netfilter: don't call hooks unless needed
Date: Tue,  8 Mar 2016 11:00:49 +0100	[thread overview]
Message-ID: <1457431250-3086-10-git-send-email-pablo@netfilter.org> (raw)
In-Reply-To: <1457431250-3086-1-git-send-email-pablo@netfilter.org>

From: Florian Westphal <fw@strlen.de>

With the previous patches in place, a netns nf_hook_list might be empty,
even if e.g. init_net performs filtering.

Thus change nf_hook_thresh to check the hook_list as well before
initializing hook_state and calling nf_hook_slow().

We still make use of static keys; if no netfilter modules are loaded
list is guaranteed to be empty.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 include/linux/netfilter.h | 29 +++++++++++------------------
 1 file changed, 11 insertions(+), 18 deletions(-)

diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
index 0ad5567..9230f9a 100644
--- a/include/linux/netfilter.h
+++ b/include/linux/netfilter.h
@@ -141,22 +141,6 @@ void nf_unregister_sockopt(struct nf_sockopt_ops *reg);
 
 #ifdef HAVE_JUMP_LABEL
 extern struct static_key nf_hooks_needed[NFPROTO_NUMPROTO][NF_MAX_HOOKS];
-
-static inline bool nf_hook_list_active(struct list_head *hook_list,
-				       u_int8_t pf, unsigned int hook)
-{
-	if (__builtin_constant_p(pf) &&
-	    __builtin_constant_p(hook))
-		return static_key_false(&nf_hooks_needed[pf][hook]);
-
-	return !list_empty(hook_list);
-}
-#else
-static inline bool nf_hook_list_active(struct list_head *hook_list,
-				       u_int8_t pf, unsigned int hook)
-{
-	return !list_empty(hook_list);
-}
 #endif
 
 int nf_hook_slow(struct sk_buff *skb, struct nf_hook_state *state);
@@ -177,9 +161,18 @@ static inline int nf_hook_thresh(u_int8_t pf, unsigned int hook,
 				 int (*okfn)(struct net *, struct sock *, struct sk_buff *),
 				 int thresh)
 {
-	struct list_head *hook_list = &net->nf.hooks[pf][hook];
+	struct list_head *hook_list;
+
+#ifdef HAVE_JUMP_LABEL
+	if (__builtin_constant_p(pf) &&
+	    __builtin_constant_p(hook) &&
+	    !static_key_false(&nf_hooks_needed[pf][hook]))
+		return 1;
+#endif
+
+	hook_list = &net->nf.hooks[pf][hook];
 
-	if (nf_hook_list_active(hook_list, pf, hook)) {
+	if (!list_empty(hook_list)) {
 		struct nf_hook_state state;
 
 		nf_hook_state_init(&state, hook_list, hook, thresh,
-- 
2.1.4


  parent reply	other threads:[~2016-03-08 10:01 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-08 10:00 [PATCH 00/10] Netfilter/IPVS updates for net-next Pablo Neira Ayuso
2016-03-08 10:00 ` [PATCH 01/10] netfilter: ipvs: Remove noisy debug print from ip_vs_del_service Pablo Neira Ayuso
2016-03-08 10:00 ` [PATCH 02/10] netfilter: ipvs: avoid unused variable warnings Pablo Neira Ayuso
2016-03-08 10:00 ` [PATCH 03/10] netfilter: meta: add PRANDOM support Pablo Neira Ayuso
2016-03-08 10:00 ` [PATCH 04/10] netfilter: xt_osf: remove unused variable Pablo Neira Ayuso
2016-03-08 10:00 ` [PATCH 05/10] netfilter: nf_defrag_ipv4: Drop redundant ip_send_check() Pablo Neira Ayuso
2016-03-08 10:00 ` [PATCH 06/10] netfilter: xtables: prepare for on-demand hook register Pablo Neira Ayuso
2016-03-08 10:00 ` [PATCH 07/10] netfilter: xtables: don't hook tables by default Pablo Neira Ayuso
2016-03-08 10:00 ` [PATCH 08/10] netfilter: bridge: register hooks only when bridge interface is added Pablo Neira Ayuso
2016-03-08 10:00 ` Pablo Neira Ayuso [this message]
2016-03-08 10:00 ` [PATCH 10/10] netfilter: nft_masq: support port range Pablo Neira Ayuso
2016-03-08 19:28 ` [PATCH 00/10] Netfilter/IPVS updates for net-next David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1457431250-3086-10-git-send-email-pablo@netfilter.org \
    --to=pablo@netfilter.org \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).