18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* RxRPC packet reception 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Copyright (C) 2007, 2016 Red Hat, Inc. All Rights Reserved. 58c2ecf20Sopenharmony_ci * Written by David Howells (dhowells@redhat.com) 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#include <linux/module.h> 118c2ecf20Sopenharmony_ci#include <linux/net.h> 128c2ecf20Sopenharmony_ci#include <linux/skbuff.h> 138c2ecf20Sopenharmony_ci#include <linux/errqueue.h> 148c2ecf20Sopenharmony_ci#include <linux/udp.h> 158c2ecf20Sopenharmony_ci#include <linux/in.h> 168c2ecf20Sopenharmony_ci#include <linux/in6.h> 178c2ecf20Sopenharmony_ci#include <linux/icmp.h> 188c2ecf20Sopenharmony_ci#include <linux/gfp.h> 198c2ecf20Sopenharmony_ci#include <net/sock.h> 208c2ecf20Sopenharmony_ci#include <net/af_rxrpc.h> 218c2ecf20Sopenharmony_ci#include <net/ip.h> 228c2ecf20Sopenharmony_ci#include <net/udp.h> 238c2ecf20Sopenharmony_ci#include <net/net_namespace.h> 248c2ecf20Sopenharmony_ci#include "ar-internal.h" 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_cistatic void rxrpc_proto_abort(const char *why, 278c2ecf20Sopenharmony_ci struct rxrpc_call *call, rxrpc_seq_t seq) 288c2ecf20Sopenharmony_ci{ 298c2ecf20Sopenharmony_ci if (rxrpc_abort_call(why, call, seq, RX_PROTOCOL_ERROR, -EBADMSG)) { 308c2ecf20Sopenharmony_ci set_bit(RXRPC_CALL_EV_ABORT, &call->events); 318c2ecf20Sopenharmony_ci rxrpc_queue_call(call); 328c2ecf20Sopenharmony_ci } 338c2ecf20Sopenharmony_ci} 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci/* 368c2ecf20Sopenharmony_ci * Do TCP-style congestion management [RFC 5681]. 378c2ecf20Sopenharmony_ci */ 388c2ecf20Sopenharmony_cistatic void rxrpc_congestion_management(struct rxrpc_call *call, 398c2ecf20Sopenharmony_ci struct sk_buff *skb, 408c2ecf20Sopenharmony_ci struct rxrpc_ack_summary *summary, 418c2ecf20Sopenharmony_ci rxrpc_serial_t acked_serial) 428c2ecf20Sopenharmony_ci{ 438c2ecf20Sopenharmony_ci enum rxrpc_congest_change change = rxrpc_cong_no_change; 448c2ecf20Sopenharmony_ci unsigned int cumulative_acks = call->cong_cumul_acks; 458c2ecf20Sopenharmony_ci unsigned int cwnd = call->cong_cwnd; 468c2ecf20Sopenharmony_ci bool resend = false; 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci summary->flight_size = 498c2ecf20Sopenharmony_ci (call->tx_top - call->tx_hard_ack) - summary->nr_acks; 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci if (test_and_clear_bit(RXRPC_CALL_RETRANS_TIMEOUT, &call->flags)) { 528c2ecf20Sopenharmony_ci summary->retrans_timeo = true; 538c2ecf20Sopenharmony_ci call->cong_ssthresh = max_t(unsigned int, 548c2ecf20Sopenharmony_ci summary->flight_size / 2, 2); 558c2ecf20Sopenharmony_ci cwnd = 1; 568c2ecf20Sopenharmony_ci if (cwnd >= call->cong_ssthresh && 578c2ecf20Sopenharmony_ci call->cong_mode == RXRPC_CALL_SLOW_START) { 588c2ecf20Sopenharmony_ci call->cong_mode = RXRPC_CALL_CONGEST_AVOIDANCE; 598c2ecf20Sopenharmony_ci call->cong_tstamp = skb->tstamp; 608c2ecf20Sopenharmony_ci cumulative_acks = 0; 618c2ecf20Sopenharmony_ci } 628c2ecf20Sopenharmony_ci } 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci cumulative_acks += summary->nr_new_acks; 658c2ecf20Sopenharmony_ci cumulative_acks += summary->nr_rot_new_acks; 668c2ecf20Sopenharmony_ci if (cumulative_acks > 255) 678c2ecf20Sopenharmony_ci cumulative_acks = 255; 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci summary->mode = call->cong_mode; 708c2ecf20Sopenharmony_ci summary->cwnd = call->cong_cwnd; 718c2ecf20Sopenharmony_ci summary->ssthresh = call->cong_ssthresh; 728c2ecf20Sopenharmony_ci summary->cumulative_acks = cumulative_acks; 738c2ecf20Sopenharmony_ci summary->dup_acks = call->cong_dup_acks; 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci switch (call->cong_mode) { 768c2ecf20Sopenharmony_ci case RXRPC_CALL_SLOW_START: 778c2ecf20Sopenharmony_ci if (summary->nr_nacks > 0) 788c2ecf20Sopenharmony_ci goto packet_loss_detected; 798c2ecf20Sopenharmony_ci if (summary->cumulative_acks > 0) 808c2ecf20Sopenharmony_ci cwnd += 1; 818c2ecf20Sopenharmony_ci if (cwnd >= call->cong_ssthresh) { 828c2ecf20Sopenharmony_ci call->cong_mode = RXRPC_CALL_CONGEST_AVOIDANCE; 838c2ecf20Sopenharmony_ci call->cong_tstamp = skb->tstamp; 848c2ecf20Sopenharmony_ci } 858c2ecf20Sopenharmony_ci goto out; 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci case RXRPC_CALL_CONGEST_AVOIDANCE: 888c2ecf20Sopenharmony_ci if (summary->nr_nacks > 0) 898c2ecf20Sopenharmony_ci goto packet_loss_detected; 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ci /* We analyse the number of packets that get ACK'd per RTT 928c2ecf20Sopenharmony_ci * period and increase the window if we managed to fill it. 938c2ecf20Sopenharmony_ci */ 948c2ecf20Sopenharmony_ci if (call->peer->rtt_count == 0) 958c2ecf20Sopenharmony_ci goto out; 968c2ecf20Sopenharmony_ci if (ktime_before(skb->tstamp, 978c2ecf20Sopenharmony_ci ktime_add_us(call->cong_tstamp, 988c2ecf20Sopenharmony_ci call->peer->srtt_us >> 3))) 998c2ecf20Sopenharmony_ci goto out_no_clear_ca; 1008c2ecf20Sopenharmony_ci change = rxrpc_cong_rtt_window_end; 1018c2ecf20Sopenharmony_ci call->cong_tstamp = skb->tstamp; 1028c2ecf20Sopenharmony_ci if (cumulative_acks >= cwnd) 1038c2ecf20Sopenharmony_ci cwnd++; 1048c2ecf20Sopenharmony_ci goto out; 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci case RXRPC_CALL_PACKET_LOSS: 1078c2ecf20Sopenharmony_ci if (summary->nr_nacks == 0) 1088c2ecf20Sopenharmony_ci goto resume_normality; 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ci if (summary->new_low_nack) { 1118c2ecf20Sopenharmony_ci change = rxrpc_cong_new_low_nack; 1128c2ecf20Sopenharmony_ci call->cong_dup_acks = 1; 1138c2ecf20Sopenharmony_ci if (call->cong_extra > 1) 1148c2ecf20Sopenharmony_ci call->cong_extra = 1; 1158c2ecf20Sopenharmony_ci goto send_extra_data; 1168c2ecf20Sopenharmony_ci } 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ci call->cong_dup_acks++; 1198c2ecf20Sopenharmony_ci if (call->cong_dup_acks < 3) 1208c2ecf20Sopenharmony_ci goto send_extra_data; 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ci change = rxrpc_cong_begin_retransmission; 1238c2ecf20Sopenharmony_ci call->cong_mode = RXRPC_CALL_FAST_RETRANSMIT; 1248c2ecf20Sopenharmony_ci call->cong_ssthresh = max_t(unsigned int, 1258c2ecf20Sopenharmony_ci summary->flight_size / 2, 2); 1268c2ecf20Sopenharmony_ci cwnd = call->cong_ssthresh + 3; 1278c2ecf20Sopenharmony_ci call->cong_extra = 0; 1288c2ecf20Sopenharmony_ci call->cong_dup_acks = 0; 1298c2ecf20Sopenharmony_ci resend = true; 1308c2ecf20Sopenharmony_ci goto out; 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ci case RXRPC_CALL_FAST_RETRANSMIT: 1338c2ecf20Sopenharmony_ci if (!summary->new_low_nack) { 1348c2ecf20Sopenharmony_ci if (summary->nr_new_acks == 0) 1358c2ecf20Sopenharmony_ci cwnd += 1; 1368c2ecf20Sopenharmony_ci call->cong_dup_acks++; 1378c2ecf20Sopenharmony_ci if (call->cong_dup_acks == 2) { 1388c2ecf20Sopenharmony_ci change = rxrpc_cong_retransmit_again; 1398c2ecf20Sopenharmony_ci call->cong_dup_acks = 0; 1408c2ecf20Sopenharmony_ci resend = true; 1418c2ecf20Sopenharmony_ci } 1428c2ecf20Sopenharmony_ci } else { 1438c2ecf20Sopenharmony_ci change = rxrpc_cong_progress; 1448c2ecf20Sopenharmony_ci cwnd = call->cong_ssthresh; 1458c2ecf20Sopenharmony_ci if (summary->nr_nacks == 0) 1468c2ecf20Sopenharmony_ci goto resume_normality; 1478c2ecf20Sopenharmony_ci } 1488c2ecf20Sopenharmony_ci goto out; 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_ci default: 1518c2ecf20Sopenharmony_ci BUG(); 1528c2ecf20Sopenharmony_ci goto out; 1538c2ecf20Sopenharmony_ci } 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_ciresume_normality: 1568c2ecf20Sopenharmony_ci change = rxrpc_cong_cleared_nacks; 1578c2ecf20Sopenharmony_ci call->cong_dup_acks = 0; 1588c2ecf20Sopenharmony_ci call->cong_extra = 0; 1598c2ecf20Sopenharmony_ci call->cong_tstamp = skb->tstamp; 1608c2ecf20Sopenharmony_ci if (cwnd < call->cong_ssthresh) 1618c2ecf20Sopenharmony_ci call->cong_mode = RXRPC_CALL_SLOW_START; 1628c2ecf20Sopenharmony_ci else 1638c2ecf20Sopenharmony_ci call->cong_mode = RXRPC_CALL_CONGEST_AVOIDANCE; 1648c2ecf20Sopenharmony_ciout: 1658c2ecf20Sopenharmony_ci cumulative_acks = 0; 1668c2ecf20Sopenharmony_ciout_no_clear_ca: 1678c2ecf20Sopenharmony_ci if (cwnd >= RXRPC_RXTX_BUFF_SIZE - 1) 1688c2ecf20Sopenharmony_ci cwnd = RXRPC_RXTX_BUFF_SIZE - 1; 1698c2ecf20Sopenharmony_ci call->cong_cwnd = cwnd; 1708c2ecf20Sopenharmony_ci call->cong_cumul_acks = cumulative_acks; 1718c2ecf20Sopenharmony_ci trace_rxrpc_congest(call, summary, acked_serial, change); 1728c2ecf20Sopenharmony_ci if (resend && !test_and_set_bit(RXRPC_CALL_EV_RESEND, &call->events)) 1738c2ecf20Sopenharmony_ci rxrpc_queue_call(call); 1748c2ecf20Sopenharmony_ci return; 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_cipacket_loss_detected: 1778c2ecf20Sopenharmony_ci change = rxrpc_cong_saw_nack; 1788c2ecf20Sopenharmony_ci call->cong_mode = RXRPC_CALL_PACKET_LOSS; 1798c2ecf20Sopenharmony_ci call->cong_dup_acks = 0; 1808c2ecf20Sopenharmony_ci goto send_extra_data; 1818c2ecf20Sopenharmony_ci 1828c2ecf20Sopenharmony_cisend_extra_data: 1838c2ecf20Sopenharmony_ci /* Send some previously unsent DATA if we have some to advance the ACK 1848c2ecf20Sopenharmony_ci * state. 1858c2ecf20Sopenharmony_ci */ 1868c2ecf20Sopenharmony_ci if (call->rxtx_annotations[call->tx_top & RXRPC_RXTX_BUFF_MASK] & 1878c2ecf20Sopenharmony_ci RXRPC_TX_ANNO_LAST || 1888c2ecf20Sopenharmony_ci summary->nr_acks != call->tx_top - call->tx_hard_ack) { 1898c2ecf20Sopenharmony_ci call->cong_extra++; 1908c2ecf20Sopenharmony_ci wake_up(&call->waitq); 1918c2ecf20Sopenharmony_ci } 1928c2ecf20Sopenharmony_ci goto out_no_clear_ca; 1938c2ecf20Sopenharmony_ci} 1948c2ecf20Sopenharmony_ci 1958c2ecf20Sopenharmony_ci/* 1968c2ecf20Sopenharmony_ci * Apply a hard ACK by advancing the Tx window. 1978c2ecf20Sopenharmony_ci */ 1988c2ecf20Sopenharmony_cistatic bool rxrpc_rotate_tx_window(struct rxrpc_call *call, rxrpc_seq_t to, 1998c2ecf20Sopenharmony_ci struct rxrpc_ack_summary *summary) 2008c2ecf20Sopenharmony_ci{ 2018c2ecf20Sopenharmony_ci struct sk_buff *skb, *list = NULL; 2028c2ecf20Sopenharmony_ci bool rot_last = false; 2038c2ecf20Sopenharmony_ci int ix; 2048c2ecf20Sopenharmony_ci u8 annotation; 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_ci if (call->acks_lowest_nak == call->tx_hard_ack) { 2078c2ecf20Sopenharmony_ci call->acks_lowest_nak = to; 2088c2ecf20Sopenharmony_ci } else if (before_eq(call->acks_lowest_nak, to)) { 2098c2ecf20Sopenharmony_ci summary->new_low_nack = true; 2108c2ecf20Sopenharmony_ci call->acks_lowest_nak = to; 2118c2ecf20Sopenharmony_ci } 2128c2ecf20Sopenharmony_ci 2138c2ecf20Sopenharmony_ci spin_lock(&call->lock); 2148c2ecf20Sopenharmony_ci 2158c2ecf20Sopenharmony_ci while (before(call->tx_hard_ack, to)) { 2168c2ecf20Sopenharmony_ci call->tx_hard_ack++; 2178c2ecf20Sopenharmony_ci ix = call->tx_hard_ack & RXRPC_RXTX_BUFF_MASK; 2188c2ecf20Sopenharmony_ci skb = call->rxtx_buffer[ix]; 2198c2ecf20Sopenharmony_ci annotation = call->rxtx_annotations[ix]; 2208c2ecf20Sopenharmony_ci rxrpc_see_skb(skb, rxrpc_skb_rotated); 2218c2ecf20Sopenharmony_ci call->rxtx_buffer[ix] = NULL; 2228c2ecf20Sopenharmony_ci call->rxtx_annotations[ix] = 0; 2238c2ecf20Sopenharmony_ci skb->next = list; 2248c2ecf20Sopenharmony_ci list = skb; 2258c2ecf20Sopenharmony_ci 2268c2ecf20Sopenharmony_ci if (annotation & RXRPC_TX_ANNO_LAST) { 2278c2ecf20Sopenharmony_ci set_bit(RXRPC_CALL_TX_LAST, &call->flags); 2288c2ecf20Sopenharmony_ci rot_last = true; 2298c2ecf20Sopenharmony_ci } 2308c2ecf20Sopenharmony_ci if ((annotation & RXRPC_TX_ANNO_MASK) != RXRPC_TX_ANNO_ACK) 2318c2ecf20Sopenharmony_ci summary->nr_rot_new_acks++; 2328c2ecf20Sopenharmony_ci } 2338c2ecf20Sopenharmony_ci 2348c2ecf20Sopenharmony_ci spin_unlock(&call->lock); 2358c2ecf20Sopenharmony_ci 2368c2ecf20Sopenharmony_ci trace_rxrpc_transmit(call, (rot_last ? 2378c2ecf20Sopenharmony_ci rxrpc_transmit_rotate_last : 2388c2ecf20Sopenharmony_ci rxrpc_transmit_rotate)); 2398c2ecf20Sopenharmony_ci wake_up(&call->waitq); 2408c2ecf20Sopenharmony_ci 2418c2ecf20Sopenharmony_ci while (list) { 2428c2ecf20Sopenharmony_ci skb = list; 2438c2ecf20Sopenharmony_ci list = skb->next; 2448c2ecf20Sopenharmony_ci skb_mark_not_on_list(skb); 2458c2ecf20Sopenharmony_ci rxrpc_free_skb(skb, rxrpc_skb_freed); 2468c2ecf20Sopenharmony_ci } 2478c2ecf20Sopenharmony_ci 2488c2ecf20Sopenharmony_ci return rot_last; 2498c2ecf20Sopenharmony_ci} 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_ci/* 2528c2ecf20Sopenharmony_ci * End the transmission phase of a call. 2538c2ecf20Sopenharmony_ci * 2548c2ecf20Sopenharmony_ci * This occurs when we get an ACKALL packet, the first DATA packet of a reply, 2558c2ecf20Sopenharmony_ci * or a final ACK packet. 2568c2ecf20Sopenharmony_ci */ 2578c2ecf20Sopenharmony_cistatic bool rxrpc_end_tx_phase(struct rxrpc_call *call, bool reply_begun, 2588c2ecf20Sopenharmony_ci const char *abort_why) 2598c2ecf20Sopenharmony_ci{ 2608c2ecf20Sopenharmony_ci unsigned int state; 2618c2ecf20Sopenharmony_ci 2628c2ecf20Sopenharmony_ci ASSERT(test_bit(RXRPC_CALL_TX_LAST, &call->flags)); 2638c2ecf20Sopenharmony_ci 2648c2ecf20Sopenharmony_ci write_lock(&call->state_lock); 2658c2ecf20Sopenharmony_ci 2668c2ecf20Sopenharmony_ci state = call->state; 2678c2ecf20Sopenharmony_ci switch (state) { 2688c2ecf20Sopenharmony_ci case RXRPC_CALL_CLIENT_SEND_REQUEST: 2698c2ecf20Sopenharmony_ci case RXRPC_CALL_CLIENT_AWAIT_REPLY: 2708c2ecf20Sopenharmony_ci if (reply_begun) 2718c2ecf20Sopenharmony_ci call->state = state = RXRPC_CALL_CLIENT_RECV_REPLY; 2728c2ecf20Sopenharmony_ci else 2738c2ecf20Sopenharmony_ci call->state = state = RXRPC_CALL_CLIENT_AWAIT_REPLY; 2748c2ecf20Sopenharmony_ci break; 2758c2ecf20Sopenharmony_ci 2768c2ecf20Sopenharmony_ci case RXRPC_CALL_SERVER_AWAIT_ACK: 2778c2ecf20Sopenharmony_ci __rxrpc_call_completed(call); 2788c2ecf20Sopenharmony_ci state = call->state; 2798c2ecf20Sopenharmony_ci break; 2808c2ecf20Sopenharmony_ci 2818c2ecf20Sopenharmony_ci default: 2828c2ecf20Sopenharmony_ci goto bad_state; 2838c2ecf20Sopenharmony_ci } 2848c2ecf20Sopenharmony_ci 2858c2ecf20Sopenharmony_ci write_unlock(&call->state_lock); 2868c2ecf20Sopenharmony_ci if (state == RXRPC_CALL_CLIENT_AWAIT_REPLY) 2878c2ecf20Sopenharmony_ci trace_rxrpc_transmit(call, rxrpc_transmit_await_reply); 2888c2ecf20Sopenharmony_ci else 2898c2ecf20Sopenharmony_ci trace_rxrpc_transmit(call, rxrpc_transmit_end); 2908c2ecf20Sopenharmony_ci _leave(" = ok"); 2918c2ecf20Sopenharmony_ci return true; 2928c2ecf20Sopenharmony_ci 2938c2ecf20Sopenharmony_cibad_state: 2948c2ecf20Sopenharmony_ci write_unlock(&call->state_lock); 2958c2ecf20Sopenharmony_ci kdebug("end_tx %s", rxrpc_call_states[call->state]); 2968c2ecf20Sopenharmony_ci rxrpc_proto_abort(abort_why, call, call->tx_top); 2978c2ecf20Sopenharmony_ci return false; 2988c2ecf20Sopenharmony_ci} 2998c2ecf20Sopenharmony_ci 3008c2ecf20Sopenharmony_ci/* 3018c2ecf20Sopenharmony_ci * Begin the reply reception phase of a call. 3028c2ecf20Sopenharmony_ci */ 3038c2ecf20Sopenharmony_cistatic bool rxrpc_receiving_reply(struct rxrpc_call *call) 3048c2ecf20Sopenharmony_ci{ 3058c2ecf20Sopenharmony_ci struct rxrpc_ack_summary summary = { 0 }; 3068c2ecf20Sopenharmony_ci unsigned long now, timo; 3078c2ecf20Sopenharmony_ci rxrpc_seq_t top = READ_ONCE(call->tx_top); 3088c2ecf20Sopenharmony_ci 3098c2ecf20Sopenharmony_ci if (call->ackr_reason) { 3108c2ecf20Sopenharmony_ci spin_lock_bh(&call->lock); 3118c2ecf20Sopenharmony_ci call->ackr_reason = 0; 3128c2ecf20Sopenharmony_ci spin_unlock_bh(&call->lock); 3138c2ecf20Sopenharmony_ci now = jiffies; 3148c2ecf20Sopenharmony_ci timo = now + MAX_JIFFY_OFFSET; 3158c2ecf20Sopenharmony_ci WRITE_ONCE(call->resend_at, timo); 3168c2ecf20Sopenharmony_ci WRITE_ONCE(call->ack_at, timo); 3178c2ecf20Sopenharmony_ci trace_rxrpc_timer(call, rxrpc_timer_init_for_reply, now); 3188c2ecf20Sopenharmony_ci } 3198c2ecf20Sopenharmony_ci 3208c2ecf20Sopenharmony_ci if (!test_bit(RXRPC_CALL_TX_LAST, &call->flags)) { 3218c2ecf20Sopenharmony_ci if (!rxrpc_rotate_tx_window(call, top, &summary)) { 3228c2ecf20Sopenharmony_ci rxrpc_proto_abort("TXL", call, top); 3238c2ecf20Sopenharmony_ci return false; 3248c2ecf20Sopenharmony_ci } 3258c2ecf20Sopenharmony_ci } 3268c2ecf20Sopenharmony_ci if (!rxrpc_end_tx_phase(call, true, "ETD")) 3278c2ecf20Sopenharmony_ci return false; 3288c2ecf20Sopenharmony_ci call->tx_phase = false; 3298c2ecf20Sopenharmony_ci return true; 3308c2ecf20Sopenharmony_ci} 3318c2ecf20Sopenharmony_ci 3328c2ecf20Sopenharmony_ci/* 3338c2ecf20Sopenharmony_ci * Scan a data packet to validate its structure and to work out how many 3348c2ecf20Sopenharmony_ci * subpackets it contains. 3358c2ecf20Sopenharmony_ci * 3368c2ecf20Sopenharmony_ci * A jumbo packet is a collection of consecutive packets glued together with 3378c2ecf20Sopenharmony_ci * little headers between that indicate how to change the initial header for 3388c2ecf20Sopenharmony_ci * each subpacket. 3398c2ecf20Sopenharmony_ci * 3408c2ecf20Sopenharmony_ci * RXRPC_JUMBO_PACKET must be set on all but the last subpacket - and all but 3418c2ecf20Sopenharmony_ci * the last are RXRPC_JUMBO_DATALEN in size. The last subpacket may be of any 3428c2ecf20Sopenharmony_ci * size. 3438c2ecf20Sopenharmony_ci */ 3448c2ecf20Sopenharmony_cistatic bool rxrpc_validate_data(struct sk_buff *skb) 3458c2ecf20Sopenharmony_ci{ 3468c2ecf20Sopenharmony_ci struct rxrpc_skb_priv *sp = rxrpc_skb(skb); 3478c2ecf20Sopenharmony_ci unsigned int offset = sizeof(struct rxrpc_wire_header); 3488c2ecf20Sopenharmony_ci unsigned int len = skb->len; 3498c2ecf20Sopenharmony_ci u8 flags = sp->hdr.flags; 3508c2ecf20Sopenharmony_ci 3518c2ecf20Sopenharmony_ci for (;;) { 3528c2ecf20Sopenharmony_ci if (flags & RXRPC_REQUEST_ACK) 3538c2ecf20Sopenharmony_ci __set_bit(sp->nr_subpackets, sp->rx_req_ack); 3548c2ecf20Sopenharmony_ci sp->nr_subpackets++; 3558c2ecf20Sopenharmony_ci 3568c2ecf20Sopenharmony_ci if (!(flags & RXRPC_JUMBO_PACKET)) 3578c2ecf20Sopenharmony_ci break; 3588c2ecf20Sopenharmony_ci 3598c2ecf20Sopenharmony_ci if (len - offset < RXRPC_JUMBO_SUBPKTLEN) 3608c2ecf20Sopenharmony_ci goto protocol_error; 3618c2ecf20Sopenharmony_ci if (flags & RXRPC_LAST_PACKET) 3628c2ecf20Sopenharmony_ci goto protocol_error; 3638c2ecf20Sopenharmony_ci offset += RXRPC_JUMBO_DATALEN; 3648c2ecf20Sopenharmony_ci if (skb_copy_bits(skb, offset, &flags, 1) < 0) 3658c2ecf20Sopenharmony_ci goto protocol_error; 3668c2ecf20Sopenharmony_ci offset += sizeof(struct rxrpc_jumbo_header); 3678c2ecf20Sopenharmony_ci } 3688c2ecf20Sopenharmony_ci 3698c2ecf20Sopenharmony_ci if (flags & RXRPC_LAST_PACKET) 3708c2ecf20Sopenharmony_ci sp->rx_flags |= RXRPC_SKB_INCL_LAST; 3718c2ecf20Sopenharmony_ci return true; 3728c2ecf20Sopenharmony_ci 3738c2ecf20Sopenharmony_ciprotocol_error: 3748c2ecf20Sopenharmony_ci return false; 3758c2ecf20Sopenharmony_ci} 3768c2ecf20Sopenharmony_ci 3778c2ecf20Sopenharmony_ci/* 3788c2ecf20Sopenharmony_ci * Handle reception of a duplicate packet. 3798c2ecf20Sopenharmony_ci * 3808c2ecf20Sopenharmony_ci * We have to take care to avoid an attack here whereby we're given a series of 3818c2ecf20Sopenharmony_ci * jumbograms, each with a sequence number one before the preceding one and 3828c2ecf20Sopenharmony_ci * filled up to maximum UDP size. If they never send us the first packet in 3838c2ecf20Sopenharmony_ci * the sequence, they can cause us to have to hold on to around 2MiB of kernel 3848c2ecf20Sopenharmony_ci * space until the call times out. 3858c2ecf20Sopenharmony_ci * 3868c2ecf20Sopenharmony_ci * We limit the space usage by only accepting three duplicate jumbo packets per 3878c2ecf20Sopenharmony_ci * call. After that, we tell the other side we're no longer accepting jumbos 3888c2ecf20Sopenharmony_ci * (that information is encoded in the ACK packet). 3898c2ecf20Sopenharmony_ci */ 3908c2ecf20Sopenharmony_cistatic void rxrpc_input_dup_data(struct rxrpc_call *call, rxrpc_seq_t seq, 3918c2ecf20Sopenharmony_ci bool is_jumbo, bool *_jumbo_bad) 3928c2ecf20Sopenharmony_ci{ 3938c2ecf20Sopenharmony_ci /* Discard normal packets that are duplicates. */ 3948c2ecf20Sopenharmony_ci if (is_jumbo) 3958c2ecf20Sopenharmony_ci return; 3968c2ecf20Sopenharmony_ci 3978c2ecf20Sopenharmony_ci /* Skip jumbo subpackets that are duplicates. When we've had three or 3988c2ecf20Sopenharmony_ci * more partially duplicate jumbo packets, we refuse to take any more 3998c2ecf20Sopenharmony_ci * jumbos for this call. 4008c2ecf20Sopenharmony_ci */ 4018c2ecf20Sopenharmony_ci if (!*_jumbo_bad) { 4028c2ecf20Sopenharmony_ci call->nr_jumbo_bad++; 4038c2ecf20Sopenharmony_ci *_jumbo_bad = true; 4048c2ecf20Sopenharmony_ci } 4058c2ecf20Sopenharmony_ci} 4068c2ecf20Sopenharmony_ci 4078c2ecf20Sopenharmony_ci/* 4088c2ecf20Sopenharmony_ci * Process a DATA packet, adding the packet to the Rx ring. The caller's 4098c2ecf20Sopenharmony_ci * packet ref must be passed on or discarded. 4108c2ecf20Sopenharmony_ci */ 4118c2ecf20Sopenharmony_cistatic void rxrpc_input_data(struct rxrpc_call *call, struct sk_buff *skb) 4128c2ecf20Sopenharmony_ci{ 4138c2ecf20Sopenharmony_ci struct rxrpc_skb_priv *sp = rxrpc_skb(skb); 4148c2ecf20Sopenharmony_ci enum rxrpc_call_state state; 4158c2ecf20Sopenharmony_ci unsigned int j, nr_subpackets, nr_unacked = 0; 4168c2ecf20Sopenharmony_ci rxrpc_serial_t serial = sp->hdr.serial, ack_serial = serial; 4178c2ecf20Sopenharmony_ci rxrpc_seq_t seq0 = sp->hdr.seq, hard_ack; 4188c2ecf20Sopenharmony_ci bool immediate_ack = false, jumbo_bad = false; 4198c2ecf20Sopenharmony_ci u8 ack = 0; 4208c2ecf20Sopenharmony_ci 4218c2ecf20Sopenharmony_ci _enter("{%u,%u},{%u,%u}", 4228c2ecf20Sopenharmony_ci call->rx_hard_ack, call->rx_top, skb->len, seq0); 4238c2ecf20Sopenharmony_ci 4248c2ecf20Sopenharmony_ci _proto("Rx DATA %%%u { #%u f=%02x n=%u }", 4258c2ecf20Sopenharmony_ci sp->hdr.serial, seq0, sp->hdr.flags, sp->nr_subpackets); 4268c2ecf20Sopenharmony_ci 4278c2ecf20Sopenharmony_ci state = READ_ONCE(call->state); 4288c2ecf20Sopenharmony_ci if (state >= RXRPC_CALL_COMPLETE) { 4298c2ecf20Sopenharmony_ci rxrpc_free_skb(skb, rxrpc_skb_freed); 4308c2ecf20Sopenharmony_ci return; 4318c2ecf20Sopenharmony_ci } 4328c2ecf20Sopenharmony_ci 4338c2ecf20Sopenharmony_ci if (state == RXRPC_CALL_SERVER_RECV_REQUEST) { 4348c2ecf20Sopenharmony_ci unsigned long timo = READ_ONCE(call->next_req_timo); 4358c2ecf20Sopenharmony_ci unsigned long now, expect_req_by; 4368c2ecf20Sopenharmony_ci 4378c2ecf20Sopenharmony_ci if (timo) { 4388c2ecf20Sopenharmony_ci now = jiffies; 4398c2ecf20Sopenharmony_ci expect_req_by = now + timo; 4408c2ecf20Sopenharmony_ci WRITE_ONCE(call->expect_req_by, expect_req_by); 4418c2ecf20Sopenharmony_ci rxrpc_reduce_call_timer(call, expect_req_by, now, 4428c2ecf20Sopenharmony_ci rxrpc_timer_set_for_idle); 4438c2ecf20Sopenharmony_ci } 4448c2ecf20Sopenharmony_ci } 4458c2ecf20Sopenharmony_ci 4468c2ecf20Sopenharmony_ci spin_lock(&call->input_lock); 4478c2ecf20Sopenharmony_ci 4488c2ecf20Sopenharmony_ci /* Received data implicitly ACKs all of the request packets we sent 4498c2ecf20Sopenharmony_ci * when we're acting as a client. 4508c2ecf20Sopenharmony_ci */ 4518c2ecf20Sopenharmony_ci if ((state == RXRPC_CALL_CLIENT_SEND_REQUEST || 4528c2ecf20Sopenharmony_ci state == RXRPC_CALL_CLIENT_AWAIT_REPLY) && 4538c2ecf20Sopenharmony_ci !rxrpc_receiving_reply(call)) 4548c2ecf20Sopenharmony_ci goto unlock; 4558c2ecf20Sopenharmony_ci 4568c2ecf20Sopenharmony_ci hard_ack = READ_ONCE(call->rx_hard_ack); 4578c2ecf20Sopenharmony_ci 4588c2ecf20Sopenharmony_ci nr_subpackets = sp->nr_subpackets; 4598c2ecf20Sopenharmony_ci if (nr_subpackets > 1) { 4608c2ecf20Sopenharmony_ci if (call->nr_jumbo_bad > 3) { 4618c2ecf20Sopenharmony_ci ack = RXRPC_ACK_NOSPACE; 4628c2ecf20Sopenharmony_ci ack_serial = serial; 4638c2ecf20Sopenharmony_ci goto ack; 4648c2ecf20Sopenharmony_ci } 4658c2ecf20Sopenharmony_ci } 4668c2ecf20Sopenharmony_ci 4678c2ecf20Sopenharmony_ci for (j = 0; j < nr_subpackets; j++) { 4688c2ecf20Sopenharmony_ci rxrpc_serial_t serial = sp->hdr.serial + j; 4698c2ecf20Sopenharmony_ci rxrpc_seq_t seq = seq0 + j; 4708c2ecf20Sopenharmony_ci unsigned int ix = seq & RXRPC_RXTX_BUFF_MASK; 4718c2ecf20Sopenharmony_ci bool terminal = (j == nr_subpackets - 1); 4728c2ecf20Sopenharmony_ci bool last = terminal && (sp->rx_flags & RXRPC_SKB_INCL_LAST); 4738c2ecf20Sopenharmony_ci u8 flags, annotation = j; 4748c2ecf20Sopenharmony_ci 4758c2ecf20Sopenharmony_ci _proto("Rx DATA+%u %%%u { #%x t=%u l=%u }", 4768c2ecf20Sopenharmony_ci j, serial, seq, terminal, last); 4778c2ecf20Sopenharmony_ci 4788c2ecf20Sopenharmony_ci if (last) { 4798c2ecf20Sopenharmony_ci if (test_bit(RXRPC_CALL_RX_LAST, &call->flags) && 4808c2ecf20Sopenharmony_ci seq != call->rx_top) { 4818c2ecf20Sopenharmony_ci rxrpc_proto_abort("LSN", call, seq); 4828c2ecf20Sopenharmony_ci goto unlock; 4838c2ecf20Sopenharmony_ci } 4848c2ecf20Sopenharmony_ci } else { 4858c2ecf20Sopenharmony_ci if (test_bit(RXRPC_CALL_RX_LAST, &call->flags) && 4868c2ecf20Sopenharmony_ci after_eq(seq, call->rx_top)) { 4878c2ecf20Sopenharmony_ci rxrpc_proto_abort("LSA", call, seq); 4888c2ecf20Sopenharmony_ci goto unlock; 4898c2ecf20Sopenharmony_ci } 4908c2ecf20Sopenharmony_ci } 4918c2ecf20Sopenharmony_ci 4928c2ecf20Sopenharmony_ci flags = 0; 4938c2ecf20Sopenharmony_ci if (last) 4948c2ecf20Sopenharmony_ci flags |= RXRPC_LAST_PACKET; 4958c2ecf20Sopenharmony_ci if (!terminal) 4968c2ecf20Sopenharmony_ci flags |= RXRPC_JUMBO_PACKET; 4978c2ecf20Sopenharmony_ci if (test_bit(j, sp->rx_req_ack)) 4988c2ecf20Sopenharmony_ci flags |= RXRPC_REQUEST_ACK; 4998c2ecf20Sopenharmony_ci trace_rxrpc_rx_data(call->debug_id, seq, serial, flags, annotation); 5008c2ecf20Sopenharmony_ci 5018c2ecf20Sopenharmony_ci if (before_eq(seq, hard_ack)) { 5028c2ecf20Sopenharmony_ci ack = RXRPC_ACK_DUPLICATE; 5038c2ecf20Sopenharmony_ci ack_serial = serial; 5048c2ecf20Sopenharmony_ci continue; 5058c2ecf20Sopenharmony_ci } 5068c2ecf20Sopenharmony_ci 5078c2ecf20Sopenharmony_ci if (call->rxtx_buffer[ix]) { 5088c2ecf20Sopenharmony_ci rxrpc_input_dup_data(call, seq, nr_subpackets > 1, 5098c2ecf20Sopenharmony_ci &jumbo_bad); 5108c2ecf20Sopenharmony_ci if (ack != RXRPC_ACK_DUPLICATE) { 5118c2ecf20Sopenharmony_ci ack = RXRPC_ACK_DUPLICATE; 5128c2ecf20Sopenharmony_ci ack_serial = serial; 5138c2ecf20Sopenharmony_ci } 5148c2ecf20Sopenharmony_ci immediate_ack = true; 5158c2ecf20Sopenharmony_ci continue; 5168c2ecf20Sopenharmony_ci } 5178c2ecf20Sopenharmony_ci 5188c2ecf20Sopenharmony_ci if (after(seq, hard_ack + call->rx_winsize)) { 5198c2ecf20Sopenharmony_ci ack = RXRPC_ACK_EXCEEDS_WINDOW; 5208c2ecf20Sopenharmony_ci ack_serial = serial; 5218c2ecf20Sopenharmony_ci if (flags & RXRPC_JUMBO_PACKET) { 5228c2ecf20Sopenharmony_ci if (!jumbo_bad) { 5238c2ecf20Sopenharmony_ci call->nr_jumbo_bad++; 5248c2ecf20Sopenharmony_ci jumbo_bad = true; 5258c2ecf20Sopenharmony_ci } 5268c2ecf20Sopenharmony_ci } 5278c2ecf20Sopenharmony_ci 5288c2ecf20Sopenharmony_ci goto ack; 5298c2ecf20Sopenharmony_ci } 5308c2ecf20Sopenharmony_ci 5318c2ecf20Sopenharmony_ci if (flags & RXRPC_REQUEST_ACK && !ack) { 5328c2ecf20Sopenharmony_ci ack = RXRPC_ACK_REQUESTED; 5338c2ecf20Sopenharmony_ci ack_serial = serial; 5348c2ecf20Sopenharmony_ci } 5358c2ecf20Sopenharmony_ci 5368c2ecf20Sopenharmony_ci if (after(seq0, call->ackr_highest_seq)) 5378c2ecf20Sopenharmony_ci call->ackr_highest_seq = seq0; 5388c2ecf20Sopenharmony_ci 5398c2ecf20Sopenharmony_ci /* Queue the packet. We use a couple of memory barriers here as need 5408c2ecf20Sopenharmony_ci * to make sure that rx_top is perceived to be set after the buffer 5418c2ecf20Sopenharmony_ci * pointer and that the buffer pointer is set after the annotation and 5428c2ecf20Sopenharmony_ci * the skb data. 5438c2ecf20Sopenharmony_ci * 5448c2ecf20Sopenharmony_ci * Barriers against rxrpc_recvmsg_data() and rxrpc_rotate_rx_window() 5458c2ecf20Sopenharmony_ci * and also rxrpc_fill_out_ack(). 5468c2ecf20Sopenharmony_ci */ 5478c2ecf20Sopenharmony_ci if (!terminal) 5488c2ecf20Sopenharmony_ci rxrpc_get_skb(skb, rxrpc_skb_got); 5498c2ecf20Sopenharmony_ci call->rxtx_annotations[ix] = annotation; 5508c2ecf20Sopenharmony_ci smp_wmb(); 5518c2ecf20Sopenharmony_ci call->rxtx_buffer[ix] = skb; 5528c2ecf20Sopenharmony_ci if (after(seq, call->rx_top)) { 5538c2ecf20Sopenharmony_ci smp_store_release(&call->rx_top, seq); 5548c2ecf20Sopenharmony_ci } else if (before(seq, call->rx_top)) { 5558c2ecf20Sopenharmony_ci /* Send an immediate ACK if we fill in a hole */ 5568c2ecf20Sopenharmony_ci if (!ack) { 5578c2ecf20Sopenharmony_ci ack = RXRPC_ACK_DELAY; 5588c2ecf20Sopenharmony_ci ack_serial = serial; 5598c2ecf20Sopenharmony_ci } 5608c2ecf20Sopenharmony_ci immediate_ack = true; 5618c2ecf20Sopenharmony_ci } 5628c2ecf20Sopenharmony_ci 5638c2ecf20Sopenharmony_ci if (terminal) { 5648c2ecf20Sopenharmony_ci /* From this point on, we're not allowed to touch the 5658c2ecf20Sopenharmony_ci * packet any longer as its ref now belongs to the Rx 5668c2ecf20Sopenharmony_ci * ring. 5678c2ecf20Sopenharmony_ci */ 5688c2ecf20Sopenharmony_ci skb = NULL; 5698c2ecf20Sopenharmony_ci sp = NULL; 5708c2ecf20Sopenharmony_ci } 5718c2ecf20Sopenharmony_ci 5728c2ecf20Sopenharmony_ci nr_unacked++; 5738c2ecf20Sopenharmony_ci 5748c2ecf20Sopenharmony_ci if (last) { 5758c2ecf20Sopenharmony_ci set_bit(RXRPC_CALL_RX_LAST, &call->flags); 5768c2ecf20Sopenharmony_ci if (!ack) { 5778c2ecf20Sopenharmony_ci ack = RXRPC_ACK_DELAY; 5788c2ecf20Sopenharmony_ci ack_serial = serial; 5798c2ecf20Sopenharmony_ci } 5808c2ecf20Sopenharmony_ci trace_rxrpc_receive(call, rxrpc_receive_queue_last, serial, seq); 5818c2ecf20Sopenharmony_ci } else { 5828c2ecf20Sopenharmony_ci trace_rxrpc_receive(call, rxrpc_receive_queue, serial, seq); 5838c2ecf20Sopenharmony_ci } 5848c2ecf20Sopenharmony_ci 5858c2ecf20Sopenharmony_ci if (after_eq(seq, call->rx_expect_next)) { 5868c2ecf20Sopenharmony_ci if (after(seq, call->rx_expect_next)) { 5878c2ecf20Sopenharmony_ci _net("OOS %u > %u", seq, call->rx_expect_next); 5888c2ecf20Sopenharmony_ci ack = RXRPC_ACK_OUT_OF_SEQUENCE; 5898c2ecf20Sopenharmony_ci ack_serial = serial; 5908c2ecf20Sopenharmony_ci } 5918c2ecf20Sopenharmony_ci call->rx_expect_next = seq + 1; 5928c2ecf20Sopenharmony_ci } 5938c2ecf20Sopenharmony_ci if (!ack) 5948c2ecf20Sopenharmony_ci ack_serial = serial; 5958c2ecf20Sopenharmony_ci } 5968c2ecf20Sopenharmony_ci 5978c2ecf20Sopenharmony_ciack: 5988c2ecf20Sopenharmony_ci if (atomic_add_return(nr_unacked, &call->ackr_nr_unacked) > 2 && !ack) 5998c2ecf20Sopenharmony_ci ack = RXRPC_ACK_IDLE; 6008c2ecf20Sopenharmony_ci 6018c2ecf20Sopenharmony_ci if (ack) 6028c2ecf20Sopenharmony_ci rxrpc_propose_ACK(call, ack, ack_serial, 6038c2ecf20Sopenharmony_ci immediate_ack, true, 6048c2ecf20Sopenharmony_ci rxrpc_propose_ack_input_data); 6058c2ecf20Sopenharmony_ci else 6068c2ecf20Sopenharmony_ci rxrpc_propose_ACK(call, RXRPC_ACK_DELAY, serial, 6078c2ecf20Sopenharmony_ci false, true, 6088c2ecf20Sopenharmony_ci rxrpc_propose_ack_input_data); 6098c2ecf20Sopenharmony_ci 6108c2ecf20Sopenharmony_ci trace_rxrpc_notify_socket(call->debug_id, serial); 6118c2ecf20Sopenharmony_ci rxrpc_notify_socket(call); 6128c2ecf20Sopenharmony_ci 6138c2ecf20Sopenharmony_ciunlock: 6148c2ecf20Sopenharmony_ci spin_unlock(&call->input_lock); 6158c2ecf20Sopenharmony_ci rxrpc_free_skb(skb, rxrpc_skb_freed); 6168c2ecf20Sopenharmony_ci _leave(" [queued]"); 6178c2ecf20Sopenharmony_ci} 6188c2ecf20Sopenharmony_ci 6198c2ecf20Sopenharmony_ci/* 6208c2ecf20Sopenharmony_ci * See if there's a cached RTT probe to complete. 6218c2ecf20Sopenharmony_ci */ 6228c2ecf20Sopenharmony_cistatic void rxrpc_complete_rtt_probe(struct rxrpc_call *call, 6238c2ecf20Sopenharmony_ci ktime_t resp_time, 6248c2ecf20Sopenharmony_ci rxrpc_serial_t acked_serial, 6258c2ecf20Sopenharmony_ci rxrpc_serial_t ack_serial, 6268c2ecf20Sopenharmony_ci enum rxrpc_rtt_rx_trace type) 6278c2ecf20Sopenharmony_ci{ 6288c2ecf20Sopenharmony_ci rxrpc_serial_t orig_serial; 6298c2ecf20Sopenharmony_ci unsigned long avail; 6308c2ecf20Sopenharmony_ci ktime_t sent_at; 6318c2ecf20Sopenharmony_ci bool matched = false; 6328c2ecf20Sopenharmony_ci int i; 6338c2ecf20Sopenharmony_ci 6348c2ecf20Sopenharmony_ci avail = READ_ONCE(call->rtt_avail); 6358c2ecf20Sopenharmony_ci smp_rmb(); /* Read avail bits before accessing data. */ 6368c2ecf20Sopenharmony_ci 6378c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(call->rtt_serial); i++) { 6388c2ecf20Sopenharmony_ci if (!test_bit(i + RXRPC_CALL_RTT_PEND_SHIFT, &avail)) 6398c2ecf20Sopenharmony_ci continue; 6408c2ecf20Sopenharmony_ci 6418c2ecf20Sopenharmony_ci sent_at = call->rtt_sent_at[i]; 6428c2ecf20Sopenharmony_ci orig_serial = call->rtt_serial[i]; 6438c2ecf20Sopenharmony_ci 6448c2ecf20Sopenharmony_ci if (orig_serial == acked_serial) { 6458c2ecf20Sopenharmony_ci clear_bit(i + RXRPC_CALL_RTT_PEND_SHIFT, &call->rtt_avail); 6468c2ecf20Sopenharmony_ci smp_mb(); /* Read data before setting avail bit */ 6478c2ecf20Sopenharmony_ci set_bit(i, &call->rtt_avail); 6488c2ecf20Sopenharmony_ci if (type != rxrpc_rtt_rx_cancel) 6498c2ecf20Sopenharmony_ci rxrpc_peer_add_rtt(call, type, i, acked_serial, ack_serial, 6508c2ecf20Sopenharmony_ci sent_at, resp_time); 6518c2ecf20Sopenharmony_ci else 6528c2ecf20Sopenharmony_ci trace_rxrpc_rtt_rx(call, rxrpc_rtt_rx_cancel, i, 6538c2ecf20Sopenharmony_ci orig_serial, acked_serial, 0, 0); 6548c2ecf20Sopenharmony_ci matched = true; 6558c2ecf20Sopenharmony_ci } 6568c2ecf20Sopenharmony_ci 6578c2ecf20Sopenharmony_ci /* If a later serial is being acked, then mark this slot as 6588c2ecf20Sopenharmony_ci * being available. 6598c2ecf20Sopenharmony_ci */ 6608c2ecf20Sopenharmony_ci if (after(acked_serial, orig_serial)) { 6618c2ecf20Sopenharmony_ci trace_rxrpc_rtt_rx(call, rxrpc_rtt_rx_obsolete, i, 6628c2ecf20Sopenharmony_ci orig_serial, acked_serial, 0, 0); 6638c2ecf20Sopenharmony_ci clear_bit(i + RXRPC_CALL_RTT_PEND_SHIFT, &call->rtt_avail); 6648c2ecf20Sopenharmony_ci smp_wmb(); 6658c2ecf20Sopenharmony_ci set_bit(i, &call->rtt_avail); 6668c2ecf20Sopenharmony_ci } 6678c2ecf20Sopenharmony_ci } 6688c2ecf20Sopenharmony_ci 6698c2ecf20Sopenharmony_ci if (!matched) 6708c2ecf20Sopenharmony_ci trace_rxrpc_rtt_rx(call, rxrpc_rtt_rx_lost, 9, 0, acked_serial, 0, 0); 6718c2ecf20Sopenharmony_ci} 6728c2ecf20Sopenharmony_ci 6738c2ecf20Sopenharmony_ci/* 6748c2ecf20Sopenharmony_ci * Process the response to a ping that we sent to find out if we lost an ACK. 6758c2ecf20Sopenharmony_ci * 6768c2ecf20Sopenharmony_ci * If we got back a ping response that indicates a lower tx_top than what we 6778c2ecf20Sopenharmony_ci * had at the time of the ping transmission, we adjudge all the DATA packets 6788c2ecf20Sopenharmony_ci * sent between the response tx_top and the ping-time tx_top to have been lost. 6798c2ecf20Sopenharmony_ci */ 6808c2ecf20Sopenharmony_cistatic void rxrpc_input_check_for_lost_ack(struct rxrpc_call *call) 6818c2ecf20Sopenharmony_ci{ 6828c2ecf20Sopenharmony_ci rxrpc_seq_t top, bottom, seq; 6838c2ecf20Sopenharmony_ci bool resend = false; 6848c2ecf20Sopenharmony_ci 6858c2ecf20Sopenharmony_ci spin_lock_bh(&call->lock); 6868c2ecf20Sopenharmony_ci 6878c2ecf20Sopenharmony_ci bottom = call->tx_hard_ack + 1; 6888c2ecf20Sopenharmony_ci top = call->acks_lost_top; 6898c2ecf20Sopenharmony_ci if (before(bottom, top)) { 6908c2ecf20Sopenharmony_ci for (seq = bottom; before_eq(seq, top); seq++) { 6918c2ecf20Sopenharmony_ci int ix = seq & RXRPC_RXTX_BUFF_MASK; 6928c2ecf20Sopenharmony_ci u8 annotation = call->rxtx_annotations[ix]; 6938c2ecf20Sopenharmony_ci u8 anno_type = annotation & RXRPC_TX_ANNO_MASK; 6948c2ecf20Sopenharmony_ci 6958c2ecf20Sopenharmony_ci if (anno_type != RXRPC_TX_ANNO_UNACK) 6968c2ecf20Sopenharmony_ci continue; 6978c2ecf20Sopenharmony_ci annotation &= ~RXRPC_TX_ANNO_MASK; 6988c2ecf20Sopenharmony_ci annotation |= RXRPC_TX_ANNO_RETRANS; 6998c2ecf20Sopenharmony_ci call->rxtx_annotations[ix] = annotation; 7008c2ecf20Sopenharmony_ci resend = true; 7018c2ecf20Sopenharmony_ci } 7028c2ecf20Sopenharmony_ci } 7038c2ecf20Sopenharmony_ci 7048c2ecf20Sopenharmony_ci spin_unlock_bh(&call->lock); 7058c2ecf20Sopenharmony_ci 7068c2ecf20Sopenharmony_ci if (resend && !test_and_set_bit(RXRPC_CALL_EV_RESEND, &call->events)) 7078c2ecf20Sopenharmony_ci rxrpc_queue_call(call); 7088c2ecf20Sopenharmony_ci} 7098c2ecf20Sopenharmony_ci 7108c2ecf20Sopenharmony_ci/* 7118c2ecf20Sopenharmony_ci * Process a ping response. 7128c2ecf20Sopenharmony_ci */ 7138c2ecf20Sopenharmony_cistatic void rxrpc_input_ping_response(struct rxrpc_call *call, 7148c2ecf20Sopenharmony_ci ktime_t resp_time, 7158c2ecf20Sopenharmony_ci rxrpc_serial_t acked_serial, 7168c2ecf20Sopenharmony_ci rxrpc_serial_t ack_serial) 7178c2ecf20Sopenharmony_ci{ 7188c2ecf20Sopenharmony_ci if (acked_serial == call->acks_lost_ping) 7198c2ecf20Sopenharmony_ci rxrpc_input_check_for_lost_ack(call); 7208c2ecf20Sopenharmony_ci} 7218c2ecf20Sopenharmony_ci 7228c2ecf20Sopenharmony_ci/* 7238c2ecf20Sopenharmony_ci * Process the extra information that may be appended to an ACK packet 7248c2ecf20Sopenharmony_ci */ 7258c2ecf20Sopenharmony_cistatic void rxrpc_input_ackinfo(struct rxrpc_call *call, struct sk_buff *skb, 7268c2ecf20Sopenharmony_ci struct rxrpc_ackinfo *ackinfo) 7278c2ecf20Sopenharmony_ci{ 7288c2ecf20Sopenharmony_ci struct rxrpc_skb_priv *sp = rxrpc_skb(skb); 7298c2ecf20Sopenharmony_ci struct rxrpc_peer *peer; 7308c2ecf20Sopenharmony_ci unsigned int mtu; 7318c2ecf20Sopenharmony_ci bool wake = false; 7328c2ecf20Sopenharmony_ci u32 rwind = ntohl(ackinfo->rwind); 7338c2ecf20Sopenharmony_ci 7348c2ecf20Sopenharmony_ci _proto("Rx ACK %%%u Info { rx=%u max=%u rwin=%u jm=%u }", 7358c2ecf20Sopenharmony_ci sp->hdr.serial, 7368c2ecf20Sopenharmony_ci ntohl(ackinfo->rxMTU), ntohl(ackinfo->maxMTU), 7378c2ecf20Sopenharmony_ci rwind, ntohl(ackinfo->jumbo_max)); 7388c2ecf20Sopenharmony_ci 7398c2ecf20Sopenharmony_ci if (rwind > RXRPC_RXTX_BUFF_SIZE - 1) 7408c2ecf20Sopenharmony_ci rwind = RXRPC_RXTX_BUFF_SIZE - 1; 7418c2ecf20Sopenharmony_ci if (call->tx_winsize != rwind) { 7428c2ecf20Sopenharmony_ci if (rwind > call->tx_winsize) 7438c2ecf20Sopenharmony_ci wake = true; 7448c2ecf20Sopenharmony_ci trace_rxrpc_rx_rwind_change(call, sp->hdr.serial, rwind, wake); 7458c2ecf20Sopenharmony_ci call->tx_winsize = rwind; 7468c2ecf20Sopenharmony_ci } 7478c2ecf20Sopenharmony_ci 7488c2ecf20Sopenharmony_ci if (call->cong_ssthresh > rwind) 7498c2ecf20Sopenharmony_ci call->cong_ssthresh = rwind; 7508c2ecf20Sopenharmony_ci 7518c2ecf20Sopenharmony_ci mtu = min(ntohl(ackinfo->rxMTU), ntohl(ackinfo->maxMTU)); 7528c2ecf20Sopenharmony_ci 7538c2ecf20Sopenharmony_ci peer = call->peer; 7548c2ecf20Sopenharmony_ci if (mtu < peer->maxdata) { 7558c2ecf20Sopenharmony_ci spin_lock_bh(&peer->lock); 7568c2ecf20Sopenharmony_ci peer->maxdata = mtu; 7578c2ecf20Sopenharmony_ci peer->mtu = mtu + peer->hdrsize; 7588c2ecf20Sopenharmony_ci spin_unlock_bh(&peer->lock); 7598c2ecf20Sopenharmony_ci _net("Net MTU %u (maxdata %u)", peer->mtu, peer->maxdata); 7608c2ecf20Sopenharmony_ci } 7618c2ecf20Sopenharmony_ci 7628c2ecf20Sopenharmony_ci if (wake) 7638c2ecf20Sopenharmony_ci wake_up(&call->waitq); 7648c2ecf20Sopenharmony_ci} 7658c2ecf20Sopenharmony_ci 7668c2ecf20Sopenharmony_ci/* 7678c2ecf20Sopenharmony_ci * Process individual soft ACKs. 7688c2ecf20Sopenharmony_ci * 7698c2ecf20Sopenharmony_ci * Each ACK in the array corresponds to one packet and can be either an ACK or 7708c2ecf20Sopenharmony_ci * a NAK. If we get find an explicitly NAK'd packet we resend immediately; 7718c2ecf20Sopenharmony_ci * packets that lie beyond the end of the ACK list are scheduled for resend by 7728c2ecf20Sopenharmony_ci * the timer on the basis that the peer might just not have processed them at 7738c2ecf20Sopenharmony_ci * the time the ACK was sent. 7748c2ecf20Sopenharmony_ci */ 7758c2ecf20Sopenharmony_cistatic void rxrpc_input_soft_acks(struct rxrpc_call *call, u8 *acks, 7768c2ecf20Sopenharmony_ci rxrpc_seq_t seq, int nr_acks, 7778c2ecf20Sopenharmony_ci struct rxrpc_ack_summary *summary) 7788c2ecf20Sopenharmony_ci{ 7798c2ecf20Sopenharmony_ci int ix; 7808c2ecf20Sopenharmony_ci u8 annotation, anno_type; 7818c2ecf20Sopenharmony_ci 7828c2ecf20Sopenharmony_ci for (; nr_acks > 0; nr_acks--, seq++) { 7838c2ecf20Sopenharmony_ci ix = seq & RXRPC_RXTX_BUFF_MASK; 7848c2ecf20Sopenharmony_ci annotation = call->rxtx_annotations[ix]; 7858c2ecf20Sopenharmony_ci anno_type = annotation & RXRPC_TX_ANNO_MASK; 7868c2ecf20Sopenharmony_ci annotation &= ~RXRPC_TX_ANNO_MASK; 7878c2ecf20Sopenharmony_ci switch (*acks++) { 7888c2ecf20Sopenharmony_ci case RXRPC_ACK_TYPE_ACK: 7898c2ecf20Sopenharmony_ci summary->nr_acks++; 7908c2ecf20Sopenharmony_ci if (anno_type == RXRPC_TX_ANNO_ACK) 7918c2ecf20Sopenharmony_ci continue; 7928c2ecf20Sopenharmony_ci summary->nr_new_acks++; 7938c2ecf20Sopenharmony_ci call->rxtx_annotations[ix] = 7948c2ecf20Sopenharmony_ci RXRPC_TX_ANNO_ACK | annotation; 7958c2ecf20Sopenharmony_ci break; 7968c2ecf20Sopenharmony_ci case RXRPC_ACK_TYPE_NACK: 7978c2ecf20Sopenharmony_ci if (!summary->nr_nacks && 7988c2ecf20Sopenharmony_ci call->acks_lowest_nak != seq) { 7998c2ecf20Sopenharmony_ci call->acks_lowest_nak = seq; 8008c2ecf20Sopenharmony_ci summary->new_low_nack = true; 8018c2ecf20Sopenharmony_ci } 8028c2ecf20Sopenharmony_ci summary->nr_nacks++; 8038c2ecf20Sopenharmony_ci if (anno_type == RXRPC_TX_ANNO_NAK) 8048c2ecf20Sopenharmony_ci continue; 8058c2ecf20Sopenharmony_ci summary->nr_new_nacks++; 8068c2ecf20Sopenharmony_ci if (anno_type == RXRPC_TX_ANNO_RETRANS) 8078c2ecf20Sopenharmony_ci continue; 8088c2ecf20Sopenharmony_ci call->rxtx_annotations[ix] = 8098c2ecf20Sopenharmony_ci RXRPC_TX_ANNO_NAK | annotation; 8108c2ecf20Sopenharmony_ci break; 8118c2ecf20Sopenharmony_ci default: 8128c2ecf20Sopenharmony_ci return rxrpc_proto_abort("SFT", call, 0); 8138c2ecf20Sopenharmony_ci } 8148c2ecf20Sopenharmony_ci } 8158c2ecf20Sopenharmony_ci} 8168c2ecf20Sopenharmony_ci 8178c2ecf20Sopenharmony_ci/* 8188c2ecf20Sopenharmony_ci * Return true if the ACK is valid - ie. it doesn't appear to have regressed 8198c2ecf20Sopenharmony_ci * with respect to the ack state conveyed by preceding ACKs. 8208c2ecf20Sopenharmony_ci */ 8218c2ecf20Sopenharmony_cistatic bool rxrpc_is_ack_valid(struct rxrpc_call *call, 8228c2ecf20Sopenharmony_ci rxrpc_seq_t first_pkt, rxrpc_seq_t prev_pkt) 8238c2ecf20Sopenharmony_ci{ 8248c2ecf20Sopenharmony_ci rxrpc_seq_t base = READ_ONCE(call->acks_first_seq); 8258c2ecf20Sopenharmony_ci 8268c2ecf20Sopenharmony_ci if (after(first_pkt, base)) 8278c2ecf20Sopenharmony_ci return true; /* The window advanced */ 8288c2ecf20Sopenharmony_ci 8298c2ecf20Sopenharmony_ci if (before(first_pkt, base)) 8308c2ecf20Sopenharmony_ci return false; /* firstPacket regressed */ 8318c2ecf20Sopenharmony_ci 8328c2ecf20Sopenharmony_ci if (after_eq(prev_pkt, call->acks_prev_seq)) 8338c2ecf20Sopenharmony_ci return true; /* previousPacket hasn't regressed. */ 8348c2ecf20Sopenharmony_ci 8358c2ecf20Sopenharmony_ci /* Some rx implementations put a serial number in previousPacket. */ 8368c2ecf20Sopenharmony_ci if (after_eq(prev_pkt, base + call->tx_winsize)) 8378c2ecf20Sopenharmony_ci return false; 8388c2ecf20Sopenharmony_ci return true; 8398c2ecf20Sopenharmony_ci} 8408c2ecf20Sopenharmony_ci 8418c2ecf20Sopenharmony_ci/* 8428c2ecf20Sopenharmony_ci * Process an ACK packet. 8438c2ecf20Sopenharmony_ci * 8448c2ecf20Sopenharmony_ci * ack.firstPacket is the sequence number of the first soft-ACK'd/NAK'd packet 8458c2ecf20Sopenharmony_ci * in the ACK array. Anything before that is hard-ACK'd and may be discarded. 8468c2ecf20Sopenharmony_ci * 8478c2ecf20Sopenharmony_ci * A hard-ACK means that a packet has been processed and may be discarded; a 8488c2ecf20Sopenharmony_ci * soft-ACK means that the packet may be discarded and retransmission 8498c2ecf20Sopenharmony_ci * requested. A phase is complete when all packets are hard-ACK'd. 8508c2ecf20Sopenharmony_ci */ 8518c2ecf20Sopenharmony_cistatic void rxrpc_input_ack(struct rxrpc_call *call, struct sk_buff *skb) 8528c2ecf20Sopenharmony_ci{ 8538c2ecf20Sopenharmony_ci struct rxrpc_ack_summary summary = { 0 }; 8548c2ecf20Sopenharmony_ci struct rxrpc_skb_priv *sp = rxrpc_skb(skb); 8558c2ecf20Sopenharmony_ci union { 8568c2ecf20Sopenharmony_ci struct rxrpc_ackpacket ack; 8578c2ecf20Sopenharmony_ci struct rxrpc_ackinfo info; 8588c2ecf20Sopenharmony_ci u8 acks[RXRPC_MAXACKS]; 8598c2ecf20Sopenharmony_ci } buf; 8608c2ecf20Sopenharmony_ci rxrpc_serial_t ack_serial, acked_serial; 8618c2ecf20Sopenharmony_ci rxrpc_seq_t first_soft_ack, hard_ack, prev_pkt; 8628c2ecf20Sopenharmony_ci int nr_acks, offset, ioffset; 8638c2ecf20Sopenharmony_ci 8648c2ecf20Sopenharmony_ci _enter(""); 8658c2ecf20Sopenharmony_ci 8668c2ecf20Sopenharmony_ci offset = sizeof(struct rxrpc_wire_header); 8678c2ecf20Sopenharmony_ci if (skb_copy_bits(skb, offset, &buf.ack, sizeof(buf.ack)) < 0) { 8688c2ecf20Sopenharmony_ci _debug("extraction failure"); 8698c2ecf20Sopenharmony_ci return rxrpc_proto_abort("XAK", call, 0); 8708c2ecf20Sopenharmony_ci } 8718c2ecf20Sopenharmony_ci offset += sizeof(buf.ack); 8728c2ecf20Sopenharmony_ci 8738c2ecf20Sopenharmony_ci ack_serial = sp->hdr.serial; 8748c2ecf20Sopenharmony_ci acked_serial = ntohl(buf.ack.serial); 8758c2ecf20Sopenharmony_ci first_soft_ack = ntohl(buf.ack.firstPacket); 8768c2ecf20Sopenharmony_ci prev_pkt = ntohl(buf.ack.previousPacket); 8778c2ecf20Sopenharmony_ci hard_ack = first_soft_ack - 1; 8788c2ecf20Sopenharmony_ci nr_acks = buf.ack.nAcks; 8798c2ecf20Sopenharmony_ci summary.ack_reason = (buf.ack.reason < RXRPC_ACK__INVALID ? 8808c2ecf20Sopenharmony_ci buf.ack.reason : RXRPC_ACK__INVALID); 8818c2ecf20Sopenharmony_ci 8828c2ecf20Sopenharmony_ci trace_rxrpc_rx_ack(call, ack_serial, acked_serial, 8838c2ecf20Sopenharmony_ci first_soft_ack, prev_pkt, 8848c2ecf20Sopenharmony_ci summary.ack_reason, nr_acks); 8858c2ecf20Sopenharmony_ci 8868c2ecf20Sopenharmony_ci switch (buf.ack.reason) { 8878c2ecf20Sopenharmony_ci case RXRPC_ACK_PING_RESPONSE: 8888c2ecf20Sopenharmony_ci rxrpc_input_ping_response(call, skb->tstamp, acked_serial, 8898c2ecf20Sopenharmony_ci ack_serial); 8908c2ecf20Sopenharmony_ci rxrpc_complete_rtt_probe(call, skb->tstamp, acked_serial, ack_serial, 8918c2ecf20Sopenharmony_ci rxrpc_rtt_rx_ping_response); 8928c2ecf20Sopenharmony_ci break; 8938c2ecf20Sopenharmony_ci case RXRPC_ACK_REQUESTED: 8948c2ecf20Sopenharmony_ci rxrpc_complete_rtt_probe(call, skb->tstamp, acked_serial, ack_serial, 8958c2ecf20Sopenharmony_ci rxrpc_rtt_rx_requested_ack); 8968c2ecf20Sopenharmony_ci break; 8978c2ecf20Sopenharmony_ci default: 8988c2ecf20Sopenharmony_ci if (acked_serial != 0) 8998c2ecf20Sopenharmony_ci rxrpc_complete_rtt_probe(call, skb->tstamp, acked_serial, ack_serial, 9008c2ecf20Sopenharmony_ci rxrpc_rtt_rx_cancel); 9018c2ecf20Sopenharmony_ci break; 9028c2ecf20Sopenharmony_ci } 9038c2ecf20Sopenharmony_ci 9048c2ecf20Sopenharmony_ci if (buf.ack.reason == RXRPC_ACK_PING) { 9058c2ecf20Sopenharmony_ci _proto("Rx ACK %%%u PING Request", ack_serial); 9068c2ecf20Sopenharmony_ci rxrpc_propose_ACK(call, RXRPC_ACK_PING_RESPONSE, 9078c2ecf20Sopenharmony_ci ack_serial, true, true, 9088c2ecf20Sopenharmony_ci rxrpc_propose_ack_respond_to_ping); 9098c2ecf20Sopenharmony_ci } else if (sp->hdr.flags & RXRPC_REQUEST_ACK) { 9108c2ecf20Sopenharmony_ci rxrpc_propose_ACK(call, RXRPC_ACK_REQUESTED, 9118c2ecf20Sopenharmony_ci ack_serial, true, true, 9128c2ecf20Sopenharmony_ci rxrpc_propose_ack_respond_to_ack); 9138c2ecf20Sopenharmony_ci } 9148c2ecf20Sopenharmony_ci 9158c2ecf20Sopenharmony_ci /* Discard any out-of-order or duplicate ACKs (outside lock). */ 9168c2ecf20Sopenharmony_ci if (!rxrpc_is_ack_valid(call, first_soft_ack, prev_pkt)) { 9178c2ecf20Sopenharmony_ci trace_rxrpc_rx_discard_ack(call->debug_id, ack_serial, 9188c2ecf20Sopenharmony_ci first_soft_ack, call->acks_first_seq, 9198c2ecf20Sopenharmony_ci prev_pkt, call->acks_prev_seq); 9208c2ecf20Sopenharmony_ci return; 9218c2ecf20Sopenharmony_ci } 9228c2ecf20Sopenharmony_ci 9238c2ecf20Sopenharmony_ci buf.info.rxMTU = 0; 9248c2ecf20Sopenharmony_ci ioffset = offset + nr_acks + 3; 9258c2ecf20Sopenharmony_ci if (skb->len >= ioffset + sizeof(buf.info) && 9268c2ecf20Sopenharmony_ci skb_copy_bits(skb, ioffset, &buf.info, sizeof(buf.info)) < 0) 9278c2ecf20Sopenharmony_ci return rxrpc_proto_abort("XAI", call, 0); 9288c2ecf20Sopenharmony_ci 9298c2ecf20Sopenharmony_ci spin_lock(&call->input_lock); 9308c2ecf20Sopenharmony_ci 9318c2ecf20Sopenharmony_ci /* Discard any out-of-order or duplicate ACKs (inside lock). */ 9328c2ecf20Sopenharmony_ci if (!rxrpc_is_ack_valid(call, first_soft_ack, prev_pkt)) { 9338c2ecf20Sopenharmony_ci trace_rxrpc_rx_discard_ack(call->debug_id, ack_serial, 9348c2ecf20Sopenharmony_ci first_soft_ack, call->acks_first_seq, 9358c2ecf20Sopenharmony_ci prev_pkt, call->acks_prev_seq); 9368c2ecf20Sopenharmony_ci goto out; 9378c2ecf20Sopenharmony_ci } 9388c2ecf20Sopenharmony_ci call->acks_latest_ts = skb->tstamp; 9398c2ecf20Sopenharmony_ci 9408c2ecf20Sopenharmony_ci call->acks_first_seq = first_soft_ack; 9418c2ecf20Sopenharmony_ci call->acks_prev_seq = prev_pkt; 9428c2ecf20Sopenharmony_ci 9438c2ecf20Sopenharmony_ci /* Parse rwind and mtu sizes if provided. */ 9448c2ecf20Sopenharmony_ci if (buf.info.rxMTU) 9458c2ecf20Sopenharmony_ci rxrpc_input_ackinfo(call, skb, &buf.info); 9468c2ecf20Sopenharmony_ci 9478c2ecf20Sopenharmony_ci if (first_soft_ack == 0) { 9488c2ecf20Sopenharmony_ci rxrpc_proto_abort("AK0", call, 0); 9498c2ecf20Sopenharmony_ci goto out; 9508c2ecf20Sopenharmony_ci } 9518c2ecf20Sopenharmony_ci 9528c2ecf20Sopenharmony_ci /* Ignore ACKs unless we are or have just been transmitting. */ 9538c2ecf20Sopenharmony_ci switch (READ_ONCE(call->state)) { 9548c2ecf20Sopenharmony_ci case RXRPC_CALL_CLIENT_SEND_REQUEST: 9558c2ecf20Sopenharmony_ci case RXRPC_CALL_CLIENT_AWAIT_REPLY: 9568c2ecf20Sopenharmony_ci case RXRPC_CALL_SERVER_SEND_REPLY: 9578c2ecf20Sopenharmony_ci case RXRPC_CALL_SERVER_AWAIT_ACK: 9588c2ecf20Sopenharmony_ci break; 9598c2ecf20Sopenharmony_ci default: 9608c2ecf20Sopenharmony_ci goto out; 9618c2ecf20Sopenharmony_ci } 9628c2ecf20Sopenharmony_ci 9638c2ecf20Sopenharmony_ci if (before(hard_ack, call->tx_hard_ack) || 9648c2ecf20Sopenharmony_ci after(hard_ack, call->tx_top)) { 9658c2ecf20Sopenharmony_ci rxrpc_proto_abort("AKW", call, 0); 9668c2ecf20Sopenharmony_ci goto out; 9678c2ecf20Sopenharmony_ci } 9688c2ecf20Sopenharmony_ci if (nr_acks > call->tx_top - hard_ack) { 9698c2ecf20Sopenharmony_ci rxrpc_proto_abort("AKN", call, 0); 9708c2ecf20Sopenharmony_ci goto out; 9718c2ecf20Sopenharmony_ci } 9728c2ecf20Sopenharmony_ci 9738c2ecf20Sopenharmony_ci if (after(hard_ack, call->tx_hard_ack)) { 9748c2ecf20Sopenharmony_ci if (rxrpc_rotate_tx_window(call, hard_ack, &summary)) { 9758c2ecf20Sopenharmony_ci rxrpc_end_tx_phase(call, false, "ETA"); 9768c2ecf20Sopenharmony_ci goto out; 9778c2ecf20Sopenharmony_ci } 9788c2ecf20Sopenharmony_ci } 9798c2ecf20Sopenharmony_ci 9808c2ecf20Sopenharmony_ci if (nr_acks > 0) { 9818c2ecf20Sopenharmony_ci if (skb_copy_bits(skb, offset, buf.acks, nr_acks) < 0) { 9828c2ecf20Sopenharmony_ci rxrpc_proto_abort("XSA", call, 0); 9838c2ecf20Sopenharmony_ci goto out; 9848c2ecf20Sopenharmony_ci } 9858c2ecf20Sopenharmony_ci rxrpc_input_soft_acks(call, buf.acks, first_soft_ack, nr_acks, 9868c2ecf20Sopenharmony_ci &summary); 9878c2ecf20Sopenharmony_ci } 9888c2ecf20Sopenharmony_ci 9898c2ecf20Sopenharmony_ci if (call->rxtx_annotations[call->tx_top & RXRPC_RXTX_BUFF_MASK] & 9908c2ecf20Sopenharmony_ci RXRPC_TX_ANNO_LAST && 9918c2ecf20Sopenharmony_ci summary.nr_acks == call->tx_top - hard_ack && 9928c2ecf20Sopenharmony_ci rxrpc_is_client_call(call)) 9938c2ecf20Sopenharmony_ci rxrpc_propose_ACK(call, RXRPC_ACK_PING, ack_serial, 9948c2ecf20Sopenharmony_ci false, true, 9958c2ecf20Sopenharmony_ci rxrpc_propose_ack_ping_for_lost_reply); 9968c2ecf20Sopenharmony_ci 9978c2ecf20Sopenharmony_ci rxrpc_congestion_management(call, skb, &summary, acked_serial); 9988c2ecf20Sopenharmony_ciout: 9998c2ecf20Sopenharmony_ci spin_unlock(&call->input_lock); 10008c2ecf20Sopenharmony_ci} 10018c2ecf20Sopenharmony_ci 10028c2ecf20Sopenharmony_ci/* 10038c2ecf20Sopenharmony_ci * Process an ACKALL packet. 10048c2ecf20Sopenharmony_ci */ 10058c2ecf20Sopenharmony_cistatic void rxrpc_input_ackall(struct rxrpc_call *call, struct sk_buff *skb) 10068c2ecf20Sopenharmony_ci{ 10078c2ecf20Sopenharmony_ci struct rxrpc_ack_summary summary = { 0 }; 10088c2ecf20Sopenharmony_ci struct rxrpc_skb_priv *sp = rxrpc_skb(skb); 10098c2ecf20Sopenharmony_ci 10108c2ecf20Sopenharmony_ci _proto("Rx ACKALL %%%u", sp->hdr.serial); 10118c2ecf20Sopenharmony_ci 10128c2ecf20Sopenharmony_ci spin_lock(&call->input_lock); 10138c2ecf20Sopenharmony_ci 10148c2ecf20Sopenharmony_ci if (rxrpc_rotate_tx_window(call, call->tx_top, &summary)) 10158c2ecf20Sopenharmony_ci rxrpc_end_tx_phase(call, false, "ETL"); 10168c2ecf20Sopenharmony_ci 10178c2ecf20Sopenharmony_ci spin_unlock(&call->input_lock); 10188c2ecf20Sopenharmony_ci} 10198c2ecf20Sopenharmony_ci 10208c2ecf20Sopenharmony_ci/* 10218c2ecf20Sopenharmony_ci * Process an ABORT packet directed at a call. 10228c2ecf20Sopenharmony_ci */ 10238c2ecf20Sopenharmony_cistatic void rxrpc_input_abort(struct rxrpc_call *call, struct sk_buff *skb) 10248c2ecf20Sopenharmony_ci{ 10258c2ecf20Sopenharmony_ci struct rxrpc_skb_priv *sp = rxrpc_skb(skb); 10268c2ecf20Sopenharmony_ci __be32 wtmp; 10278c2ecf20Sopenharmony_ci u32 abort_code = RX_CALL_DEAD; 10288c2ecf20Sopenharmony_ci 10298c2ecf20Sopenharmony_ci _enter(""); 10308c2ecf20Sopenharmony_ci 10318c2ecf20Sopenharmony_ci if (skb->len >= 4 && 10328c2ecf20Sopenharmony_ci skb_copy_bits(skb, sizeof(struct rxrpc_wire_header), 10338c2ecf20Sopenharmony_ci &wtmp, sizeof(wtmp)) >= 0) 10348c2ecf20Sopenharmony_ci abort_code = ntohl(wtmp); 10358c2ecf20Sopenharmony_ci 10368c2ecf20Sopenharmony_ci trace_rxrpc_rx_abort(call, sp->hdr.serial, abort_code); 10378c2ecf20Sopenharmony_ci 10388c2ecf20Sopenharmony_ci _proto("Rx ABORT %%%u { %x }", sp->hdr.serial, abort_code); 10398c2ecf20Sopenharmony_ci 10408c2ecf20Sopenharmony_ci rxrpc_set_call_completion(call, RXRPC_CALL_REMOTELY_ABORTED, 10418c2ecf20Sopenharmony_ci abort_code, -ECONNABORTED); 10428c2ecf20Sopenharmony_ci} 10438c2ecf20Sopenharmony_ci 10448c2ecf20Sopenharmony_ci/* 10458c2ecf20Sopenharmony_ci * Process an incoming call packet. 10468c2ecf20Sopenharmony_ci */ 10478c2ecf20Sopenharmony_cistatic void rxrpc_input_call_packet(struct rxrpc_call *call, 10488c2ecf20Sopenharmony_ci struct sk_buff *skb) 10498c2ecf20Sopenharmony_ci{ 10508c2ecf20Sopenharmony_ci struct rxrpc_skb_priv *sp = rxrpc_skb(skb); 10518c2ecf20Sopenharmony_ci unsigned long timo; 10528c2ecf20Sopenharmony_ci 10538c2ecf20Sopenharmony_ci _enter("%p,%p", call, skb); 10548c2ecf20Sopenharmony_ci 10558c2ecf20Sopenharmony_ci timo = READ_ONCE(call->next_rx_timo); 10568c2ecf20Sopenharmony_ci if (timo) { 10578c2ecf20Sopenharmony_ci unsigned long now = jiffies, expect_rx_by; 10588c2ecf20Sopenharmony_ci 10598c2ecf20Sopenharmony_ci expect_rx_by = now + timo; 10608c2ecf20Sopenharmony_ci WRITE_ONCE(call->expect_rx_by, expect_rx_by); 10618c2ecf20Sopenharmony_ci rxrpc_reduce_call_timer(call, expect_rx_by, now, 10628c2ecf20Sopenharmony_ci rxrpc_timer_set_for_normal); 10638c2ecf20Sopenharmony_ci } 10648c2ecf20Sopenharmony_ci 10658c2ecf20Sopenharmony_ci switch (sp->hdr.type) { 10668c2ecf20Sopenharmony_ci case RXRPC_PACKET_TYPE_DATA: 10678c2ecf20Sopenharmony_ci rxrpc_input_data(call, skb); 10688c2ecf20Sopenharmony_ci goto no_free; 10698c2ecf20Sopenharmony_ci 10708c2ecf20Sopenharmony_ci case RXRPC_PACKET_TYPE_ACK: 10718c2ecf20Sopenharmony_ci rxrpc_input_ack(call, skb); 10728c2ecf20Sopenharmony_ci break; 10738c2ecf20Sopenharmony_ci 10748c2ecf20Sopenharmony_ci case RXRPC_PACKET_TYPE_BUSY: 10758c2ecf20Sopenharmony_ci _proto("Rx BUSY %%%u", sp->hdr.serial); 10768c2ecf20Sopenharmony_ci 10778c2ecf20Sopenharmony_ci /* Just ignore BUSY packets from the server; the retry and 10788c2ecf20Sopenharmony_ci * lifespan timers will take care of business. BUSY packets 10798c2ecf20Sopenharmony_ci * from the client don't make sense. 10808c2ecf20Sopenharmony_ci */ 10818c2ecf20Sopenharmony_ci break; 10828c2ecf20Sopenharmony_ci 10838c2ecf20Sopenharmony_ci case RXRPC_PACKET_TYPE_ABORT: 10848c2ecf20Sopenharmony_ci rxrpc_input_abort(call, skb); 10858c2ecf20Sopenharmony_ci break; 10868c2ecf20Sopenharmony_ci 10878c2ecf20Sopenharmony_ci case RXRPC_PACKET_TYPE_ACKALL: 10888c2ecf20Sopenharmony_ci rxrpc_input_ackall(call, skb); 10898c2ecf20Sopenharmony_ci break; 10908c2ecf20Sopenharmony_ci 10918c2ecf20Sopenharmony_ci default: 10928c2ecf20Sopenharmony_ci break; 10938c2ecf20Sopenharmony_ci } 10948c2ecf20Sopenharmony_ci 10958c2ecf20Sopenharmony_ci rxrpc_free_skb(skb, rxrpc_skb_freed); 10968c2ecf20Sopenharmony_cino_free: 10978c2ecf20Sopenharmony_ci _leave(""); 10988c2ecf20Sopenharmony_ci} 10998c2ecf20Sopenharmony_ci 11008c2ecf20Sopenharmony_ci/* 11018c2ecf20Sopenharmony_ci * Handle a new service call on a channel implicitly completing the preceding 11028c2ecf20Sopenharmony_ci * call on that channel. This does not apply to client conns. 11038c2ecf20Sopenharmony_ci * 11048c2ecf20Sopenharmony_ci * TODO: If callNumber > call_id + 1, renegotiate security. 11058c2ecf20Sopenharmony_ci */ 11068c2ecf20Sopenharmony_cistatic void rxrpc_input_implicit_end_call(struct rxrpc_sock *rx, 11078c2ecf20Sopenharmony_ci struct rxrpc_connection *conn, 11088c2ecf20Sopenharmony_ci struct rxrpc_call *call) 11098c2ecf20Sopenharmony_ci{ 11108c2ecf20Sopenharmony_ci switch (READ_ONCE(call->state)) { 11118c2ecf20Sopenharmony_ci case RXRPC_CALL_SERVER_AWAIT_ACK: 11128c2ecf20Sopenharmony_ci rxrpc_call_completed(call); 11138c2ecf20Sopenharmony_ci fallthrough; 11148c2ecf20Sopenharmony_ci case RXRPC_CALL_COMPLETE: 11158c2ecf20Sopenharmony_ci break; 11168c2ecf20Sopenharmony_ci default: 11178c2ecf20Sopenharmony_ci if (rxrpc_abort_call("IMP", call, 0, RX_CALL_DEAD, -ESHUTDOWN)) { 11188c2ecf20Sopenharmony_ci set_bit(RXRPC_CALL_EV_ABORT, &call->events); 11198c2ecf20Sopenharmony_ci rxrpc_queue_call(call); 11208c2ecf20Sopenharmony_ci } 11218c2ecf20Sopenharmony_ci trace_rxrpc_improper_term(call); 11228c2ecf20Sopenharmony_ci break; 11238c2ecf20Sopenharmony_ci } 11248c2ecf20Sopenharmony_ci 11258c2ecf20Sopenharmony_ci spin_lock(&rx->incoming_lock); 11268c2ecf20Sopenharmony_ci __rxrpc_disconnect_call(conn, call); 11278c2ecf20Sopenharmony_ci spin_unlock(&rx->incoming_lock); 11288c2ecf20Sopenharmony_ci} 11298c2ecf20Sopenharmony_ci 11308c2ecf20Sopenharmony_ci/* 11318c2ecf20Sopenharmony_ci * post connection-level events to the connection 11328c2ecf20Sopenharmony_ci * - this includes challenges, responses, some aborts and call terminal packet 11338c2ecf20Sopenharmony_ci * retransmission. 11348c2ecf20Sopenharmony_ci */ 11358c2ecf20Sopenharmony_cistatic void rxrpc_post_packet_to_conn(struct rxrpc_connection *conn, 11368c2ecf20Sopenharmony_ci struct sk_buff *skb) 11378c2ecf20Sopenharmony_ci{ 11388c2ecf20Sopenharmony_ci _enter("%p,%p", conn, skb); 11398c2ecf20Sopenharmony_ci 11408c2ecf20Sopenharmony_ci skb_queue_tail(&conn->rx_queue, skb); 11418c2ecf20Sopenharmony_ci rxrpc_queue_conn(conn); 11428c2ecf20Sopenharmony_ci} 11438c2ecf20Sopenharmony_ci 11448c2ecf20Sopenharmony_ci/* 11458c2ecf20Sopenharmony_ci * post endpoint-level events to the local endpoint 11468c2ecf20Sopenharmony_ci * - this includes debug and version messages 11478c2ecf20Sopenharmony_ci */ 11488c2ecf20Sopenharmony_cistatic void rxrpc_post_packet_to_local(struct rxrpc_local *local, 11498c2ecf20Sopenharmony_ci struct sk_buff *skb) 11508c2ecf20Sopenharmony_ci{ 11518c2ecf20Sopenharmony_ci _enter("%p,%p", local, skb); 11528c2ecf20Sopenharmony_ci 11538c2ecf20Sopenharmony_ci if (rxrpc_get_local_maybe(local)) { 11548c2ecf20Sopenharmony_ci skb_queue_tail(&local->event_queue, skb); 11558c2ecf20Sopenharmony_ci rxrpc_queue_local(local); 11568c2ecf20Sopenharmony_ci } else { 11578c2ecf20Sopenharmony_ci rxrpc_free_skb(skb, rxrpc_skb_freed); 11588c2ecf20Sopenharmony_ci } 11598c2ecf20Sopenharmony_ci} 11608c2ecf20Sopenharmony_ci 11618c2ecf20Sopenharmony_ci/* 11628c2ecf20Sopenharmony_ci * put a packet up for transport-level abort 11638c2ecf20Sopenharmony_ci */ 11648c2ecf20Sopenharmony_cistatic void rxrpc_reject_packet(struct rxrpc_local *local, struct sk_buff *skb) 11658c2ecf20Sopenharmony_ci{ 11668c2ecf20Sopenharmony_ci if (rxrpc_get_local_maybe(local)) { 11678c2ecf20Sopenharmony_ci skb_queue_tail(&local->reject_queue, skb); 11688c2ecf20Sopenharmony_ci rxrpc_queue_local(local); 11698c2ecf20Sopenharmony_ci } else { 11708c2ecf20Sopenharmony_ci rxrpc_free_skb(skb, rxrpc_skb_freed); 11718c2ecf20Sopenharmony_ci } 11728c2ecf20Sopenharmony_ci} 11738c2ecf20Sopenharmony_ci 11748c2ecf20Sopenharmony_ci/* 11758c2ecf20Sopenharmony_ci * Extract the wire header from a packet and translate the byte order. 11768c2ecf20Sopenharmony_ci */ 11778c2ecf20Sopenharmony_cistatic noinline 11788c2ecf20Sopenharmony_ciint rxrpc_extract_header(struct rxrpc_skb_priv *sp, struct sk_buff *skb) 11798c2ecf20Sopenharmony_ci{ 11808c2ecf20Sopenharmony_ci struct rxrpc_wire_header whdr; 11818c2ecf20Sopenharmony_ci 11828c2ecf20Sopenharmony_ci /* dig out the RxRPC connection details */ 11838c2ecf20Sopenharmony_ci if (skb_copy_bits(skb, 0, &whdr, sizeof(whdr)) < 0) { 11848c2ecf20Sopenharmony_ci trace_rxrpc_rx_eproto(NULL, sp->hdr.serial, 11858c2ecf20Sopenharmony_ci tracepoint_string("bad_hdr")); 11868c2ecf20Sopenharmony_ci return -EBADMSG; 11878c2ecf20Sopenharmony_ci } 11888c2ecf20Sopenharmony_ci 11898c2ecf20Sopenharmony_ci memset(sp, 0, sizeof(*sp)); 11908c2ecf20Sopenharmony_ci sp->hdr.epoch = ntohl(whdr.epoch); 11918c2ecf20Sopenharmony_ci sp->hdr.cid = ntohl(whdr.cid); 11928c2ecf20Sopenharmony_ci sp->hdr.callNumber = ntohl(whdr.callNumber); 11938c2ecf20Sopenharmony_ci sp->hdr.seq = ntohl(whdr.seq); 11948c2ecf20Sopenharmony_ci sp->hdr.serial = ntohl(whdr.serial); 11958c2ecf20Sopenharmony_ci sp->hdr.flags = whdr.flags; 11968c2ecf20Sopenharmony_ci sp->hdr.type = whdr.type; 11978c2ecf20Sopenharmony_ci sp->hdr.userStatus = whdr.userStatus; 11988c2ecf20Sopenharmony_ci sp->hdr.securityIndex = whdr.securityIndex; 11998c2ecf20Sopenharmony_ci sp->hdr._rsvd = ntohs(whdr._rsvd); 12008c2ecf20Sopenharmony_ci sp->hdr.serviceId = ntohs(whdr.serviceId); 12018c2ecf20Sopenharmony_ci return 0; 12028c2ecf20Sopenharmony_ci} 12038c2ecf20Sopenharmony_ci 12048c2ecf20Sopenharmony_ci/* 12058c2ecf20Sopenharmony_ci * handle data received on the local endpoint 12068c2ecf20Sopenharmony_ci * - may be called in interrupt context 12078c2ecf20Sopenharmony_ci * 12088c2ecf20Sopenharmony_ci * [!] Note that as this is called from the encap_rcv hook, the socket is not 12098c2ecf20Sopenharmony_ci * held locked by the caller and nothing prevents sk_user_data on the UDP from 12108c2ecf20Sopenharmony_ci * being cleared in the middle of processing this function. 12118c2ecf20Sopenharmony_ci * 12128c2ecf20Sopenharmony_ci * Called with the RCU read lock held from the IP layer via UDP. 12138c2ecf20Sopenharmony_ci */ 12148c2ecf20Sopenharmony_ciint rxrpc_input_packet(struct sock *udp_sk, struct sk_buff *skb) 12158c2ecf20Sopenharmony_ci{ 12168c2ecf20Sopenharmony_ci struct rxrpc_local *local = rcu_dereference_sk_user_data(udp_sk); 12178c2ecf20Sopenharmony_ci struct rxrpc_connection *conn; 12188c2ecf20Sopenharmony_ci struct rxrpc_channel *chan; 12198c2ecf20Sopenharmony_ci struct rxrpc_call *call = NULL; 12208c2ecf20Sopenharmony_ci struct rxrpc_skb_priv *sp; 12218c2ecf20Sopenharmony_ci struct rxrpc_peer *peer = NULL; 12228c2ecf20Sopenharmony_ci struct rxrpc_sock *rx = NULL; 12238c2ecf20Sopenharmony_ci unsigned int channel; 12248c2ecf20Sopenharmony_ci 12258c2ecf20Sopenharmony_ci _enter("%p", udp_sk); 12268c2ecf20Sopenharmony_ci 12278c2ecf20Sopenharmony_ci if (unlikely(!local)) { 12288c2ecf20Sopenharmony_ci kfree_skb(skb); 12298c2ecf20Sopenharmony_ci return 0; 12308c2ecf20Sopenharmony_ci } 12318c2ecf20Sopenharmony_ci if (skb->tstamp == 0) 12328c2ecf20Sopenharmony_ci skb->tstamp = ktime_get_real(); 12338c2ecf20Sopenharmony_ci 12348c2ecf20Sopenharmony_ci rxrpc_new_skb(skb, rxrpc_skb_received); 12358c2ecf20Sopenharmony_ci 12368c2ecf20Sopenharmony_ci skb_pull(skb, sizeof(struct udphdr)); 12378c2ecf20Sopenharmony_ci 12388c2ecf20Sopenharmony_ci /* The UDP protocol already released all skb resources; 12398c2ecf20Sopenharmony_ci * we are free to add our own data there. 12408c2ecf20Sopenharmony_ci */ 12418c2ecf20Sopenharmony_ci sp = rxrpc_skb(skb); 12428c2ecf20Sopenharmony_ci 12438c2ecf20Sopenharmony_ci /* dig out the RxRPC connection details */ 12448c2ecf20Sopenharmony_ci if (rxrpc_extract_header(sp, skb) < 0) 12458c2ecf20Sopenharmony_ci goto bad_message; 12468c2ecf20Sopenharmony_ci 12478c2ecf20Sopenharmony_ci if (IS_ENABLED(CONFIG_AF_RXRPC_INJECT_LOSS)) { 12488c2ecf20Sopenharmony_ci static int lose; 12498c2ecf20Sopenharmony_ci if ((lose++ & 7) == 7) { 12508c2ecf20Sopenharmony_ci trace_rxrpc_rx_lose(sp); 12518c2ecf20Sopenharmony_ci rxrpc_free_skb(skb, rxrpc_skb_lost); 12528c2ecf20Sopenharmony_ci return 0; 12538c2ecf20Sopenharmony_ci } 12548c2ecf20Sopenharmony_ci } 12558c2ecf20Sopenharmony_ci 12568c2ecf20Sopenharmony_ci if (skb->tstamp == 0) 12578c2ecf20Sopenharmony_ci skb->tstamp = ktime_get_real(); 12588c2ecf20Sopenharmony_ci trace_rxrpc_rx_packet(sp); 12598c2ecf20Sopenharmony_ci 12608c2ecf20Sopenharmony_ci switch (sp->hdr.type) { 12618c2ecf20Sopenharmony_ci case RXRPC_PACKET_TYPE_VERSION: 12628c2ecf20Sopenharmony_ci if (rxrpc_to_client(sp)) 12638c2ecf20Sopenharmony_ci goto discard; 12648c2ecf20Sopenharmony_ci rxrpc_post_packet_to_local(local, skb); 12658c2ecf20Sopenharmony_ci goto out; 12668c2ecf20Sopenharmony_ci 12678c2ecf20Sopenharmony_ci case RXRPC_PACKET_TYPE_BUSY: 12688c2ecf20Sopenharmony_ci if (rxrpc_to_server(sp)) 12698c2ecf20Sopenharmony_ci goto discard; 12708c2ecf20Sopenharmony_ci fallthrough; 12718c2ecf20Sopenharmony_ci case RXRPC_PACKET_TYPE_ACK: 12728c2ecf20Sopenharmony_ci case RXRPC_PACKET_TYPE_ACKALL: 12738c2ecf20Sopenharmony_ci if (sp->hdr.callNumber == 0) 12748c2ecf20Sopenharmony_ci goto bad_message; 12758c2ecf20Sopenharmony_ci fallthrough; 12768c2ecf20Sopenharmony_ci case RXRPC_PACKET_TYPE_ABORT: 12778c2ecf20Sopenharmony_ci break; 12788c2ecf20Sopenharmony_ci 12798c2ecf20Sopenharmony_ci case RXRPC_PACKET_TYPE_DATA: 12808c2ecf20Sopenharmony_ci if (sp->hdr.callNumber == 0 || 12818c2ecf20Sopenharmony_ci sp->hdr.seq == 0) 12828c2ecf20Sopenharmony_ci goto bad_message; 12838c2ecf20Sopenharmony_ci if (!rxrpc_validate_data(skb)) 12848c2ecf20Sopenharmony_ci goto bad_message; 12858c2ecf20Sopenharmony_ci 12868c2ecf20Sopenharmony_ci /* Unshare the packet so that it can be modified for in-place 12878c2ecf20Sopenharmony_ci * decryption. 12888c2ecf20Sopenharmony_ci */ 12898c2ecf20Sopenharmony_ci if (sp->hdr.securityIndex != 0) { 12908c2ecf20Sopenharmony_ci struct sk_buff *nskb = skb_unshare(skb, GFP_ATOMIC); 12918c2ecf20Sopenharmony_ci if (!nskb) { 12928c2ecf20Sopenharmony_ci rxrpc_eaten_skb(skb, rxrpc_skb_unshared_nomem); 12938c2ecf20Sopenharmony_ci goto out; 12948c2ecf20Sopenharmony_ci } 12958c2ecf20Sopenharmony_ci 12968c2ecf20Sopenharmony_ci if (nskb != skb) { 12978c2ecf20Sopenharmony_ci rxrpc_eaten_skb(skb, rxrpc_skb_received); 12988c2ecf20Sopenharmony_ci skb = nskb; 12998c2ecf20Sopenharmony_ci rxrpc_new_skb(skb, rxrpc_skb_unshared); 13008c2ecf20Sopenharmony_ci sp = rxrpc_skb(skb); 13018c2ecf20Sopenharmony_ci } 13028c2ecf20Sopenharmony_ci } 13038c2ecf20Sopenharmony_ci break; 13048c2ecf20Sopenharmony_ci 13058c2ecf20Sopenharmony_ci case RXRPC_PACKET_TYPE_CHALLENGE: 13068c2ecf20Sopenharmony_ci if (rxrpc_to_server(sp)) 13078c2ecf20Sopenharmony_ci goto discard; 13088c2ecf20Sopenharmony_ci break; 13098c2ecf20Sopenharmony_ci case RXRPC_PACKET_TYPE_RESPONSE: 13108c2ecf20Sopenharmony_ci if (rxrpc_to_client(sp)) 13118c2ecf20Sopenharmony_ci goto discard; 13128c2ecf20Sopenharmony_ci break; 13138c2ecf20Sopenharmony_ci 13148c2ecf20Sopenharmony_ci /* Packet types 9-11 should just be ignored. */ 13158c2ecf20Sopenharmony_ci case RXRPC_PACKET_TYPE_PARAMS: 13168c2ecf20Sopenharmony_ci case RXRPC_PACKET_TYPE_10: 13178c2ecf20Sopenharmony_ci case RXRPC_PACKET_TYPE_11: 13188c2ecf20Sopenharmony_ci goto discard; 13198c2ecf20Sopenharmony_ci 13208c2ecf20Sopenharmony_ci default: 13218c2ecf20Sopenharmony_ci _proto("Rx Bad Packet Type %u", sp->hdr.type); 13228c2ecf20Sopenharmony_ci goto bad_message; 13238c2ecf20Sopenharmony_ci } 13248c2ecf20Sopenharmony_ci 13258c2ecf20Sopenharmony_ci if (sp->hdr.serviceId == 0) 13268c2ecf20Sopenharmony_ci goto bad_message; 13278c2ecf20Sopenharmony_ci 13288c2ecf20Sopenharmony_ci if (rxrpc_to_server(sp)) { 13298c2ecf20Sopenharmony_ci /* Weed out packets to services we're not offering. Packets 13308c2ecf20Sopenharmony_ci * that would begin a call are explicitly rejected and the rest 13318c2ecf20Sopenharmony_ci * are just discarded. 13328c2ecf20Sopenharmony_ci */ 13338c2ecf20Sopenharmony_ci rx = rcu_dereference(local->service); 13348c2ecf20Sopenharmony_ci if (!rx || (sp->hdr.serviceId != rx->srx.srx_service && 13358c2ecf20Sopenharmony_ci sp->hdr.serviceId != rx->second_service)) { 13368c2ecf20Sopenharmony_ci if (sp->hdr.type == RXRPC_PACKET_TYPE_DATA && 13378c2ecf20Sopenharmony_ci sp->hdr.seq == 1) 13388c2ecf20Sopenharmony_ci goto unsupported_service; 13398c2ecf20Sopenharmony_ci goto discard; 13408c2ecf20Sopenharmony_ci } 13418c2ecf20Sopenharmony_ci } 13428c2ecf20Sopenharmony_ci 13438c2ecf20Sopenharmony_ci conn = rxrpc_find_connection_rcu(local, skb, &peer); 13448c2ecf20Sopenharmony_ci if (conn) { 13458c2ecf20Sopenharmony_ci if (sp->hdr.securityIndex != conn->security_ix) 13468c2ecf20Sopenharmony_ci goto wrong_security; 13478c2ecf20Sopenharmony_ci 13488c2ecf20Sopenharmony_ci if (sp->hdr.serviceId != conn->service_id) { 13498c2ecf20Sopenharmony_ci int old_id; 13508c2ecf20Sopenharmony_ci 13518c2ecf20Sopenharmony_ci if (!test_bit(RXRPC_CONN_PROBING_FOR_UPGRADE, &conn->flags)) 13528c2ecf20Sopenharmony_ci goto reupgrade; 13538c2ecf20Sopenharmony_ci old_id = cmpxchg(&conn->service_id, conn->params.service_id, 13548c2ecf20Sopenharmony_ci sp->hdr.serviceId); 13558c2ecf20Sopenharmony_ci 13568c2ecf20Sopenharmony_ci if (old_id != conn->params.service_id && 13578c2ecf20Sopenharmony_ci old_id != sp->hdr.serviceId) 13588c2ecf20Sopenharmony_ci goto reupgrade; 13598c2ecf20Sopenharmony_ci } 13608c2ecf20Sopenharmony_ci 13618c2ecf20Sopenharmony_ci if (sp->hdr.callNumber == 0) { 13628c2ecf20Sopenharmony_ci /* Connection-level packet */ 13638c2ecf20Sopenharmony_ci _debug("CONN %p {%d}", conn, conn->debug_id); 13648c2ecf20Sopenharmony_ci rxrpc_post_packet_to_conn(conn, skb); 13658c2ecf20Sopenharmony_ci goto out; 13668c2ecf20Sopenharmony_ci } 13678c2ecf20Sopenharmony_ci 13688c2ecf20Sopenharmony_ci if ((int)sp->hdr.serial - (int)conn->hi_serial > 0) 13698c2ecf20Sopenharmony_ci conn->hi_serial = sp->hdr.serial; 13708c2ecf20Sopenharmony_ci 13718c2ecf20Sopenharmony_ci /* Call-bound packets are routed by connection channel. */ 13728c2ecf20Sopenharmony_ci channel = sp->hdr.cid & RXRPC_CHANNELMASK; 13738c2ecf20Sopenharmony_ci chan = &conn->channels[channel]; 13748c2ecf20Sopenharmony_ci 13758c2ecf20Sopenharmony_ci /* Ignore really old calls */ 13768c2ecf20Sopenharmony_ci if (sp->hdr.callNumber < chan->last_call) 13778c2ecf20Sopenharmony_ci goto discard; 13788c2ecf20Sopenharmony_ci 13798c2ecf20Sopenharmony_ci if (sp->hdr.callNumber == chan->last_call) { 13808c2ecf20Sopenharmony_ci if (chan->call || 13818c2ecf20Sopenharmony_ci sp->hdr.type == RXRPC_PACKET_TYPE_ABORT) 13828c2ecf20Sopenharmony_ci goto discard; 13838c2ecf20Sopenharmony_ci 13848c2ecf20Sopenharmony_ci /* For the previous service call, if completed 13858c2ecf20Sopenharmony_ci * successfully, we discard all further packets. 13868c2ecf20Sopenharmony_ci */ 13878c2ecf20Sopenharmony_ci if (rxrpc_conn_is_service(conn) && 13888c2ecf20Sopenharmony_ci chan->last_type == RXRPC_PACKET_TYPE_ACK) 13898c2ecf20Sopenharmony_ci goto discard; 13908c2ecf20Sopenharmony_ci 13918c2ecf20Sopenharmony_ci /* But otherwise we need to retransmit the final packet 13928c2ecf20Sopenharmony_ci * from data cached in the connection record. 13938c2ecf20Sopenharmony_ci */ 13948c2ecf20Sopenharmony_ci if (sp->hdr.type == RXRPC_PACKET_TYPE_DATA) 13958c2ecf20Sopenharmony_ci trace_rxrpc_rx_data(chan->call_debug_id, 13968c2ecf20Sopenharmony_ci sp->hdr.seq, 13978c2ecf20Sopenharmony_ci sp->hdr.serial, 13988c2ecf20Sopenharmony_ci sp->hdr.flags, 0); 13998c2ecf20Sopenharmony_ci rxrpc_post_packet_to_conn(conn, skb); 14008c2ecf20Sopenharmony_ci goto out; 14018c2ecf20Sopenharmony_ci } 14028c2ecf20Sopenharmony_ci 14038c2ecf20Sopenharmony_ci call = rcu_dereference(chan->call); 14048c2ecf20Sopenharmony_ci 14058c2ecf20Sopenharmony_ci if (sp->hdr.callNumber > chan->call_id) { 14068c2ecf20Sopenharmony_ci if (rxrpc_to_client(sp)) 14078c2ecf20Sopenharmony_ci goto reject_packet; 14088c2ecf20Sopenharmony_ci if (call) 14098c2ecf20Sopenharmony_ci rxrpc_input_implicit_end_call(rx, conn, call); 14108c2ecf20Sopenharmony_ci call = NULL; 14118c2ecf20Sopenharmony_ci } 14128c2ecf20Sopenharmony_ci 14138c2ecf20Sopenharmony_ci if (call) { 14148c2ecf20Sopenharmony_ci if (sp->hdr.serviceId != call->service_id) 14158c2ecf20Sopenharmony_ci call->service_id = sp->hdr.serviceId; 14168c2ecf20Sopenharmony_ci if ((int)sp->hdr.serial - (int)call->rx_serial > 0) 14178c2ecf20Sopenharmony_ci call->rx_serial = sp->hdr.serial; 14188c2ecf20Sopenharmony_ci if (!test_bit(RXRPC_CALL_RX_HEARD, &call->flags)) 14198c2ecf20Sopenharmony_ci set_bit(RXRPC_CALL_RX_HEARD, &call->flags); 14208c2ecf20Sopenharmony_ci } 14218c2ecf20Sopenharmony_ci } 14228c2ecf20Sopenharmony_ci 14238c2ecf20Sopenharmony_ci if (!call || refcount_read(&call->ref) == 0) { 14248c2ecf20Sopenharmony_ci if (rxrpc_to_client(sp) || 14258c2ecf20Sopenharmony_ci sp->hdr.type != RXRPC_PACKET_TYPE_DATA) 14268c2ecf20Sopenharmony_ci goto bad_message; 14278c2ecf20Sopenharmony_ci if (sp->hdr.seq != 1) 14288c2ecf20Sopenharmony_ci goto discard; 14298c2ecf20Sopenharmony_ci call = rxrpc_new_incoming_call(local, rx, skb); 14308c2ecf20Sopenharmony_ci if (!call) 14318c2ecf20Sopenharmony_ci goto reject_packet; 14328c2ecf20Sopenharmony_ci } 14338c2ecf20Sopenharmony_ci 14348c2ecf20Sopenharmony_ci /* Process a call packet; this either discards or passes on the ref 14358c2ecf20Sopenharmony_ci * elsewhere. 14368c2ecf20Sopenharmony_ci */ 14378c2ecf20Sopenharmony_ci rxrpc_input_call_packet(call, skb); 14388c2ecf20Sopenharmony_ci goto out; 14398c2ecf20Sopenharmony_ci 14408c2ecf20Sopenharmony_cidiscard: 14418c2ecf20Sopenharmony_ci rxrpc_free_skb(skb, rxrpc_skb_freed); 14428c2ecf20Sopenharmony_ciout: 14438c2ecf20Sopenharmony_ci trace_rxrpc_rx_done(0, 0); 14448c2ecf20Sopenharmony_ci return 0; 14458c2ecf20Sopenharmony_ci 14468c2ecf20Sopenharmony_ciwrong_security: 14478c2ecf20Sopenharmony_ci trace_rxrpc_abort(0, "SEC", sp->hdr.cid, sp->hdr.callNumber, sp->hdr.seq, 14488c2ecf20Sopenharmony_ci RXKADINCONSISTENCY, EBADMSG); 14498c2ecf20Sopenharmony_ci skb->priority = RXKADINCONSISTENCY; 14508c2ecf20Sopenharmony_ci goto post_abort; 14518c2ecf20Sopenharmony_ci 14528c2ecf20Sopenharmony_ciunsupported_service: 14538c2ecf20Sopenharmony_ci trace_rxrpc_abort(0, "INV", sp->hdr.cid, sp->hdr.callNumber, sp->hdr.seq, 14548c2ecf20Sopenharmony_ci RX_INVALID_OPERATION, EOPNOTSUPP); 14558c2ecf20Sopenharmony_ci skb->priority = RX_INVALID_OPERATION; 14568c2ecf20Sopenharmony_ci goto post_abort; 14578c2ecf20Sopenharmony_ci 14588c2ecf20Sopenharmony_cireupgrade: 14598c2ecf20Sopenharmony_ci trace_rxrpc_abort(0, "UPG", sp->hdr.cid, sp->hdr.callNumber, sp->hdr.seq, 14608c2ecf20Sopenharmony_ci RX_PROTOCOL_ERROR, EBADMSG); 14618c2ecf20Sopenharmony_ci goto protocol_error; 14628c2ecf20Sopenharmony_ci 14638c2ecf20Sopenharmony_cibad_message: 14648c2ecf20Sopenharmony_ci trace_rxrpc_abort(0, "BAD", sp->hdr.cid, sp->hdr.callNumber, sp->hdr.seq, 14658c2ecf20Sopenharmony_ci RX_PROTOCOL_ERROR, EBADMSG); 14668c2ecf20Sopenharmony_ciprotocol_error: 14678c2ecf20Sopenharmony_ci skb->priority = RX_PROTOCOL_ERROR; 14688c2ecf20Sopenharmony_cipost_abort: 14698c2ecf20Sopenharmony_ci skb->mark = RXRPC_SKB_MARK_REJECT_ABORT; 14708c2ecf20Sopenharmony_cireject_packet: 14718c2ecf20Sopenharmony_ci trace_rxrpc_rx_done(skb->mark, skb->priority); 14728c2ecf20Sopenharmony_ci rxrpc_reject_packet(local, skb); 14738c2ecf20Sopenharmony_ci _leave(" [badmsg]"); 14748c2ecf20Sopenharmony_ci return 0; 14758c2ecf20Sopenharmony_ci} 1476