aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Emelyanov <xemul@parallels.com>2011-12-29 19:53:13 -0500
committerDavid S. Miller <davem@davemloft.net>2011-12-30 16:42:19 -0500
commit5d2e5f274f9e9a06fb934dd45260e2616a9992e6 (patch)
tree61ae9157e41b00a19f58518d58d0c739393cbccb
parent288461e1546fa4162fa237eeed8ea09a16521dcd (diff)
sock_diag: Introduce the meminfo nla core (v2)
Add a routine that dumps memory-related values of a socket. It's made as an array to make it possible to add more stuff here later without breaking compatibility. Since v1: The SK_MEMINFO_ constants are in userspace visible part of sock_diag.h, the rest is under __KERNEL__. Signed-off-by: Pavel Emelyanov <xemul@parallels.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/linux/sock_diag.h15
-rw-r--r--net/core/sock_diag.c23
2 files changed, 38 insertions, 0 deletions
diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
index 66bc18ef4fa4..251729a47880 100644
--- a/include/linux/sock_diag.h
+++ b/include/linux/sock_diag.h
@@ -10,9 +10,22 @@ struct sock_diag_req {
10 __u8 sdiag_protocol; 10 __u8 sdiag_protocol;
11}; 11};
12 12
13enum {
14 SK_MEMINFO_RMEM_ALLOC,
15 SK_MEMINFO_RCVBUF,
16 SK_MEMINFO_WMEM_ALLOC,
17 SK_MEMINFO_SNDBUF,
18 SK_MEMINFO_FWD_ALLOC,
19 SK_MEMINFO_WMEM_QUEUED,
20 SK_MEMINFO_OPTMEM,
21
22 SK_MEMINFO_VARS,
23};
24
13#ifdef __KERNEL__ 25#ifdef __KERNEL__
14struct sk_buff; 26struct sk_buff;
15struct nlmsghdr; 27struct nlmsghdr;
28struct sock;
16 29
17struct sock_diag_handler { 30struct sock_diag_handler {
18 __u8 family; 31 __u8 family;
@@ -28,6 +41,8 @@ void sock_diag_unregister_inet_compat(int (*fn)(struct sk_buff *skb, struct nlms
28int sock_diag_check_cookie(void *sk, __u32 *cookie); 41int sock_diag_check_cookie(void *sk, __u32 *cookie);
29void sock_diag_save_cookie(void *sk, __u32 *cookie); 42void sock_diag_save_cookie(void *sk, __u32 *cookie);
30 43
44int sock_diag_put_meminfo(struct sock *sk, struct sk_buff *skb, int attr);
45
31extern struct sock *sock_diag_nlsk; 46extern struct sock *sock_diag_nlsk;
32#endif /* KERNEL */ 47#endif /* KERNEL */
33#endif 48#endif
diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
index 711bdefe7753..b9868e1fd62c 100644
--- a/net/core/sock_diag.c
+++ b/net/core/sock_diag.c
@@ -4,6 +4,8 @@
4#include <net/netlink.h> 4#include <net/netlink.h>
5#include <net/net_namespace.h> 5#include <net/net_namespace.h>
6#include <linux/module.h> 6#include <linux/module.h>
7#include <linux/rtnetlink.h>
8#include <net/sock.h>
7 9
8#include <linux/inet_diag.h> 10#include <linux/inet_diag.h>
9#include <linux/sock_diag.h> 11#include <linux/sock_diag.h>
@@ -31,6 +33,27 @@ void sock_diag_save_cookie(void *sk, __u32 *cookie)
31} 33}
32EXPORT_SYMBOL_GPL(sock_diag_save_cookie); 34EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
33 35
36int sock_diag_put_meminfo(struct sock *sk, struct sk_buff *skb, int attrtype)
37{
38 __u32 *mem;
39
40 mem = RTA_DATA(__RTA_PUT(skb, attrtype, SK_MEMINFO_VARS * sizeof(__u32)));
41
42 mem[SK_MEMINFO_RMEM_ALLOC] = sk_rmem_alloc_get(sk);
43 mem[SK_MEMINFO_RCVBUF] = sk->sk_rcvbuf;
44 mem[SK_MEMINFO_WMEM_ALLOC] = sk_wmem_alloc_get(sk);
45 mem[SK_MEMINFO_SNDBUF] = sk->sk_sndbuf;
46 mem[SK_MEMINFO_FWD_ALLOC] = sk->sk_forward_alloc;
47 mem[SK_MEMINFO_WMEM_QUEUED] = sk->sk_wmem_queued;
48 mem[SK_MEMINFO_OPTMEM] = atomic_read(&sk->sk_omem_alloc);
49
50 return 0;
51
52rtattr_failure:
53 return -EMSGSIZE;
54}
55EXPORT_SYMBOL_GPL(sock_diag_put_meminfo);
56
34void sock_diag_register_inet_compat(int (*fn)(struct sk_buff *skb, struct nlmsghdr *nlh)) 57void sock_diag_register_inet_compat(int (*fn)(struct sk_buff *skb, struct nlmsghdr *nlh))
35{ 58{
36 mutex_lock(&sock_diag_table_mutex); 59 mutex_lock(&sock_diag_table_mutex);