www.usr.com/support/gpl/USR9107_release.1.4.tar.gz
[bcm963xx.git] / kernel / linux / 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 int br_dev_xmit(struct sk_buff *skb, struct net_device *dev)
32 {
33         struct net_bridge *br = netdev_priv(dev);
34         const unsigned char *dest = skb->data;
35         struct net_bridge_fdb_entry *dst;
36
37         br->statistics.tx_packets++;
38         br->statistics.tx_bytes += skb->len;
39
40         skb->mac.raw = skb->data;
41         skb_pull(skb, ETH_HLEN);
42
43         rcu_read_lock();
44         if (dest[0] & 1) {
45 #if defined(CONFIG_MIPS_BRCM)
46                 if (!mc_forward(br, skb, dest, 0, 0))           
47 #endif
48                 br_flood_deliver(br, skb, 0);
49         }
50         else if ((dst = __br_fdb_get(br, dest)) != NULL)
51                 br_deliver(dst->dst, skb);
52         else
53                 br_flood_deliver(br, skb, 0);
54
55         rcu_read_unlock();
56         return 0;
57 }
58
59 static int br_dev_open(struct net_device *dev)
60 {
61         netif_start_queue(dev);
62
63         br_stp_enable_bridge(dev->priv);
64
65         return 0;
66 }
67
68 static void br_dev_set_multicast_list(struct net_device *dev)
69 {
70 }
71
72 static int br_dev_stop(struct net_device *dev)
73 {
74         br_stp_disable_bridge(dev->priv);
75
76         netif_stop_queue(dev);
77
78         return 0;
79 }
80
81 static int br_change_mtu(struct net_device *dev, int new_mtu)
82 {
83         if ((new_mtu < 68) || new_mtu > br_min_mtu(dev->priv))
84                 return -EINVAL;
85
86         dev->mtu = new_mtu;
87         return 0;
88 }
89
90 static int br_dev_accept_fastpath(struct net_device *dev, struct dst_entry *dst)
91 {
92         return -1;
93 }
94
95 void br_dev_setup(struct net_device *dev)
96 {
97         memset(dev->dev_addr, 0, ETH_ALEN);
98
99         ether_setup(dev);
100
101         dev->do_ioctl = br_dev_ioctl;
102         dev->get_stats = br_dev_get_stats;
103         dev->hard_start_xmit = br_dev_xmit;
104         dev->open = br_dev_open;
105         dev->set_multicast_list = br_dev_set_multicast_list;
106         dev->change_mtu = br_change_mtu;
107         dev->destructor = free_netdev;
108         SET_MODULE_OWNER(dev);
109         dev->stop = br_dev_stop;
110         dev->accept_fastpath = br_dev_accept_fastpath;
111         dev->tx_queue_len = 0;
112         dev->set_mac_address = NULL;
113         dev->priv_flags = IFF_EBRIDGE;
114 }