From: David Ahern <dsahern@kernel.org>
To: netdev@vger.kernel.org
Cc: idosch@mellanox.com, stephen@networkplumber.org,
David Ahern <dsahern@gmail.com>
Subject: [PATCH iproute2-next 2/5] ip neigh: Convert do_show_or_flush to use rtnl_neighdump_req
Date: Wed, 2 Jan 2019 20:38:29 -0800 [thread overview]
Message-ID: <20190103043832.3748-3-dsahern@kernel.org> (raw)
In-Reply-To: <20190103043832.3748-1-dsahern@kernel.org>
From: David Ahern <dsahern@gmail.com>
Add ipneigh_dump_filter to add filter attributes to the neighbor
dump request and update do_show_or_flush to use rtnl_neighdump_req.
Signed-off-by: David Ahern <dsahern@gmail.com>
---
ip/ipneigh.c | 42 ++++++++++++++++++++++++++----------------
1 file changed, 26 insertions(+), 16 deletions(-)
diff --git a/ip/ipneigh.c b/ip/ipneigh.c
index 26ac2d1be21f..2d717d2d2aeb 100644
--- a/ip/ipneigh.c
+++ b/ip/ipneigh.c
@@ -41,6 +41,7 @@ static struct
int flushe;
int master;
int protocol;
+ __u8 ndm_flags;
} filter;
static void usage(void) __attribute__((noreturn));
@@ -408,16 +409,29 @@ void ipneigh_reset_filter(int ifindex)
filter.index = ifindex;
}
+static int ipneigh_dump_filter(struct nlmsghdr *nlh, int reqlen)
+{
+ struct ndmsg *ndm = NLMSG_DATA(nlh);
+ int err;
+
+ ndm->ndm_flags = filter.ndm_flags;
+
+ if (filter.index) {
+ err = addattr32(nlh, reqlen, NDA_IFINDEX, filter.index);
+ if (err)
+ return err;
+ }
+ if (filter.master) {
+ err = addattr32(nlh, reqlen, NDA_MASTER, filter.master);
+ if (err)
+ return err;
+ }
+
+ return 0;
+}
+
static int do_show_or_flush(int argc, char **argv, int flush)
{
- struct {
- struct nlmsghdr n;
- struct ndmsg ndm;
- char buf[256];
- } req = {
- .n.nlmsg_type = RTM_GETNEIGH,
- .n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg)),
- };
char *filter_dev = NULL;
int state_given = 0;
@@ -448,7 +462,6 @@ static int do_show_or_flush(int argc, char **argv, int flush)
ifindex = ll_name_to_index(*argv);
if (!ifindex)
invarg("Device does not exist\n", *argv);
- addattr32(&req.n, sizeof(req), NDA_MASTER, ifindex);
filter.master = ifindex;
} else if (strcmp(*argv, "vrf") == 0) {
int ifindex;
@@ -459,7 +472,6 @@ static int do_show_or_flush(int argc, char **argv, int flush)
invarg("Not a valid VRF name\n", *argv);
if (!name_is_vrf(*argv))
invarg("Not a valid VRF name\n", *argv);
- addattr32(&req.n, sizeof(req), NDA_MASTER, ifindex);
filter.master = ifindex;
} else if (strcmp(*argv, "unused") == 0) {
filter.unused_only = 1;
@@ -482,7 +494,7 @@ static int do_show_or_flush(int argc, char **argv, int flush)
state = 0x100;
filter.state |= state;
} else if (strcmp(*argv, "proxy") == 0) {
- req.ndm.ndm_flags = NTF_PROXY;
+ filter.ndm_flags = NTF_PROXY;
} else if (matches(*argv, "protocol") == 0) {
__u32 prot;
@@ -513,11 +525,8 @@ static int do_show_or_flush(int argc, char **argv, int flush)
filter.index = ll_name_to_index(filter_dev);
if (!filter.index)
return nodev(filter_dev);
- addattr32(&req.n, sizeof(req), NDA_IFINDEX, filter.index);
}
- req.ndm.ndm_family = filter.family;
-
if (flush) {
int round = 0;
char flushb[4096-512];
@@ -527,7 +536,8 @@ static int do_show_or_flush(int argc, char **argv, int flush)
filter.flushe = sizeof(flushb);
while (round < MAX_ROUNDS) {
- if (rtnl_dump_request_n(&rth, &req.n) < 0) {
+ if (rtnl_neighdump_req(&rth, filter.family,
+ ipneigh_dump_filter) < 0) {
perror("Cannot send dump request");
exit(1);
}
@@ -560,7 +570,7 @@ static int do_show_or_flush(int argc, char **argv, int flush)
return 1;
}
- if (rtnl_dump_request_n(&rth, &req.n) < 0) {
+ if (rtnl_neighdump_req(&rth, filter.family, ipneigh_dump_filter) < 0) {
perror("Cannot send dump request");
exit(1);
}
--
2.11.0
next prev parent reply other threads:[~2019-01-03 4:38 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-03 4:38 [PATCH iproute2-next 0/5] ip bridge: Updates to neigh and fdb dumps David Ahern
2019-01-03 4:38 ` [PATCH iproute2-next 1/5] libnetlink: Add filter function to rtnl_neighdump_req David Ahern
2019-01-03 4:38 ` David Ahern [this message]
2019-01-03 4:38 ` [PATCH iproute2-next 3/5] bridge: Update fdb show to use rtnl_neighdump_req David Ahern
2019-01-03 4:38 ` [PATCH iproute2-next 4/5] libnetlink: Add RTNL_HANDLE_F_STRICT_CHK flag David Ahern
2019-01-03 4:38 ` [PATCH iproute2-next 5/5] bridge: fdb: Fix filtering with strict checking disabled David Ahern
2019-01-04 13:45 ` Ido Schimmel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190103043832.3748-3-dsahern@kernel.org \
--to=dsahern@kernel.org \
--cc=dsahern@gmail.com \
--cc=idosch@mellanox.com \
--cc=netdev@vger.kernel.org \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.