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