]>
git.proxmox.com Git - mirror_iproute2.git/blob - tipc/nametable.c
2 * nametable.c TIPC nametable functionality.
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.
9 * Authors: Richard Alpe <richard.alpe@ericsson.com>
15 #include <linux/tipc_netlink.h>
16 #include <linux/tipc.h>
17 #include <linux/genetlink.h>
18 #include <libmnl/libmnl.h>
22 #include "nametable.h"
26 #define PORTID_STR_LEN 45 /* Four u32 and five delimiter chars */
28 static int nametable_show_cb(const struct nlmsghdr
*nlh
, void *data
)
30 int *iteration
= data
;
31 struct genlmsghdr
*genl
= mnl_nlmsg_get_payload(nlh
);
32 struct nlattr
*info
[TIPC_NLA_MAX
+ 1] = {};
33 struct nlattr
*attrs
[TIPC_NLA_NAME_TABLE_MAX
+ 1] = {};
34 struct nlattr
*publ
[TIPC_NLA_PUBL_MAX
+ 1] = {};
35 const char *scope
[] = { "", "zone", "cluster", "node" };
38 mnl_attr_parse(nlh
, sizeof(*genl
), parse_attrs
, info
);
39 if (!info
[TIPC_NLA_NAME_TABLE
])
42 mnl_attr_parse_nested(info
[TIPC_NLA_NAME_TABLE
], parse_attrs
, attrs
);
43 if (!attrs
[TIPC_NLA_NAME_TABLE_PUBL
])
46 mnl_attr_parse_nested(attrs
[TIPC_NLA_NAME_TABLE_PUBL
], parse_attrs
, publ
);
47 if (!publ
[TIPC_NLA_NAME_TABLE_PUBL
])
50 if (!*iteration
&& !is_json_context())
51 printf("%-10s %-10s %-10s %-8s %-10s %-33s\n",
52 "Type", "Lower", "Upper", "Scope", "Port",
56 hash2nodestr(mnl_attr_get_u32(publ
[TIPC_NLA_PUBL_NODE
]), str
);
58 open_json_object(NULL
);
59 print_uint(PRINT_ANY
, "type", "%-10u",
60 mnl_attr_get_u32(publ
[TIPC_NLA_PUBL_TYPE
]));
61 print_string(PRINT_FP
, NULL
, " ", "");
62 print_uint(PRINT_ANY
, "lower", "%-10u",
63 mnl_attr_get_u32(publ
[TIPC_NLA_PUBL_LOWER
]));
64 print_string(PRINT_FP
, NULL
, " ", "");
65 print_uint(PRINT_ANY
, "upper", "%-10u",
66 mnl_attr_get_u32(publ
[TIPC_NLA_PUBL_UPPER
]));
67 print_string(PRINT_FP
, NULL
, " ", "");
68 print_string(PRINT_ANY
, "scope", "%-8s",
69 scope
[mnl_attr_get_u32(publ
[TIPC_NLA_PUBL_SCOPE
])]);
70 print_string(PRINT_FP
, NULL
, " ", "");
71 print_uint(PRINT_ANY
, "port", "%-10u",
72 mnl_attr_get_u32(publ
[TIPC_NLA_PUBL_REF
]));
73 print_string(PRINT_FP
, NULL
, " ", "");
74 print_string(PRINT_ANY
, "node", "%s", str
);
75 print_string(PRINT_FP
, NULL
, "\n", "");
81 static int cmd_nametable_show(struct nlmsghdr
*nlh
, const struct cmd
*cmd
,
82 struct cmdl
*cmdl
, void *data
)
85 char buf
[MNL_SOCKET_BUFFER_SIZE
];
89 fprintf(stderr
, "Usage: %s nametable show\n", cmdl
->argv
[0]);
93 if (!(nlh
= msg_init(buf
, TIPC_NL_NAME_TABLE_GET
))) {
94 fprintf(stderr
, "error, message initialisation failed\n");
99 rc
= msg_dumpit(nlh
, nametable_show_cb
, &iteration
);
105 void cmd_nametable_help(struct cmdl
*cmdl
)
108 "Usage: %s nametable COMMAND\n\n"
110 " show - Show nametable\n",
114 int cmd_nametable(struct nlmsghdr
*nlh
, const struct cmd
*cmd
, struct cmdl
*cmdl
,
117 const struct cmd cmds
[] = {
118 { "show", cmd_nametable_show
, NULL
},
122 return run_cmd(nlh
, cmd
, cmds
, cmdl
, NULL
);