diff options
Diffstat (limited to 'net/tipc/node.c')
| -rw-r--r-- | net/tipc/node.c | 154 |
1 files changed, 130 insertions, 24 deletions
diff --git a/net/tipc/node.c b/net/tipc/node.c index 90cee4a6fce4..8d353ec77a66 100644 --- a/net/tipc/node.c +++ b/net/tipc/node.c | |||
| @@ -58,6 +58,12 @@ struct tipc_sock_conn { | |||
| 58 | struct list_head list; | 58 | struct list_head list; |
| 59 | }; | 59 | }; |
| 60 | 60 | ||
| 61 | static const struct nla_policy tipc_nl_node_policy[TIPC_NLA_NODE_MAX + 1] = { | ||
| 62 | [TIPC_NLA_NODE_UNSPEC] = { .type = NLA_UNSPEC }, | ||
| 63 | [TIPC_NLA_NODE_ADDR] = { .type = NLA_U32 }, | ||
| 64 | [TIPC_NLA_NODE_UP] = { .type = NLA_FLAG } | ||
| 65 | }; | ||
| 66 | |||
| 61 | /* | 67 | /* |
| 62 | * A trivial power-of-two bitmask technique is used for speed, since this | 68 | * 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 | 69 | * operation is done for every incoming TIPC packet. The number of hash table |
| @@ -107,9 +113,10 @@ struct tipc_node *tipc_node_create(u32 addr) | |||
| 107 | spin_lock_init(&n_ptr->lock); | 113 | spin_lock_init(&n_ptr->lock); |
| 108 | INIT_HLIST_NODE(&n_ptr->hash); | 114 | INIT_HLIST_NODE(&n_ptr->hash); |
| 109 | INIT_LIST_HEAD(&n_ptr->list); | 115 | INIT_LIST_HEAD(&n_ptr->list); |
| 110 | INIT_LIST_HEAD(&n_ptr->nsub); | 116 | INIT_LIST_HEAD(&n_ptr->publ_list); |
| 111 | INIT_LIST_HEAD(&n_ptr->conn_sks); | 117 | INIT_LIST_HEAD(&n_ptr->conn_sks); |
| 112 | __skb_queue_head_init(&n_ptr->waiting_sks); | 118 | skb_queue_head_init(&n_ptr->waiting_sks); |
| 119 | __skb_queue_head_init(&n_ptr->bclink.deferred_queue); | ||
| 113 | 120 | ||
| 114 | hlist_add_head_rcu(&n_ptr->hash, &node_htable[tipc_hashfn(addr)]); | 121 | hlist_add_head_rcu(&n_ptr->hash, &node_htable[tipc_hashfn(addr)]); |
| 115 | 122 | ||
| @@ -219,11 +226,11 @@ void tipc_node_abort_sock_conns(struct list_head *conns) | |||
| 219 | void tipc_node_link_up(struct tipc_node *n_ptr, struct tipc_link *l_ptr) | 226 | void tipc_node_link_up(struct tipc_node *n_ptr, struct tipc_link *l_ptr) |
| 220 | { | 227 | { |
| 221 | struct tipc_link **active = &n_ptr->active_links[0]; | 228 | struct tipc_link **active = &n_ptr->active_links[0]; |
| 222 | u32 addr = n_ptr->addr; | ||
| 223 | 229 | ||
| 224 | n_ptr->working_links++; | 230 | n_ptr->working_links++; |
| 225 | tipc_nametbl_publish(TIPC_LINK_STATE, addr, addr, TIPC_NODE_SCOPE, | 231 | n_ptr->action_flags |= TIPC_NOTIFY_LINK_UP; |
| 226 | l_ptr->bearer_id, addr); | 232 | n_ptr->link_id = l_ptr->peer_bearer_id << 16 | l_ptr->bearer_id; |
| 233 | |||
| 227 | pr_info("Established link <%s> on network plane %c\n", | 234 | pr_info("Established link <%s> on network plane %c\n", |
| 228 | l_ptr->name, l_ptr->net_plane); | 235 | l_ptr->name, l_ptr->net_plane); |
| 229 | 236 | ||
| @@ -284,10 +291,10 @@ static void node_select_active_links(struct tipc_node *n_ptr) | |||
| 284 | void tipc_node_link_down(struct tipc_node *n_ptr, struct tipc_link *l_ptr) | 291 | void tipc_node_link_down(struct tipc_node *n_ptr, struct tipc_link *l_ptr) |
| 285 | { | 292 | { |
| 286 | struct tipc_link **active; | 293 | struct tipc_link **active; |
| 287 | u32 addr = n_ptr->addr; | ||
| 288 | 294 | ||
| 289 | n_ptr->working_links--; | 295 | n_ptr->working_links--; |
| 290 | tipc_nametbl_withdraw(TIPC_LINK_STATE, addr, l_ptr->bearer_id, addr); | 296 | n_ptr->action_flags |= TIPC_NOTIFY_LINK_DOWN; |
| 297 | n_ptr->link_id = l_ptr->peer_bearer_id << 16 | l_ptr->bearer_id; | ||
| 291 | 298 | ||
| 292 | if (!tipc_link_is_active(l_ptr)) { | 299 | if (!tipc_link_is_active(l_ptr)) { |
| 293 | pr_info("Lost standby link <%s> on network plane %c\n", | 300 | pr_info("Lost standby link <%s> on network plane %c\n", |
| @@ -375,8 +382,7 @@ static void node_lost_contact(struct tipc_node *n_ptr) | |||
| 375 | 382 | ||
| 376 | /* Flush broadcast link info associated with lost node */ | 383 | /* Flush broadcast link info associated with lost node */ |
| 377 | if (n_ptr->bclink.recv_permitted) { | 384 | if (n_ptr->bclink.recv_permitted) { |
| 378 | kfree_skb_list(n_ptr->bclink.deferred_head); | 385 | __skb_queue_purge(&n_ptr->bclink.deferred_queue); |
| 379 | n_ptr->bclink.deferred_size = 0; | ||
| 380 | 386 | ||
| 381 | if (n_ptr->bclink.reasm_buf) { | 387 | if (n_ptr->bclink.reasm_buf) { |
| 382 | kfree_skb(n_ptr->bclink.reasm_buf); | 388 | kfree_skb(n_ptr->bclink.reasm_buf); |
| @@ -552,28 +558,30 @@ void tipc_node_unlock(struct tipc_node *node) | |||
| 552 | LIST_HEAD(conn_sks); | 558 | LIST_HEAD(conn_sks); |
| 553 | struct sk_buff_head waiting_sks; | 559 | struct sk_buff_head waiting_sks; |
| 554 | u32 addr = 0; | 560 | u32 addr = 0; |
| 555 | unsigned int flags = node->action_flags; | 561 | int flags = node->action_flags; |
| 562 | u32 link_id = 0; | ||
| 556 | 563 | ||
| 557 | if (likely(!node->action_flags)) { | 564 | if (likely(!flags)) { |
| 558 | spin_unlock_bh(&node->lock); | 565 | spin_unlock_bh(&node->lock); |
| 559 | return; | 566 | return; |
| 560 | } | 567 | } |
| 561 | 568 | ||
| 569 | addr = node->addr; | ||
| 570 | link_id = node->link_id; | ||
| 562 | __skb_queue_head_init(&waiting_sks); | 571 | __skb_queue_head_init(&waiting_sks); |
| 563 | if (node->action_flags & TIPC_WAKEUP_USERS) { | 572 | |
| 573 | if (flags & TIPC_WAKEUP_USERS) | ||
| 564 | skb_queue_splice_init(&node->waiting_sks, &waiting_sks); | 574 | skb_queue_splice_init(&node->waiting_sks, &waiting_sks); |
| 565 | node->action_flags &= ~TIPC_WAKEUP_USERS; | 575 | |
| 566 | } | 576 | if (flags & TIPC_NOTIFY_NODE_DOWN) { |
| 567 | if (node->action_flags & TIPC_NOTIFY_NODE_DOWN) { | 577 | list_replace_init(&node->publ_list, &nsub_list); |
| 568 | list_replace_init(&node->nsub, &nsub_list); | ||
| 569 | list_replace_init(&node->conn_sks, &conn_sks); | 578 | list_replace_init(&node->conn_sks, &conn_sks); |
| 570 | node->action_flags &= ~TIPC_NOTIFY_NODE_DOWN; | ||
| 571 | } | 579 | } |
| 572 | if (node->action_flags & TIPC_NOTIFY_NODE_UP) { | 580 | node->action_flags &= ~(TIPC_WAKEUP_USERS | TIPC_NOTIFY_NODE_DOWN | |
| 573 | node->action_flags &= ~TIPC_NOTIFY_NODE_UP; | 581 | TIPC_NOTIFY_NODE_UP | TIPC_NOTIFY_LINK_UP | |
| 574 | addr = node->addr; | 582 | TIPC_NOTIFY_LINK_DOWN | |
| 575 | } | 583 | TIPC_WAKEUP_BCAST_USERS); |
| 576 | node->action_flags &= ~TIPC_WAKEUP_BCAST_USERS; | 584 | |
| 577 | spin_unlock_bh(&node->lock); | 585 | spin_unlock_bh(&node->lock); |
| 578 | 586 | ||
| 579 | while (!skb_queue_empty(&waiting_sks)) | 587 | while (!skb_queue_empty(&waiting_sks)) |
| @@ -583,11 +591,109 @@ void tipc_node_unlock(struct tipc_node *node) | |||
| 583 | tipc_node_abort_sock_conns(&conn_sks); | 591 | tipc_node_abort_sock_conns(&conn_sks); |
| 584 | 592 | ||
| 585 | if (!list_empty(&nsub_list)) | 593 | if (!list_empty(&nsub_list)) |
| 586 | tipc_nodesub_notify(&nsub_list); | 594 | tipc_publ_notify(&nsub_list, addr); |
| 587 | 595 | ||
| 588 | if (flags & TIPC_WAKEUP_BCAST_USERS) | 596 | if (flags & TIPC_WAKEUP_BCAST_USERS) |
| 589 | tipc_bclink_wakeup_users(); | 597 | tipc_bclink_wakeup_users(); |
| 590 | 598 | ||
| 591 | if (addr) | 599 | if (flags & TIPC_NOTIFY_NODE_UP) |
| 592 | tipc_named_node_up(addr); | 600 | tipc_named_node_up(addr); |
| 601 | |||
| 602 | if (flags & TIPC_NOTIFY_LINK_UP) | ||
| 603 | tipc_nametbl_publish(TIPC_LINK_STATE, addr, addr, | ||
| 604 | TIPC_NODE_SCOPE, link_id, addr); | ||
| 605 | |||
| 606 | if (flags & TIPC_NOTIFY_LINK_DOWN) | ||
| 607 | tipc_nametbl_withdraw(TIPC_LINK_STATE, addr, | ||
| 608 | link_id, addr); | ||
| 609 | } | ||
| 610 | |||
| 611 | /* Caller should hold node lock for the passed node */ | ||
| 612 | static int __tipc_nl_add_node(struct tipc_nl_msg *msg, struct tipc_node *node) | ||
| 613 | { | ||
| 614 | void *hdr; | ||
| 615 | struct nlattr *attrs; | ||
| 616 | |||
| 617 | hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_v2_family, | ||
| 618 | NLM_F_MULTI, TIPC_NL_NODE_GET); | ||
| 619 | if (!hdr) | ||
| 620 | return -EMSGSIZE; | ||
| 621 | |||
| 622 | attrs = nla_nest_start(msg->skb, TIPC_NLA_NODE); | ||
| 623 | if (!attrs) | ||
| 624 | goto msg_full; | ||
| 625 | |||
| 626 | if (nla_put_u32(msg->skb, TIPC_NLA_NODE_ADDR, node->addr)) | ||
| 627 | goto attr_msg_full; | ||
| 628 | if (tipc_node_is_up(node)) | ||
| 629 | if (nla_put_flag(msg->skb, TIPC_NLA_NODE_UP)) | ||
| 630 | goto attr_msg_full; | ||
| 631 | |||
| 632 | nla_nest_end(msg->skb, attrs); | ||
| 633 | genlmsg_end(msg->skb, hdr); | ||
| 634 | |||
| 635 | return 0; | ||
| 636 | |||
| 637 | attr_msg_full: | ||
| 638 | nla_nest_cancel(msg->skb, attrs); | ||
| 639 | msg_full: | ||
| 640 | genlmsg_cancel(msg->skb, hdr); | ||
| 641 | |||
| 642 | return -EMSGSIZE; | ||
| 643 | } | ||
| 644 | |||
| 645 | int tipc_nl_node_dump(struct sk_buff *skb, struct netlink_callback *cb) | ||
| 646 | { | ||
| 647 | int err; | ||
| 648 | int done = cb->args[0]; | ||
| 649 | int last_addr = cb->args[1]; | ||
| 650 | struct tipc_node *node; | ||
| 651 | struct tipc_nl_msg msg; | ||
| 652 | |||
| 653 | if (done) | ||
| 654 | return 0; | ||
| 655 | |||
| 656 | msg.skb = skb; | ||
| 657 | msg.portid = NETLINK_CB(cb->skb).portid; | ||
| 658 | msg.seq = cb->nlh->nlmsg_seq; | ||
| 659 | |||
| 660 | rcu_read_lock(); | ||
| 661 | |||
| 662 | if (last_addr && !tipc_node_find(last_addr)) { | ||
| 663 | rcu_read_unlock(); | ||
| 664 | /* We never set seq or call nl_dump_check_consistent() this | ||
| 665 | * means that setting prev_seq here will cause the consistence | ||
| 666 | * check to fail in the netlink callback handler. Resulting in | ||
| 667 | * the NLMSG_DONE message having the NLM_F_DUMP_INTR flag set if | ||
| 668 | * the node state changed while we released the lock. | ||
| 669 | */ | ||
| 670 | cb->prev_seq = 1; | ||
| 671 | return -EPIPE; | ||
| 672 | } | ||
| 673 | |||
| 674 | list_for_each_entry_rcu(node, &tipc_node_list, list) { | ||
| 675 | if (last_addr) { | ||
| 676 | if (node->addr == last_addr) | ||
| 677 | last_addr = 0; | ||
| 678 | else | ||
| 679 | continue; | ||
| 680 | } | ||
| 681 | |||
| 682 | tipc_node_lock(node); | ||
| 683 | err = __tipc_nl_add_node(&msg, node); | ||
| 684 | if (err) { | ||
| 685 | last_addr = node->addr; | ||
| 686 | tipc_node_unlock(node); | ||
| 687 | goto out; | ||
| 688 | } | ||
| 689 | |||
| 690 | tipc_node_unlock(node); | ||
| 691 | } | ||
| 692 | done = 1; | ||
| 693 | out: | ||
| 694 | cb->args[0] = done; | ||
| 695 | cb->args[1] = last_addr; | ||
| 696 | rcu_read_unlock(); | ||
| 697 | |||
| 698 | return skb->len; | ||
| 593 | } | 699 | } |
