Commit 22931d3b906cd0a1726a49a09713f9220a5fab8a
Committed by
David S. Miller
1 parent
fa7ff56f75
Exists in
master
and in
38 other branches
unix_diag: Basic module skeleton
Includes basic module_init/_exit functionality, dump/get_exact stubs and declares the basic API structures for request and response. Signed-off-by: Pavel Emelyanov <xemul@parallels.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Showing 2 changed files with 81 additions and 0 deletions Side-by-side Diff
include/linux/unix_diag.h
1 | +#ifndef __UNIX_DIAG_H__ | |
2 | +#define __UNIX_DIAG_H__ | |
3 | + | |
4 | +struct unix_diag_req { | |
5 | + __u8 sdiag_family; | |
6 | + __u8 sdiag_protocol; | |
7 | + __u16 pad; | |
8 | + __u32 udiag_states; | |
9 | + __u32 udiag_ino; | |
10 | + __u32 udiag_show; | |
11 | + __u32 udiag_cookie[2]; | |
12 | +}; | |
13 | + | |
14 | +struct unix_diag_msg { | |
15 | + __u8 udiag_family; | |
16 | + __u8 udiag_type; | |
17 | + __u8 udiag_state; | |
18 | + __u8 pad; | |
19 | + | |
20 | + __u32 udiag_ino; | |
21 | + __u32 udiag_cookie[2]; | |
22 | +}; | |
23 | + | |
24 | +#endif |
net/unix/diag.c
1 | +#include <linux/types.h> | |
2 | +#include <linux/spinlock.h> | |
3 | +#include <linux/sock_diag.h> | |
4 | +#include <linux/unix_diag.h> | |
5 | +#include <linux/skbuff.h> | |
6 | +#include <net/netlink.h> | |
7 | +#include <net/af_unix.h> | |
8 | +#include <net/tcp_states.h> | |
9 | + | |
10 | +#define UNIX_DIAG_PUT(skb, attrtype, attrlen) \ | |
11 | + RTA_DATA(__RTA_PUT(skb, attrtype, attrlen)) | |
12 | + | |
13 | +static int unix_diag_dump(struct sk_buff *skb, struct netlink_callback *cb) | |
14 | +{ | |
15 | + return 0; | |
16 | +} | |
17 | + | |
18 | +static int unix_diag_get_exact(struct sk_buff *in_skb, | |
19 | + const struct nlmsghdr *nlh, | |
20 | + struct unix_diag_req *req) | |
21 | +{ | |
22 | + return -EAFNOSUPPORT; | |
23 | +} | |
24 | + | |
25 | +static int unix_diag_handler_dump(struct sk_buff *skb, struct nlmsghdr *h) | |
26 | +{ | |
27 | + int hdrlen = sizeof(struct unix_diag_req); | |
28 | + | |
29 | + if (nlmsg_len(h) < hdrlen) | |
30 | + return -EINVAL; | |
31 | + | |
32 | + if (h->nlmsg_flags & NLM_F_DUMP) | |
33 | + return netlink_dump_start(sock_diag_nlsk, skb, h, | |
34 | + unix_diag_dump, NULL, 0); | |
35 | + else | |
36 | + return unix_diag_get_exact(skb, h, (struct unix_diag_req *)NLMSG_DATA(h)); | |
37 | +} | |
38 | + | |
39 | +static struct sock_diag_handler unix_diag_handler = { | |
40 | + .family = AF_UNIX, | |
41 | + .dump = unix_diag_handler_dump, | |
42 | +}; | |
43 | + | |
44 | +static int __init unix_diag_init(void) | |
45 | +{ | |
46 | + return sock_diag_register(&unix_diag_handler); | |
47 | +} | |
48 | + | |
49 | +static void __exit unix_diag_exit(void) | |
50 | +{ | |
51 | + sock_diag_unregister(&unix_diag_handler); | |
52 | +} | |
53 | + | |
54 | +module_init(unix_diag_init); | |
55 | +module_exit(unix_diag_exit); | |
56 | +MODULE_LICENSE("GPL"); | |
57 | +MODULE_ALIAS_NET_PF_PROTO_TYPE(PF_NETLINK, NETLINK_SOCK_DIAG, 1 /* AF_LOCAL */); |