12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later 28c3e34a4SDavid Howells /* connection-level event handling 38c3e34a4SDavid Howells * 48c3e34a4SDavid Howells * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. 58c3e34a4SDavid Howells * Written by David Howells (dhowells@redhat.com) 68c3e34a4SDavid Howells */ 78c3e34a4SDavid Howells 88c3e34a4SDavid Howells #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 98c3e34a4SDavid Howells 108c3e34a4SDavid Howells #include <linux/module.h> 118c3e34a4SDavid Howells #include <linux/net.h> 128c3e34a4SDavid Howells #include <linux/skbuff.h> 138c3e34a4SDavid Howells #include <linux/errqueue.h> 148c3e34a4SDavid Howells #include <net/sock.h> 158c3e34a4SDavid Howells #include <net/af_rxrpc.h> 168c3e34a4SDavid Howells #include <net/ip.h> 178c3e34a4SDavid Howells #include "ar-internal.h" 188c3e34a4SDavid Howells 198c3e34a4SDavid Howells /* 2018bfeba5SDavid Howells * Retransmit terminal ACK or ABORT of the previous call. 2118bfeba5SDavid Howells */ 22f5c17aaeSDavid Howells static void rxrpc_conn_retransmit_call(struct rxrpc_connection *conn, 233136ef49SDavid Howells struct sk_buff *skb, 243136ef49SDavid Howells unsigned int channel) 2518bfeba5SDavid Howells { 263136ef49SDavid Howells struct rxrpc_skb_priv *sp = skb ? rxrpc_skb(skb) : NULL; 2718bfeba5SDavid Howells struct rxrpc_channel *chan; 2818bfeba5SDavid Howells struct msghdr msg; 295fc62f6aSDavid Howells struct kvec iov[3]; 3018bfeba5SDavid Howells struct { 3118bfeba5SDavid Howells struct rxrpc_wire_header whdr; 3218bfeba5SDavid Howells union { 335fc62f6aSDavid Howells __be32 abort_code; 3418bfeba5SDavid Howells struct rxrpc_ackpacket ack; 3518bfeba5SDavid Howells }; 3618bfeba5SDavid Howells } __attribute__((packed)) pkt; 375fc62f6aSDavid Howells struct rxrpc_ackinfo ack_info; 3818bfeba5SDavid Howells size_t len; 396b47fe1dSDavid Howells int ret, ioc; 405fc62f6aSDavid Howells u32 serial, mtu, call_id, padding; 4118bfeba5SDavid Howells 4218bfeba5SDavid Howells _enter("%d", conn->debug_id); 4318bfeba5SDavid Howells 443136ef49SDavid Howells chan = &conn->channels[channel]; 4518bfeba5SDavid Howells 4618bfeba5SDavid Howells /* If the last call got moved on whilst we were waiting to run, just 4718bfeba5SDavid Howells * ignore this packet. 4818bfeba5SDavid Howells */ 4918bfeba5SDavid Howells call_id = READ_ONCE(chan->last_call); 5018bfeba5SDavid Howells /* Sync with __rxrpc_disconnect_call() */ 5118bfeba5SDavid Howells smp_rmb(); 523136ef49SDavid Howells if (skb && call_id != sp->hdr.callNumber) 5318bfeba5SDavid Howells return; 5418bfeba5SDavid Howells 552cc80086SDavid Howells msg.msg_name = &conn->peer->srx.transport; 562cc80086SDavid Howells msg.msg_namelen = conn->peer->srx.transport_len; 5718bfeba5SDavid Howells msg.msg_control = NULL; 5818bfeba5SDavid Howells msg.msg_controllen = 0; 5918bfeba5SDavid Howells msg.msg_flags = 0; 6018bfeba5SDavid Howells 615fc62f6aSDavid Howells iov[0].iov_base = &pkt; 625fc62f6aSDavid Howells iov[0].iov_len = sizeof(pkt.whdr); 635fc62f6aSDavid Howells iov[1].iov_base = &padding; 645fc62f6aSDavid Howells iov[1].iov_len = 3; 655fc62f6aSDavid Howells iov[2].iov_base = &ack_info; 665fc62f6aSDavid Howells iov[2].iov_len = sizeof(ack_info); 675fc62f6aSDavid Howells 683136ef49SDavid Howells pkt.whdr.epoch = htonl(conn->proto.epoch); 69fb1967a6SDavid Howells pkt.whdr.cid = htonl(conn->proto.cid | channel); 703136ef49SDavid Howells pkt.whdr.callNumber = htonl(call_id); 7118bfeba5SDavid Howells pkt.whdr.seq = 0; 7218bfeba5SDavid Howells pkt.whdr.type = chan->last_type; 7318bfeba5SDavid Howells pkt.whdr.flags = conn->out_clientflag; 7418bfeba5SDavid Howells pkt.whdr.userStatus = 0; 7518bfeba5SDavid Howells pkt.whdr.securityIndex = conn->security_ix; 7618bfeba5SDavid Howells pkt.whdr._rsvd = 0; 7768d6d1aeSDavid Howells pkt.whdr.serviceId = htons(conn->service_id); 7818bfeba5SDavid Howells 7918bfeba5SDavid Howells len = sizeof(pkt.whdr); 8018bfeba5SDavid Howells switch (chan->last_type) { 8118bfeba5SDavid Howells case RXRPC_PACKET_TYPE_ABORT: 825fc62f6aSDavid Howells pkt.abort_code = htonl(chan->last_abort); 835fc62f6aSDavid Howells iov[0].iov_len += sizeof(pkt.abort_code); 845fc62f6aSDavid Howells len += sizeof(pkt.abort_code); 855fc62f6aSDavid Howells ioc = 1; 8618bfeba5SDavid Howells break; 8718bfeba5SDavid Howells 8818bfeba5SDavid Howells case RXRPC_PACKET_TYPE_ACK: 892cc80086SDavid Howells mtu = conn->peer->if_mtu; 902cc80086SDavid Howells mtu -= conn->peer->hdrsize; 9118bfeba5SDavid Howells pkt.ack.bufferSpace = 0; 923136ef49SDavid Howells pkt.ack.maxSkew = htons(skb ? skb->priority : 0); 933136ef49SDavid Howells pkt.ack.firstPacket = htonl(chan->last_seq + 1); 943136ef49SDavid Howells pkt.ack.previousPacket = htonl(chan->last_seq); 953136ef49SDavid Howells pkt.ack.serial = htonl(skb ? sp->hdr.serial : 0); 963136ef49SDavid Howells pkt.ack.reason = skb ? RXRPC_ACK_DUPLICATE : RXRPC_ACK_IDLE; 9718bfeba5SDavid Howells pkt.ack.nAcks = 0; 985fc62f6aSDavid Howells ack_info.rxMTU = htonl(rxrpc_rx_mtu); 995fc62f6aSDavid Howells ack_info.maxMTU = htonl(mtu); 1005fc62f6aSDavid Howells ack_info.rwind = htonl(rxrpc_rx_window_size); 1015fc62f6aSDavid Howells ack_info.jumbo_max = htonl(rxrpc_rx_jumbo_max); 10257494343SDavid Howells pkt.whdr.flags |= RXRPC_SLOW_START_OK; 1035fc62f6aSDavid Howells padding = 0; 1045fc62f6aSDavid Howells iov[0].iov_len += sizeof(pkt.ack); 1055fc62f6aSDavid Howells len += sizeof(pkt.ack) + 3 + sizeof(ack_info); 1065fc62f6aSDavid Howells ioc = 3; 10718bfeba5SDavid Howells break; 1085fc62f6aSDavid Howells 1095fc62f6aSDavid Howells default: 1105fc62f6aSDavid Howells return; 11118bfeba5SDavid Howells } 11218bfeba5SDavid Howells 11318bfeba5SDavid Howells /* Resync with __rxrpc_disconnect_call() and check that the last call 11418bfeba5SDavid Howells * didn't get advanced whilst we were filling out the packets. 11518bfeba5SDavid Howells */ 11618bfeba5SDavid Howells smp_rmb(); 11718bfeba5SDavid Howells if (READ_ONCE(chan->last_call) != call_id) 11818bfeba5SDavid Howells return; 11918bfeba5SDavid Howells 12018bfeba5SDavid Howells serial = atomic_inc_return(&conn->serial); 12118bfeba5SDavid Howells pkt.whdr.serial = htonl(serial); 12218bfeba5SDavid Howells 12318bfeba5SDavid Howells switch (chan->last_type) { 12418bfeba5SDavid Howells case RXRPC_PACKET_TYPE_ABORT: 12518bfeba5SDavid Howells break; 12618bfeba5SDavid Howells case RXRPC_PACKET_TYPE_ACK: 1274764c0daSDavid Howells trace_rxrpc_tx_ack(chan->call_debug_id, serial, 128f3f8337cSDavid Howells ntohl(pkt.ack.firstPacket), 129f3f8337cSDavid Howells ntohl(pkt.ack.serial), 130f3f8337cSDavid Howells pkt.ack.reason, 0); 13118bfeba5SDavid Howells break; 13218bfeba5SDavid Howells } 13318bfeba5SDavid Howells 1342cc80086SDavid Howells ret = kernel_sendmsg(conn->local->socket, &msg, iov, ioc, len); 1352cc80086SDavid Howells conn->peer->last_tx_at = ktime_get_seconds(); 1366b47fe1dSDavid Howells if (ret < 0) 1374764c0daSDavid Howells trace_rxrpc_tx_fail(chan->call_debug_id, serial, ret, 1384764c0daSDavid Howells rxrpc_tx_point_call_final_resend); 1394764c0daSDavid Howells else 1404764c0daSDavid Howells trace_rxrpc_tx_packet(chan->call_debug_id, &pkt.whdr, 1414764c0daSDavid Howells rxrpc_tx_point_call_final_resend); 1426b47fe1dSDavid Howells 14318bfeba5SDavid Howells _leave(""); 14418bfeba5SDavid Howells } 14518bfeba5SDavid Howells 14618bfeba5SDavid Howells /* 1478c3e34a4SDavid Howells * pass a connection-level abort onto all calls on that connection 1488c3e34a4SDavid Howells */ 149f5c17aaeSDavid Howells static void rxrpc_abort_calls(struct rxrpc_connection *conn, 15039ce6755SDavid Howells enum rxrpc_call_completion compl, 15139ce6755SDavid Howells rxrpc_serial_t serial) 1528c3e34a4SDavid Howells { 1538c3e34a4SDavid Howells struct rxrpc_call *call; 154248f219cSDavid Howells int i; 1558c3e34a4SDavid Howells 15664753092SDavid Howells _enter("{%d},%x", conn->debug_id, conn->abort_code); 1578c3e34a4SDavid Howells 158245500d8SDavid Howells spin_lock(&conn->bundle->channel_lock); 1598c3e34a4SDavid Howells 160a1399f8bSDavid Howells for (i = 0; i < RXRPC_MAXCALLS; i++) { 161a1399f8bSDavid Howells call = rcu_dereference_protected( 162a1399f8bSDavid Howells conn->channels[i].call, 163245500d8SDavid Howells lockdep_is_held(&conn->bundle->channel_lock)); 164ccbd3dbeSDavid Howells if (call) { 1655a42976dSDavid Howells if (compl == RXRPC_CALL_LOCALLY_ABORTED) 166a25e21f0SDavid Howells trace_rxrpc_abort(call->debug_id, 167a25e21f0SDavid Howells "CON", call->cid, 1685a42976dSDavid Howells call->call_id, 0, 16964753092SDavid Howells conn->abort_code, 17064753092SDavid Howells conn->error); 17139ce6755SDavid Howells else 17239ce6755SDavid Howells trace_rxrpc_rx_abort(call, serial, 17339ce6755SDavid Howells conn->abort_code); 1745ac0d622SDavid Howells rxrpc_set_call_completion(call, compl, 17564753092SDavid Howells conn->abort_code, 1765ac0d622SDavid Howells conn->error); 1778c3e34a4SDavid Howells } 178ccbd3dbeSDavid Howells } 1798c3e34a4SDavid Howells 180245500d8SDavid Howells spin_unlock(&conn->bundle->channel_lock); 1818c3e34a4SDavid Howells _leave(""); 1828c3e34a4SDavid Howells } 1838c3e34a4SDavid Howells 1848c3e34a4SDavid Howells /* 1858c3e34a4SDavid Howells * generate a connection-level abort 1868c3e34a4SDavid Howells */ 1878c3e34a4SDavid Howells static int rxrpc_abort_connection(struct rxrpc_connection *conn, 1883a92789aSDavid Howells int error, u32 abort_code) 1898c3e34a4SDavid Howells { 1908c3e34a4SDavid Howells struct rxrpc_wire_header whdr; 1918c3e34a4SDavid Howells struct msghdr msg; 1928c3e34a4SDavid Howells struct kvec iov[2]; 1938c3e34a4SDavid Howells __be32 word; 1948c3e34a4SDavid Howells size_t len; 1958c3e34a4SDavid Howells u32 serial; 1968c3e34a4SDavid Howells int ret; 1978c3e34a4SDavid Howells 1988c3e34a4SDavid Howells _enter("%d,,%u,%u", conn->debug_id, error, abort_code); 1998c3e34a4SDavid Howells 2008c3e34a4SDavid Howells /* generate a connection-level abort */ 2018c3e34a4SDavid Howells spin_lock_bh(&conn->state_lock); 202f5c17aaeSDavid Howells if (conn->state >= RXRPC_CONN_REMOTELY_ABORTED) { 2038c3e34a4SDavid Howells spin_unlock_bh(&conn->state_lock); 2048c3e34a4SDavid Howells _leave(" = 0 [already dead]"); 2058c3e34a4SDavid Howells return 0; 2068c3e34a4SDavid Howells } 2078c3e34a4SDavid Howells 20864753092SDavid Howells conn->error = error; 20964753092SDavid Howells conn->abort_code = abort_code; 210f5c17aaeSDavid Howells conn->state = RXRPC_CONN_LOCALLY_ABORTED; 211245500d8SDavid Howells set_bit(RXRPC_CONN_DONT_REUSE, &conn->flags); 212f5c17aaeSDavid Howells spin_unlock_bh(&conn->state_lock); 213f5c17aaeSDavid Howells 2142cc80086SDavid Howells msg.msg_name = &conn->peer->srx.transport; 2152cc80086SDavid Howells msg.msg_namelen = conn->peer->srx.transport_len; 2168c3e34a4SDavid Howells msg.msg_control = NULL; 2178c3e34a4SDavid Howells msg.msg_controllen = 0; 2188c3e34a4SDavid Howells msg.msg_flags = 0; 2198c3e34a4SDavid Howells 22019ffa01cSDavid Howells whdr.epoch = htonl(conn->proto.epoch); 22119ffa01cSDavid Howells whdr.cid = htonl(conn->proto.cid); 2228c3e34a4SDavid Howells whdr.callNumber = 0; 2238c3e34a4SDavid Howells whdr.seq = 0; 2248c3e34a4SDavid Howells whdr.type = RXRPC_PACKET_TYPE_ABORT; 2258c3e34a4SDavid Howells whdr.flags = conn->out_clientflag; 2268c3e34a4SDavid Howells whdr.userStatus = 0; 2278c3e34a4SDavid Howells whdr.securityIndex = conn->security_ix; 2288c3e34a4SDavid Howells whdr._rsvd = 0; 22968d6d1aeSDavid Howells whdr.serviceId = htons(conn->service_id); 2308c3e34a4SDavid Howells 23164753092SDavid Howells word = htonl(conn->abort_code); 2328c3e34a4SDavid Howells 2338c3e34a4SDavid Howells iov[0].iov_base = &whdr; 2348c3e34a4SDavid Howells iov[0].iov_len = sizeof(whdr); 2358c3e34a4SDavid Howells iov[1].iov_base = &word; 2368c3e34a4SDavid Howells iov[1].iov_len = sizeof(word); 2378c3e34a4SDavid Howells 2388c3e34a4SDavid Howells len = iov[0].iov_len + iov[1].iov_len; 2398c3e34a4SDavid Howells 2408c3e34a4SDavid Howells serial = atomic_inc_return(&conn->serial); 24139ce6755SDavid Howells rxrpc_abort_calls(conn, RXRPC_CALL_LOCALLY_ABORTED, serial); 2428c3e34a4SDavid Howells whdr.serial = htonl(serial); 2438c3e34a4SDavid Howells 2442cc80086SDavid Howells ret = kernel_sendmsg(conn->local->socket, &msg, iov, 2, len); 2458c3e34a4SDavid Howells if (ret < 0) { 2466b47fe1dSDavid Howells trace_rxrpc_tx_fail(conn->debug_id, serial, ret, 2474764c0daSDavid Howells rxrpc_tx_point_conn_abort); 2488c3e34a4SDavid Howells _debug("sendmsg failed: %d", ret); 2498c3e34a4SDavid Howells return -EAGAIN; 2508c3e34a4SDavid Howells } 2518c3e34a4SDavid Howells 2524764c0daSDavid Howells trace_rxrpc_tx_packet(conn->debug_id, &whdr, rxrpc_tx_point_conn_abort); 2534764c0daSDavid Howells 2542cc80086SDavid Howells conn->peer->last_tx_at = ktime_get_seconds(); 255ace45becSDavid Howells 2568c3e34a4SDavid Howells _leave(" = 0"); 2578c3e34a4SDavid Howells return 0; 2588c3e34a4SDavid Howells } 2598c3e34a4SDavid Howells 2608c3e34a4SDavid Howells /* 2618c3e34a4SDavid Howells * mark a call as being on a now-secured channel 262248f219cSDavid Howells * - must be called with BH's disabled. 2638c3e34a4SDavid Howells */ 2648c3e34a4SDavid Howells static void rxrpc_call_is_secure(struct rxrpc_call *call) 2658c3e34a4SDavid Howells { 2668c3e34a4SDavid Howells _enter("%p", call); 2678c3e34a4SDavid Howells if (call) { 268248f219cSDavid Howells write_lock_bh(&call->state_lock); 269248f219cSDavid Howells if (call->state == RXRPC_CALL_SERVER_SECURING) { 2702d914c1bSDavid Howells call->state = RXRPC_CALL_SERVER_RECV_REQUEST; 271248f219cSDavid Howells rxrpc_notify_socket(call); 272248f219cSDavid Howells } 273248f219cSDavid Howells write_unlock_bh(&call->state_lock); 2748c3e34a4SDavid Howells } 2758c3e34a4SDavid Howells } 2768c3e34a4SDavid Howells 2778c3e34a4SDavid Howells /* 2788c3e34a4SDavid Howells * connection-level Rx packet processor 2798c3e34a4SDavid Howells */ 2808c3e34a4SDavid Howells static int rxrpc_process_event(struct rxrpc_connection *conn, 2818c3e34a4SDavid Howells struct sk_buff *skb, 2828c3e34a4SDavid Howells u32 *_abort_code) 2838c3e34a4SDavid Howells { 2848c3e34a4SDavid Howells struct rxrpc_skb_priv *sp = rxrpc_skb(skb); 2858c3e34a4SDavid Howells int loop, ret; 2868c3e34a4SDavid Howells 2878c3e34a4SDavid Howells if (conn->state >= RXRPC_CONN_REMOTELY_ABORTED) { 288248f219cSDavid Howells _leave(" = -ECONNABORTED [%u]", conn->state); 2898c3e34a4SDavid Howells return -ECONNABORTED; 2908c3e34a4SDavid Howells } 2918c3e34a4SDavid Howells 2928c3e34a4SDavid Howells _enter("{%d},{%u,%%%u},", conn->debug_id, sp->hdr.type, sp->hdr.serial); 2938c3e34a4SDavid Howells 2948c3e34a4SDavid Howells switch (sp->hdr.type) { 29518bfeba5SDavid Howells case RXRPC_PACKET_TYPE_DATA: 29618bfeba5SDavid Howells case RXRPC_PACKET_TYPE_ACK: 2973136ef49SDavid Howells rxrpc_conn_retransmit_call(conn, skb, 2983136ef49SDavid Howells sp->hdr.cid & RXRPC_CHANNELMASK); 29918bfeba5SDavid Howells return 0; 30018bfeba5SDavid Howells 3014d4a6ac7SDavid Howells case RXRPC_PACKET_TYPE_BUSY: 3024d4a6ac7SDavid Howells /* Just ignore BUSY packets for now. */ 3034d4a6ac7SDavid Howells return 0; 3044d4a6ac7SDavid Howells 3058c3e34a4SDavid Howells case RXRPC_PACKET_TYPE_ABORT: 30664753092SDavid Howells conn->error = -ECONNABORTED; 307f14febd8SDavid Howells conn->abort_code = skb->priority; 3088c3e34a4SDavid Howells conn->state = RXRPC_CONN_REMOTELY_ABORTED; 309245500d8SDavid Howells set_bit(RXRPC_CONN_DONT_REUSE, &conn->flags); 31039ce6755SDavid Howells rxrpc_abort_calls(conn, RXRPC_CALL_REMOTELY_ABORTED, sp->hdr.serial); 3118c3e34a4SDavid Howells return -ECONNABORTED; 3128c3e34a4SDavid Howells 3138c3e34a4SDavid Howells case RXRPC_PACKET_TYPE_CHALLENGE: 3148c3e34a4SDavid Howells return conn->security->respond_to_challenge(conn, skb, 3158c3e34a4SDavid Howells _abort_code); 3168c3e34a4SDavid Howells 3178c3e34a4SDavid Howells case RXRPC_PACKET_TYPE_RESPONSE: 3188c3e34a4SDavid Howells ret = conn->security->verify_response(conn, skb, _abort_code); 3198c3e34a4SDavid Howells if (ret < 0) 3208c3e34a4SDavid Howells return ret; 3218c3e34a4SDavid Howells 32241057ebdSDavid Howells ret = conn->security->init_connection_security( 3232cc80086SDavid Howells conn, conn->key->payload.data[0]); 3248c3e34a4SDavid Howells if (ret < 0) 3258c3e34a4SDavid Howells return ret; 3268c3e34a4SDavid Howells 327245500d8SDavid Howells spin_lock(&conn->bundle->channel_lock); 328fa1d113aSDavid Howells spin_lock_bh(&conn->state_lock); 3298c3e34a4SDavid Howells 330bba304dbSDavid Howells if (conn->state == RXRPC_CONN_SERVICE_CHALLENGING) { 331bba304dbSDavid Howells conn->state = RXRPC_CONN_SERVICE; 332fa1d113aSDavid Howells spin_unlock_bh(&conn->state_lock); 3338c3e34a4SDavid Howells for (loop = 0; loop < RXRPC_MAXCALLS; loop++) 334dee46364SDavid Howells rxrpc_call_is_secure( 335dee46364SDavid Howells rcu_dereference_protected( 336a1399f8bSDavid Howells conn->channels[loop].call, 337245500d8SDavid Howells lockdep_is_held(&conn->bundle->channel_lock))); 338248f219cSDavid Howells } else { 339fa1d113aSDavid Howells spin_unlock_bh(&conn->state_lock); 3408c3e34a4SDavid Howells } 3418c3e34a4SDavid Howells 342245500d8SDavid Howells spin_unlock(&conn->bundle->channel_lock); 3438c3e34a4SDavid Howells return 0; 3448c3e34a4SDavid Howells 3458c3e34a4SDavid Howells default: 346fb46f6eeSDavid Howells trace_rxrpc_rx_eproto(NULL, sp->hdr.serial, 347fb46f6eeSDavid Howells tracepoint_string("bad_conn_pkt")); 3488c3e34a4SDavid Howells return -EPROTO; 3498c3e34a4SDavid Howells } 3508c3e34a4SDavid Howells } 3518c3e34a4SDavid Howells 3528c3e34a4SDavid Howells /* 3538c3e34a4SDavid Howells * set up security and issue a challenge 3548c3e34a4SDavid Howells */ 3558c3e34a4SDavid Howells static void rxrpc_secure_connection(struct rxrpc_connection *conn) 3568c3e34a4SDavid Howells { 3578c3e34a4SDavid Howells u32 abort_code; 3588c3e34a4SDavid Howells int ret; 3598c3e34a4SDavid Howells 3608c3e34a4SDavid Howells _enter("{%d}", conn->debug_id); 3618c3e34a4SDavid Howells 3628c3e34a4SDavid Howells ASSERT(conn->security_ix != 0); 3638c3e34a4SDavid Howells 3648c3e34a4SDavid Howells if (conn->security->issue_challenge(conn) < 0) { 3658c3e34a4SDavid Howells abort_code = RX_CALL_DEAD; 3668c3e34a4SDavid Howells ret = -ENOMEM; 3678c3e34a4SDavid Howells goto abort; 3688c3e34a4SDavid Howells } 3698c3e34a4SDavid Howells 3708c3e34a4SDavid Howells _leave(""); 3718c3e34a4SDavid Howells return; 3728c3e34a4SDavid Howells 3738c3e34a4SDavid Howells abort: 3748c3e34a4SDavid Howells _debug("abort %d, %d", ret, abort_code); 3753a92789aSDavid Howells rxrpc_abort_connection(conn, ret, abort_code); 3768c3e34a4SDavid Howells _leave(" [aborted]"); 3778c3e34a4SDavid Howells } 3788c3e34a4SDavid Howells 3798c3e34a4SDavid Howells /* 3803136ef49SDavid Howells * Process delayed final ACKs that we haven't subsumed into a subsequent call. 3813136ef49SDavid Howells */ 382ddc7834aSDavid Howells void rxrpc_process_delayed_final_acks(struct rxrpc_connection *conn, bool force) 3833136ef49SDavid Howells { 3843136ef49SDavid Howells unsigned long j = jiffies, next_j; 3853136ef49SDavid Howells unsigned int channel; 3863136ef49SDavid Howells bool set; 3873136ef49SDavid Howells 3883136ef49SDavid Howells again: 3893136ef49SDavid Howells next_j = j + LONG_MAX; 3903136ef49SDavid Howells set = false; 3913136ef49SDavid Howells for (channel = 0; channel < RXRPC_MAXCALLS; channel++) { 3923136ef49SDavid Howells struct rxrpc_channel *chan = &conn->channels[channel]; 3933136ef49SDavid Howells unsigned long ack_at; 3943136ef49SDavid Howells 3953136ef49SDavid Howells if (!test_bit(RXRPC_CONN_FINAL_ACK_0 + channel, &conn->flags)) 3963136ef49SDavid Howells continue; 3973136ef49SDavid Howells 3983136ef49SDavid Howells smp_rmb(); /* vs rxrpc_disconnect_client_call */ 3993136ef49SDavid Howells ack_at = READ_ONCE(chan->final_ack_at); 4003136ef49SDavid Howells 401ddc7834aSDavid Howells if (time_before(j, ack_at) && !force) { 4023136ef49SDavid Howells if (time_before(ack_at, next_j)) { 4033136ef49SDavid Howells next_j = ack_at; 4043136ef49SDavid Howells set = true; 4053136ef49SDavid Howells } 4063136ef49SDavid Howells continue; 4073136ef49SDavid Howells } 4083136ef49SDavid Howells 4093136ef49SDavid Howells if (test_and_clear_bit(RXRPC_CONN_FINAL_ACK_0 + channel, 4103136ef49SDavid Howells &conn->flags)) 4113136ef49SDavid Howells rxrpc_conn_retransmit_call(conn, NULL, channel); 4123136ef49SDavid Howells } 4133136ef49SDavid Howells 4143136ef49SDavid Howells j = jiffies; 4153136ef49SDavid Howells if (time_before_eq(next_j, j)) 4163136ef49SDavid Howells goto again; 4173136ef49SDavid Howells if (set) 4183136ef49SDavid Howells rxrpc_reduce_conn_timer(conn, next_j); 4193136ef49SDavid Howells } 4203136ef49SDavid Howells 4213136ef49SDavid Howells /* 4228c3e34a4SDavid Howells * connection-level event processor 4238c3e34a4SDavid Howells */ 42404d36d74SDavid Howells static void rxrpc_do_process_connection(struct rxrpc_connection *conn) 4258c3e34a4SDavid Howells { 4268c3e34a4SDavid Howells struct sk_buff *skb; 4278c3e34a4SDavid Howells u32 abort_code = RX_PROTOCOL_ERROR; 4288c3e34a4SDavid Howells int ret; 4298c3e34a4SDavid Howells 4302c4579e4SDavid Howells if (test_and_clear_bit(RXRPC_CONN_EV_CHALLENGE, &conn->events)) 4318c3e34a4SDavid Howells rxrpc_secure_connection(conn); 4328c3e34a4SDavid Howells 4333136ef49SDavid Howells /* Process delayed ACKs whose time has come. */ 4343136ef49SDavid Howells if (conn->flags & RXRPC_CONN_FINAL_ACK_MASK) 435ddc7834aSDavid Howells rxrpc_process_delayed_final_acks(conn, false); 4363136ef49SDavid Howells 4378c3e34a4SDavid Howells /* go through the conn-level event packets, releasing the ref on this 4388c3e34a4SDavid Howells * connection that each one has when we've finished with it */ 4398c3e34a4SDavid Howells while ((skb = skb_dequeue(&conn->rx_queue))) { 440987db9f7SDavid Howells rxrpc_see_skb(skb, rxrpc_skb_seen); 4418c3e34a4SDavid Howells ret = rxrpc_process_event(conn, skb, &abort_code); 4428c3e34a4SDavid Howells switch (ret) { 4438c3e34a4SDavid Howells case -EPROTO: 4448c3e34a4SDavid Howells case -EKEYEXPIRED: 4458c3e34a4SDavid Howells case -EKEYREJECTED: 4468c3e34a4SDavid Howells goto protocol_error; 4478c2f826dSDavid Howells case -ENOMEM: 4488c3e34a4SDavid Howells case -EAGAIN: 4498c3e34a4SDavid Howells goto requeue_and_leave; 4508c3e34a4SDavid Howells case -ECONNABORTED: 4518c3e34a4SDavid Howells default: 452987db9f7SDavid Howells rxrpc_free_skb(skb, rxrpc_skb_freed); 4538c3e34a4SDavid Howells break; 4548c3e34a4SDavid Howells } 4558c3e34a4SDavid Howells } 4568c3e34a4SDavid Howells 4578c3e34a4SDavid Howells return; 4588c3e34a4SDavid Howells 4598c3e34a4SDavid Howells requeue_and_leave: 4608c3e34a4SDavid Howells skb_queue_head(&conn->rx_queue, skb); 46104d36d74SDavid Howells return; 4628c3e34a4SDavid Howells 4638c3e34a4SDavid Howells protocol_error: 4643a92789aSDavid Howells if (rxrpc_abort_connection(conn, ret, abort_code) < 0) 4658c3e34a4SDavid Howells goto requeue_and_leave; 466987db9f7SDavid Howells rxrpc_free_skb(skb, rxrpc_skb_freed); 46704d36d74SDavid Howells return; 46804d36d74SDavid Howells } 46904d36d74SDavid Howells 47004d36d74SDavid Howells void rxrpc_process_connection(struct work_struct *work) 47104d36d74SDavid Howells { 47204d36d74SDavid Howells struct rxrpc_connection *conn = 47304d36d74SDavid Howells container_of(work, struct rxrpc_connection, processor); 47404d36d74SDavid Howells 475*7fa25105SDavid Howells rxrpc_see_connection(conn, rxrpc_conn_see_work); 47604d36d74SDavid Howells 4770fde882fSDavid Howells if (__rxrpc_use_local(conn->local, rxrpc_local_use_conn_work)) { 47804d36d74SDavid Howells rxrpc_do_process_connection(conn); 4790fde882fSDavid Howells rxrpc_unuse_local(conn->local, rxrpc_local_unuse_conn_work); 48004d36d74SDavid Howells } 48104d36d74SDavid Howells 482*7fa25105SDavid Howells rxrpc_put_connection(conn, rxrpc_conn_put_work); 48304d36d74SDavid Howells _leave(""); 48404d36d74SDavid Howells return; 4858c3e34a4SDavid Howells } 486