From mboxrd@z Thu Jan 1 00:00:00 1970 From: Serhey Popovych Subject: [PATCH iproute2 v2 7/9] vti/tunnel: Unify ikey/okey printing Date: Thu, 18 Jan 2018 16:04:34 +0200 Message-ID: <1516284276-10942-8-git-send-email-serhe.popovych@gmail.com> References: <1516284276-10942-1-git-send-email-serhe.popovych@gmail.com> To: netdev@vger.kernel.org Return-path: Received: from mail-lf0-f67.google.com ([209.85.215.67]:44005 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756501AbeAROFq (ORCPT ); Thu, 18 Jan 2018 09:05:46 -0500 Received: by mail-lf0-f67.google.com with SMTP id o89so22684697lfg.10 for ; Thu, 18 Jan 2018 06:05:45 -0800 (PST) Received: from tuxracer.localdomain ([2a01:6d80::195:20:96:53]) by smtp.gmail.com with ESMTPSA id r21sm1344748lja.8.2018.01.18.06.05.43 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Jan 2018 06:05:43 -0800 (PST) In-Reply-To: <1516284276-10942-1-git-send-email-serhe.popovych@gmail.com> Sender: netdev-owner@vger.kernel.org List-ID: For vti6 tunnel we print [io]key in dotted-quad notation (ipv4 address) while in vti we do that in hex format. For vti tunnel we print [io]key only if value is not zero while for vti6 we miss such check. Unify vti and vti6 tunnel [io]key output. While here enlarge s2 buffer to the same size as in rest of tunnel support code (64 bytes) and check return from inet_ntop(). Signed-off-by: Serhey Popovych --- ip/link_vti.c | 22 ++++++++++++++-------- ip/link_vti6.c | 14 ++++++++++---- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/ip/link_vti.c b/ip/link_vti.c index baaaf2f..1439e53 100644 --- a/ip/link_vti.c +++ b/ip/link_vti.c @@ -167,8 +167,7 @@ static void vti_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) { const char *local = "any"; const char *remote = "any"; - __u32 key; - char s2[IFNAMSIZ]; + char s2[64]; if (!tb) return; @@ -200,14 +199,21 @@ static void vti_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) } } - if (tb[IFLA_VTI_IKEY] && - (key = rta_getattr_u32(tb[IFLA_VTI_IKEY]))) - print_0xhex(PRINT_ANY, "ikey", "ikey %#x ", ntohl(key)); + if (tb[IFLA_VTI_IKEY]) { + struct rtattr *rta = tb[IFLA_VTI_IKEY]; + __u32 key = rta_getattr_u32(rta); + if (key && inet_ntop(AF_INET, RTA_DATA(rta), s2, sizeof(s2))) + print_string(PRINT_ANY, "ikey", "ikey %s ", s2); + } + + if (tb[IFLA_VTI_OKEY]) { + struct rtattr *rta = tb[IFLA_VTI_OKEY]; + __u32 key = rta_getattr_u32(rta); - if (tb[IFLA_VTI_OKEY] && - (key = rta_getattr_u32(tb[IFLA_VTI_OKEY]))) - print_0xhex(PRINT_ANY, "okey", "okey %#x ", ntohl(key)); + if (key && inet_ntop(AF_INET, RTA_DATA(rta), s2, sizeof(s2))) + print_string(PRINT_ANY, "okey", "okey %s ", s2); + } if (tb[IFLA_VTI_FWMARK]) { __u32 fwmark = rta_getattr_u32(tb[IFLA_VTI_FWMARK]); diff --git a/ip/link_vti6.c b/ip/link_vti6.c index 952dbb0..6b61e3d 100644 --- a/ip/link_vti6.c +++ b/ip/link_vti6.c @@ -199,13 +199,19 @@ static void vti6_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) } if (tb[IFLA_VTI_IKEY]) { - inet_ntop(AF_INET, RTA_DATA(tb[IFLA_VTI_IKEY]), s2, sizeof(s2)); - print_string(PRINT_ANY, "ikey", "ikey %s ", s2); + struct rtattr *rta = tb[IFLA_VTI_IKEY]; + __u32 key = rta_getattr_u32(rta); + + if (key && inet_ntop(AF_INET, RTA_DATA(rta), s2, sizeof(s2))) + print_string(PRINT_ANY, "ikey", "ikey %s ", s2); } if (tb[IFLA_VTI_OKEY]) { - inet_ntop(AF_INET, RTA_DATA(tb[IFLA_VTI_OKEY]), s2, sizeof(s2)); - print_string(PRINT_ANY, "okey", "okey %s ", s2); + struct rtattr *rta = tb[IFLA_VTI_OKEY]; + __u32 key = rta_getattr_u32(rta); + + if (key && inet_ntop(AF_INET, RTA_DATA(rta), s2, sizeof(s2))) + print_string(PRINT_ANY, "okey", "okey %s ", s2); } if (tb[IFLA_VTI_FWMARK]) { -- 1.7.10.4