diff --git a/ip/iplink_geneve.c b/ip/iplink_geneve.c index 1c28bb9c..c6660726 100644 --- a/ip/iplink_geneve.c +++ b/ip/iplink_geneve.c @@ -230,6 +230,11 @@ static void geneve_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) if (!tb) return; + if (tb[IFLA_GENEVE_COLLECT_METADATA]) { + print_bool(PRINT_ANY, "external", "external", true); + return; + } + if (!tb[IFLA_GENEVE_ID] || RTA_PAYLOAD(tb[IFLA_GENEVE_ID]) < sizeof(__u32)) return; @@ -292,9 +297,6 @@ static void geneve_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) "dstport %u ", rta_getattr_be16(tb[IFLA_GENEVE_PORT])); - if (tb[IFLA_GENEVE_COLLECT_METADATA]) - print_bool(PRINT_ANY, "collect_metadata", "external ", true); - if (tb[IFLA_GENEVE_UDP_CSUM]) { if (is_json_context()) { print_bool(PRINT_JSON, diff --git a/ip/iplink_vxlan.c b/ip/iplink_vxlan.c index ad03ffb6..00875ba7 100644 --- a/ip/iplink_vxlan.c +++ b/ip/iplink_vxlan.c @@ -381,6 +381,12 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) if (!tb) return; + if (tb[IFLA_VXLAN_COLLECT_METADATA] && + rta_getattr_u8(tb[IFLA_VXLAN_COLLECT_METADATA])) { + print_bool(PRINT_ANY, "external", "external", true); + return; + } + if (!tb[IFLA_VXLAN_ID] || RTA_PAYLOAD(tb[IFLA_VXLAN_ID]) < sizeof(__u32)) return; @@ -582,10 +588,6 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) rta_getattr_u8(tb[IFLA_VXLAN_REMCSUM_RX])) print_bool(PRINT_ANY, "remcsum_rx", "remcsumrx ", true); - if (tb[IFLA_VXLAN_COLLECT_METADATA] && - rta_getattr_u8(tb[IFLA_VXLAN_COLLECT_METADATA])) - print_bool(PRINT_ANY, "collect_metadata", "external ", true); - if (tb[IFLA_VXLAN_GBP]) print_bool(PRINT_ANY, "gbp", "gbp ", true); if (tb[IFLA_VXLAN_GPE]) diff --git a/ip/link_gre.c b/ip/link_gre.c index 850eddb7..d91a435b 100644 --- a/ip/link_gre.c +++ b/ip/link_gre.c @@ -362,6 +362,8 @@ get_failed: addattr_l(n, 1024, IFLA_GRE_LOCAL, &saddr, 4); addattr_l(n, 1024, IFLA_GRE_REMOTE, &daddr, 4); addattr_l(n, 1024, IFLA_GRE_PMTUDISC, &pmtudisc, 1); + if (ignore_df) + addattr8(n, 1024, IFLA_GRE_IGNORE_DF, ignore_df & 1); if (link) addattr32(n, 1024, IFLA_GRE_LINK, link); addattr_l(n, 1024, IFLA_GRE_TTL, &ttl, 1); @@ -370,28 +372,27 @@ get_failed: if (erspan_ver) { addattr8(n, 1024, IFLA_GRE_ERSPAN_VER, erspan_ver); if (erspan_ver == 1 && erspan_idx != 0) { - addattr32(n, 1024, IFLA_GRE_ERSPAN_INDEX, erspan_idx); + addattr32(n, 1024, + IFLA_GRE_ERSPAN_INDEX, erspan_idx); } else if (erspan_ver == 2) { - addattr8(n, 1024, IFLA_GRE_ERSPAN_DIR, erspan_dir); - addattr16(n, 1024, IFLA_GRE_ERSPAN_HWID, erspan_hwid); + addattr8(n, 1024, + IFLA_GRE_ERSPAN_DIR, erspan_dir); + addattr16(n, 1024, + IFLA_GRE_ERSPAN_HWID, erspan_hwid); } } + addattr16(n, 1024, IFLA_GRE_ENCAP_TYPE, encaptype); + addattr16(n, 1024, IFLA_GRE_ENCAP_FLAGS, encapflags); + addattr16(n, 1024, IFLA_GRE_ENCAP_SPORT, htons(encapsport)); + addattr16(n, 1024, IFLA_GRE_ENCAP_DPORT, htons(encapdport)); } else { addattr_l(n, 1024, IFLA_GRE_COLLECT_METADATA, NULL, 0); } - addattr16(n, 1024, IFLA_GRE_ENCAP_TYPE, encaptype); - addattr16(n, 1024, IFLA_GRE_ENCAP_FLAGS, encapflags); - addattr16(n, 1024, IFLA_GRE_ENCAP_SPORT, htons(encapsport)); - addattr16(n, 1024, IFLA_GRE_ENCAP_DPORT, htons(encapdport)); - - if (ignore_df) - addattr8(n, 1024, IFLA_GRE_IGNORE_DF, ignore_df & 1); - return 0; } -static void gre_print_direct_opt(FILE *f, struct rtattr *tb[]) +static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) { char s2[64]; const char *local = "any"; @@ -401,6 +402,14 @@ static void gre_print_direct_opt(FILE *f, struct rtattr *tb[]) __u8 ttl = 0; __u8 tos = 0; + if (!tb) + return; + + if (tb[IFLA_GRE_COLLECT_METADATA]) { + print_bool(PRINT_ANY, "external", "external", true); + return; + } + if (tb[IFLA_GRE_REMOTE]) { unsigned int addr = rta_getattr_u32(tb[IFLA_GRE_REMOTE]); @@ -451,6 +460,9 @@ static void gre_print_direct_opt(FILE *f, struct rtattr *tb[]) print_bool(PRINT_JSON, "pmtudisc", NULL, true); } + if (tb[IFLA_GRE_IGNORE_DF] && rta_getattr_u8(tb[IFLA_GRE_IGNORE_DF])) + print_bool(PRINT_ANY, "ignore_df", "ignore-df ", true); + if (tb[IFLA_GRE_IFLAGS]) iflags = rta_getattr_u16(tb[IFLA_GRE_IFLAGS]); @@ -484,20 +496,6 @@ static void gre_print_direct_opt(FILE *f, struct rtattr *tb[]) "fwmark", "fwmark 0x%x ", fwmark); } } -} - -static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) -{ - if (!tb) - return; - - if (!tb[IFLA_GRE_COLLECT_METADATA]) - gre_print_direct_opt(f, tb); - else - print_bool(PRINT_ANY, "external", "external ", true); - - if (tb[IFLA_GRE_IGNORE_DF] && rta_getattr_u8(tb[IFLA_GRE_IGNORE_DF])) - print_bool(PRINT_ANY, "ignore_df", "ignore-df ", true); if (tb[IFLA_GRE_ERSPAN_INDEX]) { __u32 erspan_idx = rta_getattr_u32(tb[IFLA_GRE_ERSPAN_INDEX]); diff --git a/ip/link_gre6.c b/ip/link_gre6.c index bb196494..b3f070ba 100644 --- a/ip/link_gre6.c +++ b/ip/link_gre6.c @@ -406,10 +406,13 @@ get_failed: if (erspan_ver) { addattr8(n, 1024, IFLA_GRE_ERSPAN_VER, erspan_ver); if (erspan_ver == 1 && erspan_idx != 0) { - addattr32(n, 1024, IFLA_GRE_ERSPAN_INDEX, erspan_idx); - } else { - addattr8(n, 1024, IFLA_GRE_ERSPAN_DIR, erspan_dir); - addattr16(n, 1024, IFLA_GRE_ERSPAN_HWID, erspan_hwid); + addattr32(n, 1024, + IFLA_GRE_ERSPAN_INDEX, erspan_idx); + } else if (erspan_ver == 2) { + addattr8(n, 1024, + IFLA_GRE_ERSPAN_DIR, erspan_dir); + addattr16(n, 1024, + IFLA_GRE_ERSPAN_HWID, erspan_hwid); } } addattr16(n, 1024, IFLA_GRE_ENCAP_TYPE, encaptype); @@ -439,7 +442,7 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) return; if (tb[IFLA_GRE_COLLECT_METADATA]) { - print_bool(PRINT_ANY, "collect_metadata", "external", true); + print_bool(PRINT_ANY, "external", "external", true); return; } @@ -604,7 +607,7 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) } static void gre_print_help(struct link_util *lu, int argc, char **argv, - FILE *f) + FILE *f) { print_usage(f); } diff --git a/ip/link_ip6tnl.c b/ip/link_ip6tnl.c index fdf113e0..ce3bcdec 100644 --- a/ip/link_ip6tnl.c +++ b/ip/link_ip6tnl.c @@ -341,8 +341,10 @@ static void ip6tunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb if (!tb) return; - if (tb[IFLA_IPTUN_COLLECT_METADATA]) - print_bool(PRINT_ANY, "external", "external ", true); + if (tb[IFLA_IPTUN_COLLECT_METADATA]) { + print_bool(PRINT_ANY, "external", "external", true); + return; + } if (tb[IFLA_IPTUN_FLAGS]) flags = rta_getattr_u32(tb[IFLA_IPTUN_FLAGS]); diff --git a/ip/link_iptnl.c b/ip/link_iptnl.c index 96048e2e..d7957637 100644 --- a/ip/link_iptnl.c +++ b/ip/link_iptnl.c @@ -371,8 +371,10 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[ if (!tb) return; - if (tb[IFLA_IPTUN_COLLECT_METADATA]) - print_bool(PRINT_ANY, "external", "external ", true); + if (tb[IFLA_IPTUN_COLLECT_METADATA]) { + print_bool(PRINT_ANY, "external", "external", true); + return; + } if (tb[IFLA_IPTUN_PROTO]) { switch (rta_getattr_u8(tb[IFLA_IPTUN_PROTO])) {