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.c51
1 files changed, 35 insertions, 16 deletions
diff --git a/net/tipc/net.c b/net/tipc/net.c
index 7f140a5308ee..e78674891166 100644
--- a/net/tipc/net.c
+++ b/net/tipc/net.c
@@ -104,27 +104,31 @@
104 * - A local spin_lock protecting the queue of subscriber events. 104 * - A local spin_lock protecting the queue of subscriber events.
105*/ 105*/
106 106
107int tipc_net_start(struct net *net, u32 addr) 107int tipc_net_init(struct net *net, u8 *node_id, u32 addr)
108{ 108{
109 struct tipc_net *tn = tipc_net(net); 109 if (tipc_own_id(net)) {
110 char addr_string[16]; 110 pr_info("Cannot configure node identity twice\n");
111 return -1;
112 }
113 pr_info("Started in network mode\n");
111 114
112 tn->own_addr = addr; 115 if (node_id) {
116 tipc_set_node_id(net, node_id);
117 tipc_net_finalize(net, tipc_own_addr(net));
118 }
119 if (addr)
120 tipc_net_finalize(net, addr);
121 return 0;
122}
113 123
114 /* Ensure that the new address is visible before we reinit. */ 124void tipc_net_finalize(struct net *net, u32 addr)
125{
126 tipc_set_node_addr(net, addr);
115 smp_mb(); 127 smp_mb();
116
117 tipc_named_reinit(net); 128 tipc_named_reinit(net);
118 tipc_sk_reinit(net); 129 tipc_sk_reinit(net);
119
120 tipc_nametbl_publish(net, TIPC_CFG_SRV, addr, addr, 130 tipc_nametbl_publish(net, TIPC_CFG_SRV, addr, addr,
121 TIPC_CLUSTER_SCOPE, 0, addr); 131 TIPC_CLUSTER_SCOPE, 0, addr);
122
123 pr_info("Started in network mode\n");
124 pr_info("Own node address %s, cluster identity %u\n",
125 tipc_addr_string_fill(addr_string, addr),
126 tn->net_id);
127 return 0;
128} 132}
129 133
130void tipc_net_stop(struct net *net) 134void tipc_net_stop(struct net *net)
@@ -146,8 +150,10 @@ void tipc_net_stop(struct net *net)
146static int __tipc_nl_add_net(struct net *net, struct tipc_nl_msg *msg) 150static int __tipc_nl_add_net(struct net *net, struct tipc_nl_msg *msg)
147{ 151{
148 struct tipc_net *tn = net_generic(net, tipc_net_id); 152 struct tipc_net *tn = net_generic(net, tipc_net_id);
149 void *hdr; 153 u64 *w0 = (u64 *)&tn->node_id[0];
154 u64 *w1 = (u64 *)&tn->node_id[8];
150 struct nlattr *attrs; 155 struct nlattr *attrs;
156 void *hdr;
151 157
152 hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family, 158 hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
153 NLM_F_MULTI, TIPC_NL_NET_GET); 159 NLM_F_MULTI, TIPC_NL_NET_GET);
@@ -160,7 +166,10 @@ static int __tipc_nl_add_net(struct net *net, struct tipc_nl_msg *msg)
160 166
161 if (nla_put_u32(msg->skb, TIPC_NLA_NET_ID, tn->net_id)) 167 if (nla_put_u32(msg->skb, TIPC_NLA_NET_ID, tn->net_id))
162 goto attr_msg_full; 168 goto attr_msg_full;
163 169 if (nla_put_u64_64bit(msg->skb, TIPC_NLA_NET_NODEID, *w0, 0))
170 goto attr_msg_full;
171 if (nla_put_u64_64bit(msg->skb, TIPC_NLA_NET_NODEID_W1, *w1, 0))
172 goto attr_msg_full;
164 nla_nest_end(msg->skb, attrs); 173 nla_nest_end(msg->skb, attrs);
165 genlmsg_end(msg->skb, hdr); 174 genlmsg_end(msg->skb, hdr);
166 175
@@ -212,6 +221,7 @@ int __tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info)
212 err = nla_parse_nested(attrs, TIPC_NLA_NET_MAX, 221 err = nla_parse_nested(attrs, TIPC_NLA_NET_MAX,
213 info->attrs[TIPC_NLA_NET], tipc_nl_net_policy, 222 info->attrs[TIPC_NLA_NET], tipc_nl_net_policy,
214 info->extack); 223 info->extack);
224
215 if (err) 225 if (err)
216 return err; 226 return err;
217 227
@@ -236,9 +246,18 @@ int __tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info)
236 if (!addr) 246 if (!addr)
237 return -EINVAL; 247 return -EINVAL;
238 tn->legacy_addr_format = true; 248 tn->legacy_addr_format = true;
239 tipc_net_start(net, addr); 249 tipc_net_init(net, NULL, addr);
240 } 250 }
241 251
252 if (attrs[TIPC_NLA_NET_NODEID]) {
253 u8 node_id[NODE_ID_LEN];
254 u64 *w0 = (u64 *)&node_id[0];
255 u64 *w1 = (u64 *)&node_id[8];
256
257 *w0 = nla_get_u64(attrs[TIPC_NLA_NET_NODEID]);
258 *w1 = nla_get_u64(attrs[TIPC_NLA_NET_NODEID_W1]);
259 tipc_net_init(net, node_id, 0);
260 }
242 return 0; 261 return 0;
243} 262}
244 263