Previously, only the interface index was printed. It is helpful to display the interface name, instead of letting the reader doing the translation from the index to the name. Because the index was already displayed before, keep it instead of replacing it, just not to break some possible scripts parsing this output. Signed-off-by: Matthieu Baerts (NGI0) --- ip/ipmptcp.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ip/ipmptcp.c b/ip/ipmptcp.c index acd008f3..5f194aca 100644 --- a/ip/ipmptcp.c +++ b/ip/ipmptcp.c @@ -471,6 +471,17 @@ static void print_addr(const char *key, int af, struct rtattr *value) printf(" %s=%s", key, str); } +static void print_iface(int index) +{ + const char *ifname; + + printf(" ifindex=%d", index); + + ifname = index ? ll_index_to_name(index) : NULL; + if (ifname) + printf(" dev=%s", ifname); +} + static int mptcp_monitor_msg(struct rtnl_ctrl_data *ctrl, struct nlmsghdr *n, void *arg) { @@ -530,7 +541,7 @@ static int mptcp_monitor_msg(struct rtnl_ctrl_data *ctrl, if (tb[MPTCP_ATTR_TIMEOUT]) printf(" timeout=%u", rta_getattr_u32(tb[MPTCP_ATTR_TIMEOUT])); if (tb[MPTCP_ATTR_IF_IDX]) - printf(" ifindex=%d", rta_getattr_s32(tb[MPTCP_ATTR_IF_IDX])); + print_iface(rta_getattr_s32(tb[MPTCP_ATTR_IF_IDX])); if (tb[MPTCP_ATTR_RESET_REASON]) printf(" reset_reason=%u", rta_getattr_u32(tb[MPTCP_ATTR_RESET_REASON])); if (tb[MPTCP_ATTR_RESET_FLAGS]) -- 2.51.0 Similar to other commands, now the addresses and interface names in "ip mptcp" commands are now displayed in color if supported/requested. That's the only attributes that are used in ipmptcp.c: no MAC or state (UP/DOWN) attributes. Signed-off-by: Matthieu Baerts (NGI0) --- ip/ipmptcp.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/ip/ipmptcp.c b/ip/ipmptcp.c index 5f194aca..ec9ef62a 100644 --- a/ip/ipmptcp.c +++ b/ip/ipmptcp.c @@ -243,8 +243,11 @@ static int print_mptcp_addrinfo(struct rtattr *addrinfo) addr_attr_type = family == AF_INET ? MPTCP_PM_ADDR_ATTR_ADDR4 : MPTCP_PM_ADDR_ATTR_ADDR6; if (tb[addr_attr_type]) { - print_string(PRINT_ANY, "address", "%s ", - format_host_rta(family, tb[addr_attr_type])); + print_color_string(PRINT_ANY, + ifa_family_color(family), + "address", + "%s ", + format_host_rta(family, tb[addr_attr_type])); } if (tb[MPTCP_PM_ADDR_ATTR_PORT]) { port = rta_getattr_u16(tb[MPTCP_PM_ADDR_ATTR_PORT]); @@ -263,8 +266,11 @@ static int print_mptcp_addrinfo(struct rtattr *addrinfo) index = rta_getattr_s32(tb[MPTCP_PM_ADDR_ATTR_IF_IDX]); ifname = index ? ll_index_to_name(index) : NULL; - if (ifname) - print_string(PRINT_ANY, "dev", "dev %s ", ifname); + if (ifname) { + print_string(PRINT_FP, NULL, "dev ", NULL); + print_color_string(PRINT_ANY, COLOR_IFNAME, "dev", + "%s ", ifname); + } } close_json_object(); @@ -467,8 +473,10 @@ static void print_addr(const char *key, int af, struct rtattr *value) void *data = RTA_DATA(value); char str[INET6_ADDRSTRLEN]; - if (inet_ntop(af, data, str, sizeof(str))) - printf(" %s=%s", key, str); + if (inet_ntop(af, data, str, sizeof(str))) { + printf(" %s=", key); + color_fprintf(stdout, ifa_family_color(af), "%s", str); + } } static void print_iface(int index) @@ -478,8 +486,10 @@ static void print_iface(int index) printf(" ifindex=%d", index); ifname = index ? ll_index_to_name(index) : NULL; - if (ifname) - printf(" dev=%s", ifname); + if (ifname) { + printf(" dev="); + color_fprintf(stdout, COLOR_IFNAME, "%s", ifname); + } } static int mptcp_monitor_msg(struct rtnl_ctrl_data *ctrl, -- 2.51.0