Bug 197270 - [Patch] Improve output of ifconfig command
Summary: [Patch] Improve output of ifconfig command
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-02-02 11:12 UTC by Vsevolod Stakhov
Modified: 2022-04-27 15:42 UTC (History)
5 users (show)

See Also:


Attachments
patch (5.57 KB, patch)
2015-02-02 11:12 UTC, Vsevolod Stakhov
no flags Details | Diff
patch (5.49 KB, patch)
2015-02-02 11:27 UTC, Vsevolod Stakhov
no flags Details | Diff
patch (5.54 KB, patch)
2015-02-02 11:36 UTC, Vsevolod Stakhov
no flags Details | Diff
reverte parts of patch (1.48 KB, patch)
2015-02-02 17:12 UTC, Vsevolod Stakhov
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Vsevolod Stakhov freebsd_committer freebsd_triage 2015-02-02 11:12:37 UTC
Created attachment 152475 [details]
patch

The following patch reorganizes the list of addresses associated with an interface and group them based on the address family. This should help to recognize interfaces with multiple AF (e.g. ipv4 and ipv6) with many aliases or additional addresses. The order of addresses inside a single group is strictly preserved.

Moreover, this patch improves scope_id output for AF_INET6 families, as the current approach uses hexadecimal string that is basically the ID of an interface, whilst this information is already depicted by getnameinfo(3) call. Therefore, now ifconfig just prints the scope of address as it is defined in 2.4 of RFC 2373.

Example of output:

Original ifconfig:

# ifconfig vlan1
vlan1: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> metric 0 mtu 1500
        options=3<RXCSUM,TXCSUM>
        ether 00:1a:64:c6:a8:7c
        inet 192.168.3.22 netmask 0xffffff00 broadcast 192.168.3.255 
        inet6 fe80::21a:64ff:fec6:a87c%vlan1 prefixlen 64 scopeid 0x6 
        inet6 fd00::316 prefixlen 120 
        inet 192.168.3.13 netmask 0xffffff00 broadcast 192.168.3.255 vhid 5 
        inet 192.168.3.1 netmask 0xffffff00 broadcast 192.168.3.255 vhid 5 
        inet6 fd00::301 prefixlen 120 vhid 5 
        nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>
        media: Ethernet autoselect (1000baseT <full-duplex>)
        status: active
        vlan: 1 parent interface: bce0
        carp: MASTER vhid 5 advbase 1 advskew 50

Modified output:
# ./ifconfig vlan1
vlan1: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> metric 0 mtu 1500
        options=3<RXCSUM,TXCSUM>
        inet6 fe80::21a:64ff:fec6:a87c%vlan1 prefixlen 64 scope: Link 
        inet6 fd00::316 prefixlen 120 scope: Global 
        inet6 fd00::301 prefixlen 120 scope: Global vhid 5 
        inet 192.168.3.22 netmask 0xffffff00 broadcast 192.168.3.255 
        inet 192.168.3.13 netmask 0xffffff00 broadcast 192.168.3.255 vhid 5 
        inet 192.168.3.1 netmask 0xffffff00 broadcast 192.168.3.255 vhid 5 
        ether 00:1a:64:c6:a8:7c
        nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>
        media: Ethernet autoselect (1000baseT <full-duplex>)
        status: active
        vlan: 1 parent interface: bce0
        carp: MASTER vhid 5 advbase 1 advskew 50
Comment 1 Vsevolod Stakhov freebsd_committer freebsd_triage 2015-02-02 11:27:36 UTC
Created attachment 152478 [details]
patch
Comment 2 Vsevolod Stakhov freebsd_committer freebsd_triage 2015-02-02 11:36:36 UTC
Created attachment 152479 [details]
patch
Comment 3 Baptiste Daroussin freebsd_committer freebsd_triage 2015-02-02 12:53:10 UTC
That looks good to me. Please commit
Comment 4 commit-hook freebsd_committer freebsd_triage 2015-02-02 13:03:48 UTC
A commit references this bug:

Author: vsevolod
Date: Mon Feb  2 13:03:05 UTC 2015
New revision: 278080
URL: https://svnweb.freebsd.org/changeset/base/278080

Log:
  Reorganize the list of addresses associated with an interface and group them
  based on the address family. This should help to recognize interfaces with
  multiple AF (e.g. ipv4 and ipv6) with many aliases or additional addresses. The
  order of addresses inside a single group is strictly preserved.

  Improve the scope_id output for AF_INET6 families, as the
  current approach uses hexadecimal string that is basically the ID of an
  interface, whilst this information is already depicted by getnameinfo(3) call.
  Therefore, now ifconfig just prints the scope of address as it is defined in
  2.4 of RFC 2373.

  PR:		197270
  Approved by:	bapt
  MFC after:	2 weeks

Changes:
  head/sbin/ifconfig/af_inet6.c
  head/sbin/ifconfig/ifconfig.c
Comment 5 Bjoern A. Zeeb freebsd_committer freebsd_triage 2015-02-02 16:42:44 UTC
It's rather unfortunate that this did not g through a proper review process and was handled within a few minutes of reporting by yourself.

The scope change doesn't look particularly great to me at all.  Also the reference in the commit message (RFC 2373) is not good as that RFC has been obsoleted at least twice and updated a couple of times.

Also changing the output format of ifconfig unfortunately break a lot of scripts of people usually so should have been handled carefully.  I strongly object to an MFC of the scope part at least.


