]> git.proxmox.com Git - mirror_iproute2.git/blob - tipc/nametable.c
tipc: fixed node and name table listings
[mirror_iproute2.git] / tipc / nametable.c
1 /*
2 * nametable.c TIPC nametable functionality.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 *
9 * Authors: Richard Alpe <richard.alpe@ericsson.com>
10 */
11
12 #include <stdio.h>
13 #include <errno.h>
14
15 #include <linux/tipc_netlink.h>
16 #include <linux/tipc.h>
17 #include <linux/genetlink.h>
18 #include <libmnl/libmnl.h>
19
20 #include "cmdl.h"
21 #include "msg.h"
22 #include "nametable.h"
23 #include "misc.h"
24
25 #define PORTID_STR_LEN 45 /* Four u32 and five delimiter chars */
26
27 static int nametable_show_cb(const struct nlmsghdr *nlh, void *data)
28 {
29 int *iteration = data;
30 struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
31 struct nlattr *info[TIPC_NLA_MAX + 1] = {};
32 struct nlattr *attrs[TIPC_NLA_NAME_TABLE_MAX + 1] = {};
33 struct nlattr *publ[TIPC_NLA_PUBL_MAX + 1] = {};
34 const char *scope[] = { "", "zone", "cluster", "node" };
35 char str[33] = {0,};
36
37 mnl_attr_parse(nlh, sizeof(*genl), parse_attrs, info);
38 if (!info[TIPC_NLA_NAME_TABLE])
39 return MNL_CB_ERROR;
40
41 mnl_attr_parse_nested(info[TIPC_NLA_NAME_TABLE], parse_attrs, attrs);
42 if (!attrs[TIPC_NLA_NAME_TABLE_PUBL])
43 return MNL_CB_ERROR;
44
45 mnl_attr_parse_nested(attrs[TIPC_NLA_NAME_TABLE_PUBL], parse_attrs, publ);
46 if (!publ[TIPC_NLA_NAME_TABLE_PUBL])
47 return MNL_CB_ERROR;
48
49 if (!*iteration)
50 printf("%-10s %-10s %-10s %-8s %-10s %-33s\n",
51 "Type", "Lower", "Upper", "Scope", "Port",
52 "Node");
53 (*iteration)++;
54
55 hash2nodestr(mnl_attr_get_u32(publ[TIPC_NLA_PUBL_NODE]), str);
56
57 printf("%-10u %-10u %-10u %-8s %-10u %s\n",
58 mnl_attr_get_u32(publ[TIPC_NLA_PUBL_TYPE]),
59 mnl_attr_get_u32(publ[TIPC_NLA_PUBL_LOWER]),
60 mnl_attr_get_u32(publ[TIPC_NLA_PUBL_UPPER]),
61 scope[mnl_attr_get_u32(publ[TIPC_NLA_PUBL_SCOPE])],
62 mnl_attr_get_u32(publ[TIPC_NLA_PUBL_REF]),
63 str);
64
65 return MNL_CB_OK;
66 }
67
68 static int cmd_nametable_show(struct nlmsghdr *nlh, const struct cmd *cmd,
69 struct cmdl *cmdl, void *data)
70 {
71 int iteration = 0;
72 char buf[MNL_SOCKET_BUFFER_SIZE];
73
74 if (help_flag) {
75 fprintf(stderr, "Usage: %s nametable show\n", cmdl->argv[0]);
76 return -EINVAL;
77 }
78
79 if (!(nlh = msg_init(buf, TIPC_NL_NAME_TABLE_GET))) {
80 fprintf(stderr, "error, message initialisation failed\n");
81 return -1;
82 }
83
84 return msg_dumpit(nlh, nametable_show_cb, &iteration);
85 }
86
87 void cmd_nametable_help(struct cmdl *cmdl)
88 {
89 fprintf(stderr,
90 "Usage: %s nametable COMMAND\n\n"
91 "COMMANDS\n"
92 " show - Show nametable\n",
93 cmdl->argv[0]);
94 }
95
96 int cmd_nametable(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl,
97 void *data)
98 {
99 const struct cmd cmds[] = {
100 { "show", cmd_nametable_show, NULL },
101 { NULL }
102 };
103
104 return run_cmd(nlh, cmd, cmds, cmdl, NULL);
105 }