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