[PATCH] Fix sighand->siglock usage in kernel/acct.c
[linux-2.6/kmemtrace.git] / net / bridge / br_forward.c
blob6ccd32b308091dcd443f6ff00ab0aea2ad456e21
1 /*
2 * Forwarding decision
3 * Linux ethernet bridge
5 * Authors:
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))
39 kfree_skb(skb);
40 else {
41 #ifdef CONFIG_BRIDGE_NETFILTER
42 /* ip_refrag calls ip_fragment, doesn't copy the MAC header. */
43 nf_bridge_maybe_copy_header(skb);
44 #endif
45 skb_push(skb, ETH_HLEN);
47 dev_queue_xmit(skb);
50 return 0;
53 int br_forward_finish(struct sk_buff *skb)
55 return NF_HOOK(PF_BRIDGE, NF_BR_POST_ROUTING, skb, NULL, skb->dev,
56 br_dev_queue_push_xmit);
60 static void __br_deliver(const struct net_bridge_port *to, struct sk_buff *skb)
62 skb->dev = to->dev;
63 NF_HOOK(PF_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
64 br_forward_finish);
67 static void __br_forward(const struct net_bridge_port *to, struct sk_buff *skb)
69 struct net_device *indev;
71 indev = skb->dev;
72 skb->dev = to->dev;
73 skb->ip_summed = CHECKSUM_NONE;
75 NF_HOOK(PF_BRIDGE, NF_BR_FORWARD, skb, indev, skb->dev,
76 br_forward_finish);
79 /* called with rcu_read_lock */
80 void br_deliver(const struct net_bridge_port *to, struct sk_buff *skb)
82 if (should_deliver(to, skb)) {
83 __br_deliver(to, skb);
84 return;
87 kfree_skb(skb);
90 /* called with rcu_read_lock */
91 void br_forward(const struct net_bridge_port *to, struct sk_buff *skb)
93 if (should_deliver(to, skb)) {
94 __br_forward(to, skb);
95 return;
98 kfree_skb(skb);
101 /* called under bridge lock */
102 static void br_flood(struct net_bridge *br, struct sk_buff *skb, int clone,
103 void (*__packet_hook)(const struct net_bridge_port *p,
104 struct sk_buff *skb))
106 struct net_bridge_port *p;
107 struct net_bridge_port *prev;
109 if (clone) {
110 struct sk_buff *skb2;
112 if ((skb2 = skb_clone(skb, GFP_ATOMIC)) == NULL) {
113 br->statistics.tx_dropped++;
114 return;
117 skb = skb2;
120 prev = NULL;
122 list_for_each_entry_rcu(p, &br->port_list, list) {
123 if (should_deliver(p, skb)) {
124 if (prev != NULL) {
125 struct sk_buff *skb2;
127 if ((skb2 = skb_clone(skb, GFP_ATOMIC)) == NULL) {
128 br->statistics.tx_dropped++;
129 kfree_skb(skb);
130 return;
133 __packet_hook(prev, skb2);
136 prev = p;
140 if (prev != NULL) {
141 __packet_hook(prev, skb);
142 return;
145 kfree_skb(skb);
149 /* called with rcu_read_lock */
150 void br_flood_deliver(struct net_bridge *br, struct sk_buff *skb, int clone)
152 br_flood(br, skb, clone, __br_deliver);
155 /* called under bridge lock */
156 void br_flood_forward(struct net_bridge *br, struct sk_buff *skb, int clone)
158 br_flood(br, skb, clone, __br_forward);