1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Processing of received RxRPC packets
4 * Copyright (C) 2020 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
8 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
10 #include "ar-internal.h"
12 static void rxrpc_proto_abort(const char *why,
13 struct rxrpc_call *call, rxrpc_seq_t seq)
15 if (rxrpc_abort_call(why, call, seq, RX_PROTOCOL_ERROR, -EBADMSG))
16 rxrpc_send_abort_packet(call);
20 * Do TCP-style congestion management [RFC 5681].
22 static void rxrpc_congestion_management(struct rxrpc_call *call,
24 struct rxrpc_ack_summary *summary,
25 rxrpc_serial_t acked_serial)
27 enum rxrpc_congest_change change = rxrpc_cong_no_change;
28 unsigned int cumulative_acks = call->cong_cumul_acks;
29 unsigned int cwnd = call->cong_cwnd;
32 summary->flight_size =
33 (call->tx_top - call->acks_hard_ack) - summary->nr_acks;
35 if (test_and_clear_bit(RXRPC_CALL_RETRANS_TIMEOUT, &call->flags)) {
36 summary->retrans_timeo = true;
37 call->cong_ssthresh = max_t(unsigned int,
38 summary->flight_size / 2, 2);
40 if (cwnd >= call->cong_ssthresh &&
41 call->cong_mode == RXRPC_CALL_SLOW_START) {
42 call->cong_mode = RXRPC_CALL_CONGEST_AVOIDANCE;
43 call->cong_tstamp = skb->tstamp;
48 cumulative_acks += summary->nr_new_acks;
49 cumulative_acks += summary->nr_rot_new_acks;
50 if (cumulative_acks > 255)
51 cumulative_acks = 255;
53 summary->mode = call->cong_mode;
54 summary->cwnd = call->cong_cwnd;
55 summary->ssthresh = call->cong_ssthresh;
56 summary->cumulative_acks = cumulative_acks;
57 summary->dup_acks = call->cong_dup_acks;
59 /* If we haven't transmitted anything for >1RTT, we should reset the
60 * congestion management state.
62 if ((call->cong_mode == RXRPC_CALL_SLOW_START ||
63 call->cong_mode == RXRPC_CALL_CONGEST_AVOIDANCE) &&
64 ktime_before(ktime_add_us(call->tx_last_sent,
65 call->peer->srtt_us >> 3),
68 change = rxrpc_cong_idle_reset;
69 summary->mode = RXRPC_CALL_SLOW_START;
70 if (RXRPC_TX_SMSS > 2190)
72 else if (RXRPC_TX_SMSS > 1095)
78 switch (call->cong_mode) {
79 case RXRPC_CALL_SLOW_START:
80 if (summary->saw_nacks)
81 goto packet_loss_detected;
82 if (summary->cumulative_acks > 0)
84 if (cwnd >= call->cong_ssthresh) {
85 call->cong_mode = RXRPC_CALL_CONGEST_AVOIDANCE;
86 call->cong_tstamp = skb->tstamp;
90 case RXRPC_CALL_CONGEST_AVOIDANCE:
91 if (summary->saw_nacks)
92 goto packet_loss_detected;
94 /* We analyse the number of packets that get ACK'd per RTT
95 * period and increase the window if we managed to fill it.
97 if (call->peer->rtt_count == 0)
99 if (ktime_before(skb->tstamp,
100 ktime_add_us(call->cong_tstamp,
101 call->peer->srtt_us >> 3)))
102 goto out_no_clear_ca;
103 change = rxrpc_cong_rtt_window_end;
104 call->cong_tstamp = skb->tstamp;
105 if (cumulative_acks >= cwnd)
109 case RXRPC_CALL_PACKET_LOSS:
110 if (!summary->saw_nacks)
111 goto resume_normality;
113 if (summary->new_low_nack) {
114 change = rxrpc_cong_new_low_nack;
115 call->cong_dup_acks = 1;
116 if (call->cong_extra > 1)
117 call->cong_extra = 1;
118 goto send_extra_data;
121 call->cong_dup_acks++;
122 if (call->cong_dup_acks < 3)
123 goto send_extra_data;
125 change = rxrpc_cong_begin_retransmission;
126 call->cong_mode = RXRPC_CALL_FAST_RETRANSMIT;
127 call->cong_ssthresh = max_t(unsigned int,
128 summary->flight_size / 2, 2);
129 cwnd = call->cong_ssthresh + 3;
130 call->cong_extra = 0;
131 call->cong_dup_acks = 0;
135 case RXRPC_CALL_FAST_RETRANSMIT:
136 if (!summary->new_low_nack) {
137 if (summary->nr_new_acks == 0)
139 call->cong_dup_acks++;
140 if (call->cong_dup_acks == 2) {
141 change = rxrpc_cong_retransmit_again;
142 call->cong_dup_acks = 0;
146 change = rxrpc_cong_progress;
147 cwnd = call->cong_ssthresh;
148 if (!summary->saw_nacks)
149 goto resume_normality;
159 change = rxrpc_cong_cleared_nacks;
160 call->cong_dup_acks = 0;
161 call->cong_extra = 0;
162 call->cong_tstamp = skb->tstamp;
163 if (cwnd < call->cong_ssthresh)
164 call->cong_mode = RXRPC_CALL_SLOW_START;
166 call->cong_mode = RXRPC_CALL_CONGEST_AVOIDANCE;
170 if (cwnd >= RXRPC_TX_MAX_WINDOW)
171 cwnd = RXRPC_TX_MAX_WINDOW;
172 call->cong_cwnd = cwnd;
173 call->cong_cumul_acks = cumulative_acks;
174 trace_rxrpc_congest(call, summary, acked_serial, change);
176 rxrpc_resend(call, skb);
179 packet_loss_detected:
180 change = rxrpc_cong_saw_nack;
181 call->cong_mode = RXRPC_CALL_PACKET_LOSS;
182 call->cong_dup_acks = 0;
183 goto send_extra_data;
186 /* Send some previously unsent DATA if we have some to advance the ACK
189 if (test_bit(RXRPC_CALL_TX_LAST, &call->flags) ||
190 summary->nr_acks != call->tx_top - call->acks_hard_ack) {
192 wake_up(&call->waitq);
194 goto out_no_clear_ca;
198 * Apply a hard ACK by advancing the Tx window.
200 static bool rxrpc_rotate_tx_window(struct rxrpc_call *call, rxrpc_seq_t to,
201 struct rxrpc_ack_summary *summary)
203 struct rxrpc_txbuf *txb;
204 bool rot_last = false;
206 list_for_each_entry_rcu(txb, &call->tx_buffer, call_link, false) {
207 if (before_eq(txb->seq, call->acks_hard_ack))
209 summary->nr_rot_new_acks++;
210 if (test_bit(RXRPC_TXBUF_LAST, &txb->flags)) {
211 set_bit(RXRPC_CALL_TX_LAST, &call->flags);
219 set_bit(RXRPC_CALL_TX_ALL_ACKED, &call->flags);
221 _enter("%x,%x,%x,%d", to, call->acks_hard_ack, call->tx_top, rot_last);
223 if (call->acks_lowest_nak == call->acks_hard_ack) {
224 call->acks_lowest_nak = to;
225 } else if (after(to, call->acks_lowest_nak)) {
226 summary->new_low_nack = true;
227 call->acks_lowest_nak = to;
230 smp_store_release(&call->acks_hard_ack, to);
232 trace_rxrpc_txqueue(call, (rot_last ?
233 rxrpc_txqueue_rotate_last :
234 rxrpc_txqueue_rotate));
235 wake_up(&call->waitq);
240 * End the transmission phase of a call.
242 * This occurs when we get an ACKALL packet, the first DATA packet of a reply,
243 * or a final ACK packet.
245 static bool rxrpc_end_tx_phase(struct rxrpc_call *call, bool reply_begun,
246 const char *abort_why)
250 ASSERT(test_bit(RXRPC_CALL_TX_LAST, &call->flags));
252 write_lock(&call->state_lock);
256 case RXRPC_CALL_CLIENT_SEND_REQUEST:
257 case RXRPC_CALL_CLIENT_AWAIT_REPLY:
259 call->state = state = RXRPC_CALL_CLIENT_RECV_REPLY;
261 call->state = state = RXRPC_CALL_CLIENT_AWAIT_REPLY;
264 case RXRPC_CALL_SERVER_AWAIT_ACK:
265 __rxrpc_call_completed(call);
273 write_unlock(&call->state_lock);
274 if (state == RXRPC_CALL_CLIENT_AWAIT_REPLY)
275 trace_rxrpc_txqueue(call, rxrpc_txqueue_await_reply);
277 trace_rxrpc_txqueue(call, rxrpc_txqueue_end);
282 write_unlock(&call->state_lock);
283 kdebug("end_tx %s", rxrpc_call_states[call->state]);
284 rxrpc_proto_abort(abort_why, call, call->tx_top);
289 * Begin the reply reception phase of a call.
291 static bool rxrpc_receiving_reply(struct rxrpc_call *call)
293 struct rxrpc_ack_summary summary = { 0 };
294 unsigned long now, timo;
295 rxrpc_seq_t top = READ_ONCE(call->tx_top);
297 if (call->ackr_reason) {
299 timo = now + MAX_JIFFY_OFFSET;
300 WRITE_ONCE(call->resend_at, timo);
301 WRITE_ONCE(call->delay_ack_at, timo);
302 trace_rxrpc_timer(call, rxrpc_timer_init_for_reply, now);
305 if (!test_bit(RXRPC_CALL_TX_LAST, &call->flags)) {
306 if (!rxrpc_rotate_tx_window(call, top, &summary)) {
307 rxrpc_proto_abort("TXL", call, top);
311 return rxrpc_end_tx_phase(call, true, "ETD");
314 static void rxrpc_input_update_ack_window(struct rxrpc_call *call,
315 rxrpc_seq_t window, rxrpc_seq_t wtop)
317 atomic64_set_release(&call->ackr_window, ((u64)wtop) << 32 | window);
321 * Push a DATA packet onto the Rx queue.
323 static void rxrpc_input_queue_data(struct rxrpc_call *call, struct sk_buff *skb,
324 rxrpc_seq_t window, rxrpc_seq_t wtop,
325 enum rxrpc_receive_trace why)
327 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
328 bool last = sp->hdr.flags & RXRPC_LAST_PACKET;
330 __skb_queue_tail(&call->recvmsg_queue, skb);
331 rxrpc_input_update_ack_window(call, window, wtop);
333 trace_rxrpc_receive(call, last ? why + 1 : why, sp->hdr.serial, sp->hdr.seq);
337 * Process a DATA packet.
339 static void rxrpc_input_data_one(struct rxrpc_call *call, struct sk_buff *skb,
342 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
344 rxrpc_serial_t serial = sp->hdr.serial;
345 u64 win = atomic64_read(&call->ackr_window);
346 rxrpc_seq_t window = lower_32_bits(win);
347 rxrpc_seq_t wtop = upper_32_bits(win);
348 rxrpc_seq_t wlimit = window + call->rx_winsize - 1;
349 rxrpc_seq_t seq = sp->hdr.seq;
350 bool last = sp->hdr.flags & RXRPC_LAST_PACKET;
353 rxrpc_inc_stat(call->rxnet, stat_rx_data);
354 if (sp->hdr.flags & RXRPC_REQUEST_ACK)
355 rxrpc_inc_stat(call->rxnet, stat_rx_data_reqack);
356 if (sp->hdr.flags & RXRPC_JUMBO_PACKET)
357 rxrpc_inc_stat(call->rxnet, stat_rx_data_jumbo);
360 if (test_and_set_bit(RXRPC_CALL_RX_LAST, &call->flags) &&
362 rxrpc_proto_abort("LSN", call, seq);
366 if (test_bit(RXRPC_CALL_RX_LAST, &call->flags) &&
367 after_eq(seq, wtop)) {
368 pr_warn("Packet beyond last: c=%x q=%x window=%x-%x wlimit=%x\n",
369 call->debug_id, seq, window, wtop, wlimit);
370 rxrpc_proto_abort("LSA", call, seq);
375 if (after(seq, call->rx_highest_seq))
376 call->rx_highest_seq = seq;
378 trace_rxrpc_rx_data(call->debug_id, seq, serial, sp->hdr.flags);
380 if (before(seq, window)) {
381 ack_reason = RXRPC_ACK_DUPLICATE;
384 if (after(seq, wlimit)) {
385 ack_reason = RXRPC_ACK_EXCEEDS_WINDOW;
389 /* Queue the packet. */
391 rxrpc_seq_t reset_from;
392 bool reset_sack = false;
394 if (sp->hdr.flags & RXRPC_REQUEST_ACK)
395 ack_reason = RXRPC_ACK_REQUESTED;
396 /* Send an immediate ACK if we fill in a hole */
397 else if (!skb_queue_empty(&call->rx_oos_queue))
398 ack_reason = RXRPC_ACK_DELAY;
400 atomic_inc_return(&call->ackr_nr_unacked);
403 if (after(window, wtop))
406 rxrpc_get_skb(skb, rxrpc_skb_get_to_recvmsg);
408 spin_lock(&call->recvmsg_queue.lock);
409 rxrpc_input_queue_data(call, skb, window, wtop, rxrpc_receive_queue);
412 while ((oos = skb_peek(&call->rx_oos_queue))) {
413 struct rxrpc_skb_priv *osp = rxrpc_skb(oos);
415 if (after(osp->hdr.seq, window))
418 __skb_unlink(oos, &call->rx_oos_queue);
419 last = osp->hdr.flags & RXRPC_LAST_PACKET;
427 rxrpc_input_queue_data(call, oos, window, wtop,
428 rxrpc_receive_queue_oos);
431 spin_unlock(&call->recvmsg_queue.lock);
435 call->ackr_sack_table[reset_from % RXRPC_SACK_SIZE] = 0;
436 } while (reset_from++, before(reset_from, window));
441 ack_reason = RXRPC_ACK_OUT_OF_SEQUENCE;
443 if (!call->ackr_sack_table[seq % RXRPC_SACK_SIZE]) {
444 call->ackr_sack_table[seq % RXRPC_SACK_SIZE] = 1;
448 if (after(seq + 1, wtop)) {
450 rxrpc_input_update_ack_window(call, window, wtop);
454 ack_reason = RXRPC_ACK_DUPLICATE;
458 skb_queue_walk(&call->rx_oos_queue, oos) {
459 struct rxrpc_skb_priv *osp = rxrpc_skb(oos);
461 if (after(osp->hdr.seq, seq)) {
462 rxrpc_get_skb(skb, rxrpc_skb_get_to_recvmsg_oos);
463 __skb_queue_before(&call->rx_oos_queue, oos, skb);
468 rxrpc_get_skb(skb, rxrpc_skb_get_to_recvmsg_oos);
469 __skb_queue_tail(&call->rx_oos_queue, skb);
471 trace_rxrpc_receive(call, last ? rxrpc_receive_oos_last : rxrpc_receive_oos,
472 sp->hdr.serial, sp->hdr.seq);
477 rxrpc_send_ACK(call, ack_reason, serial,
478 rxrpc_propose_ack_input_data);
480 rxrpc_propose_delay_ACK(call, serial,
481 rxrpc_propose_ack_input_data);
485 * Split a jumbo packet and file the bits separately.
487 static bool rxrpc_input_split_jumbo(struct rxrpc_call *call, struct sk_buff *skb)
489 struct rxrpc_jumbo_header jhdr;
490 struct rxrpc_skb_priv *sp = rxrpc_skb(skb), *jsp;
491 struct sk_buff *jskb;
492 unsigned int offset = sizeof(struct rxrpc_wire_header);
493 unsigned int len = skb->len - offset;
496 while (sp->hdr.flags & RXRPC_JUMBO_PACKET) {
497 if (len < RXRPC_JUMBO_SUBPKTLEN)
499 if (sp->hdr.flags & RXRPC_LAST_PACKET)
501 if (skb_copy_bits(skb, offset + RXRPC_JUMBO_DATALEN,
502 &jhdr, sizeof(jhdr)) < 0)
505 jskb = skb_clone(skb, GFP_NOFS);
507 kdebug("couldn't clone");
510 rxrpc_new_skb(jskb, rxrpc_skb_new_jumbo_subpacket);
511 jsp = rxrpc_skb(jskb);
512 jsp->offset = offset;
513 jsp->len = RXRPC_JUMBO_DATALEN;
514 rxrpc_input_data_one(call, jskb, ¬ify);
515 rxrpc_free_skb(jskb, rxrpc_skb_put_jumbo_subpacket);
517 sp->hdr.flags = jhdr.flags;
518 sp->hdr._rsvd = ntohs(jhdr._rsvd);
521 offset += RXRPC_JUMBO_SUBPKTLEN;
522 len -= RXRPC_JUMBO_SUBPKTLEN;
527 rxrpc_input_data_one(call, skb, ¬ify);
529 trace_rxrpc_notify_socket(call->debug_id, sp->hdr.serial);
530 rxrpc_notify_socket(call);
539 * Process a DATA packet, adding the packet to the Rx ring. The caller's
540 * packet ref must be passed on or discarded.
542 static void rxrpc_input_data(struct rxrpc_call *call, struct sk_buff *skb)
544 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
545 enum rxrpc_call_state state;
546 rxrpc_serial_t serial = sp->hdr.serial;
547 rxrpc_seq_t seq0 = sp->hdr.seq;
549 _enter("{%llx,%x},{%u,%x}",
550 atomic64_read(&call->ackr_window), call->rx_highest_seq,
553 state = READ_ONCE(call->state);
554 if (state >= RXRPC_CALL_COMPLETE)
557 if (state == RXRPC_CALL_SERVER_RECV_REQUEST) {
558 unsigned long timo = READ_ONCE(call->next_req_timo);
559 unsigned long now, expect_req_by;
563 expect_req_by = now + timo;
564 WRITE_ONCE(call->expect_req_by, expect_req_by);
565 rxrpc_reduce_call_timer(call, expect_req_by, now,
566 rxrpc_timer_set_for_idle);
570 /* Received data implicitly ACKs all of the request packets we sent
571 * when we're acting as a client.
573 if ((state == RXRPC_CALL_CLIENT_SEND_REQUEST ||
574 state == RXRPC_CALL_CLIENT_AWAIT_REPLY) &&
575 !rxrpc_receiving_reply(call))
578 if (!rxrpc_input_split_jumbo(call, skb)) {
579 rxrpc_proto_abort("VLD", call, sp->hdr.seq);
585 trace_rxrpc_notify_socket(call->debug_id, serial);
586 rxrpc_notify_socket(call);
591 * See if there's a cached RTT probe to complete.
593 static void rxrpc_complete_rtt_probe(struct rxrpc_call *call,
595 rxrpc_serial_t acked_serial,
596 rxrpc_serial_t ack_serial,
597 enum rxrpc_rtt_rx_trace type)
599 rxrpc_serial_t orig_serial;
602 bool matched = false;
605 avail = READ_ONCE(call->rtt_avail);
606 smp_rmb(); /* Read avail bits before accessing data. */
608 for (i = 0; i < ARRAY_SIZE(call->rtt_serial); i++) {
609 if (!test_bit(i + RXRPC_CALL_RTT_PEND_SHIFT, &avail))
612 sent_at = call->rtt_sent_at[i];
613 orig_serial = call->rtt_serial[i];
615 if (orig_serial == acked_serial) {
616 clear_bit(i + RXRPC_CALL_RTT_PEND_SHIFT, &call->rtt_avail);
617 smp_mb(); /* Read data before setting avail bit */
618 set_bit(i, &call->rtt_avail);
619 if (type != rxrpc_rtt_rx_cancel)
620 rxrpc_peer_add_rtt(call, type, i, acked_serial, ack_serial,
623 trace_rxrpc_rtt_rx(call, rxrpc_rtt_rx_cancel, i,
624 orig_serial, acked_serial, 0, 0);
628 /* If a later serial is being acked, then mark this slot as
631 if (after(acked_serial, orig_serial)) {
632 trace_rxrpc_rtt_rx(call, rxrpc_rtt_rx_obsolete, i,
633 orig_serial, acked_serial, 0, 0);
634 clear_bit(i + RXRPC_CALL_RTT_PEND_SHIFT, &call->rtt_avail);
636 set_bit(i, &call->rtt_avail);
641 trace_rxrpc_rtt_rx(call, rxrpc_rtt_rx_lost, 9, 0, acked_serial, 0, 0);
645 * Process the extra information that may be appended to an ACK packet
647 static void rxrpc_input_ackinfo(struct rxrpc_call *call, struct sk_buff *skb,
648 struct rxrpc_ackinfo *ackinfo)
650 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
651 struct rxrpc_peer *peer;
654 u32 rwind = ntohl(ackinfo->rwind);
656 if (rwind > RXRPC_TX_MAX_WINDOW)
657 rwind = RXRPC_TX_MAX_WINDOW;
658 if (call->tx_winsize != rwind) {
659 if (rwind > call->tx_winsize)
661 trace_rxrpc_rx_rwind_change(call, sp->hdr.serial, rwind, wake);
662 call->tx_winsize = rwind;
665 if (call->cong_ssthresh > rwind)
666 call->cong_ssthresh = rwind;
668 mtu = min(ntohl(ackinfo->rxMTU), ntohl(ackinfo->maxMTU));
671 if (mtu < peer->maxdata) {
672 spin_lock_bh(&peer->lock);
674 peer->mtu = mtu + peer->hdrsize;
675 spin_unlock_bh(&peer->lock);
679 wake_up(&call->waitq);
683 * Process individual soft ACKs.
685 * Each ACK in the array corresponds to one packet and can be either an ACK or
686 * a NAK. If we get find an explicitly NAK'd packet we resend immediately;
687 * packets that lie beyond the end of the ACK list are scheduled for resend by
688 * the timer on the basis that the peer might just not have processed them at
689 * the time the ACK was sent.
691 static void rxrpc_input_soft_acks(struct rxrpc_call *call, u8 *acks,
692 rxrpc_seq_t seq, int nr_acks,
693 struct rxrpc_ack_summary *summary)
697 for (i = 0; i < nr_acks; i++) {
698 if (acks[i] == RXRPC_ACK_TYPE_ACK) {
700 summary->nr_new_acks++;
702 if (!summary->saw_nacks &&
703 call->acks_lowest_nak != seq + i) {
704 call->acks_lowest_nak = seq + i;
705 summary->new_low_nack = true;
707 summary->saw_nacks = true;
713 * Return true if the ACK is valid - ie. it doesn't appear to have regressed
714 * with respect to the ack state conveyed by preceding ACKs.
716 static bool rxrpc_is_ack_valid(struct rxrpc_call *call,
717 rxrpc_seq_t first_pkt, rxrpc_seq_t prev_pkt)
719 rxrpc_seq_t base = READ_ONCE(call->acks_first_seq);
721 if (after(first_pkt, base))
722 return true; /* The window advanced */
724 if (before(first_pkt, base))
725 return false; /* firstPacket regressed */
727 if (after_eq(prev_pkt, call->acks_prev_seq))
728 return true; /* previousPacket hasn't regressed. */
730 /* Some rx implementations put a serial number in previousPacket. */
731 if (after_eq(prev_pkt, base + call->tx_winsize))
737 * Process an ACK packet.
739 * ack.firstPacket is the sequence number of the first soft-ACK'd/NAK'd packet
740 * in the ACK array. Anything before that is hard-ACK'd and may be discarded.
742 * A hard-ACK means that a packet has been processed and may be discarded; a
743 * soft-ACK means that the packet may be discarded and retransmission
744 * requested. A phase is complete when all packets are hard-ACK'd.
746 static void rxrpc_input_ack(struct rxrpc_call *call, struct sk_buff *skb)
748 struct rxrpc_ack_summary summary = { 0 };
749 struct rxrpc_ackpacket ack;
750 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
751 struct rxrpc_ackinfo info;
752 rxrpc_serial_t ack_serial, acked_serial;
753 rxrpc_seq_t first_soft_ack, hard_ack, prev_pkt;
754 int nr_acks, offset, ioffset;
758 offset = sizeof(struct rxrpc_wire_header);
759 if (skb_copy_bits(skb, offset, &ack, sizeof(ack)) < 0)
760 return rxrpc_proto_abort("XAK", call, 0);
761 offset += sizeof(ack);
763 ack_serial = sp->hdr.serial;
764 acked_serial = ntohl(ack.serial);
765 first_soft_ack = ntohl(ack.firstPacket);
766 prev_pkt = ntohl(ack.previousPacket);
767 hard_ack = first_soft_ack - 1;
769 summary.ack_reason = (ack.reason < RXRPC_ACK__INVALID ?
770 ack.reason : RXRPC_ACK__INVALID);
772 trace_rxrpc_rx_ack(call, ack_serial, acked_serial,
773 first_soft_ack, prev_pkt,
774 summary.ack_reason, nr_acks);
775 rxrpc_inc_stat(call->rxnet, stat_rx_acks[ack.reason]);
777 switch (ack.reason) {
778 case RXRPC_ACK_PING_RESPONSE:
779 rxrpc_complete_rtt_probe(call, skb->tstamp, acked_serial, ack_serial,
780 rxrpc_rtt_rx_ping_response);
782 case RXRPC_ACK_REQUESTED:
783 rxrpc_complete_rtt_probe(call, skb->tstamp, acked_serial, ack_serial,
784 rxrpc_rtt_rx_requested_ack);
787 if (acked_serial != 0)
788 rxrpc_complete_rtt_probe(call, skb->tstamp, acked_serial, ack_serial,
789 rxrpc_rtt_rx_cancel);
793 if (ack.reason == RXRPC_ACK_PING) {
794 rxrpc_send_ACK(call, RXRPC_ACK_PING_RESPONSE, ack_serial,
795 rxrpc_propose_ack_respond_to_ping);
796 } else if (sp->hdr.flags & RXRPC_REQUEST_ACK) {
797 rxrpc_send_ACK(call, RXRPC_ACK_REQUESTED, ack_serial,
798 rxrpc_propose_ack_respond_to_ack);
801 /* If we get an EXCEEDS_WINDOW ACK from the server, it probably
802 * indicates that the client address changed due to NAT. The server
803 * lost the call because it switched to a different peer.
805 if (unlikely(ack.reason == RXRPC_ACK_EXCEEDS_WINDOW) &&
806 first_soft_ack == 1 &&
808 rxrpc_is_client_call(call)) {
809 rxrpc_set_call_completion(call, RXRPC_CALL_REMOTELY_ABORTED,
814 /* If we get an OUT_OF_SEQUENCE ACK from the server, that can also
815 * indicate a change of address. However, we can retransmit the call
816 * if we still have it buffered to the beginning.
818 if (unlikely(ack.reason == RXRPC_ACK_OUT_OF_SEQUENCE) &&
819 first_soft_ack == 1 &&
821 call->acks_hard_ack == 0 &&
822 rxrpc_is_client_call(call)) {
823 rxrpc_set_call_completion(call, RXRPC_CALL_REMOTELY_ABORTED,
828 /* Discard any out-of-order or duplicate ACKs (outside lock). */
829 if (!rxrpc_is_ack_valid(call, first_soft_ack, prev_pkt)) {
830 trace_rxrpc_rx_discard_ack(call->debug_id, ack_serial,
831 first_soft_ack, call->acks_first_seq,
832 prev_pkt, call->acks_prev_seq);
837 ioffset = offset + nr_acks + 3;
838 if (skb->len >= ioffset + sizeof(info) &&
839 skb_copy_bits(skb, ioffset, &info, sizeof(info)) < 0)
840 return rxrpc_proto_abort("XAI", call, 0);
845 call->acks_latest_ts = skb->tstamp;
846 call->acks_first_seq = first_soft_ack;
847 call->acks_prev_seq = prev_pkt;
849 switch (ack.reason) {
853 if (after(acked_serial, call->acks_highest_serial))
854 call->acks_highest_serial = acked_serial;
858 /* Parse rwind and mtu sizes if provided. */
860 rxrpc_input_ackinfo(call, skb, &info);
862 if (first_soft_ack == 0)
863 return rxrpc_proto_abort("AK0", call, 0);
865 /* Ignore ACKs unless we are or have just been transmitting. */
866 switch (READ_ONCE(call->state)) {
867 case RXRPC_CALL_CLIENT_SEND_REQUEST:
868 case RXRPC_CALL_CLIENT_AWAIT_REPLY:
869 case RXRPC_CALL_SERVER_SEND_REPLY:
870 case RXRPC_CALL_SERVER_AWAIT_ACK:
876 if (before(hard_ack, call->acks_hard_ack) ||
877 after(hard_ack, call->tx_top))
878 return rxrpc_proto_abort("AKW", call, 0);
879 if (nr_acks > call->tx_top - hard_ack)
880 return rxrpc_proto_abort("AKN", call, 0);
882 if (after(hard_ack, call->acks_hard_ack)) {
883 if (rxrpc_rotate_tx_window(call, hard_ack, &summary)) {
884 rxrpc_end_tx_phase(call, false, "ETA");
890 if (offset > (int)skb->len - nr_acks)
891 return rxrpc_proto_abort("XSA", call, 0);
892 rxrpc_input_soft_acks(call, skb->data + offset, first_soft_ack,
896 if (test_bit(RXRPC_CALL_TX_LAST, &call->flags) &&
897 summary.nr_acks == call->tx_top - hard_ack &&
898 rxrpc_is_client_call(call))
899 rxrpc_propose_ping(call, ack_serial,
900 rxrpc_propose_ack_ping_for_lost_reply);
902 rxrpc_congestion_management(call, skb, &summary, acked_serial);
906 * Process an ACKALL packet.
908 static void rxrpc_input_ackall(struct rxrpc_call *call, struct sk_buff *skb)
910 struct rxrpc_ack_summary summary = { 0 };
912 if (rxrpc_rotate_tx_window(call, call->tx_top, &summary))
913 rxrpc_end_tx_phase(call, false, "ETL");
917 * Process an ABORT packet directed at a call.
919 static void rxrpc_input_abort(struct rxrpc_call *call, struct sk_buff *skb)
921 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
923 trace_rxrpc_rx_abort(call, sp->hdr.serial, skb->priority);
925 rxrpc_set_call_completion(call, RXRPC_CALL_REMOTELY_ABORTED,
926 skb->priority, -ECONNABORTED);
930 * Process an incoming call packet.
932 void rxrpc_input_call_packet(struct rxrpc_call *call, struct sk_buff *skb)
934 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
937 _enter("%p,%p", call, skb);
939 if (sp->hdr.serviceId != call->dest_srx.srx_service)
940 call->dest_srx.srx_service = sp->hdr.serviceId;
941 if ((int)sp->hdr.serial - (int)call->rx_serial > 0)
942 call->rx_serial = sp->hdr.serial;
943 if (!test_bit(RXRPC_CALL_RX_HEARD, &call->flags))
944 set_bit(RXRPC_CALL_RX_HEARD, &call->flags);
946 timo = READ_ONCE(call->next_rx_timo);
948 unsigned long now = jiffies, expect_rx_by;
950 expect_rx_by = now + timo;
951 WRITE_ONCE(call->expect_rx_by, expect_rx_by);
952 rxrpc_reduce_call_timer(call, expect_rx_by, now,
953 rxrpc_timer_set_for_normal);
956 switch (sp->hdr.type) {
957 case RXRPC_PACKET_TYPE_DATA:
958 rxrpc_input_data(call, skb);
961 case RXRPC_PACKET_TYPE_ACK:
962 rxrpc_input_ack(call, skb);
965 case RXRPC_PACKET_TYPE_BUSY:
966 /* Just ignore BUSY packets from the server; the retry and
967 * lifespan timers will take care of business. BUSY packets
968 * from the client don't make sense.
972 case RXRPC_PACKET_TYPE_ABORT:
973 rxrpc_input_abort(call, skb);
976 case RXRPC_PACKET_TYPE_ACKALL:
977 rxrpc_input_ackall(call, skb);
986 * Handle a new service call on a channel implicitly completing the preceding
987 * call on that channel. This does not apply to client conns.
989 * TODO: If callNumber > call_id + 1, renegotiate security.
991 void rxrpc_implicit_end_call(struct rxrpc_call *call, struct sk_buff *skb)
993 struct rxrpc_connection *conn = call->conn;
995 switch (READ_ONCE(call->state)) {
996 case RXRPC_CALL_SERVER_AWAIT_ACK:
997 rxrpc_call_completed(call);
999 case RXRPC_CALL_COMPLETE:
1002 if (rxrpc_abort_call("IMP", call, 0, RX_CALL_DEAD, -ESHUTDOWN))
1003 rxrpc_send_abort_packet(call);
1004 trace_rxrpc_improper_term(call);
1008 rxrpc_input_call_event(call, skb);
1010 spin_lock(&conn->bundle->channel_lock);
1011 __rxrpc_disconnect_call(conn, call);
1012 spin_unlock(&conn->bundle->channel_lock);