@@ -346,25 +346,29 @@ static void ip6tunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb
if (tb[IFLA_IPTUN_PROTO]) {
switch (rta_getattr_u8(tb[IFLA_IPTUN_PROTO])) {
case IPPROTO_IPIP:
- fprintf(f, "ipip6 ");
+ print_string(PRINT_ANY, "proto", "%s ", "ipip6");
break;
case IPPROTO_IPV6:
- fprintf(f, "ip6ip6 ");
+ print_string(PRINT_ANY, "proto", "%s ", "ip6ip6");
break;
case 0:
- fprintf(f, "any ");
+ print_string(PRINT_ANY, "proto", "%s ", "any");
break;
}
}
if (tb[IFLA_IPTUN_REMOTE]) {
- fprintf(f, "remote %s ",
- rt_addr_n2a_rta(AF_INET6, tb[IFLA_IPTUN_REMOTE]));
+ print_string(PRINT_ANY,
+ "remote",
+ "remote %s ",
+ rt_addr_n2a_rta(AF_INET6, tb[IFLA_IPTUN_REMOTE]));
}
if (tb[IFLA_IPTUN_LOCAL]) {
- fprintf(f, "local %s ",
- rt_addr_n2a_rta(AF_INET6, tb[IFLA_IPTUN_LOCAL]));
+ print_string(PRINT_ANY,
+ "local",
+ "local %s ",
+ rt_addr_n2a_rta(AF_INET6, tb[IFLA_IPTUN_LOCAL]));
}
if (tb[IFLA_IPTUN_LINK] && rta_getattr_u32(tb[IFLA_IPTUN_LINK])) {
@@ -372,93 +376,161 @@ static void ip6tunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb
const char *n = if_indextoname(link, s2);
if (n)
- fprintf(f, "dev %s ", n);
+ print_string(PRINT_ANY, "link", "dev %s ", n);
else
- fprintf(f, "dev %u ", link);
+ print_uint(PRINT_ANY, "link_index", "dev %u ", link);
}
if (flags & IP6_TNL_F_IGN_ENCAP_LIMIT)
- printf("encaplimit none ");
+ print_bool(PRINT_ANY,
+ "ip6_tnl_f_ign_encap_limit",
+ "encaplimit none ",
+ true);
else if (tb[IFLA_IPTUN_ENCAP_LIMIT])
- fprintf(f, "encaplimit %u ",
- rta_getattr_u8(tb[IFLA_IPTUN_ENCAP_LIMIT]));
+ print_uint(PRINT_ANY,
+ "encap_limit",
+ "encaplimit %u ",
+ rta_getattr_u8(tb[IFLA_IPTUN_ENCAP_LIMIT]));
if (tb[IFLA_IPTUN_TTL])
- fprintf(f, "hoplimit %u ", rta_getattr_u8(tb[IFLA_IPTUN_TTL]));
+ print_uint(PRINT_ANY,
+ "ttl",
+ "hoplimit %u ",
+ rta_getattr_u8(tb[IFLA_IPTUN_TTL]));
if (flags & IP6_TNL_F_USE_ORIG_TCLASS)
- printf("tclass inherit ");
+ print_bool(PRINT_ANY,
+ "ip6_tnl_f_use_orig_tclass",
+ "tclass inherit ",
+ true);
else if (tb[IFLA_IPTUN_FLOWINFO]) {
__u32 val = ntohl(flowinfo & IP6_FLOWINFO_TCLASS);
- printf("tclass 0x%02x ", (__u8)(val >> 20));
+ if (is_json_context()) {
+ SPRINT_BUF(b1);
+
+ snprintf(b1, sizeof(b1), "0x%02x", (__u8)(val >> 20));
+ print_string(PRINT_JSON, "flowinfo_tclass", NULL, b1);
+ } else {
+ printf("tclass 0x%02x ", (__u8)(val >> 20));
+ }
+ }
+
+ if (flags & IP6_TNL_F_USE_ORIG_FLOWLABEL) {
+ print_bool(PRINT_ANY,
+ "ip6_tnl_f_use_orig_flowlabel",
+ "flowlabel inherit ",
+ true);
+ } else {
+ if (is_json_context()) {
+ SPRINT_BUF(b1);
+
+ snprintf(b1, sizeof(b1), "0x%05x",
+ ntohl(flowinfo & IP6_FLOWINFO_FLOWLABEL));
+ print_string(PRINT_JSON, "flowlabel", NULL, b1);
+ } else {
+ printf("flowlabel 0x%05x ",
+ ntohl(flowinfo & IP6_FLOWINFO_FLOWLABEL));
+ }
}
- if (flags & IP6_TNL_F_USE_ORIG_FLOWLABEL)
- printf("flowlabel inherit ");
- else
- printf("flowlabel 0x%05x ", ntohl(flowinfo & IP6_FLOWINFO_FLOWLABEL));
+ if (is_json_context()) {
+ SPRINT_BUF(flwinfo);
- printf("(flowinfo 0x%08x) ", ntohl(flowinfo));
+ snprintf(flwinfo, sizeof(flwinfo), "0x%08x", ntohl(flowinfo));
+ print_string(PRINT_JSON, "flowinfo", NULL, flwinfo);
+ } else {
+ printf("(flowinfo 0x%08x) ", ntohl(flowinfo));
+
+ }
if (flags & IP6_TNL_F_RCV_DSCP_COPY)
- printf("dscp inherit ");
+ print_bool(PRINT_ANY,
+ "ip6_tnl_f_rcv_dscp_copy",
+ "dscp inherit ",
+ true);
if (flags & IP6_TNL_F_MIP6_DEV)
- fprintf(f, "mip6 ");
+ print_bool(PRINT_ANY, "ip6_tnl_f_mip6_dev", "mip6 ", true);
+
+ if (flags & IP6_TNL_F_USE_ORIG_FWMARK) {
+ print_bool(PRINT_ANY,
+ "ip6_tnl_f_use_orig_fwmark",
+ "fwmark inherit ",
+ true);
+ } else if (tb[IFLA_IPTUN_FWMARK]) {
+ __u32 fwmark = rta_getattr_u32(tb[IFLA_IPTUN_FWMARK]);
- if (flags & IP6_TNL_F_USE_ORIG_FWMARK)
- fprintf(f, "fwmark inherit ");
- else if (tb[IFLA_IPTUN_FWMARK] && rta_getattr_u32(tb[IFLA_IPTUN_FWMARK]))
- fprintf(f, "fwmark 0x%x ", rta_getattr_u32(tb[IFLA_IPTUN_FWMARK]));
+ if (fwmark) {
+ SPRINT_BUF(b1);
+
+ snprintf(b1, sizeof(b1), "0x%x", fwmark);
+ print_string(PRINT_ANY, "fwmark", "fwmark %s ", b1);
+ }
+ }
if (tb[IFLA_IPTUN_ENCAP_TYPE] &&
- rta_getattr_u16(tb[IFLA_IPTUN_ENCAP_TYPE]) !=
- TUNNEL_ENCAP_NONE) {
+ rta_getattr_u16(tb[IFLA_IPTUN_ENCAP_TYPE]) != TUNNEL_ENCAP_NONE) {
__u16 type = rta_getattr_u16(tb[IFLA_IPTUN_ENCAP_TYPE]);
__u16 flags = rta_getattr_u16(tb[IFLA_IPTUN_ENCAP_FLAGS]);
__u16 sport = rta_getattr_u16(tb[IFLA_IPTUN_ENCAP_SPORT]);
__u16 dport = rta_getattr_u16(tb[IFLA_IPTUN_ENCAP_DPORT]);
- fputs("encap ", f);
+ open_json_object("encap");
+ print_string(PRINT_FP, NULL, "encap ", NULL);
switch (type) {
case TUNNEL_ENCAP_FOU:
- fputs("fou ", f);
+ print_string(PRINT_ANY, "type", "%s ", "fou");
break;
case TUNNEL_ENCAP_GUE:
- fputs("gue ", f);
+ print_string(PRINT_ANY, "type", "%s ", "gue");
break;
default:
- fputs("unknown ", f);
+ print_null(PRINT_ANY, "type", "unknown ", NULL);
break;
}
- if (sport == 0)
- fputs("encap-sport auto ", f);
- else
- fprintf(f, "encap-sport %u", ntohs(sport));
+ if (is_json_context()) {
+ print_uint(PRINT_JSON,
+ "sport",
+ NULL,
+ sport ? ntohs(sport) : 0);
+ print_uint(PRINT_JSON, "dport", NULL, ntohs(dport));
+ print_bool(PRINT_JSON, "csum", NULL,
+ flags & TUNNEL_ENCAP_FLAG_CSUM);
+ print_bool(PRINT_JSON, "csum6", NULL,
+ flags & TUNNEL_ENCAP_FLAG_CSUM6);
+ print_bool(PRINT_JSON, "remcsum", NULL,
+ flags & TUNNEL_ENCAP_FLAG_REMCSUM);
+ close_json_object();
+ } else {
+ if (sport == 0)
+ fputs("encap-sport auto ", f);
+ else
+ fprintf(f, "encap-sport %u", ntohs(sport));
- fprintf(f, "encap-dport %u ", ntohs(dport));
+ fprintf(f, "encap-dport %u ", ntohs(dport));
- if (flags & TUNNEL_ENCAP_FLAG_CSUM)
- fputs("encap-csum ", f);
- else
- fputs("noencap-csum ", f);
+ if (flags & TUNNEL_ENCAP_FLAG_CSUM)
+ fputs("encap-csum ", f);
+ else
+ fputs("noencap-csum ", f);
- if (flags & TUNNEL_ENCAP_FLAG_CSUM6)
- fputs("encap-csum6 ", f);
- else
- fputs("noencap-csum6 ", f);
+ if (flags & TUNNEL_ENCAP_FLAG_CSUM6)
+ fputs("encap-csum6 ", f);
+ else
+ fputs("noencap-csum6 ", f);
- if (flags & TUNNEL_ENCAP_FLAG_REMCSUM)
- fputs("encap-remcsum ", f);
- else
- fputs("noencap-remcsum ", f);
+ if (flags & TUNNEL_ENCAP_FLAG_REMCSUM)
+ fputs("encap-remcsum ", f);
+ else
+ fputs("noencap-remcsum ", f);
+ }
}
}
static void ip6tunnel_print_help(struct link_util *lu, int argc, char **argv,
- FILE *f)
+ FILE *f)
{
print_usage(f);
}