3 * Linux ethernet bridge
6 * Lennert Buytenhek <buytenh@gnu.org>
8 * $Id: br_forward.c,v 1.1.1.1 2005/04/11 02:51:12 jack Exp $
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version
13 * 2 of the License, or (at your option) any later version.
16 #include <linux/kernel.h>
17 #include <linux/netdevice.h>
18 #include <linux/inetdevice.h>
19 #include <linux/skbuff.h>
20 #include <linux/if_bridge.h>
21 #include <linux/netfilter_bridge.h>
22 #include "br_private.h"
24 static inline int should_deliver(struct net_bridge_port *p, struct sk_buff *skb)
26 if (skb->dev == p->dev ||
27 p->state != BR_STATE_FORWARDING)
33 static int __dev_queue_push_xmit(struct sk_buff *skb)
35 skb_push(skb, ETH_HLEN);
41 static int __br_forward_finish(struct sk_buff *skb)
43 NF_HOOK(PF_BRIDGE, NF_BR_POST_ROUTING, skb, NULL, skb->dev,
44 __dev_queue_push_xmit);
49 static void __br_deliver(struct net_bridge_port *to, struct sk_buff *skb)
52 #ifdef CONFIG_NETFILTER_DEBUG
55 NF_HOOK(PF_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
59 static void __br_forward(struct net_bridge_port *to, struct sk_buff *skb)
61 struct net_device *indev;
66 NF_HOOK(PF_BRIDGE, NF_BR_FORWARD, skb, indev, skb->dev,
70 /* called under bridge lock */
71 void br_deliver(struct net_bridge_port *to, struct sk_buff *skb)
73 if (should_deliver(to, skb)) {
74 __br_deliver(to, skb);
81 /* called under bridge lock */
82 void br_forward(struct net_bridge_port *to, struct sk_buff *skb)
84 if (should_deliver(to, skb)) {
85 __br_forward(to, skb);
92 /* called under bridge lock */
93 static void br_flood(struct net_bridge *br, struct sk_buff *skb, int clone,
94 void (*__packet_hook)(struct net_bridge_port *p, struct sk_buff *skb))
96 struct net_bridge_port *p;
97 struct net_bridge_port *prev;
100 struct sk_buff *skb2;
102 if ((skb2 = skb_clone(skb, GFP_ATOMIC)) == NULL) {
103 br->statistics.tx_dropped++;
114 if (should_deliver(p, skb)) {
116 struct sk_buff *skb2;
118 if ((skb2 = skb_clone(skb, GFP_ATOMIC)) == NULL) {
119 br->statistics.tx_dropped++;
124 __packet_hook(prev, skb2);
134 __packet_hook(prev, skb);
141 /* called under bridge lock */
142 void br_flood_deliver(struct net_bridge *br, struct sk_buff *skb, int clone)
144 br_flood(br, skb, clone, __br_deliver);
147 /* called under bridge lock */
148 void br_flood_forward(struct net_bridge *br, struct sk_buff *skb, int clone)
150 br_flood(br, skb, clone, __br_forward);