]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - ip/iptoken.c
rdma: Provide and reuse filter functions
[mirror_iproute2.git] / ip / iptoken.c
index 0528bad70a80e6357b8107a8cd687a84f47c2e26..f1194c3e1aa453007639babfc122e13829d55ba6 100644 (file)
@@ -13,7 +13,6 @@
 #include <stdlib.h>
 #include <stdbool.h>
 #include <unistd.h>
-#include <syslog.h>
 #include <fcntl.h>
 #include <string.h>
 #include <sys/socket.h>
@@ -26,6 +25,7 @@
 #include "rt_names.h"
 #include "utils.h"
 #include "ip_common.h"
+#include "json_print.h"
 
 extern struct rtnl_handle rth;
 
@@ -42,7 +42,7 @@ static void usage(void)
        exit(-1);
 }
 
-static int print_token(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
+static int print_token(struct nlmsghdr *n, void *arg)
 {
        struct rtnl_dump_args *args = arg;
        FILE *fp = args->fp;
@@ -78,9 +78,17 @@ static int print_token(const struct sockaddr_nl *who, struct nlmsghdr *n, void *
                return -1;
        }
 
-       fprintf(fp, "token %s dev %s\n",
-               format_host_rta(ifi->ifi_family, ltb[IFLA_INET6_TOKEN]),
-               ll_index_to_name(ifi->ifi_index));
+       open_json_object(NULL);
+       print_string(PRINT_FP, NULL, "token ", NULL);
+       print_color_string(PRINT_ANY,
+                          ifa_family_color(ifi->ifi_family),
+                          "token", "%s",
+                          format_host_rta(ifi->ifi_family, ltb[IFLA_INET6_TOKEN]));
+       print_string(PRINT_FP, NULL, " dev ", NULL);
+       print_color_string(PRINT_ANY, COLOR_IFNAME,
+                          "ifname", "%s\n",
+                          ll_index_to_name(ifi->ifi_index));
+       close_json_object();
        fflush(fp);
 
        return 0;
@@ -101,15 +109,18 @@ static int iptoken_list(int argc, char **argv)
                argc--; argv++;
        }
 
-       if (rtnl_wilddump_request(&rth, af, RTM_GETLINK) < 0) {
+       if (rtnl_linkdump_req(&rth, af) < 0) {
                perror("Cannot send dump request");
                return -1;
        }
 
+       new_json_obj(json);
        if (rtnl_dump_filter(&rth, print_token, &da) < 0) {
+               delete_json_obj();
                fprintf(stderr, "Dump terminated\n");
                return -1;
        }
+       delete_json_obj();
 
        return 0;
 }