blob: 19311aafcf5a06e6ae7abaaf82527711573dc6d6 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Generic parts
3 * Linux ethernet bridge
4 *
5 * Authors:
6 * Lennert Buytenhek <buytenh@gnu.org>
7 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 * 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 Torvalds1da177e2005-04-16 15:20:36 -070014#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 Hemmingercf0f02d2006-03-20 22:59:06 -080019#include <linux/llc.h>
20#include <net/llc.h>
Patrick McHardy7c85fbf2008-07-05 21:25:56 -070021#include <net/stp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
23#include "br_private.h"
24
WANG Congb86f81cc2014-01-10 13:58:47 -080025static 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 Hemmingercf0f02d2006-03-20 22:59:06 -080039
Alexey Dobriyan712d6952008-09-08 16:20:18 -070040static struct pernet_operations br_net_ops = {
41 .exit = br_net_exit,
42};
43
WANG Congb86f81cc2014-01-10 13:58:47 -080044static const struct stp_proto br_stp_proto = {
45 .rcv = br_stp_rcv,
46};
47
Linus Torvalds1da177e2005-04-16 15:20:36 -070048static int __init br_init(void)
49{
Stephen Hemmingerc0909712006-05-25 15:59:33 -070050 int err;
51
Patrick McHardy7c85fbf2008-07-05 21:25:56 -070052 err = stp_proto_register(&br_stp_proto);
53 if (err < 0) {
stephen hemminger28a16c92010-05-10 09:31:09 +000054 pr_err("bridge: can't register sap for STP\n");
Patrick McHardy7c85fbf2008-07-05 21:25:56 -070055 return err;
Stephen Hemmingercf0f02d2006-03-20 22:59:06 -080056 }
57
Akinobu Mita87a596e2007-04-07 18:57:07 +090058 err = br_fdb_init();
59 if (err)
Pavel Emelyanov17efdd42007-11-29 23:41:43 +110060 goto err_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
Alexey Dobriyan712d6952008-09-08 16:20:18 -070062 err = register_pernet_subsys(&br_net_ops);
Stephen Hemmingerc0909712006-05-25 15:59:33 -070063 if (err)
64 goto err_out1;
65
Alexey Dobriyan712d6952008-09-08 16:20:18 -070066 err = br_netfilter_init();
Stephen Hemmingerc0909712006-05-25 15:59:33 -070067 if (err)
68 goto err_out2;
69
Alexey Dobriyan712d6952008-09-08 16:20:18 -070070 err = register_netdevice_notifier(&br_device_notifier);
Thomas Graf32fe21c2007-03-22 11:59:03 -070071 if (err)
72 goto err_out3;
73
Alexey Dobriyan712d6952008-09-08 16:20:18 -070074 err = br_netlink_init();
75 if (err)
76 goto err_out4;
77
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 brioctl_set(br_ioctl_deviceless_stub);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
Igor Maraviće6373c42011-12-12 02:58:25 +000080#if IS_ENABLED(CONFIG_ATM_LANE)
Michał Mirosławda678292009-06-05 05:35:28 +000081 br_fdb_test_addr_hook = br_fdb_test_addr;
82#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 return 0;
Alexey Dobriyan712d6952008-09-08 16:20:18 -070085err_out4:
Thomas Graf32fe21c2007-03-22 11:59:03 -070086 unregister_netdevice_notifier(&br_device_notifier);
Alexey Dobriyan712d6952008-09-08 16:20:18 -070087err_out3:
Stephen Hemmingerc0909712006-05-25 15:59:33 -070088 br_netfilter_fini();
Alexey Dobriyan712d6952008-09-08 16:20:18 -070089err_out2:
90 unregister_pernet_subsys(&br_net_ops);
Stephen Hemmingerc0909712006-05-25 15:59:33 -070091err_out1:
Pavel Emelyanov17efdd42007-11-29 23:41:43 +110092 br_fdb_fini();
93err_out:
Patrick McHardy7c85fbf2008-07-05 21:25:56 -070094 stp_proto_unregister(&br_stp_proto);
Stephen Hemmingerc0909712006-05-25 15:59:33 -070095 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096}
97
98static void __exit br_deinit(void)
99{
Patrick McHardy7c85fbf2008-07-05 21:25:56 -0700100 stp_proto_unregister(&br_stp_proto);
Stephen Hemmingercf0f02d2006-03-20 22:59:06 -0800101
Stephen Hemminger11dc1f32006-05-25 16:00:12 -0700102 br_netlink_fini();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 unregister_netdevice_notifier(&br_device_notifier);
104 brioctl_set(NULL);
105
Alexey Dobriyan712d6952008-09-08 16:20:18 -0700106 unregister_pernet_subsys(&br_net_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
Jesper Dangaard Brouer473c22d2009-06-26 10:45:48 +0000108 rcu_barrier(); /* Wait for completion of call_rcu()'s */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Bodo Stroesserd69efb12008-04-29 03:18:13 -0700110 br_netfilter_fini();
Igor Maraviće6373c42011-12-12 02:58:25 +0000111#if IS_ENABLED(CONFIG_ATM_LANE)
Michał Mirosławda678292009-06-05 05:35:28 +0000112 br_fdb_test_addr_hook = NULL;
113#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 br_fdb_fini();
116}
117
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118module_init(br_init)
119module_exit(br_deinit)
120MODULE_LICENSE("GPL");
Stephen Hemminger8cbb512e2005-12-21 19:01:30 -0800121MODULE_VERSION(BR_VERSION);
stephen hemmingerbb900b22011-04-04 14:03:32 +0000122MODULE_ALIAS_RTNL_LINK("bridge");