David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 1 | /* connection-level event handling |
| 2 | * |
| 3 | * Copyright (C) 2007 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 | |
Joe Perches | 9b6d539 | 2016-06-02 12:08:52 -0700 | [diff] [blame] | 12 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 13 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 14 | #include <linux/module.h> |
| 15 | #include <linux/net.h> |
| 16 | #include <linux/skbuff.h> |
| 17 | #include <linux/errqueue.h> |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 18 | #include <net/sock.h> |
| 19 | #include <net/af_rxrpc.h> |
| 20 | #include <net/ip.h> |
| 21 | #include "ar-internal.h" |
| 22 | |
| 23 | /* |
David Howells | 18bfeba | 2016-08-23 15:27:25 +0100 | [diff] [blame] | 24 | * Retransmit terminal ACK or ABORT of the previous call. |
| 25 | */ |
David Howells | f5c17aa | 2016-08-30 09:49:28 +0100 | [diff] [blame] | 26 | static void rxrpc_conn_retransmit_call(struct rxrpc_connection *conn, |
| 27 | struct sk_buff *skb) |
David Howells | 18bfeba | 2016-08-23 15:27:25 +0100 | [diff] [blame] | 28 | { |
| 29 | struct rxrpc_skb_priv *sp = rxrpc_skb(skb); |
| 30 | struct rxrpc_channel *chan; |
| 31 | struct msghdr msg; |
| 32 | struct kvec iov; |
| 33 | struct { |
| 34 | struct rxrpc_wire_header whdr; |
| 35 | union { |
| 36 | struct { |
| 37 | __be32 code; |
| 38 | } abort; |
| 39 | struct { |
| 40 | struct rxrpc_ackpacket ack; |
David Howells | 2266ffd | 2016-08-24 13:06:14 +0100 | [diff] [blame] | 41 | u8 padding[3]; |
David Howells | 18bfeba | 2016-08-23 15:27:25 +0100 | [diff] [blame] | 42 | struct rxrpc_ackinfo info; |
| 43 | }; |
| 44 | }; |
| 45 | } __attribute__((packed)) pkt; |
| 46 | size_t len; |
| 47 | u32 serial, mtu, call_id; |
| 48 | |
| 49 | _enter("%d", conn->debug_id); |
| 50 | |
| 51 | chan = &conn->channels[sp->hdr.cid & RXRPC_CHANNELMASK]; |
| 52 | |
| 53 | /* If the last call got moved on whilst we were waiting to run, just |
| 54 | * ignore this packet. |
| 55 | */ |
| 56 | call_id = READ_ONCE(chan->last_call); |
| 57 | /* Sync with __rxrpc_disconnect_call() */ |
| 58 | smp_rmb(); |
| 59 | if (call_id != sp->hdr.callNumber) |
| 60 | return; |
| 61 | |
| 62 | msg.msg_name = &conn->params.peer->srx.transport; |
| 63 | msg.msg_namelen = conn->params.peer->srx.transport_len; |
| 64 | msg.msg_control = NULL; |
| 65 | msg.msg_controllen = 0; |
| 66 | msg.msg_flags = 0; |
| 67 | |
| 68 | pkt.whdr.epoch = htonl(sp->hdr.epoch); |
| 69 | pkt.whdr.cid = htonl(sp->hdr.cid); |
| 70 | pkt.whdr.callNumber = htonl(sp->hdr.callNumber); |
| 71 | pkt.whdr.seq = 0; |
| 72 | pkt.whdr.type = chan->last_type; |
| 73 | pkt.whdr.flags = conn->out_clientflag; |
| 74 | pkt.whdr.userStatus = 0; |
| 75 | pkt.whdr.securityIndex = conn->security_ix; |
| 76 | pkt.whdr._rsvd = 0; |
| 77 | pkt.whdr.serviceId = htons(chan->last_service_id); |
| 78 | |
| 79 | len = sizeof(pkt.whdr); |
| 80 | switch (chan->last_type) { |
| 81 | case RXRPC_PACKET_TYPE_ABORT: |
| 82 | pkt.abort.code = htonl(chan->last_abort); |
| 83 | len += sizeof(pkt.abort); |
| 84 | break; |
| 85 | |
| 86 | case RXRPC_PACKET_TYPE_ACK: |
| 87 | mtu = conn->params.peer->if_mtu; |
| 88 | mtu -= conn->params.peer->hdrsize; |
| 89 | pkt.ack.bufferSpace = 0; |
| 90 | pkt.ack.maxSkew = htons(skb->priority); |
| 91 | pkt.ack.firstPacket = htonl(chan->last_seq); |
| 92 | pkt.ack.previousPacket = htonl(chan->last_seq - 1); |
| 93 | pkt.ack.serial = htonl(sp->hdr.serial); |
| 94 | pkt.ack.reason = RXRPC_ACK_DUPLICATE; |
| 95 | pkt.ack.nAcks = 0; |
| 96 | pkt.info.rxMTU = htonl(rxrpc_rx_mtu); |
| 97 | pkt.info.maxMTU = htonl(mtu); |
| 98 | pkt.info.rwind = htonl(rxrpc_rx_window_size); |
| 99 | pkt.info.jumbo_max = htonl(rxrpc_rx_jumbo_max); |
| 100 | len += sizeof(pkt.ack) + sizeof(pkt.info); |
| 101 | break; |
| 102 | } |
| 103 | |
| 104 | /* Resync with __rxrpc_disconnect_call() and check that the last call |
| 105 | * didn't get advanced whilst we were filling out the packets. |
| 106 | */ |
| 107 | smp_rmb(); |
| 108 | if (READ_ONCE(chan->last_call) != call_id) |
| 109 | return; |
| 110 | |
| 111 | iov.iov_base = &pkt; |
| 112 | iov.iov_len = len; |
| 113 | |
| 114 | serial = atomic_inc_return(&conn->serial); |
| 115 | pkt.whdr.serial = htonl(serial); |
| 116 | |
| 117 | switch (chan->last_type) { |
| 118 | case RXRPC_PACKET_TYPE_ABORT: |
| 119 | _proto("Tx ABORT %%%u { %d } [re]", serial, conn->local_abort); |
| 120 | break; |
| 121 | case RXRPC_PACKET_TYPE_ACK: |
David Howells | be832ae | 2016-09-23 12:39:22 +0100 | [diff] [blame^] | 122 | trace_rxrpc_tx_ack(NULL, serial, chan->last_seq, 0, |
| 123 | RXRPC_ACK_DUPLICATE, 0); |
David Howells | 18bfeba | 2016-08-23 15:27:25 +0100 | [diff] [blame] | 124 | _proto("Tx ACK %%%u [re]", serial); |
| 125 | break; |
| 126 | } |
| 127 | |
| 128 | kernel_sendmsg(conn->params.local->socket, &msg, &iov, 1, len); |
| 129 | _leave(""); |
| 130 | return; |
| 131 | } |
| 132 | |
| 133 | /* |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 134 | * pass a connection-level abort onto all calls on that connection |
| 135 | */ |
David Howells | f5c17aa | 2016-08-30 09:49:28 +0100 | [diff] [blame] | 136 | static void rxrpc_abort_calls(struct rxrpc_connection *conn, |
| 137 | enum rxrpc_call_completion compl, |
| 138 | u32 abort_code, int error) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 139 | { |
| 140 | struct rxrpc_call *call; |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 141 | int i; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 142 | |
| 143 | _enter("{%d},%x", conn->debug_id, abort_code); |
| 144 | |
David Howells | a1399f8 | 2016-06-27 14:39:44 +0100 | [diff] [blame] | 145 | spin_lock(&conn->channel_lock); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 146 | |
David Howells | a1399f8 | 2016-06-27 14:39:44 +0100 | [diff] [blame] | 147 | for (i = 0; i < RXRPC_MAXCALLS; i++) { |
| 148 | call = rcu_dereference_protected( |
| 149 | conn->channels[i].call, |
| 150 | lockdep_is_held(&conn->channel_lock)); |
David Howells | ccbd3db | 2016-08-30 09:49:28 +0100 | [diff] [blame] | 151 | if (call) { |
David Howells | 5a42976 | 2016-09-06 22:19:51 +0100 | [diff] [blame] | 152 | if (compl == RXRPC_CALL_LOCALLY_ABORTED) |
| 153 | trace_rxrpc_abort("CON", call->cid, |
| 154 | call->call_id, 0, |
| 155 | abort_code, error); |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 156 | if (rxrpc_set_call_completion(call, compl, |
| 157 | abort_code, error)) |
| 158 | rxrpc_notify_socket(call); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 159 | } |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 160 | } |
| 161 | |
David Howells | a1399f8 | 2016-06-27 14:39:44 +0100 | [diff] [blame] | 162 | spin_unlock(&conn->channel_lock); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 163 | _leave(""); |
| 164 | } |
| 165 | |
| 166 | /* |
| 167 | * generate a connection-level abort |
| 168 | */ |
| 169 | static int rxrpc_abort_connection(struct rxrpc_connection *conn, |
| 170 | u32 error, u32 abort_code) |
| 171 | { |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 172 | struct rxrpc_wire_header whdr; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 173 | struct msghdr msg; |
| 174 | struct kvec iov[2]; |
| 175 | __be32 word; |
| 176 | size_t len; |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 177 | u32 serial; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 178 | int ret; |
| 179 | |
| 180 | _enter("%d,,%u,%u", conn->debug_id, error, abort_code); |
| 181 | |
| 182 | /* generate a connection-level abort */ |
| 183 | spin_lock_bh(&conn->state_lock); |
David Howells | f5c17aa | 2016-08-30 09:49:28 +0100 | [diff] [blame] | 184 | if (conn->state >= RXRPC_CONN_REMOTELY_ABORTED) { |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 185 | spin_unlock_bh(&conn->state_lock); |
| 186 | _leave(" = 0 [already dead]"); |
| 187 | return 0; |
| 188 | } |
| 189 | |
David Howells | f5c17aa | 2016-08-30 09:49:28 +0100 | [diff] [blame] | 190 | conn->state = RXRPC_CONN_LOCALLY_ABORTED; |
| 191 | spin_unlock_bh(&conn->state_lock); |
| 192 | |
| 193 | rxrpc_abort_calls(conn, RXRPC_CALL_LOCALLY_ABORTED, abort_code, error); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 194 | |
David Howells | 85f3227 | 2016-04-04 14:00:36 +0100 | [diff] [blame] | 195 | msg.msg_name = &conn->params.peer->srx.transport; |
| 196 | msg.msg_namelen = conn->params.peer->srx.transport_len; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 197 | msg.msg_control = NULL; |
| 198 | msg.msg_controllen = 0; |
| 199 | msg.msg_flags = 0; |
| 200 | |
David Howells | 19ffa01 | 2016-04-04 14:00:36 +0100 | [diff] [blame] | 201 | whdr.epoch = htonl(conn->proto.epoch); |
| 202 | whdr.cid = htonl(conn->proto.cid); |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 203 | whdr.callNumber = 0; |
| 204 | whdr.seq = 0; |
| 205 | whdr.type = RXRPC_PACKET_TYPE_ABORT; |
| 206 | whdr.flags = conn->out_clientflag; |
| 207 | whdr.userStatus = 0; |
| 208 | whdr.securityIndex = conn->security_ix; |
| 209 | whdr._rsvd = 0; |
David Howells | 19ffa01 | 2016-04-04 14:00:36 +0100 | [diff] [blame] | 210 | whdr.serviceId = htons(conn->params.service_id); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 211 | |
David Howells | dc44b3a | 2016-04-07 17:23:30 +0100 | [diff] [blame] | 212 | word = htonl(conn->local_abort); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 213 | |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 214 | iov[0].iov_base = &whdr; |
| 215 | iov[0].iov_len = sizeof(whdr); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 216 | iov[1].iov_base = &word; |
| 217 | iov[1].iov_len = sizeof(word); |
| 218 | |
| 219 | len = iov[0].iov_len + iov[1].iov_len; |
| 220 | |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 221 | serial = atomic_inc_return(&conn->serial); |
| 222 | whdr.serial = htonl(serial); |
David Howells | dc44b3a | 2016-04-07 17:23:30 +0100 | [diff] [blame] | 223 | _proto("Tx CONN ABORT %%%u { %d }", serial, conn->local_abort); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 224 | |
David Howells | 85f3227 | 2016-04-04 14:00:36 +0100 | [diff] [blame] | 225 | ret = kernel_sendmsg(conn->params.local->socket, &msg, iov, 2, len); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 226 | if (ret < 0) { |
| 227 | _debug("sendmsg failed: %d", ret); |
| 228 | return -EAGAIN; |
| 229 | } |
| 230 | |
| 231 | _leave(" = 0"); |
| 232 | return 0; |
| 233 | } |
| 234 | |
| 235 | /* |
| 236 | * mark a call as being on a now-secured channel |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 237 | * - must be called with BH's disabled. |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 238 | */ |
Roel Kluin | 5eaa65b | 2008-12-10 15:18:31 -0800 | [diff] [blame] | 239 | static void rxrpc_call_is_secure(struct rxrpc_call *call) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 240 | { |
| 241 | _enter("%p", call); |
| 242 | if (call) { |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 243 | write_lock_bh(&call->state_lock); |
| 244 | if (call->state == RXRPC_CALL_SERVER_SECURING) { |
| 245 | call->state = RXRPC_CALL_SERVER_ACCEPTING; |
| 246 | rxrpc_notify_socket(call); |
| 247 | } |
| 248 | write_unlock_bh(&call->state_lock); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 249 | } |
| 250 | } |
| 251 | |
| 252 | /* |
| 253 | * connection-level Rx packet processor |
| 254 | */ |
| 255 | static int rxrpc_process_event(struct rxrpc_connection *conn, |
| 256 | struct sk_buff *skb, |
| 257 | u32 *_abort_code) |
| 258 | { |
| 259 | struct rxrpc_skb_priv *sp = rxrpc_skb(skb); |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 260 | __be32 wtmp; |
| 261 | u32 abort_code; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 262 | int loop, ret; |
| 263 | |
David Howells | 519d256 | 2009-06-16 21:36:44 +0100 | [diff] [blame] | 264 | if (conn->state >= RXRPC_CONN_REMOTELY_ABORTED) { |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 265 | _leave(" = -ECONNABORTED [%u]", conn->state); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 266 | return -ECONNABORTED; |
David Howells | 519d256 | 2009-06-16 21:36:44 +0100 | [diff] [blame] | 267 | } |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 268 | |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 269 | _enter("{%d},{%u,%%%u},", conn->debug_id, sp->hdr.type, sp->hdr.serial); |
David Howells | 519d256 | 2009-06-16 21:36:44 +0100 | [diff] [blame] | 270 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 271 | switch (sp->hdr.type) { |
David Howells | 18bfeba | 2016-08-23 15:27:25 +0100 | [diff] [blame] | 272 | case RXRPC_PACKET_TYPE_DATA: |
| 273 | case RXRPC_PACKET_TYPE_ACK: |
David Howells | f5c17aa | 2016-08-30 09:49:28 +0100 | [diff] [blame] | 274 | rxrpc_conn_retransmit_call(conn, skb); |
David Howells | 18bfeba | 2016-08-23 15:27:25 +0100 | [diff] [blame] | 275 | return 0; |
| 276 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 277 | case RXRPC_PACKET_TYPE_ABORT: |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 278 | if (skb_copy_bits(skb, sp->offset, &wtmp, sizeof(wtmp)) < 0) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 279 | return -EPROTO; |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 280 | abort_code = ntohl(wtmp); |
| 281 | _proto("Rx ABORT %%%u { ac=%d }", sp->hdr.serial, abort_code); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 282 | |
| 283 | conn->state = RXRPC_CONN_REMOTELY_ABORTED; |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 284 | rxrpc_abort_calls(conn, RXRPC_CALL_REMOTELY_ABORTED, |
| 285 | abort_code, ECONNABORTED); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 286 | return -ECONNABORTED; |
| 287 | |
| 288 | case RXRPC_PACKET_TYPE_CHALLENGE: |
David Howells | e0e4d82 | 2016-04-07 17:23:58 +0100 | [diff] [blame] | 289 | return conn->security->respond_to_challenge(conn, skb, |
| 290 | _abort_code); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 291 | |
| 292 | case RXRPC_PACKET_TYPE_RESPONSE: |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 293 | ret = conn->security->verify_response(conn, skb, _abort_code); |
| 294 | if (ret < 0) |
| 295 | return ret; |
| 296 | |
| 297 | ret = conn->security->init_connection_security(conn); |
| 298 | if (ret < 0) |
| 299 | return ret; |
| 300 | |
Herbert Xu | a263629 | 2016-06-26 14:55:24 -0700 | [diff] [blame] | 301 | ret = conn->security->prime_packet_security(conn); |
| 302 | if (ret < 0) |
| 303 | return ret; |
| 304 | |
David Howells | a1399f8 | 2016-06-27 14:39:44 +0100 | [diff] [blame] | 305 | spin_lock(&conn->channel_lock); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 306 | spin_lock(&conn->state_lock); |
| 307 | |
David Howells | bba304d | 2016-06-27 10:32:02 +0100 | [diff] [blame] | 308 | if (conn->state == RXRPC_CONN_SERVICE_CHALLENGING) { |
| 309 | conn->state = RXRPC_CONN_SERVICE; |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 310 | spin_unlock(&conn->state_lock); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 311 | for (loop = 0; loop < RXRPC_MAXCALLS; loop++) |
David Howells | dee4636 | 2016-06-27 17:11:19 +0100 | [diff] [blame] | 312 | rxrpc_call_is_secure( |
| 313 | rcu_dereference_protected( |
David Howells | a1399f8 | 2016-06-27 14:39:44 +0100 | [diff] [blame] | 314 | conn->channels[loop].call, |
| 315 | lockdep_is_held(&conn->channel_lock))); |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 316 | } else { |
| 317 | spin_unlock(&conn->state_lock); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 318 | } |
| 319 | |
David Howells | a1399f8 | 2016-06-27 14:39:44 +0100 | [diff] [blame] | 320 | spin_unlock(&conn->channel_lock); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 321 | return 0; |
| 322 | |
| 323 | default: |
David Howells | 519d256 | 2009-06-16 21:36:44 +0100 | [diff] [blame] | 324 | _leave(" = -EPROTO [%u]", sp->hdr.type); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 325 | return -EPROTO; |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | /* |
| 330 | * set up security and issue a challenge |
| 331 | */ |
| 332 | static void rxrpc_secure_connection(struct rxrpc_connection *conn) |
| 333 | { |
| 334 | u32 abort_code; |
| 335 | int ret; |
| 336 | |
| 337 | _enter("{%d}", conn->debug_id); |
| 338 | |
| 339 | ASSERT(conn->security_ix != 0); |
| 340 | |
David Howells | 19ffa01 | 2016-04-04 14:00:36 +0100 | [diff] [blame] | 341 | if (!conn->params.key) { |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 342 | _debug("set up security"); |
| 343 | ret = rxrpc_init_server_conn_security(conn); |
| 344 | switch (ret) { |
| 345 | case 0: |
| 346 | break; |
| 347 | case -ENOENT: |
| 348 | abort_code = RX_CALL_DEAD; |
| 349 | goto abort; |
| 350 | default: |
| 351 | abort_code = RXKADNOAUTH; |
| 352 | goto abort; |
| 353 | } |
| 354 | } |
| 355 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 356 | if (conn->security->issue_challenge(conn) < 0) { |
| 357 | abort_code = RX_CALL_DEAD; |
| 358 | ret = -ENOMEM; |
| 359 | goto abort; |
| 360 | } |
| 361 | |
| 362 | _leave(""); |
| 363 | return; |
| 364 | |
| 365 | abort: |
| 366 | _debug("abort %d, %d", ret, abort_code); |
| 367 | rxrpc_abort_connection(conn, -ret, abort_code); |
| 368 | _leave(" [aborted]"); |
| 369 | } |
| 370 | |
| 371 | /* |
| 372 | * connection-level event processor |
| 373 | */ |
| 374 | void rxrpc_process_connection(struct work_struct *work) |
| 375 | { |
| 376 | struct rxrpc_connection *conn = |
| 377 | container_of(work, struct rxrpc_connection, processor); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 378 | struct sk_buff *skb; |
| 379 | u32 abort_code = RX_PROTOCOL_ERROR; |
| 380 | int ret; |
| 381 | |
David Howells | 363deea | 2016-09-17 10:49:14 +0100 | [diff] [blame] | 382 | rxrpc_see_connection(conn); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 383 | |
David Howells | 2c4579e | 2016-06-27 10:32:03 +0100 | [diff] [blame] | 384 | if (test_and_clear_bit(RXRPC_CONN_EV_CHALLENGE, &conn->events)) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 385 | rxrpc_secure_connection(conn); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 386 | |
| 387 | /* go through the conn-level event packets, releasing the ref on this |
| 388 | * connection that each one has when we've finished with it */ |
| 389 | while ((skb = skb_dequeue(&conn->rx_queue))) { |
David Howells | 71f3ca4 | 2016-09-17 10:49:14 +0100 | [diff] [blame] | 390 | rxrpc_see_skb(skb, rxrpc_skb_rx_seen); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 391 | ret = rxrpc_process_event(conn, skb, &abort_code); |
| 392 | switch (ret) { |
| 393 | case -EPROTO: |
| 394 | case -EKEYEXPIRED: |
| 395 | case -EKEYREJECTED: |
| 396 | goto protocol_error; |
| 397 | case -EAGAIN: |
| 398 | goto requeue_and_leave; |
| 399 | case -ECONNABORTED: |
| 400 | default: |
David Howells | 71f3ca4 | 2016-09-17 10:49:14 +0100 | [diff] [blame] | 401 | rxrpc_free_skb(skb, rxrpc_skb_rx_freed); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 402 | break; |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | out: |
| 407 | rxrpc_put_connection(conn); |
| 408 | _leave(""); |
| 409 | return; |
| 410 | |
| 411 | requeue_and_leave: |
| 412 | skb_queue_head(&conn->rx_queue, skb); |
| 413 | goto out; |
| 414 | |
| 415 | protocol_error: |
| 416 | if (rxrpc_abort_connection(conn, -ret, abort_code) < 0) |
| 417 | goto requeue_and_leave; |
David Howells | 71f3ca4 | 2016-09-17 10:49:14 +0100 | [diff] [blame] | 418 | rxrpc_free_skb(skb, rxrpc_skb_rx_freed); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 419 | _leave(" [EPROTO]"); |
| 420 | goto out; |
| 421 | } |