tipc: fixed node and name table listings

We make it easier for users to correlate between 128-bit node
identities and 32-bit node hash number by extending the 'node list'
command to also show the hash number.

We also improve the 'nametable show' command to show the node identity
instead of the node hash number. Since the former potentially is much
longer than the latter, we make room for it by eliminating the (to the
user) irrelevant publication key. We also reorder some of the columns so
that the node id comes last, since this looks nicer and is more logical.

Signed-off-by: David Ahern <dsahern@gmail.com>
This commit is contained in:
Jon Maloy 2018-05-17 16:02:42 +02:00 committed by David Ahern
parent 53d34eb66c
commit 5947046dd9
5 changed files with 43 additions and 19 deletions

View File

@ -13,6 +13,10 @@
#include <stdint.h>
#include <linux/tipc.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <unistd.h>
#include <errno.h>
#include "misc.h"
#define IN_RANGE(val, low, high) ((val) <= (high) && (val) >= (low))
@ -109,3 +113,19 @@ void nodeid2str(uint8_t *id, char *str)
for (i = 31; str[i] == '0'; i--)
str[i] = 0;
}
void hash2nodestr(uint32_t hash, char *str)
{
struct tipc_sioc_nodeid_req nr = {};
int sd;
sd = socket(AF_TIPC, SOCK_RDM, 0);
if (sd < 0) {
fprintf(stderr, "opening TIPC socket: %s\n", strerror(errno));
return;
}
nr.peer = hash;
if (!ioctl(sd, SIOCGETNODEID, &nr))
nodeid2str((uint8_t *)nr.node_id, str);
close(sd);
}

View File

@ -17,5 +17,6 @@
uint32_t str2addr(char *str);
int str2nodeid(char *str, uint8_t *id);
void nodeid2str(uint8_t *id, char *str);
void hash2nodestr(uint32_t hash, char *str);
#endif

View File

@ -20,6 +20,7 @@
#include "cmdl.h"
#include "msg.h"
#include "nametable.h"
#include "misc.h"
#define PORTID_STR_LEN 45 /* Four u32 and five delimiter chars */
@ -31,6 +32,7 @@ static int nametable_show_cb(const struct nlmsghdr *nlh, void *data)
struct nlattr *attrs[TIPC_NLA_NAME_TABLE_MAX + 1] = {};
struct nlattr *publ[TIPC_NLA_PUBL_MAX + 1] = {};
const char *scope[] = { "", "zone", "cluster", "node" };
char str[33] = {0,};
mnl_attr_parse(nlh, sizeof(*genl), parse_attrs, info);
if (!info[TIPC_NLA_NAME_TABLE])
@ -45,20 +47,20 @@ static int nametable_show_cb(const struct nlmsghdr *nlh, void *data)
return MNL_CB_ERROR;
if (!*iteration)
printf("%-10s %-10s %-10s %-10s %-10s %-10s\n",
"Type", "Lower", "Upper", "Node", "Port",
"Publication Scope");
printf("%-10s %-10s %-10s %-8s %-10s %-33s\n",
"Type", "Lower", "Upper", "Scope", "Port",
"Node");
(*iteration)++;
printf("%-10u %-10u %-10u %-10x %-10u %-12u",
hash2nodestr(mnl_attr_get_u32(publ[TIPC_NLA_PUBL_NODE]), str);
printf("%-10u %-10u %-10u %-8s %-10u %s\n",
mnl_attr_get_u32(publ[TIPC_NLA_PUBL_TYPE]),
mnl_attr_get_u32(publ[TIPC_NLA_PUBL_LOWER]),
mnl_attr_get_u32(publ[TIPC_NLA_PUBL_UPPER]),
mnl_attr_get_u32(publ[TIPC_NLA_PUBL_NODE]),
scope[mnl_attr_get_u32(publ[TIPC_NLA_PUBL_SCOPE])],
mnl_attr_get_u32(publ[TIPC_NLA_PUBL_REF]),
mnl_attr_get_u32(publ[TIPC_NLA_PUBL_KEY]));
printf("%s\n", scope[mnl_attr_get_u32(publ[TIPC_NLA_PUBL_SCOPE])]);
str);
return MNL_CB_OK;
}

View File

@ -26,10 +26,11 @@
static int node_list_cb(const struct nlmsghdr *nlh, void *data)
{
uint32_t addr;
struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
struct nlattr *info[TIPC_NLA_MAX + 1] = {};
struct nlattr *attrs[TIPC_NLA_NODE_MAX + 1] = {};
char str[33] = {};
uint32_t addr;
mnl_attr_parse(nlh, sizeof(*genl), parse_attrs, info);
if (!info[TIPC_NLA_NODE])
@ -40,13 +41,12 @@ static int node_list_cb(const struct nlmsghdr *nlh, void *data)
return MNL_CB_ERROR;
addr = mnl_attr_get_u32(attrs[TIPC_NLA_NODE_ADDR]);
printf("%x: ", addr);
hash2nodestr(addr, str);
printf("%-32s %08x ", str, addr);
if (attrs[TIPC_NLA_NODE_UP])
printf("up\n");
else
printf("down\n");
return MNL_CB_OK;
}
@ -64,7 +64,7 @@ static int cmd_node_list(struct nlmsghdr *nlh, const struct cmd *cmd,
fprintf(stderr, "error, message initialisation failed\n");
return -1;
}
printf("Node Identity Hash State\n");
return msg_dumpit(nlh, node_list_cb, NULL);
}
@ -120,7 +120,7 @@ static int cmd_node_get_addr(struct nlmsghdr *nlh, const struct cmd *cmd,
}
close(sk);
printf("%x\n", addr.addr.id.node);
printf("%08x\n", addr.addr.id.node);
return 0;
}
@ -167,7 +167,6 @@ static int nodeid_get_cb(const struct nlmsghdr *nlh, void *data)
uint8_t id[16] = {0,};
uint64_t *w0 = (uint64_t *) &id[0];
uint64_t *w1 = (uint64_t *) &id[8];
int i;
mnl_attr_parse(nlh, sizeof(*genl), parse_attrs, info);
if (!info[TIPC_NLA_NET])
@ -180,10 +179,8 @@ static int nodeid_get_cb(const struct nlmsghdr *nlh, void *data)
*w0 = mnl_attr_get_u64(attrs[TIPC_NLA_NET_NODEID]);
*w1 = mnl_attr_get_u64(attrs[TIPC_NLA_NET_NODEID_W1]);
nodeid2str(id, str);
printf("Node Identity Hash\n");
printf("%s", str);
for (i = strlen(str); i <= 33; i++)
printf(" ");
printf("Node Identity Hash\n");
printf("%-33s", str);
cmd_node_get_addr(NULL, NULL, NULL, NULL);
return MNL_CB_OK;
}

View File

@ -39,7 +39,11 @@ static int cmd_peer_rm_addr(struct nlmsghdr *nlh, const struct cmd *cmd,
}
str = shift_cmdl(cmdl);
/* First try legacy Z.C.N format, then integer format */
addr = str2addr(str);
if (!addr)
addr = atoi(str);
if (!addr)
return -1;