iproute2/ip
Serhey Popovych 8df708afd6 ipaddress: Fix and make consistent label match handling
Since commit 9516823051 ("ipaddress: Improve print_linkinfo()") we
return -1 instead of 0 when ip-address(8) label does not match network
device name as we did before change. This causes regression when trying
to output ip address matching label:

     # ip addr add 192.168.192.1/24 dev lo label lo:1
     # ip addr show label lo:1
     <no output>

This is special case and return 0 from print_linkinfo() earlier to match
only filter.ifindex and filter.up if given, but not rest fields in
@filter. Then call print_selected_addrinfo() without calling
print_link_stats() in ipaddr_list_flush_or_save().

Later print_selected_addrinfo() calls print_addrinfo() that finally
matches IFA_LABEL attribute in netlink buffer with filter.label using
ifa_label_match_rta().

On the other hand there is three conditions checked in print_linkinfo()
to determine label special case:

    1) filter.label != NULL
    2) filter.family == AF_UNSPEC || filter.family == AF_PACKET
    3) fnmatch(filter.label, name, 0)

With 1) it is ok to check if filtering by label is on by given pattern
in @filter.label.

Since label is IPv4 specific and AF_PACKET is for printing ip-link(8)
information (see ipaddr_link_list()::ipaddress.c as example) checking
for AF_PACKET in 2) doesn't take much sense: better to defer these
checks to print_addrinfo() determine valid combinations before calling
ifa_label_match_rta() to finally match IFA_LABEL to pattern in
filter.label.

For 3) we have following call for test case:

    fnmatch(pattern, string, flags) ->
      fnmatch(filter.label, name, 0) ->
        fnmatch("lo:1", "lo", 0) == FNM_NOMATCH (1) or non-zero on error

To support special case in print_linkinfo() for filtering by label we
only need to check if label pattern is given in filter.label and return
0 to skip print_link_stats() in ipaddr_list_flush_or_save(): actual
filtering will be done in print_addrinfo().

Before commit 9516823051 ("ipaddress: Improve print_linkinfo()"):
-------------------------------------------------------------------

$ ip addr sh label lo
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN \
group default qlen 1000
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                                          fnmatch("lo", "lo", 0) == 0
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
$ ip addr show label 'lo:*'
    inet 192.168.192.1/24 scope global lo:1
       valid_lft forever preferred_lft forever
$ ip addr sh label lo:1
    inet 192.168.192.1/24 scope global lo:1
       valid_lft forever preferred_lft forever
$ ip -4 addr sh label lo:1
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN \
group default qlen 1000
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                                             filter.family == AF_INET
    inet 192.168.192.1/24 scope global lo:1
       valid_lft forever preferred_lft forever

After this change applied:
--------------------------

$ ip/ip addr show label lo
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
$ ip/ip addr show label 'lo:*'
    inet 192.168.192.1/24 scope global lo:1
        valid_lft forever preferred_lft forever
$ ip/ip addr show label lo:1
    inet 192.168.192.1/24 scope global lo:1
       valid_lft forever preferred_lft forever
$ ip/ip -4 addr show label lo:1
    inet 192.168.192.1/24 scope global lo:1
       valid_lft forever preferred_lft forever

Note that we no longer show link information as we did previously:
    we are filtering by "label" pattern, not showing by "dev".

