aboutsummaryrefslogtreecommitdiffstats
path: root/net/rxrpc/ar-input.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/rxrpc/ar-input.c')
-rw-r--r--net/rxrpc/ar-input.c190
1 files changed, 80 insertions, 110 deletions
diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
index 529572f18d1f..73742647c135 100644
--- a/net/rxrpc/ar-input.c
+++ b/net/rxrpc/ar-input.c
@@ -25,8 +25,6 @@
25#include <net/net_namespace.h> 25#include <net/net_namespace.h>
26#include "ar-internal.h" 26#include "ar-internal.h"
27 27
28unsigned long rxrpc_ack_timeout = 1;
29
30const char *rxrpc_pkts[] = { 28const char *rxrpc_pkts[] = {
31 "?00", 29 "?00",
32 "DATA", "ACK", "BUSY", "ABORT", "ACKALL", "CHALL", "RESP", "DEBUG", 30 "DATA", "ACK", "BUSY", "ABORT", "ACKALL", "CHALL", "RESP", "DEBUG",
@@ -349,8 +347,7 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
349 * it */ 347 * it */
350 if (sp->hdr.flags & RXRPC_REQUEST_ACK) { 348 if (sp->hdr.flags & RXRPC_REQUEST_ACK) {
351 _proto("ACK Requested on %%%u", serial); 349 _proto("ACK Requested on %%%u", serial);
352 rxrpc_propose_ACK(call, RXRPC_ACK_REQUESTED, sp->hdr.serial, 350 rxrpc_propose_ACK(call, RXRPC_ACK_REQUESTED, sp->hdr.serial, false);
353 !(sp->hdr.flags & RXRPC_MORE_PACKETS));
354 } 351 }
355 352
356 switch (sp->hdr.type) { 353 switch (sp->hdr.type) {
@@ -526,36 +523,38 @@ protocol_error:
526 * post an incoming packet to the appropriate call/socket to deal with 523 * post an incoming packet to the appropriate call/socket to deal with
527 * - must get rid of the sk_buff, either by freeing it or by queuing it 524 * - must get rid of the sk_buff, either by freeing it or by queuing it
528 */ 525 */
529static void rxrpc_post_packet_to_call(struct rxrpc_connection *conn, 526static void rxrpc_post_packet_to_call(struct rxrpc_call *call,
530 struct sk_buff *skb) 527 struct sk_buff *skb)
531{ 528{
532 struct rxrpc_skb_priv *sp; 529 struct rxrpc_skb_priv *sp;
533 struct rxrpc_call *call;
534 struct rb_node *p;
535 __be32 call_id;
536
537 _enter("%p,%p", conn, skb);
538 530
539 read_lock_bh(&conn->lock); 531 _enter("%p,%p", call, skb);
540 532
541 sp = rxrpc_skb(skb); 533 sp = rxrpc_skb(skb);
542 534
543 /* look at extant calls by channel number first */
544 call = conn->channels[ntohl(sp->hdr.cid) & RXRPC_CHANNELMASK];
545 if (!call || call->call_id != sp->hdr.callNumber)
546 goto call_not_extant;
547
548 _debug("extant call [%d]", call->state); 535 _debug("extant call [%d]", call->state);
549 ASSERTCMP(call->conn, ==, conn);
550 536
551 read_lock(&call->state_lock); 537 read_lock(&call->state_lock);
552 switch (call->state) { 538 switch (call->state) {
553 case RXRPC_CALL_LOCALLY_ABORTED: 539 case RXRPC_CALL_LOCALLY_ABORTED:
554 if (!test_and_set_bit(RXRPC_CALL_ABORT, &call->events)) 540 if (!test_and_set_bit(RXRPC_CALL_ABORT, &call->events)) {
555 rxrpc_queue_call(call); 541 rxrpc_queue_call(call);
542 goto free_unlock;
543 }
556 case RXRPC_CALL_REMOTELY_ABORTED: 544 case RXRPC_CALL_REMOTELY_ABORTED:
557 case RXRPC_CALL_NETWORK_ERROR: 545 case RXRPC_CALL_NETWORK_ERROR:
558 case RXRPC_CALL_DEAD: 546 case RXRPC_CALL_DEAD:
547 goto dead_call;
548 case RXRPC_CALL_COMPLETE:
549 case RXRPC_CALL_CLIENT_FINAL_ACK:
550 /* complete server call */
551 if (call->conn->in_clientflag)
552 goto dead_call;
553 /* resend last packet of a completed call */
554 _debug("final ack again");
555 rxrpc_get_call(call);
556 set_bit(RXRPC_CALL_ACK_FINAL, &call->events);
557 rxrpc_queue_call(call);
559 goto free_unlock; 558 goto free_unlock;
560 default: 559 default:
561 break; 560 break;
@@ -563,7 +562,6 @@ static void rxrpc_post_packet_to_call(struct rxrpc_connection *conn,
563 562
564 read_unlock(&call->state_lock); 563 read_unlock(&call->state_lock);
565 rxrpc_get_call(call); 564 rxrpc_get_call(call);
566 read_unlock_bh(&conn->lock);
567 565
568 if (sp->hdr.type == RXRPC_PACKET_TYPE_DATA && 566 if (sp->hdr.type == RXRPC_PACKET_TYPE_DATA &&
569 sp->hdr.flags & RXRPC_JUMBO_PACKET) 567 sp->hdr.flags & RXRPC_JUMBO_PACKET)
@@ -574,78 +572,16 @@ static void rxrpc_post_packet_to_call(struct rxrpc_connection *conn,
574 rxrpc_put_call(call); 572 rxrpc_put_call(call);
575 goto done; 573 goto done;
576 574
577call_not_extant:
578 /* search the completed calls in case what we're dealing with is
579 * there */
580 _debug("call not extant");
581
582 call_id = sp->hdr.callNumber;
583 p = conn->calls.rb_node;
584 while (p) {
585 call = rb_entry(p, struct rxrpc_call, conn_node);
586
587 if (call_id < call->call_id)
588 p = p->rb_left;
589 else if (call_id > call->call_id)
590 p = p->rb_right;
591 else
592 goto found_completed_call;
593 }
594
595dead_call: 575dead_call:
596 /* it's a either a really old call that we no longer remember or its a 576 if (sp->hdr.type != RXRPC_PACKET_TYPE_ABORT) {
597 * new incoming call */ 577 skb->priority = RX_CALL_DEAD;
598 read_unlock_bh(&conn->lock); 578 rxrpc_reject_packet(call->conn->trans->local, skb);
599 579 goto unlock;
600 if (sp->hdr.flags & RXRPC_CLIENT_INITIATED &&
601 sp->hdr.seq == cpu_to_be32(1)) {
602 _debug("incoming call");
603 skb_queue_tail(&conn->trans->local->accept_queue, skb);
604 rxrpc_queue_work(&conn->trans->local->acceptor);
605 goto done;
606 }
607
608 _debug("dead call");
609 skb->priority = RX_CALL_DEAD;
610 rxrpc_reject_packet(conn->trans->local, skb);
611 goto done;
612
613 /* resend last packet of a completed call
614 * - client calls may have been aborted or ACK'd
615 * - server calls may have been aborted
616 */
617found_completed_call:
618 _debug("completed call");
619
620 if (atomic_read(&call->usage) == 0)
621 goto dead_call;
622
623 /* synchronise any state changes */
624 read_lock(&call->state_lock);
625 ASSERTIFCMP(call->state != RXRPC_CALL_CLIENT_FINAL_ACK,
626 call->state, >=, RXRPC_CALL_COMPLETE);
627
628 if (call->state == RXRPC_CALL_LOCALLY_ABORTED ||
629 call->state == RXRPC_CALL_REMOTELY_ABORTED ||
630 call->state == RXRPC_CALL_DEAD) {
631 read_unlock(&call->state_lock);
632 goto dead_call;
633 }
634
635 if (call->conn->in_clientflag) {
636 read_unlock(&call->state_lock);
637 goto dead_call; /* complete server call */
638 } 580 }
639
640 _debug("final ack again");
641 rxrpc_get_call(call);
642 set_bit(RXRPC_CALL_ACK_FINAL, &call->events);
643 rxrpc_queue_call(call);
644
645free_unlock: 581free_unlock:
646 read_unlock(&call->state_lock);
647 read_unlock_bh(&conn->lock);
648 rxrpc_free_skb(skb); 582 rxrpc_free_skb(skb);
583unlock:
584 read_unlock(&call->state_lock);
649done: 585done:
650 _leave(""); 586 _leave("");
651} 587}
@@ -664,17 +600,42 @@ static void rxrpc_post_packet_to_conn(struct rxrpc_connection *conn,
664 rxrpc_queue_conn(conn); 600 rxrpc_queue_conn(conn);
665} 601}
666 602
603static struct rxrpc_connection *rxrpc_conn_from_local(struct rxrpc_local *local,
604 struct sk_buff *skb,
605 struct rxrpc_skb_priv *sp)
606{
607 struct rxrpc_peer *peer;
608 struct rxrpc_transport *trans;
609 struct rxrpc_connection *conn;
610
611 peer = rxrpc_find_peer(local, ip_hdr(skb)->saddr,
612 udp_hdr(skb)->source);
613 if (IS_ERR(peer))
614 goto cant_find_conn;
615
616 trans = rxrpc_find_transport(local, peer);
617 rxrpc_put_peer(peer);
618 if (!trans)
619 goto cant_find_conn;
620
621 conn = rxrpc_find_connection(trans, &sp->hdr);
622 rxrpc_put_transport(trans);
623 if (!conn)
624 goto cant_find_conn;
625
626 return conn;
627cant_find_conn:
628 return NULL;
629}
630
667/* 631/*
668 * handle data received on the local endpoint 632 * handle data received on the local endpoint
669 * - may be called in interrupt context 633 * - may be called in interrupt context
670 */ 634 */
671void rxrpc_data_ready(struct sock *sk, int count) 635void rxrpc_data_ready(struct sock *sk, int count)
672{ 636{
673 struct rxrpc_connection *conn;
674 struct rxrpc_transport *trans;
675 struct rxrpc_skb_priv *sp; 637 struct rxrpc_skb_priv *sp;
676 struct rxrpc_local *local; 638 struct rxrpc_local *local;
677 struct rxrpc_peer *peer;
678 struct sk_buff *skb; 639 struct sk_buff *skb;
679 int ret; 640 int ret;
680 641
@@ -749,27 +710,34 @@ void rxrpc_data_ready(struct sock *sk, int count)
749 (sp->hdr.callNumber == 0 || sp->hdr.seq == 0)) 710 (sp->hdr.callNumber == 0 || sp->hdr.seq == 0))
750 goto bad_message; 711 goto bad_message;
751 712
752 peer = rxrpc_find_peer(local, ip_hdr(skb)->saddr, udp_hdr(skb)->source); 713 if (sp->hdr.callNumber == 0) {
753 if (IS_ERR(peer)) 714 /* This is a connection-level packet. These should be
754 goto cant_route_call; 715 * fairly rare, so the extra overhead of looking them up the
716 * old-fashioned way doesn't really hurt */
717 struct rxrpc_connection *conn;
755 718
756 trans = rxrpc_find_transport(local, peer); 719 conn = rxrpc_conn_from_local(local, skb, sp);
757 rxrpc_put_peer(peer); 720 if (!conn)
758 if (!trans) 721 goto cant_route_call;
759 goto cant_route_call;
760 722
761 conn = rxrpc_find_connection(trans, &sp->hdr); 723 _debug("CONN %p {%d}", conn, conn->debug_id);
762 rxrpc_put_transport(trans);
763 if (!conn)
764 goto cant_route_call;
765
766 _debug("CONN %p {%d}", conn, conn->debug_id);
767
768 if (sp->hdr.callNumber == 0)
769 rxrpc_post_packet_to_conn(conn, skb); 724 rxrpc_post_packet_to_conn(conn, skb);
770 else 725 rxrpc_put_connection(conn);
771 rxrpc_post_packet_to_call(conn, skb); 726 } else {
772 rxrpc_put_connection(conn); 727 struct rxrpc_call *call;
728 u8 in_clientflag = 0;
729
730 if (sp->hdr.flags & RXRPC_CLIENT_INITIATED)
731 in_clientflag = RXRPC_CLIENT_INITIATED;
732 call = rxrpc_find_call_hash(in_clientflag, sp->hdr.cid,
733 sp->hdr.callNumber, sp->hdr.epoch,
734 sp->hdr.serviceId, local, AF_INET,
735 (u8 *)&ip_hdr(skb)->saddr);
736 if (call)
737 rxrpc_post_packet_to_call(call, skb);
738 else
739 goto cant_route_call;
740 }
773 rxrpc_put_local(local); 741 rxrpc_put_local(local);
774 return; 742 return;
775 743
@@ -790,8 +758,10 @@ cant_route_call:
790 skb->priority = RX_CALL_DEAD; 758 skb->priority = RX_CALL_DEAD;
791 } 759 }
792 760
793 _debug("reject"); 761 if (sp->hdr.type != RXRPC_PACKET_TYPE_ABORT) {
794 rxrpc_reject_packet(local, skb); 762 _debug("reject type %d",sp->hdr.type);
763 rxrpc_reject_packet(local, skb);
764 }
795 rxrpc_put_local(local); 765 rxrpc_put_local(local);
796 _leave(" [no call]"); 766 _leave(" [no call]");
797 return; 767 return;