blob: d2ec3fd593e8386571f5ce56063d87875418c164 [file] [log] [blame]
David Howells17926a72007-04-26 15:48:28 -07001/* 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 Perches9b6d5392016-06-02 12:08:52 -070012#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13
David Howells17926a72007-04-26 15:48:28 -070014#include <linux/module.h>
15#include <linux/net.h>
16#include <linux/skbuff.h>
17#include <linux/errqueue.h>
David Howells17926a72007-04-26 15:48:28 -070018#include <net/sock.h>
19#include <net/af_rxrpc.h>
20#include <net/ip.h>
21#include "ar-internal.h"
22
23/*
David Howells18bfeba2016-08-23 15:27:25 +010024 * Retransmit terminal ACK or ABORT of the previous call.
25 */
David Howellsf5c17aa2016-08-30 09:49:28 +010026static void rxrpc_conn_retransmit_call(struct rxrpc_connection *conn,
David Howells3136ef42017-11-24 10:18:41 +000027 struct sk_buff *skb,
28 unsigned int channel)
David Howells18bfeba2016-08-23 15:27:25 +010029{
David Howells3136ef42017-11-24 10:18:41 +000030 struct rxrpc_skb_priv *sp = skb ? rxrpc_skb(skb) : NULL;
David Howells18bfeba2016-08-23 15:27:25 +010031 struct rxrpc_channel *chan;
32 struct msghdr msg;
David Howells5fc62f62017-11-29 14:40:41 +000033 struct kvec iov[3];
David Howells18bfeba2016-08-23 15:27:25 +010034 struct {
35 struct rxrpc_wire_header whdr;
36 union {
David Howells5fc62f62017-11-29 14:40:41 +000037 __be32 abort_code;
38 struct rxrpc_ackpacket ack;
David Howells18bfeba2016-08-23 15:27:25 +010039 };
40 } __attribute__((packed)) pkt;
David Howells5fc62f62017-11-29 14:40:41 +000041 struct rxrpc_ackinfo ack_info;
David Howells18bfeba2016-08-23 15:27:25 +010042 size_t len;
David Howells5fc62f62017-11-29 14:40:41 +000043 int ioc;
44 u32 serial, mtu, call_id, padding;
David Howells18bfeba2016-08-23 15:27:25 +010045
46 _enter("%d", conn->debug_id);
47
David Howells3136ef42017-11-24 10:18:41 +000048 chan = &conn->channels[channel];
David Howells18bfeba2016-08-23 15:27:25 +010049
50 /* If the last call got moved on whilst we were waiting to run, just
51 * ignore this packet.
52 */
53 call_id = READ_ONCE(chan->last_call);
54 /* Sync with __rxrpc_disconnect_call() */
55 smp_rmb();
David Howells3136ef42017-11-24 10:18:41 +000056 if (skb && call_id != sp->hdr.callNumber)
David Howells18bfeba2016-08-23 15:27:25 +010057 return;
58
59 msg.msg_name = &conn->params.peer->srx.transport;
60 msg.msg_namelen = conn->params.peer->srx.transport_len;
61 msg.msg_control = NULL;
62 msg.msg_controllen = 0;
63 msg.msg_flags = 0;
64
David Howells5fc62f62017-11-29 14:40:41 +000065 iov[0].iov_base = &pkt;
66 iov[0].iov_len = sizeof(pkt.whdr);
67 iov[1].iov_base = &padding;
68 iov[1].iov_len = 3;
69 iov[2].iov_base = &ack_info;
70 iov[2].iov_len = sizeof(ack_info);
71
David Howells3136ef42017-11-24 10:18:41 +000072 pkt.whdr.epoch = htonl(conn->proto.epoch);
73 pkt.whdr.cid = htonl(conn->proto.cid);
74 pkt.whdr.callNumber = htonl(call_id);
David Howells18bfeba2016-08-23 15:27:25 +010075 pkt.whdr.seq = 0;
76 pkt.whdr.type = chan->last_type;
77 pkt.whdr.flags = conn->out_clientflag;
78 pkt.whdr.userStatus = 0;
79 pkt.whdr.securityIndex = conn->security_ix;
80 pkt.whdr._rsvd = 0;
David Howells68d6d1a2017-06-05 14:30:49 +010081 pkt.whdr.serviceId = htons(conn->service_id);
David Howells18bfeba2016-08-23 15:27:25 +010082
83 len = sizeof(pkt.whdr);
84 switch (chan->last_type) {
85 case RXRPC_PACKET_TYPE_ABORT:
David Howells5fc62f62017-11-29 14:40:41 +000086 pkt.abort_code = htonl(chan->last_abort);
87 iov[0].iov_len += sizeof(pkt.abort_code);
88 len += sizeof(pkt.abort_code);
89 ioc = 1;
David Howells18bfeba2016-08-23 15:27:25 +010090 break;
91
92 case RXRPC_PACKET_TYPE_ACK:
93 mtu = conn->params.peer->if_mtu;
94 mtu -= conn->params.peer->hdrsize;
95 pkt.ack.bufferSpace = 0;
David Howells3136ef42017-11-24 10:18:41 +000096 pkt.ack.maxSkew = htons(skb ? skb->priority : 0);
97 pkt.ack.firstPacket = htonl(chan->last_seq + 1);
98 pkt.ack.previousPacket = htonl(chan->last_seq);
99 pkt.ack.serial = htonl(skb ? sp->hdr.serial : 0);
100 pkt.ack.reason = skb ? RXRPC_ACK_DUPLICATE : RXRPC_ACK_IDLE;
David Howells18bfeba2016-08-23 15:27:25 +0100101 pkt.ack.nAcks = 0;
David Howells5fc62f62017-11-29 14:40:41 +0000102 ack_info.rxMTU = htonl(rxrpc_rx_mtu);
103 ack_info.maxMTU = htonl(mtu);
104 ack_info.rwind = htonl(rxrpc_rx_window_size);
105 ack_info.jumbo_max = htonl(rxrpc_rx_jumbo_max);
David Howells57494342016-09-24 18:05:27 +0100106 pkt.whdr.flags |= RXRPC_SLOW_START_OK;
David Howells5fc62f62017-11-29 14:40:41 +0000107 padding = 0;
108 iov[0].iov_len += sizeof(pkt.ack);
109 len += sizeof(pkt.ack) + 3 + sizeof(ack_info);
110 ioc = 3;
David Howells18bfeba2016-08-23 15:27:25 +0100111 break;
David Howells5fc62f62017-11-29 14:40:41 +0000112
113 default:
114 return;
David Howells18bfeba2016-08-23 15:27:25 +0100115 }
116
117 /* Resync with __rxrpc_disconnect_call() and check that the last call
118 * didn't get advanced whilst we were filling out the packets.
119 */
120 smp_rmb();
121 if (READ_ONCE(chan->last_call) != call_id)
122 return;
123
David Howells18bfeba2016-08-23 15:27:25 +0100124 serial = atomic_inc_return(&conn->serial);
125 pkt.whdr.serial = htonl(serial);
126
127 switch (chan->last_type) {
128 case RXRPC_PACKET_TYPE_ABORT:
129 _proto("Tx ABORT %%%u { %d } [re]", serial, conn->local_abort);
130 break;
131 case RXRPC_PACKET_TYPE_ACK:
David Howellsbe832ae2016-09-23 12:39:22 +0100132 trace_rxrpc_tx_ack(NULL, serial, chan->last_seq, 0,
133 RXRPC_ACK_DUPLICATE, 0);
David Howells18bfeba2016-08-23 15:27:25 +0100134 _proto("Tx ACK %%%u [re]", serial);
135 break;
136 }
137
David Howells5fc62f62017-11-29 14:40:41 +0000138 kernel_sendmsg(conn->params.local->socket, &msg, iov, ioc, len);
David Howells18bfeba2016-08-23 15:27:25 +0100139 _leave("");
140 return;
141}
142
143/*
David Howells17926a72007-04-26 15:48:28 -0700144 * pass a connection-level abort onto all calls on that connection
145 */
David Howellsf5c17aa2016-08-30 09:49:28 +0100146static void rxrpc_abort_calls(struct rxrpc_connection *conn,
147 enum rxrpc_call_completion compl,
148 u32 abort_code, int error)
David Howells17926a72007-04-26 15:48:28 -0700149{
150 struct rxrpc_call *call;
David Howells248f2192016-09-08 11:10:12 +0100151 int i;
David Howells17926a72007-04-26 15:48:28 -0700152
153 _enter("{%d},%x", conn->debug_id, abort_code);
154
David Howellsa1399f82016-06-27 14:39:44 +0100155 spin_lock(&conn->channel_lock);
David Howells17926a72007-04-26 15:48:28 -0700156
David Howellsa1399f82016-06-27 14:39:44 +0100157 for (i = 0; i < RXRPC_MAXCALLS; i++) {
158 call = rcu_dereference_protected(
159 conn->channels[i].call,
160 lockdep_is_held(&conn->channel_lock));
David Howellsccbd3db2016-08-30 09:49:28 +0100161 if (call) {
David Howells5a429762016-09-06 22:19:51 +0100162 if (compl == RXRPC_CALL_LOCALLY_ABORTED)
David Howellsa25e21f2018-03-27 23:03:00 +0100163 trace_rxrpc_abort(call->debug_id,
164 "CON", call->cid,
David Howells5a429762016-09-06 22:19:51 +0100165 call->call_id, 0,
166 abort_code, error);
David Howells248f2192016-09-08 11:10:12 +0100167 if (rxrpc_set_call_completion(call, compl,
168 abort_code, error))
169 rxrpc_notify_socket(call);
David Howells17926a72007-04-26 15:48:28 -0700170 }
David Howells17926a72007-04-26 15:48:28 -0700171 }
172
David Howellsa1399f82016-06-27 14:39:44 +0100173 spin_unlock(&conn->channel_lock);
David Howells17926a72007-04-26 15:48:28 -0700174 _leave("");
175}
176
177/*
178 * generate a connection-level abort
179 */
180static int rxrpc_abort_connection(struct rxrpc_connection *conn,
David Howells3a927892017-04-06 10:11:56 +0100181 int error, u32 abort_code)
David Howells17926a72007-04-26 15:48:28 -0700182{
David Howells0d12f8a2016-03-04 15:53:46 +0000183 struct rxrpc_wire_header whdr;
David Howells17926a72007-04-26 15:48:28 -0700184 struct msghdr msg;
185 struct kvec iov[2];
186 __be32 word;
187 size_t len;
David Howells0d12f8a2016-03-04 15:53:46 +0000188 u32 serial;
David Howells17926a72007-04-26 15:48:28 -0700189 int ret;
190
191 _enter("%d,,%u,%u", conn->debug_id, error, abort_code);
192
193 /* generate a connection-level abort */
194 spin_lock_bh(&conn->state_lock);
David Howellsf5c17aa2016-08-30 09:49:28 +0100195 if (conn->state >= RXRPC_CONN_REMOTELY_ABORTED) {
David Howells17926a72007-04-26 15:48:28 -0700196 spin_unlock_bh(&conn->state_lock);
197 _leave(" = 0 [already dead]");
198 return 0;
199 }
200
David Howellsf5c17aa2016-08-30 09:49:28 +0100201 conn->state = RXRPC_CONN_LOCALLY_ABORTED;
202 spin_unlock_bh(&conn->state_lock);
203
204 rxrpc_abort_calls(conn, RXRPC_CALL_LOCALLY_ABORTED, abort_code, error);
David Howells17926a72007-04-26 15:48:28 -0700205
David Howells85f32272016-04-04 14:00:36 +0100206 msg.msg_name = &conn->params.peer->srx.transport;
207 msg.msg_namelen = conn->params.peer->srx.transport_len;
David Howells17926a72007-04-26 15:48:28 -0700208 msg.msg_control = NULL;
209 msg.msg_controllen = 0;
210 msg.msg_flags = 0;
211
David Howells19ffa012016-04-04 14:00:36 +0100212 whdr.epoch = htonl(conn->proto.epoch);
213 whdr.cid = htonl(conn->proto.cid);
David Howells0d12f8a2016-03-04 15:53:46 +0000214 whdr.callNumber = 0;
215 whdr.seq = 0;
216 whdr.type = RXRPC_PACKET_TYPE_ABORT;
217 whdr.flags = conn->out_clientflag;
218 whdr.userStatus = 0;
219 whdr.securityIndex = conn->security_ix;
220 whdr._rsvd = 0;
David Howells68d6d1a2017-06-05 14:30:49 +0100221 whdr.serviceId = htons(conn->service_id);
David Howells17926a72007-04-26 15:48:28 -0700222
David Howellsdc44b3a2016-04-07 17:23:30 +0100223 word = htonl(conn->local_abort);
David Howells17926a72007-04-26 15:48:28 -0700224
David Howells0d12f8a2016-03-04 15:53:46 +0000225 iov[0].iov_base = &whdr;
226 iov[0].iov_len = sizeof(whdr);
David Howells17926a72007-04-26 15:48:28 -0700227 iov[1].iov_base = &word;
228 iov[1].iov_len = sizeof(word);
229
230 len = iov[0].iov_len + iov[1].iov_len;
231
David Howells0d12f8a2016-03-04 15:53:46 +0000232 serial = atomic_inc_return(&conn->serial);
233 whdr.serial = htonl(serial);
David Howellsdc44b3a2016-04-07 17:23:30 +0100234 _proto("Tx CONN ABORT %%%u { %d }", serial, conn->local_abort);
David Howells17926a72007-04-26 15:48:28 -0700235
David Howells85f32272016-04-04 14:00:36 +0100236 ret = kernel_sendmsg(conn->params.local->socket, &msg, iov, 2, len);
David Howells17926a72007-04-26 15:48:28 -0700237 if (ret < 0) {
238 _debug("sendmsg failed: %d", ret);
239 return -EAGAIN;
240 }
241
242 _leave(" = 0");
243 return 0;
244}
245
246/*
247 * mark a call as being on a now-secured channel
David Howells248f2192016-09-08 11:10:12 +0100248 * - must be called with BH's disabled.
David Howells17926a72007-04-26 15:48:28 -0700249 */
Roel Kluin5eaa65b2008-12-10 15:18:31 -0800250static void rxrpc_call_is_secure(struct rxrpc_call *call)
David Howells17926a72007-04-26 15:48:28 -0700251{
252 _enter("%p", call);
253 if (call) {
David Howells248f2192016-09-08 11:10:12 +0100254 write_lock_bh(&call->state_lock);
255 if (call->state == RXRPC_CALL_SERVER_SECURING) {
256 call->state = RXRPC_CALL_SERVER_ACCEPTING;
257 rxrpc_notify_socket(call);
258 }
259 write_unlock_bh(&call->state_lock);
David Howells17926a72007-04-26 15:48:28 -0700260 }
261}
262
263/*
264 * connection-level Rx packet processor
265 */
266static int rxrpc_process_event(struct rxrpc_connection *conn,
267 struct sk_buff *skb,
268 u32 *_abort_code)
269{
270 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
David Howells0d12f8a2016-03-04 15:53:46 +0000271 __be32 wtmp;
272 u32 abort_code;
David Howells17926a72007-04-26 15:48:28 -0700273 int loop, ret;
274
David Howells519d2562009-06-16 21:36:44 +0100275 if (conn->state >= RXRPC_CONN_REMOTELY_ABORTED) {
David Howells248f2192016-09-08 11:10:12 +0100276 _leave(" = -ECONNABORTED [%u]", conn->state);
David Howells17926a72007-04-26 15:48:28 -0700277 return -ECONNABORTED;
David Howells519d2562009-06-16 21:36:44 +0100278 }
David Howells17926a72007-04-26 15:48:28 -0700279
David Howells0d12f8a2016-03-04 15:53:46 +0000280 _enter("{%d},{%u,%%%u},", conn->debug_id, sp->hdr.type, sp->hdr.serial);
David Howells519d2562009-06-16 21:36:44 +0100281
David Howells17926a72007-04-26 15:48:28 -0700282 switch (sp->hdr.type) {
David Howells18bfeba2016-08-23 15:27:25 +0100283 case RXRPC_PACKET_TYPE_DATA:
284 case RXRPC_PACKET_TYPE_ACK:
David Howells3136ef42017-11-24 10:18:41 +0000285 rxrpc_conn_retransmit_call(conn, skb,
286 sp->hdr.cid & RXRPC_CHANNELMASK);
David Howells18bfeba2016-08-23 15:27:25 +0100287 return 0;
288
David Howells4d4a6ac2017-03-16 16:27:10 +0000289 case RXRPC_PACKET_TYPE_BUSY:
290 /* Just ignore BUSY packets for now. */
291 return 0;
292
David Howells17926a72007-04-26 15:48:28 -0700293 case RXRPC_PACKET_TYPE_ABORT:
David Howells775e5b72016-09-30 13:26:03 +0100294 if (skb_copy_bits(skb, sizeof(struct rxrpc_wire_header),
David Howellsfb46f6e2017-04-06 10:12:00 +0100295 &wtmp, sizeof(wtmp)) < 0) {
296 trace_rxrpc_rx_eproto(NULL, sp->hdr.serial,
297 tracepoint_string("bad_abort"));
David Howells17926a72007-04-26 15:48:28 -0700298 return -EPROTO;
David Howellsfb46f6e2017-04-06 10:12:00 +0100299 }
David Howells0d12f8a2016-03-04 15:53:46 +0000300 abort_code = ntohl(wtmp);
301 _proto("Rx ABORT %%%u { ac=%d }", sp->hdr.serial, abort_code);
David Howells17926a72007-04-26 15:48:28 -0700302
303 conn->state = RXRPC_CONN_REMOTELY_ABORTED;
David Howells248f2192016-09-08 11:10:12 +0100304 rxrpc_abort_calls(conn, RXRPC_CALL_REMOTELY_ABORTED,
David Howells3a927892017-04-06 10:11:56 +0100305 abort_code, -ECONNABORTED);
David Howells17926a72007-04-26 15:48:28 -0700306 return -ECONNABORTED;
307
308 case RXRPC_PACKET_TYPE_CHALLENGE:
David Howellse0e4d822016-04-07 17:23:58 +0100309 return conn->security->respond_to_challenge(conn, skb,
310 _abort_code);
David Howells17926a72007-04-26 15:48:28 -0700311
312 case RXRPC_PACKET_TYPE_RESPONSE:
David Howells17926a72007-04-26 15:48:28 -0700313 ret = conn->security->verify_response(conn, skb, _abort_code);
314 if (ret < 0)
315 return ret;
316
317 ret = conn->security->init_connection_security(conn);
318 if (ret < 0)
319 return ret;
320
Herbert Xua2636292016-06-26 14:55:24 -0700321 ret = conn->security->prime_packet_security(conn);
322 if (ret < 0)
323 return ret;
324
David Howellsa1399f82016-06-27 14:39:44 +0100325 spin_lock(&conn->channel_lock);
David Howells17926a72007-04-26 15:48:28 -0700326 spin_lock(&conn->state_lock);
327
David Howellsbba304d2016-06-27 10:32:02 +0100328 if (conn->state == RXRPC_CONN_SERVICE_CHALLENGING) {
329 conn->state = RXRPC_CONN_SERVICE;
David Howells248f2192016-09-08 11:10:12 +0100330 spin_unlock(&conn->state_lock);
David Howells17926a72007-04-26 15:48:28 -0700331 for (loop = 0; loop < RXRPC_MAXCALLS; loop++)
David Howellsdee46362016-06-27 17:11:19 +0100332 rxrpc_call_is_secure(
333 rcu_dereference_protected(
David Howellsa1399f82016-06-27 14:39:44 +0100334 conn->channels[loop].call,
335 lockdep_is_held(&conn->channel_lock)));
David Howells248f2192016-09-08 11:10:12 +0100336 } else {
337 spin_unlock(&conn->state_lock);
David Howells17926a72007-04-26 15:48:28 -0700338 }
339
David Howellsa1399f82016-06-27 14:39:44 +0100340 spin_unlock(&conn->channel_lock);
David Howells17926a72007-04-26 15:48:28 -0700341 return 0;
342
343 default:
David Howellsfb46f6e2017-04-06 10:12:00 +0100344 trace_rxrpc_rx_eproto(NULL, sp->hdr.serial,
345 tracepoint_string("bad_conn_pkt"));
David Howells17926a72007-04-26 15:48:28 -0700346 return -EPROTO;
347 }
348}
349
350/*
351 * set up security and issue a challenge
352 */
353static void rxrpc_secure_connection(struct rxrpc_connection *conn)
354{
355 u32 abort_code;
356 int ret;
357
358 _enter("{%d}", conn->debug_id);
359
360 ASSERT(conn->security_ix != 0);
361
David Howells19ffa012016-04-04 14:00:36 +0100362 if (!conn->params.key) {
David Howells17926a72007-04-26 15:48:28 -0700363 _debug("set up security");
364 ret = rxrpc_init_server_conn_security(conn);
365 switch (ret) {
366 case 0:
367 break;
368 case -ENOENT:
369 abort_code = RX_CALL_DEAD;
370 goto abort;
371 default:
372 abort_code = RXKADNOAUTH;
373 goto abort;
374 }
375 }
376
David Howells17926a72007-04-26 15:48:28 -0700377 if (conn->security->issue_challenge(conn) < 0) {
378 abort_code = RX_CALL_DEAD;
379 ret = -ENOMEM;
380 goto abort;
381 }
382
383 _leave("");
384 return;
385
386abort:
387 _debug("abort %d, %d", ret, abort_code);
David Howells3a927892017-04-06 10:11:56 +0100388 rxrpc_abort_connection(conn, ret, abort_code);
David Howells17926a72007-04-26 15:48:28 -0700389 _leave(" [aborted]");
390}
391
392/*
David Howells3136ef42017-11-24 10:18:41 +0000393 * Process delayed final ACKs that we haven't subsumed into a subsequent call.
394 */
395static void rxrpc_process_delayed_final_acks(struct rxrpc_connection *conn)
396{
397 unsigned long j = jiffies, next_j;
398 unsigned int channel;
399 bool set;
400
401again:
402 next_j = j + LONG_MAX;
403 set = false;
404 for (channel = 0; channel < RXRPC_MAXCALLS; channel++) {
405 struct rxrpc_channel *chan = &conn->channels[channel];
406 unsigned long ack_at;
407
408 if (!test_bit(RXRPC_CONN_FINAL_ACK_0 + channel, &conn->flags))
409 continue;
410
411 smp_rmb(); /* vs rxrpc_disconnect_client_call */
412 ack_at = READ_ONCE(chan->final_ack_at);
413
414 if (time_before(j, ack_at)) {
415 if (time_before(ack_at, next_j)) {
416 next_j = ack_at;
417 set = true;
418 }
419 continue;
420 }
421
422 if (test_and_clear_bit(RXRPC_CONN_FINAL_ACK_0 + channel,
423 &conn->flags))
424 rxrpc_conn_retransmit_call(conn, NULL, channel);
425 }
426
427 j = jiffies;
428 if (time_before_eq(next_j, j))
429 goto again;
430 if (set)
431 rxrpc_reduce_conn_timer(conn, next_j);
432}
433
434/*
David Howells17926a72007-04-26 15:48:28 -0700435 * connection-level event processor
436 */
437void rxrpc_process_connection(struct work_struct *work)
438{
439 struct rxrpc_connection *conn =
440 container_of(work, struct rxrpc_connection, processor);
David Howells17926a72007-04-26 15:48:28 -0700441 struct sk_buff *skb;
442 u32 abort_code = RX_PROTOCOL_ERROR;
443 int ret;
444
David Howells363deea2016-09-17 10:49:14 +0100445 rxrpc_see_connection(conn);
David Howells17926a72007-04-26 15:48:28 -0700446
David Howells2c4579e2016-06-27 10:32:03 +0100447 if (test_and_clear_bit(RXRPC_CONN_EV_CHALLENGE, &conn->events))
David Howells17926a72007-04-26 15:48:28 -0700448 rxrpc_secure_connection(conn);
David Howells17926a72007-04-26 15:48:28 -0700449
David Howells3136ef42017-11-24 10:18:41 +0000450 /* Process delayed ACKs whose time has come. */
451 if (conn->flags & RXRPC_CONN_FINAL_ACK_MASK)
452 rxrpc_process_delayed_final_acks(conn);
453
David Howells17926a72007-04-26 15:48:28 -0700454 /* go through the conn-level event packets, releasing the ref on this
455 * connection that each one has when we've finished with it */
456 while ((skb = skb_dequeue(&conn->rx_queue))) {
David Howells71f3ca42016-09-17 10:49:14 +0100457 rxrpc_see_skb(skb, rxrpc_skb_rx_seen);
David Howells17926a72007-04-26 15:48:28 -0700458 ret = rxrpc_process_event(conn, skb, &abort_code);
459 switch (ret) {
460 case -EPROTO:
461 case -EKEYEXPIRED:
462 case -EKEYREJECTED:
463 goto protocol_error;
David Howells8c2f8262018-02-08 15:59:07 +0000464 case -ENOMEM:
David Howells17926a72007-04-26 15:48:28 -0700465 case -EAGAIN:
466 goto requeue_and_leave;
467 case -ECONNABORTED:
468 default:
David Howells71f3ca42016-09-17 10:49:14 +0100469 rxrpc_free_skb(skb, rxrpc_skb_rx_freed);
David Howells17926a72007-04-26 15:48:28 -0700470 break;
471 }
472 }
473
474out:
475 rxrpc_put_connection(conn);
476 _leave("");
477 return;
478
479requeue_and_leave:
480 skb_queue_head(&conn->rx_queue, skb);
481 goto out;
482
483protocol_error:
David Howells3a927892017-04-06 10:11:56 +0100484 if (rxrpc_abort_connection(conn, ret, abort_code) < 0)
David Howells17926a72007-04-26 15:48:28 -0700485 goto requeue_and_leave;
David Howells71f3ca42016-09-17 10:49:14 +0100486 rxrpc_free_skb(skb, rxrpc_skb_rx_freed);
David Howells17926a72007-04-26 15:48:28 -0700487 goto out;
488}