]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - ip/iproute.c
ip route: Print "rt_offload" and "rt_trap" indication
[mirror_iproute2.git] / ip / iproute.c
index 6b8142250349f71764a83612ec1d29ee88ef5b05..93b805c9004d65c1917d94724b79448b4c3cd40b 100644 (file)
@@ -368,6 +368,10 @@ void print_rt_flags(FILE *fp, unsigned int flags)
                print_string(PRINT_ANY, NULL, "%s ", "linkdown");
        if (flags & RTNH_F_UNRESOLVED)
                print_string(PRINT_ANY, NULL, "%s ", "unresolved");
+       if (flags & RTM_F_OFFLOAD)
+               print_string(PRINT_ANY, NULL, "%s ", "rt_offload");
+       if (flags & RTM_F_TRAP)
+               print_string(PRINT_ANY, NULL, "%s ", "rt_trap");
 
        close_json_array(PRINT_JSON, NULL);
 }
@@ -576,6 +580,7 @@ static void print_rta_metrics(FILE *fp, const struct rtattr *rta)
        int i;
 
        open_json_array(PRINT_JSON, "metrics");
+       open_json_object(NULL);
 
        parse_rtattr(mxrta, RTAX_MAX, RTA_DATA(rta), RTA_PAYLOAD(rta));
 
@@ -609,7 +614,7 @@ static void print_rta_metrics(FILE *fp, const struct rtattr *rta)
                        print_rtax_features(fp, val);
                        break;
                default:
-                       fprintf(fp, "%u ", val);
+                       print_uint(PRINT_ANY, mx_names[i], "%u ", val);
                        break;
 
                case RTAX_RTT:
@@ -637,6 +642,7 @@ static void print_rta_metrics(FILE *fp, const struct rtattr *rta)
                }
        }
 
+       close_json_object();
        close_json_array(PRINT_JSON, NULL);
 }
 
@@ -647,24 +653,26 @@ static void print_rta_multipath(FILE *fp, const struct rtmsg *r,
        int len = RTA_PAYLOAD(rta);
        int first = 1;
 
+       open_json_array(PRINT_JSON, "nexthops");
+
        while (len >= sizeof(*nh)) {
                struct rtattr *tb[RTA_MAX + 1];
 
                if (nh->rtnh_len > len)
                        break;
 
-               if (!is_json_context()) {
-                       if ((r->rtm_flags & RTM_F_CLONED) &&
-                           r->rtm_type == RTN_MULTICAST) {
-                               if (first) {
-                                       fprintf(fp, "Oifs: ");
-                                       first = 0;
-                               } else {
-                                       fprintf(fp, " ");
-                               }
-                       } else
-                               fprintf(fp, "%s\tnexthop ", _SL_);
-               }
+               open_json_object(NULL);
+
+               if ((r->rtm_flags & RTM_F_CLONED) &&
+                   r->rtm_type == RTN_MULTICAST) {
+                       if (first) {
+                               print_string(PRINT_FP, NULL, "Oifs: ", NULL);
+                               first = 0;
+                       } else {
+                               print_string(PRINT_FP, NULL, " ", NULL);
+                       }
+               } else
+                       print_string(PRINT_FP, NULL, "%s\tnexthop ", _SL_);
 
                if (nh->rtnh_len > sizeof(*nh)) {
                        parse_rtattr(tb, RTA_MAX, RTNH_DATA(nh),
@@ -687,22 +695,30 @@ static void print_rta_multipath(FILE *fp, const struct rtmsg *r,
 
                if ((r->rtm_flags & RTM_F_CLONED) &&
                    r->rtm_type == RTN_MULTICAST) {
-                       fprintf(fp, "%s", ll_index_to_name(nh->rtnh_ifindex));
+                       print_string(PRINT_ANY, "dev",
+                                    "%s", ll_index_to_name(nh->rtnh_ifindex));
+
                        if (nh->rtnh_hops != 1)
-                               fprintf(fp, "(ttl>%d)", nh->rtnh_hops);
-                       fprintf(fp, " ");
+                               print_int(PRINT_ANY, "ttl", "(ttl>%d)", nh->rtnh_hops);
+
+                       print_string(PRINT_FP, NULL, " ", NULL);
                } else {
-                       fprintf(fp, "dev %s ", ll_index_to_name(nh->rtnh_ifindex));
+                       print_string(PRINT_ANY, "dev",
+                                    "dev %s ", ll_index_to_name(nh->rtnh_ifindex));
+
                        if (r->rtm_family != AF_MPLS)
-                               fprintf(fp, "weight %d ",
-                                       nh->rtnh_hops+1);
+                               print_int(PRINT_ANY, "weight",
+                                         "weight %d ", nh->rtnh_hops + 1);
                }
 
                print_rt_flags(fp, nh->rtnh_flags);
 
                len -= NLMSG_ALIGN(nh->rtnh_len);
                nh = RTNH_NEXT(nh);
+
+               close_json_object();
        }
+       close_json_array(PRINT_JSON, NULL);
 }
 
 int print_route(struct nlmsghdr *n, void *arg)
@@ -1613,6 +1629,30 @@ static int save_route_prep(void)
        return 0;
 }
 
+static int iproute_dump_filter(struct nlmsghdr *nlh, int reqlen)
+{
+       struct rtmsg *rtm = NLMSG_DATA(nlh);
+       int err;
+
+       rtm->rtm_protocol = filter.protocol;
+       if (filter.cloned)
+               rtm->rtm_flags |= RTM_F_CLONED;
+
+       if (filter.tb) {
+               err = addattr32(nlh, reqlen, RTA_TABLE, filter.tb);
+               if (err)
+                       return err;
+       }
+
+       if (filter.oif) {
+               err = addattr32(nlh, reqlen, RTA_OIF, filter.oif);
+               if (err)
+                       return err;
+       }
+
+       return 0;
+}
+
 static int iproute_flush(int family, rtnl_filter_t filter_fn)
 {
        time_t start = time(0);
@@ -1635,7 +1675,7 @@ static int iproute_flush(int family, rtnl_filter_t filter_fn)
        filter.flushe = sizeof(flushb);
 
        for (;;) {
-               if (rtnl_routedump_req(&rth, family, NULL) < 0) {
+               if (rtnl_routedump_req(&rth, family, iproute_dump_filter) < 0) {
                        perror("Cannot send dump request");
                        return -2;
                }
@@ -1675,30 +1715,6 @@ static int iproute_flush(int family, rtnl_filter_t filter_fn)
        }
 }
 
-static int iproute_dump_filter(struct nlmsghdr *nlh, int reqlen)
-{
-       struct rtmsg *rtm = NLMSG_DATA(nlh);
-       int err;
-
-       rtm->rtm_protocol = filter.protocol;
-       if (filter.cloned)
-               rtm->rtm_flags |= RTM_F_CLONED;
-
-       if (filter.tb) {
-               err = addattr32(nlh, reqlen, RTA_TABLE, filter.tb);
-               if (err)
-                       return err;
-       }
-
-       if (filter.oif) {
-               err = addattr32(nlh, reqlen, RTA_OIF, filter.oif);
-               if (err)
-                       return err;
-       }
-
-       return 0;
-}
-
 static int iproute_list_flush_or_save(int argc, char **argv, int action)
 {
        int dump_family = preferred_family;