Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Generic parts |
| 3 | * Linux ethernet bridge |
| 4 | * |
| 5 | * Authors: |
| 6 | * Lennert Buytenhek <buytenh@gnu.org> |
| 7 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/module.h> |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/netdevice.h> |
| 17 | #include <linux/etherdevice.h> |
| 18 | #include <linux/init.h> |
Stephen Hemminger | cf0f02d | 2006-03-20 22:59:06 -0800 | [diff] [blame] | 19 | #include <linux/llc.h> |
| 20 | #include <net/llc.h> |
Patrick McHardy | 7c85fbf | 2008-07-05 21:25:56 -0700 | [diff] [blame] | 21 | #include <net/stp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
| 23 | #include "br_private.h" |
| 24 | |
WANG Cong | b86f81cc | 2014-01-10 13:58:47 -0800 | [diff] [blame] | 25 | static void __net_exit br_net_exit(struct net *net) |
| 26 | { |
| 27 | struct net_device *dev; |
| 28 | LIST_HEAD(list); |
| 29 | |
| 30 | rtnl_lock(); |
| 31 | for_each_netdev(net, dev) |
| 32 | if (dev->priv_flags & IFF_EBRIDGE) |
| 33 | br_dev_delete(dev, &list); |
| 34 | |
| 35 | unregister_netdevice_many(&list); |
| 36 | rtnl_unlock(); |
| 37 | |
| 38 | } |
Stephen Hemminger | cf0f02d | 2006-03-20 22:59:06 -0800 | [diff] [blame] | 39 | |
Alexey Dobriyan | 712d695 | 2008-09-08 16:20:18 -0700 | [diff] [blame] | 40 | static struct pernet_operations br_net_ops = { |
| 41 | .exit = br_net_exit, |
| 42 | }; |
| 43 | |
WANG Cong | b86f81cc | 2014-01-10 13:58:47 -0800 | [diff] [blame] | 44 | static const struct stp_proto br_stp_proto = { |
| 45 | .rcv = br_stp_rcv, |
| 46 | }; |
| 47 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | static int __init br_init(void) |
| 49 | { |
Stephen Hemminger | c090971 | 2006-05-25 15:59:33 -0700 | [diff] [blame] | 50 | int err; |
| 51 | |
Patrick McHardy | 7c85fbf | 2008-07-05 21:25:56 -0700 | [diff] [blame] | 52 | err = stp_proto_register(&br_stp_proto); |
| 53 | if (err < 0) { |
stephen hemminger | 28a16c9 | 2010-05-10 09:31:09 +0000 | [diff] [blame] | 54 | pr_err("bridge: can't register sap for STP\n"); |
Patrick McHardy | 7c85fbf | 2008-07-05 21:25:56 -0700 | [diff] [blame] | 55 | return err; |
Stephen Hemminger | cf0f02d | 2006-03-20 22:59:06 -0800 | [diff] [blame] | 56 | } |
| 57 | |
Akinobu Mita | 87a596e | 2007-04-07 18:57:07 +0900 | [diff] [blame] | 58 | err = br_fdb_init(); |
| 59 | if (err) |
Pavel Emelyanov | 17efdd4 | 2007-11-29 23:41:43 +1100 | [diff] [blame] | 60 | goto err_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
Alexey Dobriyan | 712d695 | 2008-09-08 16:20:18 -0700 | [diff] [blame] | 62 | err = register_pernet_subsys(&br_net_ops); |
Stephen Hemminger | c090971 | 2006-05-25 15:59:33 -0700 | [diff] [blame] | 63 | if (err) |
| 64 | goto err_out1; |
| 65 | |
Alexey Dobriyan | 712d695 | 2008-09-08 16:20:18 -0700 | [diff] [blame] | 66 | err = br_netfilter_init(); |
Stephen Hemminger | c090971 | 2006-05-25 15:59:33 -0700 | [diff] [blame] | 67 | if (err) |
| 68 | goto err_out2; |
| 69 | |
Alexey Dobriyan | 712d695 | 2008-09-08 16:20:18 -0700 | [diff] [blame] | 70 | err = register_netdevice_notifier(&br_device_notifier); |
Thomas Graf | 32fe21c | 2007-03-22 11:59:03 -0700 | [diff] [blame] | 71 | if (err) |
| 72 | goto err_out3; |
| 73 | |
Alexey Dobriyan | 712d695 | 2008-09-08 16:20:18 -0700 | [diff] [blame] | 74 | err = br_netlink_init(); |
| 75 | if (err) |
| 76 | goto err_out4; |
| 77 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | brioctl_set(br_ioctl_deviceless_stub); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
Igor Maravić | e6373c4 | 2011-12-12 02:58:25 +0000 | [diff] [blame] | 80 | #if IS_ENABLED(CONFIG_ATM_LANE) |
Michał Mirosław | da67829 | 2009-06-05 05:35:28 +0000 | [diff] [blame] | 81 | br_fdb_test_addr_hook = br_fdb_test_addr; |
| 82 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | return 0; |
Alexey Dobriyan | 712d695 | 2008-09-08 16:20:18 -0700 | [diff] [blame] | 85 | err_out4: |
Thomas Graf | 32fe21c | 2007-03-22 11:59:03 -0700 | [diff] [blame] | 86 | unregister_netdevice_notifier(&br_device_notifier); |
Alexey Dobriyan | 712d695 | 2008-09-08 16:20:18 -0700 | [diff] [blame] | 87 | err_out3: |
Stephen Hemminger | c090971 | 2006-05-25 15:59:33 -0700 | [diff] [blame] | 88 | br_netfilter_fini(); |
Alexey Dobriyan | 712d695 | 2008-09-08 16:20:18 -0700 | [diff] [blame] | 89 | err_out2: |
| 90 | unregister_pernet_subsys(&br_net_ops); |
Stephen Hemminger | c090971 | 2006-05-25 15:59:33 -0700 | [diff] [blame] | 91 | err_out1: |
Pavel Emelyanov | 17efdd4 | 2007-11-29 23:41:43 +1100 | [diff] [blame] | 92 | br_fdb_fini(); |
| 93 | err_out: |
Patrick McHardy | 7c85fbf | 2008-07-05 21:25:56 -0700 | [diff] [blame] | 94 | stp_proto_unregister(&br_stp_proto); |
Stephen Hemminger | c090971 | 2006-05-25 15:59:33 -0700 | [diff] [blame] | 95 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | static void __exit br_deinit(void) |
| 99 | { |
Patrick McHardy | 7c85fbf | 2008-07-05 21:25:56 -0700 | [diff] [blame] | 100 | stp_proto_unregister(&br_stp_proto); |
Stephen Hemminger | cf0f02d | 2006-03-20 22:59:06 -0800 | [diff] [blame] | 101 | |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 102 | br_netlink_fini(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | unregister_netdevice_notifier(&br_device_notifier); |
| 104 | brioctl_set(NULL); |
| 105 | |
Alexey Dobriyan | 712d695 | 2008-09-08 16:20:18 -0700 | [diff] [blame] | 106 | unregister_pernet_subsys(&br_net_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
Jesper Dangaard Brouer | 473c22d | 2009-06-26 10:45:48 +0000 | [diff] [blame] | 108 | rcu_barrier(); /* Wait for completion of call_rcu()'s */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
Bodo Stroesser | d69efb1 | 2008-04-29 03:18:13 -0700 | [diff] [blame] | 110 | br_netfilter_fini(); |
Igor Maravić | e6373c4 | 2011-12-12 02:58:25 +0000 | [diff] [blame] | 111 | #if IS_ENABLED(CONFIG_ATM_LANE) |
Michał Mirosław | da67829 | 2009-06-05 05:35:28 +0000 | [diff] [blame] | 112 | br_fdb_test_addr_hook = NULL; |
| 113 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | br_fdb_fini(); |
| 116 | } |
| 117 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | module_init(br_init) |
| 119 | module_exit(br_deinit) |
| 120 | MODULE_LICENSE("GPL"); |
Stephen Hemminger | 8cbb512e | 2005-12-21 19:01:30 -0800 | [diff] [blame] | 121 | MODULE_VERSION(BR_VERSION); |
stephen hemminger | bb900b2 | 2011-04-04 14:03:32 +0000 | [diff] [blame] | 122 | MODULE_ALIAS_RTNL_LINK("bridge"); |