Commit 16660f0b authored by David Ahern's avatar David Ahern Committed by David S. Miller

net: Add support for filtering neigh dump by device index

Add support for filtering neighbor dumps by device by adding the
NDA_IFINDEX attribute to the dump request.
Signed-off-by: default avatarDavid Ahern <dsa@cumulusnetworks.com>
Reviewed-by: default avatarNikolay Aleksandrov <nikolay@cumulusnetworks.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent e892406f
...@@ -2249,6 +2249,14 @@ static bool neigh_master_filtered(struct net_device *dev, int master_idx) ...@@ -2249,6 +2249,14 @@ static bool neigh_master_filtered(struct net_device *dev, int master_idx)
return false; return false;
} }
static bool neigh_ifindex_filtered(struct net_device *dev, int filter_idx)
{
if (filter_idx && dev->ifindex != filter_idx)
return true;
return false;
}
static int neigh_dump_table(struct neigh_table *tbl, struct sk_buff *skb, static int neigh_dump_table(struct neigh_table *tbl, struct sk_buff *skb,
struct netlink_callback *cb) struct netlink_callback *cb)
{ {
...@@ -2259,16 +2267,19 @@ static int neigh_dump_table(struct neigh_table *tbl, struct sk_buff *skb, ...@@ -2259,16 +2267,19 @@ static int neigh_dump_table(struct neigh_table *tbl, struct sk_buff *skb,
int rc, h, s_h = cb->args[1]; int rc, h, s_h = cb->args[1];
int idx, s_idx = idx = cb->args[2]; int idx, s_idx = idx = cb->args[2];
struct neigh_hash_table *nht; struct neigh_hash_table *nht;
int filter_master_idx = 0; int filter_master_idx = 0, filter_idx = 0;
unsigned int flags = NLM_F_MULTI; unsigned int flags = NLM_F_MULTI;
int err; int err;
err = nlmsg_parse(nlh, sizeof(struct ndmsg), tb, NDA_MAX, NULL); err = nlmsg_parse(nlh, sizeof(struct ndmsg), tb, NDA_MAX, NULL);
if (!err) { if (!err) {
if (tb[NDA_IFINDEX])
filter_idx = nla_get_u32(tb[NDA_IFINDEX]);
if (tb[NDA_MASTER]) if (tb[NDA_MASTER])
filter_master_idx = nla_get_u32(tb[NDA_MASTER]); filter_master_idx = nla_get_u32(tb[NDA_MASTER]);
if (filter_master_idx) if (filter_idx || filter_master_idx)
flags |= NLM_F_DUMP_FILTERED; flags |= NLM_F_DUMP_FILTERED;
} }
...@@ -2283,6 +2294,8 @@ static int neigh_dump_table(struct neigh_table *tbl, struct sk_buff *skb, ...@@ -2283,6 +2294,8 @@ static int neigh_dump_table(struct neigh_table *tbl, struct sk_buff *skb,
n = rcu_dereference_bh(n->next)) { n = rcu_dereference_bh(n->next)) {
if (!net_eq(dev_net(n->dev), net)) if (!net_eq(dev_net(n->dev), net))
continue; continue;
if (neigh_ifindex_filtered(n->dev, filter_idx))
continue;
if (neigh_master_filtered(n->dev, filter_master_idx)) if (neigh_master_filtered(n->dev, filter_master_idx))
continue; continue;
if (idx < s_idx) if (idx < s_idx)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment