1 /*
2 * Forwarding decision
3 * Linux ethernet bridge
4 *
5 * Authors:
6 * Lennert Buytenhek <buytenh@gnu.org>
7 *
8 * $Id: br_forward.c,v 1.2 2000/02/21 15:51:33 davem Exp $
9 *
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.
14 */
15
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 "br_private.h"
22
23 static inline int should_forward(struct net_bridge_port *p, struct sk_buff *skb)
24 {
25 if (skb->dev == p->dev ||
26 p->state != BR_STATE_FORWARDING)
27 return 0;
28
29 return 1;
30 }
31
32 static void __br_forward(struct net_bridge_port *to, struct sk_buff *skb)
33 {
34 skb->dev = to->dev;
35 dev_queue_xmit(skb);
36 }
37
38 /* called under bridge lock */
39 void br_forward(struct net_bridge_port *to, struct sk_buff *skb)
40 {
41 if (should_forward(to, skb)) {
42 __br_forward(to, skb);
43 return;
44 }
45
46 kfree_skb(skb);
47 }
48
49 /* called under bridge lock */
50 void br_flood(struct net_bridge *br, struct sk_buff *skb, int clone)
51 {
52 struct net_bridge_port *p;
53 struct net_bridge_port *prev;
54
55 if (clone) {
56 struct sk_buff *skb2;
57
58 if ((skb2 = skb_clone(skb, GFP_ATOMIC)) == NULL) {
59 br->statistics.tx_dropped++;
60 return;
61 }
62
63 skb = skb2;
64 }
65
66 prev = NULL;
67
68 p = br->port_list;
69 while (p != NULL) {
70 if (should_forward(p, skb)) {
71 if (prev != NULL) {
72 struct sk_buff *skb2;
73
74 if ((skb2 = skb_clone(skb, GFP_ATOMIC)) == NULL) {
75 br->statistics.tx_dropped++;
76 kfree_skb(skb);
77 return;
78 }
79
80 __br_forward(prev, skb2);
81 }
82
83 prev = p;
84 }
85
86 p = p->next;
87 }
88
89 if (prev != NULL) {
90 __br_forward(prev, skb);
91 return;
92 }
93
94 kfree_skb(skb);
95 }
96
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.