1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36#include "core.h"
37#include "socket.h"
38#include <linux/sock_diag.h>
39#include <linux/tipc_sockets_diag.h>
40
41static u64 __tipc_diag_gen_cookie(struct sock *sk)
42{
43 u32 res[2];
44
45 sock_diag_save_cookie(sk, res);
46 return *((u64 *)res);
47}
48
49static int __tipc_add_sock_diag(struct sk_buff *skb,
50 struct netlink_callback *cb,
51 struct tipc_sock *tsk)
52{
53 struct tipc_sock_diag_req *req = nlmsg_data(cb->nlh);
54 struct nlmsghdr *nlh;
55 int err;
56
57 nlh = nlmsg_put_answer(skb, cb, SOCK_DIAG_BY_FAMILY, 0,
58 NLM_F_MULTI);
59 if (!nlh)
60 return -EMSGSIZE;
61
62 err = tipc_sk_fill_sock_diag(skb, cb, tsk, req->tidiag_states,
63 __tipc_diag_gen_cookie);
64 if (err)
65 return err;
66
67 nlmsg_end(skb, nlh);
68 return 0;
69}
70
71static int tipc_diag_dump(struct sk_buff *skb, struct netlink_callback *cb)
72{
73 return tipc_nl_sk_walk(skb, cb, __tipc_add_sock_diag);
74}
75
76static int tipc_sock_diag_handler_dump(struct sk_buff *skb,
77 struct nlmsghdr *h)
78{
79 int hdrlen = sizeof(struct tipc_sock_diag_req);
80 struct net *net = sock_net(skb->sk);
81
82 if (nlmsg_len(h) < hdrlen)
83 return -EINVAL;
84
85 if (h->nlmsg_flags & NLM_F_DUMP) {
86 struct netlink_dump_control c = {
87 .start = tipc_dump_start,
88 .dump = tipc_diag_dump,
89 .done = tipc_dump_done,
90 };
91 netlink_dump_start(net->diag_nlsk, skb, h, &c);
92 return 0;
93 }
94 return -EOPNOTSUPP;
95}
96
97static const struct sock_diag_handler tipc_sock_diag_handler = {
98 .family = AF_TIPC,
99 .dump = tipc_sock_diag_handler_dump,
100};
101
102static int __init tipc_diag_init(void)
103{
104 return sock_diag_register(&tipc_sock_diag_handler);
105}
106
107static void __exit tipc_diag_exit(void)
108{
109 sock_diag_unregister(&tipc_sock_diag_handler);
110}
111
112module_init(tipc_diag_init);
113module_exit(tipc_diag_exit);
114
115MODULE_LICENSE("Dual BSD/GPL");
116MODULE_ALIAS_NET_PF_PROTO_TYPE(PF_NETLINK, NETLINK_SOCK_DIAG, AF_TIPC);
117