From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Ahern Subject: Re: [PATCH iproute2-next v2 5/6] utils: Introduce and use print_name_and_link() to print name@link Date: Wed, 31 Jan 2018 20:50:08 -0700 Message-ID: <2dbfa441-ab91-01b6-d6c8-0ed484cc1d79@gmail.com> References: <1517335761-22095-1-git-send-email-serhe.popovych@gmail.com> <1517335761-22095-6-git-send-email-serhe.popovych@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit To: Serhey Popovych , netdev@vger.kernel.org Return-path: Received: from mail-pl0-f67.google.com ([209.85.160.67]:39469 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750866AbeBADtu (ORCPT ); Wed, 31 Jan 2018 22:49:50 -0500 Received: by mail-pl0-f67.google.com with SMTP id o13so2490058pli.6 for ; Wed, 31 Jan 2018 19:49:50 -0800 (PST) In-Reply-To: <1517335761-22095-6-git-send-email-serhe.popovych@gmail.com> Content-Language: en-US Sender: netdev-owner@vger.kernel.org List-ID: On 1/30/18 11:09 AM, Serhey Popovych wrote: > There is at least three places implementing same things: two in > ipaddress.c print_linkinfo() & print_linkinfo_brief() and one in > bridge/link.c. > > These two implementations diverge from each other very little: > bridge/link.c does not support JSON output at the moment and > print_linkinfo_brief() does not handle IFLA_LINK_NETNS case. > > Introduce and use print_name_and_link() routine to handle name@link > output in all possible variations; respect IFLA_LINK_NETNS attribute to > handle case when link is in different namespace; use "if%d" template > for interface name instead of "" to share logic with other > code (e.g. ll_name_to_index() and ll_index_to_name()) supporting such > template. > > Signed-off-by: Serhey Popovych > --- > bridge/link.c | 13 +++---------- > include/utils.h | 4 ++++ > ip/ipaddress.c | 48 ++---------------------------------------------- > lib/utils.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ > 4 files changed, 60 insertions(+), 56 deletions(-) > > diff --git a/bridge/link.c b/bridge/link.c > index a11cbb1..90c9734 100644 > --- a/bridge/link.c > +++ b/bridge/link.c > @@ -125,20 +125,13 @@ int print_linkinfo(const struct sockaddr_nl *who, > if (n->nlmsg_type == RTM_DELLINK) > fprintf(fp, "Deleted "); > > - fprintf(fp, "%d: %s ", ifi->ifi_index, > - tb[IFLA_IFNAME] ? rta_getattr_str(tb[IFLA_IFNAME]) : ""); > + fprintf(fp, "%d: ", ifi->ifi_index); > + > + print_name_and_link("%s: ", COLOR_NONE, name, tb); It only needs tb[IFLA_LINK] so just pass it. Makes the arg list consistent with the function name too.