Commit | Line | Data |
---|---|---|
ec26815a | 1 | /* AFS Cache Manager Service |
1da177e4 LT |
2 | * |
3 | * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved. | |
4 | * Written by David Howells (dhowells@redhat.com) | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU General Public License | |
8 | * as published by the Free Software Foundation; either version | |
9 | * 2 of the License, or (at your option) any later version. | |
10 | */ | |
11 | ||
12 | #include <linux/module.h> | |
13 | #include <linux/init.h> | |
5a0e3ad6 | 14 | #include <linux/slab.h> |
1da177e4 | 15 | #include <linux/sched.h> |
08e0e7c8 | 16 | #include <linux/ip.h> |
1da177e4 | 17 | #include "internal.h" |
08e0e7c8 | 18 | #include "afs_cm.h" |
1da177e4 | 19 | |
d001648e DH |
20 | static int afs_deliver_cb_init_call_back_state(struct afs_call *); |
21 | static int afs_deliver_cb_init_call_back_state3(struct afs_call *); | |
22 | static int afs_deliver_cb_probe(struct afs_call *); | |
23 | static int afs_deliver_cb_callback(struct afs_call *); | |
24 | static int afs_deliver_cb_probe_uuid(struct afs_call *); | |
25 | static int afs_deliver_cb_tell_me_about_yourself(struct afs_call *); | |
08e0e7c8 | 26 | static void afs_cm_destructor(struct afs_call *); |
1da177e4 | 27 | |
1da177e4 | 28 | /* |
08e0e7c8 | 29 | * CB.CallBack operation type |
1da177e4 | 30 | */ |
08e0e7c8 | 31 | static const struct afs_call_type afs_SRXCBCallBack = { |
00d3b7a4 | 32 | .name = "CB.CallBack", |
08e0e7c8 DH |
33 | .deliver = afs_deliver_cb_callback, |
34 | .abort_to_error = afs_abort_to_error, | |
35 | .destructor = afs_cm_destructor, | |
36 | }; | |
1da177e4 | 37 | |
1da177e4 | 38 | /* |
08e0e7c8 | 39 | * CB.InitCallBackState operation type |
1da177e4 | 40 | */ |
08e0e7c8 | 41 | static const struct afs_call_type afs_SRXCBInitCallBackState = { |
00d3b7a4 | 42 | .name = "CB.InitCallBackState", |
08e0e7c8 DH |
43 | .deliver = afs_deliver_cb_init_call_back_state, |
44 | .abort_to_error = afs_abort_to_error, | |
45 | .destructor = afs_cm_destructor, | |
46 | }; | |
1da177e4 | 47 | |
c35eccb1 DH |
48 | /* |
49 | * CB.InitCallBackState3 operation type | |
50 | */ | |
51 | static const struct afs_call_type afs_SRXCBInitCallBackState3 = { | |
52 | .name = "CB.InitCallBackState3", | |
53 | .deliver = afs_deliver_cb_init_call_back_state3, | |
54 | .abort_to_error = afs_abort_to_error, | |
55 | .destructor = afs_cm_destructor, | |
56 | }; | |
57 | ||
1da177e4 | 58 | /* |
08e0e7c8 | 59 | * CB.Probe operation type |
1da177e4 | 60 | */ |
08e0e7c8 | 61 | static const struct afs_call_type afs_SRXCBProbe = { |
00d3b7a4 | 62 | .name = "CB.Probe", |
08e0e7c8 DH |
63 | .deliver = afs_deliver_cb_probe, |
64 | .abort_to_error = afs_abort_to_error, | |
65 | .destructor = afs_cm_destructor, | |
66 | }; | |
1da177e4 | 67 | |
9396d496 DH |
68 | /* |
69 | * CB.ProbeUuid operation type | |
70 | */ | |
71 | static const struct afs_call_type afs_SRXCBProbeUuid = { | |
72 | .name = "CB.ProbeUuid", | |
73 | .deliver = afs_deliver_cb_probe_uuid, | |
74 | .abort_to_error = afs_abort_to_error, | |
75 | .destructor = afs_cm_destructor, | |
76 | }; | |
77 | ||
b908fe6b | 78 | /* |
7c80bcce | 79 | * CB.TellMeAboutYourself operation type |
b908fe6b | 80 | */ |
7c80bcce DH |
81 | static const struct afs_call_type afs_SRXCBTellMeAboutYourself = { |
82 | .name = "CB.TellMeAboutYourself", | |
83 | .deliver = afs_deliver_cb_tell_me_about_yourself, | |
b908fe6b DH |
84 | .abort_to_error = afs_abort_to_error, |
85 | .destructor = afs_cm_destructor, | |
86 | }; | |
87 | ||
1da177e4 | 88 | /* |
08e0e7c8 DH |
89 | * route an incoming cache manager call |
90 | * - return T if supported, F if not | |
1da177e4 | 91 | */ |
08e0e7c8 | 92 | bool afs_cm_incoming_call(struct afs_call *call) |
1da177e4 | 93 | { |
08e0e7c8 DH |
94 | u32 operation_id = ntohl(call->operation_ID); |
95 | ||
96 | _enter("{CB.OP %u}", operation_id); | |
97 | ||
98 | switch (operation_id) { | |
99 | case CBCallBack: | |
100 | call->type = &afs_SRXCBCallBack; | |
101 | return true; | |
102 | case CBInitCallBackState: | |
103 | call->type = &afs_SRXCBInitCallBackState; | |
104 | return true; | |
c35eccb1 DH |
105 | case CBInitCallBackState3: |
106 | call->type = &afs_SRXCBInitCallBackState3; | |
107 | return true; | |
08e0e7c8 DH |
108 | case CBProbe: |
109 | call->type = &afs_SRXCBProbe; | |
110 | return true; | |
7c80bcce DH |
111 | case CBTellMeAboutYourself: |
112 | call->type = &afs_SRXCBTellMeAboutYourself; | |
b908fe6b | 113 | return true; |
08e0e7c8 DH |
114 | default: |
115 | return false; | |
1da177e4 | 116 | } |
ec26815a | 117 | } |
1da177e4 | 118 | |
1da177e4 | 119 | /* |
08e0e7c8 | 120 | * clean up a cache manager call |
1da177e4 | 121 | */ |
08e0e7c8 | 122 | static void afs_cm_destructor(struct afs_call *call) |
1da177e4 | 123 | { |
08e0e7c8 DH |
124 | _enter(""); |
125 | ||
6c67c7c3 DH |
126 | /* Break the callbacks here so that we do it after the final ACK is |
127 | * received. The step number here must match the final number in | |
128 | * afs_deliver_cb_callback(). | |
129 | */ | |
d001648e | 130 | if (call->unmarshall == 5) { |
6c67c7c3 DH |
131 | ASSERT(call->server && call->count && call->request); |
132 | afs_break_callbacks(call->server, call->count, call->request); | |
133 | } | |
134 | ||
08e0e7c8 DH |
135 | afs_put_server(call->server); |
136 | call->server = NULL; | |
137 | kfree(call->buffer); | |
138 | call->buffer = NULL; | |
ec26815a | 139 | } |
1da177e4 | 140 | |
1da177e4 | 141 | /* |
08e0e7c8 | 142 | * allow the fileserver to see if the cache manager is still alive |
1da177e4 | 143 | */ |
08e0e7c8 | 144 | static void SRXAFSCB_CallBack(struct work_struct *work) |
1da177e4 | 145 | { |
08e0e7c8 | 146 | struct afs_call *call = container_of(work, struct afs_call, work); |
1da177e4 | 147 | |
08e0e7c8 | 148 | _enter(""); |
1da177e4 | 149 | |
08e0e7c8 DH |
150 | /* be sure to send the reply *before* attempting to spam the AFS server |
151 | * with FSFetchStatus requests on the vnodes with broken callbacks lest | |
152 | * the AFS server get into a vicious cycle of trying to break further | |
153 | * callbacks because it hadn't received completion of the CBCallBack op | |
154 | * yet */ | |
155 | afs_send_empty_reply(call); | |
1da177e4 | 156 | |
08e0e7c8 DH |
157 | afs_break_callbacks(call->server, call->count, call->request); |
158 | _leave(""); | |
ec26815a | 159 | } |
1da177e4 | 160 | |
1da177e4 | 161 | /* |
08e0e7c8 | 162 | * deliver request data to a CB.CallBack call |
1da177e4 | 163 | */ |
d001648e | 164 | static int afs_deliver_cb_callback(struct afs_call *call) |
1da177e4 | 165 | { |
8324f0bc | 166 | struct sockaddr_rxrpc srx; |
08e0e7c8 DH |
167 | struct afs_callback *cb; |
168 | struct afs_server *server; | |
08e0e7c8 DH |
169 | __be32 *bp; |
170 | u32 tmp; | |
171 | int ret, loop; | |
172 | ||
d001648e | 173 | _enter("{%u}", call->unmarshall); |
08e0e7c8 DH |
174 | |
175 | switch (call->unmarshall) { | |
176 | case 0: | |
8324f0bc | 177 | rxrpc_kernel_get_peer(afs_socket, call->rxcall, &srx); |
08e0e7c8 DH |
178 | call->offset = 0; |
179 | call->unmarshall++; | |
180 | ||
181 | /* extract the FID array and its count in two steps */ | |
182 | case 1: | |
183 | _debug("extract FID count"); | |
d001648e | 184 | ret = afs_extract_data(call, &call->tmp, 4, true); |
372ee163 DH |
185 | if (ret < 0) |
186 | return ret; | |
1da177e4 | 187 | |
08e0e7c8 DH |
188 | call->count = ntohl(call->tmp); |
189 | _debug("FID count: %u", call->count); | |
190 | if (call->count > AFSCBMAX) | |
191 | return -EBADMSG; | |
192 | ||
193 | call->buffer = kmalloc(call->count * 3 * 4, GFP_KERNEL); | |
194 | if (!call->buffer) | |
195 | return -ENOMEM; | |
196 | call->offset = 0; | |
197 | call->unmarshall++; | |
198 | ||
199 | case 2: | |
200 | _debug("extract FID array"); | |
d001648e DH |
201 | ret = afs_extract_data(call, call->buffer, |
202 | call->count * 3 * 4, true); | |
372ee163 DH |
203 | if (ret < 0) |
204 | return ret; | |
1da177e4 | 205 | |
08e0e7c8 DH |
206 | _debug("unmarshall FID array"); |
207 | call->request = kcalloc(call->count, | |
208 | sizeof(struct afs_callback), | |
209 | GFP_KERNEL); | |
210 | if (!call->request) | |
211 | return -ENOMEM; | |
212 | ||
213 | cb = call->request; | |
214 | bp = call->buffer; | |
215 | for (loop = call->count; loop > 0; loop--, cb++) { | |
216 | cb->fid.vid = ntohl(*bp++); | |
217 | cb->fid.vnode = ntohl(*bp++); | |
218 | cb->fid.unique = ntohl(*bp++); | |
219 | cb->type = AFSCM_CB_UNTYPED; | |
1da177e4 LT |
220 | } |
221 | ||
08e0e7c8 DH |
222 | call->offset = 0; |
223 | call->unmarshall++; | |
224 | ||
225 | /* extract the callback array and its count in two steps */ | |
226 | case 3: | |
227 | _debug("extract CB count"); | |
d001648e | 228 | ret = afs_extract_data(call, &call->tmp, 4, true); |
372ee163 DH |
229 | if (ret < 0) |
230 | return ret; | |
1da177e4 | 231 | |
08e0e7c8 DH |
232 | tmp = ntohl(call->tmp); |
233 | _debug("CB count: %u", tmp); | |
234 | if (tmp != call->count && tmp != 0) | |
235 | return -EBADMSG; | |
236 | call->offset = 0; | |
237 | call->unmarshall++; | |
08e0e7c8 DH |
238 | |
239 | case 4: | |
240 | _debug("extract CB array"); | |
d001648e DH |
241 | ret = afs_extract_data(call, call->buffer, |
242 | call->count * 3 * 4, false); | |
372ee163 DH |
243 | if (ret < 0) |
244 | return ret; | |
1da177e4 | 245 | |
08e0e7c8 DH |
246 | _debug("unmarshall CB array"); |
247 | cb = call->request; | |
248 | bp = call->buffer; | |
249 | for (loop = call->count; loop > 0; loop--, cb++) { | |
250 | cb->version = ntohl(*bp++); | |
251 | cb->expiry = ntohl(*bp++); | |
252 | cb->type = ntohl(*bp++); | |
253 | } | |
1da177e4 | 254 | |
08e0e7c8 DH |
255 | call->offset = 0; |
256 | call->unmarshall++; | |
1da177e4 | 257 | |
6c67c7c3 DH |
258 | /* Record that the message was unmarshalled successfully so |
259 | * that the call destructor can know do the callback breaking | |
260 | * work, even if the final ACK isn't received. | |
261 | * | |
262 | * If the step number changes, then afs_cm_destructor() must be | |
263 | * updated also. | |
264 | */ | |
265 | call->unmarshall++; | |
d001648e | 266 | case 5: |
1da177e4 LT |
267 | break; |
268 | } | |
269 | ||
08e0e7c8 | 270 | call->state = AFS_CALL_REPLYING; |
1da177e4 | 271 | |
08e0e7c8 DH |
272 | /* we'll need the file server record as that tells us which set of |
273 | * vnodes to operate upon */ | |
8324f0bc | 274 | server = afs_find_server(&srx); |
08e0e7c8 DH |
275 | if (!server) |
276 | return -ENOTCONN; | |
277 | call->server = server; | |
278 | ||
279 | INIT_WORK(&call->work, SRXAFSCB_CallBack); | |
0ad53eee | 280 | queue_work(afs_wq, &call->work); |
08e0e7c8 | 281 | return 0; |
ec26815a | 282 | } |
1da177e4 | 283 | |
1da177e4 | 284 | /* |
08e0e7c8 | 285 | * allow the fileserver to request callback state (re-)initialisation |
1da177e4 | 286 | */ |
08e0e7c8 | 287 | static void SRXAFSCB_InitCallBackState(struct work_struct *work) |
1da177e4 | 288 | { |
08e0e7c8 | 289 | struct afs_call *call = container_of(work, struct afs_call, work); |
1da177e4 | 290 | |
08e0e7c8 | 291 | _enter("{%p}", call->server); |
1da177e4 | 292 | |
08e0e7c8 DH |
293 | afs_init_callback_state(call->server); |
294 | afs_send_empty_reply(call); | |
295 | _leave(""); | |
ec26815a | 296 | } |
1da177e4 | 297 | |
1da177e4 | 298 | /* |
08e0e7c8 | 299 | * deliver request data to a CB.InitCallBackState call |
1da177e4 | 300 | */ |
d001648e | 301 | static int afs_deliver_cb_init_call_back_state(struct afs_call *call) |
1da177e4 | 302 | { |
8324f0bc | 303 | struct sockaddr_rxrpc srx; |
1da177e4 | 304 | struct afs_server *server; |
372ee163 | 305 | int ret; |
1da177e4 | 306 | |
d001648e | 307 | _enter(""); |
1da177e4 | 308 | |
8324f0bc DH |
309 | rxrpc_kernel_get_peer(afs_socket, call->rxcall, &srx); |
310 | ||
d001648e | 311 | ret = afs_extract_data(call, NULL, 0, false); |
372ee163 DH |
312 | if (ret < 0) |
313 | return ret; | |
1da177e4 | 314 | |
08e0e7c8 DH |
315 | /* no unmarshalling required */ |
316 | call->state = AFS_CALL_REPLYING; | |
1da177e4 | 317 | |
08e0e7c8 DH |
318 | /* we'll need the file server record as that tells us which set of |
319 | * vnodes to operate upon */ | |
8324f0bc | 320 | server = afs_find_server(&srx); |
08e0e7c8 DH |
321 | if (!server) |
322 | return -ENOTCONN; | |
323 | call->server = server; | |
1da177e4 | 324 | |
08e0e7c8 | 325 | INIT_WORK(&call->work, SRXAFSCB_InitCallBackState); |
0ad53eee | 326 | queue_work(afs_wq, &call->work); |
08e0e7c8 DH |
327 | return 0; |
328 | } | |
1da177e4 | 329 | |
c35eccb1 DH |
330 | /* |
331 | * deliver request data to a CB.InitCallBackState3 call | |
332 | */ | |
d001648e | 333 | static int afs_deliver_cb_init_call_back_state3(struct afs_call *call) |
c35eccb1 | 334 | { |
8324f0bc | 335 | struct sockaddr_rxrpc srx; |
c35eccb1 | 336 | struct afs_server *server; |
d001648e DH |
337 | struct afs_uuid *r; |
338 | unsigned loop; | |
339 | __be32 *b; | |
340 | int ret; | |
c35eccb1 | 341 | |
d001648e | 342 | _enter(""); |
c35eccb1 | 343 | |
8324f0bc DH |
344 | rxrpc_kernel_get_peer(afs_socket, call->rxcall, &srx); |
345 | ||
d001648e DH |
346 | _enter("{%u}", call->unmarshall); |
347 | ||
348 | switch (call->unmarshall) { | |
349 | case 0: | |
350 | call->offset = 0; | |
351 | call->buffer = kmalloc(11 * sizeof(__be32), GFP_KERNEL); | |
352 | if (!call->buffer) | |
353 | return -ENOMEM; | |
354 | call->unmarshall++; | |
355 | ||
356 | case 1: | |
357 | _debug("extract UUID"); | |
358 | ret = afs_extract_data(call, call->buffer, | |
359 | 11 * sizeof(__be32), false); | |
360 | switch (ret) { | |
361 | case 0: break; | |
362 | case -EAGAIN: return 0; | |
363 | default: return ret; | |
364 | } | |
365 | ||
366 | _debug("unmarshall UUID"); | |
367 | call->request = kmalloc(sizeof(struct afs_uuid), GFP_KERNEL); | |
368 | if (!call->request) | |
369 | return -ENOMEM; | |
370 | ||
371 | b = call->buffer; | |
372 | r = call->request; | |
373 | r->time_low = ntohl(b[0]); | |
374 | r->time_mid = ntohl(b[1]); | |
375 | r->time_hi_and_version = ntohl(b[2]); | |
376 | r->clock_seq_hi_and_reserved = ntohl(b[3]); | |
377 | r->clock_seq_low = ntohl(b[4]); | |
378 | ||
379 | for (loop = 0; loop < 6; loop++) | |
380 | r->node[loop] = ntohl(b[loop + 5]); | |
381 | ||
382 | call->offset = 0; | |
383 | call->unmarshall++; | |
384 | ||
385 | case 2: | |
386 | break; | |
387 | } | |
c35eccb1 DH |
388 | |
389 | /* no unmarshalling required */ | |
390 | call->state = AFS_CALL_REPLYING; | |
391 | ||
392 | /* we'll need the file server record as that tells us which set of | |
393 | * vnodes to operate upon */ | |
8324f0bc | 394 | server = afs_find_server(&srx); |
c35eccb1 DH |
395 | if (!server) |
396 | return -ENOTCONN; | |
397 | call->server = server; | |
398 | ||
399 | INIT_WORK(&call->work, SRXAFSCB_InitCallBackState); | |
0ad53eee | 400 | queue_work(afs_wq, &call->work); |
c35eccb1 DH |
401 | return 0; |
402 | } | |
403 | ||
08e0e7c8 DH |
404 | /* |
405 | * allow the fileserver to see if the cache manager is still alive | |
406 | */ | |
407 | static void SRXAFSCB_Probe(struct work_struct *work) | |
408 | { | |
409 | struct afs_call *call = container_of(work, struct afs_call, work); | |
1da177e4 | 410 | |
08e0e7c8 DH |
411 | _enter(""); |
412 | afs_send_empty_reply(call); | |
413 | _leave(""); | |
414 | } | |
1da177e4 | 415 | |
08e0e7c8 DH |
416 | /* |
417 | * deliver request data to a CB.Probe call | |
418 | */ | |
d001648e | 419 | static int afs_deliver_cb_probe(struct afs_call *call) |
08e0e7c8 | 420 | { |
372ee163 DH |
421 | int ret; |
422 | ||
d001648e | 423 | _enter(""); |
1da177e4 | 424 | |
d001648e | 425 | ret = afs_extract_data(call, NULL, 0, false); |
372ee163 DH |
426 | if (ret < 0) |
427 | return ret; | |
1da177e4 | 428 | |
08e0e7c8 DH |
429 | /* no unmarshalling required */ |
430 | call->state = AFS_CALL_REPLYING; | |
1da177e4 | 431 | |
08e0e7c8 | 432 | INIT_WORK(&call->work, SRXAFSCB_Probe); |
0ad53eee | 433 | queue_work(afs_wq, &call->work); |
08e0e7c8 | 434 | return 0; |
ec26815a | 435 | } |
b908fe6b | 436 | |
9396d496 DH |
437 | /* |
438 | * allow the fileserver to quickly find out if the fileserver has been rebooted | |
439 | */ | |
440 | static void SRXAFSCB_ProbeUuid(struct work_struct *work) | |
441 | { | |
442 | struct afs_call *call = container_of(work, struct afs_call, work); | |
443 | struct afs_uuid *r = call->request; | |
444 | ||
445 | struct { | |
446 | __be32 match; | |
447 | } reply; | |
448 | ||
449 | _enter(""); | |
450 | ||
9396d496 DH |
451 | if (memcmp(r, &afs_uuid, sizeof(afs_uuid)) == 0) |
452 | reply.match = htonl(0); | |
453 | else | |
454 | reply.match = htonl(1); | |
455 | ||
456 | afs_send_simple_reply(call, &reply, sizeof(reply)); | |
457 | _leave(""); | |
458 | } | |
459 | ||
460 | /* | |
461 | * deliver request data to a CB.ProbeUuid call | |
462 | */ | |
d001648e | 463 | static int afs_deliver_cb_probe_uuid(struct afs_call *call) |
9396d496 DH |
464 | { |
465 | struct afs_uuid *r; | |
466 | unsigned loop; | |
467 | __be32 *b; | |
468 | int ret; | |
469 | ||
d001648e | 470 | _enter("{%u}", call->unmarshall); |
9396d496 DH |
471 | |
472 | switch (call->unmarshall) { | |
473 | case 0: | |
474 | call->offset = 0; | |
475 | call->buffer = kmalloc(11 * sizeof(__be32), GFP_KERNEL); | |
476 | if (!call->buffer) | |
477 | return -ENOMEM; | |
478 | call->unmarshall++; | |
479 | ||
480 | case 1: | |
481 | _debug("extract UUID"); | |
d001648e DH |
482 | ret = afs_extract_data(call, call->buffer, |
483 | 11 * sizeof(__be32), false); | |
9396d496 DH |
484 | switch (ret) { |
485 | case 0: break; | |
486 | case -EAGAIN: return 0; | |
487 | default: return ret; | |
488 | } | |
489 | ||
490 | _debug("unmarshall UUID"); | |
491 | call->request = kmalloc(sizeof(struct afs_uuid), GFP_KERNEL); | |
492 | if (!call->request) | |
493 | return -ENOMEM; | |
494 | ||
495 | b = call->buffer; | |
496 | r = call->request; | |
497 | r->time_low = ntohl(b[0]); | |
498 | r->time_mid = ntohl(b[1]); | |
499 | r->time_hi_and_version = ntohl(b[2]); | |
500 | r->clock_seq_hi_and_reserved = ntohl(b[3]); | |
501 | r->clock_seq_low = ntohl(b[4]); | |
502 | ||
503 | for (loop = 0; loop < 6; loop++) | |
504 | r->node[loop] = ntohl(b[loop + 5]); | |
505 | ||
506 | call->offset = 0; | |
507 | call->unmarshall++; | |
508 | ||
509 | case 2: | |
9396d496 DH |
510 | break; |
511 | } | |
512 | ||
9396d496 DH |
513 | call->state = AFS_CALL_REPLYING; |
514 | ||
515 | INIT_WORK(&call->work, SRXAFSCB_ProbeUuid); | |
0ad53eee | 516 | queue_work(afs_wq, &call->work); |
9396d496 DH |
517 | return 0; |
518 | } | |
519 | ||
b908fe6b DH |
520 | /* |
521 | * allow the fileserver to ask about the cache manager's capabilities | |
522 | */ | |
7c80bcce | 523 | static void SRXAFSCB_TellMeAboutYourself(struct work_struct *work) |
b908fe6b DH |
524 | { |
525 | struct afs_interface *ifs; | |
526 | struct afs_call *call = container_of(work, struct afs_call, work); | |
527 | int loop, nifs; | |
528 | ||
529 | struct { | |
530 | struct /* InterfaceAddr */ { | |
531 | __be32 nifs; | |
532 | __be32 uuid[11]; | |
533 | __be32 ifaddr[32]; | |
534 | __be32 netmask[32]; | |
535 | __be32 mtu[32]; | |
536 | } ia; | |
537 | struct /* Capabilities */ { | |
538 | __be32 capcount; | |
539 | __be32 caps[1]; | |
540 | } cap; | |
541 | } reply; | |
542 | ||
543 | _enter(""); | |
544 | ||
545 | nifs = 0; | |
546 | ifs = kcalloc(32, sizeof(*ifs), GFP_KERNEL); | |
547 | if (ifs) { | |
548 | nifs = afs_get_ipv4_interfaces(ifs, 32, false); | |
549 | if (nifs < 0) { | |
550 | kfree(ifs); | |
551 | ifs = NULL; | |
552 | nifs = 0; | |
553 | } | |
554 | } | |
555 | ||
556 | memset(&reply, 0, sizeof(reply)); | |
557 | reply.ia.nifs = htonl(nifs); | |
558 | ||
559 | reply.ia.uuid[0] = htonl(afs_uuid.time_low); | |
560 | reply.ia.uuid[1] = htonl(afs_uuid.time_mid); | |
561 | reply.ia.uuid[2] = htonl(afs_uuid.time_hi_and_version); | |
562 | reply.ia.uuid[3] = htonl((s8) afs_uuid.clock_seq_hi_and_reserved); | |
563 | reply.ia.uuid[4] = htonl((s8) afs_uuid.clock_seq_low); | |
564 | for (loop = 0; loop < 6; loop++) | |
565 | reply.ia.uuid[loop + 5] = htonl((s8) afs_uuid.node[loop]); | |
566 | ||
567 | if (ifs) { | |
568 | for (loop = 0; loop < nifs; loop++) { | |
569 | reply.ia.ifaddr[loop] = ifs[loop].address.s_addr; | |
570 | reply.ia.netmask[loop] = ifs[loop].netmask.s_addr; | |
571 | reply.ia.mtu[loop] = htonl(ifs[loop].mtu); | |
572 | } | |
5b35fad9 | 573 | kfree(ifs); |
b908fe6b DH |
574 | } |
575 | ||
576 | reply.cap.capcount = htonl(1); | |
577 | reply.cap.caps[0] = htonl(AFS_CAP_ERROR_TRANSLATION); | |
578 | afs_send_simple_reply(call, &reply, sizeof(reply)); | |
579 | ||
580 | _leave(""); | |
581 | } | |
582 | ||
583 | /* | |
7c80bcce | 584 | * deliver request data to a CB.TellMeAboutYourself call |
b908fe6b | 585 | */ |
d001648e | 586 | static int afs_deliver_cb_tell_me_about_yourself(struct afs_call *call) |
b908fe6b | 587 | { |
372ee163 DH |
588 | int ret; |
589 | ||
d001648e | 590 | _enter(""); |
b908fe6b | 591 | |
d001648e | 592 | ret = afs_extract_data(call, NULL, 0, false); |
372ee163 DH |
593 | if (ret < 0) |
594 | return ret; | |
b908fe6b DH |
595 | |
596 | /* no unmarshalling required */ | |
597 | call->state = AFS_CALL_REPLYING; | |
598 | ||
7c80bcce | 599 | INIT_WORK(&call->work, SRXAFSCB_TellMeAboutYourself); |
0ad53eee | 600 | queue_work(afs_wq, &call->work); |
b908fe6b DH |
601 | return 0; |
602 | } |