Commit | Line | Data |
---|---|---|
2874c5fd | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
96b2d69b | 2 | /* Processing of received RxRPC packets |
17926a79 | 3 | * |
96b2d69b | 4 | * Copyright (C) 2020 Red Hat, Inc. All Rights Reserved. |
17926a79 | 5 | * Written by David Howells (dhowells@redhat.com) |
17926a79 DH |
6 | */ |
7 | ||
9b6d5398 JP |
8 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
9 | ||
17926a79 DH |
10 | #include "ar-internal.h" |
11 | ||
248f219c DH |
12 | static void rxrpc_proto_abort(const char *why, |
13 | struct rxrpc_call *call, rxrpc_seq_t seq) | |
14 | { | |
3a92789a | 15 | if (rxrpc_abort_call(why, call, seq, RX_PROTOCOL_ERROR, -EBADMSG)) { |
248f219c | 16 | set_bit(RXRPC_CALL_EV_ABORT, &call->events); |
cb0fc0c9 | 17 | rxrpc_queue_call(call, rxrpc_call_queue_abort); |
248f219c DH |
18 | } |
19 | } | |
20 | ||
57494343 DH |
21 | /* |
22 | * Do TCP-style congestion management [RFC 5681]. | |
23 | */ | |
24 | static void rxrpc_congestion_management(struct rxrpc_call *call, | |
25 | struct sk_buff *skb, | |
ed1e8679 DH |
26 | struct rxrpc_ack_summary *summary, |
27 | rxrpc_serial_t acked_serial) | |
57494343 DH |
28 | { |
29 | enum rxrpc_congest_change change = rxrpc_cong_no_change; | |
57494343 DH |
30 | unsigned int cumulative_acks = call->cong_cumul_acks; |
31 | unsigned int cwnd = call->cong_cwnd; | |
32 | bool resend = false; | |
33 | ||
34 | summary->flight_size = | |
a4ea4c47 | 35 | (call->tx_top - call->acks_hard_ack) - summary->nr_acks; |
57494343 DH |
36 | |
37 | if (test_and_clear_bit(RXRPC_CALL_RETRANS_TIMEOUT, &call->flags)) { | |
38 | summary->retrans_timeo = true; | |
39 | call->cong_ssthresh = max_t(unsigned int, | |
40 | summary->flight_size / 2, 2); | |
41 | cwnd = 1; | |
8782def2 | 42 | if (cwnd >= call->cong_ssthresh && |
57494343 DH |
43 | call->cong_mode == RXRPC_CALL_SLOW_START) { |
44 | call->cong_mode = RXRPC_CALL_CONGEST_AVOIDANCE; | |
45 | call->cong_tstamp = skb->tstamp; | |
46 | cumulative_acks = 0; | |
47 | } | |
48 | } | |
49 | ||
50 | cumulative_acks += summary->nr_new_acks; | |
51 | cumulative_acks += summary->nr_rot_new_acks; | |
52 | if (cumulative_acks > 255) | |
53 | cumulative_acks = 255; | |
54 | ||
55 | summary->mode = call->cong_mode; | |
56 | summary->cwnd = call->cong_cwnd; | |
57 | summary->ssthresh = call->cong_ssthresh; | |
58 | summary->cumulative_acks = cumulative_acks; | |
59 | summary->dup_acks = call->cong_dup_acks; | |
60 | ||
1fc4fa2a DH |
61 | /* If we haven't transmitted anything for >1RTT, we should reset the |
62 | * congestion management state. | |
63 | */ | |
64 | if ((call->cong_mode == RXRPC_CALL_SLOW_START || | |
65 | call->cong_mode == RXRPC_CALL_CONGEST_AVOIDANCE) && | |
66 | ktime_before(ktime_add_us(call->tx_last_sent, | |
67 | call->peer->srtt_us >> 3), | |
68 | ktime_get_real()) | |
69 | ) { | |
70 | change = rxrpc_cong_idle_reset; | |
71 | summary->mode = RXRPC_CALL_SLOW_START; | |
72 | if (RXRPC_TX_SMSS > 2190) | |
73 | summary->cwnd = 2; | |
74 | else if (RXRPC_TX_SMSS > 1095) | |
75 | summary->cwnd = 3; | |
76 | else | |
77 | summary->cwnd = 4; | |
78 | } | |
79 | ||
57494343 DH |
80 | switch (call->cong_mode) { |
81 | case RXRPC_CALL_SLOW_START: | |
d57a3a15 | 82 | if (summary->saw_nacks) |
57494343 DH |
83 | goto packet_loss_detected; |
84 | if (summary->cumulative_acks > 0) | |
85 | cwnd += 1; | |
8782def2 | 86 | if (cwnd >= call->cong_ssthresh) { |
57494343 DH |
87 | call->cong_mode = RXRPC_CALL_CONGEST_AVOIDANCE; |
88 | call->cong_tstamp = skb->tstamp; | |
89 | } | |
90 | goto out; | |
91 | ||
92 | case RXRPC_CALL_CONGEST_AVOIDANCE: | |
d57a3a15 | 93 | if (summary->saw_nacks) |
57494343 DH |
94 | goto packet_loss_detected; |
95 | ||
96 | /* We analyse the number of packets that get ACK'd per RTT | |
97 | * period and increase the window if we managed to fill it. | |
98 | */ | |
c410bf01 | 99 | if (call->peer->rtt_count == 0) |
57494343 DH |
100 | goto out; |
101 | if (ktime_before(skb->tstamp, | |
c410bf01 DH |
102 | ktime_add_us(call->cong_tstamp, |
103 | call->peer->srtt_us >> 3))) | |
57494343 DH |
104 | goto out_no_clear_ca; |
105 | change = rxrpc_cong_rtt_window_end; | |
106 | call->cong_tstamp = skb->tstamp; | |
107 | if (cumulative_acks >= cwnd) | |
108 | cwnd++; | |
109 | goto out; | |
110 | ||
111 | case RXRPC_CALL_PACKET_LOSS: | |
d57a3a15 | 112 | if (!summary->saw_nacks) |
57494343 DH |
113 | goto resume_normality; |
114 | ||
115 | if (summary->new_low_nack) { | |
116 | change = rxrpc_cong_new_low_nack; | |
117 | call->cong_dup_acks = 1; | |
118 | if (call->cong_extra > 1) | |
119 | call->cong_extra = 1; | |
120 | goto send_extra_data; | |
121 | } | |
122 | ||
123 | call->cong_dup_acks++; | |
124 | if (call->cong_dup_acks < 3) | |
125 | goto send_extra_data; | |
126 | ||
127 | change = rxrpc_cong_begin_retransmission; | |
128 | call->cong_mode = RXRPC_CALL_FAST_RETRANSMIT; | |
129 | call->cong_ssthresh = max_t(unsigned int, | |
130 | summary->flight_size / 2, 2); | |
131 | cwnd = call->cong_ssthresh + 3; | |
132 | call->cong_extra = 0; | |
133 | call->cong_dup_acks = 0; | |
134 | resend = true; | |
135 | goto out; | |
136 | ||
137 | case RXRPC_CALL_FAST_RETRANSMIT: | |
138 | if (!summary->new_low_nack) { | |
139 | if (summary->nr_new_acks == 0) | |
140 | cwnd += 1; | |
141 | call->cong_dup_acks++; | |
142 | if (call->cong_dup_acks == 2) { | |
143 | change = rxrpc_cong_retransmit_again; | |
144 | call->cong_dup_acks = 0; | |
145 | resend = true; | |
146 | } | |
147 | } else { | |
148 | change = rxrpc_cong_progress; | |
149 | cwnd = call->cong_ssthresh; | |
d57a3a15 | 150 | if (!summary->saw_nacks) |
57494343 DH |
151 | goto resume_normality; |
152 | } | |
153 | goto out; | |
154 | ||
155 | default: | |
156 | BUG(); | |
157 | goto out; | |
158 | } | |
159 | ||
160 | resume_normality: | |
161 | change = rxrpc_cong_cleared_nacks; | |
162 | call->cong_dup_acks = 0; | |
163 | call->cong_extra = 0; | |
164 | call->cong_tstamp = skb->tstamp; | |
8782def2 | 165 | if (cwnd < call->cong_ssthresh) |
57494343 DH |
166 | call->cong_mode = RXRPC_CALL_SLOW_START; |
167 | else | |
168 | call->cong_mode = RXRPC_CALL_CONGEST_AVOIDANCE; | |
169 | out: | |
170 | cumulative_acks = 0; | |
171 | out_no_clear_ca: | |
a4ea4c47 DH |
172 | if (cwnd >= RXRPC_TX_MAX_WINDOW) |
173 | cwnd = RXRPC_TX_MAX_WINDOW; | |
57494343 DH |
174 | call->cong_cwnd = cwnd; |
175 | call->cong_cumul_acks = cumulative_acks; | |
ed1e8679 | 176 | trace_rxrpc_congest(call, summary, acked_serial, change); |
57494343 | 177 | if (resend && !test_and_set_bit(RXRPC_CALL_EV_RESEND, &call->events)) |
cb0fc0c9 | 178 | rxrpc_queue_call(call, rxrpc_call_queue_resend); |
57494343 DH |
179 | return; |
180 | ||
181 | packet_loss_detected: | |
182 | change = rxrpc_cong_saw_nack; | |
183 | call->cong_mode = RXRPC_CALL_PACKET_LOSS; | |
184 | call->cong_dup_acks = 0; | |
185 | goto send_extra_data; | |
186 | ||
187 | send_extra_data: | |
188 | /* Send some previously unsent DATA if we have some to advance the ACK | |
189 | * state. | |
190 | */ | |
a4ea4c47 DH |
191 | if (test_bit(RXRPC_CALL_TX_LAST, &call->flags) || |
192 | summary->nr_acks != call->tx_top - call->acks_hard_ack) { | |
57494343 DH |
193 | call->cong_extra++; |
194 | wake_up(&call->waitq); | |
195 | } | |
196 | goto out_no_clear_ca; | |
197 | } | |
198 | ||
17926a79 | 199 | /* |
248f219c | 200 | * Apply a hard ACK by advancing the Tx window. |
17926a79 | 201 | */ |
c479d5f2 | 202 | static bool rxrpc_rotate_tx_window(struct rxrpc_call *call, rxrpc_seq_t to, |
31a1b989 | 203 | struct rxrpc_ack_summary *summary) |
17926a79 | 204 | { |
a4ea4c47 | 205 | struct rxrpc_txbuf *txb; |
c479d5f2 | 206 | bool rot_last = false; |
17926a79 | 207 | |
a4ea4c47 DH |
208 | list_for_each_entry_rcu(txb, &call->tx_buffer, call_link, false) { |
209 | if (before_eq(txb->seq, call->acks_hard_ack)) | |
210 | continue; | |
d57a3a15 | 211 | summary->nr_rot_new_acks++; |
a4ea4c47 | 212 | if (test_bit(RXRPC_TXBUF_LAST, &txb->flags)) { |
70790dbe | 213 | set_bit(RXRPC_CALL_TX_LAST, &call->flags); |
c479d5f2 DH |
214 | rot_last = true; |
215 | } | |
a4ea4c47 DH |
216 | if (txb->seq == to) |
217 | break; | |
248f219c | 218 | } |
17926a79 | 219 | |
a4ea4c47 DH |
220 | if (rot_last) |
221 | set_bit(RXRPC_CALL_TX_ALL_ACKED, &call->flags); | |
17926a79 | 222 | |
a4ea4c47 | 223 | _enter("%x,%x,%x,%d", to, call->acks_hard_ack, call->tx_top, rot_last); |
bc4abfcf | 224 | |
a4ea4c47 DH |
225 | if (call->acks_lowest_nak == call->acks_hard_ack) { |
226 | call->acks_lowest_nak = to; | |
1fc4fa2a | 227 | } else if (after(to, call->acks_lowest_nak)) { |
a4ea4c47 DH |
228 | summary->new_low_nack = true; |
229 | call->acks_lowest_nak = to; | |
17926a79 | 230 | } |
c479d5f2 | 231 | |
a4ea4c47 DH |
232 | smp_store_release(&call->acks_hard_ack, to); |
233 | ||
234 | trace_rxrpc_txqueue(call, (rot_last ? | |
235 | rxrpc_txqueue_rotate_last : | |
236 | rxrpc_txqueue_rotate)); | |
237 | wake_up(&call->waitq); | |
c479d5f2 | 238 | return rot_last; |
248f219c | 239 | } |
17926a79 | 240 | |
248f219c DH |
241 | /* |
242 | * End the transmission phase of a call. | |
243 | * | |
244 | * This occurs when we get an ACKALL packet, the first DATA packet of a reply, | |
245 | * or a final ACK packet. | |
246 | */ | |
70790dbe DH |
247 | static bool rxrpc_end_tx_phase(struct rxrpc_call *call, bool reply_begun, |
248 | const char *abort_why) | |
248f219c | 249 | { |
dfe99522 | 250 | unsigned int state; |
17926a79 | 251 | |
70790dbe | 252 | ASSERT(test_bit(RXRPC_CALL_TX_LAST, &call->flags)); |
17926a79 | 253 | |
248f219c | 254 | write_lock(&call->state_lock); |
651350d1 | 255 | |
dfe99522 DH |
256 | state = call->state; |
257 | switch (state) { | |
70790dbe | 258 | case RXRPC_CALL_CLIENT_SEND_REQUEST: |
248f219c | 259 | case RXRPC_CALL_CLIENT_AWAIT_REPLY: |
70790dbe | 260 | if (reply_begun) |
dfe99522 | 261 | call->state = state = RXRPC_CALL_CLIENT_RECV_REPLY; |
70790dbe | 262 | else |
dfe99522 | 263 | call->state = state = RXRPC_CALL_CLIENT_AWAIT_REPLY; |
248f219c | 264 | break; |
70790dbe | 265 | |
248f219c DH |
266 | case RXRPC_CALL_SERVER_AWAIT_ACK: |
267 | __rxrpc_call_completed(call); | |
dfe99522 | 268 | state = call->state; |
248f219c | 269 | break; |
70790dbe DH |
270 | |
271 | default: | |
272 | goto bad_state; | |
17926a79 | 273 | } |
17926a79 | 274 | |
248f219c | 275 | write_unlock(&call->state_lock); |
dfe99522 | 276 | if (state == RXRPC_CALL_CLIENT_AWAIT_REPLY) |
a4ea4c47 | 277 | trace_rxrpc_txqueue(call, rxrpc_txqueue_await_reply); |
dfe99522 | 278 | else |
a4ea4c47 | 279 | trace_rxrpc_txqueue(call, rxrpc_txqueue_end); |
248f219c DH |
280 | _leave(" = ok"); |
281 | return true; | |
70790dbe DH |
282 | |
283 | bad_state: | |
284 | write_unlock(&call->state_lock); | |
285 | kdebug("end_tx %s", rxrpc_call_states[call->state]); | |
286 | rxrpc_proto_abort(abort_why, call, call->tx_top); | |
287 | return false; | |
288 | } | |
289 | ||
290 | /* | |
291 | * Begin the reply reception phase of a call. | |
292 | */ | |
293 | static bool rxrpc_receiving_reply(struct rxrpc_call *call) | |
294 | { | |
31a1b989 | 295 | struct rxrpc_ack_summary summary = { 0 }; |
a158bdd3 | 296 | unsigned long now, timo; |
70790dbe DH |
297 | rxrpc_seq_t top = READ_ONCE(call->tx_top); |
298 | ||
dd7c1ee5 | 299 | if (call->ackr_reason) { |
a158bdd3 DH |
300 | now = jiffies; |
301 | timo = now + MAX_JIFFY_OFFSET; | |
302 | WRITE_ONCE(call->resend_at, timo); | |
530403d9 | 303 | WRITE_ONCE(call->delay_ack_at, timo); |
a158bdd3 | 304 | trace_rxrpc_timer(call, rxrpc_timer_init_for_reply, now); |
dd7c1ee5 DH |
305 | } |
306 | ||
70790dbe | 307 | if (!test_bit(RXRPC_CALL_TX_LAST, &call->flags)) { |
c479d5f2 DH |
308 | if (!rxrpc_rotate_tx_window(call, top, &summary)) { |
309 | rxrpc_proto_abort("TXL", call, top); | |
310 | return false; | |
311 | } | |
70790dbe | 312 | } |
a11e6ff9 | 313 | return rxrpc_end_tx_phase(call, true, "ETD"); |
248f219c DH |
314 | } |
315 | ||
5d7edbc9 DH |
316 | static void rxrpc_input_update_ack_window(struct rxrpc_call *call, |
317 | rxrpc_seq_t window, rxrpc_seq_t wtop) | |
318 | { | |
319 | atomic64_set_release(&call->ackr_window, ((u64)wtop) << 32 | window); | |
320 | } | |
321 | ||
248f219c | 322 | /* |
5d7edbc9 DH |
323 | * Push a DATA packet onto the Rx queue. |
324 | */ | |
325 | static void rxrpc_input_queue_data(struct rxrpc_call *call, struct sk_buff *skb, | |
326 | rxrpc_seq_t window, rxrpc_seq_t wtop, | |
327 | enum rxrpc_receive_trace why) | |
328 | { | |
329 | struct rxrpc_skb_priv *sp = rxrpc_skb(skb); | |
330 | bool last = sp->hdr.flags & RXRPC_LAST_PACKET; | |
331 | ||
332 | __skb_queue_tail(&call->recvmsg_queue, skb); | |
333 | rxrpc_input_update_ack_window(call, window, wtop); | |
334 | ||
335 | trace_rxrpc_receive(call, last ? why + 1 : why, sp->hdr.serial, sp->hdr.seq); | |
336 | } | |
337 | ||
338 | /* | |
339 | * Process a DATA packet. | |
248f219c | 340 | */ |
2d1faf7a DH |
341 | static void rxrpc_input_data_one(struct rxrpc_call *call, struct sk_buff *skb, |
342 | bool *_notify) | |
248f219c DH |
343 | { |
344 | struct rxrpc_skb_priv *sp = rxrpc_skb(skb); | |
5d7edbc9 | 345 | struct sk_buff *oos; |
d4d02d8b | 346 | rxrpc_serial_t serial = sp->hdr.serial; |
5d7edbc9 DH |
347 | u64 win = atomic64_read(&call->ackr_window); |
348 | rxrpc_seq_t window = lower_32_bits(win); | |
349 | rxrpc_seq_t wtop = upper_32_bits(win); | |
350 | rxrpc_seq_t wlimit = window + call->rx_winsize - 1; | |
351 | rxrpc_seq_t seq = sp->hdr.seq; | |
d4d02d8b | 352 | bool last = sp->hdr.flags & RXRPC_LAST_PACKET; |
5d7edbc9 | 353 | int ack_reason = -1; |
248f219c | 354 | |
d4d02d8b DH |
355 | rxrpc_inc_stat(call->rxnet, stat_rx_data); |
356 | if (sp->hdr.flags & RXRPC_REQUEST_ACK) | |
357 | rxrpc_inc_stat(call->rxnet, stat_rx_data_reqack); | |
358 | if (sp->hdr.flags & RXRPC_JUMBO_PACKET) | |
359 | rxrpc_inc_stat(call->rxnet, stat_rx_data_jumbo); | |
c3c9e3df | 360 | |
d4d02d8b | 361 | if (last) { |
5d7edbc9 DH |
362 | if (test_and_set_bit(RXRPC_CALL_RX_LAST, &call->flags) && |
363 | seq + 1 != wtop) { | |
d4d02d8b | 364 | rxrpc_proto_abort("LSN", call, seq); |
2d1faf7a | 365 | return; |
d4d02d8b DH |
366 | } |
367 | } else { | |
368 | if (test_bit(RXRPC_CALL_RX_LAST, &call->flags) && | |
5d7edbc9 DH |
369 | after_eq(seq, wtop)) { |
370 | pr_warn("Packet beyond last: c=%x q=%x window=%x-%x wlimit=%x\n", | |
371 | call->debug_id, seq, window, wtop, wlimit); | |
d4d02d8b | 372 | rxrpc_proto_abort("LSA", call, seq); |
2d1faf7a | 373 | return; |
d4d02d8b | 374 | } |
c3c9e3df | 375 | } |
248f219c | 376 | |
5d7edbc9 DH |
377 | if (after(seq, call->rx_highest_seq)) |
378 | call->rx_highest_seq = seq; | |
379 | ||
d4d02d8b | 380 | trace_rxrpc_rx_data(call->debug_id, seq, serial, sp->hdr.flags); |
17926a79 | 381 | |
5d7edbc9 DH |
382 | if (before(seq, window)) { |
383 | ack_reason = RXRPC_ACK_DUPLICATE; | |
384 | goto send_ack; | |
d4d02d8b | 385 | } |
5d7edbc9 DH |
386 | if (after(seq, wlimit)) { |
387 | ack_reason = RXRPC_ACK_EXCEEDS_WINDOW; | |
388 | goto send_ack; | |
d4d02d8b DH |
389 | } |
390 | ||
5d7edbc9 DH |
391 | /* Queue the packet. */ |
392 | if (seq == window) { | |
393 | rxrpc_seq_t reset_from; | |
394 | bool reset_sack = false; | |
d4d02d8b | 395 | |
5d7edbc9 DH |
396 | if (sp->hdr.flags & RXRPC_REQUEST_ACK) |
397 | ack_reason = RXRPC_ACK_REQUESTED; | |
398 | /* Send an immediate ACK if we fill in a hole */ | |
399 | else if (!skb_queue_empty(&call->rx_oos_queue)) | |
400 | ack_reason = RXRPC_ACK_DELAY; | |
d4d02d8b | 401 | |
5d7edbc9 DH |
402 | window++; |
403 | if (after(window, wtop)) | |
404 | wtop = window; | |
d4d02d8b | 405 | |
2d1faf7a DH |
406 | rxrpc_get_skb(skb, rxrpc_skb_get_to_recvmsg); |
407 | ||
5d7edbc9 DH |
408 | spin_lock(&call->recvmsg_queue.lock); |
409 | rxrpc_input_queue_data(call, skb, window, wtop, rxrpc_receive_queue); | |
2d1faf7a | 410 | *_notify = true; |
5d7edbc9 DH |
411 | |
412 | while ((oos = skb_peek(&call->rx_oos_queue))) { | |
413 | struct rxrpc_skb_priv *osp = rxrpc_skb(oos); | |
414 | ||
415 | if (after(osp->hdr.seq, window)) | |
416 | break; | |
417 | ||
418 | __skb_unlink(oos, &call->rx_oos_queue); | |
419 | last = osp->hdr.flags & RXRPC_LAST_PACKET; | |
420 | seq = osp->hdr.seq; | |
421 | if (!reset_sack) { | |
422 | reset_from = seq; | |
423 | reset_sack = true; | |
424 | } | |
425 | ||
426 | window++; | |
427 | rxrpc_input_queue_data(call, oos, window, wtop, | |
428 | rxrpc_receive_queue_oos); | |
d4d02d8b | 429 | } |
d4d02d8b | 430 | |
5d7edbc9 | 431 | spin_unlock(&call->recvmsg_queue.lock); |
d4d02d8b | 432 | |
5d7edbc9 DH |
433 | if (reset_sack) { |
434 | do { | |
435 | call->ackr_sack_table[reset_from % RXRPC_SACK_SIZE] = 0; | |
436 | } while (reset_from++, before(reset_from, window)); | |
437 | } | |
d4d02d8b | 438 | } else { |
5d7edbc9 | 439 | bool keep = false; |
d4d02d8b | 440 | |
5d7edbc9 DH |
441 | ack_reason = RXRPC_ACK_OUT_OF_SEQUENCE; |
442 | ||
443 | if (!call->ackr_sack_table[seq % RXRPC_SACK_SIZE]) { | |
444 | call->ackr_sack_table[seq % RXRPC_SACK_SIZE] = 1; | |
445 | keep = 1; | |
446 | } | |
447 | ||
448 | if (after(seq + 1, wtop)) { | |
449 | wtop = seq + 1; | |
450 | rxrpc_input_update_ack_window(call, window, wtop); | |
451 | } | |
452 | ||
453 | if (!keep) { | |
454 | ack_reason = RXRPC_ACK_DUPLICATE; | |
455 | goto send_ack; | |
456 | } | |
457 | ||
458 | skb_queue_walk(&call->rx_oos_queue, oos) { | |
459 | struct rxrpc_skb_priv *osp = rxrpc_skb(oos); | |
460 | ||
461 | if (after(osp->hdr.seq, seq)) { | |
2d1faf7a | 462 | rxrpc_get_skb(skb, rxrpc_skb_get_to_recvmsg_oos); |
5d7edbc9 DH |
463 | __skb_queue_before(&call->rx_oos_queue, oos, skb); |
464 | goto oos_queued; | |
465 | } | |
d4d02d8b | 466 | } |
5d7edbc9 | 467 | |
2d1faf7a | 468 | rxrpc_get_skb(skb, rxrpc_skb_get_to_recvmsg_oos); |
5d7edbc9 DH |
469 | __skb_queue_tail(&call->rx_oos_queue, skb); |
470 | oos_queued: | |
471 | trace_rxrpc_receive(call, last ? rxrpc_receive_oos_last : rxrpc_receive_oos, | |
472 | sp->hdr.serial, sp->hdr.seq); | |
d4d02d8b DH |
473 | } |
474 | ||
5d7edbc9 DH |
475 | send_ack: |
476 | if (ack_reason < 0 && | |
477 | atomic_inc_return(&call->ackr_nr_unacked) > 2 && | |
478 | test_and_set_bit(RXRPC_CALL_IDLE_ACK_PENDING, &call->flags)) { | |
479 | ack_reason = RXRPC_ACK_IDLE; | |
480 | } else if (ack_reason >= 0) { | |
481 | set_bit(RXRPC_CALL_IDLE_ACK_PENDING, &call->flags); | |
482 | } | |
483 | ||
484 | if (ack_reason >= 0) | |
485 | rxrpc_send_ACK(call, ack_reason, serial, | |
d4d02d8b DH |
486 | rxrpc_propose_ack_input_data); |
487 | else | |
488 | rxrpc_propose_delay_ACK(call, serial, | |
489 | rxrpc_propose_ack_input_data); | |
17926a79 DH |
490 | } |
491 | ||
492 | /* | |
d4d02d8b | 493 | * Split a jumbo packet and file the bits separately. |
17926a79 | 494 | */ |
d4d02d8b | 495 | static bool rxrpc_input_split_jumbo(struct rxrpc_call *call, struct sk_buff *skb) |
17926a79 | 496 | { |
d4d02d8b DH |
497 | struct rxrpc_jumbo_header jhdr; |
498 | struct rxrpc_skb_priv *sp = rxrpc_skb(skb), *jsp; | |
499 | struct sk_buff *jskb; | |
500 | unsigned int offset = sizeof(struct rxrpc_wire_header); | |
501 | unsigned int len = skb->len - offset; | |
2d1faf7a | 502 | bool notify = false; |
17926a79 | 503 | |
d4d02d8b DH |
504 | while (sp->hdr.flags & RXRPC_JUMBO_PACKET) { |
505 | if (len < RXRPC_JUMBO_SUBPKTLEN) | |
506 | goto protocol_error; | |
507 | if (sp->hdr.flags & RXRPC_LAST_PACKET) | |
508 | goto protocol_error; | |
509 | if (skb_copy_bits(skb, offset + RXRPC_JUMBO_DATALEN, | |
510 | &jhdr, sizeof(jhdr)) < 0) | |
511 | goto protocol_error; | |
512 | ||
513 | jskb = skb_clone(skb, GFP_ATOMIC); | |
514 | if (!jskb) { | |
515 | kdebug("couldn't clone"); | |
516 | return false; | |
517 | } | |
9a36a6bc | 518 | rxrpc_new_skb(jskb, rxrpc_skb_new_jumbo_subpacket); |
d4d02d8b DH |
519 | jsp = rxrpc_skb(jskb); |
520 | jsp->offset = offset; | |
521 | jsp->len = RXRPC_JUMBO_DATALEN; | |
2d1faf7a DH |
522 | rxrpc_input_data_one(call, jskb, ¬ify); |
523 | rxrpc_free_skb(jskb, rxrpc_skb_put_jumbo_subpacket); | |
d4d02d8b DH |
524 | |
525 | sp->hdr.flags = jhdr.flags; | |
526 | sp->hdr._rsvd = ntohs(jhdr._rsvd); | |
527 | sp->hdr.seq++; | |
528 | sp->hdr.serial++; | |
529 | offset += RXRPC_JUMBO_SUBPKTLEN; | |
530 | len -= RXRPC_JUMBO_SUBPKTLEN; | |
248f219c | 531 | } |
d4d02d8b DH |
532 | |
533 | sp->offset = offset; | |
534 | sp->len = len; | |
2d1faf7a DH |
535 | rxrpc_input_data_one(call, skb, ¬ify); |
536 | if (notify) { | |
537 | trace_rxrpc_notify_socket(call->debug_id, sp->hdr.serial); | |
538 | rxrpc_notify_socket(call); | |
539 | } | |
d4d02d8b DH |
540 | return true; |
541 | ||
542 | protocol_error: | |
543 | return false; | |
248f219c | 544 | } |
17926a79 | 545 | |
248f219c | 546 | /* |
4858e403 DH |
547 | * Process a DATA packet, adding the packet to the Rx ring. The caller's |
548 | * packet ref must be passed on or discarded. | |
248f219c | 549 | */ |
e8c3af6b | 550 | static void rxrpc_input_data(struct rxrpc_call *call, struct sk_buff *skb) |
248f219c DH |
551 | { |
552 | struct rxrpc_skb_priv *sp = rxrpc_skb(skb); | |
146d8fef | 553 | enum rxrpc_call_state state; |
d4d02d8b DH |
554 | rxrpc_serial_t serial = sp->hdr.serial; |
555 | rxrpc_seq_t seq0 = sp->hdr.seq; | |
17926a79 | 556 | |
5d7edbc9 DH |
557 | _enter("{%llx,%x},{%u,%x}", |
558 | atomic64_read(&call->ackr_window), call->rx_highest_seq, | |
559 | skb->len, seq0); | |
17926a79 | 560 | |
146d8fef | 561 | state = READ_ONCE(call->state); |
2d1faf7a | 562 | if (state >= RXRPC_CALL_COMPLETE) |
248f219c | 563 | return; |
17926a79 | 564 | |
d4d02d8b DH |
565 | /* Unshare the packet so that it can be modified for in-place |
566 | * decryption. | |
567 | */ | |
568 | if (sp->hdr.securityIndex != 0) { | |
569 | struct sk_buff *nskb = skb_unshare(skb, GFP_ATOMIC); | |
570 | if (!nskb) { | |
9a36a6bc | 571 | rxrpc_eaten_skb(skb, rxrpc_skb_eaten_by_unshare_nomem); |
d4d02d8b DH |
572 | return; |
573 | } | |
574 | ||
575 | if (nskb != skb) { | |
9a36a6bc | 576 | rxrpc_eaten_skb(skb, rxrpc_skb_eaten_by_unshare); |
d4d02d8b | 577 | skb = nskb; |
9a36a6bc | 578 | rxrpc_new_skb(skb, rxrpc_skb_new_unshared); |
d4d02d8b DH |
579 | sp = rxrpc_skb(skb); |
580 | } | |
581 | } | |
582 | ||
a95d25dd | 583 | if (state == RXRPC_CALL_SERVER_RECV_REQUEST) { |
a158bdd3 DH |
584 | unsigned long timo = READ_ONCE(call->next_req_timo); |
585 | unsigned long now, expect_req_by; | |
586 | ||
587 | if (timo) { | |
588 | now = jiffies; | |
589 | expect_req_by = now + timo; | |
590 | WRITE_ONCE(call->expect_req_by, expect_req_by); | |
591 | rxrpc_reduce_call_timer(call, expect_req_by, now, | |
592 | rxrpc_timer_set_for_idle); | |
593 | } | |
594 | } | |
595 | ||
248f219c DH |
596 | /* Received data implicitly ACKs all of the request packets we sent |
597 | * when we're acting as a client. | |
598 | */ | |
146d8fef DH |
599 | if ((state == RXRPC_CALL_CLIENT_SEND_REQUEST || |
600 | state == RXRPC_CALL_CLIENT_AWAIT_REPLY) && | |
70790dbe | 601 | !rxrpc_receiving_reply(call)) |
d4d02d8b | 602 | goto out; |
72f0c6fb | 603 | |
d4d02d8b DH |
604 | if (!rxrpc_input_split_jumbo(call, skb)) { |
605 | rxrpc_proto_abort("VLD", call, sp->hdr.seq); | |
606 | goto out; | |
248f219c | 607 | } |
d4d02d8b | 608 | skb = NULL; |
17926a79 | 609 | |
d4d02d8b | 610 | out: |
f71dbf2f DH |
611 | trace_rxrpc_notify_socket(call->debug_id, serial); |
612 | rxrpc_notify_socket(call); | |
248f219c | 613 | _leave(" [queued]"); |
17926a79 DH |
614 | } |
615 | ||
50235c4b | 616 | /* |
4700c4d8 | 617 | * See if there's a cached RTT probe to complete. |
50235c4b | 618 | */ |
4700c4d8 DH |
619 | static void rxrpc_complete_rtt_probe(struct rxrpc_call *call, |
620 | ktime_t resp_time, | |
621 | rxrpc_serial_t acked_serial, | |
622 | rxrpc_serial_t ack_serial, | |
623 | enum rxrpc_rtt_rx_trace type) | |
50235c4b | 624 | { |
4700c4d8 DH |
625 | rxrpc_serial_t orig_serial; |
626 | unsigned long avail; | |
50235c4b | 627 | ktime_t sent_at; |
4700c4d8 DH |
628 | bool matched = false; |
629 | int i; | |
50235c4b | 630 | |
4700c4d8 DH |
631 | avail = READ_ONCE(call->rtt_avail); |
632 | smp_rmb(); /* Read avail bits before accessing data. */ | |
50235c4b | 633 | |
4700c4d8 DH |
634 | for (i = 0; i < ARRAY_SIZE(call->rtt_serial); i++) { |
635 | if (!test_bit(i + RXRPC_CALL_RTT_PEND_SHIFT, &avail)) | |
50235c4b | 636 | continue; |
b604dd98 | 637 | |
4700c4d8 DH |
638 | sent_at = call->rtt_sent_at[i]; |
639 | orig_serial = call->rtt_serial[i]; | |
640 | ||
641 | if (orig_serial == acked_serial) { | |
642 | clear_bit(i + RXRPC_CALL_RTT_PEND_SHIFT, &call->rtt_avail); | |
643 | smp_mb(); /* Read data before setting avail bit */ | |
644 | set_bit(i, &call->rtt_avail); | |
645 | if (type != rxrpc_rtt_rx_cancel) | |
646 | rxrpc_peer_add_rtt(call, type, i, acked_serial, ack_serial, | |
647 | sent_at, resp_time); | |
648 | else | |
649 | trace_rxrpc_rtt_rx(call, rxrpc_rtt_rx_cancel, i, | |
650 | orig_serial, acked_serial, 0, 0); | |
651 | matched = true; | |
652 | } | |
653 | ||
654 | /* If a later serial is being acked, then mark this slot as | |
655 | * being available. | |
656 | */ | |
657 | if (after(acked_serial, orig_serial)) { | |
658 | trace_rxrpc_rtt_rx(call, rxrpc_rtt_rx_obsolete, i, | |
659 | orig_serial, acked_serial, 0, 0); | |
660 | clear_bit(i + RXRPC_CALL_RTT_PEND_SHIFT, &call->rtt_avail); | |
661 | smp_wmb(); | |
662 | set_bit(i, &call->rtt_avail); | |
663 | } | |
664 | } | |
50235c4b | 665 | |
4700c4d8 DH |
666 | if (!matched) |
667 | trace_rxrpc_rtt_rx(call, rxrpc_rtt_rx_lost, 9, 0, acked_serial, 0, 0); | |
50235c4b DH |
668 | } |
669 | ||
bd1fdf8c DH |
670 | /* |
671 | * Process the response to a ping that we sent to find out if we lost an ACK. | |
672 | * | |
673 | * If we got back a ping response that indicates a lower tx_top than what we | |
674 | * had at the time of the ping transmission, we adjudge all the DATA packets | |
675 | * sent between the response tx_top and the ping-time tx_top to have been lost. | |
676 | */ | |
677 | static void rxrpc_input_check_for_lost_ack(struct rxrpc_call *call) | |
678 | { | |
d57a3a15 DH |
679 | if (after(call->acks_lost_top, call->acks_prev_seq) && |
680 | !test_and_set_bit(RXRPC_CALL_EV_RESEND, &call->events)) | |
cb0fc0c9 | 681 | rxrpc_queue_call(call, rxrpc_call_queue_resend); |
bd1fdf8c DH |
682 | } |
683 | ||
8e83134d DH |
684 | /* |
685 | * Process a ping response. | |
686 | */ | |
687 | static void rxrpc_input_ping_response(struct rxrpc_call *call, | |
688 | ktime_t resp_time, | |
4700c4d8 | 689 | rxrpc_serial_t acked_serial, |
8e83134d DH |
690 | rxrpc_serial_t ack_serial) |
691 | { | |
4700c4d8 | 692 | if (acked_serial == call->acks_lost_ping) |
bd1fdf8c | 693 | rxrpc_input_check_for_lost_ack(call); |
8e83134d DH |
694 | } |
695 | ||
17926a79 | 696 | /* |
248f219c | 697 | * Process the extra information that may be appended to an ACK packet |
17926a79 | 698 | */ |
248f219c DH |
699 | static void rxrpc_input_ackinfo(struct rxrpc_call *call, struct sk_buff *skb, |
700 | struct rxrpc_ackinfo *ackinfo) | |
17926a79 | 701 | { |
248f219c DH |
702 | struct rxrpc_skb_priv *sp = rxrpc_skb(skb); |
703 | struct rxrpc_peer *peer; | |
704 | unsigned int mtu; | |
702f2ac8 | 705 | bool wake = false; |
01fd0742 | 706 | u32 rwind = ntohl(ackinfo->rwind); |
248f219c | 707 | |
a4ea4c47 DH |
708 | if (rwind > RXRPC_TX_MAX_WINDOW) |
709 | rwind = RXRPC_TX_MAX_WINDOW; | |
702f2ac8 | 710 | if (call->tx_winsize != rwind) { |
702f2ac8 DH |
711 | if (rwind > call->tx_winsize) |
712 | wake = true; | |
a2ad7c21 | 713 | trace_rxrpc_rx_rwind_change(call, sp->hdr.serial, rwind, wake); |
702f2ac8 DH |
714 | call->tx_winsize = rwind; |
715 | } | |
716 | ||
08511150 DH |
717 | if (call->cong_ssthresh > rwind) |
718 | call->cong_ssthresh = rwind; | |
248f219c DH |
719 | |
720 | mtu = min(ntohl(ackinfo->rxMTU), ntohl(ackinfo->maxMTU)); | |
721 | ||
722 | peer = call->peer; | |
723 | if (mtu < peer->maxdata) { | |
724 | spin_lock_bh(&peer->lock); | |
725 | peer->maxdata = mtu; | |
726 | peer->mtu = mtu + peer->hdrsize; | |
727 | spin_unlock_bh(&peer->lock); | |
248f219c | 728 | } |
702f2ac8 DH |
729 | |
730 | if (wake) | |
731 | wake_up(&call->waitq); | |
248f219c | 732 | } |
17926a79 | 733 | |
248f219c DH |
734 | /* |
735 | * Process individual soft ACKs. | |
736 | * | |
737 | * Each ACK in the array corresponds to one packet and can be either an ACK or | |
738 | * a NAK. If we get find an explicitly NAK'd packet we resend immediately; | |
739 | * packets that lie beyond the end of the ACK list are scheduled for resend by | |
740 | * the timer on the basis that the peer might just not have processed them at | |
741 | * the time the ACK was sent. | |
742 | */ | |
743 | static void rxrpc_input_soft_acks(struct rxrpc_call *call, u8 *acks, | |
31a1b989 DH |
744 | rxrpc_seq_t seq, int nr_acks, |
745 | struct rxrpc_ack_summary *summary) | |
248f219c | 746 | { |
d57a3a15 | 747 | unsigned int i; |
a4ea4c47 | 748 | |
d57a3a15 DH |
749 | for (i = 0; i < nr_acks; i++) { |
750 | if (acks[i] == RXRPC_ACK_TYPE_ACK) { | |
31a1b989 | 751 | summary->nr_acks++; |
31a1b989 | 752 | summary->nr_new_acks++; |
d57a3a15 DH |
753 | } else { |
754 | if (!summary->saw_nacks && | |
755 | call->acks_lowest_nak != seq + i) { | |
756 | call->acks_lowest_nak = seq + i; | |
31a1b989 DH |
757 | summary->new_low_nack = true; |
758 | } | |
d57a3a15 | 759 | summary->saw_nacks = true; |
17926a79 | 760 | } |
17926a79 DH |
761 | } |
762 | } | |
763 | ||
441fdee1 DH |
764 | /* |
765 | * Return true if the ACK is valid - ie. it doesn't appear to have regressed | |
766 | * with respect to the ack state conveyed by preceding ACKs. | |
767 | */ | |
768 | static bool rxrpc_is_ack_valid(struct rxrpc_call *call, | |
769 | rxrpc_seq_t first_pkt, rxrpc_seq_t prev_pkt) | |
770 | { | |
8940ba3c | 771 | rxrpc_seq_t base = READ_ONCE(call->acks_first_seq); |
441fdee1 DH |
772 | |
773 | if (after(first_pkt, base)) | |
774 | return true; /* The window advanced */ | |
775 | ||
776 | if (before(first_pkt, base)) | |
777 | return false; /* firstPacket regressed */ | |
778 | ||
8940ba3c | 779 | if (after_eq(prev_pkt, call->acks_prev_seq)) |
441fdee1 DH |
780 | return true; /* previousPacket hasn't regressed. */ |
781 | ||
782 | /* Some rx implementations put a serial number in previousPacket. */ | |
783 | if (after_eq(prev_pkt, base + call->tx_winsize)) | |
784 | return false; | |
785 | return true; | |
786 | } | |
787 | ||
17926a79 | 788 | /* |
248f219c DH |
789 | * Process an ACK packet. |
790 | * | |
791 | * ack.firstPacket is the sequence number of the first soft-ACK'd/NAK'd packet | |
792 | * in the ACK array. Anything before that is hard-ACK'd and may be discarded. | |
793 | * | |
794 | * A hard-ACK means that a packet has been processed and may be discarded; a | |
795 | * soft-ACK means that the packet may be discarded and retransmission | |
796 | * requested. A phase is complete when all packets are hard-ACK'd. | |
17926a79 | 797 | */ |
e8c3af6b | 798 | static void rxrpc_input_ack(struct rxrpc_call *call, struct sk_buff *skb) |
17926a79 | 799 | { |
31a1b989 | 800 | struct rxrpc_ack_summary summary = { 0 }; |
d57a3a15 | 801 | struct rxrpc_ackpacket ack; |
17926a79 | 802 | struct rxrpc_skb_priv *sp = rxrpc_skb(skb); |
d57a3a15 | 803 | struct rxrpc_ackinfo info; |
2d1faf7a | 804 | struct sk_buff *skb_old = NULL; |
68528d93 | 805 | rxrpc_serial_t ack_serial, acked_serial; |
1a2391c3 | 806 | rxrpc_seq_t first_soft_ack, hard_ack, prev_pkt; |
775e5b71 | 807 | int nr_acks, offset, ioffset; |
248f219c DH |
808 | |
809 | _enter(""); | |
810 | ||
775e5b71 | 811 | offset = sizeof(struct rxrpc_wire_header); |
d57a3a15 DH |
812 | if (skb_copy_bits(skb, offset, &ack, sizeof(ack)) < 0) { |
813 | rxrpc_proto_abort("XAK", call, 0); | |
4041a8ff | 814 | goto out; |
17926a79 | 815 | } |
d57a3a15 | 816 | offset += sizeof(ack); |
248f219c | 817 | |
68528d93 | 818 | ack_serial = sp->hdr.serial; |
d57a3a15 DH |
819 | acked_serial = ntohl(ack.serial); |
820 | first_soft_ack = ntohl(ack.firstPacket); | |
821 | prev_pkt = ntohl(ack.previousPacket); | |
248f219c | 822 | hard_ack = first_soft_ack - 1; |
d57a3a15 DH |
823 | nr_acks = ack.nAcks; |
824 | summary.ack_reason = (ack.reason < RXRPC_ACK__INVALID ? | |
825 | ack.reason : RXRPC_ACK__INVALID); | |
248f219c | 826 | |
68528d93 | 827 | trace_rxrpc_rx_ack(call, ack_serial, acked_serial, |
1a2391c3 | 828 | first_soft_ack, prev_pkt, |
b1d9f7fd | 829 | summary.ack_reason, nr_acks); |
d57a3a15 | 830 | rxrpc_inc_stat(call->rxnet, stat_rx_acks[ack.reason]); |
ec71eb9a | 831 | |
d57a3a15 | 832 | switch (ack.reason) { |
4700c4d8 | 833 | case RXRPC_ACK_PING_RESPONSE: |
4700c4d8 DH |
834 | rxrpc_complete_rtt_probe(call, skb->tstamp, acked_serial, ack_serial, |
835 | rxrpc_rtt_rx_ping_response); | |
836 | break; | |
837 | case RXRPC_ACK_REQUESTED: | |
838 | rxrpc_complete_rtt_probe(call, skb->tstamp, acked_serial, ack_serial, | |
839 | rxrpc_rtt_rx_requested_ack); | |
840 | break; | |
841 | default: | |
842 | if (acked_serial != 0) | |
843 | rxrpc_complete_rtt_probe(call, skb->tstamp, acked_serial, ack_serial, | |
844 | rxrpc_rtt_rx_cancel); | |
845 | break; | |
846 | } | |
8e83134d | 847 | |
d57a3a15 | 848 | if (ack.reason == RXRPC_ACK_PING) { |
72f0c6fb DH |
849 | rxrpc_send_ACK(call, RXRPC_ACK_PING_RESPONSE, ack_serial, |
850 | rxrpc_propose_ack_respond_to_ping); | |
248f219c | 851 | } else if (sp->hdr.flags & RXRPC_REQUEST_ACK) { |
72f0c6fb DH |
852 | rxrpc_send_ACK(call, RXRPC_ACK_REQUESTED, ack_serial, |
853 | rxrpc_propose_ack_respond_to_ack); | |
17926a79 DH |
854 | } |
855 | ||
adc9613f DH |
856 | /* If we get an EXCEEDS_WINDOW ACK from the server, it probably |
857 | * indicates that the client address changed due to NAT. The server | |
858 | * lost the call because it switched to a different peer. | |
859 | */ | |
d57a3a15 | 860 | if (unlikely(ack.reason == RXRPC_ACK_EXCEEDS_WINDOW) && |
adc9613f DH |
861 | first_soft_ack == 1 && |
862 | prev_pkt == 0 && | |
863 | rxrpc_is_client_call(call)) { | |
864 | rxrpc_set_call_completion(call, RXRPC_CALL_REMOTELY_ABORTED, | |
865 | 0, -ENETRESET); | |
4041a8ff | 866 | goto out; |
adc9613f DH |
867 | } |
868 | ||
869 | /* If we get an OUT_OF_SEQUENCE ACK from the server, that can also | |
870 | * indicate a change of address. However, we can retransmit the call | |
871 | * if we still have it buffered to the beginning. | |
872 | */ | |
d57a3a15 | 873 | if (unlikely(ack.reason == RXRPC_ACK_OUT_OF_SEQUENCE) && |
adc9613f DH |
874 | first_soft_ack == 1 && |
875 | prev_pkt == 0 && | |
a4ea4c47 | 876 | call->acks_hard_ack == 0 && |
adc9613f DH |
877 | rxrpc_is_client_call(call)) { |
878 | rxrpc_set_call_completion(call, RXRPC_CALL_REMOTELY_ABORTED, | |
879 | 0, -ENETRESET); | |
4041a8ff | 880 | goto out; |
adc9613f DH |
881 | } |
882 | ||
1a2391c3 | 883 | /* Discard any out-of-order or duplicate ACKs (outside lock). */ |
441fdee1 | 884 | if (!rxrpc_is_ack_valid(call, first_soft_ack, prev_pkt)) { |
68528d93 | 885 | trace_rxrpc_rx_discard_ack(call->debug_id, ack_serial, |
8940ba3c DH |
886 | first_soft_ack, call->acks_first_seq, |
887 | prev_pkt, call->acks_prev_seq); | |
4041a8ff | 888 | goto out; |
d1f12947 | 889 | } |
c1e15b49 | 890 | |
d57a3a15 | 891 | info.rxMTU = 0; |
775e5b71 | 892 | ioffset = offset + nr_acks + 3; |
d57a3a15 DH |
893 | if (skb->len >= ioffset + sizeof(info) && |
894 | skb_copy_bits(skb, ioffset, &info, sizeof(info)) < 0) { | |
895 | rxrpc_proto_abort("XAI", call, 0); | |
4041a8ff | 896 | goto out; |
d57a3a15 DH |
897 | } |
898 | ||
899 | if (nr_acks > 0) | |
900 | skb_condense(skb); | |
c1e15b49 | 901 | |
1a2391c3 | 902 | /* Discard any out-of-order or duplicate ACKs (inside lock). */ |
441fdee1 | 903 | if (!rxrpc_is_ack_valid(call, first_soft_ack, prev_pkt)) { |
68528d93 | 904 | trace_rxrpc_rx_discard_ack(call->debug_id, ack_serial, |
8940ba3c DH |
905 | first_soft_ack, call->acks_first_seq, |
906 | prev_pkt, call->acks_prev_seq); | |
c1e15b49 | 907 | goto out; |
d1f12947 | 908 | } |
298bc15b | 909 | call->acks_latest_ts = skb->tstamp; |
298bc15b | 910 | |
8940ba3c DH |
911 | call->acks_first_seq = first_soft_ack; |
912 | call->acks_prev_seq = prev_pkt; | |
1a2391c3 | 913 | |
d57a3a15 DH |
914 | switch (ack.reason) { |
915 | case RXRPC_ACK_PING: | |
916 | break; | |
917 | case RXRPC_ACK_PING_RESPONSE: | |
918 | rxrpc_input_ping_response(call, skb->tstamp, acked_serial, | |
919 | ack_serial); | |
920 | fallthrough; | |
921 | default: | |
922 | if (after(acked_serial, call->acks_highest_serial)) | |
923 | call->acks_highest_serial = acked_serial; | |
924 | break; | |
925 | } | |
589a0c1e | 926 | |
298bc15b | 927 | /* Parse rwind and mtu sizes if provided. */ |
d57a3a15 DH |
928 | if (info.rxMTU) |
929 | rxrpc_input_ackinfo(call, skb, &info); | |
17926a79 | 930 | |
c1e15b49 DH |
931 | if (first_soft_ack == 0) { |
932 | rxrpc_proto_abort("AK0", call, 0); | |
933 | goto out; | |
934 | } | |
17926a79 | 935 | |
248f219c | 936 | /* Ignore ACKs unless we are or have just been transmitting. */ |
146d8fef | 937 | switch (READ_ONCE(call->state)) { |
248f219c DH |
938 | case RXRPC_CALL_CLIENT_SEND_REQUEST: |
939 | case RXRPC_CALL_CLIENT_AWAIT_REPLY: | |
940 | case RXRPC_CALL_SERVER_SEND_REPLY: | |
941 | case RXRPC_CALL_SERVER_AWAIT_ACK: | |
942 | break; | |
17926a79 | 943 | default: |
c1e15b49 | 944 | goto out; |
248f219c | 945 | } |
17926a79 | 946 | |
a4ea4c47 | 947 | if (before(hard_ack, call->acks_hard_ack) || |
c1e15b49 DH |
948 | after(hard_ack, call->tx_top)) { |
949 | rxrpc_proto_abort("AKW", call, 0); | |
950 | goto out; | |
951 | } | |
952 | if (nr_acks > call->tx_top - hard_ack) { | |
953 | rxrpc_proto_abort("AKN", call, 0); | |
954 | goto out; | |
955 | } | |
17926a79 | 956 | |
a4ea4c47 | 957 | if (after(hard_ack, call->acks_hard_ack)) { |
c479d5f2 DH |
958 | if (rxrpc_rotate_tx_window(call, hard_ack, &summary)) { |
959 | rxrpc_end_tx_phase(call, false, "ETA"); | |
c1e15b49 | 960 | goto out; |
c479d5f2 DH |
961 | } |
962 | } | |
17926a79 | 963 | |
70790dbe | 964 | if (nr_acks > 0) { |
d57a3a15 | 965 | if (offset > (int)skb->len - nr_acks) { |
c1e15b49 DH |
966 | rxrpc_proto_abort("XSA", call, 0); |
967 | goto out; | |
968 | } | |
d57a3a15 | 969 | |
2d1faf7a | 970 | rxrpc_get_skb(skb, rxrpc_skb_get_ack); |
d57a3a15 DH |
971 | spin_lock(&call->acks_ack_lock); |
972 | skb_old = call->acks_soft_tbl; | |
973 | call->acks_soft_tbl = skb; | |
974 | spin_unlock(&call->acks_ack_lock); | |
975 | ||
976 | rxrpc_input_soft_acks(call, skb->data + offset, first_soft_ack, | |
977 | nr_acks, &summary); | |
d57a3a15 DH |
978 | } else if (call->acks_soft_tbl) { |
979 | spin_lock(&call->acks_ack_lock); | |
980 | skb_old = call->acks_soft_tbl; | |
981 | call->acks_soft_tbl = NULL; | |
982 | spin_unlock(&call->acks_ack_lock); | |
70790dbe DH |
983 | } |
984 | ||
a4ea4c47 | 985 | if (test_bit(RXRPC_CALL_TX_LAST, &call->flags) && |
a9f312d9 DH |
986 | summary.nr_acks == call->tx_top - hard_ack && |
987 | rxrpc_is_client_call(call)) | |
72f0c6fb DH |
988 | rxrpc_propose_ping(call, ack_serial, |
989 | rxrpc_propose_ack_ping_for_lost_reply); | |
57494343 | 990 | |
c1e15b49 DH |
991 | rxrpc_congestion_management(call, skb, &summary, acked_serial); |
992 | out: | |
9a36a6bc | 993 | rxrpc_free_skb(skb_old, rxrpc_skb_put_ack); |
17926a79 DH |
994 | } |
995 | ||
996 | /* | |
248f219c | 997 | * Process an ACKALL packet. |
17926a79 | 998 | */ |
248f219c | 999 | static void rxrpc_input_ackall(struct rxrpc_call *call, struct sk_buff *skb) |
17926a79 | 1000 | { |
31a1b989 | 1001 | struct rxrpc_ack_summary summary = { 0 }; |
17926a79 | 1002 | |
c479d5f2 | 1003 | if (rxrpc_rotate_tx_window(call, call->tx_top, &summary)) |
70790dbe | 1004 | rxrpc_end_tx_phase(call, false, "ETL"); |
248f219c | 1005 | } |
17926a79 | 1006 | |
248f219c | 1007 | /* |
005ede28 | 1008 | * Process an ABORT packet directed at a call. |
248f219c DH |
1009 | */ |
1010 | static void rxrpc_input_abort(struct rxrpc_call *call, struct sk_buff *skb) | |
1011 | { | |
1012 | struct rxrpc_skb_priv *sp = rxrpc_skb(skb); | |
17926a79 | 1013 | |
f14febd8 | 1014 | trace_rxrpc_rx_abort(call, sp->hdr.serial, skb->priority); |
005ede28 | 1015 | |
5ac0d622 | 1016 | rxrpc_set_call_completion(call, RXRPC_CALL_REMOTELY_ABORTED, |
f14febd8 | 1017 | skb->priority, -ECONNABORTED); |
17926a79 DH |
1018 | } |
1019 | ||
1020 | /* | |
248f219c | 1021 | * Process an incoming call packet. |
17926a79 | 1022 | */ |
15f661dc | 1023 | void rxrpc_input_call_event(struct rxrpc_call *call, struct sk_buff *skb) |
17926a79 | 1024 | { |
248f219c | 1025 | struct rxrpc_skb_priv *sp = rxrpc_skb(skb); |
a158bdd3 | 1026 | unsigned long timo; |
17926a79 | 1027 | |
7727640c | 1028 | _enter("%p,%p", call, skb); |
17926a79 | 1029 | |
a158bdd3 DH |
1030 | timo = READ_ONCE(call->next_rx_timo); |
1031 | if (timo) { | |
1032 | unsigned long now = jiffies, expect_rx_by; | |
1033 | ||
c54e43d7 | 1034 | expect_rx_by = now + timo; |
a158bdd3 DH |
1035 | WRITE_ONCE(call->expect_rx_by, expect_rx_by); |
1036 | rxrpc_reduce_call_timer(call, expect_rx_by, now, | |
1037 | rxrpc_timer_set_for_normal); | |
1038 | } | |
3d7682af | 1039 | |
248f219c DH |
1040 | switch (sp->hdr.type) { |
1041 | case RXRPC_PACKET_TYPE_DATA: | |
e8c3af6b | 1042 | rxrpc_input_data(call, skb); |
2d1faf7a | 1043 | break; |
f5c17aae | 1044 | |
248f219c | 1045 | case RXRPC_PACKET_TYPE_ACK: |
e8c3af6b | 1046 | rxrpc_input_ack(call, skb); |
2d1faf7a | 1047 | break; |
17926a79 | 1048 | |
248f219c | 1049 | case RXRPC_PACKET_TYPE_BUSY: |
248f219c DH |
1050 | /* Just ignore BUSY packets from the server; the retry and |
1051 | * lifespan timers will take care of business. BUSY packets | |
1052 | * from the client don't make sense. | |
1053 | */ | |
1054 | break; | |
17926a79 | 1055 | |
248f219c DH |
1056 | case RXRPC_PACKET_TYPE_ABORT: |
1057 | rxrpc_input_abort(call, skb); | |
1058 | break; | |
17926a79 | 1059 | |
248f219c DH |
1060 | case RXRPC_PACKET_TYPE_ACKALL: |
1061 | rxrpc_input_ackall(call, skb); | |
1062 | break; | |
f5c17aae | 1063 | |
248f219c | 1064 | default: |
248f219c | 1065 | break; |
17926a79 | 1066 | } |
17926a79 DH |
1067 | } |
1068 | ||
b3156274 | 1069 | /* |
c1e15b49 DH |
1070 | * Handle a new service call on a channel implicitly completing the preceding |
1071 | * call on that channel. This does not apply to client conns. | |
b3156274 DH |
1072 | * |
1073 | * TODO: If callNumber > call_id + 1, renegotiate security. | |
1074 | */ | |
cd21effb | 1075 | void rxrpc_input_implicit_end_call(struct rxrpc_connection *conn, |
96b2d69b | 1076 | struct rxrpc_call *call) |
b3156274 | 1077 | { |
146d8fef | 1078 | switch (READ_ONCE(call->state)) { |
b3156274 DH |
1079 | case RXRPC_CALL_SERVER_AWAIT_ACK: |
1080 | rxrpc_call_completed(call); | |
df561f66 | 1081 | fallthrough; |
b3156274 DH |
1082 | case RXRPC_CALL_COMPLETE: |
1083 | break; | |
1084 | default: | |
3a92789a | 1085 | if (rxrpc_abort_call("IMP", call, 0, RX_CALL_DEAD, -ESHUTDOWN)) { |
b3156274 | 1086 | set_bit(RXRPC_CALL_EV_ABORT, &call->events); |
cb0fc0c9 | 1087 | rxrpc_queue_call(call, rxrpc_call_queue_abort); |
b3156274 | 1088 | } |
c1e15b49 | 1089 | trace_rxrpc_improper_term(call); |
b3156274 DH |
1090 | break; |
1091 | } | |
1092 | ||
cd21effb | 1093 | spin_lock(&conn->bundle->channel_lock); |
b3156274 | 1094 | __rxrpc_disconnect_call(conn, call); |
cd21effb | 1095 | spin_unlock(&conn->bundle->channel_lock); |
b3156274 | 1096 | } |