1 From 2a95183a5e0375df756efb2ca37602d71e8455f9 Mon Sep 17 00:00:00 2001
2 From: Florian Westphal <fw@strlen.de>
3 Date: Thu, 7 Dec 2017 16:28:26 +0100
4 Subject: [PATCH 08/11] netfilter: don't allocate space for arp/bridge hooks
7 no need to define hook points if the family isn't supported.
8 Because we need these hooks for either nftables, arp/ebtables
9 or the 'call-iptables' hack we have in the bridge layer add two
10 new dependencies, NETFILTER_FAMILY_{ARP,BRIDGE}, and have the
13 Signed-off-by: Florian Westphal <fw@strlen.de>
14 Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
16 include/linux/netfilter.h | 4 ++++
17 include/net/netns/netfilter.h | 4 ++++
19 net/bridge/netfilter/Kconfig | 2 ++
20 net/ipv4/netfilter/Kconfig | 2 ++
21 net/netfilter/Kconfig | 6 ++++++
22 net/netfilter/core.c | 8 ++++++++
23 net/netfilter/nf_queue.c | 2 ++
24 8 files changed, 29 insertions(+)
26 --- a/include/linux/netfilter.h
27 +++ b/include/linux/netfilter.h
28 @@ -214,10 +214,14 @@ static inline int nf_hook(u_int8_t pf, u
29 hook_head = rcu_dereference(net->nf.hooks_ipv6[hook]);
32 +#ifdef CONFIG_NETFILTER_FAMILY_ARP
33 hook_head = rcu_dereference(net->nf.hooks_arp[hook]);
37 +#ifdef CONFIG_NETFILTER_FAMILY_BRIDGE
38 hook_head = rcu_dereference(net->nf.hooks_bridge[hook]);
41 #if IS_ENABLED(CONFIG_DECNET)
43 --- a/include/net/netns/netfilter.h
44 +++ b/include/net/netns/netfilter.h
45 @@ -19,8 +19,12 @@ struct netns_nf {
47 struct nf_hook_entries __rcu *hooks_ipv4[NF_INET_NUMHOOKS];
48 struct nf_hook_entries __rcu *hooks_ipv6[NF_INET_NUMHOOKS];
49 +#ifdef CONFIG_NETFILTER_FAMILY_ARP
50 struct nf_hook_entries __rcu *hooks_arp[NF_ARP_NUMHOOKS];
52 +#ifdef CONFIG_NETFILTER_FAMILY_BRIDGE
53 struct nf_hook_entries __rcu *hooks_bridge[NF_INET_NUMHOOKS];
55 #if IS_ENABLED(CONFIG_DECNET)
56 struct nf_hook_entries __rcu *hooks_decnet[NF_DN_NUMHOOKS];
60 @@ -182,6 +182,7 @@ config BRIDGE_NETFILTER
62 depends on NETFILTER && INET
63 depends on NETFILTER_ADVANCED
64 + select NETFILTER_FAMILY_BRIDGE
67 Enabling this option will let arptables resp. iptables see bridged
68 --- a/net/bridge/netfilter/Kconfig
69 +++ b/net/bridge/netfilter/Kconfig
72 menuconfig NF_TABLES_BRIDGE
73 depends on BRIDGE && NETFILTER && NF_TABLES
74 + select NETFILTER_FAMILY_BRIDGE
75 tristate "Ethernet Bridge nf_tables support"
78 @@ -29,6 +30,7 @@ endif # NF_TABLES_BRIDGE
79 menuconfig BRIDGE_NF_EBTABLES
80 tristate "Ethernet Bridge tables (ebtables) support"
81 depends on BRIDGE && NETFILTER && NETFILTER_XTABLES
82 + select NETFILTER_FAMILY_BRIDGE
84 ebtables is a general, extensible frame/packet identification
85 framework. Say 'Y' or 'M' here if you want to do Ethernet
86 --- a/net/ipv4/netfilter/Kconfig
87 +++ b/net/ipv4/netfilter/Kconfig
88 @@ -72,6 +72,7 @@ endif # NF_TABLES_IPV4
91 tristate "ARP nf_tables support"
92 + select NETFILTER_FAMILY_ARP
94 This option enables the ARP support for nf_tables.
96 @@ -392,6 +393,7 @@ endif # IP_NF_IPTABLES
97 config IP_NF_ARPTABLES
98 tristate "ARP tables support"
99 select NETFILTER_XTABLES
100 + select NETFILTER_FAMILY_ARP
101 depends on NETFILTER_ADVANCED
103 arptables is a general, extensible packet identification framework.
104 --- a/net/netfilter/Kconfig
105 +++ b/net/netfilter/Kconfig
106 @@ -12,6 +12,12 @@ config NETFILTER_INGRESS
107 config NETFILTER_NETLINK
110 +config NETFILTER_FAMILY_BRIDGE
113 +config NETFILTER_FAMILY_ARP
116 config NETFILTER_NETLINK_ACCT
117 tristate "Netfilter NFACCT over NFNETLINK interface"
118 depends on NETFILTER_ADVANCED
119 --- a/net/netfilter/core.c
120 +++ b/net/netfilter/core.c
121 @@ -267,14 +267,18 @@ static struct nf_hook_entries __rcu **nf
125 +#ifdef CONFIG_NETFILTER_FAMILY_ARP
127 if (WARN_ON_ONCE(ARRAY_SIZE(net->nf.hooks_arp) <= reg->hooknum))
129 return net->nf.hooks_arp + reg->hooknum;
131 +#ifdef CONFIG_NETFILTER_FAMILY_BRIDGE
133 if (WARN_ON_ONCE(ARRAY_SIZE(net->nf.hooks_bridge) <= reg->hooknum))
135 return net->nf.hooks_bridge + reg->hooknum;
138 if (WARN_ON_ONCE(ARRAY_SIZE(net->nf.hooks_ipv4) <= reg->hooknum))
140 @@ -573,8 +577,12 @@ static int __net_init netfilter_net_init
142 __netfilter_net_init(net->nf.hooks_ipv4, ARRAY_SIZE(net->nf.hooks_ipv4));
143 __netfilter_net_init(net->nf.hooks_ipv6, ARRAY_SIZE(net->nf.hooks_ipv6));
144 +#ifdef CONFIG_NETFILTER_FAMILY_ARP
145 __netfilter_net_init(net->nf.hooks_arp, ARRAY_SIZE(net->nf.hooks_arp));
147 +#ifdef CONFIG_NETFILTER_FAMILY_BRIDGE
148 __netfilter_net_init(net->nf.hooks_bridge, ARRAY_SIZE(net->nf.hooks_bridge));
150 #if IS_ENABLED(CONFIG_DECNET)
151 __netfilter_net_init(net->nf.hooks_decnet, ARRAY_SIZE(net->nf.hooks_decnet));
153 --- a/net/netfilter/nf_queue.c
154 +++ b/net/netfilter/nf_queue.c
155 @@ -205,8 +205,10 @@ repeat:
156 static struct nf_hook_entries *nf_hook_entries_head(const struct net *net, u8 pf, u8 hooknum)
159 +#ifdef CONFIG_NETFILTER_FAMILY_BRIDGE
161 return rcu_dereference(net->nf.hooks_bridge[hooknum]);
164 return rcu_dereference(net->nf.hooks_ipv4[hooknum]);