Skip to content

Commit cf6f7e1

Browse files
Parthasarathy Bhuvaragandavem330
authored andcommitted
tipc: dump monitor attributes
In this commit, we dump the monitor attributes when queried. The link monitor attributes are separated into two kinds: 1. general attributes per bearer 2. specific attributes per node/peer This style resembles the socket attributes and the nametable publications per socket. Reviewed-by: Jon Maloy <[email protected]> Signed-off-by: Parthasarathy Bhuvaragan <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent ff0d3e7 commit cf6f7e1

File tree

6 files changed

+260
-0
lines changed

6 files changed

+260
-0
lines changed

include/uapi/linux/tipc_netlink.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ enum {
5858
TIPC_NL_NAME_TABLE_GET,
5959
TIPC_NL_MON_SET,
6060
TIPC_NL_MON_GET,
61+
TIPC_NL_MON_PEER_GET,
6162

6263
__TIPC_NL_CMD_MAX,
6364
TIPC_NL_CMD_MAX = __TIPC_NL_CMD_MAX - 1
@@ -75,6 +76,7 @@ enum {
7576
TIPC_NLA_NET, /* nest */
7677
TIPC_NLA_NAME_TABLE, /* nest */
7778
TIPC_NLA_MON, /* nest */
79+
TIPC_NLA_MON_PEER, /* nest */
7880

7981
__TIPC_NLA_MAX,
8082
TIPC_NLA_MAX = __TIPC_NLA_MAX - 1
@@ -173,6 +175,11 @@ enum {
173175
enum {
174176
TIPC_NLA_MON_UNSPEC,
175177
TIPC_NLA_MON_ACTIVATION_THRESHOLD, /* u32 */
178+
TIPC_NLA_MON_REF, /* u32 */
179+
TIPC_NLA_MON_ACTIVE, /* flag */
180+
TIPC_NLA_MON_BEARER_NAME, /* string */
181+
TIPC_NLA_MON_PEERCNT, /* u32 */
182+
TIPC_NLA_MON_LISTGEN, /* u32 */
176183

177184
__TIPC_NLA_MON_MAX,
178185
TIPC_NLA_MON_MAX = __TIPC_NLA_MON_MAX - 1
@@ -194,6 +201,24 @@ enum {
194201
TIPC_NLA_PUBL_MAX = __TIPC_NLA_PUBL_MAX - 1
195202
};
196203

204+
/* Monitor peer info */
205+
enum {
206+
TIPC_NLA_MON_PEER_UNSPEC,
207+
208+
TIPC_NLA_MON_PEER_ADDR, /* u32 */
209+
TIPC_NLA_MON_PEER_DOMGEN, /* u32 */
210+
TIPC_NLA_MON_PEER_APPLIED, /* u32 */
211+
TIPC_NLA_MON_PEER_UPMAP, /* u64 */
212+
TIPC_NLA_MON_PEER_MEMBERS, /* tlv */
213+
TIPC_NLA_MON_PEER_UP, /* flag */
214+
TIPC_NLA_MON_PEER_HEAD, /* flag */
215+
TIPC_NLA_MON_PEER_LOCAL, /* flag */
216+
TIPC_NLA_MON_PEER_PAD, /* flag */
217+
218+
__TIPC_NLA_MON_PEER_MAX,
219+
TIPC_NLA_MON_PEER_MAX = __TIPC_NLA_MON_PEER_MAX - 1
220+
};
221+
197222
/* Nest, connection info */
198223
enum {
199224
TIPC_NLA_CON_UNSPEC,

net/tipc/monitor.c

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@
3333
* POSSIBILITY OF SUCH DAMAGE.
3434
*/
3535

36+
#include <net/genetlink.h>
3637
#include "core.h"
3738
#include "addr.h"
3839
#include "monitor.h"
40+
#include "bearer.h"
3941

4042
#define MAX_MON_DOMAIN 64
4143
#define MON_TIMEOUT 120000
@@ -668,3 +670,134 @@ int tipc_nl_monitor_get_threshold(struct net *net)
668670

669671
return tn->mon_threshold;
670672
}
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+
}

net/tipc/monitor.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
#ifndef _TIPC_MONITOR_H
3737
#define _TIPC_MONITOR_H
3838

39+
#include "netlink.h"
40+
3941
/* struct tipc_mon_state: link instance's cache of monitor list and domain state
4042
* @list_gen: current generation of this node's monitor list
4143
* @gen: current generation of this node's local domain
@@ -71,6 +73,10 @@ void tipc_mon_remove_peer(struct net *net, u32 addr, int bearer_id);
7173

7274
int tipc_nl_monitor_set_threshold(struct net *net, u32 cluster_size);
7375
int tipc_nl_monitor_get_threshold(struct net *net);
76+
int __tipc_nl_add_monitor(struct net *net, struct tipc_nl_msg *msg,
77+
u32 bearer_id);
78+
int tipc_nl_add_monitor_peer(struct net *net, struct tipc_nl_msg *msg,
79+
u32 bearer_id, u32 *prev_node);
7480

7581
extern const int tipc_max_domain_size;
7682
#endif

net/tipc/netlink.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ tipc_nl_name_table_policy[TIPC_NLA_NAME_TABLE_MAX + 1] = {
6464

6565
const struct nla_policy tipc_nl_monitor_policy[TIPC_NLA_MON_MAX + 1] = {
6666
[TIPC_NLA_MON_UNSPEC] = { .type = NLA_UNSPEC },
67+
[TIPC_NLA_MON_REF] = { .type = NLA_U32 },
6768
[TIPC_NLA_MON_ACTIVATION_THRESHOLD] = { .type = NLA_U32 },
6869
};
6970

@@ -229,6 +230,12 @@ static const struct genl_ops tipc_genl_v2_ops[] = {
229230
{
230231
.cmd = TIPC_NL_MON_GET,
231232
.doit = tipc_nl_node_get_monitor,
233+
.dumpit = tipc_nl_node_dump_monitor,
234+
.policy = tipc_nl_policy,
235+
},
236+
{
237+
.cmd = TIPC_NL_MON_PEER_GET,
238+
.dumpit = tipc_nl_node_dump_monitor_peer,
232239
.policy = tipc_nl_policy,
233240
},
234241
};

net/tipc/node.c

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2007,3 +2007,89 @@ int tipc_nl_node_get_monitor(struct sk_buff *skb, struct genl_info *info)
20072007

20082008
return genlmsg_reply(msg.skb, info);
20092009
}
2010+
2011+
int tipc_nl_node_dump_monitor(struct sk_buff *skb, struct netlink_callback *cb)
2012+
{
2013+
struct net *net = sock_net(skb->sk);
2014+
u32 prev_bearer = cb->args[0];
2015+
struct tipc_nl_msg msg;
2016+
int err;
2017+
int i;
2018+
2019+
if (prev_bearer == MAX_BEARERS)
2020+
return 0;
2021+
2022+
msg.skb = skb;
2023+
msg.portid = NETLINK_CB(cb->skb).portid;
2024+
msg.seq = cb->nlh->nlmsg_seq;
2025+
2026+
rtnl_lock();
2027+
for (i = prev_bearer; i < MAX_BEARERS; i++) {
2028+
prev_bearer = i;
2029+
err = __tipc_nl_add_monitor(net, &msg, prev_bearer);
2030+
if (err)
2031+
goto out;
2032+
}
2033+
2034+
out:
2035+
rtnl_unlock();
2036+
cb->args[0] = prev_bearer;
2037+
2038+
return skb->len;
2039+
}
2040+
2041+
int tipc_nl_node_dump_monitor_peer(struct sk_buff *skb,
2042+
struct netlink_callback *cb)
2043+
{
2044+
struct net *net = sock_net(skb->sk);
2045+
u32 prev_node = cb->args[1];
2046+
u32 bearer_id = cb->args[2];
2047+
int done = cb->args[0];
2048+
struct tipc_nl_msg msg;
2049+
int err;
2050+
2051+
if (!prev_node) {
2052+
struct nlattr **attrs;
2053+
struct nlattr *mon[TIPC_NLA_MON_MAX + 1];
2054+
2055+
err = tipc_nlmsg_parse(cb->nlh, &attrs);
2056+
if (err)
2057+
return err;
2058+
2059+
if (!attrs[TIPC_NLA_MON])
2060+
return -EINVAL;
2061+
2062+
err = nla_parse_nested(mon, TIPC_NLA_MON_MAX,
2063+
attrs[TIPC_NLA_MON],
2064+
tipc_nl_monitor_policy);
2065+
if (err)
2066+
return err;
2067+
2068+
if (!mon[TIPC_NLA_MON_REF])
2069+
return -EINVAL;
2070+
2071+
bearer_id = nla_get_u32(mon[TIPC_NLA_MON_REF]);
2072+
2073+
if (bearer_id >= MAX_BEARERS)
2074+
return -EINVAL;
2075+
}
2076+
2077+
if (done)
2078+
return 0;
2079+
2080+
msg.skb = skb;
2081+
msg.portid = NETLINK_CB(cb->skb).portid;
2082+
msg.seq = cb->nlh->nlmsg_seq;
2083+
2084+
rtnl_lock();
2085+
err = tipc_nl_add_monitor_peer(net, &msg, bearer_id, &prev_node);
2086+
if (!err)
2087+
done = 1;
2088+
2089+
rtnl_unlock();
2090+
cb->args[0] = done;
2091+
cb->args[1] = prev_node;
2092+
cb->args[2] = bearer_id;
2093+
2094+
return skb->len;
2095+
}

net/tipc/node.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,7 @@ int tipc_nl_node_set_link(struct sk_buff *skb, struct genl_info *info);
8080

8181
int tipc_nl_node_set_monitor(struct sk_buff *skb, struct genl_info *info);
8282
int tipc_nl_node_get_monitor(struct sk_buff *skb, struct genl_info *info);
83+
int tipc_nl_node_dump_monitor(struct sk_buff *skb, struct netlink_callback *cb);
84+
int tipc_nl_node_dump_monitor_peer(struct sk_buff *skb,
85+
struct netlink_callback *cb);
8386
#endif

0 commit comments

Comments
 (0)