blob: ba780cc8e515d2dcd6424d627c286ec1ceb86a47 [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
Patrick McHardy7c85fbf2008-07-05 21:25:56 -070025static const struct stp_proto br_stp_proto = {
26 .rcv = br_stp_rcv,
27};
Stephen Hemmingercf0f02d2006-03-20 22:59:06 -080028
Alexey Dobriyan712d6952008-09-08 16:20:18 -070029static struct pernet_operations br_net_ops = {
30 .exit = br_net_exit,
31};
32
Linus Torvalds1da177e2005-04-16 15:20:36 -070033static int __init br_init(void)
34{
Stephen Hemmingerc0909712006-05-25 15:59:33 -070035 int err;
36
Patrick McHardy7c85fbf2008-07-05 21:25:56 -070037 err = stp_proto_register(&br_stp_proto);
38 if (err < 0) {
stephen hemminger28a16c92010-05-10 09:31:09 +000039 pr_err("bridge: can't register sap for STP\n");
Patrick McHardy7c85fbf2008-07-05 21:25:56 -070040 return err;
Stephen Hemmingercf0f02d2006-03-20 22:59:06 -080041 }
42
Akinobu Mita87a596e2007-04-07 18:57:07 +090043 err = br_fdb_init();
44 if (err)
Pavel Emelyanov17efdd42007-11-29 23:41:43 +110045 goto err_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
Alexey Dobriyan712d6952008-09-08 16:20:18 -070047 err = register_pernet_subsys(&br_net_ops);
Stephen Hemmingerc0909712006-05-25 15:59:33 -070048 if (err)
49 goto err_out1;
50
Alexey Dobriyan712d6952008-09-08 16:20:18 -070051 err = br_netfilter_init();
Stephen Hemmingerc0909712006-05-25 15:59:33 -070052 if (err)
53 goto err_out2;
54
Alexey Dobriyan712d6952008-09-08 16:20:18 -070055 err = register_netdevice_notifier(&br_device_notifier);
Thomas Graf32fe21c2007-03-22 11:59:03 -070056 if (err)
57 goto err_out3;
58
Alexey Dobriyan712d6952008-09-08 16:20:18 -070059 err = br_netlink_init();
60 if (err)
61 goto err_out4;
62
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 brioctl_set(br_ioctl_deviceless_stub);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
Igor Maraviće6373c42011-12-12 02:58:25 +000065#if IS_ENABLED(CONFIG_ATM_LANE)
Michał Mirosławda678292009-06-05 05:35:28 +000066 br_fdb_test_addr_hook = br_fdb_test_addr;
67#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 return 0;
Alexey Dobriyan712d6952008-09-08 16:20:18 -070070err_out4:
Thomas Graf32fe21c2007-03-22 11:59:03 -070071 unregister_netdevice_notifier(&br_device_notifier);
Alexey Dobriyan712d6952008-09-08 16:20:18 -070072err_out3:
Stephen Hemmingerc0909712006-05-25 15:59:33 -070073 br_netfilter_fini();
Alexey Dobriyan712d6952008-09-08 16:20:18 -070074err_out2:
75 unregister_pernet_subsys(&br_net_ops);
Stephen Hemmingerc0909712006-05-25 15:59:33 -070076err_out1:
Pavel Emelyanov17efdd42007-11-29 23:41:43 +110077 br_fdb_fini();
78err_out:
Patrick McHardy7c85fbf2008-07-05 21:25:56 -070079 stp_proto_unregister(&br_stp_proto);
Stephen Hemmingerc0909712006-05-25 15:59:33 -070080 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081}
82
83static void __exit br_deinit(void)
84{
Patrick McHardy7c85fbf2008-07-05 21:25:56 -070085 stp_proto_unregister(&br_stp_proto);
Stephen Hemmingercf0f02d2006-03-20 22:59:06 -080086
Stephen Hemminger11dc1f32006-05-25 16:00:12 -070087 br_netlink_fini();
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 unregister_netdevice_notifier(&br_device_notifier);
89 brioctl_set(NULL);
90
Alexey Dobriyan712d6952008-09-08 16:20:18 -070091 unregister_pernet_subsys(&br_net_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
Jesper Dangaard Brouer473c22d2009-06-26 10:45:48 +000093 rcu_barrier(); /* Wait for completion of call_rcu()'s */
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
Bodo Stroesserd69efb12008-04-29 03:18:13 -070095 br_netfilter_fini();
Igor Maraviće6373c42011-12-12 02:58:25 +000096#if IS_ENABLED(CONFIG_ATM_LANE)
Michał Mirosławda678292009-06-05 05:35:28 +000097 br_fdb_test_addr_hook = NULL;
98#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 br_fdb_fini();
101}
102
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103module_init(br_init)
104module_exit(br_deinit)
105MODULE_LICENSE("GPL");
Stephen Hemminger8cbb5122005-12-21 19:01:30 -0800106MODULE_VERSION(BR_VERSION);
stephen hemmingerbb900b22011-04-04 14:03:32 +0000107MODULE_ALIAS_RTNL_LINK("bridge");