|
33 | 33 | * POSSIBILITY OF SUCH DAMAGE. |
34 | 34 | */ |
35 | 35 |
|
| 36 | +#include <net/genetlink.h> |
36 | 37 | #include "core.h" |
37 | 38 | #include "addr.h" |
38 | 39 | #include "monitor.h" |
| 40 | +#include "bearer.h" |
39 | 41 |
|
40 | 42 | #define MAX_MON_DOMAIN 64 |
41 | 43 | #define MON_TIMEOUT 120000 |
@@ -668,3 +670,134 @@ int tipc_nl_monitor_get_threshold(struct net *net) |
668 | 670 |
|
669 | 671 | return tn->mon_threshold; |
670 | 672 | } |
| 673 | + |
| 674 | +int __tipc_nl_add_monitor_peer(struct tipc_peer *peer, struct tipc_nl_msg *msg) |
| 675 | +{ |
| 676 | + struct tipc_mon_domain *dom = peer->domain; |
| 677 | + struct nlattr *attrs; |
| 678 | + void *hdr; |
| 679 | + |
| 680 | + hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family, |
| 681 | + NLM_F_MULTI, TIPC_NL_MON_PEER_GET); |
| 682 | + if (!hdr) |
| 683 | + return -EMSGSIZE; |
| 684 | + |
| 685 | + attrs = nla_nest_start(msg->skb, TIPC_NLA_MON_PEER); |
| 686 | + if (!attrs) |
| 687 | + goto msg_full; |
| 688 | + |
| 689 | + if (nla_put_u32(msg->skb, TIPC_NLA_MON_PEER_ADDR, peer->addr)) |
| 690 | + goto attr_msg_full; |
| 691 | + if (nla_put_u32(msg->skb, TIPC_NLA_MON_PEER_APPLIED, peer->applied)) |
| 692 | + goto attr_msg_full; |
| 693 | + |
| 694 | + if (peer->is_up) |
| 695 | + if (nla_put_flag(msg->skb, TIPC_NLA_MON_PEER_UP)) |
| 696 | + goto attr_msg_full; |
| 697 | + if (peer->is_local) |
| 698 | + if (nla_put_flag(msg->skb, TIPC_NLA_MON_PEER_LOCAL)) |
| 699 | + goto attr_msg_full; |
| 700 | + if (peer->is_head) |
| 701 | + if (nla_put_flag(msg->skb, TIPC_NLA_MON_PEER_HEAD)) |
| 702 | + goto attr_msg_full; |
| 703 | + |
| 704 | + if (dom) { |
| 705 | + if (nla_put_u32(msg->skb, TIPC_NLA_MON_PEER_DOMGEN, dom->gen)) |
| 706 | + goto attr_msg_full; |
| 707 | + if (nla_put_u64_64bit(msg->skb, TIPC_NLA_MON_PEER_UPMAP, |
| 708 | + dom->up_map, TIPC_NLA_MON_PEER_PAD)) |
| 709 | + goto attr_msg_full; |
| 710 | + if (nla_put(msg->skb, TIPC_NLA_MON_PEER_MEMBERS, |
| 711 | + dom->member_cnt * sizeof(u32), &dom->members)) |
| 712 | + goto attr_msg_full; |
| 713 | + } |
| 714 | + |
| 715 | + nla_nest_end(msg->skb, attrs); |
| 716 | + genlmsg_end(msg->skb, hdr); |
| 717 | + return 0; |
| 718 | + |
| 719 | +attr_msg_full: |
| 720 | + nla_nest_cancel(msg->skb, attrs); |
| 721 | +msg_full: |
| 722 | + genlmsg_cancel(msg->skb, hdr); |
| 723 | + |
| 724 | + return -EMSGSIZE; |
| 725 | +} |
| 726 | + |
| 727 | +int tipc_nl_add_monitor_peer(struct net *net, struct tipc_nl_msg *msg, |
| 728 | + u32 bearer_id, u32 *prev_node) |
| 729 | +{ |
| 730 | + struct tipc_monitor *mon = tipc_monitor(net, bearer_id); |
| 731 | + struct tipc_peer *peer = mon->self; |
| 732 | + |
| 733 | + if (!mon) |
| 734 | + return -EINVAL; |
| 735 | + |
| 736 | + read_lock_bh(&mon->lock); |
| 737 | + do { |
| 738 | + if (*prev_node) { |
| 739 | + if (peer->addr == *prev_node) |
| 740 | + *prev_node = 0; |
| 741 | + else |
| 742 | + continue; |
| 743 | + } |
| 744 | + if (__tipc_nl_add_monitor_peer(peer, msg)) { |
| 745 | + *prev_node = peer->addr; |
| 746 | + read_unlock_bh(&mon->lock); |
| 747 | + return -EMSGSIZE; |
| 748 | + } |
| 749 | + } while ((peer = peer_nxt(peer)) != mon->self); |
| 750 | + read_unlock_bh(&mon->lock); |
| 751 | + |
| 752 | + return 0; |
| 753 | +} |
| 754 | + |
| 755 | +int __tipc_nl_add_monitor(struct net *net, struct tipc_nl_msg *msg, |
| 756 | + u32 bearer_id) |
| 757 | +{ |
| 758 | + struct tipc_monitor *mon = tipc_monitor(net, bearer_id); |
| 759 | + char bearer_name[TIPC_MAX_BEARER_NAME]; |
| 760 | + struct nlattr *attrs; |
| 761 | + void *hdr; |
| 762 | + int ret; |
| 763 | + |
| 764 | + ret = tipc_bearer_get_name(net, bearer_name, bearer_id); |
| 765 | + if (ret || !mon) |
| 766 | + return -EINVAL; |
| 767 | + |
| 768 | + hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family, |
| 769 | + NLM_F_MULTI, TIPC_NL_MON_GET); |
| 770 | + if (!hdr) |
| 771 | + return -EMSGSIZE; |
| 772 | + |
| 773 | + attrs = nla_nest_start(msg->skb, TIPC_NLA_MON); |
| 774 | + if (!attrs) |
| 775 | + goto msg_full; |
| 776 | + |
| 777 | + read_lock_bh(&mon->lock); |
| 778 | + if (nla_put_u32(msg->skb, TIPC_NLA_MON_REF, bearer_id)) |
| 779 | + goto attr_msg_full; |
| 780 | + if (tipc_mon_is_active(net, mon)) |
| 781 | + if (nla_put_flag(msg->skb, TIPC_NLA_MON_ACTIVE)) |
| 782 | + goto attr_msg_full; |
| 783 | + if (nla_put_string(msg->skb, TIPC_NLA_MON_BEARER_NAME, bearer_name)) |
| 784 | + goto attr_msg_full; |
| 785 | + if (nla_put_u32(msg->skb, TIPC_NLA_MON_PEERCNT, mon->peer_cnt)) |
| 786 | + goto attr_msg_full; |
| 787 | + if (nla_put_u32(msg->skb, TIPC_NLA_MON_LISTGEN, mon->list_gen)) |
| 788 | + goto attr_msg_full; |
| 789 | + |
| 790 | + read_unlock_bh(&mon->lock); |
| 791 | + nla_nest_end(msg->skb, attrs); |
| 792 | + genlmsg_end(msg->skb, hdr); |
| 793 | + |
| 794 | + return 0; |
| 795 | + |
| 796 | +attr_msg_full: |
| 797 | + nla_nest_cancel(msg->skb, attrs); |
| 798 | +msg_full: |
| 799 | + genlmsg_cancel(msg->skb, hdr); |
| 800 | + read_unlock_bh(&mon->lock); |
| 801 | + |
| 802 | + return -EMSGSIZE; |
| 803 | +} |
0 commit comments