From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Ahern Subject: [PATCH iproute2-next 05/12] ip route: Add protocol, table id and device to dump request Date: Wed, 19 Dec 2018 19:54:20 -0800 Message-ID: <20181220035427.14453-6-dsahern@kernel.org> References: <20181220035427.14453-1-dsahern@kernel.org> Cc: stephen@networkplumber.org, David Ahern To: netdev@vger.kernel.org Return-path: Received: from mail.kernel.org ([198.145.29.99]:51772 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729293AbeLTDxz (ORCPT ); Wed, 19 Dec 2018 22:53:55 -0500 In-Reply-To: <20181220035427.14453-1-dsahern@kernel.org> Sender: netdev-owner@vger.kernel.org List-ID: From: David Ahern Add protocol, table id and device to dump request if set in filter. If kernel side filtering is supported it is used to reduce the amount of data sent to userspace. Older kernels do not parse attributes on a route dump request, so these are silently ignored and ip will do the filtering in userspace. Signed-off-by: David Ahern --- ip/iproute.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ip/iproute.c b/ip/iproute.c index 3c0be0a96d4e..5bffb9d88b58 100644 --- a/ip/iproute.c +++ b/ip/iproute.c @@ -1669,10 +1669,24 @@ static int iproute_flush(int do_ipv6, rtnl_filter_t filter_fn) static int iproute_dump_filter(struct nlmsghdr *nlh, int reqlen) { struct rtmsg *rtm = NLMSG_DATA(nlh); + int err; + rtm->rtm_protocol = filter.protocol; if (filter.cloned) rtm->rtm_flags |= RTM_F_CLONED; + if (filter.tb) { + err = addattr32(nlh, reqlen, RTA_TABLE, filter.tb); + if (err) + return err; + } + + if (filter.oif) { + err = addattr32(nlh, reqlen, RTA_OIF, filter.oif); + if (err) + return err; + } + return 0; } -- 2.11.0