Commit b613f56e authored by Lorenzo Colitti's avatar Lorenzo Colitti Committed by David S. Miller

net: diag: split inet_diag_dump_one_icsk into two

Currently, inet_diag_dump_one_icsk finds a socket and then dumps
its information to userspace. Split it into a part that finds the
socket and a part that dumps the information.
Signed-off-by: default avatarLorenzo Colitti <lorenzo@google.com>
Acked-by: default avatarEric Dumazet <edumazet@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent fec65bd4
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <uapi/linux/inet_diag.h> #include <uapi/linux/inet_diag.h>
struct net;
struct sock; struct sock;
struct inet_hashinfo; struct inet_hashinfo;
struct nlattr; struct nlattr;
...@@ -41,6 +42,10 @@ int inet_diag_dump_one_icsk(struct inet_hashinfo *hashinfo, ...@@ -41,6 +42,10 @@ int inet_diag_dump_one_icsk(struct inet_hashinfo *hashinfo,
struct sk_buff *in_skb, const struct nlmsghdr *nlh, struct sk_buff *in_skb, const struct nlmsghdr *nlh,
const struct inet_diag_req_v2 *req); const struct inet_diag_req_v2 *req);
struct sock *inet_diag_find_one_icsk(struct net *net,
struct inet_hashinfo *hashinfo,
const struct inet_diag_req_v2 *req);
int inet_diag_bc_sk(const struct nlattr *_bc, struct sock *sk); int inet_diag_bc_sk(const struct nlattr *_bc, struct sock *sk);
extern int inet_diag_register(const struct inet_diag_handler *handler); extern int inet_diag_register(const struct inet_diag_handler *handler);
......
...@@ -350,17 +350,12 @@ static int sk_diag_fill(struct sock *sk, struct sk_buff *skb, ...@@ -350,17 +350,12 @@ static int sk_diag_fill(struct sock *sk, struct sk_buff *skb,
nlmsg_flags, unlh); nlmsg_flags, unlh);
} }
int inet_diag_dump_one_icsk(struct inet_hashinfo *hashinfo, struct sock *inet_diag_find_one_icsk(struct net *net,
struct sk_buff *in_skb, struct inet_hashinfo *hashinfo,
const struct nlmsghdr *nlh, const struct inet_diag_req_v2 *req)
const struct inet_diag_req_v2 *req)
{ {
struct net *net = sock_net(in_skb->sk);
struct sk_buff *rep;
struct sock *sk; struct sock *sk;
int err;
err = -EINVAL;
if (req->sdiag_family == AF_INET) if (req->sdiag_family == AF_INET)
sk = inet_lookup(net, hashinfo, req->id.idiag_dst[0], sk = inet_lookup(net, hashinfo, req->id.idiag_dst[0],
req->id.idiag_dport, req->id.idiag_src[0], req->id.idiag_dport, req->id.idiag_src[0],
...@@ -375,15 +370,33 @@ int inet_diag_dump_one_icsk(struct inet_hashinfo *hashinfo, ...@@ -375,15 +370,33 @@ int inet_diag_dump_one_icsk(struct inet_hashinfo *hashinfo,
req->id.idiag_if); req->id.idiag_if);
#endif #endif
else else
goto out_nosk; return ERR_PTR(-EINVAL);
err = -ENOENT;
if (!sk) if (!sk)
goto out_nosk; return ERR_PTR(-ENOENT);
err = sock_diag_check_cookie(sk, req->id.idiag_cookie); if (sock_diag_check_cookie(sk, req->id.idiag_cookie)) {
if (err) sock_gen_put(sk);
goto out; return ERR_PTR(-ENOENT);
}
return sk;
}
EXPORT_SYMBOL_GPL(inet_diag_find_one_icsk);
int inet_diag_dump_one_icsk(struct inet_hashinfo *hashinfo,
struct sk_buff *in_skb,
const struct nlmsghdr *nlh,
const struct inet_diag_req_v2 *req)
{
struct net *net = sock_net(in_skb->sk);
struct sk_buff *rep;
struct sock *sk;
int err;
sk = inet_diag_find_one_icsk(net, hashinfo, req);
if (IS_ERR(sk))
return PTR_ERR(sk);
rep = nlmsg_new(inet_sk_attr_size(), GFP_KERNEL); rep = nlmsg_new(inet_sk_attr_size(), GFP_KERNEL);
if (!rep) { if (!rep) {
...@@ -409,7 +422,6 @@ int inet_diag_dump_one_icsk(struct inet_hashinfo *hashinfo, ...@@ -409,7 +422,6 @@ int inet_diag_dump_one_icsk(struct inet_hashinfo *hashinfo,
if (sk) if (sk)
sock_gen_put(sk); sock_gen_put(sk);
out_nosk:
return err; return err;
} }
EXPORT_SYMBOL_GPL(inet_diag_dump_one_icsk); EXPORT_SYMBOL_GPL(inet_diag_dump_one_icsk);
......
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