2 * Handle incoming frames
3 * Linux ethernet bridge
6 * Lennert Buytenhek <buytenh@gnu.org>
8 * $Id: br_input.c,v 1.1.1.1 2005/04/11 02:51:12 jack 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/etherdevice.h>
19 #include <linux/if_bridge.h>
20 #include <linux/netfilter_bridge.h>
21 #include "br_private.h"
23 unsigned char bridge_ula[6] = { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x00 };
24 extern long Packets; //jack20040813+
26 static int br_pass_frame_up_finish(struct sk_buff *skb)
28 #ifdef CONFIG_NETFILTER_DEBUG
36 static void br_pass_frame_up(struct net_bridge *br, struct sk_buff *skb)
38 struct net_device *indev;
40 br->statistics.rx_packets++;
41 Packets++; //jack20040813+
42 br->statistics.rx_bytes += skb->len;
46 skb->pkt_type = PACKET_HOST;
47 skb_push(skb, ETH_HLEN);
48 skb->protocol = eth_type_trans(skb, &br->dev);
50 NF_HOOK(PF_BRIDGE, NF_BR_LOCAL_IN, skb, indev, NULL,
51 br_pass_frame_up_finish);
54 static int br_handle_frame_finish(struct sk_buff *skb)
56 struct net_bridge *br;
58 struct net_bridge_fdb_entry *dst;
59 struct net_bridge_port *p;
62 dest = skb->mac.ethernet->h_dest;
64 p = skb->dev->br_port;
70 if (skb->dev->br_port == NULL)
74 if (br->dev.flags & IFF_PROMISC) {
77 skb2 = skb_clone(skb, GFP_ATOMIC);
80 br_pass_frame_up(br, skb2);
85 br_flood_forward(br, skb, !passedup);
87 br_pass_frame_up(br, skb);
91 dst = br_fdb_get(br, dest);
92 if (dst != NULL && dst->is_local) {
94 br_pass_frame_up(br, skb);
102 br_forward(dst->dst, skb);
107 br_flood_forward(br, skb, 0);
110 read_unlock(&br->lock);
114 read_unlock(&br->lock);
120 int br_handle_frame(struct sk_buff *skb)
122 struct net_bridge *br;
124 struct net_bridge_port *p;
126 dest = skb->mac.ethernet->h_dest;
128 p = skb->dev->br_port;
133 read_lock(&br->lock);
134 if (skb->dev->br_port == NULL)
137 if (!(br->dev.flags & IFF_UP) ||
138 p->state == BR_STATE_DISABLED)
141 if (skb->mac.ethernet->h_source[0] & 1)
144 if (p->state == BR_STATE_LEARNING ||
145 p->state == BR_STATE_FORWARDING)
146 br_fdb_insert(br, p, skb->mac.ethernet->h_source, 0);
148 if (br->stp_enabled &&
149 !memcmp(dest, bridge_ula, 5) &&
151 goto handle_special_frame;
153 if (p->state == BR_STATE_FORWARDING) {
154 if (br_should_route_hook && br_should_route_hook(&skb)) {
155 read_unlock(&br->lock);
159 NF_HOOK(PF_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL,
160 br_handle_frame_finish);
161 read_unlock(&br->lock);
166 read_unlock(&br->lock);
171 handle_special_frame:
173 br_stp_handle_bpdu(skb);
174 read_unlock(&br->lock);
178 read_unlock(&br->lock);