br_device.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. #include <linux/kernel.h>
  16. #include <linux/netdevice.h>
  17. #include <linux/module.h>
  18. #include <asm/uaccess.h>
  19. #include "br_private.h"
  20. static struct net_device_stats *br_dev_get_stats(struct net_device *dev)
  21. {
  22. struct net_bridge *br = netdev_priv(dev);
  23. return &br->statistics;
  24. }
  25. int br_dev_xmit(struct sk_buff *skb, struct net_device *dev)
  26. {
  27. struct net_bridge *br = netdev_priv(dev);
  28. const unsigned char *dest = skb->data;
  29. struct net_bridge_fdb_entry *dst;
  30. br->statistics.tx_packets++;
  31. br->statistics.tx_bytes += skb->len;
  32. skb->mac.raw = skb->data;
  33. skb_pull(skb, ETH_HLEN);
  34. rcu_read_lock();
  35. if (dest[0] & 1)
  36. br_flood_deliver(br, skb, 0);
  37. else if ((dst = __br_fdb_get(br, dest)) != NULL)
  38. br_deliver(dst->dst, skb);
  39. else
  40. br_flood_deliver(br, skb, 0);
  41. rcu_read_unlock();
  42. return 0;
  43. }
  44. static int br_dev_open(struct net_device *dev)
  45. {
  46. struct net_bridge *br = netdev_priv(dev);
  47. br_features_recompute(br);
  48. netif_start_queue(dev);
  49. br_stp_enable_bridge(br);
  50. return 0;
  51. }
  52. static void br_dev_set_multicast_list(struct net_device *dev)
  53. {
  54. }
  55. static int br_dev_stop(struct net_device *dev)
  56. {
  57. br_stp_disable_bridge(netdev_priv(dev));
  58. netif_stop_queue(dev);
  59. return 0;
  60. }
  61. static int br_change_mtu(struct net_device *dev, int new_mtu)
  62. {
  63. if (new_mtu < 68 || new_mtu > br_min_mtu(netdev_priv(dev)))
  64. return -EINVAL;
  65. dev->mtu = new_mtu;
  66. return 0;
  67. }
  68. void br_dev_setup(struct net_device *dev)
  69. {
  70. memset(dev->dev_addr, 0, ETH_ALEN);
  71. ether_setup(dev);
  72. dev->do_ioctl = br_dev_ioctl;
  73. dev->get_stats = br_dev_get_stats;
  74. dev->hard_start_xmit = br_dev_xmit;
  75. dev->open = br_dev_open;
  76. dev->set_multicast_list = br_dev_set_multicast_list;
  77. dev->change_mtu = br_change_mtu;
  78. dev->destructor = free_netdev;
  79. SET_MODULE_OWNER(dev);
  80. dev->stop = br_dev_stop;
  81. dev->tx_queue_len = 0;
  82. dev->set_mac_address = NULL;
  83. dev->priv_flags = IFF_EBRIDGE;
  84. }