diff options
Diffstat (limited to 'net/core/sock_diag.c')
-rw-r--r-- | net/core/sock_diag.c | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c index 5fd146720f3..9d8755e4a7a 100644 --- a/net/core/sock_diag.c +++ b/net/core/sock_diag.c | |||
@@ -4,7 +4,6 @@ | |||
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 | #include <net/sock.h> |
9 | 8 | ||
10 | #include <linux/inet_diag.h> | 9 | #include <linux/inet_diag.h> |
@@ -35,9 +34,7 @@ EXPORT_SYMBOL_GPL(sock_diag_save_cookie); | |||
35 | 34 | ||
36 | int sock_diag_put_meminfo(struct sock *sk, struct sk_buff *skb, int attrtype) | 35 | int sock_diag_put_meminfo(struct sock *sk, struct sk_buff *skb, int attrtype) |
37 | { | 36 | { |
38 | __u32 *mem; | 37 | u32 mem[SK_MEMINFO_VARS]; |
39 | |||
40 | mem = RTA_DATA(__RTA_PUT(skb, attrtype, SK_MEMINFO_VARS * sizeof(__u32))); | ||
41 | 38 | ||
42 | mem[SK_MEMINFO_RMEM_ALLOC] = sk_rmem_alloc_get(sk); | 39 | mem[SK_MEMINFO_RMEM_ALLOC] = sk_rmem_alloc_get(sk); |
43 | mem[SK_MEMINFO_RCVBUF] = sk->sk_rcvbuf; | 40 | mem[SK_MEMINFO_RCVBUF] = sk->sk_rcvbuf; |
@@ -46,11 +43,9 @@ int sock_diag_put_meminfo(struct sock *sk, struct sk_buff *skb, int attrtype) | |||
46 | mem[SK_MEMINFO_FWD_ALLOC] = sk->sk_forward_alloc; | 43 | mem[SK_MEMINFO_FWD_ALLOC] = sk->sk_forward_alloc; |
47 | mem[SK_MEMINFO_WMEM_QUEUED] = sk->sk_wmem_queued; | 44 | mem[SK_MEMINFO_WMEM_QUEUED] = sk->sk_wmem_queued; |
48 | mem[SK_MEMINFO_OPTMEM] = atomic_read(&sk->sk_omem_alloc); | 45 | mem[SK_MEMINFO_OPTMEM] = atomic_read(&sk->sk_omem_alloc); |
46 | mem[SK_MEMINFO_BACKLOG] = sk->sk_backlog.len; | ||
49 | 47 | ||
50 | return 0; | 48 | return nla_put(skb, attrtype, sizeof(mem), &mem); |
51 | |||
52 | rtattr_failure: | ||
53 | return -EMSGSIZE; | ||
54 | } | 49 | } |
55 | EXPORT_SYMBOL_GPL(sock_diag_put_meminfo); | 50 | EXPORT_SYMBOL_GPL(sock_diag_put_meminfo); |
56 | 51 | ||
@@ -120,7 +115,7 @@ static inline void sock_diag_unlock_handler(const struct sock_diag_handler *h) | |||
120 | static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh) | 115 | static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh) |
121 | { | 116 | { |
122 | int err; | 117 | int err; |
123 | struct sock_diag_req *req = NLMSG_DATA(nlh); | 118 | struct sock_diag_req *req = nlmsg_data(nlh); |
124 | const struct sock_diag_handler *hndl; | 119 | const struct sock_diag_handler *hndl; |
125 | 120 | ||
126 | if (nlmsg_len(nlh) < sizeof(*req)) | 121 | if (nlmsg_len(nlh) < sizeof(*req)) |
@@ -171,19 +166,36 @@ static void sock_diag_rcv(struct sk_buff *skb) | |||
171 | mutex_unlock(&sock_diag_mutex); | 166 | mutex_unlock(&sock_diag_mutex); |
172 | } | 167 | } |
173 | 168 | ||
174 | struct sock *sock_diag_nlsk; | 169 | static int __net_init diag_net_init(struct net *net) |
175 | EXPORT_SYMBOL_GPL(sock_diag_nlsk); | 170 | { |
171 | struct netlink_kernel_cfg cfg = { | ||
172 | .input = sock_diag_rcv, | ||
173 | }; | ||
174 | |||
175 | net->diag_nlsk = netlink_kernel_create(net, NETLINK_SOCK_DIAG, | ||
176 | THIS_MODULE, &cfg); | ||
177 | return net->diag_nlsk == NULL ? -ENOMEM : 0; | ||
178 | } | ||
179 | |||
180 | static void __net_exit diag_net_exit(struct net *net) | ||
181 | { | ||
182 | netlink_kernel_release(net->diag_nlsk); | ||
183 | net->diag_nlsk = NULL; | ||
184 | } | ||
185 | |||
186 | static struct pernet_operations diag_net_ops = { | ||
187 | .init = diag_net_init, | ||
188 | .exit = diag_net_exit, | ||
189 | }; | ||
176 | 190 | ||
177 | static int __init sock_diag_init(void) | 191 | static int __init sock_diag_init(void) |
178 | { | 192 | { |
179 | sock_diag_nlsk = netlink_kernel_create(&init_net, NETLINK_SOCK_DIAG, 0, | 193 | return register_pernet_subsys(&diag_net_ops); |
180 | sock_diag_rcv, NULL, THIS_MODULE); | ||
181 | return sock_diag_nlsk == NULL ? -ENOMEM : 0; | ||
182 | } | 194 | } |
183 | 195 | ||
184 | static void __exit sock_diag_exit(void) | 196 | static void __exit sock_diag_exit(void) |
185 | { | 197 | { |
186 | netlink_kernel_release(sock_diag_nlsk); | 198 | unregister_pernet_subsys(&diag_net_ops); |
187 | } | 199 | } |
188 | 200 | ||
189 | module_init(sock_diag_init); | 201 | module_init(sock_diag_init); |