]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - tipc/nametable.c
ll_map: Add function to remove link cache entry by index
[mirror_iproute2.git] / tipc / nametable.c
index ae73dfa5f8b9b8350d9ad4c964b7bcf45178f203..d899eeb67c07dcf0edd2d32410b7d0c6413b3f1d 100644 (file)
@@ -21,6 +21,7 @@
 #include "msg.h"
 #include "nametable.h"
 #include "misc.h"
+#include "utils.h"
 
 #define PORTID_STR_LEN 45 /* Four u32 and five delimiter chars */
 
@@ -46,7 +47,7 @@ static int nametable_show_cb(const struct nlmsghdr *nlh, void *data)
        if (!publ[TIPC_NLA_NAME_TABLE_PUBL])
                return MNL_CB_ERROR;
 
-       if (!*iteration)
+       if (!*iteration && !is_json_context())
                printf("%-10s %-10s %-10s %-8s %-10s %-33s\n",
                       "Type", "Lower", "Upper", "Scope", "Port",
                       "Node");
@@ -54,13 +55,25 @@ static int nametable_show_cb(const struct nlmsghdr *nlh, void *data)
 
        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]),
-              scope[mnl_attr_get_u32(publ[TIPC_NLA_PUBL_SCOPE])],
-              mnl_attr_get_u32(publ[TIPC_NLA_PUBL_REF]),
-              str);
+       open_json_object(NULL);
+       print_uint(PRINT_ANY, "type", "%-10u",
+                          mnl_attr_get_u32(publ[TIPC_NLA_PUBL_TYPE]));
+       print_string(PRINT_FP, NULL, " ", "");
+       print_uint(PRINT_ANY, "lower", "%-10u",
+                          mnl_attr_get_u32(publ[TIPC_NLA_PUBL_LOWER]));
+       print_string(PRINT_FP, NULL, " ", "");
+       print_uint(PRINT_ANY, "upper", "%-10u",
+                          mnl_attr_get_u32(publ[TIPC_NLA_PUBL_UPPER]));
+       print_string(PRINT_FP, NULL, " ", "");
+       print_string(PRINT_ANY, "scope", "%-8s",
+                            scope[mnl_attr_get_u32(publ[TIPC_NLA_PUBL_SCOPE])]);
+       print_string(PRINT_FP, NULL, " ", "");
+       print_uint(PRINT_ANY, "port", "%-10u",
+                          mnl_attr_get_u32(publ[TIPC_NLA_PUBL_REF]));
+       print_string(PRINT_FP, NULL, " ", "");
+       print_string(PRINT_ANY, "node", "%s", str);
+       print_string(PRINT_FP, NULL, "\n", "");
+       close_json_object();
 
        return MNL_CB_OK;
 }
@@ -70,6 +83,7 @@ static int cmd_nametable_show(struct nlmsghdr *nlh, const struct cmd *cmd,
 {
        int iteration = 0;
        char buf[MNL_SOCKET_BUFFER_SIZE];
+       int rc = 0;
 
        if (help_flag) {
                fprintf(stderr, "Usage: %s nametable show\n", cmdl->argv[0]);
@@ -81,7 +95,11 @@ static int cmd_nametable_show(struct nlmsghdr *nlh, const struct cmd *cmd,
                return -1;
        }
 
-       return msg_dumpit(nlh, nametable_show_cb, &iteration);
+       new_json_obj(json);
+       rc = msg_dumpit(nlh, nametable_show_cb, &iteration);
+       delete_json_obj();
+
+       return rc;
 }
 
 void cmd_nametable_help(struct cmdl *cmdl)