diff options
Diffstat (limited to 'net/tipc/node.c')
-rw-r--r-- | net/tipc/node.c | 336 |
1 files changed, 110 insertions, 226 deletions
diff --git a/net/tipc/node.c b/net/tipc/node.c index 8d353ec77a66..86152de8248d 100644 --- a/net/tipc/node.c +++ b/net/tipc/node.c | |||
@@ -35,22 +35,14 @@ | |||
35 | */ | 35 | */ |
36 | 36 | ||
37 | #include "core.h" | 37 | #include "core.h" |
38 | #include "config.h" | 38 | #include "link.h" |
39 | #include "node.h" | 39 | #include "node.h" |
40 | #include "name_distr.h" | 40 | #include "name_distr.h" |
41 | #include "socket.h" | 41 | #include "socket.h" |
42 | 42 | ||
43 | #define NODE_HTABLE_SIZE 512 | ||
44 | |||
45 | static void node_lost_contact(struct tipc_node *n_ptr); | 43 | static void node_lost_contact(struct tipc_node *n_ptr); |
46 | static void node_established_contact(struct tipc_node *n_ptr); | 44 | static void node_established_contact(struct tipc_node *n_ptr); |
47 | 45 | ||
48 | static struct hlist_head node_htable[NODE_HTABLE_SIZE]; | ||
49 | LIST_HEAD(tipc_node_list); | ||
50 | static u32 tipc_num_nodes; | ||
51 | static u32 tipc_num_links; | ||
52 | static DEFINE_SPINLOCK(node_list_lock); | ||
53 | |||
54 | struct tipc_sock_conn { | 46 | struct tipc_sock_conn { |
55 | u32 port; | 47 | u32 port; |
56 | u32 peer_port; | 48 | u32 peer_port; |
@@ -78,15 +70,17 @@ static unsigned int tipc_hashfn(u32 addr) | |||
78 | /* | 70 | /* |
79 | * tipc_node_find - locate specified node object, if it exists | 71 | * tipc_node_find - locate specified node object, if it exists |
80 | */ | 72 | */ |
81 | struct tipc_node *tipc_node_find(u32 addr) | 73 | struct tipc_node *tipc_node_find(struct net *net, u32 addr) |
82 | { | 74 | { |
75 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
83 | struct tipc_node *node; | 76 | struct tipc_node *node; |
84 | 77 | ||
85 | if (unlikely(!in_own_cluster_exact(addr))) | 78 | if (unlikely(!in_own_cluster_exact(net, addr))) |
86 | return NULL; | 79 | return NULL; |
87 | 80 | ||
88 | rcu_read_lock(); | 81 | rcu_read_lock(); |
89 | hlist_for_each_entry_rcu(node, &node_htable[tipc_hashfn(addr)], hash) { | 82 | hlist_for_each_entry_rcu(node, &tn->node_htable[tipc_hashfn(addr)], |
83 | hash) { | ||
90 | if (node->addr == addr) { | 84 | if (node->addr == addr) { |
91 | rcu_read_unlock(); | 85 | rcu_read_unlock(); |
92 | return node; | 86 | return node; |
@@ -96,72 +90,68 @@ struct tipc_node *tipc_node_find(u32 addr) | |||
96 | return NULL; | 90 | return NULL; |
97 | } | 91 | } |
98 | 92 | ||
99 | struct tipc_node *tipc_node_create(u32 addr) | 93 | struct tipc_node *tipc_node_create(struct net *net, u32 addr) |
100 | { | 94 | { |
95 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
101 | struct tipc_node *n_ptr, *temp_node; | 96 | struct tipc_node *n_ptr, *temp_node; |
102 | 97 | ||
103 | spin_lock_bh(&node_list_lock); | 98 | spin_lock_bh(&tn->node_list_lock); |
104 | 99 | n_ptr = tipc_node_find(net, addr); | |
100 | if (n_ptr) | ||
101 | goto exit; | ||
105 | n_ptr = kzalloc(sizeof(*n_ptr), GFP_ATOMIC); | 102 | n_ptr = kzalloc(sizeof(*n_ptr), GFP_ATOMIC); |
106 | if (!n_ptr) { | 103 | if (!n_ptr) { |
107 | spin_unlock_bh(&node_list_lock); | ||
108 | pr_warn("Node creation failed, no memory\n"); | 104 | pr_warn("Node creation failed, no memory\n"); |
109 | return NULL; | 105 | goto exit; |
110 | } | 106 | } |
111 | |||
112 | n_ptr->addr = addr; | 107 | n_ptr->addr = addr; |
108 | n_ptr->net = net; | ||
113 | spin_lock_init(&n_ptr->lock); | 109 | spin_lock_init(&n_ptr->lock); |
114 | INIT_HLIST_NODE(&n_ptr->hash); | 110 | INIT_HLIST_NODE(&n_ptr->hash); |
115 | INIT_LIST_HEAD(&n_ptr->list); | 111 | INIT_LIST_HEAD(&n_ptr->list); |
116 | INIT_LIST_HEAD(&n_ptr->publ_list); | 112 | INIT_LIST_HEAD(&n_ptr->publ_list); |
117 | INIT_LIST_HEAD(&n_ptr->conn_sks); | 113 | INIT_LIST_HEAD(&n_ptr->conn_sks); |
118 | skb_queue_head_init(&n_ptr->waiting_sks); | ||
119 | __skb_queue_head_init(&n_ptr->bclink.deferred_queue); | 114 | __skb_queue_head_init(&n_ptr->bclink.deferred_queue); |
120 | 115 | hlist_add_head_rcu(&n_ptr->hash, &tn->node_htable[tipc_hashfn(addr)]); | |
121 | hlist_add_head_rcu(&n_ptr->hash, &node_htable[tipc_hashfn(addr)]); | 116 | list_for_each_entry_rcu(temp_node, &tn->node_list, list) { |
122 | |||
123 | list_for_each_entry_rcu(temp_node, &tipc_node_list, list) { | ||
124 | if (n_ptr->addr < temp_node->addr) | 117 | if (n_ptr->addr < temp_node->addr) |
125 | break; | 118 | break; |
126 | } | 119 | } |
127 | list_add_tail_rcu(&n_ptr->list, &temp_node->list); | 120 | list_add_tail_rcu(&n_ptr->list, &temp_node->list); |
128 | n_ptr->action_flags = TIPC_WAIT_PEER_LINKS_DOWN; | 121 | n_ptr->action_flags = TIPC_WAIT_PEER_LINKS_DOWN; |
129 | n_ptr->signature = INVALID_NODE_SIG; | 122 | n_ptr->signature = INVALID_NODE_SIG; |
130 | 123 | exit: | |
131 | tipc_num_nodes++; | 124 | spin_unlock_bh(&tn->node_list_lock); |
132 | |||
133 | spin_unlock_bh(&node_list_lock); | ||
134 | return n_ptr; | 125 | return n_ptr; |
135 | } | 126 | } |
136 | 127 | ||
137 | static void tipc_node_delete(struct tipc_node *n_ptr) | 128 | static void tipc_node_delete(struct tipc_net *tn, struct tipc_node *n_ptr) |
138 | { | 129 | { |
139 | list_del_rcu(&n_ptr->list); | 130 | list_del_rcu(&n_ptr->list); |
140 | hlist_del_rcu(&n_ptr->hash); | 131 | hlist_del_rcu(&n_ptr->hash); |
141 | kfree_rcu(n_ptr, rcu); | 132 | kfree_rcu(n_ptr, rcu); |
142 | |||
143 | tipc_num_nodes--; | ||
144 | } | 133 | } |
145 | 134 | ||
146 | void tipc_node_stop(void) | 135 | void tipc_node_stop(struct net *net) |
147 | { | 136 | { |
137 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
148 | struct tipc_node *node, *t_node; | 138 | struct tipc_node *node, *t_node; |
149 | 139 | ||
150 | spin_lock_bh(&node_list_lock); | 140 | spin_lock_bh(&tn->node_list_lock); |
151 | list_for_each_entry_safe(node, t_node, &tipc_node_list, list) | 141 | list_for_each_entry_safe(node, t_node, &tn->node_list, list) |
152 | tipc_node_delete(node); | 142 | tipc_node_delete(tn, node); |
153 | spin_unlock_bh(&node_list_lock); | 143 | spin_unlock_bh(&tn->node_list_lock); |
154 | } | 144 | } |
155 | 145 | ||
156 | int tipc_node_add_conn(u32 dnode, u32 port, u32 peer_port) | 146 | int tipc_node_add_conn(struct net *net, u32 dnode, u32 port, u32 peer_port) |
157 | { | 147 | { |
158 | struct tipc_node *node; | 148 | struct tipc_node *node; |
159 | struct tipc_sock_conn *conn; | 149 | struct tipc_sock_conn *conn; |
160 | 150 | ||
161 | if (in_own_node(dnode)) | 151 | if (in_own_node(net, dnode)) |
162 | return 0; | 152 | return 0; |
163 | 153 | ||
164 | node = tipc_node_find(dnode); | 154 | node = tipc_node_find(net, dnode); |
165 | if (!node) { | 155 | if (!node) { |
166 | pr_warn("Connecting sock to node 0x%x failed\n", dnode); | 156 | pr_warn("Connecting sock to node 0x%x failed\n", dnode); |
167 | return -EHOSTUNREACH; | 157 | return -EHOSTUNREACH; |
@@ -179,15 +169,15 @@ int tipc_node_add_conn(u32 dnode, u32 port, u32 peer_port) | |||
179 | return 0; | 169 | return 0; |
180 | } | 170 | } |
181 | 171 | ||
182 | void tipc_node_remove_conn(u32 dnode, u32 port) | 172 | void tipc_node_remove_conn(struct net *net, u32 dnode, u32 port) |
183 | { | 173 | { |
184 | struct tipc_node *node; | 174 | struct tipc_node *node; |
185 | struct tipc_sock_conn *conn, *safe; | 175 | struct tipc_sock_conn *conn, *safe; |
186 | 176 | ||
187 | if (in_own_node(dnode)) | 177 | if (in_own_node(net, dnode)) |
188 | return; | 178 | return; |
189 | 179 | ||
190 | node = tipc_node_find(dnode); | 180 | node = tipc_node_find(net, dnode); |
191 | if (!node) | 181 | if (!node) |
192 | return; | 182 | return; |
193 | 183 | ||
@@ -201,23 +191,6 @@ void tipc_node_remove_conn(u32 dnode, u32 port) | |||
201 | tipc_node_unlock(node); | 191 | tipc_node_unlock(node); |
202 | } | 192 | } |
203 | 193 | ||
204 | void tipc_node_abort_sock_conns(struct list_head *conns) | ||
205 | { | ||
206 | struct tipc_sock_conn *conn, *safe; | ||
207 | struct sk_buff *buf; | ||
208 | |||
209 | list_for_each_entry_safe(conn, safe, conns, list) { | ||
210 | buf = tipc_msg_create(TIPC_CRITICAL_IMPORTANCE, TIPC_CONN_MSG, | ||
211 | SHORT_H_SIZE, 0, tipc_own_addr, | ||
212 | conn->peer_node, conn->port, | ||
213 | conn->peer_port, TIPC_ERR_NO_NODE); | ||
214 | if (likely(buf)) | ||
215 | tipc_sk_rcv(buf); | ||
216 | list_del(&conn->list); | ||
217 | kfree(conn); | ||
218 | } | ||
219 | } | ||
220 | |||
221 | /** | 194 | /** |
222 | * tipc_node_link_up - handle addition of link | 195 | * tipc_node_link_up - handle addition of link |
223 | * | 196 | * |
@@ -231,8 +204,8 @@ void tipc_node_link_up(struct tipc_node *n_ptr, struct tipc_link *l_ptr) | |||
231 | n_ptr->action_flags |= TIPC_NOTIFY_LINK_UP; | 204 | n_ptr->action_flags |= TIPC_NOTIFY_LINK_UP; |
232 | n_ptr->link_id = l_ptr->peer_bearer_id << 16 | l_ptr->bearer_id; | 205 | n_ptr->link_id = l_ptr->peer_bearer_id << 16 | l_ptr->bearer_id; |
233 | 206 | ||
234 | pr_info("Established link <%s> on network plane %c\n", | 207 | pr_debug("Established link <%s> on network plane %c\n", |
235 | l_ptr->name, l_ptr->net_plane); | 208 | l_ptr->name, l_ptr->net_plane); |
236 | 209 | ||
237 | if (!active[0]) { | 210 | if (!active[0]) { |
238 | active[0] = active[1] = l_ptr; | 211 | active[0] = active[1] = l_ptr; |
@@ -240,7 +213,7 @@ void tipc_node_link_up(struct tipc_node *n_ptr, struct tipc_link *l_ptr) | |||
240 | goto exit; | 213 | goto exit; |
241 | } | 214 | } |
242 | if (l_ptr->priority < active[0]->priority) { | 215 | if (l_ptr->priority < active[0]->priority) { |
243 | pr_info("New link <%s> becomes standby\n", l_ptr->name); | 216 | pr_debug("New link <%s> becomes standby\n", l_ptr->name); |
244 | goto exit; | 217 | goto exit; |
245 | } | 218 | } |
246 | tipc_link_dup_queue_xmit(active[0], l_ptr); | 219 | tipc_link_dup_queue_xmit(active[0], l_ptr); |
@@ -248,9 +221,9 @@ void tipc_node_link_up(struct tipc_node *n_ptr, struct tipc_link *l_ptr) | |||
248 | active[0] = l_ptr; | 221 | active[0] = l_ptr; |
249 | goto exit; | 222 | goto exit; |
250 | } | 223 | } |
251 | pr_info("Old link <%s> becomes standby\n", active[0]->name); | 224 | pr_debug("Old link <%s> becomes standby\n", active[0]->name); |
252 | if (active[1] != active[0]) | 225 | if (active[1] != active[0]) |
253 | pr_info("Old link <%s> becomes standby\n", active[1]->name); | 226 | pr_debug("Old link <%s> becomes standby\n", active[1]->name); |
254 | active[0] = active[1] = l_ptr; | 227 | active[0] = active[1] = l_ptr; |
255 | exit: | 228 | exit: |
256 | /* Leave room for changeover header when returning 'mtu' to users: */ | 229 | /* Leave room for changeover header when returning 'mtu' to users: */ |
@@ -290,6 +263,7 @@ static void node_select_active_links(struct tipc_node *n_ptr) | |||
290 | */ | 263 | */ |
291 | void tipc_node_link_down(struct tipc_node *n_ptr, struct tipc_link *l_ptr) | 264 | void tipc_node_link_down(struct tipc_node *n_ptr, struct tipc_link *l_ptr) |
292 | { | 265 | { |
266 | struct tipc_net *tn = net_generic(n_ptr->net, tipc_net_id); | ||
293 | struct tipc_link **active; | 267 | struct tipc_link **active; |
294 | 268 | ||
295 | n_ptr->working_links--; | 269 | n_ptr->working_links--; |
@@ -297,12 +271,12 @@ void tipc_node_link_down(struct tipc_node *n_ptr, struct tipc_link *l_ptr) | |||
297 | n_ptr->link_id = l_ptr->peer_bearer_id << 16 | l_ptr->bearer_id; | 271 | n_ptr->link_id = l_ptr->peer_bearer_id << 16 | l_ptr->bearer_id; |
298 | 272 | ||
299 | if (!tipc_link_is_active(l_ptr)) { | 273 | if (!tipc_link_is_active(l_ptr)) { |
300 | pr_info("Lost standby link <%s> on network plane %c\n", | 274 | pr_debug("Lost standby link <%s> on network plane %c\n", |
301 | l_ptr->name, l_ptr->net_plane); | 275 | l_ptr->name, l_ptr->net_plane); |
302 | return; | 276 | return; |
303 | } | 277 | } |
304 | pr_info("Lost link <%s> on network plane %c\n", | 278 | pr_debug("Lost link <%s> on network plane %c\n", |
305 | l_ptr->name, l_ptr->net_plane); | 279 | l_ptr->name, l_ptr->net_plane); |
306 | 280 | ||
307 | active = &n_ptr->active_links[0]; | 281 | active = &n_ptr->active_links[0]; |
308 | if (active[0] == l_ptr) | 282 | if (active[0] == l_ptr) |
@@ -324,7 +298,7 @@ void tipc_node_link_down(struct tipc_node *n_ptr, struct tipc_link *l_ptr) | |||
324 | } | 298 | } |
325 | 299 | ||
326 | /* Loopback link went down? No fragmentation needed from now on. */ | 300 | /* Loopback link went down? No fragmentation needed from now on. */ |
327 | if (n_ptr->addr == tipc_own_addr) { | 301 | if (n_ptr->addr == tn->own_addr) { |
328 | n_ptr->act_mtus[0] = MAX_MSG_SIZE; | 302 | n_ptr->act_mtus[0] = MAX_MSG_SIZE; |
329 | n_ptr->act_mtus[1] = MAX_MSG_SIZE; | 303 | n_ptr->act_mtus[1] = MAX_MSG_SIZE; |
330 | } | 304 | } |
@@ -343,9 +317,6 @@ int tipc_node_is_up(struct tipc_node *n_ptr) | |||
343 | void tipc_node_attach_link(struct tipc_node *n_ptr, struct tipc_link *l_ptr) | 317 | void tipc_node_attach_link(struct tipc_node *n_ptr, struct tipc_link *l_ptr) |
344 | { | 318 | { |
345 | n_ptr->links[l_ptr->bearer_id] = l_ptr; | 319 | n_ptr->links[l_ptr->bearer_id] = l_ptr; |
346 | spin_lock_bh(&node_list_lock); | ||
347 | tipc_num_links++; | ||
348 | spin_unlock_bh(&node_list_lock); | ||
349 | n_ptr->link_cnt++; | 320 | n_ptr->link_cnt++; |
350 | } | 321 | } |
351 | 322 | ||
@@ -357,9 +328,6 @@ void tipc_node_detach_link(struct tipc_node *n_ptr, struct tipc_link *l_ptr) | |||
357 | if (l_ptr != n_ptr->links[i]) | 328 | if (l_ptr != n_ptr->links[i]) |
358 | continue; | 329 | continue; |
359 | n_ptr->links[i] = NULL; | 330 | n_ptr->links[i] = NULL; |
360 | spin_lock_bh(&node_list_lock); | ||
361 | tipc_num_links--; | ||
362 | spin_unlock_bh(&node_list_lock); | ||
363 | n_ptr->link_cnt--; | 331 | n_ptr->link_cnt--; |
364 | } | 332 | } |
365 | } | 333 | } |
@@ -368,17 +336,21 @@ static void node_established_contact(struct tipc_node *n_ptr) | |||
368 | { | 336 | { |
369 | n_ptr->action_flags |= TIPC_NOTIFY_NODE_UP; | 337 | n_ptr->action_flags |= TIPC_NOTIFY_NODE_UP; |
370 | n_ptr->bclink.oos_state = 0; | 338 | n_ptr->bclink.oos_state = 0; |
371 | n_ptr->bclink.acked = tipc_bclink_get_last_sent(); | 339 | n_ptr->bclink.acked = tipc_bclink_get_last_sent(n_ptr->net); |
372 | tipc_bclink_add_node(n_ptr->addr); | 340 | tipc_bclink_add_node(n_ptr->net, n_ptr->addr); |
373 | } | 341 | } |
374 | 342 | ||
375 | static void node_lost_contact(struct tipc_node *n_ptr) | 343 | static void node_lost_contact(struct tipc_node *n_ptr) |
376 | { | 344 | { |
377 | char addr_string[16]; | 345 | char addr_string[16]; |
378 | u32 i; | 346 | struct tipc_sock_conn *conn, *safe; |
347 | struct list_head *conns = &n_ptr->conn_sks; | ||
348 | struct sk_buff *skb; | ||
349 | struct tipc_net *tn = net_generic(n_ptr->net, tipc_net_id); | ||
350 | uint i; | ||
379 | 351 | ||
380 | pr_info("Lost contact with %s\n", | 352 | pr_debug("Lost contact with %s\n", |
381 | tipc_addr_string_fill(addr_string, n_ptr->addr)); | 353 | tipc_addr_string_fill(addr_string, n_ptr->addr)); |
382 | 354 | ||
383 | /* Flush broadcast link info associated with lost node */ | 355 | /* Flush broadcast link info associated with lost node */ |
384 | if (n_ptr->bclink.recv_permitted) { | 356 | if (n_ptr->bclink.recv_permitted) { |
@@ -389,7 +361,7 @@ static void node_lost_contact(struct tipc_node *n_ptr) | |||
389 | n_ptr->bclink.reasm_buf = NULL; | 361 | n_ptr->bclink.reasm_buf = NULL; |
390 | } | 362 | } |
391 | 363 | ||
392 | tipc_bclink_remove_node(n_ptr->addr); | 364 | tipc_bclink_remove_node(n_ptr->net, n_ptr->addr); |
393 | tipc_bclink_acknowledge(n_ptr, INVALID_LINK_SEQ); | 365 | tipc_bclink_acknowledge(n_ptr, INVALID_LINK_SEQ); |
394 | 366 | ||
395 | n_ptr->bclink.recv_permitted = false; | 367 | n_ptr->bclink.recv_permitted = false; |
@@ -403,126 +375,33 @@ static void node_lost_contact(struct tipc_node *n_ptr) | |||
403 | l_ptr->reset_checkpoint = l_ptr->next_in_no; | 375 | l_ptr->reset_checkpoint = l_ptr->next_in_no; |
404 | l_ptr->exp_msg_count = 0; | 376 | l_ptr->exp_msg_count = 0; |
405 | tipc_link_reset_fragments(l_ptr); | 377 | tipc_link_reset_fragments(l_ptr); |
406 | } | ||
407 | |||
408 | n_ptr->action_flags &= ~TIPC_WAIT_OWN_LINKS_DOWN; | ||
409 | |||
410 | /* Notify subscribers and prevent re-contact with node until | ||
411 | * cleanup is done. | ||
412 | */ | ||
413 | n_ptr->action_flags |= TIPC_WAIT_PEER_LINKS_DOWN | | ||
414 | TIPC_NOTIFY_NODE_DOWN; | ||
415 | } | ||
416 | 378 | ||
417 | struct sk_buff *tipc_node_get_nodes(const void *req_tlv_area, int req_tlv_space) | 379 | /* Link marked for deletion after failover? => do it now */ |
418 | { | 380 | if (l_ptr->flags & LINK_STOPPED) |
419 | u32 domain; | 381 | tipc_link_delete(l_ptr); |
420 | struct sk_buff *buf; | ||
421 | struct tipc_node *n_ptr; | ||
422 | struct tipc_node_info node_info; | ||
423 | u32 payload_size; | ||
424 | |||
425 | if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NET_ADDR)) | ||
426 | return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); | ||
427 | |||
428 | domain = ntohl(*(__be32 *)TLV_DATA(req_tlv_area)); | ||
429 | if (!tipc_addr_domain_valid(domain)) | ||
430 | return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE | ||
431 | " (network address)"); | ||
432 | |||
433 | spin_lock_bh(&node_list_lock); | ||
434 | if (!tipc_num_nodes) { | ||
435 | spin_unlock_bh(&node_list_lock); | ||
436 | return tipc_cfg_reply_none(); | ||
437 | } | 382 | } |
438 | 383 | ||
439 | /* For now, get space for all other nodes */ | 384 | n_ptr->action_flags &= ~TIPC_WAIT_OWN_LINKS_DOWN; |
440 | payload_size = TLV_SPACE(sizeof(node_info)) * tipc_num_nodes; | ||
441 | if (payload_size > 32768u) { | ||
442 | spin_unlock_bh(&node_list_lock); | ||
443 | return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED | ||
444 | " (too many nodes)"); | ||
445 | } | ||
446 | spin_unlock_bh(&node_list_lock); | ||
447 | |||
448 | buf = tipc_cfg_reply_alloc(payload_size); | ||
449 | if (!buf) | ||
450 | return NULL; | ||
451 | |||
452 | /* Add TLVs for all nodes in scope */ | ||
453 | rcu_read_lock(); | ||
454 | list_for_each_entry_rcu(n_ptr, &tipc_node_list, list) { | ||
455 | if (!tipc_in_scope(domain, n_ptr->addr)) | ||
456 | continue; | ||
457 | node_info.addr = htonl(n_ptr->addr); | ||
458 | node_info.up = htonl(tipc_node_is_up(n_ptr)); | ||
459 | tipc_cfg_append_tlv(buf, TIPC_TLV_NODE_INFO, | ||
460 | &node_info, sizeof(node_info)); | ||
461 | } | ||
462 | rcu_read_unlock(); | ||
463 | return buf; | ||
464 | } | ||
465 | |||
466 | struct sk_buff *tipc_node_get_links(const void *req_tlv_area, int req_tlv_space) | ||
467 | { | ||
468 | u32 domain; | ||
469 | struct sk_buff *buf; | ||
470 | struct tipc_node *n_ptr; | ||
471 | struct tipc_link_info link_info; | ||
472 | u32 payload_size; | ||
473 | |||
474 | if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NET_ADDR)) | ||
475 | return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); | ||
476 | |||
477 | domain = ntohl(*(__be32 *)TLV_DATA(req_tlv_area)); | ||
478 | if (!tipc_addr_domain_valid(domain)) | ||
479 | return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE | ||
480 | " (network address)"); | ||
481 | |||
482 | if (!tipc_own_addr) | ||
483 | return tipc_cfg_reply_none(); | ||
484 | |||
485 | spin_lock_bh(&node_list_lock); | ||
486 | /* Get space for all unicast links + broadcast link */ | ||
487 | payload_size = TLV_SPACE((sizeof(link_info)) * (tipc_num_links + 1)); | ||
488 | if (payload_size > 32768u) { | ||
489 | spin_unlock_bh(&node_list_lock); | ||
490 | return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED | ||
491 | " (too many links)"); | ||
492 | } | ||
493 | spin_unlock_bh(&node_list_lock); | ||
494 | |||
495 | buf = tipc_cfg_reply_alloc(payload_size); | ||
496 | if (!buf) | ||
497 | return NULL; | ||
498 | 385 | ||
499 | /* Add TLV for broadcast link */ | 386 | /* Prevent re-contact with node until cleanup is done */ |
500 | link_info.dest = htonl(tipc_cluster_mask(tipc_own_addr)); | 387 | n_ptr->action_flags |= TIPC_WAIT_PEER_LINKS_DOWN; |
501 | link_info.up = htonl(1); | ||
502 | strlcpy(link_info.str, tipc_bclink_name, TIPC_MAX_LINK_NAME); | ||
503 | tipc_cfg_append_tlv(buf, TIPC_TLV_LINK_INFO, &link_info, sizeof(link_info)); | ||
504 | 388 | ||
505 | /* Add TLVs for any other links in scope */ | 389 | /* Notify publications from this node */ |
506 | rcu_read_lock(); | 390 | n_ptr->action_flags |= TIPC_NOTIFY_NODE_DOWN; |
507 | list_for_each_entry_rcu(n_ptr, &tipc_node_list, list) { | ||
508 | u32 i; | ||
509 | 391 | ||
510 | if (!tipc_in_scope(domain, n_ptr->addr)) | 392 | /* Notify sockets connected to node */ |
511 | continue; | 393 | list_for_each_entry_safe(conn, safe, conns, list) { |
512 | tipc_node_lock(n_ptr); | 394 | skb = tipc_msg_create(TIPC_CRITICAL_IMPORTANCE, TIPC_CONN_MSG, |
513 | for (i = 0; i < MAX_BEARERS; i++) { | 395 | SHORT_H_SIZE, 0, tn->own_addr, |
514 | if (!n_ptr->links[i]) | 396 | conn->peer_node, conn->port, |
515 | continue; | 397 | conn->peer_port, TIPC_ERR_NO_NODE); |
516 | link_info.dest = htonl(n_ptr->addr); | 398 | if (likely(skb)) { |
517 | link_info.up = htonl(tipc_link_is_up(n_ptr->links[i])); | 399 | skb_queue_tail(n_ptr->inputq, skb); |
518 | strcpy(link_info.str, n_ptr->links[i]->name); | 400 | n_ptr->action_flags |= TIPC_MSG_EVT; |
519 | tipc_cfg_append_tlv(buf, TIPC_TLV_LINK_INFO, | ||
520 | &link_info, sizeof(link_info)); | ||
521 | } | 401 | } |
522 | tipc_node_unlock(n_ptr); | 402 | list_del(&conn->list); |
403 | kfree(conn); | ||
523 | } | 404 | } |
524 | rcu_read_unlock(); | ||
525 | return buf; | ||
526 | } | 405 | } |
527 | 406 | ||
528 | /** | 407 | /** |
@@ -534,10 +413,11 @@ struct sk_buff *tipc_node_get_links(const void *req_tlv_area, int req_tlv_space) | |||
534 | * | 413 | * |
535 | * Returns 0 on success | 414 | * Returns 0 on success |
536 | */ | 415 | */ |
537 | int tipc_node_get_linkname(u32 bearer_id, u32 addr, char *linkname, size_t len) | 416 | int tipc_node_get_linkname(struct net *net, u32 bearer_id, u32 addr, |
417 | char *linkname, size_t len) | ||
538 | { | 418 | { |
539 | struct tipc_link *link; | 419 | struct tipc_link *link; |
540 | struct tipc_node *node = tipc_node_find(addr); | 420 | struct tipc_node *node = tipc_node_find(net, addr); |
541 | 421 | ||
542 | if ((bearer_id >= MAX_BEARERS) || !node) | 422 | if ((bearer_id >= MAX_BEARERS) || !node) |
543 | return -EINVAL; | 423 | return -EINVAL; |
@@ -554,58 +434,60 @@ int tipc_node_get_linkname(u32 bearer_id, u32 addr, char *linkname, size_t len) | |||
554 | 434 | ||
555 | void tipc_node_unlock(struct tipc_node *node) | 435 | void tipc_node_unlock(struct tipc_node *node) |
556 | { | 436 | { |
557 | LIST_HEAD(nsub_list); | 437 | struct net *net = node->net; |
558 | LIST_HEAD(conn_sks); | ||
559 | struct sk_buff_head waiting_sks; | ||
560 | u32 addr = 0; | 438 | u32 addr = 0; |
561 | int flags = node->action_flags; | 439 | u32 flags = node->action_flags; |
562 | u32 link_id = 0; | 440 | u32 link_id = 0; |
441 | struct list_head *publ_list; | ||
442 | struct sk_buff_head *inputq = node->inputq; | ||
443 | struct sk_buff_head *namedq; | ||
563 | 444 | ||
564 | if (likely(!flags)) { | 445 | if (likely(!flags || (flags == TIPC_MSG_EVT))) { |
446 | node->action_flags = 0; | ||
565 | spin_unlock_bh(&node->lock); | 447 | spin_unlock_bh(&node->lock); |
448 | if (flags == TIPC_MSG_EVT) | ||
449 | tipc_sk_rcv(net, inputq); | ||
566 | return; | 450 | return; |
567 | } | 451 | } |
568 | 452 | ||
569 | addr = node->addr; | 453 | addr = node->addr; |
570 | link_id = node->link_id; | 454 | link_id = node->link_id; |
571 | __skb_queue_head_init(&waiting_sks); | 455 | namedq = node->namedq; |
456 | publ_list = &node->publ_list; | ||
572 | 457 | ||
573 | if (flags & TIPC_WAKEUP_USERS) | 458 | node->action_flags &= ~(TIPC_MSG_EVT | |
574 | skb_queue_splice_init(&node->waiting_sks, &waiting_sks); | 459 | TIPC_NOTIFY_NODE_DOWN | TIPC_NOTIFY_NODE_UP | |
575 | 460 | TIPC_NOTIFY_LINK_DOWN | TIPC_NOTIFY_LINK_UP | | |
576 | if (flags & TIPC_NOTIFY_NODE_DOWN) { | 461 | TIPC_WAKEUP_BCAST_USERS | TIPC_BCAST_MSG_EVT | |
577 | list_replace_init(&node->publ_list, &nsub_list); | 462 | TIPC_NAMED_MSG_EVT); |
578 | list_replace_init(&node->conn_sks, &conn_sks); | ||
579 | } | ||
580 | node->action_flags &= ~(TIPC_WAKEUP_USERS | TIPC_NOTIFY_NODE_DOWN | | ||
581 | TIPC_NOTIFY_NODE_UP | TIPC_NOTIFY_LINK_UP | | ||
582 | TIPC_NOTIFY_LINK_DOWN | | ||
583 | TIPC_WAKEUP_BCAST_USERS); | ||
584 | 463 | ||
585 | spin_unlock_bh(&node->lock); | 464 | spin_unlock_bh(&node->lock); |
586 | 465 | ||
587 | while (!skb_queue_empty(&waiting_sks)) | 466 | if (flags & TIPC_NOTIFY_NODE_DOWN) |
588 | tipc_sk_rcv(__skb_dequeue(&waiting_sks)); | 467 | tipc_publ_notify(net, publ_list, addr); |
589 | |||
590 | if (!list_empty(&conn_sks)) | ||
591 | tipc_node_abort_sock_conns(&conn_sks); | ||
592 | |||
593 | if (!list_empty(&nsub_list)) | ||
594 | tipc_publ_notify(&nsub_list, addr); | ||
595 | 468 | ||
596 | if (flags & TIPC_WAKEUP_BCAST_USERS) | 469 | if (flags & TIPC_WAKEUP_BCAST_USERS) |
597 | tipc_bclink_wakeup_users(); | 470 | tipc_bclink_wakeup_users(net); |
598 | 471 | ||
599 | if (flags & TIPC_NOTIFY_NODE_UP) | 472 | if (flags & TIPC_NOTIFY_NODE_UP) |
600 | tipc_named_node_up(addr); | 473 | tipc_named_node_up(net, addr); |
601 | 474 | ||
602 | if (flags & TIPC_NOTIFY_LINK_UP) | 475 | if (flags & TIPC_NOTIFY_LINK_UP) |
603 | tipc_nametbl_publish(TIPC_LINK_STATE, addr, addr, | 476 | tipc_nametbl_publish(net, TIPC_LINK_STATE, addr, addr, |
604 | TIPC_NODE_SCOPE, link_id, addr); | 477 | TIPC_NODE_SCOPE, link_id, addr); |
605 | 478 | ||
606 | if (flags & TIPC_NOTIFY_LINK_DOWN) | 479 | if (flags & TIPC_NOTIFY_LINK_DOWN) |
607 | tipc_nametbl_withdraw(TIPC_LINK_STATE, addr, | 480 | tipc_nametbl_withdraw(net, TIPC_LINK_STATE, addr, |
608 | link_id, addr); | 481 | link_id, addr); |
482 | |||
483 | if (flags & TIPC_MSG_EVT) | ||
484 | tipc_sk_rcv(net, inputq); | ||
485 | |||
486 | if (flags & TIPC_NAMED_MSG_EVT) | ||
487 | tipc_named_rcv(net, namedq); | ||
488 | |||
489 | if (flags & TIPC_BCAST_MSG_EVT) | ||
490 | tipc_bclink_input(net); | ||
609 | } | 491 | } |
610 | 492 | ||
611 | /* Caller should hold node lock for the passed node */ | 493 | /* Caller should hold node lock for the passed node */ |
@@ -614,7 +496,7 @@ static int __tipc_nl_add_node(struct tipc_nl_msg *msg, struct tipc_node *node) | |||
614 | void *hdr; | 496 | void *hdr; |
615 | struct nlattr *attrs; | 497 | struct nlattr *attrs; |
616 | 498 | ||
617 | hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_v2_family, | 499 | hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family, |
618 | NLM_F_MULTI, TIPC_NL_NODE_GET); | 500 | NLM_F_MULTI, TIPC_NL_NODE_GET); |
619 | if (!hdr) | 501 | if (!hdr) |
620 | return -EMSGSIZE; | 502 | return -EMSGSIZE; |
@@ -645,6 +527,8 @@ msg_full: | |||
645 | int tipc_nl_node_dump(struct sk_buff *skb, struct netlink_callback *cb) | 527 | int tipc_nl_node_dump(struct sk_buff *skb, struct netlink_callback *cb) |
646 | { | 528 | { |
647 | int err; | 529 | int err; |
530 | struct net *net = sock_net(skb->sk); | ||
531 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
648 | int done = cb->args[0]; | 532 | int done = cb->args[0]; |
649 | int last_addr = cb->args[1]; | 533 | int last_addr = cb->args[1]; |
650 | struct tipc_node *node; | 534 | struct tipc_node *node; |
@@ -659,7 +543,7 @@ int tipc_nl_node_dump(struct sk_buff *skb, struct netlink_callback *cb) | |||
659 | 543 | ||
660 | rcu_read_lock(); | 544 | rcu_read_lock(); |
661 | 545 | ||
662 | if (last_addr && !tipc_node_find(last_addr)) { | 546 | if (last_addr && !tipc_node_find(net, last_addr)) { |
663 | rcu_read_unlock(); | 547 | rcu_read_unlock(); |
664 | /* We never set seq or call nl_dump_check_consistent() this | 548 | /* We never set seq or call nl_dump_check_consistent() this |
665 | * means that setting prev_seq here will cause the consistence | 549 | * means that setting prev_seq here will cause the consistence |
@@ -671,7 +555,7 @@ int tipc_nl_node_dump(struct sk_buff *skb, struct netlink_callback *cb) | |||
671 | return -EPIPE; | 555 | return -EPIPE; |
672 | } | 556 | } |
673 | 557 | ||
674 | list_for_each_entry_rcu(node, &tipc_node_list, list) { | 558 | list_for_each_entry_rcu(node, &tn->node_list, list) { |
675 | if (last_addr) { | 559 | if (last_addr) { |
676 | if (node->addr == last_addr) | 560 | if (node->addr == last_addr) |
677 | last_addr = 0; | 561 | last_addr = 0; |