From patchwork Thu Jan 3 04:38:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Ahern X-Patchwork-Id: 1020169 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="BrF1vcaU"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43VZtX3dBzz9rxp for ; Thu, 3 Jan 2019 15:38:44 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729349AbfACEig (ORCPT ); Wed, 2 Jan 2019 23:38:36 -0500 Received: from mail.kernel.org ([198.145.29.99]:34012 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728640AbfACEif (ORCPT ); Wed, 2 Jan 2019 23:38:35 -0500 Received: from kenny.it.cumulusnetworks.com. (fw.cumulusnetworks.com [216.129.126.126]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7045520896; Thu, 3 Jan 2019 04:38:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546490314; bh=CIAUfFFGbD8lVFs9YQXlVMvlWzNMoq9rkMqF9O3+DLc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BrF1vcaU2B28bcfd8PFVxC+JrWT99nxgPwP9DRrWSLEepKPIrC1xMqmvAdG5wtcSA +/v4gFha0YIQ5WUSmLXTGLk/rBvIpVlOXHOyF80LoeBZeJSWz3b2Zor9a3YDa/tt3f WV1FXkOTDGc4LqBm9itOr6ZB39b6OtPfcQ6aZH/4= From: David Ahern To: netdev@vger.kernel.org Cc: idosch@mellanox.com, stephen@networkplumber.org, David Ahern Subject: [PATCH iproute2-next 1/5] libnetlink: Add filter function to rtnl_neighdump_req Date: Wed, 2 Jan 2019 20:38:28 -0800 Message-Id: <20190103043832.3748-2-dsahern@kernel.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190103043832.3748-1-dsahern@kernel.org> References: <20190103043832.3748-1-dsahern@kernel.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: David Ahern Add filter function to rtnl_neighdump_req and a buffer to the request for the filter functions to append attributes. Signed-off-by: David Ahern --- include/libnetlink.h | 3 ++- lib/libnetlink.c | 12 +++++++++++- misc/arpd.c | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/include/libnetlink.h b/include/libnetlink.h index dc0c9c4eb3f5..148951510d1e 100644 --- a/include/libnetlink.h +++ b/include/libnetlink.h @@ -60,7 +60,8 @@ int rtnl_routedump_req(struct rtnl_handle *rth, int family, __attribute__((warn_unused_result)); int rtnl_ruledump_req(struct rtnl_handle *rth, int family) __attribute__((warn_unused_result)); -int rtnl_neighdump_req(struct rtnl_handle *rth, int family) +int rtnl_neighdump_req(struct rtnl_handle *rth, int family, + req_filter_fn_t filter_fn) __attribute__((warn_unused_result)); int rtnl_neightbldump_req(struct rtnl_handle *rth, int family) __attribute__((warn_unused_result)); diff --git a/lib/libnetlink.c b/lib/libnetlink.c index 4d7d081054fd..19318b445266 100644 --- a/lib/libnetlink.c +++ b/lib/libnetlink.c @@ -327,11 +327,13 @@ int rtnl_ruledump_req(struct rtnl_handle *rth, int family) return send(rth->fd, &req, sizeof(req), 0); } -int rtnl_neighdump_req(struct rtnl_handle *rth, int family) +int rtnl_neighdump_req(struct rtnl_handle *rth, int family, + req_filter_fn_t filter_fn) { struct { struct nlmsghdr nlh; struct ndmsg ndm; + char buf[256]; } req = { .nlh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg)), .nlh.nlmsg_type = RTM_GETNEIGH, @@ -340,6 +342,14 @@ int rtnl_neighdump_req(struct rtnl_handle *rth, int family) .ndm.ndm_family = family, }; + if (filter_fn) { + int err; + + err = filter_fn(&req.nlh, sizeof(req)); + if (err) + return err; + } + return send(rth->fd, &req, sizeof(req), 0); } diff --git a/misc/arpd.c b/misc/arpd.c index ce7c09978c2b..504961cb5e3a 100644 --- a/misc/arpd.c +++ b/misc/arpd.c @@ -424,7 +424,7 @@ static int do_one_request(struct nlmsghdr *n) static void load_initial_table(void) { - if (rtnl_neighdump_req(&rth, AF_INET) < 0) { + if (rtnl_neighdump_req(&rth, AF_INET, NULL) < 0) { perror("dump request failed"); exit(1); }