sh: Runtime PM pdev hwblk - Migo-R
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / net / bridge / br_forward.c
blobd2c27c808d3bad3cb7b782f731c39345098c7df6
1 /*
2 * Forwarding decision
3 * Linux ethernet bridge
5 * Authors:
6 * Lennert Buytenhek <buytenh@gnu.org>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version
11 * 2 of the License, or (at your option) any later version.
14 #include <linux/kernel.h>
15 #include <linux/netdevice.h>
16 #include <linux/skbuff.h>
17 #include <linux/if_vlan.h>
18 #include <linux/netfilter_bridge.h>
19 #include "br_private.h"
21 /* Don't forward packets to originating port or forwarding diasabled */
22 static inline int should_deliver(const struct net_bridge_port *p,
23 const struct sk_buff *skb)
25 return (skb->dev != p->dev && p->state == BR_STATE_FORWARDING);
28 static inline unsigned packet_length(const struct sk_buff *skb)
30 return skb->len - (skb->protocol == htons(ETH_P_8021Q) ? VLAN_HLEN : 0);
33 int br_dev_queue_push_xmit(struct sk_buff *skb)
35 /* drop mtu oversized packets except gso */
36 if (packet_length(skb) > skb->dev->mtu && !skb_is_gso(skb))
37 kfree_skb(skb);
38 else {
39 /* ip_refrag calls ip_fragment, doesn't copy the MAC header. */
40 if (nf_bridge_maybe_copy_header(skb))
41 kfree_skb(skb);
42 else {
43 skb_push(skb, ETH_HLEN);
45 dev_queue_xmit(skb);
49 return 0;
52 int br_forward_finish(struct sk_buff *skb)
54 return NF_HOOK(PF_BRIDGE, NF_BR_POST_ROUTING, skb, NULL, skb->dev,
55 br_dev_queue_push_xmit);
59 static void __br_deliver(const struct net_bridge_port *to, struct sk_buff *skb)
61 skb->dev = to->dev;
62 NF_HOOK(PF_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
63 br_forward_finish);
66 static void __br_forward(const struct net_bridge_port *to, struct sk_buff *skb)
68 struct net_device *indev;
70 if (skb_warn_if_lro(skb)) {
71 kfree_skb(skb);
72 return;
75 indev = skb->dev;
76 skb->dev = to->dev;
77 skb_forward_csum(skb);
79 NF_HOOK(PF_BRIDGE, NF_BR_FORWARD, skb, indev, skb->dev,
80 br_forward_finish);
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);
88 return;
91 kfree_skb(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);
99 return;
102 kfree_skb(skb);
105 /* called under bridge lock */
106 static void br_flood(struct net_bridge *br, struct sk_buff *skb,
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;
113 prev = NULL;
115 list_for_each_entry_rcu(p, &br->port_list, list) {
116 if (should_deliver(p, skb)) {
117 if (prev != NULL) {
118 struct sk_buff *skb2;
120 if ((skb2 = skb_clone(skb, GFP_ATOMIC)) == NULL) {
121 br->dev->stats.tx_dropped++;
122 kfree_skb(skb);
123 return;
126 __packet_hook(prev, skb2);
129 prev = p;
133 if (prev != NULL) {
134 __packet_hook(prev, skb);
135 return;
138 kfree_skb(skb);
142 /* called with rcu_read_lock */
143 void br_flood_deliver(struct net_bridge *br, struct sk_buff *skb)
145 br_flood(br, skb, __br_deliver);
148 /* called under bridge lock */
149 void br_flood_forward(struct net_bridge *br, struct sk_buff *skb)
151 br_flood(br, skb, __br_forward);