br_notify.c 2.0 KB

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