From: Serhey Popovych <serhe.popovych@gmail.com>
To: David Ahern <dsahern@gmail.com>, netdev@vger.kernel.org
Subject: Re: [PATCH iproute2-next v2 5/6] utils: Introduce and use print_name_and_link() to print name@link
Date: Thu, 1 Feb 2018 13:09:54 +0200 [thread overview]
Message-ID: <605c7f63-a97e-aad0-c492-7b0ddf8b19fc@gmail.com> (raw)
In-Reply-To: <2dbfa441-ab91-01b6-d6c8-0ed484cc1d79@gmail.com>
[-- Attachment #1.1: Type: text/plain, Size: 2442 bytes --]
David Ahern wrote:
> 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 "<nil>" 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 <serhe.popovych@gmail.com>
>> ---
>> 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]) : "<nil>");
>> + 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.
>
Unfortunately not only: it uses IFLA_LINK_NETNSID too. May be adding
"_rta" suffix to this routine as we did in the past when introducing
get_addr_rta() and similar routines? In my opinion this is preferred
than adding one more parameters to the routine.
On the other hand tb[IFLA_LINK] taken by rta_getaddr_u32() (but actually
it is "int" with values strictly greater than zero as implemented in
kernel), so making function to catch missing tb[IFLA_LINK] would require
some helper and may broke "should never happen" case when
(int)rta_getattr_u32(tb[IFLA_LINK]) < 0.
Currently we may call ll_index_to_name() with negative iflink.
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 490 bytes --]
next prev parent reply other threads:[~2018-02-01 11:10 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-30 18:09 [PATCH iproute2-next v2 0/6] ipaddress: Get rid of print_linkinfo_brief() Serhey Popovych
2018-01-30 18:09 ` [PATCH iproute2-next v2 1/6] ipaddress: Improve print_linkinfo() Serhey Popovych
2018-02-01 3:29 ` David Ahern
2018-02-01 10:59 ` Serhey Popovych
2018-01-30 18:09 ` [PATCH iproute2-next v2 2/6] ipaddress: Simplify print_linkinfo_brief() and it's usage Serhey Popovych
2018-02-01 3:43 ` David Ahern
2018-02-01 11:00 ` Serhey Popovych
2018-01-30 18:09 ` [PATCH iproute2-next v2 3/6] lib: Correct object file dependencies Serhey Popovych
2018-01-30 18:09 ` [PATCH iproute2-next v2 4/6] utils: Introduce and use get_ifname_rta() Serhey Popovych
2018-02-01 3:45 ` David Ahern
2018-01-30 18:09 ` [PATCH iproute2-next v2 5/6] utils: Introduce and use print_name_and_link() to print name@link Serhey Popovych
2018-02-01 3:50 ` David Ahern
2018-02-01 11:09 ` Serhey Popovych [this message]
2018-02-01 15:40 ` David Ahern
2018-01-30 18:09 ` [PATCH iproute2-next v2 6/6] ipaddress: Make print_linkinfo_brief() static Serhey Popovych
2018-02-01 3:53 ` [PATCH iproute2-next v2 0/6] ipaddress: Get rid of print_linkinfo_brief() David Ahern
2018-02-01 11:12 ` Serhey Popovych
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=605c7f63-a97e-aad0-c492-7b0ddf8b19fc@gmail.com \
--to=serhe.popovych@gmail.com \
--cc=dsahern@gmail.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).