]> Pileus Git - ~andy/linux/blob - net/bridge/br_device.c
bridge: Add multicast start/stop hooks
[~andy/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  *      This program is free software; you can redistribute it and/or
9  *      modify it under the terms of the GNU General Public License
10  *      as published by the Free Software Foundation; either version
11  *      2 of the License, or (at your option) any later version.
12  */
13
14 #include <linux/kernel.h>
15 #include <linux/netdevice.h>
16 #include <linux/etherdevice.h>
17 #include <linux/ethtool.h>
18
19 #include <asm/uaccess.h>
20 #include "br_private.h"
21
22 /* net device transmit always called with no BH (preempt_disabled) */
23 netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev)
24 {
25         struct net_bridge *br = netdev_priv(dev);
26         const unsigned char *dest = skb->data;
27         struct net_bridge_fdb_entry *dst;
28
29         BR_INPUT_SKB_CB(skb)->brdev = dev;
30
31         dev->stats.tx_packets++;
32         dev->stats.tx_bytes += skb->len;
33
34         skb_reset_mac_header(skb);
35         skb_pull(skb, ETH_HLEN);
36
37         if (dest[0] & 1)
38                 br_flood_deliver(br, skb);
39         else if ((dst = __br_fdb_get(br, dest)) != NULL)
40                 br_deliver(dst->dst, skb);
41         else
42                 br_flood_deliver(br, skb);
43
44         return NETDEV_TX_OK;
45 }
46
47 static int br_dev_open(struct net_device *dev)
48 {
49         struct net_bridge *br = netdev_priv(dev);
50
51         br_features_recompute(br);
52         netif_start_queue(dev);
53         br_stp_enable_bridge(br);
54         br_multicast_open(br);
55
56         return 0;
57 }
58
59 static void br_dev_set_multicast_list(struct net_device *dev)
60 {
61 }
62
63 static int br_dev_stop(struct net_device *dev)
64 {
65         struct net_bridge *br = netdev_priv(dev);
66
67         br_stp_disable_bridge(br);
68         br_multicast_stop(br);
69
70         netif_stop_queue(dev);
71
72         return 0;
73 }
74
75 static int br_change_mtu(struct net_device *dev, int new_mtu)
76 {
77         struct net_bridge *br = netdev_priv(dev);
78         if (new_mtu < 68 || new_mtu > br_min_mtu(br))
79                 return -EINVAL;
80
81         dev->mtu = new_mtu;
82
83 #ifdef CONFIG_BRIDGE_NETFILTER
84         /* remember the MTU in the rtable for PMTU */
85         br->fake_rtable.u.dst.metrics[RTAX_MTU - 1] = new_mtu;
86 #endif
87
88         return 0;
89 }
90
91 /* Allow setting mac address to any valid ethernet address. */
92 static int br_set_mac_address(struct net_device *dev, void *p)
93 {
94         struct net_bridge *br = netdev_priv(dev);
95         struct sockaddr *addr = p;
96
97         if (!is_valid_ether_addr(addr->sa_data))
98                 return -EINVAL;
99
100         spin_lock_bh(&br->lock);
101         memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
102         br_stp_change_bridge_id(br, addr->sa_data);
103         br->flags |= BR_SET_MAC_ADDR;
104         spin_unlock_bh(&br->lock);
105
106         return 0;
107 }
108
109 static void br_getinfo(struct net_device *dev, struct ethtool_drvinfo *info)
110 {
111         strcpy(info->driver, "bridge");
112         strcpy(info->version, BR_VERSION);
113         strcpy(info->fw_version, "N/A");
114         strcpy(info->bus_info, "N/A");
115 }
116
117 static int br_set_sg(struct net_device *dev, u32 data)
118 {
119         struct net_bridge *br = netdev_priv(dev);
120
121         if (data)
122                 br->feature_mask |= NETIF_F_SG;
123         else
124                 br->feature_mask &= ~NETIF_F_SG;
125
126         br_features_recompute(br);
127         return 0;
128 }
129
130 static int br_set_tso(struct net_device *dev, u32 data)
131 {
132         struct net_bridge *br = netdev_priv(dev);
133
134         if (data)
135                 br->feature_mask |= NETIF_F_TSO;
136         else
137                 br->feature_mask &= ~NETIF_F_TSO;
138
139         br_features_recompute(br);
140         return 0;
141 }
142
143 static int br_set_tx_csum(struct net_device *dev, u32 data)
144 {
145         struct net_bridge *br = netdev_priv(dev);
146
147         if (data)
148                 br->feature_mask |= NETIF_F_NO_CSUM;
149         else
150                 br->feature_mask &= ~NETIF_F_ALL_CSUM;
151
152         br_features_recompute(br);
153         return 0;
154 }
155
156 static const struct ethtool_ops br_ethtool_ops = {
157         .get_drvinfo    = br_getinfo,
158         .get_link       = ethtool_op_get_link,
159         .get_tx_csum    = ethtool_op_get_tx_csum,
160         .set_tx_csum    = br_set_tx_csum,
161         .get_sg         = ethtool_op_get_sg,
162         .set_sg         = br_set_sg,
163         .get_tso        = ethtool_op_get_tso,
164         .set_tso        = br_set_tso,
165         .get_ufo        = ethtool_op_get_ufo,
166         .set_ufo        = ethtool_op_set_ufo,
167         .get_flags      = ethtool_op_get_flags,
168 };
169
170 static const struct net_device_ops br_netdev_ops = {
171         .ndo_open                = br_dev_open,
172         .ndo_stop                = br_dev_stop,
173         .ndo_start_xmit          = br_dev_xmit,
174         .ndo_set_mac_address     = br_set_mac_address,
175         .ndo_set_multicast_list  = br_dev_set_multicast_list,
176         .ndo_change_mtu          = br_change_mtu,
177         .ndo_do_ioctl            = br_dev_ioctl,
178 };
179
180 void br_dev_setup(struct net_device *dev)
181 {
182         random_ether_addr(dev->dev_addr);
183         ether_setup(dev);
184
185         dev->netdev_ops = &br_netdev_ops;
186         dev->destructor = free_netdev;
187         SET_ETHTOOL_OPS(dev, &br_ethtool_ops);
188         dev->tx_queue_len = 0;
189         dev->priv_flags = IFF_EBRIDGE;
190
191         dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_HIGHDMA |
192                         NETIF_F_GSO_MASK | NETIF_F_NO_CSUM | NETIF_F_LLTX |
193                         NETIF_F_NETNS_LOCAL | NETIF_F_GSO;
194 }