Merge remote-tracking branch 'asoc/fix/pcm' into asoc-linus
[platform/adaptation/renesas_rcar/renesas_kernel.git] / net / bridge / br.c
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
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>
19 #include <linux/llc.h>
20 #include <net/llc.h>
21 #include <net/stp.h>
22
23 #include "br_private.h"
24
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 }
39
40 static struct pernet_operations br_net_ops = {
41         .exit   = br_net_exit,
42 };
43
44 static const struct stp_proto br_stp_proto = {
45         .rcv    = br_stp_rcv,
46 };
47
48 static int __init br_init(void)
49 {
50         int err;
51
52         err = stp_proto_register(&br_stp_proto);
53         if (err < 0) {
54                 pr_err("bridge: can't register sap for STP\n");
55                 return err;
56         }
57
58         err = br_fdb_init();
59         if (err)
60                 goto err_out;
61
62         err = register_pernet_subsys(&br_net_ops);
63         if (err)
64                 goto err_out1;
65
66         err = br_netfilter_init();
67         if (err)
68                 goto err_out2;
69
70         err = register_netdevice_notifier(&br_device_notifier);
71         if (err)
72                 goto err_out3;
73
74         err = br_netlink_init();
75         if (err)
76                 goto err_out4;
77
78         brioctl_set(br_ioctl_deviceless_stub);
79
80 #if IS_ENABLED(CONFIG_ATM_LANE)
81         br_fdb_test_addr_hook = br_fdb_test_addr;
82 #endif
83
84         return 0;
85 err_out4:
86         unregister_netdevice_notifier(&br_device_notifier);
87 err_out3:
88         br_netfilter_fini();
89 err_out2:
90         unregister_pernet_subsys(&br_net_ops);
91 err_out1:
92         br_fdb_fini();
93 err_out:
94         stp_proto_unregister(&br_stp_proto);
95         return err;
96 }
97
98 static void __exit br_deinit(void)
99 {
100         stp_proto_unregister(&br_stp_proto);
101
102         br_netlink_fini();
103         unregister_netdevice_notifier(&br_device_notifier);
104         brioctl_set(NULL);
105
106         unregister_pernet_subsys(&br_net_ops);
107
108         rcu_barrier(); /* Wait for completion of call_rcu()'s */
109
110         br_netfilter_fini();
111 #if IS_ENABLED(CONFIG_ATM_LANE)
112         br_fdb_test_addr_hook = NULL;
113 #endif
114
115         br_fdb_fini();
116 }
117
118 module_init(br_init)
119 module_exit(br_deinit)
120 MODULE_LICENSE("GPL");
121 MODULE_VERSION(BR_VERSION);
122 MODULE_ALIAS_RTNL_LINK("bridge");