* [PATCH net-next] net: Add support for filtering neigh dump by device index
@ 2015-10-03 18:25 David Ahern
2015-10-03 18:39 ` Nikolay Aleksandrov
0 siblings, 1 reply; 2+ messages in thread
From: David Ahern @ 2015-10-03 18:25 UTC (permalink / raw)
To: netdev; +Cc: roopa, David Ahern
Add support for filtering neighbor dumps by device by adding the
NDA_IFINDEX attribute to the dump request. When set the kernel only
sends neighbor entries for the given device.
Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
---
net/core/neighbour.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/net/core/neighbour.c b/net/core/neighbour.c
index 8c57fdf4d68e..f7786eaef613 100644
--- a/net/core/neighbour.c
+++ b/net/core/neighbour.c
@@ -2249,6 +2249,14 @@ static bool neigh_master_filtered(struct net_device *dev, int master_idx)
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,
struct netlink_callback *cb)
{
@@ -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 idx, s_idx = idx = cb->args[2];
struct neigh_hash_table *nht;
- int filter_master_idx = 0;
+ int filter_master_idx = 0, filter_idx = 0;
unsigned int flags = NLM_F_MULTI;
int err;
err = nlmsg_parse(nlh, sizeof(struct ndmsg), tb, NDA_MAX, NULL);
if (!err) {
+ if (tb[NDA_IFINDEX])
+ filter_idx = nla_get_u32(tb[NDA_IFINDEX]);
+
if (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;
}
@@ -2283,6 +2294,8 @@ static int neigh_dump_table(struct neigh_table *tbl, struct sk_buff *skb,
n = rcu_dereference_bh(n->next)) {
if (!net_eq(dev_net(n->dev), net))
continue;
+ if (neigh_ifindex_filtered(n->dev, filter_idx))
+ continue;
if (neigh_master_filtered(n->dev, filter_master_idx))
continue;
if (idx < s_idx)
--
1.9.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net-next] net: Add support for filtering neigh dump by device index
2015-10-03 18:25 [PATCH net-next] net: Add support for filtering neigh dump by device index David Ahern
@ 2015-10-03 18:39 ` Nikolay Aleksandrov
0 siblings, 0 replies; 2+ messages in thread
From: Nikolay Aleksandrov @ 2015-10-03 18:39 UTC (permalink / raw)
To: David Ahern, netdev; +Cc: roopa
On 10/03/2015 08:25 PM, David Ahern wrote:
> Add support for filtering neighbor dumps by device by adding the
> NDA_IFINDEX attribute to the dump request. When set the kernel only
> sends neighbor entries for the given device.
>
> Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
> ---
> net/core/neighbour.c | 17 +++++++++++++++--
> 1 file changed, 15 insertions(+), 2 deletions(-)
>
> diff --git a/net/core/neighbour.c b/net/core/neighbour.c
> index 8c57fdf4d68e..f7786eaef613 100644
> --- a/net/core/neighbour.c
> +++ b/net/core/neighbour.c
> @@ -2249,6 +2249,14 @@ static bool neigh_master_filtered(struct net_device *dev, int master_idx)
> 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,
> struct netlink_callback *cb)
> {
> @@ -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 idx, s_idx = idx = cb->args[2];
> struct neigh_hash_table *nht;
> - int filter_master_idx = 0;
> + int filter_master_idx = 0, filter_idx = 0;
> unsigned int flags = NLM_F_MULTI;
> int err;
>
> err = nlmsg_parse(nlh, sizeof(struct ndmsg), tb, NDA_MAX, NULL);
> if (!err) {
> + if (tb[NDA_IFINDEX])
> + filter_idx = nla_get_u32(tb[NDA_IFINDEX]);
> +
> if (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;
> }
>
> @@ -2283,6 +2294,8 @@ static int neigh_dump_table(struct neigh_table *tbl, struct sk_buff *skb,
> n = rcu_dereference_bh(n->next)) {
> if (!net_eq(dev_net(n->dev), net))
> continue;
> + if (neigh_ifindex_filtered(n->dev, filter_idx))
> + continue;
> if (neigh_master_filtered(n->dev, filter_master_idx))
> continue;
> if (idx < s_idx)
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-10-03 18:39 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-03 18:25 [PATCH net-next] net: Add support for filtering neigh dump by device index David Ahern
2015-10-03 18:39 ` Nikolay Aleksandrov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox