hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/net/tipc/core.c
....@@ -34,8 +34,6 @@
3434 * POSSIBILITY OF SUCH DAMAGE.
3535 */
3636
37
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
38
-
3937 #include "core.h"
4038 #include "name_table.h"
4139 #include "subscr.h"
....@@ -43,6 +41,8 @@
4341 #include "net.h"
4442 #include "socket.h"
4543 #include "bcast.h"
44
+#include "node.h"
45
+#include "crypto.h"
4646
4747 #include <linux/module.h>
4848
....@@ -59,6 +59,8 @@
5959 tn->node_addr = 0;
6060 tn->trial_addr = 0;
6161 tn->addr_trial_end = 0;
62
+ tn->capabilities = TIPC_NODE_CAPABILITIES;
63
+ INIT_WORK(&tn->work, tipc_net_finalize_work);
6264 memset(tn->node_id, 0, sizeof(tn->node_id));
6365 memset(tn->node_id_string, 0, sizeof(tn->node_id_string));
6466 tn->mon_threshold = TIPC_DEF_MON_THRESHOLD;
....@@ -66,6 +68,11 @@
6668 INIT_LIST_HEAD(&tn->node_list);
6769 spin_lock_init(&tn->node_list_lock);
6870
71
+#ifdef CONFIG_TIPC_CRYPTO
72
+ err = tipc_crypto_start(&tn->crypto_tx, net, NULL);
73
+ if (err)
74
+ goto out_crypto;
75
+#endif
6976 err = tipc_sk_rht_init(net);
7077 if (err)
7178 goto out_sk_rht;
....@@ -80,6 +87,10 @@
8087 if (err)
8188 goto out_bclink;
8289
90
+ err = tipc_attach_loopback(net);
91
+ if (err)
92
+ goto out_bclink;
93
+
8394 return 0;
8495
8596 out_bclink:
....@@ -87,21 +98,40 @@
8798 out_nametbl:
8899 tipc_sk_rht_destroy(net);
89100 out_sk_rht:
101
+
102
+#ifdef CONFIG_TIPC_CRYPTO
103
+ tipc_crypto_stop(&tn->crypto_tx);
104
+out_crypto:
105
+#endif
90106 return err;
91107 }
92108
93109 static void __net_exit tipc_exit_net(struct net *net)
94110 {
95
- tipc_net_stop(net);
111
+ struct tipc_net *tn = tipc_net(net);
96112
97
- /* Make sure the tipc_net_finalize_work stopped
98
- * before releasing the resources.
99
- */
100
- flush_scheduled_work();
113
+ tipc_detach_loopback(net);
114
+ tipc_net_stop(net);
115
+ /* Make sure the tipc_net_finalize_work() finished */
116
+ cancel_work_sync(&tn->work);
101117 tipc_bcast_stop(net);
102118 tipc_nametbl_stop(net);
103119 tipc_sk_rht_destroy(net);
120
+#ifdef CONFIG_TIPC_CRYPTO
121
+ tipc_crypto_stop(&tipc_net(net)->crypto_tx);
122
+#endif
123
+ while (atomic_read(&tn->wq_count))
124
+ cond_resched();
104125 }
126
+
127
+static void __net_exit tipc_pernet_pre_exit(struct net *net)
128
+{
129
+ tipc_node_pre_cleanup_net(net);
130
+}
131
+
132
+static struct pernet_operations tipc_pernet_pre_exit_ops = {
133
+ .pre_exit = tipc_pernet_pre_exit,
134
+};
105135
106136 static struct pernet_operations tipc_net_ops = {
107137 .init = tipc_init_net,
....@@ -141,6 +171,10 @@
141171 if (err)
142172 goto out_pernet_topsrv;
143173
174
+ err = register_pernet_subsys(&tipc_pernet_pre_exit_ops);
175
+ if (err)
176
+ goto out_register_pernet_subsys;
177
+
144178 err = tipc_bearer_setup();
145179 if (err)
146180 goto out_bearer;
....@@ -161,6 +195,8 @@
161195 out_netlink:
162196 tipc_bearer_cleanup();
163197 out_bearer:
198
+ unregister_pernet_subsys(&tipc_pernet_pre_exit_ops);
199
+out_register_pernet_subsys:
164200 unregister_pernet_device(&tipc_topsrv_net_ops);
165201 out_pernet_topsrv:
166202 tipc_socket_stop();
....@@ -178,6 +214,7 @@
178214 tipc_netlink_compat_stop();
179215 tipc_netlink_stop();
180216 tipc_bearer_cleanup();
217
+ unregister_pernet_subsys(&tipc_pernet_pre_exit_ops);
181218 unregister_pernet_device(&tipc_topsrv_net_ops);
182219 tipc_socket_stop();
183220 unregister_pernet_device(&tipc_net_ops);