From: David Ahern Subject: Re: [PATCH iproute2-next 2/8] ipaddress: Use get_addr_rta() Date: Tue, 23 Jan 2018 10:40:22 -0700 Message-ID: <4dcd4ad7-680b-f8b8-2503-06646619f24d@gmail.com> References: <1516641978-24269-1-git-send-email-serhe.popovych@gmail.com> <1516641978-24269-3-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-pf0-f178.google.com ([209.85.192.178]:34736 "EHLO mail-pf0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751259AbeAWRkQ (ORCPT ); Tue, 23 Jan 2018 12:40:16 -0500 Received: by mail-pf0-f178.google.com with SMTP id e76so876887pfk.1 for ; Tue, 23 Jan 2018 09:40:16 -0800 (PST) In-Reply-To: <1516641978-24269-3-git-send-email-serhe.popovych@gmail.com> Content-Language: en-US Sender: netdev-owner@vger.kernel.org List-ID: On 1/22/18 10:26 AM, Serhey Popovych wrote: > diff --git a/ip/ipaddress.c b/ip/ipaddress.c > index ba60125..38d994e 100644 > --- a/ip/ipaddress.c > +++ b/ip/ipaddress.c > @@ -1523,19 +1523,20 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n, > if (fnmatch(filter.label, label, 0) != 0) > return 0; > } > - if (filter.pfx.family) { > - if (rta_tb[IFA_LOCAL]) { > - inet_prefix dst = { .family = ifa->ifa_family }; > - > - memcpy(&dst.data, RTA_DATA(rta_tb[IFA_LOCAL]), RTA_PAYLOAD(rta_tb[IFA_LOCAL])); > - if (inet_addr_match(&dst, &filter.pfx, filter.pfx.bitlen)) > - return 0; > - } > - } > > if (filter.family && filter.family != ifa->ifa_family) > return 0; > > + if (filter.pfx.family && rta_tb[IFA_LOCAL]) { > + struct rtattr *rta = rta_tb[IFA_LOCAL]; > + inet_prefix dst, *f_pfx = &filter.pfx; > + > + if (get_addr_rta(&dst, rta, f_pfx->family)) > + return 0; > + if (inet_addr_match(&dst, f_pfx, f_pfx->bitlen)) > + return 0; > + } > + Those 2 checks are a consistent them throughout the patches. Given that why not create a helper that takes an rta and an inet_prefix and returns the result of both checks?