Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 21fdd092 authored by David Ahern's avatar David Ahern Committed by David S. Miller
Browse files

net: Add support for filtering neigh dump by master device



Add support for filtering neighbor dumps by master device by adding
the NDA_MASTER attribute to the dump request. A new netlink flag,
NLM_F_DUMP_FILTERED, is added to indicate the kernel supports the
request and output is filtered as requested.

Signed-off-by: default avatarDavid Ahern <dsa@cumulusnetworks.com>
Acked-by: default avatarRoopa Prabhu <roopa@cumulusnetworks.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 51723935
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -54,6 +54,7 @@ struct nlmsghdr {
#define NLM_F_ACK		4	/* Reply with ack, with zero or error code */
#define NLM_F_ACK		4	/* Reply with ack, with zero or error code */
#define NLM_F_ECHO		8	/* Echo this request 		*/
#define NLM_F_ECHO		8	/* Echo this request 		*/
#define NLM_F_DUMP_INTR		16	/* Dump was inconsistent due to sequence change */
#define NLM_F_DUMP_INTR		16	/* Dump was inconsistent due to sequence change */
#define NLM_F_DUMP_FILTERED	32	/* Dump was filtered as requested */


/* Modifiers to GET request */
/* Modifiers to GET request */
#define NLM_F_ROOT	0x100	/* specify tree	root	*/
#define NLM_F_ROOT	0x100	/* specify tree	root	*/
+31 −1
Original line number Original line Diff line number Diff line
@@ -2235,14 +2235,42 @@ static void neigh_update_notify(struct neighbour *neigh)
	__neigh_notify(neigh, RTM_NEWNEIGH, 0);
	__neigh_notify(neigh, RTM_NEWNEIGH, 0);
}
}


static bool neigh_master_filtered(struct net_device *dev, int master_idx)
{
	struct net_device *master;

	if (!master_idx)
		return false;

	master = netdev_master_upper_dev_get(dev);
	if (!master || master->ifindex != master_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)
{
{
	struct net *net = sock_net(skb->sk);
	struct net *net = sock_net(skb->sk);
	const struct nlmsghdr *nlh = cb->nlh;
	struct nlattr *tb[NDA_MAX + 1];
	struct neighbour *n;
	struct neighbour *n;
	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;
	unsigned int flags = NLM_F_MULTI;
	int err;

	err = nlmsg_parse(nlh, sizeof(struct ndmsg), tb, NDA_MAX, NULL);
	if (!err) {
		if (tb[NDA_MASTER])
			filter_master_idx = nla_get_u32(tb[NDA_MASTER]);

		if (filter_master_idx)
			flags |= NLM_F_DUMP_FILTERED;
	}


	rcu_read_lock_bh();
	rcu_read_lock_bh();
	nht = rcu_dereference_bh(tbl->nht);
	nht = rcu_dereference_bh(tbl->nht);
@@ -2255,12 +2283,14 @@ 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_master_filtered(n->dev, filter_master_idx))
				continue;
			if (idx < s_idx)
			if (idx < s_idx)
				goto next;
				goto next;
			if (neigh_fill_info(skb, n, NETLINK_CB(cb->skb).portid,
			if (neigh_fill_info(skb, n, NETLINK_CB(cb->skb).portid,
					    cb->nlh->nlmsg_seq,
					    cb->nlh->nlmsg_seq,
					    RTM_NEWNEIGH,
					    RTM_NEWNEIGH,
					    NLM_F_MULTI) < 0) {
					    flags) < 0) {
				rc = -1;
				rc = -1;
				goto out;
				goto out;
			}
			}