Commit 5fcd266a authored by David Ahern's avatar David Ahern Committed by David S. Miller

net/ipv4: Add support for dumping addresses for a specific device

If an RTM_GETADDR dump request has ifa_index set in the ifaddrmsg
header, then return only the addresses for that device.
Signed-off-by: default avatarDavid Ahern <dsahern@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent fe884c2b
...@@ -109,6 +109,7 @@ struct inet_fill_args { ...@@ -109,6 +109,7 @@ struct inet_fill_args {
int event; int event;
unsigned int flags; unsigned int flags;
int netnsid; int netnsid;
int ifindex;
}; };
#define IN4_ADDR_HSIZE_SHIFT 8 #define IN4_ADDR_HSIZE_SHIFT 8
...@@ -1663,8 +1664,9 @@ static int inet_fill_ifaddr(struct sk_buff *skb, struct in_ifaddr *ifa, ...@@ -1663,8 +1664,9 @@ static int inet_fill_ifaddr(struct sk_buff *skb, struct in_ifaddr *ifa,
static int inet_valid_dump_ifaddr_req(const struct nlmsghdr *nlh, static int inet_valid_dump_ifaddr_req(const struct nlmsghdr *nlh,
struct inet_fill_args *fillargs, struct inet_fill_args *fillargs,
struct net **tgt_net, struct sock *sk, struct net **tgt_net, struct sock *sk,
struct netlink_ext_ack *extack) struct netlink_callback *cb)
{ {
struct netlink_ext_ack *extack = cb->extack;
struct nlattr *tb[IFA_MAX+1]; struct nlattr *tb[IFA_MAX+1];
struct ifaddrmsg *ifm; struct ifaddrmsg *ifm;
int err, i; int err, i;
...@@ -1679,9 +1681,11 @@ static int inet_valid_dump_ifaddr_req(const struct nlmsghdr *nlh, ...@@ -1679,9 +1681,11 @@ static int inet_valid_dump_ifaddr_req(const struct nlmsghdr *nlh,
NL_SET_ERR_MSG(extack, "ipv4: Invalid values in header for address dump request"); NL_SET_ERR_MSG(extack, "ipv4: Invalid values in header for address dump request");
return -EINVAL; return -EINVAL;
} }
if (ifm->ifa_index) {
NL_SET_ERR_MSG(extack, "ipv4: Filter by device index not supported for address dump"); fillargs->ifindex = ifm->ifa_index;
return -EINVAL; if (fillargs->ifindex) {
cb->answer_flags |= NLM_F_DUMP_FILTERED;
fillargs->flags |= NLM_F_DUMP_FILTERED;
} }
err = nlmsg_parse_strict(nlh, sizeof(*ifm), tb, IFA_MAX, err = nlmsg_parse_strict(nlh, sizeof(*ifm), tb, IFA_MAX,
...@@ -1765,9 +1769,22 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb) ...@@ -1765,9 +1769,22 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
if (cb->strict_check) { if (cb->strict_check) {
err = inet_valid_dump_ifaddr_req(nlh, &fillargs, &tgt_net, err = inet_valid_dump_ifaddr_req(nlh, &fillargs, &tgt_net,
skb->sk, cb->extack); skb->sk, cb);
if (err < 0) if (err < 0)
return err; return err;
if (fillargs.ifindex) {
dev = __dev_get_by_index(tgt_net, fillargs.ifindex);
if (!dev)
return -ENODEV;
in_dev = __in_dev_get_rtnl(dev);
if (in_dev) {
err = in_dev_dump_addr(in_dev, skb, cb, s_ip_idx,
&fillargs);
}
goto put_tgt_net;
}
} }
for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) { for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
...@@ -1800,6 +1817,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb) ...@@ -1800,6 +1817,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
done: done:
cb->args[0] = h; cb->args[0] = h;
cb->args[1] = idx; cb->args[1] = idx;
put_tgt_net:
if (fillargs.netnsid >= 0) if (fillargs.netnsid >= 0)
put_net(tgt_net); put_net(tgt_net);
......
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