diff options
author | NeilBrown <neilb@suse.de> | 2012-08-01 06:40:02 -0400 |
---|---|---|
committer | NeilBrown <neilb@suse.de> | 2012-08-01 06:40:02 -0400 |
commit | bb181e2e48f8c85db08c9cb015cbba9618dbf05c (patch) | |
tree | 191bc24dd97bcb174535cc217af082f16da3b43d /net/unix/diag.c | |
parent | d57368afe63b3b7b45ce6c2b8c5276417935be2f (diff) | |
parent | c039c332f23e794deb6d6f37b9f07ff3b27fb2cf (diff) |
Merge commit 'c039c332f23e794deb6d6f37b9f07ff3b27fb2cf' into md
Pull in pre-requisites for adding raid10 support to dm-raid.
Diffstat (limited to 'net/unix/diag.c')
-rw-r--r-- | net/unix/diag.c | 115 |
1 files changed, 55 insertions, 60 deletions
diff --git a/net/unix/diag.c b/net/unix/diag.c index 47d3002737f5..750b13408449 100644 --- a/net/unix/diag.c +++ b/net/unix/diag.c | |||
@@ -8,40 +8,31 @@ | |||
8 | #include <net/af_unix.h> | 8 | #include <net/af_unix.h> |
9 | #include <net/tcp_states.h> | 9 | #include <net/tcp_states.h> |
10 | 10 | ||
11 | #define UNIX_DIAG_PUT(skb, attrtype, attrlen) \ | ||
12 | RTA_DATA(__RTA_PUT(skb, attrtype, attrlen)) | ||
13 | |||
14 | static int sk_diag_dump_name(struct sock *sk, struct sk_buff *nlskb) | 11 | static int sk_diag_dump_name(struct sock *sk, struct sk_buff *nlskb) |
15 | { | 12 | { |
16 | struct unix_address *addr = unix_sk(sk)->addr; | 13 | struct unix_address *addr = unix_sk(sk)->addr; |
17 | char *s; | ||
18 | |||
19 | if (addr) { | ||
20 | s = UNIX_DIAG_PUT(nlskb, UNIX_DIAG_NAME, addr->len - sizeof(short)); | ||
21 | memcpy(s, addr->name->sun_path, addr->len - sizeof(short)); | ||
22 | } | ||
23 | 14 | ||
24 | return 0; | 15 | if (!addr) |
16 | return 0; | ||
25 | 17 | ||
26 | rtattr_failure: | 18 | return nla_put(nlskb, UNIX_DIAG_NAME, addr->len - sizeof(short), |
27 | return -EMSGSIZE; | 19 | addr->name->sun_path); |
28 | } | 20 | } |
29 | 21 | ||
30 | static int sk_diag_dump_vfs(struct sock *sk, struct sk_buff *nlskb) | 22 | static int sk_diag_dump_vfs(struct sock *sk, struct sk_buff *nlskb) |
31 | { | 23 | { |
32 | struct dentry *dentry = unix_sk(sk)->path.dentry; | 24 | struct dentry *dentry = unix_sk(sk)->path.dentry; |
33 | struct unix_diag_vfs *uv; | ||
34 | 25 | ||
35 | if (dentry) { | 26 | if (dentry) { |
36 | uv = UNIX_DIAG_PUT(nlskb, UNIX_DIAG_VFS, sizeof(*uv)); | 27 | struct unix_diag_vfs uv = { |
37 | uv->udiag_vfs_ino = dentry->d_inode->i_ino; | 28 | .udiag_vfs_ino = dentry->d_inode->i_ino, |
38 | uv->udiag_vfs_dev = dentry->d_sb->s_dev; | 29 | .udiag_vfs_dev = dentry->d_sb->s_dev, |
30 | }; | ||
31 | |||
32 | return nla_put(nlskb, UNIX_DIAG_VFS, sizeof(uv), &uv); | ||
39 | } | 33 | } |
40 | 34 | ||
41 | return 0; | 35 | return 0; |
42 | |||
43 | rtattr_failure: | ||
44 | return -EMSGSIZE; | ||
45 | } | 36 | } |
46 | 37 | ||
47 | static int sk_diag_dump_peer(struct sock *sk, struct sk_buff *nlskb) | 38 | static int sk_diag_dump_peer(struct sock *sk, struct sk_buff *nlskb) |
@@ -56,24 +47,28 @@ static int sk_diag_dump_peer(struct sock *sk, struct sk_buff *nlskb) | |||
56 | unix_state_unlock(peer); | 47 | unix_state_unlock(peer); |
57 | sock_put(peer); | 48 | sock_put(peer); |
58 | 49 | ||
59 | RTA_PUT_U32(nlskb, UNIX_DIAG_PEER, ino); | 50 | return nla_put_u32(nlskb, UNIX_DIAG_PEER, ino); |
60 | } | 51 | } |
61 | 52 | ||
62 | return 0; | 53 | return 0; |
63 | rtattr_failure: | ||
64 | return -EMSGSIZE; | ||
65 | } | 54 | } |
66 | 55 | ||
67 | static int sk_diag_dump_icons(struct sock *sk, struct sk_buff *nlskb) | 56 | static int sk_diag_dump_icons(struct sock *sk, struct sk_buff *nlskb) |
68 | { | 57 | { |
69 | struct sk_buff *skb; | 58 | struct sk_buff *skb; |
59 | struct nlattr *attr; | ||
70 | u32 *buf; | 60 | u32 *buf; |
71 | int i; | 61 | int i; |
72 | 62 | ||
73 | if (sk->sk_state == TCP_LISTEN) { | 63 | if (sk->sk_state == TCP_LISTEN) { |
74 | spin_lock(&sk->sk_receive_queue.lock); | 64 | spin_lock(&sk->sk_receive_queue.lock); |
75 | buf = UNIX_DIAG_PUT(nlskb, UNIX_DIAG_ICONS, | 65 | |
76 | sk->sk_receive_queue.qlen * sizeof(u32)); | 66 | attr = nla_reserve(nlskb, UNIX_DIAG_ICONS, |
67 | sk->sk_receive_queue.qlen * sizeof(u32)); | ||
68 | if (!attr) | ||
69 | goto errout; | ||
70 | |||
71 | buf = nla_data(attr); | ||
77 | i = 0; | 72 | i = 0; |
78 | skb_queue_walk(&sk->sk_receive_queue, skb) { | 73 | skb_queue_walk(&sk->sk_receive_queue, skb) { |
79 | struct sock *req, *peer; | 74 | struct sock *req, *peer; |
@@ -94,43 +89,38 @@ static int sk_diag_dump_icons(struct sock *sk, struct sk_buff *nlskb) | |||
94 | 89 | ||
95 | return 0; | 90 | return 0; |
96 | 91 | ||
97 | rtattr_failure: | 92 | errout: |
98 | spin_unlock(&sk->sk_receive_queue.lock); | 93 | spin_unlock(&sk->sk_receive_queue.lock); |
99 | return -EMSGSIZE; | 94 | return -EMSGSIZE; |
100 | } | 95 | } |
101 | 96 | ||
102 | static int sk_diag_show_rqlen(struct sock *sk, struct sk_buff *nlskb) | 97 | static int sk_diag_show_rqlen(struct sock *sk, struct sk_buff *nlskb) |
103 | { | 98 | { |
104 | struct unix_diag_rqlen *rql; | 99 | struct unix_diag_rqlen rql; |
105 | |||
106 | rql = UNIX_DIAG_PUT(nlskb, UNIX_DIAG_RQLEN, sizeof(*rql)); | ||
107 | 100 | ||
108 | if (sk->sk_state == TCP_LISTEN) { | 101 | if (sk->sk_state == TCP_LISTEN) { |
109 | rql->udiag_rqueue = sk->sk_receive_queue.qlen; | 102 | rql.udiag_rqueue = sk->sk_receive_queue.qlen; |
110 | rql->udiag_wqueue = sk->sk_max_ack_backlog; | 103 | rql.udiag_wqueue = sk->sk_max_ack_backlog; |
111 | } else { | 104 | } else { |
112 | rql->udiag_rqueue = (__u32)unix_inq_len(sk); | 105 | rql.udiag_rqueue = (u32) unix_inq_len(sk); |
113 | rql->udiag_wqueue = (__u32)unix_outq_len(sk); | 106 | rql.udiag_wqueue = (u32) unix_outq_len(sk); |
114 | } | 107 | } |
115 | 108 | ||
116 | return 0; | 109 | return nla_put(nlskb, UNIX_DIAG_RQLEN, sizeof(rql), &rql); |
117 | |||
118 | rtattr_failure: | ||
119 | return -EMSGSIZE; | ||
120 | } | 110 | } |
121 | 111 | ||
122 | static int sk_diag_fill(struct sock *sk, struct sk_buff *skb, struct unix_diag_req *req, | 112 | static int sk_diag_fill(struct sock *sk, struct sk_buff *skb, struct unix_diag_req *req, |
123 | u32 pid, u32 seq, u32 flags, int sk_ino) | 113 | u32 pid, u32 seq, u32 flags, int sk_ino) |
124 | { | 114 | { |
125 | unsigned char *b = skb_tail_pointer(skb); | ||
126 | struct nlmsghdr *nlh; | 115 | struct nlmsghdr *nlh; |
127 | struct unix_diag_msg *rep; | 116 | struct unix_diag_msg *rep; |
128 | 117 | ||
129 | nlh = NLMSG_PUT(skb, pid, seq, SOCK_DIAG_BY_FAMILY, sizeof(*rep)); | 118 | nlh = nlmsg_put(skb, pid, seq, SOCK_DIAG_BY_FAMILY, sizeof(*rep), |
130 | nlh->nlmsg_flags = flags; | 119 | flags); |
131 | 120 | if (!nlh) | |
132 | rep = NLMSG_DATA(nlh); | 121 | return -EMSGSIZE; |
133 | 122 | ||
123 | rep = nlmsg_data(nlh); | ||
134 | rep->udiag_family = AF_UNIX; | 124 | rep->udiag_family = AF_UNIX; |
135 | rep->udiag_type = sk->sk_type; | 125 | rep->udiag_type = sk->sk_type; |
136 | rep->udiag_state = sk->sk_state; | 126 | rep->udiag_state = sk->sk_state; |
@@ -139,33 +129,32 @@ static int sk_diag_fill(struct sock *sk, struct sk_buff *skb, struct unix_diag_r | |||
139 | 129 | ||
140 | if ((req->udiag_show & UDIAG_SHOW_NAME) && | 130 | if ((req->udiag_show & UDIAG_SHOW_NAME) && |
141 | sk_diag_dump_name(sk, skb)) | 131 | sk_diag_dump_name(sk, skb)) |
142 | goto nlmsg_failure; | 132 | goto out_nlmsg_trim; |
143 | 133 | ||
144 | if ((req->udiag_show & UDIAG_SHOW_VFS) && | 134 | if ((req->udiag_show & UDIAG_SHOW_VFS) && |
145 | sk_diag_dump_vfs(sk, skb)) | 135 | sk_diag_dump_vfs(sk, skb)) |
146 | goto nlmsg_failure; | 136 | goto out_nlmsg_trim; |
147 | 137 | ||
148 | if ((req->udiag_show & UDIAG_SHOW_PEER) && | 138 | if ((req->udiag_show & UDIAG_SHOW_PEER) && |
149 | sk_diag_dump_peer(sk, skb)) | 139 | sk_diag_dump_peer(sk, skb)) |
150 | goto nlmsg_failure; | 140 | goto out_nlmsg_trim; |
151 | 141 | ||
152 | if ((req->udiag_show & UDIAG_SHOW_ICONS) && | 142 | if ((req->udiag_show & UDIAG_SHOW_ICONS) && |
153 | sk_diag_dump_icons(sk, skb)) | 143 | sk_diag_dump_icons(sk, skb)) |
154 | goto nlmsg_failure; | 144 | goto out_nlmsg_trim; |
155 | 145 | ||
156 | if ((req->udiag_show & UDIAG_SHOW_RQLEN) && | 146 | if ((req->udiag_show & UDIAG_SHOW_RQLEN) && |
157 | sk_diag_show_rqlen(sk, skb)) | 147 | sk_diag_show_rqlen(sk, skb)) |
158 | goto nlmsg_failure; | 148 | goto out_nlmsg_trim; |
159 | 149 | ||
160 | if ((req->udiag_show & UDIAG_SHOW_MEMINFO) && | 150 | if ((req->udiag_show & UDIAG_SHOW_MEMINFO) && |
161 | sock_diag_put_meminfo(sk, skb, UNIX_DIAG_MEMINFO)) | 151 | sock_diag_put_meminfo(sk, skb, UNIX_DIAG_MEMINFO)) |
162 | goto nlmsg_failure; | 152 | goto out_nlmsg_trim; |
163 | 153 | ||
164 | nlh->nlmsg_len = skb_tail_pointer(skb) - b; | 154 | return nlmsg_end(skb, nlh); |
165 | return skb->len; | ||
166 | 155 | ||
167 | nlmsg_failure: | 156 | out_nlmsg_trim: |
168 | nlmsg_trim(skb, b); | 157 | nlmsg_cancel(skb, nlh); |
169 | return -EMSGSIZE; | 158 | return -EMSGSIZE; |
170 | } | 159 | } |
171 | 160 | ||
@@ -188,19 +177,24 @@ static int unix_diag_dump(struct sk_buff *skb, struct netlink_callback *cb) | |||
188 | { | 177 | { |
189 | struct unix_diag_req *req; | 178 | struct unix_diag_req *req; |
190 | int num, s_num, slot, s_slot; | 179 | int num, s_num, slot, s_slot; |
180 | struct net *net = sock_net(skb->sk); | ||
191 | 181 | ||
192 | req = NLMSG_DATA(cb->nlh); | 182 | req = nlmsg_data(cb->nlh); |
193 | 183 | ||
194 | s_slot = cb->args[0]; | 184 | s_slot = cb->args[0]; |
195 | num = s_num = cb->args[1]; | 185 | num = s_num = cb->args[1]; |
196 | 186 | ||
197 | spin_lock(&unix_table_lock); | 187 | spin_lock(&unix_table_lock); |
198 | for (slot = s_slot; slot <= UNIX_HASH_SIZE; s_num = 0, slot++) { | 188 | for (slot = s_slot; |
189 | slot < ARRAY_SIZE(unix_socket_table); | ||
190 | s_num = 0, slot++) { | ||
199 | struct sock *sk; | 191 | struct sock *sk; |
200 | struct hlist_node *node; | 192 | struct hlist_node *node; |
201 | 193 | ||
202 | num = 0; | 194 | num = 0; |
203 | sk_for_each(sk, node, &unix_socket_table[slot]) { | 195 | sk_for_each(sk, node, &unix_socket_table[slot]) { |
196 | if (!net_eq(sock_net(sk), net)) | ||
197 | continue; | ||
204 | if (num < s_num) | 198 | if (num < s_num) |
205 | goto next; | 199 | goto next; |
206 | if (!(req->udiag_states & (1 << sk->sk_state))) | 200 | if (!(req->udiag_states & (1 << sk->sk_state))) |
@@ -228,7 +222,7 @@ static struct sock *unix_lookup_by_ino(int ino) | |||
228 | struct sock *sk; | 222 | struct sock *sk; |
229 | 223 | ||
230 | spin_lock(&unix_table_lock); | 224 | spin_lock(&unix_table_lock); |
231 | for (i = 0; i <= UNIX_HASH_SIZE; i++) { | 225 | for (i = 0; i < ARRAY_SIZE(unix_socket_table); i++) { |
232 | struct hlist_node *node; | 226 | struct hlist_node *node; |
233 | 227 | ||
234 | sk_for_each(sk, node, &unix_socket_table[i]) | 228 | sk_for_each(sk, node, &unix_socket_table[i]) |
@@ -252,6 +246,7 @@ static int unix_diag_get_exact(struct sk_buff *in_skb, | |||
252 | struct sock *sk; | 246 | struct sock *sk; |
253 | struct sk_buff *rep; | 247 | struct sk_buff *rep; |
254 | unsigned int extra_len; | 248 | unsigned int extra_len; |
249 | struct net *net = sock_net(in_skb->sk); | ||
255 | 250 | ||
256 | if (req->udiag_ino == 0) | 251 | if (req->udiag_ino == 0) |
257 | goto out_nosk; | 252 | goto out_nosk; |
@@ -268,22 +263,21 @@ static int unix_diag_get_exact(struct sk_buff *in_skb, | |||
268 | extra_len = 256; | 263 | extra_len = 256; |
269 | again: | 264 | again: |
270 | err = -ENOMEM; | 265 | err = -ENOMEM; |
271 | rep = alloc_skb(NLMSG_SPACE((sizeof(struct unix_diag_msg) + extra_len)), | 266 | rep = nlmsg_new(sizeof(struct unix_diag_msg) + extra_len, GFP_KERNEL); |
272 | GFP_KERNEL); | ||
273 | if (!rep) | 267 | if (!rep) |
274 | goto out; | 268 | goto out; |
275 | 269 | ||
276 | err = sk_diag_fill(sk, rep, req, NETLINK_CB(in_skb).pid, | 270 | err = sk_diag_fill(sk, rep, req, NETLINK_CB(in_skb).pid, |
277 | nlh->nlmsg_seq, 0, req->udiag_ino); | 271 | nlh->nlmsg_seq, 0, req->udiag_ino); |
278 | if (err < 0) { | 272 | if (err < 0) { |
279 | kfree_skb(rep); | 273 | nlmsg_free(rep); |
280 | extra_len += 256; | 274 | extra_len += 256; |
281 | if (extra_len >= PAGE_SIZE) | 275 | if (extra_len >= PAGE_SIZE) |
282 | goto out; | 276 | goto out; |
283 | 277 | ||
284 | goto again; | 278 | goto again; |
285 | } | 279 | } |
286 | err = netlink_unicast(sock_diag_nlsk, rep, NETLINK_CB(in_skb).pid, | 280 | err = netlink_unicast(net->diag_nlsk, rep, NETLINK_CB(in_skb).pid, |
287 | MSG_DONTWAIT); | 281 | MSG_DONTWAIT); |
288 | if (err > 0) | 282 | if (err > 0) |
289 | err = 0; | 283 | err = 0; |
@@ -297,6 +291,7 @@ out_nosk: | |||
297 | static int unix_diag_handler_dump(struct sk_buff *skb, struct nlmsghdr *h) | 291 | static int unix_diag_handler_dump(struct sk_buff *skb, struct nlmsghdr *h) |
298 | { | 292 | { |
299 | int hdrlen = sizeof(struct unix_diag_req); | 293 | int hdrlen = sizeof(struct unix_diag_req); |
294 | struct net *net = sock_net(skb->sk); | ||
300 | 295 | ||
301 | if (nlmsg_len(h) < hdrlen) | 296 | if (nlmsg_len(h) < hdrlen) |
302 | return -EINVAL; | 297 | return -EINVAL; |
@@ -305,9 +300,9 @@ static int unix_diag_handler_dump(struct sk_buff *skb, struct nlmsghdr *h) | |||
305 | struct netlink_dump_control c = { | 300 | struct netlink_dump_control c = { |
306 | .dump = unix_diag_dump, | 301 | .dump = unix_diag_dump, |
307 | }; | 302 | }; |
308 | return netlink_dump_start(sock_diag_nlsk, skb, h, &c); | 303 | return netlink_dump_start(net->diag_nlsk, skb, h, &c); |
309 | } else | 304 | } else |
310 | return unix_diag_get_exact(skb, h, (struct unix_diag_req *)NLMSG_DATA(h)); | 305 | return unix_diag_get_exact(skb, h, nlmsg_data(h)); |
311 | } | 306 | } |
312 | 307 | ||
313 | static const struct sock_diag_handler unix_diag_handler = { | 308 | static const struct sock_diag_handler unix_diag_handler = { |