netfilter: x_tables: align per cpu xt_counter
[profile/common/platform/kernel/linux-artik7.git] / net / bridge / br_netfilter_hooks.c
1 /*
2  *      Handle firewalling
3  *      Linux ethernet bridge
4  *
5  *      Authors:
6  *      Lennert Buytenhek               <buytenh@gnu.org>
7  *      Bart De Schuymer                <bdschuym@pandora.be>
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>
19 #include <linux/slab.h>
20 #include <linux/ip.h>
21 #include <linux/netdevice.h>
22 #include <linux/skbuff.h>
23 #include <linux/if_arp.h>
24 #include <linux/if_ether.h>
25 #include <linux/if_vlan.h>
26 #include <linux/if_pppox.h>
27 #include <linux/ppp_defs.h>
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>
33 #include <linux/inetdevice.h>
34
35 #include <net/ip.h>
36 #include <net/ipv6.h>
37 #include <net/addrconf.h>
38 #include <net/route.h>
39 #include <net/netfilter/br_netfilter.h>
40
41 #include <asm/uaccess.h>
42 #include "br_private.h"
43 #ifdef CONFIG_SYSCTL
44 #include <linux/sysctl.h>
45 #endif
46
47 #ifdef CONFIG_SYSCTL
48 static struct ctl_table_header *brnf_sysctl_header;
49 static int brnf_call_iptables __read_mostly = 1;
50 static int brnf_call_ip6tables __read_mostly = 1;
51 static int brnf_call_arptables __read_mostly = 1;
52 static int brnf_filter_vlan_tagged __read_mostly = 0;
53 static int brnf_filter_pppoe_tagged __read_mostly = 0;
54 static int brnf_pass_vlan_indev __read_mostly = 0;
55 #else
56 #define brnf_call_iptables 1
57 #define brnf_call_ip6tables 1
58 #define brnf_call_arptables 1
59 #define brnf_filter_vlan_tagged 0
60 #define brnf_filter_pppoe_tagged 0
61 #define brnf_pass_vlan_indev 0
62 #endif
63
64 #define IS_IP(skb) \
65         (!skb_vlan_tag_present(skb) && skb->protocol == htons(ETH_P_IP))
66
67 #define IS_IPV6(skb) \
68         (!skb_vlan_tag_present(skb) && skb->protocol == htons(ETH_P_IPV6))
69
70 #define IS_ARP(skb) \
71         (!skb_vlan_tag_present(skb) && skb->protocol == htons(ETH_P_ARP))
72
73 static inline __be16 vlan_proto(const struct sk_buff *skb)
74 {
75         if (skb_vlan_tag_present(skb))
76                 return skb->protocol;
77         else if (skb->protocol == htons(ETH_P_8021Q))
78                 return vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
79         else
80                 return 0;
81 }
82
83 #define IS_VLAN_IP(skb) \
84         (vlan_proto(skb) == htons(ETH_P_IP) && \
85          brnf_filter_vlan_tagged)
86
87 #define IS_VLAN_IPV6(skb) \
88         (vlan_proto(skb) == htons(ETH_P_IPV6) && \
89          brnf_filter_vlan_tagged)
90
91 #define IS_VLAN_ARP(skb) \
92         (vlan_proto(skb) == htons(ETH_P_ARP) && \
93          brnf_filter_vlan_tagged)
94
95 static inline __be16 pppoe_proto(const struct sk_buff *skb)
96 {
97         return *((__be16 *)(skb_mac_header(skb) + ETH_HLEN +
98                             sizeof(struct pppoe_hdr)));
99 }
100
101 #define IS_PPPOE_IP(skb) \
102         (skb->protocol == htons(ETH_P_PPP_SES) && \
103          pppoe_proto(skb) == htons(PPP_IP) && \
104          brnf_filter_pppoe_tagged)
105
106 #define IS_PPPOE_IPV6(skb) \
107         (skb->protocol == htons(ETH_P_PPP_SES) && \
108          pppoe_proto(skb) == htons(PPP_IPV6) && \
109          brnf_filter_pppoe_tagged)
110
111 /* largest possible L2 header, see br_nf_dev_queue_xmit() */
112 #define NF_BRIDGE_MAX_MAC_HEADER_LENGTH (PPPOE_SES_HLEN + ETH_HLEN)
113
114 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV4)
115 struct brnf_frag_data {
116         char mac[NF_BRIDGE_MAX_MAC_HEADER_LENGTH];
117         u8 encap_size;
118         u8 size;
119         u16 vlan_tci;
120         __be16 vlan_proto;
121 };
122
123 static DEFINE_PER_CPU(struct brnf_frag_data, brnf_frag_data_storage);
124 #endif
125
126 static struct nf_bridge_info *nf_bridge_info_get(const struct sk_buff *skb)
127 {
128         return skb->nf_bridge;
129 }
130
131 static void nf_bridge_info_free(struct sk_buff *skb)
132 {
133         if (skb->nf_bridge) {
134                 nf_bridge_put(skb->nf_bridge);
135                 skb->nf_bridge = NULL;
136         }
137 }
138
139 static inline struct rtable *bridge_parent_rtable(const struct net_device *dev)
140 {
141         struct net_bridge_port *port;
142
143         port = br_port_get_rcu(dev);
144         return port ? &port->br->fake_rtable : NULL;
145 }
146
147 static inline struct net_device *bridge_parent(const struct net_device *dev)
148 {
149         struct net_bridge_port *port;
150
151         port = br_port_get_rcu(dev);
152         return port ? port->br->dev : NULL;
153 }
154
155 static inline struct nf_bridge_info *nf_bridge_alloc(struct sk_buff *skb)
156 {
157         skb->nf_bridge = kzalloc(sizeof(struct nf_bridge_info), GFP_ATOMIC);
158         if (likely(skb->nf_bridge))
159                 atomic_set(&(skb->nf_bridge->use), 1);
160
161         return skb->nf_bridge;
162 }
163
164 static inline struct nf_bridge_info *nf_bridge_unshare(struct sk_buff *skb)
165 {
166         struct nf_bridge_info *nf_bridge = skb->nf_bridge;
167
168         if (atomic_read(&nf_bridge->use) > 1) {
169                 struct nf_bridge_info *tmp = nf_bridge_alloc(skb);
170
171                 if (tmp) {
172                         memcpy(tmp, nf_bridge, sizeof(struct nf_bridge_info));
173                         atomic_set(&tmp->use, 1);
174                 }
175                 nf_bridge_put(nf_bridge);
176                 nf_bridge = tmp;
177         }
178         return nf_bridge;
179 }
180
181 static unsigned int nf_bridge_encap_header_len(const struct sk_buff *skb)
182 {
183         switch (skb->protocol) {
184         case __cpu_to_be16(ETH_P_8021Q):
185                 return VLAN_HLEN;
186         case __cpu_to_be16(ETH_P_PPP_SES):
187                 return PPPOE_SES_HLEN;
188         default:
189                 return 0;
190         }
191 }
192
193 static inline void nf_bridge_push_encap_header(struct sk_buff *skb)
194 {
195         unsigned int len = nf_bridge_encap_header_len(skb);
196
197         skb_push(skb, len);
198         skb->network_header -= len;
199 }
200
201 static inline void nf_bridge_pull_encap_header(struct sk_buff *skb)
202 {
203         unsigned int len = nf_bridge_encap_header_len(skb);
204
205         skb_pull(skb, len);
206         skb->network_header += len;
207 }
208
209 static inline void nf_bridge_pull_encap_header_rcsum(struct sk_buff *skb)
210 {
211         unsigned int len = nf_bridge_encap_header_len(skb);
212
213         skb_pull_rcsum(skb, len);
214         skb->network_header += len;
215 }
216
217 /* When handing a packet over to the IP layer
218  * check whether we have a skb that is in the
219  * expected format
220  */
221
222 static int br_validate_ipv4(struct sk_buff *skb)
223 {
224         const struct iphdr *iph;
225         struct net_device *dev = skb->dev;
226         u32 len;
227
228         if (!pskb_may_pull(skb, sizeof(struct iphdr)))
229                 goto inhdr_error;
230
231         iph = ip_hdr(skb);
232
233         /* Basic sanity checks */
234         if (iph->ihl < 5 || iph->version != 4)
235                 goto inhdr_error;
236
237         if (!pskb_may_pull(skb, iph->ihl*4))
238                 goto inhdr_error;
239
240         iph = ip_hdr(skb);
241         if (unlikely(ip_fast_csum((u8 *)iph, iph->ihl)))
242                 goto inhdr_error;
243
244         len = ntohs(iph->tot_len);
245         if (skb->len < len) {
246                 IP_INC_STATS_BH(dev_net(dev), IPSTATS_MIB_INTRUNCATEDPKTS);
247                 goto drop;
248         } else if (len < (iph->ihl*4))
249                 goto inhdr_error;
250
251         if (pskb_trim_rcsum(skb, len)) {
252                 IP_INC_STATS_BH(dev_net(dev), IPSTATS_MIB_INDISCARDS);
253                 goto drop;
254         }
255
256         memset(IPCB(skb), 0, sizeof(struct inet_skb_parm));
257         /* We should really parse IP options here but until
258          * somebody who actually uses IP options complains to
259          * us we'll just silently ignore the options because
260          * we're lazy!
261          */
262         return 0;
263
264 inhdr_error:
265         IP_INC_STATS_BH(dev_net(dev), IPSTATS_MIB_INHDRERRORS);
266 drop:
267         return -1;
268 }
269
270 /* We only check the length. A bridge shouldn't do any hop-by-hop stuff
271  * anyway
272  */
273 static int check_hbh_len(struct sk_buff *skb)
274 {
275         unsigned char *raw = (u8 *)(ipv6_hdr(skb) + 1);
276         u32 pkt_len;
277         const unsigned char *nh = skb_network_header(skb);
278         int off = raw - nh;
279         int len = (raw[1] + 1) << 3;
280
281         if ((raw + len) - skb->data > skb_headlen(skb))
282                 goto bad;
283
284         off += 2;
285         len -= 2;
286
287         while (len > 0) {
288                 int optlen = nh[off + 1] + 2;
289
290                 switch (nh[off]) {
291                 case IPV6_TLV_PAD1:
292                         optlen = 1;
293                         break;
294
295                 case IPV6_TLV_PADN:
296                         break;
297
298                 case IPV6_TLV_JUMBO:
299                         if (nh[off + 1] != 4 || (off & 3) != 2)
300                                 goto bad;
301                         pkt_len = ntohl(*(__be32 *)(nh + off + 2));
302                         if (pkt_len <= IPV6_MAXPLEN ||
303                             ipv6_hdr(skb)->payload_len)
304                                 goto bad;
305                         if (pkt_len > skb->len - sizeof(struct ipv6hdr))
306                                 goto bad;
307                         if (pskb_trim_rcsum(skb,
308                                             pkt_len + sizeof(struct ipv6hdr)))
309                                 goto bad;
310                         nh = skb_network_header(skb);
311                         break;
312                 default:
313                         if (optlen > len)
314                                 goto bad;
315                         break;
316                 }
317                 off += optlen;
318                 len -= optlen;
319         }
320         if (len == 0)
321                 return 0;
322 bad:
323         return -1;
324 }
325
326 /* Equivalent to br_validate_ipv4 for IPv6 */
327 static int br_validate_ipv6(struct sk_buff *skb)
328 {
329         const struct ipv6hdr *hdr;
330         struct net_device *dev = skb->dev;
331         struct inet6_dev *idev = in6_dev_get(skb->dev);
332         u32 pkt_len;
333         u8 ip6h_len = sizeof(struct ipv6hdr);
334
335         if (!pskb_may_pull(skb, ip6h_len))
336                 goto inhdr_error;
337
338         if (skb->len < ip6h_len)
339                 goto drop;
340
341         hdr = ipv6_hdr(skb);
342
343         if (hdr->version != 6)
344                 goto inhdr_error;
345
346         pkt_len = ntohs(hdr->payload_len);
347
348         if (pkt_len || hdr->nexthdr != NEXTHDR_HOP) {
349                 if (pkt_len + ip6h_len > skb->len) {
350                         IP6_INC_STATS_BH(dev_net(dev), idev,
351                                          IPSTATS_MIB_INTRUNCATEDPKTS);
352                         goto drop;
353                 }
354                 if (pskb_trim_rcsum(skb, pkt_len + ip6h_len)) {
355                         IP6_INC_STATS_BH(dev_net(dev), idev,
356                                          IPSTATS_MIB_INDISCARDS);
357                         goto drop;
358                 }
359         }
360         if (hdr->nexthdr == NEXTHDR_HOP && check_hbh_len(skb))
361                 goto drop;
362
363         memset(IP6CB(skb), 0, sizeof(struct inet6_skb_parm));
364         /* No IP options in IPv6 header; however it should be
365          * checked if some next headers need special treatment
366          */
367         return 0;
368
369 inhdr_error:
370         IP6_INC_STATS_BH(dev_net(dev), idev, IPSTATS_MIB_INHDRERRORS);
371 drop:
372         return -1;
373 }
374
375 static void nf_bridge_update_protocol(struct sk_buff *skb)
376 {
377         switch (skb->nf_bridge->orig_proto) {
378         case BRNF_PROTO_8021Q:
379                 skb->protocol = htons(ETH_P_8021Q);
380                 break;
381         case BRNF_PROTO_PPPOE:
382                 skb->protocol = htons(ETH_P_PPP_SES);
383                 break;
384         case BRNF_PROTO_UNCHANGED:
385                 break;
386         }
387 }
388
389 /* Obtain the correct destination MAC address, while preserving the original
390  * source MAC address. If we already know this address, we just copy it. If we
391  * don't, we use the neighbour framework to find out. In both cases, we make
392  * sure that br_handle_frame_finish() is called afterwards.
393  */
394 static int br_nf_pre_routing_finish_bridge(struct sock *sk, struct sk_buff *skb)
395 {
396         struct neighbour *neigh;
397         struct dst_entry *dst;
398
399         skb->dev = bridge_parent(skb->dev);
400         if (!skb->dev)
401                 goto free_skb;
402         dst = skb_dst(skb);
403         neigh = dst_neigh_lookup_skb(dst, skb);
404         if (neigh) {
405                 struct nf_bridge_info *nf_bridge = nf_bridge_info_get(skb);
406                 int ret;
407
408                 if (neigh->hh.hh_len) {
409                         neigh_hh_bridge(&neigh->hh, skb);
410                         skb->dev = nf_bridge->physindev;
411                         ret = br_handle_frame_finish(sk, skb);
412                 } else {
413                         /* the neighbour function below overwrites the complete
414                          * MAC header, so we save the Ethernet source address and
415                          * protocol number.
416                          */
417                         skb_copy_from_linear_data_offset(skb,
418                                                          -(ETH_HLEN-ETH_ALEN),
419                                                          nf_bridge->neigh_header,
420                                                          ETH_HLEN-ETH_ALEN);
421                         /* tell br_dev_xmit to continue with forwarding */
422                         nf_bridge->mask |= BRNF_BRIDGED_DNAT;
423                         /* FIXME Need to refragment */
424                         ret = neigh->output(neigh, skb);
425                 }
426                 neigh_release(neigh);
427                 return ret;
428         }
429 free_skb:
430         kfree_skb(skb);
431         return 0;
432 }
433
434 static bool daddr_was_changed(const struct sk_buff *skb,
435                               const struct nf_bridge_info *nf_bridge)
436 {
437         switch (skb->protocol) {
438         case htons(ETH_P_IP):
439                 return ip_hdr(skb)->daddr != nf_bridge->ipv4_daddr;
440         case htons(ETH_P_IPV6):
441                 return memcmp(&nf_bridge->ipv6_daddr, &ipv6_hdr(skb)->daddr,
442                               sizeof(ipv6_hdr(skb)->daddr)) != 0;
443         default:
444                 return false;
445         }
446 }
447
448 /* PF_BRIDGE/PRE_ROUTING: Undo the changes made for ip6tables
449  * PREROUTING and continue the bridge PRE_ROUTING hook. See comment
450  * for br_nf_pre_routing_finish(), same logic is used here but
451  * equivalent IPv6 function ip6_route_input() called indirectly.
452  */
453 static int br_nf_pre_routing_finish_ipv6(struct sock *sk, struct sk_buff *skb)
454 {
455         struct nf_bridge_info *nf_bridge = nf_bridge_info_get(skb);
456         struct rtable *rt;
457         struct net_device *dev = skb->dev;
458         const struct nf_ipv6_ops *v6ops = nf_get_ipv6_ops();
459
460         nf_bridge->frag_max_size = IP6CB(skb)->frag_max_size;
461
462         if (nf_bridge->pkt_otherhost) {
463                 skb->pkt_type = PACKET_OTHERHOST;
464                 nf_bridge->pkt_otherhost = false;
465         }
466         nf_bridge->mask &= ~BRNF_NF_BRIDGE_PREROUTING;
467         if (daddr_was_changed(skb, nf_bridge)) {
468                 skb_dst_drop(skb);
469                 v6ops->route_input(skb);
470
471                 if (skb_dst(skb)->error) {
472                         kfree_skb(skb);
473                         return 0;
474                 }
475
476                 if (skb_dst(skb)->dev == dev) {
477                         skb->dev = nf_bridge->physindev;
478                         nf_bridge_update_protocol(skb);
479                         nf_bridge_push_encap_header(skb);
480                         NF_HOOK_THRESH(NFPROTO_BRIDGE, NF_BR_PRE_ROUTING,
481                                        sk, skb, skb->dev, NULL,
482                                        br_nf_pre_routing_finish_bridge,
483                                        1);
484                         return 0;
485                 }
486                 ether_addr_copy(eth_hdr(skb)->h_dest, dev->dev_addr);
487                 skb->pkt_type = PACKET_HOST;
488         } else {
489                 rt = bridge_parent_rtable(nf_bridge->physindev);
490                 if (!rt) {
491                         kfree_skb(skb);
492                         return 0;
493                 }
494                 skb_dst_set_noref(skb, &rt->dst);
495         }
496
497         skb->dev = nf_bridge->physindev;
498         nf_bridge_update_protocol(skb);
499         nf_bridge_push_encap_header(skb);
500         NF_HOOK_THRESH(NFPROTO_BRIDGE, NF_BR_PRE_ROUTING, sk, skb,
501                        skb->dev, NULL,
502                        br_handle_frame_finish, 1);
503
504         return 0;
505 }
506
507 /* This requires some explaining. If DNAT has taken place,
508  * we will need to fix up the destination Ethernet address.
509  * This is also true when SNAT takes place (for the reply direction).
510  *
511  * There are two cases to consider:
512  * 1. The packet was DNAT'ed to a device in the same bridge
513  *    port group as it was received on. We can still bridge
514  *    the packet.
515  * 2. The packet was DNAT'ed to a different device, either
516  *    a non-bridged device or another bridge port group.
517  *    The packet will need to be routed.
518  *
519  * The correct way of distinguishing between these two cases is to
520  * call ip_route_input() and to look at skb->dst->dev, which is
521  * changed to the destination device if ip_route_input() succeeds.
522  *
523  * Let's first consider the case that ip_route_input() succeeds:
524  *
525  * If the output device equals the logical bridge device the packet
526  * came in on, we can consider this bridging. The corresponding MAC
527  * address will be obtained in br_nf_pre_routing_finish_bridge.
528  * Otherwise, the packet is considered to be routed and we just
529  * change the destination MAC address so that the packet will
530  * later be passed up to the IP stack to be routed. For a redirected
531  * packet, ip_route_input() will give back the localhost as output device,
532  * which differs from the bridge device.
533  *
534  * Let's now consider the case that ip_route_input() fails:
535  *
536  * This can be because the destination address is martian, in which case
537  * the packet will be dropped.
538  * If IP forwarding is disabled, ip_route_input() will fail, while
539  * ip_route_output_key() can return success. The source
540  * address for ip_route_output_key() is set to zero, so ip_route_output_key()
541  * thinks we're handling a locally generated packet and won't care
542  * if IP forwarding is enabled. If the output device equals the logical bridge
543  * device, we proceed as if ip_route_input() succeeded. If it differs from the
544  * logical bridge port or if ip_route_output_key() fails we drop the packet.
545  */
546 static int br_nf_pre_routing_finish(struct sock *sk, struct sk_buff *skb)
547 {
548         struct net_device *dev = skb->dev;
549         struct iphdr *iph = ip_hdr(skb);
550         struct nf_bridge_info *nf_bridge = nf_bridge_info_get(skb);
551         struct rtable *rt;
552         int err;
553
554         nf_bridge->frag_max_size = IPCB(skb)->frag_max_size;
555
556         if (nf_bridge->pkt_otherhost) {
557                 skb->pkt_type = PACKET_OTHERHOST;
558                 nf_bridge->pkt_otherhost = false;
559         }
560         nf_bridge->mask &= ~BRNF_NF_BRIDGE_PREROUTING;
561         if (daddr_was_changed(skb, nf_bridge)) {
562                 if ((err = ip_route_input(skb, iph->daddr, iph->saddr, iph->tos, dev))) {
563                         struct in_device *in_dev = __in_dev_get_rcu(dev);
564
565                         /* If err equals -EHOSTUNREACH the error is due to a
566                          * martian destination or due to the fact that
567                          * forwarding is disabled. For most martian packets,
568                          * ip_route_output_key() will fail. It won't fail for 2 types of
569                          * martian destinations: loopback destinations and destination
570                          * 0.0.0.0. In both cases the packet will be dropped because the
571                          * destination is the loopback device and not the bridge. */
572                         if (err != -EHOSTUNREACH || !in_dev || IN_DEV_FORWARD(in_dev))
573                                 goto free_skb;
574
575                         rt = ip_route_output(dev_net(dev), iph->daddr, 0,
576                                              RT_TOS(iph->tos), 0);
577                         if (!IS_ERR(rt)) {
578                                 /* - Bridged-and-DNAT'ed traffic doesn't
579                                  *   require ip_forwarding. */
580                                 if (rt->dst.dev == dev) {
581                                         skb_dst_set(skb, &rt->dst);
582                                         goto bridged_dnat;
583                                 }
584                                 ip_rt_put(rt);
585                         }
586 free_skb:
587                         kfree_skb(skb);
588                         return 0;
589                 } else {
590                         if (skb_dst(skb)->dev == dev) {
591 bridged_dnat:
592                                 skb->dev = nf_bridge->physindev;
593                                 nf_bridge_update_protocol(skb);
594                                 nf_bridge_push_encap_header(skb);
595                                 NF_HOOK_THRESH(NFPROTO_BRIDGE,
596                                                NF_BR_PRE_ROUTING,
597                                                sk, skb, skb->dev, NULL,
598                                                br_nf_pre_routing_finish_bridge,
599                                                1);
600                                 return 0;
601                         }
602                         ether_addr_copy(eth_hdr(skb)->h_dest, dev->dev_addr);
603                         skb->pkt_type = PACKET_HOST;
604                 }
605         } else {
606                 rt = bridge_parent_rtable(nf_bridge->physindev);
607                 if (!rt) {
608                         kfree_skb(skb);
609                         return 0;
610                 }
611                 skb_dst_set_noref(skb, &rt->dst);
612         }
613
614         skb->dev = nf_bridge->physindev;
615         nf_bridge_update_protocol(skb);
616         nf_bridge_push_encap_header(skb);
617         NF_HOOK_THRESH(NFPROTO_BRIDGE, NF_BR_PRE_ROUTING, sk, skb,
618                        skb->dev, NULL,
619                        br_handle_frame_finish, 1);
620
621         return 0;
622 }
623
624 static struct net_device *brnf_get_logical_dev(struct sk_buff *skb, const struct net_device *dev)
625 {
626         struct net_device *vlan, *br;
627
628         br = bridge_parent(dev);
629         if (brnf_pass_vlan_indev == 0 || !skb_vlan_tag_present(skb))
630                 return br;
631
632         vlan = __vlan_find_dev_deep_rcu(br, skb->vlan_proto,
633                                     skb_vlan_tag_get(skb) & VLAN_VID_MASK);
634
635         return vlan ? vlan : br;
636 }
637
638 /* Some common code for IPv4/IPv6 */
639 static struct net_device *setup_pre_routing(struct sk_buff *skb)
640 {
641         struct nf_bridge_info *nf_bridge = nf_bridge_info_get(skb);
642
643         if (skb->pkt_type == PACKET_OTHERHOST) {
644                 skb->pkt_type = PACKET_HOST;
645                 nf_bridge->pkt_otherhost = true;
646         }
647
648         nf_bridge->mask |= BRNF_NF_BRIDGE_PREROUTING;
649         nf_bridge->physindev = skb->dev;
650         skb->dev = brnf_get_logical_dev(skb, skb->dev);
651
652         if (skb->protocol == htons(ETH_P_8021Q))
653                 nf_bridge->orig_proto = BRNF_PROTO_8021Q;
654         else if (skb->protocol == htons(ETH_P_PPP_SES))
655                 nf_bridge->orig_proto = BRNF_PROTO_PPPOE;
656
657         /* Must drop socket now because of tproxy. */
658         skb_orphan(skb);
659         return skb->dev;
660 }
661
662 /* Replicate the checks that IPv6 does on packet reception and pass the packet
663  * to ip6tables.
664  */
665 static unsigned int br_nf_pre_routing_ipv6(const struct nf_hook_ops *ops,
666                                            struct sk_buff *skb,
667                                            const struct nf_hook_state *state)
668 {
669         struct nf_bridge_info *nf_bridge;
670
671         if (br_validate_ipv6(skb))
672                 return NF_DROP;
673
674         nf_bridge_put(skb->nf_bridge);
675         if (!nf_bridge_alloc(skb))
676                 return NF_DROP;
677         if (!setup_pre_routing(skb))
678                 return NF_DROP;
679
680         nf_bridge = nf_bridge_info_get(skb);
681         nf_bridge->ipv6_daddr = ipv6_hdr(skb)->daddr;
682
683         skb->protocol = htons(ETH_P_IPV6);
684         NF_HOOK(NFPROTO_IPV6, NF_INET_PRE_ROUTING, state->sk, skb,
685                 skb->dev, NULL,
686                 br_nf_pre_routing_finish_ipv6);
687
688         return NF_STOLEN;
689 }
690
691 /* Direct IPv6 traffic to br_nf_pre_routing_ipv6.
692  * Replicate the checks that IPv4 does on packet reception.
693  * Set skb->dev to the bridge device (i.e. parent of the
694  * receiving device) to make netfilter happy, the REDIRECT
695  * target in particular.  Save the original destination IP
696  * address to be able to detect DNAT afterwards. */
697 static unsigned int br_nf_pre_routing(const struct nf_hook_ops *ops,
698                                       struct sk_buff *skb,
699                                       const struct nf_hook_state *state)
700 {
701         struct nf_bridge_info *nf_bridge;
702         struct net_bridge_port *p;
703         struct net_bridge *br;
704         __u32 len = nf_bridge_encap_header_len(skb);
705
706         if (unlikely(!pskb_may_pull(skb, len)))
707                 return NF_DROP;
708
709         p = br_port_get_rcu(state->in);
710         if (p == NULL)
711                 return NF_DROP;
712         br = p->br;
713
714         if (IS_IPV6(skb) || IS_VLAN_IPV6(skb) || IS_PPPOE_IPV6(skb)) {
715                 if (!brnf_call_ip6tables && !br->nf_call_ip6tables)
716                         return NF_ACCEPT;
717
718                 nf_bridge_pull_encap_header_rcsum(skb);
719                 return br_nf_pre_routing_ipv6(ops, skb, state);
720         }
721
722         if (!brnf_call_iptables && !br->nf_call_iptables)
723                 return NF_ACCEPT;
724
725         if (!IS_IP(skb) && !IS_VLAN_IP(skb) && !IS_PPPOE_IP(skb))
726                 return NF_ACCEPT;
727
728         nf_bridge_pull_encap_header_rcsum(skb);
729
730         if (br_validate_ipv4(skb))
731                 return NF_DROP;
732
733         nf_bridge_put(skb->nf_bridge);
734         if (!nf_bridge_alloc(skb))
735                 return NF_DROP;
736         if (!setup_pre_routing(skb))
737                 return NF_DROP;
738
739         nf_bridge = nf_bridge_info_get(skb);
740         nf_bridge->ipv4_daddr = ip_hdr(skb)->daddr;
741
742         skb->protocol = htons(ETH_P_IP);
743
744         NF_HOOK(NFPROTO_IPV4, NF_INET_PRE_ROUTING, state->sk, skb,
745                 skb->dev, NULL,
746                 br_nf_pre_routing_finish);
747
748         return NF_STOLEN;
749 }
750
751
752 /* PF_BRIDGE/LOCAL_IN ************************************************/
753 /* The packet is locally destined, which requires a real
754  * dst_entry, so detach the fake one.  On the way up, the
755  * packet would pass through PRE_ROUTING again (which already
756  * took place when the packet entered the bridge), but we
757  * register an IPv4 PRE_ROUTING 'sabotage' hook that will
758  * prevent this from happening. */
759 static unsigned int br_nf_local_in(const struct nf_hook_ops *ops,
760                                    struct sk_buff *skb,
761                                    const struct nf_hook_state *state)
762 {
763         br_drop_fake_rtable(skb);
764         return NF_ACCEPT;
765 }
766
767 /* PF_BRIDGE/FORWARD *************************************************/
768 static int br_nf_forward_finish(struct sock *sk, struct sk_buff *skb)
769 {
770         struct nf_bridge_info *nf_bridge = nf_bridge_info_get(skb);
771         struct net_device *in;
772
773         if (!IS_ARP(skb) && !IS_VLAN_ARP(skb)) {
774
775                 if (skb->protocol == htons(ETH_P_IP))
776                         nf_bridge->frag_max_size = IPCB(skb)->frag_max_size;
777
778                 if (skb->protocol == htons(ETH_P_IPV6))
779                         nf_bridge->frag_max_size = IP6CB(skb)->frag_max_size;
780
781                 in = nf_bridge->physindev;
782                 if (nf_bridge->pkt_otherhost) {
783                         skb->pkt_type = PACKET_OTHERHOST;
784                         nf_bridge->pkt_otherhost = false;
785                 }
786                 nf_bridge_update_protocol(skb);
787         } else {
788                 in = *((struct net_device **)(skb->cb));
789         }
790         nf_bridge_push_encap_header(skb);
791
792         NF_HOOK_THRESH(NFPROTO_BRIDGE, NF_BR_FORWARD, sk, skb,
793                        in, skb->dev, br_forward_finish, 1);
794         return 0;
795 }
796
797
798 /* This is the 'purely bridged' case.  For IP, we pass the packet to
799  * netfilter with indev and outdev set to the bridge device,
800  * but we are still able to filter on the 'real' indev/outdev
801  * because of the physdev module. For ARP, indev and outdev are the
802  * bridge ports. */
803 static unsigned int br_nf_forward_ip(const struct nf_hook_ops *ops,
804                                      struct sk_buff *skb,
805                                      const struct nf_hook_state *state)
806 {
807         struct nf_bridge_info *nf_bridge;
808         struct net_device *parent;
809         u_int8_t pf;
810
811         if (!skb->nf_bridge)
812                 return NF_ACCEPT;
813
814         /* Need exclusive nf_bridge_info since we might have multiple
815          * different physoutdevs. */
816         if (!nf_bridge_unshare(skb))
817                 return NF_DROP;
818
819         nf_bridge = nf_bridge_info_get(skb);
820         if (!nf_bridge)
821                 return NF_DROP;
822
823         parent = bridge_parent(state->out);
824         if (!parent)
825                 return NF_DROP;
826
827         if (IS_IP(skb) || IS_VLAN_IP(skb) || IS_PPPOE_IP(skb))
828                 pf = NFPROTO_IPV4;
829         else if (IS_IPV6(skb) || IS_VLAN_IPV6(skb) || IS_PPPOE_IPV6(skb))
830                 pf = NFPROTO_IPV6;
831         else
832                 return NF_ACCEPT;
833
834         nf_bridge_pull_encap_header(skb);
835
836         if (skb->pkt_type == PACKET_OTHERHOST) {
837                 skb->pkt_type = PACKET_HOST;
838                 nf_bridge->pkt_otherhost = true;
839         }
840
841         if (pf == NFPROTO_IPV4) {
842                 if (br_validate_ipv4(skb))
843                         return NF_DROP;
844                 IPCB(skb)->frag_max_size = nf_bridge->frag_max_size;
845         }
846
847         if (pf == NFPROTO_IPV6) {
848                 if (br_validate_ipv6(skb))
849                         return NF_DROP;
850                 IP6CB(skb)->frag_max_size = nf_bridge->frag_max_size;
851         }
852
853         nf_bridge->physoutdev = skb->dev;
854         if (pf == NFPROTO_IPV4)
855                 skb->protocol = htons(ETH_P_IP);
856         else
857                 skb->protocol = htons(ETH_P_IPV6);
858
859         NF_HOOK(pf, NF_INET_FORWARD, NULL, skb,
860                 brnf_get_logical_dev(skb, state->in),
861                 parent, br_nf_forward_finish);
862
863         return NF_STOLEN;
864 }
865
866 static unsigned int br_nf_forward_arp(const struct nf_hook_ops *ops,
867                                       struct sk_buff *skb,
868                                       const struct nf_hook_state *state)
869 {
870         struct net_bridge_port *p;
871         struct net_bridge *br;
872         struct net_device **d = (struct net_device **)(skb->cb);
873
874         p = br_port_get_rcu(state->out);
875         if (p == NULL)
876                 return NF_ACCEPT;
877         br = p->br;
878
879         if (!brnf_call_arptables && !br->nf_call_arptables)
880                 return NF_ACCEPT;
881
882         if (!IS_ARP(skb)) {
883                 if (!IS_VLAN_ARP(skb))
884                         return NF_ACCEPT;
885                 nf_bridge_pull_encap_header(skb);
886         }
887
888         if (arp_hdr(skb)->ar_pln != 4) {
889                 if (IS_VLAN_ARP(skb))
890                         nf_bridge_push_encap_header(skb);
891                 return NF_ACCEPT;
892         }
893         *d = state->in;
894         NF_HOOK(NFPROTO_ARP, NF_ARP_FORWARD, state->sk, skb,
895                 state->in, state->out, br_nf_forward_finish);
896
897         return NF_STOLEN;
898 }
899
900 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV4) || IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
901 static int br_nf_push_frag_xmit(struct sock *sk, struct sk_buff *skb)
902 {
903         struct brnf_frag_data *data;
904         int err;
905
906         data = this_cpu_ptr(&brnf_frag_data_storage);
907         err = skb_cow_head(skb, data->size);
908
909         if (err) {
910                 kfree_skb(skb);
911                 return 0;
912         }
913
914         if (data->vlan_tci) {
915                 skb->vlan_tci = data->vlan_tci;
916                 skb->vlan_proto = data->vlan_proto;
917         }
918
919         skb_copy_to_linear_data_offset(skb, -data->size, data->mac, data->size);
920         __skb_push(skb, data->encap_size);
921
922         nf_bridge_info_free(skb);
923         return br_dev_queue_push_xmit(sk, skb);
924 }
925 #endif
926
927 static int br_nf_ip_fragment(struct sock *sk, struct sk_buff *skb,
928                              int (*output)(struct sock *, struct sk_buff *))
929 {
930         unsigned int mtu = ip_skb_dst_mtu(skb);
931         struct iphdr *iph = ip_hdr(skb);
932         struct rtable *rt = skb_rtable(skb);
933         struct net_device *dev = rt->dst.dev;
934
935         if (unlikely(((iph->frag_off & htons(IP_DF)) && !skb->ignore_df) ||
936                      (IPCB(skb)->frag_max_size &&
937                       IPCB(skb)->frag_max_size > mtu))) {
938                 IP_INC_STATS(dev_net(dev), IPSTATS_MIB_FRAGFAILS);
939                 kfree_skb(skb);
940                 return -EMSGSIZE;
941         }
942
943         return ip_do_fragment(sk, skb, output);
944 }
945
946 static unsigned int nf_bridge_mtu_reduction(const struct sk_buff *skb)
947 {
948         if (skb->nf_bridge->orig_proto == BRNF_PROTO_PPPOE)
949                 return PPPOE_SES_HLEN;
950         return 0;
951 }
952
953 static int br_nf_dev_queue_xmit(struct sock *sk, struct sk_buff *skb)
954 {
955         struct nf_bridge_info *nf_bridge;
956         unsigned int mtu_reserved;
957
958         mtu_reserved = nf_bridge_mtu_reduction(skb);
959
960         if (skb_is_gso(skb) || skb->len + mtu_reserved <= skb->dev->mtu) {
961                 nf_bridge_info_free(skb);
962                 return br_dev_queue_push_xmit(sk, skb);
963         }
964
965         nf_bridge = nf_bridge_info_get(skb);
966
967 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV4)
968         /* This is wrong! We should preserve the original fragment
969          * boundaries by preserving frag_list rather than refragmenting.
970          */
971         if (skb->protocol == htons(ETH_P_IP)) {
972                 struct brnf_frag_data *data;
973
974                 if (br_validate_ipv4(skb))
975                         return NF_DROP;
976
977                 IPCB(skb)->frag_max_size = nf_bridge->frag_max_size;
978
979                 nf_bridge_update_protocol(skb);
980
981                 data = this_cpu_ptr(&brnf_frag_data_storage);
982
983                 data->vlan_tci = skb->vlan_tci;
984                 data->vlan_proto = skb->vlan_proto;
985                 data->encap_size = nf_bridge_encap_header_len(skb);
986                 data->size = ETH_HLEN + data->encap_size;
987
988                 skb_copy_from_linear_data_offset(skb, -data->size, data->mac,
989                                                  data->size);
990
991                 return br_nf_ip_fragment(sk, skb, br_nf_push_frag_xmit);
992         }
993 #endif
994 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
995         if (skb->protocol == htons(ETH_P_IPV6)) {
996                 const struct nf_ipv6_ops *v6ops = nf_get_ipv6_ops();
997                 struct brnf_frag_data *data;
998
999                 if (br_validate_ipv6(skb))
1000                         return NF_DROP;
1001
1002                 IP6CB(skb)->frag_max_size = nf_bridge->frag_max_size;
1003
1004                 nf_bridge_update_protocol(skb);
1005
1006                 data = this_cpu_ptr(&brnf_frag_data_storage);
1007                 data->encap_size = nf_bridge_encap_header_len(skb);
1008                 data->size = ETH_HLEN + data->encap_size;
1009
1010                 skb_copy_from_linear_data_offset(skb, -data->size, data->mac,
1011                                                  data->size);
1012
1013                 if (v6ops)
1014                         return v6ops->fragment(sk, skb, br_nf_push_frag_xmit);
1015                 else
1016                         return -EMSGSIZE;
1017         }
1018 #endif
1019         nf_bridge_info_free(skb);
1020         return br_dev_queue_push_xmit(sk, skb);
1021 }
1022
1023 /* PF_BRIDGE/POST_ROUTING ********************************************/
1024 static unsigned int br_nf_post_routing(const struct nf_hook_ops *ops,
1025                                        struct sk_buff *skb,
1026                                        const struct nf_hook_state *state)
1027 {
1028         struct nf_bridge_info *nf_bridge = nf_bridge_info_get(skb);
1029         struct net_device *realoutdev = bridge_parent(skb->dev);
1030         u_int8_t pf;
1031
1032         /* if nf_bridge is set, but ->physoutdev is NULL, this packet came in
1033          * on a bridge, but was delivered locally and is now being routed:
1034          *
1035          * POST_ROUTING was already invoked from the ip stack.
1036          */
1037         if (!nf_bridge || !nf_bridge->physoutdev)
1038                 return NF_ACCEPT;
1039
1040         if (!realoutdev)
1041                 return NF_DROP;
1042
1043         if (IS_IP(skb) || IS_VLAN_IP(skb) || IS_PPPOE_IP(skb))
1044                 pf = NFPROTO_IPV4;
1045         else if (IS_IPV6(skb) || IS_VLAN_IPV6(skb) || IS_PPPOE_IPV6(skb))
1046                 pf = NFPROTO_IPV6;
1047         else
1048                 return NF_ACCEPT;
1049
1050         /* We assume any code from br_dev_queue_push_xmit onwards doesn't care
1051          * about the value of skb->pkt_type. */
1052         if (skb->pkt_type == PACKET_OTHERHOST) {
1053                 skb->pkt_type = PACKET_HOST;
1054                 nf_bridge->pkt_otherhost = true;
1055         }
1056
1057         nf_bridge_pull_encap_header(skb);
1058         if (pf == NFPROTO_IPV4)
1059                 skb->protocol = htons(ETH_P_IP);
1060         else
1061                 skb->protocol = htons(ETH_P_IPV6);
1062
1063         NF_HOOK(pf, NF_INET_POST_ROUTING, state->sk, skb,
1064                 NULL, realoutdev,
1065                 br_nf_dev_queue_xmit);
1066
1067         return NF_STOLEN;
1068 }
1069
1070 /* IP/SABOTAGE *****************************************************/
1071 /* Don't hand locally destined packets to PF_INET(6)/PRE_ROUTING
1072  * for the second time. */
1073 static unsigned int ip_sabotage_in(const struct nf_hook_ops *ops,
1074                                    struct sk_buff *skb,
1075                                    const struct nf_hook_state *state)
1076 {
1077         if (skb->nf_bridge &&
1078             !(skb->nf_bridge->mask & BRNF_NF_BRIDGE_PREROUTING)) {
1079                 return NF_STOP;
1080         }
1081
1082         return NF_ACCEPT;
1083 }
1084
1085 /* This is called when br_netfilter has called into iptables/netfilter,
1086  * and DNAT has taken place on a bridge-forwarded packet.
1087  *
1088  * neigh->output has created a new MAC header, with local br0 MAC
1089  * as saddr.
1090  *
1091  * This restores the original MAC saddr of the bridged packet
1092  * before invoking bridge forward logic to transmit the packet.
1093  */
1094 static void br_nf_pre_routing_finish_bridge_slow(struct sk_buff *skb)
1095 {
1096         struct nf_bridge_info *nf_bridge = nf_bridge_info_get(skb);
1097
1098         skb_pull(skb, ETH_HLEN);
1099         nf_bridge->mask &= ~BRNF_BRIDGED_DNAT;
1100
1101         BUILD_BUG_ON(sizeof(nf_bridge->neigh_header) != (ETH_HLEN - ETH_ALEN));
1102
1103         skb_copy_to_linear_data_offset(skb, -(ETH_HLEN - ETH_ALEN),
1104                                        nf_bridge->neigh_header,
1105                                        ETH_HLEN - ETH_ALEN);
1106         skb->dev = nf_bridge->physindev;
1107
1108         nf_bridge->physoutdev = NULL;
1109         br_handle_frame_finish(NULL, skb);
1110 }
1111
1112 static int br_nf_dev_xmit(struct sk_buff *skb)
1113 {
1114         if (skb->nf_bridge && (skb->nf_bridge->mask & BRNF_BRIDGED_DNAT)) {
1115                 br_nf_pre_routing_finish_bridge_slow(skb);
1116                 return 1;
1117         }
1118         return 0;
1119 }
1120
1121 static const struct nf_br_ops br_ops = {
1122         .br_dev_xmit_hook =     br_nf_dev_xmit,
1123 };
1124
1125 void br_netfilter_enable(void)
1126 {
1127 }
1128 EXPORT_SYMBOL_GPL(br_netfilter_enable);
1129
1130 /* For br_nf_post_routing, we need (prio = NF_BR_PRI_LAST), because
1131  * br_dev_queue_push_xmit is called afterwards */
1132 static struct nf_hook_ops br_nf_ops[] __read_mostly = {
1133         {
1134                 .hook = br_nf_pre_routing,
1135                 .owner = THIS_MODULE,
1136                 .pf = NFPROTO_BRIDGE,
1137                 .hooknum = NF_BR_PRE_ROUTING,
1138                 .priority = NF_BR_PRI_BRNF,
1139         },
1140         {
1141                 .hook = br_nf_local_in,
1142                 .owner = THIS_MODULE,
1143                 .pf = NFPROTO_BRIDGE,
1144                 .hooknum = NF_BR_LOCAL_IN,
1145                 .priority = NF_BR_PRI_BRNF,
1146         },
1147         {
1148                 .hook = br_nf_forward_ip,
1149                 .owner = THIS_MODULE,
1150                 .pf = NFPROTO_BRIDGE,
1151                 .hooknum = NF_BR_FORWARD,
1152                 .priority = NF_BR_PRI_BRNF - 1,
1153         },
1154         {
1155                 .hook = br_nf_forward_arp,
1156                 .owner = THIS_MODULE,
1157                 .pf = NFPROTO_BRIDGE,
1158                 .hooknum = NF_BR_FORWARD,
1159                 .priority = NF_BR_PRI_BRNF,
1160         },
1161         {
1162                 .hook = br_nf_post_routing,
1163                 .owner = THIS_MODULE,
1164                 .pf = NFPROTO_BRIDGE,
1165                 .hooknum = NF_BR_POST_ROUTING,
1166                 .priority = NF_BR_PRI_LAST,
1167         },
1168         {
1169                 .hook = ip_sabotage_in,
1170                 .owner = THIS_MODULE,
1171                 .pf = NFPROTO_IPV4,
1172                 .hooknum = NF_INET_PRE_ROUTING,
1173                 .priority = NF_IP_PRI_FIRST,
1174         },
1175         {
1176                 .hook = ip_sabotage_in,
1177                 .owner = THIS_MODULE,
1178                 .pf = NFPROTO_IPV6,
1179                 .hooknum = NF_INET_PRE_ROUTING,
1180                 .priority = NF_IP6_PRI_FIRST,
1181         },
1182 };
1183
1184 #ifdef CONFIG_SYSCTL
1185 static
1186 int brnf_sysctl_call_tables(struct ctl_table *ctl, int write,
1187                             void __user *buffer, size_t *lenp, loff_t *ppos)
1188 {
1189         int ret;
1190
1191         ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
1192
1193         if (write && *(int *)(ctl->data))
1194                 *(int *)(ctl->data) = 1;
1195         return ret;
1196 }
1197
1198 static struct ctl_table brnf_table[] = {
1199         {
1200                 .procname       = "bridge-nf-call-arptables",
1201                 .data           = &brnf_call_arptables,
1202                 .maxlen         = sizeof(int),
1203                 .mode           = 0644,
1204                 .proc_handler   = brnf_sysctl_call_tables,
1205         },
1206         {
1207                 .procname       = "bridge-nf-call-iptables",
1208                 .data           = &brnf_call_iptables,
1209                 .maxlen         = sizeof(int),
1210                 .mode           = 0644,
1211                 .proc_handler   = brnf_sysctl_call_tables,
1212         },
1213         {
1214                 .procname       = "bridge-nf-call-ip6tables",
1215                 .data           = &brnf_call_ip6tables,
1216                 .maxlen         = sizeof(int),
1217                 .mode           = 0644,
1218                 .proc_handler   = brnf_sysctl_call_tables,
1219         },
1220         {
1221                 .procname       = "bridge-nf-filter-vlan-tagged",
1222                 .data           = &brnf_filter_vlan_tagged,
1223                 .maxlen         = sizeof(int),
1224                 .mode           = 0644,
1225                 .proc_handler   = brnf_sysctl_call_tables,
1226         },
1227         {
1228                 .procname       = "bridge-nf-filter-pppoe-tagged",
1229                 .data           = &brnf_filter_pppoe_tagged,
1230                 .maxlen         = sizeof(int),
1231                 .mode           = 0644,
1232                 .proc_handler   = brnf_sysctl_call_tables,
1233         },
1234         {
1235                 .procname       = "bridge-nf-pass-vlan-input-dev",
1236                 .data           = &brnf_pass_vlan_indev,
1237                 .maxlen         = sizeof(int),
1238                 .mode           = 0644,
1239                 .proc_handler   = brnf_sysctl_call_tables,
1240         },
1241         { }
1242 };
1243 #endif
1244
1245 static int __init br_netfilter_init(void)
1246 {
1247         int ret;
1248
1249         ret = nf_register_hooks(br_nf_ops, ARRAY_SIZE(br_nf_ops));
1250         if (ret < 0)
1251                 return ret;
1252
1253 #ifdef CONFIG_SYSCTL
1254         brnf_sysctl_header = register_net_sysctl(&init_net, "net/bridge", brnf_table);
1255         if (brnf_sysctl_header == NULL) {
1256                 printk(KERN_WARNING
1257                        "br_netfilter: can't register to sysctl.\n");
1258                 nf_unregister_hooks(br_nf_ops, ARRAY_SIZE(br_nf_ops));
1259                 return -ENOMEM;
1260         }
1261 #endif
1262         RCU_INIT_POINTER(nf_br_ops, &br_ops);
1263         printk(KERN_NOTICE "Bridge firewalling registered\n");
1264         return 0;
1265 }
1266
1267 static void __exit br_netfilter_fini(void)
1268 {
1269         RCU_INIT_POINTER(nf_br_ops, NULL);
1270         nf_unregister_hooks(br_nf_ops, ARRAY_SIZE(br_nf_ops));
1271 #ifdef CONFIG_SYSCTL
1272         unregister_net_sysctl_table(brnf_sysctl_header);
1273 #endif
1274 }
1275
1276 module_init(br_netfilter_init);
1277 module_exit(br_netfilter_fini);
1278
1279 MODULE_LICENSE("GPL");
1280 MODULE_AUTHOR("Lennert Buytenhek <buytenh@gnu.org>");
1281 MODULE_AUTHOR("Bart De Schuymer <bdschuym@pandora.be>");
1282 MODULE_DESCRIPTION("Linux ethernet netfilter firewall bridge");