Commit ac14ad97 authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller

ipv6: use xarray iterator to implement inet6_dump_ifinfo()

Prepare inet6_dump_ifinfo() to run with RCU protection
instead of RTNL and use for_each_netdev_dump() interface.

Also properly return 0 at the end of a dump, avoiding
an extra recvmsg() system call and RTNL acquisition.

Note that RTNL-less dumps need core changes, coming later
in the series.
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Reviewed-by: default avatarIdo Schimmel <idosch@nvidia.com>
Reviewed-by: default avatarDonald Hunter <donald.hunter@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 8afc7a78
......@@ -6132,50 +6132,42 @@ static int inet6_valid_dump_ifinfo(const struct nlmsghdr *nlh,
static int inet6_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
{
struct net *net = sock_net(skb->sk);
int h, s_h;
int idx = 0, s_idx;
struct {
unsigned long ifindex;
} *ctx = (void *)cb->ctx;
struct net_device *dev;
struct inet6_dev *idev;
struct hlist_head *head;
int err;
/* only requests using strict checking can pass data to
* influence the dump
*/
if (cb->strict_check) {
int err = inet6_valid_dump_ifinfo(cb->nlh, cb->extack);
err = inet6_valid_dump_ifinfo(cb->nlh, cb->extack);
if (err < 0)
return err;
}
s_h = cb->args[0];
s_idx = cb->args[1];
err = 0;
rcu_read_lock();
for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
idx = 0;
head = &net->dev_index_head[h];
hlist_for_each_entry_rcu(dev, head, index_hlist) {
if (idx < s_idx)
goto cont;
idev = __in6_dev_get(dev);
if (!idev)
goto cont;
if (inet6_fill_ifinfo(skb, idev,
NETLINK_CB(cb->skb).portid,
cb->nlh->nlmsg_seq,
RTM_NEWLINK, NLM_F_MULTI) < 0)
goto out;
cont:
idx++;
for_each_netdev_dump(net, dev, ctx->ifindex) {
idev = __in6_dev_get(dev);
if (!idev)
continue;
err = inet6_fill_ifinfo(skb, idev,
NETLINK_CB(cb->skb).portid,
cb->nlh->nlmsg_seq,
RTM_NEWLINK, NLM_F_MULTI);
if (err < 0) {
if (likely(skb->len))
err = skb->len;
break;
}
}
out:
rcu_read_unlock();
cb->args[1] = idx;
cb->args[0] = h;
return skb->len;
return err;
}
void inet6_ifinfo_notify(int event, struct inet6_dev *idev)
......
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