18c3e34a4SDavid Howells /* RxRPC packet transmission 28c3e34a4SDavid Howells * 38c3e34a4SDavid Howells * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. 48c3e34a4SDavid Howells * Written by David Howells (dhowells@redhat.com) 58c3e34a4SDavid Howells * 68c3e34a4SDavid Howells * This program is free software; you can redistribute it and/or 78c3e34a4SDavid Howells * modify it under the terms of the GNU General Public License 88c3e34a4SDavid Howells * as published by the Free Software Foundation; either version 98c3e34a4SDavid Howells * 2 of the License, or (at your option) any later version. 108c3e34a4SDavid Howells */ 118c3e34a4SDavid Howells 128c3e34a4SDavid Howells #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 138c3e34a4SDavid Howells 148c3e34a4SDavid Howells #include <linux/net.h> 158c3e34a4SDavid Howells #include <linux/gfp.h> 168c3e34a4SDavid Howells #include <linux/skbuff.h> 178c3e34a4SDavid Howells #include <linux/export.h> 188c3e34a4SDavid Howells #include <net/sock.h> 198c3e34a4SDavid Howells #include <net/af_rxrpc.h> 208c3e34a4SDavid Howells #include "ar-internal.h" 218c3e34a4SDavid Howells 2226cb02aaSDavid Howells struct rxrpc_ack_buffer { 238d94aa38SDavid Howells struct rxrpc_wire_header whdr; 248d94aa38SDavid Howells struct rxrpc_ackpacket ack; 258d94aa38SDavid Howells u8 acks[255]; 268d94aa38SDavid Howells u8 pad[3]; 278d94aa38SDavid Howells struct rxrpc_ackinfo ackinfo; 288d94aa38SDavid Howells }; 298d94aa38SDavid Howells 3026cb02aaSDavid Howells struct rxrpc_abort_buffer { 3126cb02aaSDavid Howells struct rxrpc_wire_header whdr; 3226cb02aaSDavid Howells __be32 abort_code; 3326cb02aaSDavid Howells }; 3426cb02aaSDavid Howells 35ace45becSDavid Howells static const char rxrpc_keepalive_string[] = ""; 36ace45becSDavid Howells 378d94aa38SDavid Howells /* 38415f44e4SDavid Howells * Arrange for a keepalive ping a certain time after we last transmitted. This 39415f44e4SDavid Howells * lets the far side know we're still interested in this call and helps keep 40415f44e4SDavid Howells * the route through any intervening firewall open. 41415f44e4SDavid Howells * 42415f44e4SDavid Howells * Receiving a response to the ping will prevent the ->expect_rx_by timer from 43415f44e4SDavid Howells * expiring. 44415f44e4SDavid Howells */ 45415f44e4SDavid Howells static void rxrpc_set_keepalive(struct rxrpc_call *call) 46415f44e4SDavid Howells { 47415f44e4SDavid Howells unsigned long now = jiffies, keepalive_at = call->next_rx_timo / 6; 48415f44e4SDavid Howells 49415f44e4SDavid Howells keepalive_at += now; 50415f44e4SDavid Howells WRITE_ONCE(call->keepalive_at, keepalive_at); 51415f44e4SDavid Howells rxrpc_reduce_call_timer(call, keepalive_at, now, 52415f44e4SDavid Howells rxrpc_timer_set_for_keepalive); 53415f44e4SDavid Howells } 54415f44e4SDavid Howells 55415f44e4SDavid Howells /* 568d94aa38SDavid Howells * Fill out an ACK packet. 578d94aa38SDavid Howells */ 581457cc4cSDavid Howells static size_t rxrpc_fill_out_ack(struct rxrpc_connection *conn, 591457cc4cSDavid Howells struct rxrpc_call *call, 6026cb02aaSDavid Howells struct rxrpc_ack_buffer *pkt, 61805b21b9SDavid Howells rxrpc_seq_t *_hard_ack, 62a5af7e1fSDavid Howells rxrpc_seq_t *_top, 63a5af7e1fSDavid Howells u8 reason) 648d94aa38SDavid Howells { 65f3639df2SDavid Howells rxrpc_serial_t serial; 66248f219cSDavid Howells rxrpc_seq_t hard_ack, top, seq; 67248f219cSDavid Howells int ix; 688d94aa38SDavid Howells u32 mtu, jmax; 698d94aa38SDavid Howells u8 *ackp = pkt->acks; 708d94aa38SDavid Howells 71248f219cSDavid Howells /* Barrier against rxrpc_input_data(). */ 72f3639df2SDavid Howells serial = call->ackr_serial; 73248f219cSDavid Howells hard_ack = READ_ONCE(call->rx_hard_ack); 74248f219cSDavid Howells top = smp_load_acquire(&call->rx_top); 75805b21b9SDavid Howells *_hard_ack = hard_ack; 76805b21b9SDavid Howells *_top = top; 77248f219cSDavid Howells 788d94aa38SDavid Howells pkt->ack.bufferSpace = htons(8); 79248f219cSDavid Howells pkt->ack.maxSkew = htons(call->ackr_skew); 80248f219cSDavid Howells pkt->ack.firstPacket = htonl(hard_ack + 1); 818d94aa38SDavid Howells pkt->ack.previousPacket = htonl(call->ackr_prev_seq); 82f3639df2SDavid Howells pkt->ack.serial = htonl(serial); 83a5af7e1fSDavid Howells pkt->ack.reason = reason; 84248f219cSDavid Howells pkt->ack.nAcks = top - hard_ack; 858d94aa38SDavid Howells 86a5af7e1fSDavid Howells if (reason == RXRPC_ACK_PING) 878e83134dSDavid Howells pkt->whdr.flags |= RXRPC_REQUEST_ACK; 888e83134dSDavid Howells 89248f219cSDavid Howells if (after(top, hard_ack)) { 90248f219cSDavid Howells seq = hard_ack + 1; 91248f219cSDavid Howells do { 92248f219cSDavid Howells ix = seq & RXRPC_RXTX_BUFF_MASK; 93248f219cSDavid Howells if (call->rxtx_buffer[ix]) 94248f219cSDavid Howells *ackp++ = RXRPC_ACK_TYPE_ACK; 95248f219cSDavid Howells else 96248f219cSDavid Howells *ackp++ = RXRPC_ACK_TYPE_NACK; 97248f219cSDavid Howells seq++; 98248f219cSDavid Howells } while (before_eq(seq, top)); 99248f219cSDavid Howells } 100248f219cSDavid Howells 1011457cc4cSDavid Howells mtu = conn->params.peer->if_mtu; 1021457cc4cSDavid Howells mtu -= conn->params.peer->hdrsize; 10375e42126SDavid Howells jmax = (call->nr_jumbo_bad > 3) ? 1 : rxrpc_rx_jumbo_max; 1048d94aa38SDavid Howells pkt->ackinfo.rxMTU = htonl(rxrpc_rx_mtu); 1058d94aa38SDavid Howells pkt->ackinfo.maxMTU = htonl(mtu); 10675e42126SDavid Howells pkt->ackinfo.rwind = htonl(call->rx_winsize); 1078d94aa38SDavid Howells pkt->ackinfo.jumbo_max = htonl(jmax); 1088d94aa38SDavid Howells 1098d94aa38SDavid Howells *ackp++ = 0; 1108d94aa38SDavid Howells *ackp++ = 0; 1118d94aa38SDavid Howells *ackp++ = 0; 112248f219cSDavid Howells return top - hard_ack + 3; 1138d94aa38SDavid Howells } 1148d94aa38SDavid Howells 1158d94aa38SDavid Howells /* 11626cb02aaSDavid Howells * Send an ACK call packet. 1178d94aa38SDavid Howells */ 118bd1fdf8cSDavid Howells int rxrpc_send_ack_packet(struct rxrpc_call *call, bool ping, 119bd1fdf8cSDavid Howells rxrpc_serial_t *_serial) 1208d94aa38SDavid Howells { 1218d94aa38SDavid Howells struct rxrpc_connection *conn = NULL; 12226cb02aaSDavid Howells struct rxrpc_ack_buffer *pkt; 1238d94aa38SDavid Howells struct msghdr msg; 1248d94aa38SDavid Howells struct kvec iov[2]; 1258d94aa38SDavid Howells rxrpc_serial_t serial; 126805b21b9SDavid Howells rxrpc_seq_t hard_ack, top; 127ace45becSDavid Howells ktime_t now; 1288d94aa38SDavid Howells size_t len, n; 12926cb02aaSDavid Howells int ret; 130a5af7e1fSDavid Howells u8 reason; 1318d94aa38SDavid Howells 1328d94aa38SDavid Howells spin_lock_bh(&call->lock); 1338d94aa38SDavid Howells if (call->conn) 1348d94aa38SDavid Howells conn = rxrpc_get_connection_maybe(call->conn); 1358d94aa38SDavid Howells spin_unlock_bh(&call->lock); 1368d94aa38SDavid Howells if (!conn) 1378d94aa38SDavid Howells return -ECONNRESET; 1388d94aa38SDavid Howells 1398d94aa38SDavid Howells pkt = kzalloc(sizeof(*pkt), GFP_KERNEL); 1408d94aa38SDavid Howells if (!pkt) { 1418d94aa38SDavid Howells rxrpc_put_connection(conn); 1428d94aa38SDavid Howells return -ENOMEM; 1438d94aa38SDavid Howells } 1448d94aa38SDavid Howells 1458d94aa38SDavid Howells msg.msg_name = &call->peer->srx.transport; 1468d94aa38SDavid Howells msg.msg_namelen = call->peer->srx.transport_len; 1478d94aa38SDavid Howells msg.msg_control = NULL; 1488d94aa38SDavid Howells msg.msg_controllen = 0; 1498d94aa38SDavid Howells msg.msg_flags = 0; 1508d94aa38SDavid Howells 1518d94aa38SDavid Howells pkt->whdr.epoch = htonl(conn->proto.epoch); 1528d94aa38SDavid Howells pkt->whdr.cid = htonl(call->cid); 1538d94aa38SDavid Howells pkt->whdr.callNumber = htonl(call->call_id); 1548d94aa38SDavid Howells pkt->whdr.seq = 0; 15526cb02aaSDavid Howells pkt->whdr.type = RXRPC_PACKET_TYPE_ACK; 15626cb02aaSDavid Howells pkt->whdr.flags = RXRPC_SLOW_START_OK | conn->out_clientflag; 1578d94aa38SDavid Howells pkt->whdr.userStatus = 0; 1588d94aa38SDavid Howells pkt->whdr.securityIndex = call->security_ix; 1598d94aa38SDavid Howells pkt->whdr._rsvd = 0; 1608d94aa38SDavid Howells pkt->whdr.serviceId = htons(call->service_id); 1618d94aa38SDavid Howells 1628d94aa38SDavid Howells spin_lock_bh(&call->lock); 163a5af7e1fSDavid Howells if (ping) { 164a5af7e1fSDavid Howells reason = RXRPC_ACK_PING; 165a5af7e1fSDavid Howells } else { 166a5af7e1fSDavid Howells reason = call->ackr_reason; 16727d0fc43SDavid Howells if (!call->ackr_reason) { 16827d0fc43SDavid Howells spin_unlock_bh(&call->lock); 16927d0fc43SDavid Howells ret = 0; 17027d0fc43SDavid Howells goto out; 17127d0fc43SDavid Howells } 1728d94aa38SDavid Howells call->ackr_reason = 0; 173a5af7e1fSDavid Howells } 1741457cc4cSDavid Howells n = rxrpc_fill_out_ack(conn, call, pkt, &hard_ack, &top, reason); 1758d94aa38SDavid Howells 1768d94aa38SDavid Howells spin_unlock_bh(&call->lock); 1778d94aa38SDavid Howells 17826cb02aaSDavid Howells iov[0].iov_base = pkt; 17926cb02aaSDavid Howells iov[0].iov_len = sizeof(pkt->whdr) + sizeof(pkt->ack) + n; 1808d94aa38SDavid Howells iov[1].iov_base = &pkt->ackinfo; 1818d94aa38SDavid Howells iov[1].iov_len = sizeof(pkt->ackinfo); 18226cb02aaSDavid Howells len = iov[0].iov_len + iov[1].iov_len; 1838d94aa38SDavid Howells 184b86e218eSDavid Howells serial = atomic_inc_return(&conn->serial); 185b86e218eSDavid Howells pkt->whdr.serial = htonl(serial); 186be832aecSDavid Howells trace_rxrpc_tx_ack(call, serial, 187b86e218eSDavid Howells ntohl(pkt->ack.firstPacket), 188b86e218eSDavid Howells ntohl(pkt->ack.serial), 189b86e218eSDavid Howells pkt->ack.reason, pkt->ack.nAcks); 190bd1fdf8cSDavid Howells if (_serial) 191bd1fdf8cSDavid Howells *_serial = serial; 192b86e218eSDavid Howells 1938e83134dSDavid Howells if (ping) { 194a5af7e1fSDavid Howells call->ping_serial = serial; 1958e83134dSDavid Howells smp_wmb(); 1968e83134dSDavid Howells /* We need to stick a time in before we send the packet in case 1978e83134dSDavid Howells * the reply gets back before kernel_sendmsg() completes - but 1988e83134dSDavid Howells * asking UDP to send the packet can take a relatively long 1998e83134dSDavid Howells * time, so we update the time after, on the assumption that 2008e83134dSDavid Howells * the packet transmission is more likely to happen towards the 2018e83134dSDavid Howells * end of the kernel_sendmsg() call. 2028e83134dSDavid Howells */ 203a5af7e1fSDavid Howells call->ping_time = ktime_get_real(); 2048e83134dSDavid Howells set_bit(RXRPC_CALL_PINGING, &call->flags); 2058e83134dSDavid Howells trace_rxrpc_rtt_tx(call, rxrpc_rtt_tx_ping, serial); 2068e83134dSDavid Howells } 20726cb02aaSDavid Howells 20826cb02aaSDavid Howells ret = kernel_sendmsg(conn->params.local->socket, &msg, iov, 2, len); 209ace45becSDavid Howells now = ktime_get_real(); 2108e83134dSDavid Howells if (ping) 211ace45becSDavid Howells call->ping_time = now; 212330bdcfaSDavid Howells conn->params.peer->last_tx_at = ktime_get_seconds(); 2136b47fe1dSDavid Howells if (ret < 0) 2146b47fe1dSDavid Howells trace_rxrpc_tx_fail(call->debug_id, serial, ret, 2156b47fe1dSDavid Howells rxrpc_tx_fail_call_ack); 2168d94aa38SDavid Howells 21726cb02aaSDavid Howells if (call->state < RXRPC_CALL_COMPLETE) { 218805b21b9SDavid Howells if (ret < 0) { 219a5af7e1fSDavid Howells if (ping) 2208e83134dSDavid Howells clear_bit(RXRPC_CALL_PINGING, &call->flags); 221248f219cSDavid Howells rxrpc_propose_ACK(call, pkt->ack.reason, 222248f219cSDavid Howells ntohs(pkt->ack.maxSkew), 223248f219cSDavid Howells ntohl(pkt->ack.serial), 2249c7ad434SDavid Howells true, true, 2259c7ad434SDavid Howells rxrpc_propose_ack_retry_tx); 226805b21b9SDavid Howells } else { 227805b21b9SDavid Howells spin_lock_bh(&call->lock); 228805b21b9SDavid Howells if (after(hard_ack, call->ackr_consumed)) 229805b21b9SDavid Howells call->ackr_consumed = hard_ack; 230805b21b9SDavid Howells if (after(top, call->ackr_seen)) 231805b21b9SDavid Howells call->ackr_seen = top; 232805b21b9SDavid Howells spin_unlock_bh(&call->lock); 233248f219cSDavid Howells } 234415f44e4SDavid Howells 235415f44e4SDavid Howells rxrpc_set_keepalive(call); 236248f219cSDavid Howells } 237248f219cSDavid Howells 2388d94aa38SDavid Howells out: 2398d94aa38SDavid Howells rxrpc_put_connection(conn); 2408d94aa38SDavid Howells kfree(pkt); 2418d94aa38SDavid Howells return ret; 2428d94aa38SDavid Howells } 2438d94aa38SDavid Howells 2448c3e34a4SDavid Howells /* 24526cb02aaSDavid Howells * Send an ABORT call packet. 24626cb02aaSDavid Howells */ 24726cb02aaSDavid Howells int rxrpc_send_abort_packet(struct rxrpc_call *call) 24826cb02aaSDavid Howells { 24926cb02aaSDavid Howells struct rxrpc_connection *conn = NULL; 25026cb02aaSDavid Howells struct rxrpc_abort_buffer pkt; 25126cb02aaSDavid Howells struct msghdr msg; 25226cb02aaSDavid Howells struct kvec iov[1]; 25326cb02aaSDavid Howells rxrpc_serial_t serial; 25426cb02aaSDavid Howells int ret; 25526cb02aaSDavid Howells 256dcbefc30SDavid Howells /* Don't bother sending aborts for a client call once the server has 257dcbefc30SDavid Howells * hard-ACK'd all of its request data. After that point, we're not 258dcbefc30SDavid Howells * going to stop the operation proceeding, and whilst we might limit 259dcbefc30SDavid Howells * the reply, it's not worth it if we can send a new call on the same 260dcbefc30SDavid Howells * channel instead, thereby closing off this call. 261dcbefc30SDavid Howells */ 262dcbefc30SDavid Howells if (rxrpc_is_client_call(call) && 263dcbefc30SDavid Howells test_bit(RXRPC_CALL_TX_LAST, &call->flags)) 264dcbefc30SDavid Howells return 0; 265dcbefc30SDavid Howells 26626cb02aaSDavid Howells spin_lock_bh(&call->lock); 26726cb02aaSDavid Howells if (call->conn) 26826cb02aaSDavid Howells conn = rxrpc_get_connection_maybe(call->conn); 26926cb02aaSDavid Howells spin_unlock_bh(&call->lock); 27026cb02aaSDavid Howells if (!conn) 27126cb02aaSDavid Howells return -ECONNRESET; 27226cb02aaSDavid Howells 27326cb02aaSDavid Howells msg.msg_name = &call->peer->srx.transport; 27426cb02aaSDavid Howells msg.msg_namelen = call->peer->srx.transport_len; 27526cb02aaSDavid Howells msg.msg_control = NULL; 27626cb02aaSDavid Howells msg.msg_controllen = 0; 27726cb02aaSDavid Howells msg.msg_flags = 0; 27826cb02aaSDavid Howells 27926cb02aaSDavid Howells pkt.whdr.epoch = htonl(conn->proto.epoch); 28026cb02aaSDavid Howells pkt.whdr.cid = htonl(call->cid); 28126cb02aaSDavid Howells pkt.whdr.callNumber = htonl(call->call_id); 28226cb02aaSDavid Howells pkt.whdr.seq = 0; 28326cb02aaSDavid Howells pkt.whdr.type = RXRPC_PACKET_TYPE_ABORT; 28426cb02aaSDavid Howells pkt.whdr.flags = conn->out_clientflag; 28526cb02aaSDavid Howells pkt.whdr.userStatus = 0; 28626cb02aaSDavid Howells pkt.whdr.securityIndex = call->security_ix; 28726cb02aaSDavid Howells pkt.whdr._rsvd = 0; 28826cb02aaSDavid Howells pkt.whdr.serviceId = htons(call->service_id); 28926cb02aaSDavid Howells pkt.abort_code = htonl(call->abort_code); 29026cb02aaSDavid Howells 29126cb02aaSDavid Howells iov[0].iov_base = &pkt; 29226cb02aaSDavid Howells iov[0].iov_len = sizeof(pkt); 29326cb02aaSDavid Howells 29426cb02aaSDavid Howells serial = atomic_inc_return(&conn->serial); 29526cb02aaSDavid Howells pkt.whdr.serial = htonl(serial); 29626cb02aaSDavid Howells 29726cb02aaSDavid Howells ret = kernel_sendmsg(conn->params.local->socket, 29826cb02aaSDavid Howells &msg, iov, 1, sizeof(pkt)); 299330bdcfaSDavid Howells conn->params.peer->last_tx_at = ktime_get_seconds(); 3006b47fe1dSDavid Howells if (ret < 0) 3016b47fe1dSDavid Howells trace_rxrpc_tx_fail(call->debug_id, serial, ret, 3026b47fe1dSDavid Howells rxrpc_tx_fail_call_abort); 3036b47fe1dSDavid Howells 30426cb02aaSDavid Howells 30526cb02aaSDavid Howells rxrpc_put_connection(conn); 30626cb02aaSDavid Howells return ret; 30726cb02aaSDavid Howells } 30826cb02aaSDavid Howells 30926cb02aaSDavid Howells /* 3108c3e34a4SDavid Howells * send a packet through the transport endpoint 3118c3e34a4SDavid Howells */ 312a1767077SDavid Howells int rxrpc_send_data_packet(struct rxrpc_call *call, struct sk_buff *skb, 313a1767077SDavid Howells bool retrans) 3148c3e34a4SDavid Howells { 3155a924b89SDavid Howells struct rxrpc_connection *conn = call->conn; 3165a924b89SDavid Howells struct rxrpc_wire_header whdr; 3175a924b89SDavid Howells struct rxrpc_skb_priv *sp = rxrpc_skb(skb); 3188c3e34a4SDavid Howells struct msghdr msg; 3195a924b89SDavid Howells struct kvec iov[2]; 3205a924b89SDavid Howells rxrpc_serial_t serial; 3215a924b89SDavid Howells size_t len; 322a1767077SDavid Howells bool lost = false; 3238c3e34a4SDavid Howells int ret, opt; 3248c3e34a4SDavid Howells 3258c3e34a4SDavid Howells _enter(",{%d}", skb->len); 3268c3e34a4SDavid Howells 3275a924b89SDavid Howells /* Each transmission of a Tx packet needs a new serial number */ 3285a924b89SDavid Howells serial = atomic_inc_return(&conn->serial); 3298c3e34a4SDavid Howells 3305a924b89SDavid Howells whdr.epoch = htonl(conn->proto.epoch); 3315a924b89SDavid Howells whdr.cid = htonl(call->cid); 3325a924b89SDavid Howells whdr.callNumber = htonl(call->call_id); 3335a924b89SDavid Howells whdr.seq = htonl(sp->hdr.seq); 3345a924b89SDavid Howells whdr.serial = htonl(serial); 3355a924b89SDavid Howells whdr.type = RXRPC_PACKET_TYPE_DATA; 3365a924b89SDavid Howells whdr.flags = sp->hdr.flags; 3375a924b89SDavid Howells whdr.userStatus = 0; 3385a924b89SDavid Howells whdr.securityIndex = call->security_ix; 3395a924b89SDavid Howells whdr._rsvd = htons(sp->hdr._rsvd); 3405a924b89SDavid Howells whdr.serviceId = htons(call->service_id); 3415a924b89SDavid Howells 3424e255721SDavid Howells if (test_bit(RXRPC_CONN_PROBING_FOR_UPGRADE, &conn->flags) && 3434e255721SDavid Howells sp->hdr.seq == 1) 3444e255721SDavid Howells whdr.userStatus = RXRPC_USERSTATUS_SERVICE_UPGRADE; 3454e255721SDavid Howells 3465a924b89SDavid Howells iov[0].iov_base = &whdr; 3475a924b89SDavid Howells iov[0].iov_len = sizeof(whdr); 3485a924b89SDavid Howells iov[1].iov_base = skb->head; 3495a924b89SDavid Howells iov[1].iov_len = skb->len; 3505a924b89SDavid Howells len = iov[0].iov_len + iov[1].iov_len; 3515a924b89SDavid Howells 3525a924b89SDavid Howells msg.msg_name = &call->peer->srx.transport; 3535a924b89SDavid Howells msg.msg_namelen = call->peer->srx.transport_len; 3548c3e34a4SDavid Howells msg.msg_control = NULL; 3558c3e34a4SDavid Howells msg.msg_controllen = 0; 3568c3e34a4SDavid Howells msg.msg_flags = 0; 3578c3e34a4SDavid Howells 35857494343SDavid Howells /* If our RTT cache needs working on, request an ACK. Also request 35957494343SDavid Howells * ACKs if a DATA packet appears to have been lost. 36057494343SDavid Howells */ 361bf7d620aSDavid Howells if (!(sp->hdr.flags & RXRPC_LAST_PACKET) && 362bd1fdf8cSDavid Howells (test_and_clear_bit(RXRPC_CALL_EV_ACK_LOST, &call->events) || 363bd1fdf8cSDavid Howells retrans || 364b112a670SDavid Howells call->cong_mode == RXRPC_CALL_SLOW_START || 36557494343SDavid Howells (call->peer->rtt_usage < 3 && sp->hdr.seq & 1) || 3660d4b103cSDavid Howells ktime_before(ktime_add_ms(call->peer->rtt_last_req, 1000), 367bf7d620aSDavid Howells ktime_get_real()))) 3680d4b103cSDavid Howells whdr.flags |= RXRPC_REQUEST_ACK; 3690d4b103cSDavid Howells 3708a681c36SDavid Howells if (IS_ENABLED(CONFIG_AF_RXRPC_INJECT_LOSS)) { 3718a681c36SDavid Howells static int lose; 3728a681c36SDavid Howells if ((lose++ & 7) == 7) { 373a1767077SDavid Howells ret = 0; 374a1767077SDavid Howells lost = true; 375a1767077SDavid Howells goto done; 3768a681c36SDavid Howells } 3778a681c36SDavid Howells } 3788a681c36SDavid Howells 3795a924b89SDavid Howells _proto("Tx DATA %%%u { #%u }", serial, sp->hdr.seq); 3805a924b89SDavid Howells 3818c3e34a4SDavid Howells /* send the packet with the don't fragment bit set if we currently 3828c3e34a4SDavid Howells * think it's small enough */ 3835a924b89SDavid Howells if (iov[1].iov_len >= call->peer->maxdata) 3845a924b89SDavid Howells goto send_fragmentable; 3855a924b89SDavid Howells 386985a5c82SDavid Howells down_read(&conn->params.local->defrag_sem); 3878c3e34a4SDavid Howells /* send the packet by UDP 3888c3e34a4SDavid Howells * - returns -EMSGSIZE if UDP would have to fragment the packet 3898c3e34a4SDavid Howells * to go out of the interface 3908c3e34a4SDavid Howells * - in which case, we'll have processed the ICMP error 3918c3e34a4SDavid Howells * message and update the peer record 3928c3e34a4SDavid Howells */ 3935a924b89SDavid Howells ret = kernel_sendmsg(conn->params.local->socket, &msg, iov, 2, len); 394330bdcfaSDavid Howells conn->params.peer->last_tx_at = ktime_get_seconds(); 3958c3e34a4SDavid Howells 396985a5c82SDavid Howells up_read(&conn->params.local->defrag_sem); 3976b47fe1dSDavid Howells if (ret < 0) 3986b47fe1dSDavid Howells trace_rxrpc_tx_fail(call->debug_id, serial, ret, 3996b47fe1dSDavid Howells rxrpc_tx_fail_call_data_nofrag); 4008c3e34a4SDavid Howells if (ret == -EMSGSIZE) 4018c3e34a4SDavid Howells goto send_fragmentable; 4028c3e34a4SDavid Howells 4035a924b89SDavid Howells done: 404a1767077SDavid Howells trace_rxrpc_tx_data(call, sp->hdr.seq, serial, whdr.flags, 405a1767077SDavid Howells retrans, lost); 40650235c4bSDavid Howells if (ret >= 0) { 4070d4b103cSDavid Howells ktime_t now = ktime_get_real(); 4080d4b103cSDavid Howells skb->tstamp = now; 40950235c4bSDavid Howells smp_wmb(); 4105a924b89SDavid Howells sp->hdr.serial = serial; 4110d4b103cSDavid Howells if (whdr.flags & RXRPC_REQUEST_ACK) { 4120d4b103cSDavid Howells call->peer->rtt_last_req = now; 41350235c4bSDavid Howells trace_rxrpc_rtt_tx(call, rxrpc_rtt_tx_data, serial); 414bd1fdf8cSDavid Howells if (call->peer->rtt_usage > 1) { 415bd1fdf8cSDavid Howells unsigned long nowj = jiffies, ack_lost_at; 416bd1fdf8cSDavid Howells 417bd1fdf8cSDavid Howells ack_lost_at = nsecs_to_jiffies(2 * call->peer->rtt); 418bd1fdf8cSDavid Howells if (ack_lost_at < 1) 419bd1fdf8cSDavid Howells ack_lost_at = 1; 420bd1fdf8cSDavid Howells 421bd1fdf8cSDavid Howells ack_lost_at += nowj; 422bd1fdf8cSDavid Howells WRITE_ONCE(call->ack_lost_at, ack_lost_at); 423bd1fdf8cSDavid Howells rxrpc_reduce_call_timer(call, ack_lost_at, nowj, 424bd1fdf8cSDavid Howells rxrpc_timer_set_for_lost_ack); 425bd1fdf8cSDavid Howells } 4268c3e34a4SDavid Howells } 427c54e43d7SDavid Howells 428c54e43d7SDavid Howells if (sp->hdr.seq == 1 && 429c54e43d7SDavid Howells !test_and_set_bit(RXRPC_CALL_BEGAN_RX_TIMER, 430c54e43d7SDavid Howells &call->flags)) { 431c54e43d7SDavid Howells unsigned long nowj = jiffies, expect_rx_by; 432c54e43d7SDavid Howells 433c54e43d7SDavid Howells expect_rx_by = nowj + call->next_rx_timo; 434c54e43d7SDavid Howells WRITE_ONCE(call->expect_rx_by, expect_rx_by); 435c54e43d7SDavid Howells rxrpc_reduce_call_timer(call, expect_rx_by, nowj, 436c54e43d7SDavid Howells rxrpc_timer_set_for_normal); 437c54e43d7SDavid Howells } 4380d4b103cSDavid Howells } 439415f44e4SDavid Howells 440415f44e4SDavid Howells rxrpc_set_keepalive(call); 441415f44e4SDavid Howells 4425a924b89SDavid Howells _leave(" = %d [%u]", ret, call->peer->maxdata); 4435a924b89SDavid Howells return ret; 4448c3e34a4SDavid Howells 4458c3e34a4SDavid Howells send_fragmentable: 4468c3e34a4SDavid Howells /* attempt to send this message with fragmentation enabled */ 4478c3e34a4SDavid Howells _debug("send fragment"); 4488c3e34a4SDavid Howells 449985a5c82SDavid Howells down_write(&conn->params.local->defrag_sem); 450985a5c82SDavid Howells 451985a5c82SDavid Howells switch (conn->params.local->srx.transport.family) { 452985a5c82SDavid Howells case AF_INET: 4538c3e34a4SDavid Howells opt = IP_PMTUDISC_DONT; 454985a5c82SDavid Howells ret = kernel_setsockopt(conn->params.local->socket, 455985a5c82SDavid Howells SOL_IP, IP_MTU_DISCOVER, 4568c3e34a4SDavid Howells (char *)&opt, sizeof(opt)); 4578c3e34a4SDavid Howells if (ret == 0) { 4585a924b89SDavid Howells ret = kernel_sendmsg(conn->params.local->socket, &msg, 4595a924b89SDavid Howells iov, 2, len); 460330bdcfaSDavid Howells conn->params.peer->last_tx_at = ktime_get_seconds(); 4618c3e34a4SDavid Howells 4628c3e34a4SDavid Howells opt = IP_PMTUDISC_DO; 463985a5c82SDavid Howells kernel_setsockopt(conn->params.local->socket, SOL_IP, 464985a5c82SDavid Howells IP_MTU_DISCOVER, 465985a5c82SDavid Howells (char *)&opt, sizeof(opt)); 466985a5c82SDavid Howells } 467985a5c82SDavid Howells break; 46875b54cb5SDavid Howells 469d1912747SDavid Howells #ifdef CONFIG_AF_RXRPC_IPV6 47075b54cb5SDavid Howells case AF_INET6: 47175b54cb5SDavid Howells opt = IPV6_PMTUDISC_DONT; 47275b54cb5SDavid Howells ret = kernel_setsockopt(conn->params.local->socket, 47375b54cb5SDavid Howells SOL_IPV6, IPV6_MTU_DISCOVER, 47475b54cb5SDavid Howells (char *)&opt, sizeof(opt)); 47575b54cb5SDavid Howells if (ret == 0) { 47675b54cb5SDavid Howells ret = kernel_sendmsg(conn->params.local->socket, &msg, 47793c62c45SDavid Howells iov, 2, len); 478330bdcfaSDavid Howells conn->params.peer->last_tx_at = ktime_get_seconds(); 47975b54cb5SDavid Howells 48075b54cb5SDavid Howells opt = IPV6_PMTUDISC_DO; 48175b54cb5SDavid Howells kernel_setsockopt(conn->params.local->socket, 48275b54cb5SDavid Howells SOL_IPV6, IPV6_MTU_DISCOVER, 48375b54cb5SDavid Howells (char *)&opt, sizeof(opt)); 48475b54cb5SDavid Howells } 48575b54cb5SDavid Howells break; 486d1912747SDavid Howells #endif 4878c3e34a4SDavid Howells } 4888c3e34a4SDavid Howells 4896b47fe1dSDavid Howells if (ret < 0) 4906b47fe1dSDavid Howells trace_rxrpc_tx_fail(call->debug_id, serial, ret, 4916b47fe1dSDavid Howells rxrpc_tx_fail_call_data_frag); 4926b47fe1dSDavid Howells 493985a5c82SDavid Howells up_write(&conn->params.local->defrag_sem); 4945a924b89SDavid Howells goto done; 4958c3e34a4SDavid Howells } 496248f219cSDavid Howells 497248f219cSDavid Howells /* 498248f219cSDavid Howells * reject packets through the local endpoint 499248f219cSDavid Howells */ 500248f219cSDavid Howells void rxrpc_reject_packets(struct rxrpc_local *local) 501248f219cSDavid Howells { 5021c2bc7b9SDavid Howells struct sockaddr_rxrpc srx; 503248f219cSDavid Howells struct rxrpc_skb_priv *sp; 504248f219cSDavid Howells struct rxrpc_wire_header whdr; 505248f219cSDavid Howells struct sk_buff *skb; 506248f219cSDavid Howells struct msghdr msg; 507248f219cSDavid Howells struct kvec iov[2]; 508248f219cSDavid Howells size_t size; 509248f219cSDavid Howells __be32 code; 5106b47fe1dSDavid Howells int ret; 511248f219cSDavid Howells 512248f219cSDavid Howells _enter("%d", local->debug_id); 513248f219cSDavid Howells 514248f219cSDavid Howells iov[0].iov_base = &whdr; 515248f219cSDavid Howells iov[0].iov_len = sizeof(whdr); 516248f219cSDavid Howells iov[1].iov_base = &code; 517248f219cSDavid Howells iov[1].iov_len = sizeof(code); 518248f219cSDavid Howells size = sizeof(whdr) + sizeof(code); 519248f219cSDavid Howells 5201c2bc7b9SDavid Howells msg.msg_name = &srx.transport; 521248f219cSDavid Howells msg.msg_control = NULL; 522248f219cSDavid Howells msg.msg_controllen = 0; 523248f219cSDavid Howells msg.msg_flags = 0; 524248f219cSDavid Howells 525248f219cSDavid Howells memset(&whdr, 0, sizeof(whdr)); 526248f219cSDavid Howells whdr.type = RXRPC_PACKET_TYPE_ABORT; 527248f219cSDavid Howells 528248f219cSDavid Howells while ((skb = skb_dequeue(&local->reject_queue))) { 52971f3ca40SDavid Howells rxrpc_see_skb(skb, rxrpc_skb_rx_seen); 530248f219cSDavid Howells sp = rxrpc_skb(skb); 5311c2bc7b9SDavid Howells 5327b674e39SDavid Howells if (rxrpc_extract_addr_from_skb(local, &srx, skb) == 0) { 5331c2bc7b9SDavid Howells msg.msg_namelen = srx.transport_len; 5341c2bc7b9SDavid Howells 535248f219cSDavid Howells code = htonl(skb->priority); 536248f219cSDavid Howells 537248f219cSDavid Howells whdr.epoch = htonl(sp->hdr.epoch); 538248f219cSDavid Howells whdr.cid = htonl(sp->hdr.cid); 539248f219cSDavid Howells whdr.callNumber = htonl(sp->hdr.callNumber); 540248f219cSDavid Howells whdr.serviceId = htons(sp->hdr.serviceId); 541248f219cSDavid Howells whdr.flags = sp->hdr.flags; 542248f219cSDavid Howells whdr.flags ^= RXRPC_CLIENT_INITIATED; 543248f219cSDavid Howells whdr.flags &= RXRPC_CLIENT_INITIATED; 544248f219cSDavid Howells 5456b47fe1dSDavid Howells ret = kernel_sendmsg(local->socket, &msg, iov, 2, size); 5466b47fe1dSDavid Howells if (ret < 0) 5476b47fe1dSDavid Howells trace_rxrpc_tx_fail(local->debug_id, 0, ret, 5486b47fe1dSDavid Howells rxrpc_tx_fail_reject); 549248f219cSDavid Howells } 550248f219cSDavid Howells 55171f3ca40SDavid Howells rxrpc_free_skb(skb, rxrpc_skb_rx_freed); 552248f219cSDavid Howells } 553248f219cSDavid Howells 554248f219cSDavid Howells _leave(""); 555248f219cSDavid Howells } 556ace45becSDavid Howells 557ace45becSDavid Howells /* 558ace45becSDavid Howells * Send a VERSION reply to a peer as a keepalive. 559ace45becSDavid Howells */ 560ace45becSDavid Howells void rxrpc_send_keepalive(struct rxrpc_peer *peer) 561ace45becSDavid Howells { 562ace45becSDavid Howells struct rxrpc_wire_header whdr; 563ace45becSDavid Howells struct msghdr msg; 564ace45becSDavid Howells struct kvec iov[2]; 565ace45becSDavid Howells size_t len; 566ace45becSDavid Howells int ret; 567ace45becSDavid Howells 568ace45becSDavid Howells _enter(""); 569ace45becSDavid Howells 570ace45becSDavid Howells msg.msg_name = &peer->srx.transport; 571ace45becSDavid Howells msg.msg_namelen = peer->srx.transport_len; 572ace45becSDavid Howells msg.msg_control = NULL; 573ace45becSDavid Howells msg.msg_controllen = 0; 574ace45becSDavid Howells msg.msg_flags = 0; 575ace45becSDavid Howells 576ace45becSDavid Howells whdr.epoch = htonl(peer->local->rxnet->epoch); 577ace45becSDavid Howells whdr.cid = 0; 578ace45becSDavid Howells whdr.callNumber = 0; 579ace45becSDavid Howells whdr.seq = 0; 580ace45becSDavid Howells whdr.serial = 0; 581ace45becSDavid Howells whdr.type = RXRPC_PACKET_TYPE_VERSION; /* Not client-initiated */ 582ace45becSDavid Howells whdr.flags = RXRPC_LAST_PACKET; 583ace45becSDavid Howells whdr.userStatus = 0; 584ace45becSDavid Howells whdr.securityIndex = 0; 585ace45becSDavid Howells whdr._rsvd = 0; 586ace45becSDavid Howells whdr.serviceId = 0; 587ace45becSDavid Howells 588ace45becSDavid Howells iov[0].iov_base = &whdr; 589ace45becSDavid Howells iov[0].iov_len = sizeof(whdr); 590ace45becSDavid Howells iov[1].iov_base = (char *)rxrpc_keepalive_string; 591ace45becSDavid Howells iov[1].iov_len = sizeof(rxrpc_keepalive_string); 592ace45becSDavid Howells 593ace45becSDavid Howells len = iov[0].iov_len + iov[1].iov_len; 594ace45becSDavid Howells 595ace45becSDavid Howells _proto("Tx VERSION (keepalive)"); 596ace45becSDavid Howells 597ace45becSDavid Howells ret = kernel_sendmsg(peer->local->socket, &msg, iov, 2, len); 598ace45becSDavid Howells if (ret < 0) 5996b47fe1dSDavid Howells trace_rxrpc_tx_fail(peer->debug_id, 0, ret, 6006b47fe1dSDavid Howells rxrpc_tx_fail_version_keepalive); 601ace45becSDavid Howells 602330bdcfaSDavid Howells peer->last_tx_at = ktime_get_seconds(); 603ace45becSDavid Howells _leave(""); 604ace45becSDavid Howells } 605