Fixes: commit 9516823051 ("ipaddress: Improve print_linkinfo()")
Reported-by: Vincent Bernat <vincent@bernat.im>
Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2018-07-18 15:52:55 -07:00
..
.gitignore Another .gitignore file. 2006-08-08 12:11:23 -07:00
Makefile ip: add rmnet initial support 2018-06-15 11:15:14 -07:00
ifcfg ifcfg/rtpr: convert to POSIX shell 2018-01-10 08:26:09 -08:00
ila_common.h SPDX license identifiers 2017-11-24 12:21:35 -08:00
ip.c Merge branch 'iproute2-master' into iproute2-next 2018-03-27 12:33:02 -07:00
ip6tunnel.c utils: Introduce and use nodev() helper routine 2018-03-11 17:58:36 -07:00
ip_common.h iplink: enable to specify a name for the link-netns 2018-06-08 10:06:21 -07:00
ipaddress.c ipaddress: Fix and make consistent label match handling 2018-07-18 15:52:55 -07:00
ipaddrlabel.c ipaddrlabel: add json support 2018-03-06 15:38:41 -08:00
ipfou.c fou: support JSON output 2018-03-06 15:39:34 -08:00
ipila.c ip/ila: support json and color 2018-03-28 20:36:58 -07:00
ipl2tp.c l2tp: no need to export session offsets in JSON output 2018-04-05 12:43:23 -07:00
iplink.c ip: add rmnet initial support 2018-06-15 11:15:14 -07:00
iplink_bond.c utils: Introduce and use nodev() helper routine 2018-03-11 17:58:36 -07:00
iplink_bond_slave.c ip: iplink_bond_slave.c: add json output support (info_slave_data) 2017-08-17 18:02:40 -07:00
iplink_bridge.c utils: Introduce and use nodev() helper routine 2018-03-11 17:58:36 -07:00
iplink_bridge_slave.c ip: Use print_0xhex() where appropriate 2018-02-09 08:05:30 -08:00
iplink_can.c Merge branch 'master' into net-next 2017-08-21 17:37:15 -07:00
iplink_dummy.c SPDX license identifiers 2017-11-24 12:21:35 -08:00
iplink_geneve.c iplink_geneve: correct size of message to avoid spurious errors 2018-04-20 10:39:53 -07:00
iplink_hsr.c ip: iplink_hsr.c: add json output support 2017-08-17 18:02:40 -07:00
iplink_ifb.c SPDX license identifiers 2017-11-24 12:21:35 -08:00
iplink_ipoib.c ip: iplink_ipoib.c: add json output support 2017-08-17 18:02:41 -07:00
iplink_ipvlan.c ip/ipvlan: enhance ability to add mode flags to existing modes 2017-11-01 22:17:01 +01:00
iplink_macvlan.c ip: link_macvlan.c: add json output support 2017-08-17 18:02:41 -07:00
iplink_netdevsim.c ip: link: add support for netdevsim device type 2018-01-02 20:46:19 -08:00
iplink_nlmon.c SPDX license identifiers 2017-11-24 12:21:35 -08:00
iplink_rmnet.c ip: add rmnet initial support 2018-06-15 11:15:14 -07:00
iplink_team.c SPDX license identifiers 2017-11-24 12:21:35 -08:00
iplink_vcan.c SPDX license identifiers 2017-11-24 12:21:35 -08:00
iplink_vlan.c treewide: Use addattr_nest()/addattr_nest_end() to handle nested attributes 2018-02-02 15:01:09 -08:00
iplink_vrf.c iplink_vrf: Save device index from response for return code 2018-06-01 15:45:09 -04:00
iplink_vxcan.c iplink: Perform most of request buffer setups and checks in iplink_parse() 2018-03-11 17:59:03 -07:00
iplink_vxlan.c vxlan: add ttl auto in help message 2018-04-23 19:43:46 -07:00
iplink_xdp.c ip: defer lookup interface index 2018-05-25 07:48:40 -07:00
iplink_xstats.c add missing iplink_xstats.c 2017-02-20 08:53:40 -08:00
ipmacsec.c json_print: Fix hidden 64-bit type promotion 2018-04-25 11:08:55 -07:00
ipmaddr.c ipmaddr: json and color support 2018-03-11 18:52:06 -07:00
ipmonitor.c drop unneeded include of syslog.h 2017-11-12 16:22:36 -08:00
ipmroute.c json_print: Fix hidden 64-bit type promotion 2018-04-25 11:08:55 -07:00
ipneigh.c ipneigh: fix missing format specifier 2018-04-20 10:33:22 -07:00
ipnetconf.c ipnetconf: add JSON support 2018-03-06 15:38:57 -08:00
ipnetns.c iplink: enable to specify a name for the link-netns 2018-06-08 10:06:21 -07:00
ipntable.c json_print: Fix hidden 64-bit type promotion 2018-04-25 11:08:55 -07:00
ipprefix.c netlink route attribute cleanup 2017-02-24 08:56:38 -08:00
iproute.c iproute: ip route get support for sport, dport and ipproto match 2018-06-01 08:19:30 -07:00
iproute_lwtunnel.c json_print: Fix hidden 64-bit type promotion 2018-04-25 11:08:55 -07:00
iprule.c iprule: support for ip_proto, sport and dport match options 2018-03-08 10:08:18 -08:00
ipseg6.c ipsr: add json support 2018-03-06 15:39:14 -08:00
iptoken.c token: support JSON 2018-03-06 15:39:19 -08:00
iptunnel.c utils: Introduce and use nodev() helper routine 2018-03-11 17:58:36 -07:00
iptuntap.c json_print: Fix hidden 64-bit type promotion 2018-04-25 11:08:55 -07:00
ipvrf.c Drop capabilities if not running ip exec vrf with libcap 2018-03-27 11:48:23 -07:00
ipxfrm.c ipxfrm: Replace STRBUF_CAT macro with strlcat() 2017-09-01 12:10:54 -07:00
link_gre.c gre/gre6: allow clearing {,i,o}{key,seq,csum} flags 2018-04-23 19:42:58 -07:00
link_gre6.c gre/gre6: allow clearing {,i,o}{key,seq,csum} flags 2018-04-23 19:42:58 -07:00
link_ip6tnl.c utils: Introduce and use nodev() helper routine 2018-03-11 17:58:36 -07:00
link_iptnl.c utils: Introduce and use nodev() helper routine 2018-03-11 17:58:36 -07:00
link_veth.c iplink: Perform most of request buffer setups and checks in iplink_parse() 2018-03-11 17:59:03 -07:00
link_vti.c utils: Introduce and use nodev() helper routine 2018-03-11 17:58:36 -07:00
link_vti6.c utils: Introduce and use nodev() helper routine 2018-03-11 17:58:36 -07:00
routef mark shell scripts +x 2018-01-10 08:23:49 -08:00
routel mark shell scripts +x 2018-01-10 08:23:49 -08:00
rtm_map.c drop unneeded include of syslog.h 2017-11-12 16:22:36 -08:00
rtmon.c drop unneeded include of syslog.h 2017-11-12 16:22:36 -08:00
rtpr ifcfg/rtpr: convert to POSIX shell 2018-01-10 08:26:09 -08:00
static-syms.c SPDX license identifiers 2017-11-24 12:21:35 -08:00
tcp_metrics.c json_print: Fix hidden 64-bit type promotion 2018-04-25 11:08:55 -07:00
tunnel.c Merge branch 'iproute2-master' into iproute2-next 2018-04-02 10:47:34 -07:00
tunnel.h iptunnel/ip6tunnel: Use netlink to walk through tunnels list 2018-02-07 16:15:42 -08:00
xfrm.h ip: Fix compilation break on old systems 2017-11-13 10:07:25 -08:00
xfrm_monitor.c iproute2: fix 'ip xfrm monitor all' command 2018-06-01 15:57:26 -04:00
xfrm_policy.c Merge branch 'master' into net-next 2017-11-09 09:45:17 +09:00
xfrm_state.c Merge branch 'master' into net-next 2017-11-09 09:45:17 +09:00