aboutsummaryrefslogtreecommitdiffstats
path: root/net/tipc/core.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/tipc/core.c')
-rw-r--r--net/tipc/core.c144
1 files changed, 62 insertions, 82 deletions
diff --git a/net/tipc/core.c b/net/tipc/core.c
index a5737b8407dd..674bd2698528 100644
--- a/net/tipc/core.c
+++ b/net/tipc/core.c
@@ -34,6 +34,8 @@
34 * POSSIBILITY OF SUCH DAMAGE. 34 * POSSIBILITY OF SUCH DAMAGE.
35 */ 35 */
36 36
37#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
38
37#include "core.h" 39#include "core.h"
38#include "name_table.h" 40#include "name_table.h"
39#include "subscr.h" 41#include "subscr.h"
@@ -42,69 +44,68 @@
42 44
43#include <linux/module.h> 45#include <linux/module.h>
44 46
45/* global variables used by multiple sub-systems within TIPC */
46int tipc_random __read_mostly;
47
48/* configurable TIPC parameters */ 47/* configurable TIPC parameters */
49u32 tipc_own_addr __read_mostly;
50int tipc_max_ports __read_mostly;
51int tipc_net_id __read_mostly; 48int tipc_net_id __read_mostly;
52int sysctl_tipc_rmem[3] __read_mostly; /* min/default/max */ 49int sysctl_tipc_rmem[3] __read_mostly; /* min/default/max */
53 50
54/** 51static int __net_init tipc_init_net(struct net *net)
55 * tipc_buf_acquire - creates a TIPC message buffer
56 * @size: message size (including TIPC header)
57 *
58 * Returns a new buffer with data pointers set to the specified size.
59 *
60 * NOTE: Headroom is reserved to allow prepending of a data link header.
61 * There may also be unrequested tailroom present at the buffer's end.
62 */
63struct sk_buff *tipc_buf_acquire(u32 size)
64{ 52{
65 struct sk_buff *skb; 53 struct tipc_net *tn = net_generic(net, tipc_net_id);
66 unsigned int buf_size = (BUF_HEADROOM + size + 3) & ~3u; 54 int err;
67 55
68 skb = alloc_skb_fclone(buf_size, GFP_ATOMIC); 56 tn->net_id = 4711;
69 if (skb) { 57 tn->own_addr = 0;
70 skb_reserve(skb, BUF_HEADROOM); 58 get_random_bytes(&tn->random, sizeof(int));
71 skb_put(skb, size); 59 INIT_LIST_HEAD(&tn->node_list);
72 skb->next = NULL; 60 spin_lock_init(&tn->node_list_lock);
73 } 61
74 return skb; 62 err = tipc_sk_rht_init(net);
63 if (err)
64 goto out_sk_rht;
65
66 err = tipc_nametbl_init(net);
67 if (err)
68 goto out_nametbl;
69
70 err = tipc_subscr_start(net);
71 if (err)
72 goto out_subscr;
73 return 0;
74
75out_subscr:
76 tipc_nametbl_stop(net);
77out_nametbl:
78 tipc_sk_rht_destroy(net);
79out_sk_rht:
80 return err;
75} 81}
76 82
77/** 83static void __net_exit tipc_exit_net(struct net *net)
78 * tipc_core_stop - switch TIPC from SINGLE NODE to NOT RUNNING mode
79 */
80static void tipc_core_stop(void)
81{ 84{
82 tipc_net_stop(); 85 tipc_subscr_stop(net);
83 tipc_bearer_cleanup(); 86 tipc_net_stop(net);
84 tipc_netlink_stop(); 87 tipc_nametbl_stop(net);
85 tipc_subscr_stop(); 88 tipc_sk_rht_destroy(net);
86 tipc_nametbl_stop();
87 tipc_sk_ref_table_stop();
88 tipc_socket_stop();
89 tipc_unregister_sysctl();
90} 89}
91 90
92/** 91static struct pernet_operations tipc_net_ops = {
93 * tipc_core_start - switch TIPC from NOT RUNNING to SINGLE NODE mode 92 .init = tipc_init_net,
94 */ 93 .exit = tipc_exit_net,
95static int tipc_core_start(void) 94 .id = &tipc_net_id,
95 .size = sizeof(struct tipc_net),
96};
97
98static int __init tipc_init(void)
96{ 99{
97 int err; 100 int err;
98 101
99 get_random_bytes(&tipc_random, sizeof(tipc_random)); 102 pr_info("Activated (version " TIPC_MOD_VER ")\n");
100
101 err = tipc_sk_ref_table_init(tipc_max_ports, tipc_random);
102 if (err)
103 goto out_reftbl;
104 103
105 err = tipc_nametbl_init(); 104 sysctl_tipc_rmem[0] = TIPC_CONN_OVERLOAD_LIMIT >> 4 <<
106 if (err) 105 TIPC_LOW_IMPORTANCE;
107 goto out_nametbl; 106 sysctl_tipc_rmem[1] = TIPC_CONN_OVERLOAD_LIMIT >> 4 <<
107 TIPC_CRITICAL_IMPORTANCE;
108 sysctl_tipc_rmem[2] = TIPC_CONN_OVERLOAD_LIMIT;
108 109
109 err = tipc_netlink_start(); 110 err = tipc_netlink_start();
110 if (err) 111 if (err)
@@ -118,58 +119,37 @@ static int tipc_core_start(void)
118 if (err) 119 if (err)
119 goto out_sysctl; 120 goto out_sysctl;
120 121
121 err = tipc_subscr_start(); 122 err = register_pernet_subsys(&tipc_net_ops);
122 if (err) 123 if (err)
123 goto out_subscr; 124 goto out_pernet;
124 125
125 err = tipc_bearer_setup(); 126 err = tipc_bearer_setup();
126 if (err) 127 if (err)
127 goto out_bearer; 128 goto out_bearer;
128 129
130 pr_info("Started in single node mode\n");
129 return 0; 131 return 0;
130out_bearer: 132out_bearer:
131 tipc_subscr_stop(); 133 unregister_pernet_subsys(&tipc_net_ops);
132out_subscr: 134out_pernet:
133 tipc_unregister_sysctl(); 135 tipc_unregister_sysctl();
134out_sysctl: 136out_sysctl:
135 tipc_socket_stop(); 137 tipc_socket_stop();
136out_socket: 138out_socket:
137 tipc_netlink_stop(); 139 tipc_netlink_stop();
138out_netlink: 140out_netlink:
139 tipc_nametbl_stop(); 141 pr_err("Unable to start in single node mode\n");
140out_nametbl:
141 tipc_sk_ref_table_stop();
142out_reftbl:
143 return err; 142 return err;
144} 143}
145 144
146static int __init tipc_init(void)
147{
148 int res;
149
150 pr_info("Activated (version " TIPC_MOD_VER ")\n");
151
152 tipc_own_addr = 0;
153 tipc_max_ports = CONFIG_TIPC_PORTS;
154 tipc_net_id = 4711;
155
156 sysctl_tipc_rmem[0] = TIPC_CONN_OVERLOAD_LIMIT >> 4 <<
157 TIPC_LOW_IMPORTANCE;
158 sysctl_tipc_rmem[1] = TIPC_CONN_OVERLOAD_LIMIT >> 4 <<
159 TIPC_CRITICAL_IMPORTANCE;
160 sysctl_tipc_rmem[2] = TIPC_CONN_OVERLOAD_LIMIT;
161
162 res = tipc_core_start();
163 if (res)
164 pr_err("Unable to start in single node mode\n");
165 else
166 pr_info("Started in single node mode\n");
167 return res;
168}
169
170static void __exit tipc_exit(void) 145static void __exit tipc_exit(void)
171{ 146{
172 tipc_core_stop(); 147 tipc_bearer_cleanup();
148 tipc_netlink_stop();
149 tipc_socket_stop();
150 tipc_unregister_sysctl();
151 unregister_pernet_subsys(&tipc_net_ops);
152
173 pr_info("Deactivated\n"); 153 pr_info("Deactivated\n");
174} 154}
175 155