From: Serhey Popovych Subject: Re: [PATCH iproute2-next] ipaddress: fix label matching Date: Sat, 14 Jul 2018 21:54:07 +0300 Message-ID: <0b8902b1-fad1-55ef-acfc-088edb4569c6@gmail.com> References: <20180711113603.16589-1-vincent@bernat.im> <18bed3ed-4ad1-4506-6b80-62af9bd9e6d2@gmail.com> <057043f9-e476-cde8-4915-8e350fc6d848@gmail.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="DNMVahh3lpgpyAW3mRFjv180LXU1i7rx7" Cc: netdev@vger.kernel.org, stephen@networkplumber.org To: Vincent Bernat , David Ahern Return-path: Received: from mail-lj1-f196.google.com ([209.85.208.196]:40021 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727282AbeGNTOP (ORCPT ); Sat, 14 Jul 2018 15:14:15 -0400 Received: by mail-lj1-f196.google.com with SMTP id j19-v6so1438849ljc.7 for ; Sat, 14 Jul 2018 11:54:15 -0700 (PDT) In-Reply-To: <057043f9-e476-cde8-4915-8e350fc6d848@gmail.com> Sender: netdev-owner@vger.kernel.org List-ID: This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --DNMVahh3lpgpyAW3mRFjv180LXU1i7rx7 Content-Type: multipart/mixed; boundary="0KRA8PI3ImG8mSTxXK0DHPtFLaiZAloXA"; protected-headers="v1" From: Serhey Popovych To: Vincent Bernat , David Ahern Cc: netdev@vger.kernel.org, stephen@networkplumber.org Message-ID: <0b8902b1-fad1-55ef-acfc-088edb4569c6@gmail.com> Subject: Re: [PATCH iproute2-next] ipaddress: fix label matching References: <20180711113603.16589-1-vincent@bernat.im> <18bed3ed-4ad1-4506-6b80-62af9bd9e6d2@gmail.com> <057043f9-e476-cde8-4915-8e350fc6d848@gmail.com> In-Reply-To: <057043f9-e476-cde8-4915-8e350fc6d848@gmail.com> --0KRA8PI3ImG8mSTxXK0DHPtFLaiZAloXA Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Serhey Popovych wrote: > Vincent Bernat wrote: >> =E2=9D=A6 11 juillet 2018 21:01 -0400, David Ahern =C2=A0: >> >>>> +++ b/ip/ipaddress.c >>>> @@ -837,11 +837,6 @@ int print_linkinfo(const struct sockaddr_nl *wh= o, >>>> if (!name) >>>> return -1; >>>> =20 >>>> - if (filter.label && >>>> - (!filter.family || filter.family =3D=3D AF_PACKET) && >>>> - fnmatch(filter.label, name, 0)) >>>> - return -1; >>>> - >>> >>> The offending commit changed the return code: >>> >>> if (filter.label && >>> (!filter.family || filter.family =3D=3D AF_PACKET) && >>> - fnmatch(filter.label, RTA_DATA(tb[IFLA_IFNAME]), 0)) >>> - return 0; >>> + fnmatch(filter.label, name, 0)) >>> + return -1; >>> >>> >>> Vincent: can you try leaving the code as is, but change the return to= 0? >> >> Yes, it works by just returning 0. The code still doesn't make sense. >> >=20 > I think return code is correct. Check presented by this code too becaus= e > print_linkinfo() isn't static and called from ipmonitor.c where no > ipaddr_filter() or similar call that filters by label present. Ok, did more deep analysis of code. Vincent, David: we should return 0 as done before 9516823051ce. This is special case to return from print_linkinfo() earlier and match only filter.ifindex and filter.up if given and not rest fields in @filter= =2E 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 filter.label using ifa_label_match_rta(). >=20 > Instead fnmatch() compares interface *name*, not label from IFA_LABEL > attribute. Thus: >=20 > fnmatch(pattern, string, flags) -> > fnmatch("lo:1", "lo", 0) =3D=3D FNM_NOMATCH (1) This still incorrect: we should not call fnmatch() with network device na= me. Also ip-link(8) does not say anything that label could be used to filter link output. Label is ip-address(8) specific. Therefore checking filter.family =3D=3D AF_PACKET looks incorrect. AF_PACKET is ip-link(8) specific. Checking against !filter.family (AF_UNSPEC) is incorrect too: user might force address family at ip command line and we never get: ip -4 addr show label lo:1 So from the code: if (filter.label && (!filter.family || filter.family =3D=3D AF_PACKET) && fnmatch(filter.label, RTA_DATA(tb[IFLA_IFNAME]), 0)) return -1; We should leave only filter.label check and return 0: if (filter.label) return 0; This will ensure we exit from print_linkinfo() earlier, skip print_link_stats() and push final filtering by label to print_selected_addrinfo() and print_addrinfo(). And finally: this is regression and should be against iproute2, not -next= =2E >=20 > Assuming above I would like to see ifa_label_match_rta() instead of ope= n > coded checks for filter.label with fmatch() in print_linkinfo(). >=20 > Also it might be good idea to pass @name from get_ifname_rta() (like we= > do in print_linkinfo()) to ifa_label_match_rta() so that we respect > IFLA_IFNAME if present. >=20 --0KRA8PI3ImG8mSTxXK0DHPtFLaiZAloXA-- --DNMVahh3lpgpyAW3mRFjv180LXU1i7rx7 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iQEcBAEBAgAGBQJbSkbUAAoJEBTawMmQ61bBh8gH/ik7roa/Ou9peIxQR8NDPFpw w05H/VRKpV9vCHKRUcbIZ2yh8/TVwb4f3tZHffbQPC2z8caXBDfMC3ursiFLBOqc Gb9AmUcpI8H0JReKxTDtkSwVb0zxu2JyTKkn5tsTSTbKbB4tv+si4jsQxovtJ5AG 3OATfFIcp/bCuhYfBYWoTkSw85l8btdSl6ijDCS4lKBDV5FyoiimD+HZRZ2QCcro 2CWQDvC9A7qVngSUjnE2o8GnEVLWz2RBYDfYS6GgysAV/fvDSqeqz2w0Sy+ztMBo mOWtJLCugxTFZUj+SaWXEZh40DHi9gLgBgnGo/4gWPj3Y24MQk8gM2yXorYVeKQ= =QfMo -----END PGP SIGNATURE----- --DNMVahh3lpgpyAW3mRFjv180LXU1i7rx7--