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/skbuff.h>
19 #include <linux/if_vlan.h>
20 #include <linux/netfilter_bridge.h>
21 #include "br_private.h"
23 static inline int should_deliver(const struct net_bridge_port *p,
24 const struct sk_buff *skb)
26 if (skb->dev == p->dev ||
27 p->state != BR_STATE_FORWARDING)
33 static inline unsigned packet_length(const struct sk_buff *skb)
35 return skb->len - (skb->protocol == htons(ETH_P_8021Q) ? VLAN_HLEN : 0);
38 int br_dev_queue_push_xmit(struct sk_buff *skb)
40 /* drop mtu oversized packets except tso */
41 if (packet_length(skb) > skb->dev->mtu && !skb_shinfo(skb)->tso_size)
44 #ifdef CONFIG_BRIDGE_NETFILTER
45 /* ip_refrag calls ip_fragment, doesn't copy the MAC header. */
46 nf_bridge_maybe_copy_header(skb);
48 skb_push(skb, ETH_HLEN);
56 int br_forward_finish(struct sk_buff *skb)
58 NF_HOOK(PF_BRIDGE, NF_BR_POST_ROUTING, skb, NULL, skb->dev,
59 br_dev_queue_push_xmit);
64 static void __br_deliver(const struct net_bridge_port *to, struct sk_buff *skb)
67 NF_HOOK(PF_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
71 static void __br_forward(const struct net_bridge_port *to, struct sk_buff *skb)
73 struct net_device *indev;
77 skb->ip_summed = CHECKSUM_NONE;
79 NF_HOOK(PF_BRIDGE, NF_BR_FORWARD, skb, indev, skb->dev,
83 /* called with rcu_read_lock */
84 void br_deliver(const struct net_bridge_port *to, struct sk_buff *skb)
86 if (should_deliver(to, skb)) {
87 __br_deliver(to, skb);
94 /* called with rcu_read_lock */
95 void br_forward(const struct net_bridge_port *to, struct sk_buff *skb)
97 if (should_deliver(to, skb)) {
98 __br_forward(to, skb);
105 /* called under bridge lock */
106 static void br_flood(struct net_bridge *br, struct sk_buff *skb, int clone,
107 void (*__packet_hook)(const struct net_bridge_port *p,
108 struct sk_buff *skb))
110 struct net_bridge_port *p;
111 struct net_bridge_port *prev;
114 struct sk_buff *skb2;
116 if ((skb2 = skb_clone(skb, GFP_ATOMIC)) == NULL) {
117 br->statistics.tx_dropped++;
126 list_for_each_entry_rcu(p, &br->port_list, list) {
127 if (should_deliver(p, skb)) {
129 struct sk_buff *skb2;
131 if ((skb2 = skb_clone(skb, GFP_ATOMIC)) == NULL) {
132 br->statistics.tx_dropped++;
137 __packet_hook(prev, skb2);
145 __packet_hook(prev, skb);
153 /* called with rcu_read_lock */
154 void br_flood_deliver(struct net_bridge *br, struct sk_buff *skb, int clone)
156 br_flood(br, skb, clone, __br_deliver);
159 /* called under bridge lock */
160 void br_flood_forward(struct net_bridge *br, struct sk_buff *skb, int clone)
162 br_flood(br, skb, clone, __br_forward);