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