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 /* Don't forward packets to originating port or forwarding diasabled */
24 static inline int should_deliver(const struct net_bridge_port *p,
25 const struct sk_buff *skb)
27 return (skb->dev != p->dev && p->state == BR_STATE_FORWARDING);
30 static inline unsigned packet_length(const struct sk_buff *skb)
32 return skb->len - (skb->protocol == htons(ETH_P_8021Q) ? VLAN_HLEN : 0);
35 int br_dev_queue_push_xmit(struct sk_buff *skb)
37 /* drop mtu oversized packets except gso */
38 if (packet_length(skb) > skb->dev->mtu && !skb_is_gso(skb))
41 /* ip_refrag calls ip_fragment, doesn't copy the MAC header. */
42 if (nf_bridge_maybe_copy_header(skb))
45 skb_push(skb, ETH_HLEN);
54 int br_forward_finish(struct sk_buff *skb)
56 return NF_HOOK(PF_BRIDGE, NF_BR_POST_ROUTING, skb, NULL, skb->dev,
57 br_dev_queue_push_xmit);
61 static void __br_deliver(const struct net_bridge_port *to, struct sk_buff *skb)
64 NF_HOOK(PF_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
68 static void __br_forward(const struct net_bridge_port *to, struct sk_buff *skb)
70 struct net_device *indev;
74 skb_forward_csum(skb);
76 NF_HOOK(PF_BRIDGE, NF_BR_FORWARD, skb, indev, skb->dev,
80 /* called with rcu_read_lock */
81 void br_deliver(const struct net_bridge_port *to, struct sk_buff *skb)
83 if (should_deliver(to, skb)) {
84 __br_deliver(to, skb);
91 /* called with rcu_read_lock */
92 void br_forward(const struct net_bridge_port *to, struct sk_buff *skb)
94 if (should_deliver(to, skb)) {
95 __br_forward(to, skb);
102 /* called under bridge lock */
103 static void br_flood(struct net_bridge *br, struct sk_buff *skb,
104 void (*__packet_hook)(const struct net_bridge_port *p,
105 struct sk_buff *skb))
107 struct net_bridge_port *p;
108 struct net_bridge_port *prev;
112 list_for_each_entry_rcu(p, &br->port_list, list) {
113 if (should_deliver(p, skb)) {
115 struct sk_buff *skb2;
117 if ((skb2 = skb_clone(skb, GFP_ATOMIC)) == NULL) {
118 br->statistics.tx_dropped++;
123 __packet_hook(prev, skb2);
131 __packet_hook(prev, skb);
139 /* called with rcu_read_lock */
140 void br_flood_deliver(struct net_bridge *br, struct sk_buff *skb)
142 br_flood(br, skb, __br_deliver);
145 /* called under bridge lock */
146 void br_flood_forward(struct net_bridge *br, struct sk_buff *skb)
148 br_flood(br, skb, __br_forward);