br_notify.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Device event handling
  3. * Linux ethernet bridge
  4. *
  5. * Authors:
  6. * Lennert Buytenhek <buytenh@gnu.org>
  7. *
  8. * $Id: br_notify.c,v 1.2 2000/02/21 15:51:34 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/rtnetlink.h>
  17. #include <net/net_namespace.h>
  18. #include "br_private.h"
  19. static int br_device_event(struct notifier_block *unused, unsigned long event, void *ptr);
  20. struct notifier_block br_device_notifier = {
  21. .notifier_call = br_device_event
  22. };
  23. /*
  24. * Handle changes in state of network devices enslaved to a bridge.
  25. *
  26. * Note: don't care about up/down if bridge itself is down, because
  27. * port state is checked when bridge is brought up.
  28. */
  29. static int br_device_event(struct notifier_block *unused, unsigned long event, void *ptr)
  30. {
  31. struct net_device *dev = ptr;
  32. struct net_bridge_port *p = dev->br_port;
  33. struct net_bridge *br;
  34. if (dev->nd_net != &init_net)
  35. return NOTIFY_DONE;
  36. /* not a port of a bridge */
  37. if (p == NULL)
  38. return NOTIFY_DONE;
  39. br = p->br;
  40. switch (event) {
  41. case NETDEV_CHANGEMTU:
  42. dev_set_mtu(br->dev, br_min_mtu(br));
  43. break;
  44. case NETDEV_CHANGEADDR:
  45. spin_lock_bh(&br->lock);
  46. br_fdb_changeaddr(p, dev->dev_addr);
  47. br_stp_recalculate_bridge_id(br);
  48. spin_unlock_bh(&br->lock);
  49. break;
  50. case NETDEV_CHANGE:
  51. br_port_carrier_check(p);
  52. break;
  53. case NETDEV_FEAT_CHANGE:
  54. spin_lock_bh(&br->lock);
  55. if (netif_running(br->dev))
  56. br_features_recompute(br);
  57. spin_unlock_bh(&br->lock);
  58. break;
  59. case NETDEV_DOWN:
  60. spin_lock_bh(&br->lock);
  61. if (br->dev->flags & IFF_UP)
  62. br_stp_disable_port(p);
  63. spin_unlock_bh(&br->lock);
  64. break;
  65. case NETDEV_UP:
  66. if (netif_carrier_ok(dev) && (br->dev->flags & IFF_UP)) {
  67. spin_lock_bh(&br->lock);
  68. br_stp_enable_port(p);
  69. spin_unlock_bh(&br->lock);
  70. }
  71. break;
  72. case NETDEV_UNREGISTER:
  73. br_del_if(br, dev);
  74. break;
  75. }
  76. /* Events that may cause spanning tree to refresh */
  77. if (event == NETDEV_CHANGEADDR || event == NETDEV_UP ||
  78. event == NETDEV_CHANGE || event == NETDEV_DOWN)
  79. br_ifinfo_notify(RTM_NEWLINK, p);
  80. return NOTIFY_DONE;
  81. }