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