From mboxrd@z Thu Jan 1 00:00:00 1970 From: Serhey Popovych Subject: [PATCH iproute2-next v3 4/8] ipmroute: Use inet_addr_match_rta() Date: Wed, 24 Jan 2018 20:56:36 +0200 Message-ID: <1516820200-13723-5-git-send-email-serhe.popovych@gmail.com> References: <1516820200-13723-1-git-send-email-serhe.popovych@gmail.com> To: netdev@vger.kernel.org Return-path: Received: from mail-lf0-f66.google.com ([209.85.215.66]:39461 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965091AbeAXS4v (ORCPT ); Wed, 24 Jan 2018 13:56:51 -0500 Received: by mail-lf0-f66.google.com with SMTP id w27so5320127lfd.6 for ; Wed, 24 Jan 2018 10:56:51 -0800 (PST) Received: from tuxracer.localdomain ([2a01:6d80::195:20:96:53]) by smtp.gmail.com with ESMTPSA id h63sm174842ljf.36.2018.01.24.10.56.49 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Jan 2018 10:56:49 -0800 (PST) In-Reply-To: <1516820200-13723-1-git-send-email-serhe.popovych@gmail.com> Sender: netdev-owner@vger.kernel.org List-ID: While there check return from get_prefix() for filter address. Signed-off-by: Serhey Popovych --- ip/ipmroute.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/ip/ipmroute.c b/ip/ipmroute.c index 0450ea9..aa5029b 100644 --- a/ip/ipmroute.c +++ b/ip/ipmroute.c @@ -95,21 +95,11 @@ int print_mroute(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) if (filter.af && filter.af != r->rtm_family) return 0; - if (tb[RTA_DST] && filter.mdst.bitlen > 0) { - inet_prefix dst = { .family = r->rtm_family }; - - memcpy(&dst.data, RTA_DATA(tb[RTA_DST]), RTA_PAYLOAD(tb[RTA_DST])); - if (inet_addr_match(&dst, &filter.mdst, filter.mdst.bitlen)) - return 0; - } - - if (tb[RTA_SRC] && filter.msrc.bitlen > 0) { - inet_prefix src = { .family = r->rtm_family }; + if (inet_addr_match_rta(&filter.mdst, tb[RTA_DST])) + return 0; - memcpy(&src.data, RTA_DATA(tb[RTA_SRC]), RTA_PAYLOAD(tb[RTA_SRC])); - if (inet_addr_match(&src, &filter.msrc, filter.msrc.bitlen)) - return 0; - } + if (inet_addr_match_rta(&filter.msrc, tb[RTA_SRC])) + return 0; family = get_real_family(r->rtm_type, r->rtm_family); @@ -213,6 +203,8 @@ static int mroute_list(int argc, char **argv) } else filter.af = RTNL_FAMILY_IP6MR; + filter.msrc.family = filter.mdst.family = family; + while (argc > 0) { if (matches(*argv, "table") == 0) { __u32 tid; @@ -233,14 +225,16 @@ static int mroute_list(int argc, char **argv) id = *argv; } else if (matches(*argv, "from") == 0) { NEXT_ARG(); - get_prefix(&filter.msrc, *argv, family); + if (get_prefix(&filter.msrc, *argv, family)) + invarg("from value is invalid\n", *argv); } else { if (strcmp(*argv, "to") == 0) { NEXT_ARG(); } if (matches(*argv, "help") == 0) usage(); - get_prefix(&filter.mdst, *argv, family); + if (get_prefix(&filter.mdst, *argv, family)) + invarg("to value is invalid\n", *argv); } argc--; argv++; } -- 1.7.10.4