All of lore.kernel.org
 help / color / mirror / Atom feed
From: Florian Westphal <fw@strlen.de>
To: <netfilter-devel@vger.kernel.org>
Cc: Florian Westphal <fw@strlen.de>
Subject: [PATCH nf-next 3/4] netfilter: reduce hook array sizes to what is needed
Date: Mon, 13 Nov 2017 17:41:06 +0100	[thread overview]
Message-ID: <20171113164107.11259-4-fw@strlen.de> (raw)
In-Reply-To: <20171113164107.11259-1-fw@strlen.de>

Not all families share the same hook count.
Previous patch added build-time assert so reduce to what is
needed.

Can't use the corresponding ARP, BRIDGE, DECNET defines
because they sit in uapi headers and including them causes
various build failures.

ARP BUILD_BUG_ON test now needs a 'builtin_constant_p' guard.
A few call sites call nf_hook() with a non-compile-time-value
in POST_ROUTING (which doesn't exist in ARP family) with.

In this case the BUILD_BUG_ON will trigger, so elide them there.

struct net before:
/* size: 4672, cachelines: 73, members: 46 */
after:
/* size: 4544, cachelines: 71, members: 46 */

Signed-off-by: Florian Westphal <fw@strlen.de>
---
 include/linux/netfilter.h     |  2 +-
 include/net/netns/netfilter.h | 10 +++++-----
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
index 2e9896d42f96..48a2f0f93033 100644
--- a/include/linux/netfilter.h
+++ b/include/linux/netfilter.h
@@ -205,7 +205,7 @@ static inline int nf_hook(u_int8_t pf, unsigned int hook, struct net *net,
 		hook_head = rcu_dereference(net->nf.hooks_ipv6[hook]);
 		break;
 	case NFPROTO_ARP:
-		BUILD_BUG_ON(hook >= ARRAY_SIZE(net->nf.hooks_arp));
+		BUILD_BUG_ON(__builtin_constant_p(pf) && hook >= ARRAY_SIZE(net->nf.hooks_arp));
 		hook_head = rcu_dereference(net->nf.hooks_arp[hook]);
 		break;
 	case NFPROTO_BRIDGE:
diff --git a/include/net/netns/netfilter.h b/include/net/netns/netfilter.h
index b39c563c2fce..96b20b872353 100644
--- a/include/net/netns/netfilter.h
+++ b/include/net/netns/netfilter.h
@@ -17,11 +17,11 @@ struct netns_nf {
 #ifdef CONFIG_SYSCTL
 	struct ctl_table_header *nf_log_dir_header;
 #endif
-	struct nf_hook_entries __rcu *hooks_ipv4[NF_MAX_HOOKS];
-	struct nf_hook_entries __rcu *hooks_ipv6[NF_MAX_HOOKS];
-	struct nf_hook_entries __rcu *hooks_arp[NF_MAX_HOOKS];
-	struct nf_hook_entries __rcu *hooks_bridge[NF_MAX_HOOKS];
-	struct nf_hook_entries __rcu *hooks_decnet[NF_MAX_HOOKS];
+	struct nf_hook_entries __rcu *hooks_ipv4[NF_INET_NUMHOOKS];
+	struct nf_hook_entries __rcu *hooks_ipv6[NF_INET_NUMHOOKS];
+	struct nf_hook_entries __rcu *hooks_arp[3];
+	struct nf_hook_entries __rcu *hooks_bridge[6];
+	struct nf_hook_entries __rcu *hooks_decnet[7];
 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV4)
 	bool			defrag_ipv4;
 #endif
-- 
2.13.6


  parent reply	other threads:[~2017-11-13 16:41 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-13 16:41 [PATCH nf-next 0/4] netfilter: reduce hook sizes in struct net Florian Westphal
2017-11-13 16:41 ` [PATCH nf-next 1/4] netfilter: reduce size of hook entry point locations Florian Westphal
2017-11-13 16:41 ` [PATCH nf-next 2/4] netfilter: add BUILD_BUG_ON asserts for hook array sizes Florian Westphal
2017-11-22 12:20   ` Pablo Neira Ayuso
2017-11-22 12:44     ` Florian Westphal
2017-11-22 12:54       ` Pablo Neira Ayuso
2017-11-13 16:41 ` Florian Westphal [this message]
2017-11-13 16:41 ` [PATCH nf-next 4/4] netfilter: add ifdefs to avoid memory waste if family is not supported Florian Westphal
2017-11-13 16:53 ` [PATCH nf-next 0/4] netfilter: reduce hook sizes in struct net Pablo Neira Ayuso

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=20171113164107.11259-4-fw@strlen.de \
    --to=fw@strlen.de \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.