bridge: kernel panic when unloading bridge module
[safe/jmp/linux-2.6] / net / bridge / br.c
1 /*
2  *      Generic parts
3  *      Linux ethernet bridge
4  *
5  *      Authors:
6  *      Lennert Buytenhek               <buytenh@gnu.org>
7  *
8  *      $Id: br.c,v 1.47 2001/12/24 00:56:41 davem Exp $
9  *
10  *      This program is free software; you can redistribute it and/or
11  *      modify it under the terms of the GNU General Public License
12  *      as published by the Free Software Foundation; either version
13  *      2 of the License, or (at your option) any later version.
14  */
15
16 #include <linux/module.h>
17 #include <linux/kernel.h>
18 #include <linux/netdevice.h>
19 #include <linux/etherdevice.h>
20 #include <linux/init.h>
21 #include <linux/llc.h>
22 #include <net/llc.h>
23
24 #include "br_private.h"
25
26 int (*br_should_route_hook)(struct sk_buff *skb);
27
28 static struct llc_sap *br_stp_sap;
29
30 static int __init br_init(void)
31 {
32         int err;
33
34         br_stp_sap = llc_sap_open(LLC_SAP_BSPAN, br_stp_rcv);
35         if (!br_stp_sap) {
36                 printk(KERN_ERR "bridge: can't register sap for STP\n");
37                 return -EADDRINUSE;
38         }
39
40         err = br_fdb_init();
41         if (err)
42                 goto err_out;
43
44         err = br_netfilter_init();
45         if (err)
46                 goto err_out1;
47
48         err = register_netdevice_notifier(&br_device_notifier);
49         if (err)
50                 goto err_out2;
51
52         err = br_netlink_init();
53         if (err)
54                 goto err_out3;
55
56         brioctl_set(br_ioctl_deviceless_stub);
57         br_handle_frame_hook = br_handle_frame;
58
59         br_fdb_get_hook = br_fdb_get;
60         br_fdb_put_hook = br_fdb_put;
61
62         return 0;
63 err_out3:
64         unregister_netdevice_notifier(&br_device_notifier);
65 err_out2:
66         br_netfilter_fini();
67 err_out1:
68         br_fdb_fini();
69 err_out:
70         llc_sap_put(br_stp_sap);
71         return err;
72 }
73
74 static void __exit br_deinit(void)
75 {
76         rcu_assign_pointer(br_stp_sap->rcv_func, NULL);
77
78         br_netlink_fini();
79         unregister_netdevice_notifier(&br_device_notifier);
80         brioctl_set(NULL);
81
82         br_cleanup_bridges();
83
84         synchronize_net();
85
86         br_netfilter_fini();
87         llc_sap_put(br_stp_sap);
88         br_fdb_get_hook = NULL;
89         br_fdb_put_hook = NULL;
90
91         br_handle_frame_hook = NULL;
92         br_fdb_fini();
93 }
94
95 EXPORT_SYMBOL(br_should_route_hook);
96
97 module_init(br_init)
98 module_exit(br_deinit)
99 MODULE_LICENSE("GPL");
100 MODULE_VERSION(BR_VERSION);