br_notify.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 "br_private.h"
  17. static int br_device_event(struct notifier_block *unused, unsigned long event, void *ptr);
  18. struct notifier_block br_device_notifier = {
  19. .notifier_call = br_device_event
  20. };
  21. /*
  22. * Handle changes in state of network devices enslaved to a bridge.
  23. *
  24. * Note: don't care about up/down if bridge itself is down, because
  25. * port state is checked when bridge is brought up.
  26. */
  27. static int br_device_event(struct notifier_block *unused, unsigned long event, void *ptr)
  28. {
  29. struct net_device *dev = ptr;
  30. struct net_bridge_port *p = dev->br_port;
  31. struct net_bridge *br;
  32. /* not a port of a bridge */
  33. if (p == NULL)
  34. return NOTIFY_DONE;
  35. br = p->br;
  36. spin_lock_bh(&br->lock);
  37. switch (event) {
  38. case NETDEV_CHANGEMTU:
  39. dev_set_mtu(br->dev, br_min_mtu(br));
  40. break;
  41. case NETDEV_CHANGEADDR:
  42. br_fdb_changeaddr(p, dev->dev_addr);
  43. br_stp_recalculate_bridge_id(br);
  44. break;
  45. case NETDEV_CHANGE:
  46. if (br->dev->flags & IFF_UP)
  47. schedule_delayed_work(&p->carrier_check, BR_PORT_DEBOUNCE);
  48. break;
  49. case NETDEV_FEAT_CHANGE:
  50. if (br->dev->flags & IFF_UP)
  51. br_features_recompute(br);
  52. /* could do recursive feature change notification
  53. * but who would care??
  54. */
  55. break;
  56. case NETDEV_DOWN:
  57. if (br->dev->flags & IFF_UP)
  58. br_stp_disable_port(p);
  59. break;
  60. case NETDEV_UP:
  61. if (netif_carrier_ok(dev) && (br->dev->flags & IFF_UP))
  62. br_stp_enable_port(p);
  63. break;
  64. case NETDEV_UNREGISTER:
  65. spin_unlock_bh(&br->lock);
  66. br_del_if(br, dev);
  67. goto done;
  68. }
  69. spin_unlock_bh(&br->lock);
  70. done:
  71. return NOTIFY_DONE;
  72. }