12 #include <linux/module.h>
14 #include <linux/net.h>
16 #include <linux/slab.h>
17 #include <linux/udp.h>
22 static unsigned int rxrpc_ack_defer = 1;
24 static const char *
const rxrpc_acks[] = {
25 "---",
"REQ",
"DUP",
"OOS",
"WIN",
"MEM",
"PNG",
"PNR",
"DLY",
"IDL",
29 static const s8 rxrpc_ack_priority[] = {
48 s8 prior = rxrpc_ack_priority[ack_reason];
56 if (prior < rxrpc_ack_priority[call->
ackr_reason]) {
64 if (prior == rxrpc_ack_priority[call->
ackr_reason]) {
95 expiry = rxrpc_ack_defer;
127 s8 prior = rxrpc_ack_priority[ack_reason];
129 if (prior > rxrpc_ack_priority[call->
ackr_reason]) {
130 spin_lock_bh(&call->
lock);
132 spin_unlock_bh(&call->
lock);
140 unsigned long resend_at)
152 _debug(
"MODIFY RESEND TIMER");
156 _debug(
"KILL RESEND TIMER");
167 static void rxrpc_resend(
struct rxrpc_call *call)
172 unsigned long *p_txb, resend_at;
194 txb = (
struct sk_buff *) *p_txb;
207 _proto(
"Tx DATA %%%u { #%d }",
221 }
else if (resend & 2) {
230 rxrpc_set_resend(call, resend, resend_at);
237 static void rxrpc_resend_timer(
struct rxrpc_call *call)
241 unsigned long *p_txb, resend_at;
248 if (call->
state >= RXRPC_CALL_COMPLETE)
260 txb = (
struct sk_buff *) (*p_txb & ~1);
270 }
else if (resend & 2) {
279 rxrpc_set_resend(call, resend, resend_at);
288 static int rxrpc_process_soft_ACKs(
struct rxrpc_call *call,
294 unsigned long *p_txb, resend_at;
308 for (loop = 0; loop < ack->
nAcks; loop++) {
312 txb = (
struct sk_buff *) (*p_txb & ~1);
315 switch (sacks[loop]) {
326 _debug(
"Unsupported ACK type %d", sacks[loop]);
342 txb = (
struct sk_buff *) (*p_txb & ~1);
355 }
else if (resend & 2) {
364 rxrpc_set_resend(call, resend, resend_at);
404 static void rxrpc_clear_tx_window(
struct rxrpc_call *call)
412 static int rxrpc_drain_rx_oos_queue(
struct rxrpc_call *call)
421 spin_lock_bh(&call->
lock);
425 goto socket_unavailable;
431 _debug(
"drain OOS packet %d [%d]",
460 spin_unlock_bh(&call->
lock);
468 static void rxrpc_insert_oos_packet(
struct rxrpc_call *call,
485 spin_lock_bh(&call->
lock);
490 _debug(
"insert oos #%u before #%u",
497 _debug(
"append oos #%u", seq);
502 if (call->
rx_first_oos == 0 || seq < call->rx_first_oos)
506 if (call->
state < RXRPC_CALL_COMPLETE &&
508 _debug(
"drain rx oos now");
513 spin_unlock_bh(&call->
lock);
520 static void rxrpc_zap_tx_window(
struct rxrpc_call *call)
524 unsigned long _skb, *acks_window;
534 _skb = acks_window[
tail] & ~1;
551 unsigned int latest,
int nAcks)
557 if (
skb_copy_bits(skb, nAcks + 3, &ackinfo,
sizeof(ackinfo)) < 0) {
562 _proto(
"Rx ACK %%%u Info { rx=%u max=%u rwin=%u jm=%u }",
565 ntohl(ackinfo.rwind),
ntohl(ackinfo.jumbo_max));
569 peer = call->
conn->trans->peer;
571 spin_lock_bh(&peer->
lock);
574 spin_unlock_bh(&peer->
lock);
582 static int rxrpc_process_rx_queue(
struct rxrpc_call *call,
599 _net(
"deferred skb %p", skb);
607 switch (sp->
hdr.type) {
611 _proto(
"OOSQ DATA %%%u { #%u }",
618 rxrpc_insert_oos_packet(call, skb);
619 goto process_further;
624 _debug(
"extraction failure");
634 _proto(
"Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
643 rxrpc_extract_ackinfo(call, skb, latest, ack.
nAcks);
646 _proto(
"Rx ACK %%%u PING Request", latest);
648 sp->
hdr.serial,
true);
653 _debug(
"discard ACK %d <= %d",
659 if (call->
state != RXRPC_CALL_CLIENT_SEND_REQUEST &&
660 call->
state != RXRPC_CALL_CLIENT_AWAIT_REPLY &&
661 call->
state != RXRPC_CALL_SERVER_SEND_REPLY &&
662 call->
state != RXRPC_CALL_SERVER_AWAIT_ACK)
669 _debug(
"hard-ACK'd packet %d not transmitted"
675 if ((call->
state == RXRPC_CALL_CLIENT_AWAIT_REPLY ||
676 call->
state == RXRPC_CALL_SERVER_AWAIT_ACK) &&
681 rxrpc_rotate_tx_window(call, hard - 1);
685 if (hard - 1 + ack.
nAcks > tx) {
686 _debug(
"soft-ACK'd packet %d+%d not"
687 " transmitted (%d top)",
688 hard - 1, ack.
nAcks, tx);
692 if (rxrpc_process_soft_ACKs(call, &ack, skb) < 0)
719 switch (call->
state) {
720 case RXRPC_CALL_CLIENT_AWAIT_REPLY:
721 call->
state = RXRPC_CALL_CLIENT_RECV_REPLY;
723 case RXRPC_CALL_SERVER_AWAIT_ACK:
725 call->
state = RXRPC_CALL_COMPLETE;
728 case RXRPC_CALL_CLIENT_SEND_REQUEST:
729 case RXRPC_CALL_SERVER_RECV_REQUEST:
730 goto protocol_error_unlock;
748 rxrpc_zap_tx_window(call);
756 spin_lock_bh(&call->
lock);
759 spin_unlock_bh(&call->
lock);
760 goto process_further;
765 goto process_further;
767 protocol_error_unlock:
785 _enter(
"{%d,%lx},%u,%u,%d",
811 memset(sp, 0,
sizeof(*sp));
816 spin_lock_bh(&call->
lock);
818 spin_unlock_bh(&call->
lock);
841 int genbit, loop, nbit,
ioc,
ret, mtu;
846 _enter(
"{%d,%s,%lx} [%lu]",
851 _debug(
"XXXXXXXXXXXXX RUNNING ON MULTIPLE CPUS XXXXXXXXXXXXX");
857 msg.
msg_name = &call->
conn->trans->peer->srx.transport.sin;
874 memset(iov, 0,
sizeof(iov));
891 error = call->
conn->trans->peer->net_error;
892 _debug(
"post net error %d", error);
907 _debug(
"post conn abort");
910 call->
conn->error,
true) < 0)
946 spin_lock_bh(&call->
lock);
950 spin_unlock_bh(&call->
lock);
959 iov[3].
iov_len =
sizeof(ackinfo);
973 _debug(
"post abort/busy");
974 rxrpc_clear_tx_window(call);
975 if (rxrpc_post_message(call, mark,
ECONNABORTED,
true) < 0)
984 _debug(
"do implicit ackall");
985 rxrpc_clear_tx_window(call);
990 if (call->
state <= RXRPC_CALL_COMPLETE) {
991 call->
state = RXRPC_CALL_LOCALLY_ABORTED;
1007 if (!skb_queue_empty(&call->
rx_queue)) {
1008 switch (rxrpc_process_rx_queue(call, &abort_code)) {
1017 rxrpc_abort_call(call, abort_code);
1024 rxrpc_resend_timer(call);
1030 _debug(
"send ACK: window: %d - %d { %lx }",
1034 if (call->
state > RXRPC_CALL_SERVER_ACK_REQUEST &&
1038 goto maybe_reschedule;
1054 spin_lock_bh(&call->
lock);
1063 for (bits = call->
ackr_window[loop]; bits; bits >>= 1
1065 _debug(
"- l=%d n=%d b=%lx", loop, nbit, bits);
1068 ack.
nAcks = nbit + 1;
1074 spin_unlock_bh(&call->
lock);
1085 iov[4].
iov_len =
sizeof(ackinfo);
1095 goto send_ACK_with_skew;
1106 spin_lock_bh(&call->
lock);
1108 if (call->
state == RXRPC_CALL_SERVER_SECURING) {
1114 call->
state = RXRPC_CALL_SERVER_ACCEPTING;
1120 if (call->
state < RXRPC_CALL_COMPLETE)
1125 spin_unlock_bh(&call->
lock);
1127 goto maybe_reschedule;
1137 goto maybe_reschedule;
1146 if (call->
state < RXRPC_CALL_COMPLETE)
1155 if (rxrpc_drain_rx_oos_queue(call) < 0)
1157 goto maybe_reschedule;
1161 goto maybe_reschedule;
1167 mtu = call->
conn->trans->peer->if_mtu;
1168 mtu -= call->
conn->trans->peer->hdrsize;
1177 _proto(
"Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
1189 goto send_message_2;
1206 }
else if (iov[3].iov_len) {
1211 }
else if (iov[2].iov_len) {
1215 }
else if (iov[1].iov_len) {
1221 &msg, iov, ioc, len);
1223 _debug(
"sendmsg failed: %d", ret);
1225 if (call->
state < RXRPC_CALL_DEAD)
1239 if (call->
state == RXRPC_CALL_CLIENT_FINAL_ACK)
1240 call->
state = RXRPC_CALL_COMPLETE;
1246 switch (call->
state) {
1247 case RXRPC_CALL_CLIENT_AWAIT_REPLY:
1248 case RXRPC_CALL_CLIENT_RECV_REPLY:
1249 case RXRPC_CALL_SERVER_RECV_REQUEST:
1250 case RXRPC_CALL_SERVER_ACK_REQUEST:
1251 _debug(
"start ACK timer");
1257 goto maybe_reschedule;
1269 if (call->
state < RXRPC_CALL_DEAD)
1275 if (call->
state >= RXRPC_CALL_COMPLETE &&
1277 _debug(
"X unlinking once-pending call %p { e=%lx f=%lx c=%x }",
1306 goto maybe_reschedule;