Commit 7e4975f7 authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller
Browse files

neighbour: fix neigh_dump_info() return value



Change neigh_dump_table() and pneigh_dump_table()
to either return 0 or -EMSGSIZE if not enough
space was available in the skb.

Then neigh_dump_info() can do the same.

This allows NLMSG_DONE to be appended to the current
skb at the end of a dump, saving a couple of recvmsg()
system calls.

Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent f8f2eb9d
Loading
Loading
Loading
Loading
+13 −18
Original line number Diff line number Diff line
@@ -2715,7 +2715,7 @@ static int neigh_dump_table(struct neigh_table *tbl, struct sk_buff *skb,
{
	struct net *net = sock_net(skb->sk);
	struct neighbour *n;
	int rc, h, s_h = cb->args[1];
	int err = 0, h, s_h = cb->args[1];
	int idx, s_idx = idx = cb->args[2];
	struct neigh_hash_table *nht;
	unsigned int flags = NLM_F_MULTI;
@@ -2737,23 +2737,20 @@ static int neigh_dump_table(struct neigh_table *tbl, struct sk_buff *skb,
			if (neigh_ifindex_filtered(n->dev, filter->dev_idx) ||
			    neigh_master_filtered(n->dev, filter->master_idx))
				goto next;
			if (neigh_fill_info(skb, n, NETLINK_CB(cb->skb).portid,
			err = neigh_fill_info(skb, n, NETLINK_CB(cb->skb).portid,
					      cb->nlh->nlmsg_seq,
					    RTM_NEWNEIGH,
					    flags) < 0) {
				rc = -1;
					      RTM_NEWNEIGH, flags);
			if (err < 0)
				goto out;
			}
next:
			idx++;
		}
	}
	rc = skb->len;
out:
	rcu_read_unlock();
	cb->args[1] = h;
	cb->args[2] = idx;
	return rc;
	return err;
}

static int pneigh_dump_table(struct neigh_table *tbl, struct sk_buff *skb,
@@ -2762,7 +2759,7 @@ static int pneigh_dump_table(struct neigh_table *tbl, struct sk_buff *skb,
{
	struct pneigh_entry *n;
	struct net *net = sock_net(skb->sk);
	int rc, h, s_h = cb->args[3];
	int err = 0, h, s_h = cb->args[3];
	int idx, s_idx = idx = cb->args[4];
	unsigned int flags = NLM_F_MULTI;

@@ -2780,11 +2777,11 @@ static int pneigh_dump_table(struct neigh_table *tbl, struct sk_buff *skb,
			if (neigh_ifindex_filtered(n->dev, filter->dev_idx) ||
			    neigh_master_filtered(n->dev, filter->master_idx))
				goto next;
			if (pneigh_fill_info(skb, n, NETLINK_CB(cb->skb).portid,
			err = pneigh_fill_info(skb, n, NETLINK_CB(cb->skb).portid,
					       cb->nlh->nlmsg_seq,
					    RTM_NEWNEIGH, flags, tbl) < 0) {
					       RTM_NEWNEIGH, flags, tbl);
			if (err < 0) {
				read_unlock_bh(&tbl->lock);
				rc = -1;
				goto out;
			}
		next:
@@ -2793,12 +2790,10 @@ static int pneigh_dump_table(struct neigh_table *tbl, struct sk_buff *skb,
	}

	read_unlock_bh(&tbl->lock);
	rc = skb->len;
out:
	cb->args[3] = h;
	cb->args[4] = idx;
	return rc;

	return err;
}

static int neigh_valid_dump_req(const struct nlmsghdr *nlh,
@@ -2905,7 +2900,7 @@ static int neigh_dump_info(struct sk_buff *skb, struct netlink_callback *cb)
	}

	cb->args[0] = t;
	return skb->len;
	return err;
}

static int neigh_valid_get_req(const struct nlmsghdr *nlh,