]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - net/bridge/br_netfilter.c
netfilter: Use nf_hook_state in nf_queue_entry.
[mirror_ubuntu-bionic-kernel.git] / net / bridge / br_netfilter.c
CommitLineData
1da177e4
LT
1/*
2 * Handle firewalling
3 * Linux ethernet bridge
4 *
5 * Authors:
8237908e
BDS
6 * Lennert Buytenhek <buytenh@gnu.org>
7 * Bart De Schuymer <bdschuym@pandora.be>
1da177e4
LT
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version
12 * 2 of the License, or (at your option) any later version.
13 *
14 * Lennert dedicates this file to Kerstin Wurdinger.
15 */
16
17#include <linux/module.h>
18#include <linux/kernel.h>
5a0e3ad6 19#include <linux/slab.h>
1da177e4
LT
20#include <linux/ip.h>
21#include <linux/netdevice.h>
22#include <linux/skbuff.h>
14c85021 23#include <linux/if_arp.h>
1da177e4
LT
24#include <linux/if_ether.h>
25#include <linux/if_vlan.h>
516299d2
MM
26#include <linux/if_pppox.h>
27#include <linux/ppp_defs.h>
1da177e4
LT
28#include <linux/netfilter_bridge.h>
29#include <linux/netfilter_ipv4.h>
30#include <linux/netfilter_ipv6.h>
31#include <linux/netfilter_arp.h>
32#include <linux/in_route.h>
f216f082 33#include <linux/inetdevice.h>
14c85021 34
1da177e4
LT
35#include <net/ip.h>
36#include <net/ipv6.h>
14c85021 37#include <net/route.h>
56768644 38#include <net/netfilter/br_netfilter.h>
14c85021 39
c055d5b0
FW
40#if IS_ENABLED(CONFIG_NF_CONNTRACK)
41#include <net/netfilter/nf_conntrack.h>
42#endif
43
1da177e4 44#include <asm/uaccess.h>
1da177e4
LT
45#include "br_private.h"
46#ifdef CONFIG_SYSCTL
47#include <linux/sysctl.h>
48#endif
49
1da177e4
LT
50#ifdef CONFIG_SYSCTL
51static struct ctl_table_header *brnf_sysctl_header;
9c1ea148
BH
52static int brnf_call_iptables __read_mostly = 1;
53static int brnf_call_ip6tables __read_mostly = 1;
54static int brnf_call_arptables __read_mostly = 1;
47e0e1ca
HX
55static int brnf_filter_vlan_tagged __read_mostly = 0;
56static int brnf_filter_pppoe_tagged __read_mostly = 0;
4981682c 57static int brnf_pass_vlan_indev __read_mostly = 0;
1da177e4 58#else
4df53d8b
PM
59#define brnf_call_iptables 1
60#define brnf_call_ip6tables 1
61#define brnf_call_arptables 1
47e0e1ca
HX
62#define brnf_filter_vlan_tagged 0
63#define brnf_filter_pppoe_tagged 0
4981682c 64#define brnf_pass_vlan_indev 0
1da177e4
LT
65#endif
66
739e4505 67#define IS_IP(skb) \
df8a39de 68 (!skb_vlan_tag_present(skb) && skb->protocol == htons(ETH_P_IP))
739e4505
FW
69
70#define IS_IPV6(skb) \
df8a39de 71 (!skb_vlan_tag_present(skb) && skb->protocol == htons(ETH_P_IPV6))
739e4505
FW
72
73#define IS_ARP(skb) \
df8a39de 74 (!skb_vlan_tag_present(skb) && skb->protocol == htons(ETH_P_ARP))
739e4505 75
b6f99a21 76static inline __be16 vlan_proto(const struct sk_buff *skb)
8b42ec39 77{
df8a39de 78 if (skb_vlan_tag_present(skb))
13937911
JG
79 return skb->protocol;
80 else if (skb->protocol == htons(ETH_P_8021Q))
81 return vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
82 else
83 return 0;
8b42ec39
SH
84}
85
86#define IS_VLAN_IP(skb) \
13937911 87 (vlan_proto(skb) == htons(ETH_P_IP) && \
8b42ec39
SH
88 brnf_filter_vlan_tagged)
89
90#define IS_VLAN_IPV6(skb) \
13937911 91 (vlan_proto(skb) == htons(ETH_P_IPV6) && \
8b42ec39
SH
92 brnf_filter_vlan_tagged)
93
94#define IS_VLAN_ARP(skb) \
13937911 95 (vlan_proto(skb) == htons(ETH_P_ARP) && \
8b42ec39 96 brnf_filter_vlan_tagged)
1da177e4 97
516299d2
MM
98static inline __be16 pppoe_proto(const struct sk_buff *skb)
99{
100 return *((__be16 *)(skb_mac_header(skb) + ETH_HLEN +
101 sizeof(struct pppoe_hdr)));
102}
103
104#define IS_PPPOE_IP(skb) \
105 (skb->protocol == htons(ETH_P_PPP_SES) && \
106 pppoe_proto(skb) == htons(PPP_IP) && \
107 brnf_filter_pppoe_tagged)
108
109#define IS_PPPOE_IPV6(skb) \
110 (skb->protocol == htons(ETH_P_PPP_SES) && \
111 pppoe_proto(skb) == htons(PPP_IPV6) && \
112 brnf_filter_pppoe_tagged)
113
4adf0af6
SW
114static inline struct rtable *bridge_parent_rtable(const struct net_device *dev)
115{
b5ed54e9 116 struct net_bridge_port *port;
117
118 port = br_port_get_rcu(dev);
119 return port ? &port->br->fake_rtable : NULL;
4adf0af6 120}
1da177e4 121
5dce971a
SH
122static inline struct net_device *bridge_parent(const struct net_device *dev)
123{
b5ed54e9 124 struct net_bridge_port *port;
5dce971a 125
b5ed54e9 126 port = br_port_get_rcu(dev);
127 return port ? port->br->dev : NULL;
5dce971a 128}
1da177e4 129
fdeabdef
SH
130static inline struct nf_bridge_info *nf_bridge_alloc(struct sk_buff *skb)
131{
132 skb->nf_bridge = kzalloc(sizeof(struct nf_bridge_info), GFP_ATOMIC);
133 if (likely(skb->nf_bridge))
134 atomic_set(&(skb->nf_bridge->use), 1);
135
136 return skb->nf_bridge;
137}
138
2dc2f207
PM
139static inline struct nf_bridge_info *nf_bridge_unshare(struct sk_buff *skb)
140{
141 struct nf_bridge_info *nf_bridge = skb->nf_bridge;
142
143 if (atomic_read(&nf_bridge->use) > 1) {
144 struct nf_bridge_info *tmp = nf_bridge_alloc(skb);
145
146 if (tmp) {
147 memcpy(tmp, nf_bridge, sizeof(struct nf_bridge_info));
148 atomic_set(&tmp->use, 1);
2dc2f207 149 }
4c3a76ab 150 nf_bridge_put(nf_bridge);
2dc2f207
PM
151 nf_bridge = tmp;
152 }
153 return nf_bridge;
154}
155
8d045163
FW
156static unsigned int nf_bridge_encap_header_len(const struct sk_buff *skb)
157{
158 switch (skb->protocol) {
159 case __cpu_to_be16(ETH_P_8021Q):
160 return VLAN_HLEN;
161 case __cpu_to_be16(ETH_P_PPP_SES):
162 return PPPOE_SES_HLEN;
163 default:
164 return 0;
165 }
166}
167
fc38582d
PM
168static inline void nf_bridge_push_encap_header(struct sk_buff *skb)
169{
170 unsigned int len = nf_bridge_encap_header_len(skb);
171
172 skb_push(skb, len);
173 skb->network_header -= len;
174}
175
176static inline void nf_bridge_pull_encap_header(struct sk_buff *skb)
fdeabdef 177{
fc38582d
PM
178 unsigned int len = nf_bridge_encap_header_len(skb);
179
180 skb_pull(skb, len);
181 skb->network_header += len;
182}
fdeabdef 183
fc38582d
PM
184static inline void nf_bridge_pull_encap_header_rcsum(struct sk_buff *skb)
185{
186 unsigned int len = nf_bridge_encap_header_len(skb);
187
188 skb_pull_rcsum(skb, len);
189 skb->network_header += len;
190}
191
192static inline void nf_bridge_save_header(struct sk_buff *skb)
193{
194 int header_size = ETH_HLEN + nf_bridge_encap_header_len(skb);
fdeabdef 195
d626f62b
ACM
196 skb_copy_from_linear_data_offset(skb, -header_size,
197 skb->nf_bridge->data, header_size);
fdeabdef
SH
198}
199
462fb2af
BD
200/* When handing a packet over to the IP layer
201 * check whether we have a skb that is in the
202 * expected format
203 */
204
d0280232 205static int br_parse_ip_options(struct sk_buff *skb)
462fb2af 206{
b71d1d42 207 const struct iphdr *iph;
462fb2af
BD
208 struct net_device *dev = skb->dev;
209 u32 len;
210
6caab7b0
SB
211 if (!pskb_may_pull(skb, sizeof(struct iphdr)))
212 goto inhdr_error;
213
462fb2af 214 iph = ip_hdr(skb);
462fb2af
BD
215
216 /* Basic sanity checks */
217 if (iph->ihl < 5 || iph->version != 4)
218 goto inhdr_error;
219
220 if (!pskb_may_pull(skb, iph->ihl*4))
221 goto inhdr_error;
222
223 iph = ip_hdr(skb);
224 if (unlikely(ip_fast_csum((u8 *)iph, iph->ihl)))
225 goto inhdr_error;
226
227 len = ntohs(iph->tot_len);
228 if (skb->len < len) {
229 IP_INC_STATS_BH(dev_net(dev), IPSTATS_MIB_INTRUNCATEDPKTS);
230 goto drop;
231 } else if (len < (iph->ihl*4))
232 goto inhdr_error;
233
234 if (pskb_trim_rcsum(skb, len)) {
235 IP_INC_STATS_BH(dev_net(dev), IPSTATS_MIB_INDISCARDS);
236 goto drop;
237 }
238
f8e9881c 239 memset(IPCB(skb), 0, sizeof(struct inet_skb_parm));
7677e868
HX
240 /* We should really parse IP options here but until
241 * somebody who actually uses IP options complains to
242 * us we'll just silently ignore the options because
243 * we're lazy!
244 */
462fb2af
BD
245 return 0;
246
247inhdr_error:
248 IP_INC_STATS_BH(dev_net(dev), IPSTATS_MIB_INHDRERRORS);
249drop:
250 return -1;
251}
252
4a9d2f20
FW
253static void nf_bridge_update_protocol(struct sk_buff *skb)
254{
255 if (skb->nf_bridge->mask & BRNF_8021Q)
256 skb->protocol = htons(ETH_P_8021Q);
257 else if (skb->nf_bridge->mask & BRNF_PPPoE)
258 skb->protocol = htons(ETH_P_PPP_SES);
259}
260
1da177e4
LT
261/* PF_BRIDGE/PRE_ROUTING *********************************************/
262/* Undo the changes made for ip6tables PREROUTING and continue the
263 * bridge PRE_ROUTING hook. */
264static int br_nf_pre_routing_finish_ipv6(struct sk_buff *skb)
265{
266 struct nf_bridge_info *nf_bridge = skb->nf_bridge;
511c3f92 267 struct rtable *rt;
1da177e4 268
1da177e4
LT
269 if (nf_bridge->mask & BRNF_PKT_TYPE) {
270 skb->pkt_type = PACKET_OTHERHOST;
271 nf_bridge->mask ^= BRNF_PKT_TYPE;
272 }
273 nf_bridge->mask ^= BRNF_NF_BRIDGE_PREROUTING;
274
511c3f92
ED
275 rt = bridge_parent_rtable(nf_bridge->physindev);
276 if (!rt) {
4adf0af6
SW
277 kfree_skb(skb);
278 return 0;
279 }
f9181f4f 280 skb_dst_set_noref(skb, &rt->dst);
1da177e4
LT
281
282 skb->dev = nf_bridge->physindev;
e179e632 283 nf_bridge_update_protocol(skb);
fc38582d 284 nf_bridge_push_encap_header(skb);
713aefa3 285 NF_HOOK_THRESH(NFPROTO_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL,
1da177e4
LT
286 br_handle_frame_finish, 1);
287
288 return 0;
289}
290
e179e632
BDS
291/* Obtain the correct destination MAC address, while preserving the original
292 * source MAC address. If we already know this address, we just copy it. If we
293 * don't, we use the neighbour framework to find out. In both cases, we make
294 * sure that br_handle_frame_finish() is called afterwards.
295 */
296static int br_nf_pre_routing_finish_bridge(struct sk_buff *skb)
297{
298 struct nf_bridge_info *nf_bridge = skb->nf_bridge;
f6b72b62 299 struct neighbour *neigh;
e179e632
BDS
300 struct dst_entry *dst;
301
302 skb->dev = bridge_parent(skb->dev);
303 if (!skb->dev)
304 goto free_skb;
305 dst = skb_dst(skb);
f9d75166
DM
306 neigh = dst_neigh_lookup_skb(dst, skb);
307 if (neigh) {
308 int ret;
309
310 if (neigh->hh.hh_len) {
311 neigh_hh_bridge(&neigh->hh, skb);
312 skb->dev = nf_bridge->physindev;
313 ret = br_handle_frame_finish(skb);
314 } else {
315 /* the neighbour function below overwrites the complete
316 * MAC header, so we save the Ethernet source address and
317 * protocol number.
318 */
319 skb_copy_from_linear_data_offset(skb,
320 -(ETH_HLEN-ETH_ALEN),
321 skb->nf_bridge->data,
322 ETH_HLEN-ETH_ALEN);
323 /* tell br_dev_xmit to continue with forwarding */
324 nf_bridge->mask |= BRNF_BRIDGED_DNAT;
93fdd47e 325 /* FIXME Need to refragment */
f9d75166
DM
326 ret = neigh->output(neigh, skb);
327 }
328 neigh_release(neigh);
329 return ret;
e179e632
BDS
330 }
331free_skb:
332 kfree_skb(skb);
333 return 0;
334}
335
c055d5b0
FW
336static bool dnat_took_place(const struct sk_buff *skb)
337{
338#if IS_ENABLED(CONFIG_NF_CONNTRACK)
339 enum ip_conntrack_info ctinfo;
340 struct nf_conn *ct;
341
342 ct = nf_ct_get(skb, &ctinfo);
343 if (!ct || nf_ct_is_untracked(ct))
344 return false;
345
346 return test_bit(IPS_DST_NAT_BIT, &ct->status);
347#else
348 return false;
349#endif
350}
351
1da177e4 352/* This requires some explaining. If DNAT has taken place,
ea2d9b41 353 * we will need to fix up the destination Ethernet address.
1da177e4
LT
354 *
355 * There are two cases to consider:
356 * 1. The packet was DNAT'ed to a device in the same bridge
357 * port group as it was received on. We can still bridge
358 * the packet.
359 * 2. The packet was DNAT'ed to a different device, either
360 * a non-bridged device or another bridge port group.
361 * The packet will need to be routed.
362 *
363 * The correct way of distinguishing between these two cases is to
364 * call ip_route_input() and to look at skb->dst->dev, which is
365 * changed to the destination device if ip_route_input() succeeds.
366 *
ea2d9b41 367 * Let's first consider the case that ip_route_input() succeeds:
1da177e4 368 *
ea2d9b41
BDS
369 * If the output device equals the logical bridge device the packet
370 * came in on, we can consider this bridging. The corresponding MAC
371 * address will be obtained in br_nf_pre_routing_finish_bridge.
1da177e4
LT
372 * Otherwise, the packet is considered to be routed and we just
373 * change the destination MAC address so that the packet will
f216f082
BDS
374 * later be passed up to the IP stack to be routed. For a redirected
375 * packet, ip_route_input() will give back the localhost as output device,
376 * which differs from the bridge device.
1da177e4 377 *
ea2d9b41 378 * Let's now consider the case that ip_route_input() fails:
1da177e4 379 *
f216f082
BDS
380 * This can be because the destination address is martian, in which case
381 * the packet will be dropped.
ea2d9b41
BDS
382 * If IP forwarding is disabled, ip_route_input() will fail, while
383 * ip_route_output_key() can return success. The source
384 * address for ip_route_output_key() is set to zero, so ip_route_output_key()
1da177e4 385 * thinks we're handling a locally generated packet and won't care
ea2d9b41
BDS
386 * if IP forwarding is enabled. If the output device equals the logical bridge
387 * device, we proceed as if ip_route_input() succeeded. If it differs from the
388 * logical bridge port or if ip_route_output_key() fails we drop the packet.
389 */
1da177e4
LT
390static int br_nf_pre_routing_finish(struct sk_buff *skb)
391{
392 struct net_device *dev = skb->dev;
eddc9ec5 393 struct iphdr *iph = ip_hdr(skb);
1da177e4 394 struct nf_bridge_info *nf_bridge = skb->nf_bridge;
511c3f92 395 struct rtable *rt;
f216f082 396 int err;
93fdd47e
HX
397 int frag_max_size;
398
399 frag_max_size = IPCB(skb)->frag_max_size;
400 BR_INPUT_SKB_CB(skb)->frag_max_size = frag_max_size;
1da177e4 401
1da177e4
LT
402 if (nf_bridge->mask & BRNF_PKT_TYPE) {
403 skb->pkt_type = PACKET_OTHERHOST;
404 nf_bridge->mask ^= BRNF_PKT_TYPE;
405 }
406 nf_bridge->mask ^= BRNF_NF_BRIDGE_PREROUTING;
1da177e4 407 if (dnat_took_place(skb)) {
f216f082 408 if ((err = ip_route_input(skb, iph->daddr, iph->saddr, iph->tos, dev))) {
f3abc9b9 409 struct in_device *in_dev = __in_dev_get_rcu(dev);
f216f082
BDS
410
411 /* If err equals -EHOSTUNREACH the error is due to a
412 * martian destination or due to the fact that
413 * forwarding is disabled. For most martian packets,
414 * ip_route_output_key() will fail. It won't fail for 2 types of
415 * martian destinations: loopback destinations and destination
416 * 0.0.0.0. In both cases the packet will be dropped because the
417 * destination is the loopback device and not the bridge. */
418 if (err != -EHOSTUNREACH || !in_dev || IN_DEV_FORWARD(in_dev))
419 goto free_skb;
1da177e4 420
78fbfd8a
DM
421 rt = ip_route_output(dev_net(dev), iph->daddr, 0,
422 RT_TOS(iph->tos), 0);
b23dd4fe 423 if (!IS_ERR(rt)) {
1c011bed 424 /* - Bridged-and-DNAT'ed traffic doesn't
f216f082 425 * require ip_forwarding. */
b23dd4fe
DM
426 if (rt->dst.dev == dev) {
427 skb_dst_set(skb, &rt->dst);
1da177e4
LT
428 goto bridged_dnat;
429 }
b23dd4fe 430 ip_rt_put(rt);
1da177e4 431 }
f216f082 432free_skb:
1da177e4
LT
433 kfree_skb(skb);
434 return 0;
435 } else {
adf30907 436 if (skb_dst(skb)->dev == dev) {
1da177e4 437bridged_dnat:
1da177e4 438 skb->dev = nf_bridge->physindev;
e179e632 439 nf_bridge_update_protocol(skb);
fc38582d 440 nf_bridge_push_encap_header(skb);
713aefa3
JE
441 NF_HOOK_THRESH(NFPROTO_BRIDGE,
442 NF_BR_PRE_ROUTING,
1da177e4
LT
443 skb, skb->dev, NULL,
444 br_nf_pre_routing_finish_bridge,
445 1);
446 return 0;
447 }
04091142 448 ether_addr_copy(eth_hdr(skb)->h_dest, dev->dev_addr);
1da177e4
LT
449 skb->pkt_type = PACKET_HOST;
450 }
451 } else {
511c3f92
ED
452 rt = bridge_parent_rtable(nf_bridge->physindev);
453 if (!rt) {
4adf0af6
SW
454 kfree_skb(skb);
455 return 0;
456 }
f9181f4f 457 skb_dst_set_noref(skb, &rt->dst);
1da177e4
LT
458 }
459
460 skb->dev = nf_bridge->physindev;
e179e632 461 nf_bridge_update_protocol(skb);
fc38582d 462 nf_bridge_push_encap_header(skb);
713aefa3 463 NF_HOOK_THRESH(NFPROTO_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL,
1da177e4
LT
464 br_handle_frame_finish, 1);
465
466 return 0;
467}
468
4981682c
PNA
469static struct net_device *brnf_get_logical_dev(struct sk_buff *skb, const struct net_device *dev)
470{
471 struct net_device *vlan, *br;
472
473 br = bridge_parent(dev);
df8a39de 474 if (brnf_pass_vlan_indev == 0 || !skb_vlan_tag_present(skb))
4981682c
PNA
475 return br;
476
f06c7f9f 477 vlan = __vlan_find_dev_deep_rcu(br, skb->vlan_proto,
df8a39de 478 skb_vlan_tag_get(skb) & VLAN_VID_MASK);
4981682c
PNA
479
480 return vlan ? vlan : br;
481}
482
1da177e4 483/* Some common code for IPv4/IPv6 */
5dce971a 484static struct net_device *setup_pre_routing(struct sk_buff *skb)
1da177e4
LT
485{
486 struct nf_bridge_info *nf_bridge = skb->nf_bridge;
487
488 if (skb->pkt_type == PACKET_OTHERHOST) {
489 skb->pkt_type = PACKET_HOST;
490 nf_bridge->mask |= BRNF_PKT_TYPE;
491 }
492
493 nf_bridge->mask |= BRNF_NF_BRIDGE_PREROUTING;
494 nf_bridge->physindev = skb->dev;
4981682c 495 skb->dev = brnf_get_logical_dev(skb, skb->dev);
e179e632
BDS
496 if (skb->protocol == htons(ETH_P_8021Q))
497 nf_bridge->mask |= BRNF_8021Q;
498 else if (skb->protocol == htons(ETH_P_PPP_SES))
499 nf_bridge->mask |= BRNF_PPPoE;
5dce971a 500
6b8dbcf2
FW
501 /* Must drop socket now because of tproxy. */
502 skb_orphan(skb);
5dce971a 503 return skb->dev;
1da177e4
LT
504}
505
506/* We only check the length. A bridge shouldn't do any hop-by-hop stuff anyway */
507static int check_hbh_len(struct sk_buff *skb)
508{
0660e03f 509 unsigned char *raw = (u8 *)(ipv6_hdr(skb) + 1);
1da177e4 510 u32 pkt_len;
d56f90a7
ACM
511 const unsigned char *nh = skb_network_header(skb);
512 int off = raw - nh;
789bc3e5 513 int len = (raw[1] + 1) << 3;
1da177e4
LT
514
515 if ((raw + len) - skb->data > skb_headlen(skb))
516 goto bad;
517
518 off += 2;
519 len -= 2;
520
521 while (len > 0) {
d56f90a7 522 int optlen = nh[off + 1] + 2;
1da177e4 523
d56f90a7 524 switch (nh[off]) {
1de5a71c 525 case IPV6_TLV_PAD1:
1da177e4
LT
526 optlen = 1;
527 break;
528
529 case IPV6_TLV_PADN:
530 break;
531
532 case IPV6_TLV_JUMBO:
d56f90a7 533 if (nh[off + 1] != 4 || (off & 3) != 2)
1da177e4 534 goto bad;
d56f90a7 535 pkt_len = ntohl(*(__be32 *) (nh + off + 2));
b0366486 536 if (pkt_len <= IPV6_MAXPLEN ||
0660e03f 537 ipv6_hdr(skb)->payload_len)
b0366486 538 goto bad;
1da177e4
LT
539 if (pkt_len > skb->len - sizeof(struct ipv6hdr))
540 goto bad;
b0366486 541 if (pskb_trim_rcsum(skb,
789bc3e5 542 pkt_len + sizeof(struct ipv6hdr)))
b0366486 543 goto bad;
d56f90a7 544 nh = skb_network_header(skb);
1da177e4
LT
545 break;
546 default:
547 if (optlen > len)
548 goto bad;
549 break;
550 }
551 off += optlen;
552 len -= optlen;
553 }
554 if (len == 0)
555 return 0;
556bad:
557 return -1;
558
559}
560
561/* Replicate the checks that IPv6 does on packet reception and pass the packet
562 * to ip6tables, which doesn't support NAT, so things are fairly simple. */
795aa6ef 563static unsigned int br_nf_pre_routing_ipv6(const struct nf_hook_ops *ops,
789bc3e5
SH
564 struct sk_buff *skb,
565 const struct net_device *in,
566 const struct net_device *out,
567 int (*okfn)(struct sk_buff *))
1da177e4 568{
b71d1d42 569 const struct ipv6hdr *hdr;
1da177e4 570 u32 pkt_len;
1da177e4
LT
571
572 if (skb->len < sizeof(struct ipv6hdr))
deef4b52 573 return NF_DROP;
1da177e4
LT
574
575 if (!pskb_may_pull(skb, sizeof(struct ipv6hdr)))
deef4b52 576 return NF_DROP;
1da177e4 577
0660e03f 578 hdr = ipv6_hdr(skb);
1da177e4
LT
579
580 if (hdr->version != 6)
deef4b52 581 return NF_DROP;
1da177e4
LT
582
583 pkt_len = ntohs(hdr->payload_len);
584
585 if (pkt_len || hdr->nexthdr != NEXTHDR_HOP) {
586 if (pkt_len + sizeof(struct ipv6hdr) > skb->len)
deef4b52 587 return NF_DROP;
b38dfee3 588 if (pskb_trim_rcsum(skb, pkt_len + sizeof(struct ipv6hdr)))
deef4b52 589 return NF_DROP;
1da177e4
LT
590 }
591 if (hdr->nexthdr == NEXTHDR_HOP && check_hbh_len(skb))
deef4b52 592 return NF_DROP;
1da177e4 593
789bc3e5 594 nf_bridge_put(skb->nf_bridge);
fdeabdef 595 if (!nf_bridge_alloc(skb))
1da177e4 596 return NF_DROP;
5dce971a
SH
597 if (!setup_pre_routing(skb))
598 return NF_DROP;
1da177e4 599
e179e632 600 skb->protocol = htons(ETH_P_IPV6);
713aefa3 601 NF_HOOK(NFPROTO_IPV6, NF_INET_PRE_ROUTING, skb, skb->dev, NULL,
1da177e4
LT
602 br_nf_pre_routing_finish_ipv6);
603
604 return NF_STOLEN;
1da177e4
LT
605}
606
607/* Direct IPv6 traffic to br_nf_pre_routing_ipv6.
608 * Replicate the checks that IPv4 does on packet reception.
609 * Set skb->dev to the bridge device (i.e. parent of the
610 * receiving device) to make netfilter happy, the REDIRECT
611 * target in particular. Save the original destination IP
612 * address to be able to detect DNAT afterwards. */
795aa6ef
PM
613static unsigned int br_nf_pre_routing(const struct nf_hook_ops *ops,
614 struct sk_buff *skb,
ee02b3a6
SH
615 const struct net_device *in,
616 const struct net_device *out,
617 int (*okfn)(struct sk_buff *))
1da177e4 618{
4df53d8b
PM
619 struct net_bridge_port *p;
620 struct net_bridge *br;
e7c243c9
EP
621 __u32 len = nf_bridge_encap_header_len(skb);
622
e7c243c9 623 if (unlikely(!pskb_may_pull(skb, len)))
deef4b52 624 return NF_DROP;
1da177e4 625
e490c1de 626 p = br_port_get_rcu(in);
4df53d8b 627 if (p == NULL)
deef4b52 628 return NF_DROP;
4df53d8b
PM
629 br = p->br;
630
739e4505 631 if (IS_IPV6(skb) || IS_VLAN_IPV6(skb) || IS_PPPOE_IPV6(skb)) {
4df53d8b 632 if (!brnf_call_ip6tables && !br->nf_call_ip6tables)
1da177e4 633 return NF_ACCEPT;
4df53d8b 634
fc38582d 635 nf_bridge_pull_encap_header_rcsum(skb);
795aa6ef 636 return br_nf_pre_routing_ipv6(ops, skb, in, out, okfn);
1da177e4 637 }
4df53d8b
PM
638
639 if (!brnf_call_iptables && !br->nf_call_iptables)
1da177e4 640 return NF_ACCEPT;
1da177e4 641
739e4505 642 if (!IS_IP(skb) && !IS_VLAN_IP(skb) && !IS_PPPOE_IP(skb))
1da177e4
LT
643 return NF_ACCEPT;
644
fc38582d 645 nf_bridge_pull_encap_header_rcsum(skb);
1da177e4 646
462fb2af 647 if (br_parse_ip_options(skb))
deef4b52 648 return NF_DROP;
17762060 649
789bc3e5 650 nf_bridge_put(skb->nf_bridge);
fdeabdef 651 if (!nf_bridge_alloc(skb))
1da177e4 652 return NF_DROP;
5dce971a
SH
653 if (!setup_pre_routing(skb))
654 return NF_DROP;
c055d5b0 655
e179e632 656 skb->protocol = htons(ETH_P_IP);
1da177e4 657
713aefa3 658 NF_HOOK(NFPROTO_IPV4, NF_INET_PRE_ROUTING, skb, skb->dev, NULL,
1da177e4
LT
659 br_nf_pre_routing_finish);
660
661 return NF_STOLEN;
1da177e4
LT
662}
663
664
665/* PF_BRIDGE/LOCAL_IN ************************************************/
666/* The packet is locally destined, which requires a real
667 * dst_entry, so detach the fake one. On the way up, the
668 * packet would pass through PRE_ROUTING again (which already
669 * took place when the packet entered the bridge), but we
670 * register an IPv4 PRE_ROUTING 'sabotage' hook that will
671 * prevent this from happening. */
795aa6ef
PM
672static unsigned int br_nf_local_in(const struct nf_hook_ops *ops,
673 struct sk_buff *skb,
789bc3e5
SH
674 const struct net_device *in,
675 const struct net_device *out,
676 int (*okfn)(struct sk_buff *))
1da177e4 677{
a881e963 678 br_drop_fake_rtable(skb);
1da177e4
LT
679 return NF_ACCEPT;
680}
681
1da177e4
LT
682/* PF_BRIDGE/FORWARD *************************************************/
683static int br_nf_forward_finish(struct sk_buff *skb)
684{
685 struct nf_bridge_info *nf_bridge = skb->nf_bridge;
686 struct net_device *in;
1da177e4 687
739e4505 688 if (!IS_ARP(skb) && !IS_VLAN_ARP(skb)) {
1da177e4
LT
689 in = nf_bridge->physindev;
690 if (nf_bridge->mask & BRNF_PKT_TYPE) {
691 skb->pkt_type = PACKET_OTHERHOST;
692 nf_bridge->mask ^= BRNF_PKT_TYPE;
693 }
e94c6743 694 nf_bridge_update_protocol(skb);
1da177e4
LT
695 } else {
696 in = *((struct net_device **)(skb->cb));
697 }
fc38582d 698 nf_bridge_push_encap_header(skb);
e179e632 699
713aefa3 700 NF_HOOK_THRESH(NFPROTO_BRIDGE, NF_BR_FORWARD, skb, in,
789bc3e5 701 skb->dev, br_forward_finish, 1);
1da177e4
LT
702 return 0;
703}
704
739e4505 705
1da177e4
LT
706/* This is the 'purely bridged' case. For IP, we pass the packet to
707 * netfilter with indev and outdev set to the bridge device,
708 * but we are still able to filter on the 'real' indev/outdev
709 * because of the physdev module. For ARP, indev and outdev are the
710 * bridge ports. */
795aa6ef
PM
711static unsigned int br_nf_forward_ip(const struct nf_hook_ops *ops,
712 struct sk_buff *skb,
789bc3e5
SH
713 const struct net_device *in,
714 const struct net_device *out,
715 int (*okfn)(struct sk_buff *))
1da177e4 716{
1da177e4 717 struct nf_bridge_info *nf_bridge;
5dce971a 718 struct net_device *parent;
76108cea 719 u_int8_t pf;
1da177e4
LT
720
721 if (!skb->nf_bridge)
722 return NF_ACCEPT;
723
2dc2f207
PM
724 /* Need exclusive nf_bridge_info since we might have multiple
725 * different physoutdevs. */
726 if (!nf_bridge_unshare(skb))
727 return NF_DROP;
728
5dce971a
SH
729 parent = bridge_parent(out);
730 if (!parent)
731 return NF_DROP;
732
739e4505 733 if (IS_IP(skb) || IS_VLAN_IP(skb) || IS_PPPOE_IP(skb))
aa740f46 734 pf = NFPROTO_IPV4;
739e4505 735 else if (IS_IPV6(skb) || IS_VLAN_IPV6(skb) || IS_PPPOE_IPV6(skb))
aa740f46 736 pf = NFPROTO_IPV6;
a2bd40ad
HX
737 else
738 return NF_ACCEPT;
1da177e4 739
3db05fea 740 nf_bridge_pull_encap_header(skb);
1da177e4 741
1da177e4
LT
742 nf_bridge = skb->nf_bridge;
743 if (skb->pkt_type == PACKET_OTHERHOST) {
744 skb->pkt_type = PACKET_HOST;
745 nf_bridge->mask |= BRNF_PKT_TYPE;
746 }
747
aa740f46 748 if (pf == NFPROTO_IPV4 && br_parse_ip_options(skb))
6b1e960f
HX
749 return NF_DROP;
750
1da177e4 751 nf_bridge->physoutdev = skb->dev;
aa740f46 752 if (pf == NFPROTO_IPV4)
e179e632
BDS
753 skb->protocol = htons(ETH_P_IP);
754 else
755 skb->protocol = htons(ETH_P_IPV6);
1da177e4 756
4981682c 757 NF_HOOK(pf, NF_INET_FORWARD, skb, brnf_get_logical_dev(skb, in), parent,
5dce971a 758 br_nf_forward_finish);
1da177e4
LT
759
760 return NF_STOLEN;
761}
762
795aa6ef
PM
763static unsigned int br_nf_forward_arp(const struct nf_hook_ops *ops,
764 struct sk_buff *skb,
789bc3e5
SH
765 const struct net_device *in,
766 const struct net_device *out,
767 int (*okfn)(struct sk_buff *))
1da177e4 768{
4df53d8b
PM
769 struct net_bridge_port *p;
770 struct net_bridge *br;
1da177e4
LT
771 struct net_device **d = (struct net_device **)(skb->cb);
772
e490c1de 773 p = br_port_get_rcu(out);
4df53d8b
PM
774 if (p == NULL)
775 return NF_ACCEPT;
776 br = p->br;
777
778 if (!brnf_call_arptables && !br->nf_call_arptables)
1da177e4 779 return NF_ACCEPT;
1da177e4 780
739e4505 781 if (!IS_ARP(skb)) {
8b42ec39 782 if (!IS_VLAN_ARP(skb))
1da177e4 783 return NF_ACCEPT;
3db05fea 784 nf_bridge_pull_encap_header(skb);
1da177e4
LT
785 }
786
d0a92be0 787 if (arp_hdr(skb)->ar_pln != 4) {
fc38582d 788 if (IS_VLAN_ARP(skb))
3db05fea 789 nf_bridge_push_encap_header(skb);
1da177e4
LT
790 return NF_ACCEPT;
791 }
792 *d = (struct net_device *)in;
fdc9314c 793 NF_HOOK(NFPROTO_ARP, NF_ARP_FORWARD, skb, (struct net_device *)in,
1da177e4
LT
794 (struct net_device *)out, br_nf_forward_finish);
795
796 return NF_STOLEN;
797}
798
aff09ce3 799#if IS_ENABLED(CONFIG_NF_DEFRAG_IPV4)
8bd63cf1
FW
800static bool nf_bridge_copy_header(struct sk_buff *skb)
801{
802 int err;
803 unsigned int header_size;
804
805 nf_bridge_update_protocol(skb);
806 header_size = ETH_HLEN + nf_bridge_encap_header_len(skb);
807 err = skb_cow_head(skb, header_size);
808 if (err)
809 return false;
810
811 skb_copy_to_linear_data_offset(skb, -header_size,
812 skb->nf_bridge->data, header_size);
813 __skb_push(skb, nf_bridge_encap_header_len(skb));
814 return true;
815}
816
817static int br_nf_push_frag_xmit(struct sk_buff *skb)
818{
819 if (!nf_bridge_copy_header(skb)) {
820 kfree_skb(skb);
821 return 0;
822 }
823
824 return br_dev_queue_push_xmit(skb);
825}
826
2e2f7aef
PM
827static int br_nf_dev_queue_xmit(struct sk_buff *skb)
828{
462fb2af 829 int ret;
93fdd47e 830 int frag_max_size;
7a8d831d 831 unsigned int mtu_reserved;
462fb2af 832
7a8d831d
FW
833 if (skb_is_gso(skb) || skb->protocol != htons(ETH_P_IP))
834 return br_dev_queue_push_xmit(skb);
835
836 mtu_reserved = nf_bridge_mtu_reduction(skb);
93fdd47e
HX
837 /* This is wrong! We should preserve the original fragment
838 * boundaries by preserving frag_list rather than refragmenting.
839 */
7a8d831d 840 if (skb->len + mtu_reserved > skb->dev->mtu) {
93fdd47e 841 frag_max_size = BR_INPUT_SKB_CB(skb)->frag_max_size;
462fb2af
BD
842 if (br_parse_ip_options(skb))
843 /* Drop invalid packet */
844 return NF_DROP;
93fdd47e 845 IPCB(skb)->frag_max_size = frag_max_size;
8bd63cf1 846 ret = ip_fragment(skb, br_nf_push_frag_xmit);
87f94b4e 847 } else
462fb2af
BD
848 ret = br_dev_queue_push_xmit(skb);
849
850 return ret;
2e2f7aef 851}
c197facc 852#else
853static int br_nf_dev_queue_xmit(struct sk_buff *skb)
854{
855 return br_dev_queue_push_xmit(skb);
856}
857#endif
1da177e4
LT
858
859/* PF_BRIDGE/POST_ROUTING ********************************************/
795aa6ef
PM
860static unsigned int br_nf_post_routing(const struct nf_hook_ops *ops,
861 struct sk_buff *skb,
789bc3e5
SH
862 const struct net_device *in,
863 const struct net_device *out,
864 int (*okfn)(struct sk_buff *))
1da177e4 865{
3db05fea 866 struct nf_bridge_info *nf_bridge = skb->nf_bridge;
1da177e4 867 struct net_device *realoutdev = bridge_parent(skb->dev);
76108cea 868 u_int8_t pf;
1da177e4 869
e4bb9bcb
FW
870 /* if nf_bridge is set, but ->physoutdev is NULL, this packet came in
871 * on a bridge, but was delivered locally and is now being routed:
872 *
873 * POST_ROUTING was already invoked from the ip stack.
874 */
875 if (!nf_bridge || !nf_bridge->physoutdev)
81d9ddae
PM
876 return NF_ACCEPT;
877
5dce971a
SH
878 if (!realoutdev)
879 return NF_DROP;
880
739e4505 881 if (IS_IP(skb) || IS_VLAN_IP(skb) || IS_PPPOE_IP(skb))
aa740f46 882 pf = NFPROTO_IPV4;
739e4505 883 else if (IS_IPV6(skb) || IS_VLAN_IPV6(skb) || IS_PPPOE_IPV6(skb))
aa740f46 884 pf = NFPROTO_IPV6;
a2bd40ad
HX
885 else
886 return NF_ACCEPT;
1da177e4 887
1da177e4
LT
888 /* We assume any code from br_dev_queue_push_xmit onwards doesn't care
889 * about the value of skb->pkt_type. */
890 if (skb->pkt_type == PACKET_OTHERHOST) {
891 skb->pkt_type = PACKET_HOST;
892 nf_bridge->mask |= BRNF_PKT_TYPE;
893 }
894
fc38582d 895 nf_bridge_pull_encap_header(skb);
1da177e4 896 nf_bridge_save_header(skb);
aa740f46 897 if (pf == NFPROTO_IPV4)
e179e632
BDS
898 skb->protocol = htons(ETH_P_IP);
899 else
900 skb->protocol = htons(ETH_P_IPV6);
1da177e4 901
6e23ae2a 902 NF_HOOK(pf, NF_INET_POST_ROUTING, skb, NULL, realoutdev,
2e2f7aef 903 br_nf_dev_queue_xmit);
1da177e4
LT
904
905 return NF_STOLEN;
1da177e4
LT
906}
907
1da177e4
LT
908/* IP/SABOTAGE *****************************************************/
909/* Don't hand locally destined packets to PF_INET(6)/PRE_ROUTING
910 * for the second time. */
795aa6ef
PM
911static unsigned int ip_sabotage_in(const struct nf_hook_ops *ops,
912 struct sk_buff *skb,
789bc3e5
SH
913 const struct net_device *in,
914 const struct net_device *out,
915 int (*okfn)(struct sk_buff *))
1da177e4 916{
3db05fea
HX
917 if (skb->nf_bridge &&
918 !(skb->nf_bridge->mask & BRNF_NF_BRIDGE_PREROUTING)) {
1da177e4
LT
919 return NF_STOP;
920 }
921
922 return NF_ACCEPT;
923}
924
e5de75bf
PNA
925/* This is called when br_netfilter has called into iptables/netfilter,
926 * and DNAT has taken place on a bridge-forwarded packet.
927 *
928 * neigh->output has created a new MAC header, with local br0 MAC
929 * as saddr.
930 *
931 * This restores the original MAC saddr of the bridged packet
932 * before invoking bridge forward logic to transmit the packet.
933 */
934static void br_nf_pre_routing_finish_bridge_slow(struct sk_buff *skb)
935{
936 struct nf_bridge_info *nf_bridge = skb->nf_bridge;
937
938 skb_pull(skb, ETH_HLEN);
939 nf_bridge->mask &= ~BRNF_BRIDGED_DNAT;
940
941 skb_copy_to_linear_data_offset(skb, -(ETH_HLEN-ETH_ALEN),
942 skb->nf_bridge->data, ETH_HLEN-ETH_ALEN);
943 skb->dev = nf_bridge->physindev;
944 br_handle_frame_finish(skb);
945}
946
1a4ba64d 947static int br_nf_dev_xmit(struct sk_buff *skb)
e5de75bf
PNA
948{
949 if (skb->nf_bridge && (skb->nf_bridge->mask & BRNF_BRIDGED_DNAT)) {
950 br_nf_pre_routing_finish_bridge_slow(skb);
951 return 1;
952 }
953 return 0;
954}
1a4ba64d
PNA
955
956static const struct nf_br_ops br_ops = {
957 .br_dev_xmit_hook = br_nf_dev_xmit,
958};
e5de75bf 959
4b7fd5d9
PNA
960void br_netfilter_enable(void)
961{
962}
963EXPORT_SYMBOL_GPL(br_netfilter_enable);
964
ea2d9b41
BDS
965/* For br_nf_post_routing, we need (prio = NF_BR_PRI_LAST), because
966 * br_dev_queue_push_xmit is called afterwards */
1999414a 967static struct nf_hook_ops br_nf_ops[] __read_mostly = {
1490fd89
CG
968 {
969 .hook = br_nf_pre_routing,
970 .owner = THIS_MODULE,
aa740f46 971 .pf = NFPROTO_BRIDGE,
1490fd89
CG
972 .hooknum = NF_BR_PRE_ROUTING,
973 .priority = NF_BR_PRI_BRNF,
974 },
975 {
976 .hook = br_nf_local_in,
977 .owner = THIS_MODULE,
aa740f46 978 .pf = NFPROTO_BRIDGE,
1490fd89
CG
979 .hooknum = NF_BR_LOCAL_IN,
980 .priority = NF_BR_PRI_BRNF,
981 },
982 {
983 .hook = br_nf_forward_ip,
984 .owner = THIS_MODULE,
aa740f46 985 .pf = NFPROTO_BRIDGE,
1490fd89
CG
986 .hooknum = NF_BR_FORWARD,
987 .priority = NF_BR_PRI_BRNF - 1,
988 },
989 {
990 .hook = br_nf_forward_arp,
991 .owner = THIS_MODULE,
aa740f46 992 .pf = NFPROTO_BRIDGE,
1490fd89
CG
993 .hooknum = NF_BR_FORWARD,
994 .priority = NF_BR_PRI_BRNF,
995 },
1490fd89
CG
996 {
997 .hook = br_nf_post_routing,
998 .owner = THIS_MODULE,
aa740f46 999 .pf = NFPROTO_BRIDGE,
1490fd89
CG
1000 .hooknum = NF_BR_POST_ROUTING,
1001 .priority = NF_BR_PRI_LAST,
1002 },
1003 {
1004 .hook = ip_sabotage_in,
1005 .owner = THIS_MODULE,
aa740f46 1006 .pf = NFPROTO_IPV4,
1490fd89
CG
1007 .hooknum = NF_INET_PRE_ROUTING,
1008 .priority = NF_IP_PRI_FIRST,
1009 },
1010 {
1011 .hook = ip_sabotage_in,
1012 .owner = THIS_MODULE,
aa740f46 1013 .pf = NFPROTO_IPV6,
1490fd89
CG
1014 .hooknum = NF_INET_PRE_ROUTING,
1015 .priority = NF_IP6_PRI_FIRST,
1016 },
1da177e4
LT
1017};
1018
1019#ifdef CONFIG_SYSCTL
1020static
fe2c6338 1021int brnf_sysctl_call_tables(struct ctl_table *ctl, int write,
56b148eb 1022 void __user *buffer, size_t *lenp, loff_t *ppos)
1da177e4
LT
1023{
1024 int ret;
1025
8d65af78 1026 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
1da177e4
LT
1027
1028 if (write && *(int *)(ctl->data))
1029 *(int *)(ctl->data) = 1;
1030 return ret;
1031}
1032
fe2c6338 1033static struct ctl_table brnf_table[] = {
1da177e4 1034 {
1da177e4
LT
1035 .procname = "bridge-nf-call-arptables",
1036 .data = &brnf_call_arptables,
1037 .maxlen = sizeof(int),
1038 .mode = 0644,
6d9f239a 1039 .proc_handler = brnf_sysctl_call_tables,
1da177e4
LT
1040 },
1041 {
1da177e4
LT
1042 .procname = "bridge-nf-call-iptables",
1043 .data = &brnf_call_iptables,
1044 .maxlen = sizeof(int),
1045 .mode = 0644,
6d9f239a 1046 .proc_handler = brnf_sysctl_call_tables,
1da177e4
LT
1047 },
1048 {
1da177e4
LT
1049 .procname = "bridge-nf-call-ip6tables",
1050 .data = &brnf_call_ip6tables,
1051 .maxlen = sizeof(int),
1052 .mode = 0644,
6d9f239a 1053 .proc_handler = brnf_sysctl_call_tables,
1da177e4
LT
1054 },
1055 {
1da177e4
LT
1056 .procname = "bridge-nf-filter-vlan-tagged",
1057 .data = &brnf_filter_vlan_tagged,
1058 .maxlen = sizeof(int),
1059 .mode = 0644,
6d9f239a 1060 .proc_handler = brnf_sysctl_call_tables,
516299d2
MM
1061 },
1062 {
516299d2
MM
1063 .procname = "bridge-nf-filter-pppoe-tagged",
1064 .data = &brnf_filter_pppoe_tagged,
1065 .maxlen = sizeof(int),
1066 .mode = 0644,
6d9f239a 1067 .proc_handler = brnf_sysctl_call_tables,
1da177e4 1068 },
4981682c
PNA
1069 {
1070 .procname = "bridge-nf-pass-vlan-input-dev",
1071 .data = &brnf_pass_vlan_indev,
1072 .maxlen = sizeof(int),
1073 .mode = 0644,
1074 .proc_handler = brnf_sysctl_call_tables,
1075 },
f8572d8f 1076 { }
1da177e4 1077};
1da177e4
LT
1078#endif
1079
34666d46 1080static int __init br_netfilter_init(void)
1da177e4 1081{
5eb87f45 1082 int ret;
1da177e4 1083
34666d46 1084 ret = nf_register_hooks(br_nf_ops, ARRAY_SIZE(br_nf_ops));
5eb87f45 1085 if (ret < 0)
1da177e4 1086 return ret;
fc66f95c 1087
1da177e4 1088#ifdef CONFIG_SYSCTL
ec8f23ce 1089 brnf_sysctl_header = register_net_sysctl(&init_net, "net/bridge", brnf_table);
1da177e4 1090 if (brnf_sysctl_header == NULL) {
789bc3e5
SH
1091 printk(KERN_WARNING
1092 "br_netfilter: can't register to sysctl.\n");
96727239
GU
1093 nf_unregister_hooks(br_nf_ops, ARRAY_SIZE(br_nf_ops));
1094 return -ENOMEM;
1da177e4
LT
1095 }
1096#endif
1a4ba64d 1097 RCU_INIT_POINTER(nf_br_ops, &br_ops);
1da177e4 1098 printk(KERN_NOTICE "Bridge firewalling registered\n");
1da177e4
LT
1099 return 0;
1100}
1101
34666d46 1102static void __exit br_netfilter_fini(void)
1da177e4 1103{
1a4ba64d 1104 RCU_INIT_POINTER(nf_br_ops, NULL);
5eb87f45 1105 nf_unregister_hooks(br_nf_ops, ARRAY_SIZE(br_nf_ops));
1da177e4 1106#ifdef CONFIG_SYSCTL
5dd3df10 1107 unregister_net_sysctl_table(brnf_sysctl_header);
1da177e4
LT
1108#endif
1109}
34666d46
PNA
1110
1111module_init(br_netfilter_init);
1112module_exit(br_netfilter_fini);
1113
1114MODULE_LICENSE("GPL");
1115MODULE_AUTHOR("Lennert Buytenhek <buytenh@gnu.org>");
1116MODULE_AUTHOR("Bart De Schuymer <bdschuym@pandora.be>");
1117MODULE_DESCRIPTION("Linux ethernet netfilter firewall bridge");