br.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * Generic parts
  3. * Linux ethernet bridge
  4. *
  5. * Authors:
  6. * Lennert Buytenhek <buytenh@gnu.org>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version
  11. * 2 of the License, or (at your option) any later version.
  12. */
  13. #include <linux/module.h>
  14. #include <linux/kernel.h>
  15. #include <linux/netdevice.h>
  16. #include <linux/etherdevice.h>
  17. #include <linux/init.h>
  18. #include <linux/llc.h>
  19. #include <net/llc.h>
  20. #include <net/stp.h>
  21. #include "br_private.h"
  22. static void __net_exit br_net_exit(struct net *net)
  23. {
  24. struct net_device *dev;
  25. LIST_HEAD(list);
  26. rtnl_lock();
  27. for_each_netdev(net, dev)
  28. if (dev->priv_flags & IFF_EBRIDGE)
  29. br_dev_delete(dev, &list);
  30. unregister_netdevice_many(&list);
  31. rtnl_unlock();
  32. }
  33. static struct pernet_operations br_net_ops = {
  34. .exit = br_net_exit,
  35. };
  36. static const struct stp_proto br_stp_proto = {
  37. .rcv = br_stp_rcv,
  38. };
  39. static int __init br_init(void)
  40. {
  41. int err;
  42. err = stp_proto_register(&br_stp_proto);
  43. if (err < 0) {
  44. pr_err("bridge: can't register sap for STP\n");
  45. return err;
  46. }
  47. err = br_fdb_init();
  48. if (err)
  49. goto err_out;
  50. err = register_pernet_subsys(&br_net_ops);
  51. if (err)
  52. goto err_out1;
  53. err = br_netfilter_init();
  54. if (err)
  55. goto err_out2;
  56. err = register_netdevice_notifier(&br_device_notifier);
  57. if (err)
  58. goto err_out3;
  59. err = br_netlink_init();
  60. if (err)
  61. goto err_out4;
  62. brioctl_set(br_ioctl_deviceless_stub);
  63. #if IS_ENABLED(CONFIG_ATM_LANE)
  64. br_fdb_test_addr_hook = br_fdb_test_addr;
  65. #endif
  66. return 0;
  67. err_out4:
  68. unregister_netdevice_notifier(&br_device_notifier);
  69. err_out3:
  70. br_netfilter_fini();
  71. err_out2:
  72. unregister_pernet_subsys(&br_net_ops);
  73. err_out1:
  74. br_fdb_fini();
  75. err_out:
  76. stp_proto_unregister(&br_stp_proto);
  77. return err;
  78. }
  79. static void __exit br_deinit(void)
  80. {
  81. stp_proto_unregister(&br_stp_proto);
  82. br_netlink_fini();
  83. unregister_netdevice_notifier(&br_device_notifier);
  84. brioctl_set(NULL);
  85. unregister_pernet_subsys(&br_net_ops);
  86. rcu_barrier(); /* Wait for completion of call_rcu()'s */
  87. br_netfilter_fini();
  88. #if IS_ENABLED(CONFIG_ATM_LANE)
  89. br_fdb_test_addr_hook = NULL;
  90. #endif
  91. br_fdb_fini();
  92. }
  93. module_init(br_init)
  94. module_exit(br_deinit)
  95. MODULE_LICENSE("GPL");
  96. MODULE_VERSION(BR_VERSION);
  97. MODULE_ALIAS_RTNL_LINK("bridge");