Skip to content

Commit a925aa0

Browse files
xemuldavem330
authored andcommitted
udp_diag: Implement the get_exact dumping functionality
Do the same as TCP does -- lookup a socket in the given udp_table, check cookie, fill the reply message with existing inet socket dumping helper and send one back. Signed-off-by: Pavel Emelyanov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 52b7c59 commit a925aa0

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

net/ipv4/udp_diag.c

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,57 @@
2121
static int udp_dump_one(struct udp_table *tbl, struct sk_buff *in_skb,
2222
const struct nlmsghdr *nlh, struct inet_diag_req *req)
2323
{
24-
return 0;
24+
int err = -EINVAL;
25+
struct sock *sk;
26+
struct sk_buff *rep;
27+
28+
if (req->sdiag_family == AF_INET)
29+
sk = __udp4_lib_lookup(&init_net,
30+
req->id.idiag_src[0], req->id.idiag_sport,
31+
req->id.idiag_dst[0], req->id.idiag_dport,
32+
req->id.idiag_if, tbl);
33+
else if (req->sdiag_family == AF_INET6)
34+
sk = __udp6_lib_lookup(&init_net,
35+
(struct in6_addr *)req->id.idiag_src,
36+
req->id.idiag_sport,
37+
(struct in6_addr *)req->id.idiag_dst,
38+
req->id.idiag_dport,
39+
req->id.idiag_if, tbl);
40+
else
41+
goto out_nosk;
42+
43+
err = -ENOENT;
44+
if (sk == NULL)
45+
goto out_nosk;
46+
47+
err = inet_diag_check_cookie(sk, req);
48+
if (err)
49+
goto out;
50+
51+
err = -ENOMEM;
52+
rep = alloc_skb(NLMSG_SPACE((sizeof(struct inet_diag_msg) +
53+
sizeof(struct inet_diag_meminfo) +
54+
64)), GFP_KERNEL);
55+
if (!rep)
56+
goto out;
57+
58+
err = inet_sk_diag_fill(sk, NULL, rep, req,
59+
NETLINK_CB(in_skb).pid,
60+
nlh->nlmsg_seq, 0, nlh);
61+
if (err < 0) {
62+
WARN_ON(err == -EMSGSIZE);
63+
kfree_skb(rep);
64+
goto out;
65+
}
66+
err = netlink_unicast(sock_diag_nlsk, rep, NETLINK_CB(in_skb).pid,
67+
MSG_DONTWAIT);
68+
if (err > 0)
69+
err = 0;
70+
out:
71+
if (sk)
72+
sock_put(sk);
73+
out_nosk:
74+
return err;
2575
}
2676

2777
static void udp_dump(struct udp_table *table, struct sk_buff *skb, struct netlink_callback *cb,

0 commit comments

Comments
 (0)