3 * Linux ethernet bridge
6 * Lennert Buytenhek <buytenh@gnu.org>
8 * $Id: br_device.c,v 1.6 2001/12/24 00:59:55 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/ethtool.h>
21 #include <asm/uaccess.h>
22 #include "br_private.h"
24 /* net device transmit always called with no BH (preempt_disabled) */
25 int br_dev_xmit(struct sk_buff *skb, struct net_device *dev)
27 struct net_bridge *br = netdev_priv(dev);
28 const unsigned char *dest = skb->data;
29 struct net_bridge_fdb_entry *dst;
31 dev->stats.tx_packets++;
32 dev->stats.tx_bytes += skb->len;
34 skb_reset_mac_header(skb);
35 skb_pull(skb, ETH_HLEN);
38 br_flood_deliver(br, skb);
39 else if ((dst = __br_fdb_get(br, dest)) != NULL)
40 br_deliver(dst->dst, skb);
42 br_flood_deliver(br, skb);
47 static int br_dev_open(struct net_device *dev)
49 struct net_bridge *br = netdev_priv(dev);
51 br_features_recompute(br);
52 netif_start_queue(dev);
53 br_stp_enable_bridge(br);
58 static void br_dev_set_multicast_list(struct net_device *dev)
62 static int br_dev_stop(struct net_device *dev)
64 br_stp_disable_bridge(netdev_priv(dev));
66 netif_stop_queue(dev);
71 static int br_change_mtu(struct net_device *dev, int new_mtu)
73 if (new_mtu < 68 || new_mtu > br_min_mtu(netdev_priv(dev)))
80 /* Allow setting mac address to any valid ethernet address. */
81 static int br_set_mac_address(struct net_device *dev, void *p)
83 struct net_bridge *br = netdev_priv(dev);
84 struct sockaddr *addr = p;
86 if (!is_valid_ether_addr(addr->sa_data))
89 spin_lock_bh(&br->lock);
90 memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
91 br_stp_change_bridge_id(br, addr->sa_data);
92 spin_unlock_bh(&br->lock);
97 static void br_getinfo(struct net_device *dev, struct ethtool_drvinfo *info)
99 strcpy(info->driver, "bridge");
100 strcpy(info->version, BR_VERSION);
101 strcpy(info->fw_version, "N/A");
102 strcpy(info->bus_info, "N/A");
105 static int br_set_sg(struct net_device *dev, u32 data)
107 struct net_bridge *br = netdev_priv(dev);
110 br->feature_mask |= NETIF_F_SG;
112 br->feature_mask &= ~NETIF_F_SG;
114 br_features_recompute(br);
118 static int br_set_tso(struct net_device *dev, u32 data)
120 struct net_bridge *br = netdev_priv(dev);
123 br->feature_mask |= NETIF_F_TSO;
125 br->feature_mask &= ~NETIF_F_TSO;
127 br_features_recompute(br);
131 static int br_set_tx_csum(struct net_device *dev, u32 data)
133 struct net_bridge *br = netdev_priv(dev);
136 br->feature_mask |= NETIF_F_NO_CSUM;
138 br->feature_mask &= ~NETIF_F_ALL_CSUM;
140 br_features_recompute(br);
144 static struct ethtool_ops br_ethtool_ops = {
145 .get_drvinfo = br_getinfo,
146 .get_link = ethtool_op_get_link,
148 .set_tx_csum = br_set_tx_csum,
149 .set_tso = br_set_tso,
152 void br_dev_setup(struct net_device *dev)
154 random_ether_addr(dev->dev_addr);
157 dev->do_ioctl = br_dev_ioctl;
158 dev->hard_start_xmit = br_dev_xmit;
159 dev->open = br_dev_open;
160 dev->set_multicast_list = br_dev_set_multicast_list;
161 dev->change_mtu = br_change_mtu;
162 dev->destructor = free_netdev;
163 SET_ETHTOOL_OPS(dev, &br_ethtool_ops);
164 dev->stop = br_dev_stop;
165 dev->tx_queue_len = 0;
166 dev->set_mac_address = br_set_mac_address;
167 dev->priv_flags = IFF_EBRIDGE;
169 dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_HIGHDMA |
170 NETIF_F_GSO_MASK | NETIF_F_NO_CSUM | NETIF_F_LLTX;