patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / net / bridge / br_device.c
1 /*
2  *      Device handling code
3  *      Linux ethernet bridge
4  *
5  *      Authors:
6  *      Lennert Buytenhek               <buytenh@gnu.org>
7  *
8  *      $Id: br_device.c,v 1.6 2001/12/24 00:59:55 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/module.h>
19 #include <asm/uaccess.h>
20 #include "br_private.h"
21
22 static struct net_device_stats *br_dev_get_stats(struct net_device *dev)
23 {
24         struct net_bridge *br;
25
26         br = dev->priv;
27
28         return &br->statistics;
29 }
30
31 static int __br_dev_xmit(struct sk_buff *skb, struct net_device *dev)
32 {
33         struct net_bridge *br;
34         unsigned char *dest;
35         struct net_bridge_fdb_entry *dst;
36
37         br = dev->priv;
38         br->statistics.tx_packets++;
39         br->statistics.tx_bytes += skb->len;
40
41         dest = skb->mac.raw = skb->data;
42         skb_pull(skb, ETH_HLEN);
43
44         if (dest[0] & 1) {
45                 br_flood_deliver(br, skb, 0);
46                 return 0;
47         }
48
49         if ((dst = br_fdb_get(br, dest)) != NULL) {
50                 br_deliver(dst->dst, skb);
51                 br_fdb_put(dst);
52                 return 0;
53         }
54
55         br_flood_deliver(br, skb, 0);
56         return 0;
57 }
58
59 int br_dev_xmit(struct sk_buff *skb, struct net_device *dev)
60 {
61         int ret;
62
63         rcu_read_lock();
64         ret = __br_dev_xmit(skb, dev);
65         rcu_read_unlock();
66
67         return ret;
68 }
69
70 static int br_dev_open(struct net_device *dev)
71 {
72         netif_start_queue(dev);
73
74         br_stp_enable_bridge(dev->priv);
75
76         return 0;
77 }
78
79 static void br_dev_set_multicast_list(struct net_device *dev)
80 {
81 }
82
83 static int br_dev_stop(struct net_device *dev)
84 {
85         br_stp_disable_bridge(dev->priv);
86
87         netif_stop_queue(dev);
88
89         return 0;
90 }
91
92 static int br_dev_accept_fastpath(struct net_device *dev, struct dst_entry *dst)
93 {
94         return -1;
95 }
96
97 void br_dev_setup(struct net_device *dev)
98 {
99         memset(dev->dev_addr, 0, ETH_ALEN);
100
101         ether_setup(dev);
102
103         dev->do_ioctl = br_dev_ioctl;
104         dev->get_stats = br_dev_get_stats;
105         dev->hard_start_xmit = br_dev_xmit;
106         dev->open = br_dev_open;
107         dev->set_multicast_list = br_dev_set_multicast_list;
108         dev->destructor = free_netdev;
109         SET_MODULE_OWNER(dev);
110         dev->stop = br_dev_stop;
111         dev->accept_fastpath = br_dev_accept_fastpath;
112         dev->tx_queue_len = 0;
113         dev->set_mac_address = NULL;
114         dev->priv_flags = IFF_EBRIDGE;
115 }