2 * Handle incoming frames
3 * Linux ethernet bridge
6 * Lennert Buytenhek <buytenh@gnu.org>
8 * $Id: br_input.c,v 1.9.2.1 2001/12/24 04:50:05 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/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 };
25 static int br_pass_frame_up_finish(struct sk_buff *skb)
32 static void br_pass_frame_up(struct net_bridge *br, struct sk_buff *skb)
34 struct net_device *indev;
36 br->statistics.rx_packets++;
37 br->statistics.rx_bytes += skb->len;
41 skb->pkt_type = PACKET_HOST;
42 skb_push(skb, ETH_HLEN);
43 skb->protocol = eth_type_trans(skb, &br->dev);
45 NF_HOOK(PF_BRIDGE, NF_BR_LOCAL_IN, skb, indev, NULL,
46 br_pass_frame_up_finish);
49 static int br_handle_frame_finish(struct sk_buff *skb)
51 struct net_bridge *br;
53 struct net_bridge_fdb_entry *dst;
54 struct net_bridge_port *p;
57 dest = skb->mac.ethernet->h_dest;
59 p = skb->dev->br_port;
65 if (skb->dev->br_port == NULL)
69 if (br->dev.flags & IFF_PROMISC) {
72 skb2 = skb_clone(skb, GFP_ATOMIC);
75 br_pass_frame_up(br, skb2);
80 br_flood_forward(br, skb, !passedup);
82 br_pass_frame_up(br, skb);
86 dst = br_fdb_get(br, dest);
87 if (dst != NULL && dst->is_local) {
89 br_pass_frame_up(br, skb);
97 br_forward(dst->dst, skb);
102 br_flood_forward(br, skb, 0);
105 read_unlock(&br->lock);
109 read_unlock(&br->lock);
115 void br_handle_frame(struct sk_buff *skb)
117 struct net_bridge *br;
119 struct net_bridge_port *p;
121 dest = skb->mac.ethernet->h_dest;
123 p = skb->dev->br_port;
128 read_lock(&br->lock);
129 if (skb->dev->br_port == NULL)
132 if (!(br->dev.flags & IFF_UP) ||
133 p->state == BR_STATE_DISABLED)
136 if (skb->mac.ethernet->h_source[0] & 1)
139 if (p->state == BR_STATE_LEARNING ||
140 p->state == BR_STATE_FORWARDING)
141 br_fdb_insert(br, p, skb->mac.ethernet->h_source, 0);
143 if (br->stp_enabled &&
144 !memcmp(dest, bridge_ula, 5) &&
146 goto handle_special_frame;
148 if (p->state == BR_STATE_FORWARDING) {
149 NF_HOOK(PF_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL,
150 br_handle_frame_finish);
151 read_unlock(&br->lock);
156 read_unlock(&br->lock);
161 handle_special_frame:
163 NF_HOOK(PF_BRIDGE, NF_BR_LOCAL_IN, skb, skb->dev,NULL,
165 read_unlock(&br->lock);
169 read_unlock(&br->lock);