3 * Linux ethernet bridge
6 * Lennert Buytenhek <buytenh@gnu.org>
7 * Bart De Schuymer (maintainer) <bdschuym@pandora.be>
10 * Apr 29 2003: physdev module support (bdschuym)
11 * Jun 19 2003: let arptables see bridged ARP traffic (bdschuym)
12 * Oct 06 2003: filter encapsulated IP/ARP VLAN traffic on untagged bridge
14 * Sep 01 2004: add IPv6 filtering (bdschuym)
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version
19 * 2 of the License, or (at your option) any later version.
21 * Lennert dedicates this file to Kerstin Wurdinger.
24 #include <linux/module.h>
25 #include <linux/kernel.h>
27 #include <linux/netdevice.h>
28 #include <linux/skbuff.h>
29 #include <linux/if_arp.h>
30 #include <linux/if_ether.h>
31 #include <linux/if_vlan.h>
32 #include <linux/if_pppox.h>
33 #include <linux/ppp_defs.h>
34 #include <linux/netfilter_bridge.h>
35 #include <linux/netfilter_ipv4.h>
36 #include <linux/netfilter_ipv6.h>
37 #include <linux/netfilter_arp.h>
38 #include <linux/in_route.h>
39 #include <linux/inetdevice.h>
43 #include <net/route.h>
45 #include <asm/uaccess.h>
46 #include "br_private.h"
48 #include <linux/sysctl.h>
51 #define skb_origaddr(skb) (((struct bridge_skb_cb *) \
52 (skb->nf_bridge->data))->daddr.ipv4)
53 #define store_orig_dstaddr(skb) (skb_origaddr(skb) = ip_hdr(skb)->daddr)
54 #define dnat_took_place(skb) (skb_origaddr(skb) != ip_hdr(skb)->daddr)
57 static struct ctl_table_header *brnf_sysctl_header;
58 static int brnf_call_iptables __read_mostly = 1;
59 static int brnf_call_ip6tables __read_mostly = 1;
60 static int brnf_call_arptables __read_mostly = 1;
61 static int brnf_filter_vlan_tagged __read_mostly = 1;
62 static int brnf_filter_pppoe_tagged __read_mostly = 1;
64 #define brnf_filter_vlan_tagged 1
65 #define brnf_filter_pppoe_tagged 1
68 static inline __be16 vlan_proto(const struct sk_buff *skb)
70 return vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
73 #define IS_VLAN_IP(skb) \
74 (skb->protocol == htons(ETH_P_8021Q) && \
75 vlan_proto(skb) == htons(ETH_P_IP) && \
76 brnf_filter_vlan_tagged)
78 #define IS_VLAN_IPV6(skb) \
79 (skb->protocol == htons(ETH_P_8021Q) && \
80 vlan_proto(skb) == htons(ETH_P_IPV6) &&\
81 brnf_filter_vlan_tagged)
83 #define IS_VLAN_ARP(skb) \
84 (skb->protocol == htons(ETH_P_8021Q) && \
85 vlan_proto(skb) == htons(ETH_P_ARP) && \
86 brnf_filter_vlan_tagged)
88 static inline __be16 pppoe_proto(const struct sk_buff *skb)
90 return *((__be16 *)(skb_mac_header(skb) + ETH_HLEN +
91 sizeof(struct pppoe_hdr)));
94 #define IS_PPPOE_IP(skb) \
95 (skb->protocol == htons(ETH_P_PPP_SES) && \
96 pppoe_proto(skb) == htons(PPP_IP) && \
97 brnf_filter_pppoe_tagged)
99 #define IS_PPPOE_IPV6(skb) \
100 (skb->protocol == htons(ETH_P_PPP_SES) && \
101 pppoe_proto(skb) == htons(PPP_IPV6) && \
102 brnf_filter_pppoe_tagged)
104 /* We need these fake structures to make netfilter happy --
105 * lots of places assume that skb->dst != NULL, which isn't
106 * all that unreasonable.
108 * Currently, we fill in the PMTU entry because netfilter
109 * refragmentation needs it, and the rt_flags entry because
110 * ipt_REJECT needs it. Future netfilter modules might
111 * require us to fill additional fields. */
112 static struct net_device __fake_net_device = {
113 .hard_header_len = ETH_HLEN
116 static struct rtable __fake_rtable = {
119 .__refcnt = ATOMIC_INIT(1),
120 .dev = &__fake_net_device,
121 .path = &__fake_rtable.u.dst,
122 .metrics = {[RTAX_MTU - 1] = 1500},
129 static inline struct net_device *bridge_parent(const struct net_device *dev)
131 struct net_bridge_port *port = rcu_dereference(dev->br_port);
133 return port ? port->br->dev : NULL;
136 static inline struct nf_bridge_info *nf_bridge_alloc(struct sk_buff *skb)
138 skb->nf_bridge = kzalloc(sizeof(struct nf_bridge_info), GFP_ATOMIC);
139 if (likely(skb->nf_bridge))
140 atomic_set(&(skb->nf_bridge->use), 1);
142 return skb->nf_bridge;
145 static inline void nf_bridge_push_encap_header(struct sk_buff *skb)
147 unsigned int len = nf_bridge_encap_header_len(skb);
150 skb->network_header -= len;
153 static inline void nf_bridge_pull_encap_header(struct sk_buff *skb)
155 unsigned int len = nf_bridge_encap_header_len(skb);
158 skb->network_header += len;
161 static inline void nf_bridge_pull_encap_header_rcsum(struct sk_buff *skb)
163 unsigned int len = nf_bridge_encap_header_len(skb);
165 skb_pull_rcsum(skb, len);
166 skb->network_header += len;
169 static inline void nf_bridge_save_header(struct sk_buff *skb)
171 int header_size = ETH_HLEN + nf_bridge_encap_header_len(skb);
173 skb_copy_from_linear_data_offset(skb, -header_size,
174 skb->nf_bridge->data, header_size);
178 * When forwarding bridge frames, we save a copy of the original
179 * header before processing.
181 int nf_bridge_copy_header(struct sk_buff *skb)
184 int header_size = ETH_HLEN + nf_bridge_encap_header_len(skb);
186 err = skb_cow_head(skb, header_size);
190 skb_copy_to_linear_data_offset(skb, -header_size,
191 skb->nf_bridge->data, header_size);
192 __skb_push(skb, nf_bridge_encap_header_len(skb));
196 /* PF_BRIDGE/PRE_ROUTING *********************************************/
197 /* Undo the changes made for ip6tables PREROUTING and continue the
198 * bridge PRE_ROUTING hook. */
199 static int br_nf_pre_routing_finish_ipv6(struct sk_buff *skb)
201 struct nf_bridge_info *nf_bridge = skb->nf_bridge;
203 if (nf_bridge->mask & BRNF_PKT_TYPE) {
204 skb->pkt_type = PACKET_OTHERHOST;
205 nf_bridge->mask ^= BRNF_PKT_TYPE;
207 nf_bridge->mask ^= BRNF_NF_BRIDGE_PREROUTING;
209 skb->dst = (struct dst_entry *)&__fake_rtable;
212 skb->dev = nf_bridge->physindev;
213 nf_bridge_push_encap_header(skb);
214 NF_HOOK_THRESH(PF_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL,
215 br_handle_frame_finish, 1);
220 static void __br_dnat_complain(void)
222 static unsigned long last_complaint;
224 if (jiffies - last_complaint >= 5 * HZ) {
225 printk(KERN_WARNING "Performing cross-bridge DNAT requires IP "
226 "forwarding to be enabled\n");
227 last_complaint = jiffies;
231 /* This requires some explaining. If DNAT has taken place,
232 * we will need to fix up the destination Ethernet address,
233 * and this is a tricky process.
235 * There are two cases to consider:
236 * 1. The packet was DNAT'ed to a device in the same bridge
237 * port group as it was received on. We can still bridge
239 * 2. The packet was DNAT'ed to a different device, either
240 * a non-bridged device or another bridge port group.
241 * The packet will need to be routed.
243 * The correct way of distinguishing between these two cases is to
244 * call ip_route_input() and to look at skb->dst->dev, which is
245 * changed to the destination device if ip_route_input() succeeds.
247 * Let us first consider the case that ip_route_input() succeeds:
249 * If skb->dst->dev equals the logical bridge device the packet
250 * came in on, we can consider this bridging. We then call
251 * skb->dst->output() which will make the packet enter br_nf_local_out()
252 * not much later. In that function it is assured that the iptables
253 * FORWARD chain is traversed for the packet.
255 * Otherwise, the packet is considered to be routed and we just
256 * change the destination MAC address so that the packet will
257 * later be passed up to the IP stack to be routed. For a redirected
258 * packet, ip_route_input() will give back the localhost as output device,
259 * which differs from the bridge device.
261 * Let us now consider the case that ip_route_input() fails:
263 * This can be because the destination address is martian, in which case
264 * the packet will be dropped.
265 * After a "echo '0' > /proc/sys/net/ipv4/ip_forward" ip_route_input()
266 * will fail, while __ip_route_output_key() will return success. The source
267 * address for __ip_route_output_key() is set to zero, so __ip_route_output_key
268 * thinks we're handling a locally generated packet and won't care
269 * if IP forwarding is allowed. We send a warning message to the users's
270 * log telling her to put IP forwarding on.
272 * ip_route_input() will also fail if there is no route available.
273 * In that case we just drop the packet.
275 * --Lennert, 20020411
276 * --Bart, 20020416 (updated)
277 * --Bart, 20021007 (updated)
278 * --Bart, 20062711 (updated) */
279 static int br_nf_pre_routing_finish_bridge(struct sk_buff *skb)
281 if (skb->pkt_type == PACKET_OTHERHOST) {
282 skb->pkt_type = PACKET_HOST;
283 skb->nf_bridge->mask |= BRNF_PKT_TYPE;
285 skb->nf_bridge->mask ^= BRNF_NF_BRIDGE_PREROUTING;
287 skb->dev = bridge_parent(skb->dev);
291 nf_bridge_pull_encap_header(skb);
292 skb->dst->output(skb);
297 static int br_nf_pre_routing_finish(struct sk_buff *skb)
299 struct net_device *dev = skb->dev;
300 struct iphdr *iph = ip_hdr(skb);
301 struct nf_bridge_info *nf_bridge = skb->nf_bridge;
304 if (nf_bridge->mask & BRNF_PKT_TYPE) {
305 skb->pkt_type = PACKET_OTHERHOST;
306 nf_bridge->mask ^= BRNF_PKT_TYPE;
308 nf_bridge->mask ^= BRNF_NF_BRIDGE_PREROUTING;
309 if (dnat_took_place(skb)) {
310 if ((err = ip_route_input(skb, iph->daddr, iph->saddr, iph->tos, dev))) {
317 .tos = RT_TOS(iph->tos) },
321 struct in_device *in_dev = in_dev_get(dev);
323 /* If err equals -EHOSTUNREACH the error is due to a
324 * martian destination or due to the fact that
325 * forwarding is disabled. For most martian packets,
326 * ip_route_output_key() will fail. It won't fail for 2 types of
327 * martian destinations: loopback destinations and destination
328 * 0.0.0.0. In both cases the packet will be dropped because the
329 * destination is the loopback device and not the bridge. */
330 if (err != -EHOSTUNREACH || !in_dev || IN_DEV_FORWARD(in_dev))
333 if (!ip_route_output_key(&rt, &fl)) {
334 /* - Bridged-and-DNAT'ed traffic doesn't
335 * require ip_forwarding. */
336 if (((struct dst_entry *)rt)->dev == dev) {
337 skb->dst = (struct dst_entry *)rt;
340 /* we are sure that forwarding is disabled, so printing
341 * this message is no problem. Note that the packet could
342 * still have a martian destination address, in which case
343 * the packet could be dropped even if forwarding were enabled */
344 __br_dnat_complain();
345 dst_release((struct dst_entry *)rt);
351 if (skb->dst->dev == dev) {
353 /* Tell br_nf_local_out this is a
355 nf_bridge->mask |= BRNF_BRIDGED_DNAT;
356 skb->dev = nf_bridge->physindev;
357 nf_bridge_push_encap_header(skb);
358 NF_HOOK_THRESH(PF_BRIDGE, NF_BR_PRE_ROUTING,
360 br_nf_pre_routing_finish_bridge,
364 memcpy(eth_hdr(skb)->h_dest, dev->dev_addr, ETH_ALEN);
365 skb->pkt_type = PACKET_HOST;
368 skb->dst = (struct dst_entry *)&__fake_rtable;
372 skb->dev = nf_bridge->physindev;
373 nf_bridge_push_encap_header(skb);
374 NF_HOOK_THRESH(PF_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL,
375 br_handle_frame_finish, 1);
380 /* Some common code for IPv4/IPv6 */
381 static struct net_device *setup_pre_routing(struct sk_buff *skb)
383 struct nf_bridge_info *nf_bridge = skb->nf_bridge;
385 if (skb->pkt_type == PACKET_OTHERHOST) {
386 skb->pkt_type = PACKET_HOST;
387 nf_bridge->mask |= BRNF_PKT_TYPE;
390 nf_bridge->mask |= BRNF_NF_BRIDGE_PREROUTING;
391 nf_bridge->physindev = skb->dev;
392 skb->dev = bridge_parent(skb->dev);
397 /* We only check the length. A bridge shouldn't do any hop-by-hop stuff anyway */
398 static int check_hbh_len(struct sk_buff *skb)
400 unsigned char *raw = (u8 *)(ipv6_hdr(skb) + 1);
402 const unsigned char *nh = skb_network_header(skb);
404 int len = (raw[1] + 1) << 3;
406 if ((raw + len) - skb->data > skb_headlen(skb))
413 int optlen = nh[off + 1] + 2;
424 if (nh[off + 1] != 4 || (off & 3) != 2)
426 pkt_len = ntohl(*(__be32 *) (nh + off + 2));
427 if (pkt_len <= IPV6_MAXPLEN ||
428 ipv6_hdr(skb)->payload_len)
430 if (pkt_len > skb->len - sizeof(struct ipv6hdr))
432 if (pskb_trim_rcsum(skb,
433 pkt_len + sizeof(struct ipv6hdr)))
435 nh = skb_network_header(skb);
452 /* Replicate the checks that IPv6 does on packet reception and pass the packet
453 * to ip6tables, which doesn't support NAT, so things are fairly simple. */
454 static unsigned int br_nf_pre_routing_ipv6(unsigned int hook,
456 const struct net_device *in,
457 const struct net_device *out,
458 int (*okfn)(struct sk_buff *))
463 if (skb->len < sizeof(struct ipv6hdr))
466 if (!pskb_may_pull(skb, sizeof(struct ipv6hdr)))
471 if (hdr->version != 6)
474 pkt_len = ntohs(hdr->payload_len);
476 if (pkt_len || hdr->nexthdr != NEXTHDR_HOP) {
477 if (pkt_len + sizeof(struct ipv6hdr) > skb->len)
479 if (pskb_trim_rcsum(skb, pkt_len + sizeof(struct ipv6hdr)))
482 if (hdr->nexthdr == NEXTHDR_HOP && check_hbh_len(skb))
485 nf_bridge_put(skb->nf_bridge);
486 if (!nf_bridge_alloc(skb))
488 if (!setup_pre_routing(skb))
491 NF_HOOK(PF_INET6, NF_IP6_PRE_ROUTING, skb, skb->dev, NULL,
492 br_nf_pre_routing_finish_ipv6);
500 /* Direct IPv6 traffic to br_nf_pre_routing_ipv6.
501 * Replicate the checks that IPv4 does on packet reception.
502 * Set skb->dev to the bridge device (i.e. parent of the
503 * receiving device) to make netfilter happy, the REDIRECT
504 * target in particular. Save the original destination IP
505 * address to be able to detect DNAT afterwards. */
506 static unsigned int br_nf_pre_routing(unsigned int hook, struct sk_buff *skb,
507 const struct net_device *in,
508 const struct net_device *out,
509 int (*okfn)(struct sk_buff *))
512 __u32 len = nf_bridge_encap_header_len(skb);
514 if (unlikely(!pskb_may_pull(skb, len)))
517 if (skb->protocol == htons(ETH_P_IPV6) || IS_VLAN_IPV6(skb) ||
518 IS_PPPOE_IPV6(skb)) {
520 if (!brnf_call_ip6tables)
523 nf_bridge_pull_encap_header_rcsum(skb);
524 return br_nf_pre_routing_ipv6(hook, skb, in, out, okfn);
527 if (!brnf_call_iptables)
531 if (skb->protocol != htons(ETH_P_IP) && !IS_VLAN_IP(skb) &&
535 nf_bridge_pull_encap_header_rcsum(skb);
537 if (!pskb_may_pull(skb, sizeof(struct iphdr)))
541 if (iph->ihl < 5 || iph->version != 4)
544 if (!pskb_may_pull(skb, 4 * iph->ihl))
548 if (ip_fast_csum((__u8 *) iph, iph->ihl) != 0)
551 len = ntohs(iph->tot_len);
552 if (skb->len < len || len < 4 * iph->ihl)
555 pskb_trim_rcsum(skb, len);
557 nf_bridge_put(skb->nf_bridge);
558 if (!nf_bridge_alloc(skb))
560 if (!setup_pre_routing(skb))
562 store_orig_dstaddr(skb);
564 NF_HOOK(PF_INET, NF_IP_PRE_ROUTING, skb, skb->dev, NULL,
565 br_nf_pre_routing_finish);
570 // IP_INC_STATS_BH(IpInHdrErrors);
576 /* PF_BRIDGE/LOCAL_IN ************************************************/
577 /* The packet is locally destined, which requires a real
578 * dst_entry, so detach the fake one. On the way up, the
579 * packet would pass through PRE_ROUTING again (which already
580 * took place when the packet entered the bridge), but we
581 * register an IPv4 PRE_ROUTING 'sabotage' hook that will
582 * prevent this from happening. */
583 static unsigned int br_nf_local_in(unsigned int hook, struct sk_buff *skb,
584 const struct net_device *in,
585 const struct net_device *out,
586 int (*okfn)(struct sk_buff *))
588 if (skb->dst == (struct dst_entry *)&__fake_rtable) {
589 dst_release(skb->dst);
596 /* PF_BRIDGE/FORWARD *************************************************/
597 static int br_nf_forward_finish(struct sk_buff *skb)
599 struct nf_bridge_info *nf_bridge = skb->nf_bridge;
600 struct net_device *in;
602 if (skb->protocol != htons(ETH_P_ARP) && !IS_VLAN_ARP(skb)) {
603 in = nf_bridge->physindev;
604 if (nf_bridge->mask & BRNF_PKT_TYPE) {
605 skb->pkt_type = PACKET_OTHERHOST;
606 nf_bridge->mask ^= BRNF_PKT_TYPE;
609 in = *((struct net_device **)(skb->cb));
611 nf_bridge_push_encap_header(skb);
612 NF_HOOK_THRESH(PF_BRIDGE, NF_BR_FORWARD, skb, in,
613 skb->dev, br_forward_finish, 1);
617 /* This is the 'purely bridged' case. For IP, we pass the packet to
618 * netfilter with indev and outdev set to the bridge device,
619 * but we are still able to filter on the 'real' indev/outdev
620 * because of the physdev module. For ARP, indev and outdev are the
622 static unsigned int br_nf_forward_ip(unsigned int hook, struct sk_buff *skb,
623 const struct net_device *in,
624 const struct net_device *out,
625 int (*okfn)(struct sk_buff *))
627 struct nf_bridge_info *nf_bridge;
628 struct net_device *parent;
634 parent = bridge_parent(out);
638 if (skb->protocol == htons(ETH_P_IP) || IS_VLAN_IP(skb) ||
644 nf_bridge_pull_encap_header(skb);
646 nf_bridge = skb->nf_bridge;
647 if (skb->pkt_type == PACKET_OTHERHOST) {
648 skb->pkt_type = PACKET_HOST;
649 nf_bridge->mask |= BRNF_PKT_TYPE;
652 /* The physdev module checks on this */
653 nf_bridge->mask |= BRNF_BRIDGED;
654 nf_bridge->physoutdev = skb->dev;
656 NF_HOOK(pf, NF_IP_FORWARD, skb, bridge_parent(in), parent,
657 br_nf_forward_finish);
662 static unsigned int br_nf_forward_arp(unsigned int hook, struct sk_buff *skb,
663 const struct net_device *in,
664 const struct net_device *out,
665 int (*okfn)(struct sk_buff *))
667 struct net_device **d = (struct net_device **)(skb->cb);
670 if (!brnf_call_arptables)
674 if (skb->protocol != htons(ETH_P_ARP)) {
675 if (!IS_VLAN_ARP(skb))
677 nf_bridge_pull_encap_header(skb);
680 if (arp_hdr(skb)->ar_pln != 4) {
681 if (IS_VLAN_ARP(skb))
682 nf_bridge_push_encap_header(skb);
685 *d = (struct net_device *)in;
686 NF_HOOK(NF_ARP, NF_ARP_FORWARD, skb, (struct net_device *)in,
687 (struct net_device *)out, br_nf_forward_finish);
692 /* PF_BRIDGE/LOCAL_OUT ***********************************************
694 * This function sees both locally originated IP packets and forwarded
695 * IP packets (in both cases the destination device is a bridge
696 * device). It also sees bridged-and-DNAT'ed packets.
698 * If (nf_bridge->mask & BRNF_BRIDGED_DNAT) then the packet is bridged
699 * and we fake the PF_BRIDGE/FORWARD hook. The function br_nf_forward()
700 * will then fake the PF_INET/FORWARD hook. br_nf_local_out() has priority
701 * NF_BR_PRI_FIRST, so no relevant PF_BRIDGE/INPUT functions have been nor
704 static unsigned int br_nf_local_out(unsigned int hook, struct sk_buff *skb,
705 const struct net_device *in,
706 const struct net_device *out,
707 int (*okfn)(struct sk_buff *))
709 struct net_device *realindev;
710 struct nf_bridge_info *nf_bridge;
715 nf_bridge = skb->nf_bridge;
716 if (!(nf_bridge->mask & BRNF_BRIDGED_DNAT))
719 /* Bridged, take PF_BRIDGE/FORWARD.
720 * (see big note in front of br_nf_pre_routing_finish) */
721 nf_bridge->physoutdev = skb->dev;
722 realindev = nf_bridge->physindev;
724 if (nf_bridge->mask & BRNF_PKT_TYPE) {
725 skb->pkt_type = PACKET_OTHERHOST;
726 nf_bridge->mask ^= BRNF_PKT_TYPE;
728 nf_bridge_push_encap_header(skb);
730 NF_HOOK(PF_BRIDGE, NF_BR_FORWARD, skb, realindev, skb->dev,
735 static int br_nf_dev_queue_xmit(struct sk_buff *skb)
737 if (skb->protocol == htons(ETH_P_IP) &&
738 skb->len > skb->dev->mtu &&
740 return ip_fragment(skb, br_dev_queue_push_xmit);
742 return br_dev_queue_push_xmit(skb);
745 /* PF_BRIDGE/POST_ROUTING ********************************************/
746 static unsigned int br_nf_post_routing(unsigned int hook, struct sk_buff *skb,
747 const struct net_device *in,
748 const struct net_device *out,
749 int (*okfn)(struct sk_buff *))
751 struct nf_bridge_info *nf_bridge = skb->nf_bridge;
752 struct net_device *realoutdev = bridge_parent(skb->dev);
755 #ifdef CONFIG_NETFILTER_DEBUG
756 /* Be very paranoid. This probably won't happen anymore, but let's
757 * keep the check just to be sure... */
758 if (skb_mac_header(skb) < skb->head ||
759 skb_mac_header(skb) + ETH_HLEN > skb->data) {
760 printk(KERN_CRIT "br_netfilter: Argh!! br_nf_post_routing: "
761 "bad mac.raw pointer.\n");
772 if (skb->protocol == htons(ETH_P_IP) || IS_VLAN_IP(skb) ||
778 #ifdef CONFIG_NETFILTER_DEBUG
779 if (skb->dst == NULL) {
780 printk(KERN_INFO "br_netfilter post_routing: skb->dst == NULL\n");
785 /* We assume any code from br_dev_queue_push_xmit onwards doesn't care
786 * about the value of skb->pkt_type. */
787 if (skb->pkt_type == PACKET_OTHERHOST) {
788 skb->pkt_type = PACKET_HOST;
789 nf_bridge->mask |= BRNF_PKT_TYPE;
792 nf_bridge_pull_encap_header(skb);
793 nf_bridge_save_header(skb);
795 #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
796 if (nf_bridge->netoutdev)
797 realoutdev = nf_bridge->netoutdev;
799 NF_HOOK(pf, NF_IP_POST_ROUTING, skb, NULL, realoutdev,
800 br_nf_dev_queue_xmit);
804 #ifdef CONFIG_NETFILTER_DEBUG
806 if (skb->dev != NULL) {
807 printk("[%s]", skb->dev->name);
809 printk("[%s]", realoutdev->name);
811 printk(" head:%p, raw:%p, data:%p\n", skb->head, skb_mac_header(skb),
818 /* IP/SABOTAGE *****************************************************/
819 /* Don't hand locally destined packets to PF_INET(6)/PRE_ROUTING
820 * for the second time. */
821 static unsigned int ip_sabotage_in(unsigned int hook, struct sk_buff *skb,
822 const struct net_device *in,
823 const struct net_device *out,
824 int (*okfn)(struct sk_buff *))
826 if (skb->nf_bridge &&
827 !(skb->nf_bridge->mask & BRNF_NF_BRIDGE_PREROUTING)) {
834 /* For br_nf_local_out we need (prio = NF_BR_PRI_FIRST), to insure that innocent
835 * PF_BRIDGE/NF_BR_LOCAL_OUT functions don't get bridged traffic as input.
836 * For br_nf_post_routing, we need (prio = NF_BR_PRI_LAST), because
837 * ip_refrag() can return NF_STOLEN. */
838 static struct nf_hook_ops br_nf_ops[] = {
839 { .hook = br_nf_pre_routing,
840 .owner = THIS_MODULE,
842 .hooknum = NF_BR_PRE_ROUTING,
843 .priority = NF_BR_PRI_BRNF, },
844 { .hook = br_nf_local_in,
845 .owner = THIS_MODULE,
847 .hooknum = NF_BR_LOCAL_IN,
848 .priority = NF_BR_PRI_BRNF, },
849 { .hook = br_nf_forward_ip,
850 .owner = THIS_MODULE,
852 .hooknum = NF_BR_FORWARD,
853 .priority = NF_BR_PRI_BRNF - 1, },
854 { .hook = br_nf_forward_arp,
855 .owner = THIS_MODULE,
857 .hooknum = NF_BR_FORWARD,
858 .priority = NF_BR_PRI_BRNF, },
859 { .hook = br_nf_local_out,
860 .owner = THIS_MODULE,
862 .hooknum = NF_BR_LOCAL_OUT,
863 .priority = NF_BR_PRI_FIRST, },
864 { .hook = br_nf_post_routing,
865 .owner = THIS_MODULE,
867 .hooknum = NF_BR_POST_ROUTING,
868 .priority = NF_BR_PRI_LAST, },
869 { .hook = ip_sabotage_in,
870 .owner = THIS_MODULE,
872 .hooknum = NF_IP_PRE_ROUTING,
873 .priority = NF_IP_PRI_FIRST, },
874 { .hook = ip_sabotage_in,
875 .owner = THIS_MODULE,
877 .hooknum = NF_IP6_PRE_ROUTING,
878 .priority = NF_IP6_PRI_FIRST, },
883 int brnf_sysctl_call_tables(ctl_table * ctl, int write, struct file *filp,
884 void __user * buffer, size_t * lenp, loff_t * ppos)
888 ret = proc_dointvec(ctl, write, filp, buffer, lenp, ppos);
890 if (write && *(int *)(ctl->data))
891 *(int *)(ctl->data) = 1;
895 static ctl_table brnf_table[] = {
897 .procname = "bridge-nf-call-arptables",
898 .data = &brnf_call_arptables,
899 .maxlen = sizeof(int),
901 .proc_handler = &brnf_sysctl_call_tables,
904 .procname = "bridge-nf-call-iptables",
905 .data = &brnf_call_iptables,
906 .maxlen = sizeof(int),
908 .proc_handler = &brnf_sysctl_call_tables,
911 .procname = "bridge-nf-call-ip6tables",
912 .data = &brnf_call_ip6tables,
913 .maxlen = sizeof(int),
915 .proc_handler = &brnf_sysctl_call_tables,
918 .procname = "bridge-nf-filter-vlan-tagged",
919 .data = &brnf_filter_vlan_tagged,
920 .maxlen = sizeof(int),
922 .proc_handler = &brnf_sysctl_call_tables,
925 .procname = "bridge-nf-filter-pppoe-tagged",
926 .data = &brnf_filter_pppoe_tagged,
927 .maxlen = sizeof(int),
929 .proc_handler = &brnf_sysctl_call_tables,
934 static ctl_table brnf_bridge_table[] = {
936 .ctl_name = NET_BRIDGE,
937 .procname = "bridge",
944 static ctl_table brnf_net_table[] = {
949 .child = brnf_bridge_table,
955 int __init br_netfilter_init(void)
959 ret = nf_register_hooks(br_nf_ops, ARRAY_SIZE(br_nf_ops));
963 brnf_sysctl_header = register_sysctl_table(brnf_net_table);
964 if (brnf_sysctl_header == NULL) {
966 "br_netfilter: can't register to sysctl.\n");
967 nf_unregister_hooks(br_nf_ops, ARRAY_SIZE(br_nf_ops));
971 printk(KERN_NOTICE "Bridge firewalling registered\n");
975 void br_netfilter_fini(void)
977 nf_unregister_hooks(br_nf_ops, ARRAY_SIZE(br_nf_ops));
979 unregister_sysctl_table(brnf_sysctl_header);