blob: 808a4723f8684c849da712808938df11f3ce4872 [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
David Howells17926a72007-04-26 15:48:28 -07002/* connection-level event handling
3 *
4 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
David Howells17926a72007-04-26 15:48:28 -07006 */
7
Joe Perches9b6d5392016-06-02 12:08:52 -07008#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
9
David Howells17926a72007-04-26 15:48:28 -070010#include <linux/module.h>
11#include <linux/net.h>
12#include <linux/skbuff.h>
13#include <linux/errqueue.h>
David Howells17926a72007-04-26 15:48:28 -070014#include <net/sock.h>
15#include <net/af_rxrpc.h>
16#include <net/ip.h>
17#include "ar-internal.h"
18
19/*
David Howells18bfeba2016-08-23 15:27:25 +010020 * Retransmit terminal ACK or ABORT of the previous call.
21 */
David Howellsf5c17aa2016-08-30 09:49:28 +010022static void rxrpc_conn_retransmit_call(struct rxrpc_connection *conn,
David Howells3136ef42017-11-24 10:18:41 +000023 struct sk_buff *skb,
24 unsigned int channel)
David Howells18bfeba2016-08-23 15:27:25 +010025{
David Howells3136ef42017-11-24 10:18:41 +000026 struct rxrpc_skb_priv *sp = skb ? rxrpc_skb(skb) : NULL;
David Howells18bfeba2016-08-23 15:27:25 +010027 struct rxrpc_channel *chan;
28 struct msghdr msg;
David Howells5fc62f62017-11-29 14:40:41 +000029 struct kvec iov[3];
David Howells18bfeba2016-08-23 15:27:25 +010030 struct {
31 struct rxrpc_wire_header whdr;
32 union {
David Howells5fc62f62017-11-29 14:40:41 +000033 __be32 abort_code;
34 struct rxrpc_ackpacket ack;
David Howells18bfeba2016-08-23 15:27:25 +010035 };
36 } __attribute__((packed)) pkt;
David Howells5fc62f62017-11-29 14:40:41 +000037 struct rxrpc_ackinfo ack_info;
David Howells18bfeba2016-08-23 15:27:25 +010038 size_t len;
David Howells6b47fe12018-05-10 23:26:01 +010039 int ret, ioc;
David Howells5fc62f62017-11-29 14:40:41 +000040 u32 serial, mtu, call_id, padding;
David Howells18bfeba2016-08-23 15:27:25 +010041
42 _enter("%d", conn->debug_id);
43
David Howells3136ef42017-11-24 10:18:41 +000044 chan = &conn->channels[channel];
David Howells18bfeba2016-08-23 15:27:25 +010045
46 /* If the last call got moved on whilst we were waiting to run, just
47 * ignore this packet.
48 */
49 call_id = READ_ONCE(chan->last_call);
50 /* Sync with __rxrpc_disconnect_call() */
51 smp_rmb();
David Howells3136ef42017-11-24 10:18:41 +000052 if (skb && call_id != sp->hdr.callNumber)
David Howells18bfeba2016-08-23 15:27:25 +010053 return;
54
55 msg.msg_name = &conn->params.peer->srx.transport;
56 msg.msg_namelen = conn->params.peer->srx.transport_len;
57 msg.msg_control = NULL;
58 msg.msg_controllen = 0;
59 msg.msg_flags = 0;
60
David Howells5fc62f62017-11-29 14:40:41 +000061 iov[0].iov_base = &pkt;
62 iov[0].iov_len = sizeof(pkt.whdr);
63 iov[1].iov_base = &padding;
64 iov[1].iov_len = 3;
65 iov[2].iov_base = &ack_info;
66 iov[2].iov_len = sizeof(ack_info);
67
David Howells3136ef42017-11-24 10:18:41 +000068 pkt.whdr.epoch = htonl(conn->proto.epoch);
David Howellsfb1967a2018-06-06 14:59:14 +010069 pkt.whdr.cid = htonl(conn->proto.cid | channel);
David Howells3136ef42017-11-24 10:18:41 +000070 pkt.whdr.callNumber = htonl(call_id);
David Howells18bfeba2016-08-23 15:27:25 +010071 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;
David Howells68d6d1a2017-06-05 14:30:49 +010077 pkt.whdr.serviceId = htons(conn->service_id);
David Howells18bfeba2016-08-23 15:27:25 +010078
79 len = sizeof(pkt.whdr);
80 switch (chan->last_type) {
81 case RXRPC_PACKET_TYPE_ABORT:
David Howells5fc62f62017-11-29 14:40:41 +000082 pkt.abort_code = htonl(chan->last_abort);
83 iov[0].iov_len += sizeof(pkt.abort_code);
84 len += sizeof(pkt.abort_code);
85 ioc = 1;
David Howells18bfeba2016-08-23 15:27:25 +010086 break;
87
88 case RXRPC_PACKET_TYPE_ACK:
89 mtu = conn->params.peer->if_mtu;
90 mtu -= conn->params.peer->hdrsize;
91 pkt.ack.bufferSpace = 0;
David Howells3136ef42017-11-24 10:18:41 +000092 pkt.ack.maxSkew = htons(skb ? skb->priority : 0);
93 pkt.ack.firstPacket = htonl(chan->last_seq + 1);
94 pkt.ack.previousPacket = htonl(chan->last_seq);
95 pkt.ack.serial = htonl(skb ? sp->hdr.serial : 0);
96 pkt.ack.reason = skb ? RXRPC_ACK_DUPLICATE : RXRPC_ACK_IDLE;
David Howells18bfeba2016-08-23 15:27:25 +010097 pkt.ack.nAcks = 0;
David Howells5fc62f62017-11-29 14:40:41 +000098 ack_info.rxMTU = htonl(rxrpc_rx_mtu);
99 ack_info.maxMTU = htonl(mtu);
100 ack_info.rwind = htonl(rxrpc_rx_window_size);
101 ack_info.jumbo_max = htonl(rxrpc_rx_jumbo_max);
David Howells57494342016-09-24 18:05:27 +0100102 pkt.whdr.flags |= RXRPC_SLOW_START_OK;
David Howells5fc62f62017-11-29 14:40:41 +0000103 padding = 0;
104 iov[0].iov_len += sizeof(pkt.ack);
105 len += sizeof(pkt.ack) + 3 + sizeof(ack_info);
106 ioc = 3;
David Howells18bfeba2016-08-23 15:27:25 +0100107 break;
David Howells5fc62f62017-11-29 14:40:41 +0000108
109 default:
110 return;
David Howells18bfeba2016-08-23 15:27:25 +0100111 }
112
113 /* Resync with __rxrpc_disconnect_call() and check that the last call
114 * didn't get advanced whilst we were filling out the packets.
115 */
116 smp_rmb();
117 if (READ_ONCE(chan->last_call) != call_id)
118 return;
119
David Howells18bfeba2016-08-23 15:27:25 +0100120 serial = atomic_inc_return(&conn->serial);
121 pkt.whdr.serial = htonl(serial);
122
123 switch (chan->last_type) {
124 case RXRPC_PACKET_TYPE_ABORT:
David Howells64753092018-10-08 15:46:17 +0100125 _proto("Tx ABORT %%%u { %d } [re]", serial, conn->abort_code);
David Howells18bfeba2016-08-23 15:27:25 +0100126 break;
127 case RXRPC_PACKET_TYPE_ACK:
David Howells4764c0d2018-07-23 17:18:37 +0100128 trace_rxrpc_tx_ack(chan->call_debug_id, serial,
David Howellsf3f83372018-07-23 17:18:36 +0100129 ntohl(pkt.ack.firstPacket),
130 ntohl(pkt.ack.serial),
131 pkt.ack.reason, 0);
David Howells18bfeba2016-08-23 15:27:25 +0100132 _proto("Tx ACK %%%u [re]", serial);
133 break;
134 }
135
David Howells6b47fe12018-05-10 23:26:01 +0100136 ret = kernel_sendmsg(conn->params.local->socket, &msg, iov, ioc, len);
David Howells330bdcf2018-08-08 11:30:02 +0100137 conn->params.peer->last_tx_at = ktime_get_seconds();
David Howells6b47fe12018-05-10 23:26:01 +0100138 if (ret < 0)
David Howells4764c0d2018-07-23 17:18:37 +0100139 trace_rxrpc_tx_fail(chan->call_debug_id, serial, ret,
140 rxrpc_tx_point_call_final_resend);
141 else
142 trace_rxrpc_tx_packet(chan->call_debug_id, &pkt.whdr,
143 rxrpc_tx_point_call_final_resend);
David Howells6b47fe12018-05-10 23:26:01 +0100144
David Howells18bfeba2016-08-23 15:27:25 +0100145 _leave("");
David Howells18bfeba2016-08-23 15:27:25 +0100146}
147
148/*
David Howells17926a72007-04-26 15:48:28 -0700149 * pass a connection-level abort onto all calls on that connection
150 */
David Howellsf5c17aa2016-08-30 09:49:28 +0100151static void rxrpc_abort_calls(struct rxrpc_connection *conn,
David Howells39ce6752019-04-12 16:34:09 +0100152 enum rxrpc_call_completion compl,
153 rxrpc_serial_t serial)
David Howells17926a72007-04-26 15:48:28 -0700154{
155 struct rxrpc_call *call;
David Howells248f2192016-09-08 11:10:12 +0100156 int i;
David Howells17926a72007-04-26 15:48:28 -0700157
David Howells64753092018-10-08 15:46:17 +0100158 _enter("{%d},%x", conn->debug_id, conn->abort_code);
David Howells17926a72007-04-26 15:48:28 -0700159
David Howellsa1399f82016-06-27 14:39:44 +0100160 spin_lock(&conn->channel_lock);
David Howells17926a72007-04-26 15:48:28 -0700161
David Howellsa1399f82016-06-27 14:39:44 +0100162 for (i = 0; i < RXRPC_MAXCALLS; i++) {
163 call = rcu_dereference_protected(
164 conn->channels[i].call,
165 lockdep_is_held(&conn->channel_lock));
David Howellsccbd3db2016-08-30 09:49:28 +0100166 if (call) {
David Howells5a429762016-09-06 22:19:51 +0100167 if (compl == RXRPC_CALL_LOCALLY_ABORTED)
David Howellsa25e21f2018-03-27 23:03:00 +0100168 trace_rxrpc_abort(call->debug_id,
169 "CON", call->cid,
David Howells5a429762016-09-06 22:19:51 +0100170 call->call_id, 0,
David Howells64753092018-10-08 15:46:17 +0100171 conn->abort_code,
172 conn->error);
David Howells39ce6752019-04-12 16:34:09 +0100173 else
174 trace_rxrpc_rx_abort(call, serial,
175 conn->abort_code);
David Howells248f2192016-09-08 11:10:12 +0100176 if (rxrpc_set_call_completion(call, compl,
David Howells64753092018-10-08 15:46:17 +0100177 conn->abort_code,
178 conn->error))
David Howells248f2192016-09-08 11:10:12 +0100179 rxrpc_notify_socket(call);
David Howells17926a72007-04-26 15:48:28 -0700180 }
David Howells17926a72007-04-26 15:48:28 -0700181 }
182
David Howellsa1399f82016-06-27 14:39:44 +0100183 spin_unlock(&conn->channel_lock);
David Howells17926a72007-04-26 15:48:28 -0700184 _leave("");
185}
186
187/*
188 * generate a connection-level abort
189 */
190static int rxrpc_abort_connection(struct rxrpc_connection *conn,
David Howells3a927892017-04-06 10:11:56 +0100191 int error, u32 abort_code)
David Howells17926a72007-04-26 15:48:28 -0700192{
David Howells0d12f8a2016-03-04 15:53:46 +0000193 struct rxrpc_wire_header whdr;
David Howells17926a72007-04-26 15:48:28 -0700194 struct msghdr msg;
195 struct kvec iov[2];
196 __be32 word;
197 size_t len;
David Howells0d12f8a2016-03-04 15:53:46 +0000198 u32 serial;
David Howells17926a72007-04-26 15:48:28 -0700199 int ret;
200
201 _enter("%d,,%u,%u", conn->debug_id, error, abort_code);
202
203 /* generate a connection-level abort */
204 spin_lock_bh(&conn->state_lock);
David Howellsf5c17aa2016-08-30 09:49:28 +0100205 if (conn->state >= RXRPC_CONN_REMOTELY_ABORTED) {
David Howells17926a72007-04-26 15:48:28 -0700206 spin_unlock_bh(&conn->state_lock);
207 _leave(" = 0 [already dead]");
208 return 0;
209 }
210
David Howells64753092018-10-08 15:46:17 +0100211 conn->error = error;
212 conn->abort_code = abort_code;
David Howellsf5c17aa2016-08-30 09:49:28 +0100213 conn->state = RXRPC_CONN_LOCALLY_ABORTED;
214 spin_unlock_bh(&conn->state_lock);
215
David Howells85f32272016-04-04 14:00:36 +0100216 msg.msg_name = &conn->params.peer->srx.transport;
217 msg.msg_namelen = conn->params.peer->srx.transport_len;
David Howells17926a72007-04-26 15:48:28 -0700218 msg.msg_control = NULL;
219 msg.msg_controllen = 0;
220 msg.msg_flags = 0;
221
David Howells19ffa012016-04-04 14:00:36 +0100222 whdr.epoch = htonl(conn->proto.epoch);
223 whdr.cid = htonl(conn->proto.cid);
David Howells0d12f8a2016-03-04 15:53:46 +0000224 whdr.callNumber = 0;
225 whdr.seq = 0;
226 whdr.type = RXRPC_PACKET_TYPE_ABORT;
227 whdr.flags = conn->out_clientflag;
228 whdr.userStatus = 0;
229 whdr.securityIndex = conn->security_ix;
230 whdr._rsvd = 0;
David Howells68d6d1a2017-06-05 14:30:49 +0100231 whdr.serviceId = htons(conn->service_id);
David Howells17926a72007-04-26 15:48:28 -0700232
David Howells64753092018-10-08 15:46:17 +0100233 word = htonl(conn->abort_code);
David Howells17926a72007-04-26 15:48:28 -0700234
David Howells0d12f8a2016-03-04 15:53:46 +0000235 iov[0].iov_base = &whdr;
236 iov[0].iov_len = sizeof(whdr);
David Howells17926a72007-04-26 15:48:28 -0700237 iov[1].iov_base = &word;
238 iov[1].iov_len = sizeof(word);
239
240 len = iov[0].iov_len + iov[1].iov_len;
241
David Howells0d12f8a2016-03-04 15:53:46 +0000242 serial = atomic_inc_return(&conn->serial);
David Howells39ce6752019-04-12 16:34:09 +0100243 rxrpc_abort_calls(conn, RXRPC_CALL_LOCALLY_ABORTED, serial);
David Howells0d12f8a2016-03-04 15:53:46 +0000244 whdr.serial = htonl(serial);
David Howells64753092018-10-08 15:46:17 +0100245 _proto("Tx CONN ABORT %%%u { %d }", serial, conn->abort_code);
David Howells17926a72007-04-26 15:48:28 -0700246
David Howells85f32272016-04-04 14:00:36 +0100247 ret = kernel_sendmsg(conn->params.local->socket, &msg, iov, 2, len);
David Howells17926a72007-04-26 15:48:28 -0700248 if (ret < 0) {
David Howells6b47fe12018-05-10 23:26:01 +0100249 trace_rxrpc_tx_fail(conn->debug_id, serial, ret,
David Howells4764c0d2018-07-23 17:18:37 +0100250 rxrpc_tx_point_conn_abort);
David Howells17926a72007-04-26 15:48:28 -0700251 _debug("sendmsg failed: %d", ret);
252 return -EAGAIN;
253 }
254
David Howells4764c0d2018-07-23 17:18:37 +0100255 trace_rxrpc_tx_packet(conn->debug_id, &whdr, rxrpc_tx_point_conn_abort);
256
David Howells330bdcf2018-08-08 11:30:02 +0100257 conn->params.peer->last_tx_at = ktime_get_seconds();
David Howellsace45be2018-03-30 21:04:43 +0100258
David Howells17926a72007-04-26 15:48:28 -0700259 _leave(" = 0");
260 return 0;
261}
262
263/*
264 * mark a call as being on a now-secured channel
David Howells248f2192016-09-08 11:10:12 +0100265 * - must be called with BH's disabled.
David Howells17926a72007-04-26 15:48:28 -0700266 */
Roel Kluin5eaa65b2008-12-10 15:18:31 -0800267static void rxrpc_call_is_secure(struct rxrpc_call *call)
David Howells17926a72007-04-26 15:48:28 -0700268{
269 _enter("%p", call);
270 if (call) {
David Howells248f2192016-09-08 11:10:12 +0100271 write_lock_bh(&call->state_lock);
272 if (call->state == RXRPC_CALL_SERVER_SECURING) {
273 call->state = RXRPC_CALL_SERVER_ACCEPTING;
274 rxrpc_notify_socket(call);
275 }
276 write_unlock_bh(&call->state_lock);
David Howells17926a72007-04-26 15:48:28 -0700277 }
278}
279
280/*
281 * connection-level Rx packet processor
282 */
283static int rxrpc_process_event(struct rxrpc_connection *conn,
284 struct sk_buff *skb,
285 u32 *_abort_code)
286{
287 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
David Howells0d12f8a2016-03-04 15:53:46 +0000288 __be32 wtmp;
289 u32 abort_code;
David Howells17926a72007-04-26 15:48:28 -0700290 int loop, ret;
291
David Howells519d2562009-06-16 21:36:44 +0100292 if (conn->state >= RXRPC_CONN_REMOTELY_ABORTED) {
David Howells248f2192016-09-08 11:10:12 +0100293 _leave(" = -ECONNABORTED [%u]", conn->state);
David Howells17926a72007-04-26 15:48:28 -0700294 return -ECONNABORTED;
David Howells519d2562009-06-16 21:36:44 +0100295 }
David Howells17926a72007-04-26 15:48:28 -0700296
David Howells0d12f8a2016-03-04 15:53:46 +0000297 _enter("{%d},{%u,%%%u},", conn->debug_id, sp->hdr.type, sp->hdr.serial);
David Howells519d2562009-06-16 21:36:44 +0100298
David Howells17926a72007-04-26 15:48:28 -0700299 switch (sp->hdr.type) {
David Howells18bfeba2016-08-23 15:27:25 +0100300 case RXRPC_PACKET_TYPE_DATA:
301 case RXRPC_PACKET_TYPE_ACK:
David Howells3136ef42017-11-24 10:18:41 +0000302 rxrpc_conn_retransmit_call(conn, skb,
303 sp->hdr.cid & RXRPC_CHANNELMASK);
David Howells18bfeba2016-08-23 15:27:25 +0100304 return 0;
305
David Howells4d4a6ac2017-03-16 16:27:10 +0000306 case RXRPC_PACKET_TYPE_BUSY:
307 /* Just ignore BUSY packets for now. */
308 return 0;
309
David Howells17926a72007-04-26 15:48:28 -0700310 case RXRPC_PACKET_TYPE_ABORT:
David Howells775e5b72016-09-30 13:26:03 +0100311 if (skb_copy_bits(skb, sizeof(struct rxrpc_wire_header),
David Howellsfb46f6e2017-04-06 10:12:00 +0100312 &wtmp, sizeof(wtmp)) < 0) {
313 trace_rxrpc_rx_eproto(NULL, sp->hdr.serial,
314 tracepoint_string("bad_abort"));
David Howells17926a72007-04-26 15:48:28 -0700315 return -EPROTO;
David Howellsfb46f6e2017-04-06 10:12:00 +0100316 }
David Howells0d12f8a2016-03-04 15:53:46 +0000317 abort_code = ntohl(wtmp);
318 _proto("Rx ABORT %%%u { ac=%d }", sp->hdr.serial, abort_code);
David Howells17926a72007-04-26 15:48:28 -0700319
David Howells64753092018-10-08 15:46:17 +0100320 conn->error = -ECONNABORTED;
321 conn->abort_code = abort_code;
David Howells17926a72007-04-26 15:48:28 -0700322 conn->state = RXRPC_CONN_REMOTELY_ABORTED;
David Howells39ce6752019-04-12 16:34:09 +0100323 rxrpc_abort_calls(conn, RXRPC_CALL_REMOTELY_ABORTED, sp->hdr.serial);
David Howells17926a72007-04-26 15:48:28 -0700324 return -ECONNABORTED;
325
326 case RXRPC_PACKET_TYPE_CHALLENGE:
David Howellse0e4d822016-04-07 17:23:58 +0100327 return conn->security->respond_to_challenge(conn, skb,
328 _abort_code);
David Howells17926a72007-04-26 15:48:28 -0700329
330 case RXRPC_PACKET_TYPE_RESPONSE:
David Howells17926a72007-04-26 15:48:28 -0700331 ret = conn->security->verify_response(conn, skb, _abort_code);
332 if (ret < 0)
333 return ret;
334
335 ret = conn->security->init_connection_security(conn);
336 if (ret < 0)
337 return ret;
338
Herbert Xua2636292016-06-26 14:55:24 -0700339 ret = conn->security->prime_packet_security(conn);
340 if (ret < 0)
341 return ret;
342
David Howellsa1399f82016-06-27 14:39:44 +0100343 spin_lock(&conn->channel_lock);
David Howells17926a72007-04-26 15:48:28 -0700344 spin_lock(&conn->state_lock);
345
David Howellsbba304d2016-06-27 10:32:02 +0100346 if (conn->state == RXRPC_CONN_SERVICE_CHALLENGING) {
347 conn->state = RXRPC_CONN_SERVICE;
David Howells248f2192016-09-08 11:10:12 +0100348 spin_unlock(&conn->state_lock);
David Howells17926a72007-04-26 15:48:28 -0700349 for (loop = 0; loop < RXRPC_MAXCALLS; loop++)
David Howellsdee46362016-06-27 17:11:19 +0100350 rxrpc_call_is_secure(
351 rcu_dereference_protected(
David Howellsa1399f82016-06-27 14:39:44 +0100352 conn->channels[loop].call,
353 lockdep_is_held(&conn->channel_lock)));
David Howells248f2192016-09-08 11:10:12 +0100354 } else {
355 spin_unlock(&conn->state_lock);
David Howells17926a72007-04-26 15:48:28 -0700356 }
357
David Howellsa1399f82016-06-27 14:39:44 +0100358 spin_unlock(&conn->channel_lock);
David Howells17926a72007-04-26 15:48:28 -0700359 return 0;
360
361 default:
David Howellsfb46f6e2017-04-06 10:12:00 +0100362 trace_rxrpc_rx_eproto(NULL, sp->hdr.serial,
363 tracepoint_string("bad_conn_pkt"));
David Howells17926a72007-04-26 15:48:28 -0700364 return -EPROTO;
365 }
366}
367
368/*
369 * set up security and issue a challenge
370 */
371static void rxrpc_secure_connection(struct rxrpc_connection *conn)
372{
373 u32 abort_code;
374 int ret;
375
376 _enter("{%d}", conn->debug_id);
377
378 ASSERT(conn->security_ix != 0);
David Howells063c60d2019-12-20 16:17:16 +0000379 ASSERT(conn->server_key);
David Howells17926a72007-04-26 15:48:28 -0700380
David Howells17926a72007-04-26 15:48:28 -0700381 if (conn->security->issue_challenge(conn) < 0) {
382 abort_code = RX_CALL_DEAD;
383 ret = -ENOMEM;
384 goto abort;
385 }
386
387 _leave("");
388 return;
389
390abort:
391 _debug("abort %d, %d", ret, abort_code);
David Howells3a927892017-04-06 10:11:56 +0100392 rxrpc_abort_connection(conn, ret, abort_code);
David Howells17926a72007-04-26 15:48:28 -0700393 _leave(" [aborted]");
394}
395
396/*
David Howells3136ef42017-11-24 10:18:41 +0000397 * Process delayed final ACKs that we haven't subsumed into a subsequent call.
398 */
399static void rxrpc_process_delayed_final_acks(struct rxrpc_connection *conn)
400{
401 unsigned long j = jiffies, next_j;
402 unsigned int channel;
403 bool set;
404
405again:
406 next_j = j + LONG_MAX;
407 set = false;
408 for (channel = 0; channel < RXRPC_MAXCALLS; channel++) {
409 struct rxrpc_channel *chan = &conn->channels[channel];
410 unsigned long ack_at;
411
412 if (!test_bit(RXRPC_CONN_FINAL_ACK_0 + channel, &conn->flags))
413 continue;
414
415 smp_rmb(); /* vs rxrpc_disconnect_client_call */
416 ack_at = READ_ONCE(chan->final_ack_at);
417
418 if (time_before(j, ack_at)) {
419 if (time_before(ack_at, next_j)) {
420 next_j = ack_at;
421 set = true;
422 }
423 continue;
424 }
425
426 if (test_and_clear_bit(RXRPC_CONN_FINAL_ACK_0 + channel,
427 &conn->flags))
428 rxrpc_conn_retransmit_call(conn, NULL, channel);
429 }
430
431 j = jiffies;
432 if (time_before_eq(next_j, j))
433 goto again;
434 if (set)
435 rxrpc_reduce_conn_timer(conn, next_j);
436}
437
438/*
David Howells17926a72007-04-26 15:48:28 -0700439 * connection-level event processor
440 */
441void rxrpc_process_connection(struct work_struct *work)
442{
443 struct rxrpc_connection *conn =
444 container_of(work, struct rxrpc_connection, processor);
David Howells17926a72007-04-26 15:48:28 -0700445 struct sk_buff *skb;
446 u32 abort_code = RX_PROTOCOL_ERROR;
447 int ret;
448
David Howells363deea2016-09-17 10:49:14 +0100449 rxrpc_see_connection(conn);
David Howells17926a72007-04-26 15:48:28 -0700450
David Howells2c4579e2016-06-27 10:32:03 +0100451 if (test_and_clear_bit(RXRPC_CONN_EV_CHALLENGE, &conn->events))
David Howells17926a72007-04-26 15:48:28 -0700452 rxrpc_secure_connection(conn);
David Howells17926a72007-04-26 15:48:28 -0700453
David Howells3136ef42017-11-24 10:18:41 +0000454 /* Process delayed ACKs whose time has come. */
455 if (conn->flags & RXRPC_CONN_FINAL_ACK_MASK)
456 rxrpc_process_delayed_final_acks(conn);
457
David Howells17926a72007-04-26 15:48:28 -0700458 /* go through the conn-level event packets, releasing the ref on this
459 * connection that each one has when we've finished with it */
460 while ((skb = skb_dequeue(&conn->rx_queue))) {
David Howells987db9f2019-08-19 09:25:38 +0100461 rxrpc_see_skb(skb, rxrpc_skb_seen);
David Howells17926a72007-04-26 15:48:28 -0700462 ret = rxrpc_process_event(conn, skb, &abort_code);
463 switch (ret) {
464 case -EPROTO:
465 case -EKEYEXPIRED:
466 case -EKEYREJECTED:
467 goto protocol_error;
David Howells8c2f8262018-02-08 15:59:07 +0000468 case -ENOMEM:
David Howells17926a72007-04-26 15:48:28 -0700469 case -EAGAIN:
470 goto requeue_and_leave;
471 case -ECONNABORTED:
472 default:
David Howells987db9f2019-08-19 09:25:38 +0100473 rxrpc_free_skb(skb, rxrpc_skb_freed);
David Howells17926a72007-04-26 15:48:28 -0700474 break;
475 }
476 }
477
478out:
479 rxrpc_put_connection(conn);
480 _leave("");
481 return;
482
483requeue_and_leave:
484 skb_queue_head(&conn->rx_queue, skb);
485 goto out;
486
487protocol_error:
David Howells3a927892017-04-06 10:11:56 +0100488 if (rxrpc_abort_connection(conn, ret, abort_code) < 0)
David Howells17926a72007-04-26 15:48:28 -0700489 goto requeue_and_leave;
David Howells987db9f2019-08-19 09:25:38 +0100490 rxrpc_free_skb(skb, rxrpc_skb_freed);
David Howells17926a72007-04-26 15:48:28 -0700491 goto out;
492}