1 From ef57170bbfdd6958281011332b1fd237712f69f0 Mon Sep 17 00:00:00 2001
2 From: Florian Westphal <fw@strlen.de>
3 Date: Thu, 7 Dec 2017 16:28:24 +0100
4 Subject: [PATCH 06/11] netfilter: reduce hook array sizes to what is needed
6 Not all families share the same hook count, adjust sizes to what is
10 /* size: 6592, cachelines: 103, members: 46 */
12 /* size: 5952, cachelines: 93, members: 46 */
14 Signed-off-by: Florian Westphal <fw@strlen.de>
15 Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
17 include/net/netns/netfilter.h | 10 +++++-----
18 net/netfilter/core.c | 24 +++++++++++++++++-------
19 2 files changed, 22 insertions(+), 12 deletions(-)
21 --- a/include/net/netns/netfilter.h
22 +++ b/include/net/netns/netfilter.h
23 @@ -17,11 +17,11 @@ struct netns_nf {
25 struct ctl_table_header *nf_log_dir_header;
27 - struct nf_hook_entries __rcu *hooks_ipv4[NF_MAX_HOOKS];
28 - struct nf_hook_entries __rcu *hooks_ipv6[NF_MAX_HOOKS];
29 - struct nf_hook_entries __rcu *hooks_arp[NF_MAX_HOOKS];
30 - struct nf_hook_entries __rcu *hooks_bridge[NF_MAX_HOOKS];
31 - struct nf_hook_entries __rcu *hooks_decnet[NF_MAX_HOOKS];
32 + struct nf_hook_entries __rcu *hooks_ipv4[NF_INET_NUMHOOKS];
33 + struct nf_hook_entries __rcu *hooks_ipv6[NF_INET_NUMHOOKS];
34 + struct nf_hook_entries __rcu *hooks_arp[NF_ARP_NUMHOOKS];
35 + struct nf_hook_entries __rcu *hooks_bridge[NF_INET_NUMHOOKS];
36 + struct nf_hook_entries __rcu *hooks_decnet[NF_DN_NUMHOOKS];
37 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV4)
40 --- a/net/netfilter/core.c
41 +++ b/net/netfilter/core.c
42 @@ -268,14 +268,24 @@ static struct nf_hook_entries __rcu **nf
46 + if (WARN_ON_ONCE(ARRAY_SIZE(net->nf.hooks_arp) <= reg->hooknum))
48 return net->nf.hooks_arp + reg->hooknum;
50 + if (WARN_ON_ONCE(ARRAY_SIZE(net->nf.hooks_bridge) <= reg->hooknum))
52 return net->nf.hooks_bridge + reg->hooknum;
54 + if (WARN_ON_ONCE(ARRAY_SIZE(net->nf.hooks_ipv4) <= reg->hooknum))
56 return net->nf.hooks_ipv4 + reg->hooknum;
58 + if (WARN_ON_ONCE(ARRAY_SIZE(net->nf.hooks_ipv6) <= reg->hooknum))
60 return net->nf.hooks_ipv6 + reg->hooknum;
62 + if (WARN_ON_ONCE(ARRAY_SIZE(net->nf.hooks_decnet) <= reg->hooknum))
64 return net->nf.hooks_decnet + reg->hooknum;
67 @@ -549,21 +559,21 @@ void (*nf_nat_decode_session_hook)(struc
68 EXPORT_SYMBOL(nf_nat_decode_session_hook);
71 -static void __net_init __netfilter_net_init(struct nf_hook_entries *e[NF_MAX_HOOKS])
72 +static void __net_init __netfilter_net_init(struct nf_hook_entries **e, int max)
76 - for (h = 0; h < NF_MAX_HOOKS; h++)
77 + for (h = 0; h < max; h++)
78 RCU_INIT_POINTER(e[h], NULL);
81 static int __net_init netfilter_net_init(struct net *net)
83 - __netfilter_net_init(net->nf.hooks_ipv4);
84 - __netfilter_net_init(net->nf.hooks_ipv6);
85 - __netfilter_net_init(net->nf.hooks_arp);
86 - __netfilter_net_init(net->nf.hooks_bridge);
87 - __netfilter_net_init(net->nf.hooks_decnet);
88 + __netfilter_net_init(net->nf.hooks_ipv4, ARRAY_SIZE(net->nf.hooks_ipv4));
89 + __netfilter_net_init(net->nf.hooks_ipv6, ARRAY_SIZE(net->nf.hooks_ipv6));
90 + __netfilter_net_init(net->nf.hooks_arp, ARRAY_SIZE(net->nf.hooks_arp));
91 + __netfilter_net_init(net->nf.hooks_bridge, ARRAY_SIZE(net->nf.hooks_bridge));
92 + __netfilter_net_init(net->nf.hooks_decnet, ARRAY_SIZE(net->nf.hooks_decnet));
95 net->nf.proc_netfilter = proc_net_mkdir(net, "netfilter",