br_device.c 2.2 KB

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