ip/tunnel: Simplify and unify tos printing
For ip tunnels tos can be 0 when not configured, 1 when inherited from encapsulated packet and rest specifying diffserv (rfc2474) or tos (rfc1349) bits. It is stored in packet tos/diffserv field and returned in tos netlink attribute to userspace. Simplify and unify tos printing by using print_0xhex() and print_string() instead of fprintf() to output values. Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
This commit is contained in:
parent
375560c4ab
commit
3caa526c7b
|
|
@ -228,7 +228,7 @@ static void geneve_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
|
||||||
{
|
{
|
||||||
__u32 vni;
|
__u32 vni;
|
||||||
__u8 ttl = 0;
|
__u8 ttl = 0;
|
||||||
__u8 tos;
|
__u8 tos = 0;
|
||||||
|
|
||||||
if (!tb)
|
if (!tb)
|
||||||
return;
|
return;
|
||||||
|
|
@ -270,20 +270,13 @@ static void geneve_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
|
||||||
else
|
else
|
||||||
print_string(PRINT_FP, NULL, "ttl %s ", "inherit");
|
print_string(PRINT_FP, NULL, "ttl %s ", "inherit");
|
||||||
|
|
||||||
if (tb[IFLA_GENEVE_TOS] &&
|
if (tb[IFLA_GENEVE_TOS])
|
||||||
(tos = rta_getattr_u8(tb[IFLA_GENEVE_TOS]))) {
|
tos = rta_getattr_u8(tb[IFLA_GENEVE_TOS]);
|
||||||
if (is_json_context()) {
|
if (tos) {
|
||||||
print_0xhex(PRINT_JSON, "tos", "%#x", tos);
|
if (is_json_context() || tos != 1)
|
||||||
} else {
|
print_0xhex(PRINT_ANY, "tos", "tos 0x%x ", tos);
|
||||||
if (tos == 1) {
|
else
|
||||||
print_string(PRINT_FP,
|
print_string(PRINT_FP, NULL, "tos %s ", "inherit");
|
||||||
"tos",
|
|
||||||
"tos %s ",
|
|
||||||
"inherit");
|
|
||||||
} else {
|
|
||||||
fprintf(f, "tos %#x ", tos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tb[IFLA_GENEVE_LABEL]) {
|
if (tb[IFLA_GENEVE_LABEL]) {
|
||||||
|
|
|
||||||
|
|
@ -395,7 +395,7 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
|
||||||
{
|
{
|
||||||
__u32 vni;
|
__u32 vni;
|
||||||
__u8 ttl = 0;
|
__u8 ttl = 0;
|
||||||
__u8 tos;
|
__u8 tos = 0;
|
||||||
__u32 maxaddr;
|
__u32 maxaddr;
|
||||||
|
|
||||||
if (!tb)
|
if (!tb)
|
||||||
|
|
@ -515,16 +515,13 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
|
||||||
if (tb[IFLA_VXLAN_L3MISS] && rta_getattr_u8(tb[IFLA_VXLAN_L3MISS]))
|
if (tb[IFLA_VXLAN_L3MISS] && rta_getattr_u8(tb[IFLA_VXLAN_L3MISS]))
|
||||||
print_bool(PRINT_ANY, "l3miss", "l3miss ", true);
|
print_bool(PRINT_ANY, "l3miss", "l3miss ", true);
|
||||||
|
|
||||||
if (tb[IFLA_VXLAN_TOS] &&
|
if (tb[IFLA_VXLAN_TOS])
|
||||||
(tos = rta_getattr_u8(tb[IFLA_VXLAN_TOS]))) {
|
tos = rta_getattr_u8(tb[IFLA_VXLAN_TOS]);
|
||||||
if (is_json_context()) {
|
if (tos) {
|
||||||
print_0xhex(PRINT_JSON, "tos", "%#x", tos);
|
if (is_json_context() || tos != 1)
|
||||||
} else {
|
print_0xhex(PRINT_ANY, "tos", "tos 0x%x ", tos);
|
||||||
if (tos == 1)
|
else
|
||||||
fprintf(f, "tos %s ", "inherit");
|
print_string(PRINT_FP, NULL, "tos %s ", "inherit");
|
||||||
else
|
|
||||||
fprintf(f, "tos %#x ", tos);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tb[IFLA_VXLAN_TTL])
|
if (tb[IFLA_VXLAN_TTL])
|
||||||
|
|
|
||||||
|
|
@ -362,6 +362,7 @@ static void gre_print_direct_opt(FILE *f, struct rtattr *tb[])
|
||||||
unsigned int iflags = 0;
|
unsigned int iflags = 0;
|
||||||
unsigned int oflags = 0;
|
unsigned int oflags = 0;
|
||||||
__u8 ttl = 0;
|
__u8 ttl = 0;
|
||||||
|
__u8 tos = 0;
|
||||||
|
|
||||||
if (tb[IFLA_GRE_REMOTE]) {
|
if (tb[IFLA_GRE_REMOTE]) {
|
||||||
unsigned int addr = rta_getattr_u32(tb[IFLA_GRE_REMOTE]);
|
unsigned int addr = rta_getattr_u32(tb[IFLA_GRE_REMOTE]);
|
||||||
|
|
@ -397,21 +398,13 @@ static void gre_print_direct_opt(FILE *f, struct rtattr *tb[])
|
||||||
else
|
else
|
||||||
print_string(PRINT_FP, NULL, "ttl %s ", "inherit");
|
print_string(PRINT_FP, NULL, "ttl %s ", "inherit");
|
||||||
|
|
||||||
if (tb[IFLA_GRE_TOS] && rta_getattr_u8(tb[IFLA_GRE_TOS])) {
|
if (tb[IFLA_GRE_TOS])
|
||||||
int tos = rta_getattr_u8(tb[IFLA_GRE_TOS]);
|
tos = rta_getattr_u8(tb[IFLA_GRE_TOS]);
|
||||||
|
if (tos) {
|
||||||
if (is_json_context()) {
|
if (is_json_context() || tos != 1)
|
||||||
SPRINT_BUF(b1);
|
print_0xhex(PRINT_ANY, "tos", "tos 0x%x ", tos);
|
||||||
|
else
|
||||||
snprintf(b1, sizeof(b1), "0x%x", tos);
|
print_string(PRINT_FP, NULL, "tos %s ", "inherit");
|
||||||
print_string(PRINT_JSON, "tos", NULL, b1);
|
|
||||||
} else {
|
|
||||||
fputs("tos ", f);
|
|
||||||
if (tos == 1)
|
|
||||||
fputs("inherit ", f);
|
|
||||||
else
|
|
||||||
fprintf(f, "0x%x ", tos);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tb[IFLA_GRE_PMTUDISC]) {
|
if (tb[IFLA_GRE_PMTUDISC]) {
|
||||||
|
|
|
||||||
|
|
@ -366,6 +366,7 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[
|
||||||
const char *remote = "any";
|
const char *remote = "any";
|
||||||
__u16 prefixlen, type;
|
__u16 prefixlen, type;
|
||||||
__u8 ttl = 0;
|
__u8 ttl = 0;
|
||||||
|
__u8 tos = 0;
|
||||||
|
|
||||||
if (!tb)
|
if (!tb)
|
||||||
return;
|
return;
|
||||||
|
|
@ -424,20 +425,13 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[
|
||||||
else
|
else
|
||||||
print_string(PRINT_FP, NULL, "ttl %s ", "inherit");
|
print_string(PRINT_FP, NULL, "ttl %s ", "inherit");
|
||||||
|
|
||||||
if (tb[IFLA_IPTUN_TOS]) {
|
if (tb[IFLA_IPTUN_TOS])
|
||||||
int tos = rta_getattr_u8(tb[IFLA_IPTUN_TOS]);
|
tos = rta_getattr_u8(tb[IFLA_IPTUN_TOS]);
|
||||||
|
if (tos) {
|
||||||
if (tos) {
|
if (is_json_context() || tos != 1)
|
||||||
if (is_json_context()) {
|
print_0xhex(PRINT_ANY, "tos", "tos 0x%x ", tos);
|
||||||
print_0xhex(PRINT_JSON, "tos", "%#x", tos);
|
else
|
||||||
} else {
|
print_string(PRINT_FP, NULL, "tos %s ", "inherit");
|
||||||
fputs("tos ", f);
|
|
||||||
if (tos == 1)
|
|
||||||
fputs("inherit ", f);
|
|
||||||
else
|
|
||||||
fprintf(f, "0x%x ", tos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tb[IFLA_IPTUN_PMTUDISC] && rta_getattr_u8(tb[IFLA_IPTUN_PMTUDISC]))
|
if (tb[IFLA_IPTUN_PMTUDISC] && rta_getattr_u8(tb[IFLA_IPTUN_PMTUDISC]))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue