aboutsummaryrefslogtreecommitdiffstats
path: root/net/tipc/net.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/tipc/net.c')
-rw-r--r--net/tipc/net.c56
1 files changed, 32 insertions, 24 deletions
diff --git a/net/tipc/net.c b/net/tipc/net.c
index cf13df3cde8f..a54f3cbe2246 100644
--- a/net/tipc/net.c
+++ b/net/tipc/net.c
@@ -40,7 +40,6 @@
40#include "subscr.h" 40#include "subscr.h"
41#include "socket.h" 41#include "socket.h"
42#include "node.h" 42#include "node.h"
43#include "config.h"
44 43
45static const struct nla_policy tipc_nl_net_policy[TIPC_NLA_NET_MAX + 1] = { 44static const struct nla_policy tipc_nl_net_policy[TIPC_NLA_NET_MAX + 1] = {
46 [TIPC_NLA_NET_UNSPEC] = { .type = NLA_UNSPEC }, 45 [TIPC_NLA_NET_UNSPEC] = { .type = NLA_UNSPEC },
@@ -108,48 +107,54 @@ static const struct nla_policy tipc_nl_net_policy[TIPC_NLA_NET_MAX + 1] = {
108 * - A local spin_lock protecting the queue of subscriber events. 107 * - A local spin_lock protecting the queue of subscriber events.
109*/ 108*/
110 109
111int tipc_net_start(u32 addr) 110int tipc_net_start(struct net *net, u32 addr)
112{ 111{
112 struct tipc_net *tn = net_generic(net, tipc_net_id);
113 char addr_string[16]; 113 char addr_string[16];
114 int res; 114 int res;
115 115
116 tipc_own_addr = addr; 116 tn->own_addr = addr;
117 tipc_named_reinit(); 117 tipc_named_reinit(net);
118 tipc_sk_reinit(); 118 tipc_sk_reinit(net);
119 res = tipc_bclink_init(); 119 res = tipc_bclink_init(net);
120 if (res) 120 if (res)
121 return res; 121 return res;
122 122
123 tipc_nametbl_publish(TIPC_CFG_SRV, tipc_own_addr, tipc_own_addr, 123 tipc_nametbl_publish(net, TIPC_CFG_SRV, tn->own_addr, tn->own_addr,
124 TIPC_ZONE_SCOPE, 0, tipc_own_addr); 124 TIPC_ZONE_SCOPE, 0, tn->own_addr);
125 125
126 pr_info("Started in network mode\n"); 126 pr_info("Started in network mode\n");
127 pr_info("Own node address %s, network identity %u\n", 127 pr_info("Own node address %s, network identity %u\n",
128 tipc_addr_string_fill(addr_string, tipc_own_addr), tipc_net_id); 128 tipc_addr_string_fill(addr_string, tn->own_addr),
129 tn->net_id);
129 return 0; 130 return 0;
130} 131}
131 132
132void tipc_net_stop(void) 133void tipc_net_stop(struct net *net)
133{ 134{
134 if (!tipc_own_addr) 135 struct tipc_net *tn = net_generic(net, tipc_net_id);
136
137 if (!tn->own_addr)
135 return; 138 return;
136 139
137 tipc_nametbl_withdraw(TIPC_CFG_SRV, tipc_own_addr, 0, tipc_own_addr); 140 tipc_nametbl_withdraw(net, TIPC_CFG_SRV, tn->own_addr, 0,
141 tn->own_addr);
138 rtnl_lock(); 142 rtnl_lock();
139 tipc_bearer_stop(); 143 tipc_bearer_stop(net);
140 tipc_bclink_stop(); 144 tipc_bclink_stop(net);
141 tipc_node_stop(); 145 tipc_node_stop(net);
142 rtnl_unlock(); 146 rtnl_unlock();
143 147
144 pr_info("Left network mode\n"); 148 pr_info("Left network mode\n");
145} 149}
146 150
147static int __tipc_nl_add_net(struct tipc_nl_msg *msg) 151static int __tipc_nl_add_net(struct net *net, struct tipc_nl_msg *msg)
148{ 152{
153 struct tipc_net *tn = net_generic(net, tipc_net_id);
149 void *hdr; 154 void *hdr;
150 struct nlattr *attrs; 155 struct nlattr *attrs;
151 156
152 hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_v2_family, 157 hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
153 NLM_F_MULTI, TIPC_NL_NET_GET); 158 NLM_F_MULTI, TIPC_NL_NET_GET);
154 if (!hdr) 159 if (!hdr)
155 return -EMSGSIZE; 160 return -EMSGSIZE;
@@ -158,7 +163,7 @@ static int __tipc_nl_add_net(struct tipc_nl_msg *msg)
158 if (!attrs) 163 if (!attrs)
159 goto msg_full; 164 goto msg_full;
160 165
161 if (nla_put_u32(msg->skb, TIPC_NLA_NET_ID, tipc_net_id)) 166 if (nla_put_u32(msg->skb, TIPC_NLA_NET_ID, tn->net_id))
162 goto attr_msg_full; 167 goto attr_msg_full;
163 168
164 nla_nest_end(msg->skb, attrs); 169 nla_nest_end(msg->skb, attrs);
@@ -176,6 +181,7 @@ msg_full:
176 181
177int tipc_nl_net_dump(struct sk_buff *skb, struct netlink_callback *cb) 182int tipc_nl_net_dump(struct sk_buff *skb, struct netlink_callback *cb)
178{ 183{
184 struct net *net = sock_net(skb->sk);
179 int err; 185 int err;
180 int done = cb->args[0]; 186 int done = cb->args[0];
181 struct tipc_nl_msg msg; 187 struct tipc_nl_msg msg;
@@ -187,7 +193,7 @@ int tipc_nl_net_dump(struct sk_buff *skb, struct netlink_callback *cb)
187 msg.portid = NETLINK_CB(cb->skb).portid; 193 msg.portid = NETLINK_CB(cb->skb).portid;
188 msg.seq = cb->nlh->nlmsg_seq; 194 msg.seq = cb->nlh->nlmsg_seq;
189 195
190 err = __tipc_nl_add_net(&msg); 196 err = __tipc_nl_add_net(net, &msg);
191 if (err) 197 if (err)
192 goto out; 198 goto out;
193 199
@@ -200,8 +206,10 @@ out:
200 206
201int tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info) 207int tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info)
202{ 208{
203 int err; 209 struct net *net = sock_net(skb->sk);
210 struct tipc_net *tn = net_generic(net, tipc_net_id);
204 struct nlattr *attrs[TIPC_NLA_NET_MAX + 1]; 211 struct nlattr *attrs[TIPC_NLA_NET_MAX + 1];
212 int err;
205 213
206 if (!info->attrs[TIPC_NLA_NET]) 214 if (!info->attrs[TIPC_NLA_NET])
207 return -EINVAL; 215 return -EINVAL;
@@ -216,21 +224,21 @@ int tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info)
216 u32 val; 224 u32 val;
217 225
218 /* Can't change net id once TIPC has joined a network */ 226 /* Can't change net id once TIPC has joined a network */
219 if (tipc_own_addr) 227 if (tn->own_addr)
220 return -EPERM; 228 return -EPERM;
221 229
222 val = nla_get_u32(attrs[TIPC_NLA_NET_ID]); 230 val = nla_get_u32(attrs[TIPC_NLA_NET_ID]);
223 if (val < 1 || val > 9999) 231 if (val < 1 || val > 9999)
224 return -EINVAL; 232 return -EINVAL;
225 233
226 tipc_net_id = val; 234 tn->net_id = val;
227 } 235 }
228 236
229 if (attrs[TIPC_NLA_NET_ADDR]) { 237 if (attrs[TIPC_NLA_NET_ADDR]) {
230 u32 addr; 238 u32 addr;
231 239
232 /* Can't change net addr once TIPC has joined a network */ 240 /* Can't change net addr once TIPC has joined a network */
233 if (tipc_own_addr) 241 if (tn->own_addr)
234 return -EPERM; 242 return -EPERM;
235 243
236 addr = nla_get_u32(attrs[TIPC_NLA_NET_ADDR]); 244 addr = nla_get_u32(attrs[TIPC_NLA_NET_ADDR]);
@@ -238,7 +246,7 @@ int tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info)
238 return -EINVAL; 246 return -EINVAL;
239 247
240 rtnl_lock(); 248 rtnl_lock();
241 tipc_net_start(addr); 249 tipc_net_start(net, addr);
242 rtnl_unlock(); 250 rtnl_unlock();
243 } 251 }
244 252