I am also worried that not having the "inet" first anymore will break scripts (the much I prefer IPv6 being a default).  Another reason to be very careful with MFCing this.
Comment 6 Vsevolod Stakhov freebsd_committer freebsd_triage 2015-02-02 16:55:14 UTC
I have added ae@, who suggested me that change.
Comment 7 Vsevolod Stakhov freebsd_committer freebsd_triage 2015-02-02 16:57:17 UTC
Regarding order, I believe that the change to revert it is completely trivial - just change the order of AF in `cmpifaddrs' function.
Comment 8 Hiroki Sato freebsd_committer freebsd_triage 2015-02-02 16:58:32 UTC
(In reply to commit-hook from comment #4)

>  Reorganize the list of addresses associated with an interface and group them
>  based on the address family. This should help to recognize interfaces with
>  multiple AF (e.g. ipv4 and ipv6) with many aliases or additional addresses. The
>  order of addresses inside a single group is strictly preserved.
>
> Improve the scope_id output for AF_INET6 families, as the
>  current approach uses hexadecimal string that is basically the ID of an
>  interface, whilst this information is already depicted by getnameinfo(3) call.
>  Therefore, now ifconfig just prints the scope of address as it is defined in
>  2.4 of RFC 2373.

 Please revert the second half of this change.  Checking the address
 structure in userland in the manner of in6_print_scope() is redundant
 because almost the same check is already performed in the kernel when
 getifaddrs(3) is called.  If scope_id > 0, or IN6_IS_ADDR_LOOPBACK()
 is true, it is link-local.  Site-local is deprecated in RFC 3879 and
 new implementation MUST NOT support it.  Plus, using hard-coded
 values of address prefixes is inappropriate.  This kind of scope
 check should be performed by only
 IN6_IS_ADDR_{LINKLOCAL,SITELOCAL,...} macros if you want a strict
 one.  And I am not sure why "Multicast" is added here.  The multicast
 group membership list is returned by getifmaddrs(3), not
 getifaddrs(3).

 Also, RFC 4007 specifies that at least non-negative decimal integer
 SHOULD be supported as scope zone id.  We support it.  However, if
 removing the scopeid part, it becomes difficult to know the zone id.
 This is the reason why scopeid is displayed along with %zone_id.
 A symbolic "%zone_id" itself means "it is non-global".
 Is "scope: link" still needed?

 Putting the above aside, I do not think it is a good idea to change
 the command line output because it breaks consistency
 (e.g. ifmcstat(8) also uses scopeid notation) and compatibility of
 scripts which depend on it, for example.  scopeid has lived for 10+
 years.  While adding "scope: link" or something may be acceptable,
 replacing scopeid with it does not look a good improvement, at least
 to me.
Comment 9 Vsevolod Stakhov freebsd_committer freebsd_triage 2015-02-02 17:12:07 UTC
Created attachment 152488 [details]
reverte parts of patch

This patch reverts the scopeid change and set the order of AF in the way it is returned by getifaddrs (previously, this order was reverted).
Comment 10 Baptiste Daroussin freebsd_committer freebsd_triage 2015-02-02 17:29:03 UTC
Hiroki: is the partial revert patch ok for you?
Comment 11 Bjoern A. Zeeb freebsd_committer freebsd_triage 2015-02-02 17:37:43 UTC
Is it possible to use a qsort(3) function to sort the remaining parts?
This discussion should really be in reviews and not here but hey ;-)
Comment 12 Hiroki Sato freebsd_committer freebsd_triage 2015-02-02 17:40:27 UTC
(In reply to Baptiste Daroussin from comment #10)
Yes, good to me.
Comment 13 Vsevolod Stakhov freebsd_committer freebsd_triage 2015-02-02 17:40:56 UTC
Bjoern, using of qsort is impossible for two main reasons:

1) it cannot sort linked lists
2) it is not stable

This sorting is a mergesort actually, so it is stable which is important while showing aliases in the correct order.
Comment 14 Vsevolod Stakhov freebsd_committer freebsd_triage 2015-02-02 17:43:14 UTC
However, if you've meant sorting of interfaces, then yes, I planned to add support of custom sorting orders for the convenient display of different interfaces.
Comment 15 Andrey V. Elsukov freebsd_committer freebsd_triage 2015-02-02 18:19:15 UTC
(In reply to Hiroki Sato from comment #8)

>  Also, RFC 4007 specifies that at least non-negative decimal integer
>  SHOULD be supported as scope zone id.  We support it.  However, if
>  removing the scopeid part, it becomes difficult to know the zone id.

Zone id is printed in the same line before "prefixlen" keyword. You can just copy an address with %zone_id and use it where you want. And I'm sure you are doing so.

>  This is the reason why scopeid is displayed along with %zone_id.
>  A symbolic "%zone_id" itself means "it is non-global".
>  Is "scope: link" still needed?

So, why this zone index is formatted in hex? 
We don't support hexadecimal values. It looks like many people use them every day... :)
 
>  Putting the above aside, I do not think it is a good idea to change
>  the command line output because it breaks consistency
>  (e.g. ifmcstat(8) also uses scopeid notation) and compatibility of

ifmcstat(8) also has this redundant information.

>  scripts which depend on it, for example.  scopeid has lived for 10+
>  years.  While adding "scope: link" or something may be acceptable,
>  replacing scopeid with it does not look a good improvement, at least
>  to me.
Comment 16 Glen Barber freebsd_committer freebsd_triage 2015-07-08 18:32:07 UTC
To originators/assignees of this PR:

A commit to the tree references this PR, however the PR is still in a non-closed state.

Please review this PR and close as appropriate, or if closing the PR requires a merge to stable/10, please let re@ know as soon as possible.

Thank you.

Glen