3 * Linux ethernet bridge
6 * Lennert Buytenhek <buytenh@gnu.org>
8 * $Id: br_forward.c,v 1.4 2001/08/14 22:05:57 davem 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 NF_HOOK(PF_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
56 static void __br_forward(struct net_bridge_port *to, struct sk_buff *skb)
58 struct net_device *indev;
62 skb->ip_summed = CHECKSUM_NONE;
64 NF_HOOK(PF_BRIDGE, NF_BR_FORWARD, skb, indev, skb->dev,
68 /* called under bridge lock */
69 void br_deliver(struct net_bridge_port *to, struct sk_buff *skb)
71 if (should_deliver(to, skb)) {
72 __br_deliver(to, skb);
79 /* called under bridge lock */
80 void br_forward(struct net_bridge_port *to, struct sk_buff *skb)
82 if (should_deliver(to, skb)) {
83 __br_forward(to, skb);
90 /* called under bridge lock */
91 static void br_flood(struct net_bridge *br, struct sk_buff *skb, int clone,
92 void (*__packet_hook)(struct net_bridge_port *p, struct sk_buff *skb))
94 struct net_bridge_port *p;
95 struct net_bridge_port *prev;
100 if ((skb2 = skb_clone(skb, GFP_ATOMIC)) == NULL) {
101 br->statistics.tx_dropped++;
112 if (should_deliver(p, skb)) {
114 struct sk_buff *skb2;
116 if ((skb2 = skb_clone(skb, GFP_ATOMIC)) == NULL) {
117 br->statistics.tx_dropped++;
122 __packet_hook(prev, skb2);
132 __packet_hook(prev, skb);
139 /* called under bridge lock */
140 void br_flood_deliver(struct net_bridge *br, struct sk_buff *skb, int clone)
142 br_flood(br, skb, clone, __br_deliver);
145 /* called under bridge lock */
146 void br_flood_forward(struct net_bridge *br, struct sk_buff *skb, int clone)
148 br_flood(br, skb, clone, __br_forward);