@@ -450,6 +450,8 @@ 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[])
{
+ __u16 type;
+
if (!tb)
return;
@@ -469,8 +471,7 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
}
if (tb[IFLA_GRE_ENCAP_TYPE] &&
- rta_getattr_u16(tb[IFLA_GRE_ENCAP_TYPE]) != TUNNEL_ENCAP_NONE) {
- __u16 type = rta_getattr_u16(tb[IFLA_GRE_ENCAP_TYPE]);
+ (type = rta_getattr_u16(tb[IFLA_GRE_ENCAP_TYPE])) != TUNNEL_ENCAP_NONE) {
__u16 flags = rta_getattr_u16(tb[IFLA_GRE_ENCAP_FLAGS]);
__u16 sport = rta_getattr_u16(tb[IFLA_GRE_ENCAP_SPORT]);
__u16 dport = rta_getattr_u16(tb[IFLA_GRE_ENCAP_DPORT]);
@@ -381,6 +381,7 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
unsigned int iflags = 0;
unsigned int oflags = 0;
unsigned int flags = 0;
+ __u16 type;
__u32 flowinfo = 0;
struct in6_addr in6_addr_any = IN6ADDR_ANY_INIT;
__u8 ttl = 0;
@@ -518,15 +519,14 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
}
if (tb[IFLA_GRE_ENCAP_TYPE] &&
- rta_getattr_u16(tb[IFLA_GRE_ENCAP_TYPE]) != TUNNEL_ENCAP_NONE) {
- __u16 type = rta_getattr_u16(tb[IFLA_GRE_ENCAP_TYPE]);
+ (type = rta_getattr_u16(tb[IFLA_GRE_ENCAP_TYPE])) != TUNNEL_ENCAP_NONE) {
__u16 flags = rta_getattr_u16(tb[IFLA_GRE_ENCAP_FLAGS]);
__u16 sport = rta_getattr_u16(tb[IFLA_GRE_ENCAP_SPORT]);
__u16 dport = rta_getattr_u16(tb[IFLA_GRE_ENCAP_DPORT]);
open_json_object("encap");
-
print_string(PRINT_FP, NULL, "encap ", NULL);
+
switch (type) {
case TUNNEL_ENCAP_FOU:
print_string(PRINT_ANY, "type", "%s ", "fou");
@@ -535,7 +535,7 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
print_string(PRINT_ANY, "type", "%s ", "gue");
break;
default:
- print_null(PRINT_ANY, "type", "unknown ", NULL);
+ print_null(PRINT_ANY, "type", "%s ", "unknown");
break;
}
@@ -336,6 +336,7 @@ static void ip6tunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb
char s2[64];
unsigned int link;
int flags = 0;
+ __u16 type;
__u32 flowinfo = 0;
__u8 ttl = 0;
@@ -458,8 +459,7 @@ static void ip6tunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb
}
if (tb[IFLA_IPTUN_ENCAP_TYPE] &&
- rta_getattr_u16(tb[IFLA_IPTUN_ENCAP_TYPE]) != TUNNEL_ENCAP_NONE) {
- __u16 type = rta_getattr_u16(tb[IFLA_IPTUN_ENCAP_TYPE]);
+ (type = rta_getattr_u16(tb[IFLA_IPTUN_ENCAP_TYPE])) != TUNNEL_ENCAP_NONE) {
__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]);
@@ -474,7 +474,7 @@ static void ip6tunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb
print_string(PRINT_ANY, "type", "%s ", "gue");
break;
default:
- print_null(PRINT_ANY, "type", "unknown ", NULL);
+ print_null(PRINT_ANY, "type", "%s ", "unknown");
break;
}
@@ -505,7 +505,7 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[
print_string(PRINT_ANY, "type", "%s ", "gue");
break;
default:
- print_null(PRINT_ANY, "type", "unknown ", NULL);
+ print_null(PRINT_ANY, "type", "%s ", "unknown");
break;
}
Print "unknown" parameter for "encap" type in PRINT_FP context using "%s " format specifier and benefit from complite time string merge. Unify encapsulation type check. Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com> --- ip/link_gre.c | 5 +++-- ip/link_gre6.c | 8 ++++---- ip/link_ip6tnl.c | 6 +++--- ip/link_iptnl.c | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-)