summaryrefslogtreecommitdiffstats
path: root/net/sctp/outqueue.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2018-06-06 21:39:49 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-06-06 21:39:49 -0400
commit1c8c5a9d38f607c0b6fd12c91cbe1a4418762a21 (patch)
treedcc97181d4d187252e0cc8fdf29d9b365fa3ffd0 /net/sctp/outqueue.c
parent285767604576148fc1be7fcd112e4a90eb0d6ad2 (diff)
parent7170e6045a6a8b33f4fa5753589dc77b16198e2d (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next
Pull networking updates from David Miller: 1) Add Maglev hashing scheduler to IPVS, from Inju Song. 2) Lots of new TC subsystem tests from Roman Mashak. 3) Add TCP zero copy receive and fix delayed acks and autotuning with SO_RCVLOWAT, from Eric Dumazet. 4) Add XDP_REDIRECT support to mlx5 driver, from Jesper Dangaard Brouer. 5) Add ttl inherit support to vxlan, from Hangbin Liu. 6) Properly separate ipv6 routes into their logically independant components. fib6_info for the routing table, and fib6_nh for sets of nexthops, which thus can be shared. From David Ahern. 7) Add bpf_xdp_adjust_tail helper, which can be used to generate ICMP messages from XDP programs. From Nikita V. Shirokov. 8) Lots of long overdue cleanups to the r8169 driver, from Heiner Kallweit. 9) Add BTF ("BPF Type Format"), from Martin KaFai Lau. 10) Add traffic condition monitoring to iwlwifi, from Luca Coelho. 11) Plumb extack down into fib_rules, from Roopa Prabhu. 12) Add Flower classifier offload support to igb, from Vinicius Costa Gomes. 13) Add UDP GSO support, from Willem de Bruijn. 14) Add documentation for eBPF helpers, from Quentin Monnet. 15) Add TLS tx offload to mlx5, from Ilya Lesokhin. 16) Allow applications to be given the number of bytes available to read on a socket via a control message returned from recvmsg(), from Soheil Hassas Yeganeh. 17) Add x86_32 eBPF JIT compiler, from Wang YanQing. 18) Add AF_XDP sockets, with zerocopy support infrastructure as well. From Björn Töpel. 19) Remove indirect load support from all of the BPF JITs and handle these operations in the verifier by translating them into native BPF instead. From Daniel Borkmann. 20) Add GRO support to ipv6 gre tunnels, from Eran Ben Elisha. 21) Allow XDP programs to do lookups in the main kernel routing tables for forwarding. From David Ahern. 22) Allow drivers to store hardware state into an ELF section of kernel dump vmcore files, and use it in cxgb4. From Rahul Lakkireddy. 23) Various RACK and loss detection improvements in TCP, from Yuchung Cheng. 24) Add TCP SACK compression, from Eric Dumazet. 25) Add User Mode Helper support and basic bpfilter infrastructure, from Alexei Starovoitov. 26) Support ports and protocol values in RTM_GETROUTE, from Roopa Prabhu. 27) Support bulking in ->ndo_xdp_xmit() API, from Jesper Dangaard Brouer. 28) Add lots of forwarding selftests, from Petr Machata. 29) Add generic network device failover driver, from Sridhar Samudrala. * ra.kernel.org:/pub/scm/linux/kernel/git/davem/net-next: (1959 commits) strparser: Add __strp_unpause and use it in ktls. rxrpc: Fix terminal retransmission connection ID to include the channel net: hns3: Optimize PF CMDQ interrupt switching process net: hns3: Fix for VF mailbox receiving unknown message net: hns3: Fix for VF mailbox cannot receiving PF response bnx2x: use the right constant Revert "net: sched: cls: Fix offloading when ingress dev is vxlan" net: dsa: b53: Fix for brcm tag issue in Cygnus SoC enic: fix UDP rss bits netdev-FAQ: clarify DaveM's position for stable backports rtnetlink: validate attributes in do_setlink() mlxsw: Add extack messages for port_{un, }split failures netdevsim: Add extack error message for devlink reload devlink: Add extack to reload and port_{un, }split operations net: metrics: add proper netlink validation ipmr: fix error path when ipmr_new_table fails ip6mr: only set ip6mr_table from setsockopt when ip6mr_new_table succeeds net: hns3: remove unused hclgevf_cfg_func_mta_filter netfilter: provide udp*_lib_lookup for nf_tproxy qed*: Utilize FW 8.37.2.0 ...
Diffstat (limited to 'net/sctp/outqueue.c')
-rw-r--r--net/sctp/outqueue.c660
1 files changed, 333 insertions, 327 deletions
diff --git a/net/sctp/outqueue.c b/net/sctp/outqueue.c
index f211b3db6a35..d68aa33485a9 100644
--- a/net/sctp/outqueue.c
+++ b/net/sctp/outqueue.c
@@ -601,14 +601,14 @@ void sctp_retransmit(struct sctp_outq *q, struct sctp_transport *transport,
601 601
602/* 602/*
603 * Transmit DATA chunks on the retransmit queue. Upon return from 603 * Transmit DATA chunks on the retransmit queue. Upon return from
604 * sctp_outq_flush_rtx() the packet 'pkt' may contain chunks which 604 * __sctp_outq_flush_rtx() the packet 'pkt' may contain chunks which
605 * need to be transmitted by the caller. 605 * need to be transmitted by the caller.
606 * We assume that pkt->transport has already been set. 606 * We assume that pkt->transport has already been set.
607 * 607 *
608 * The return value is a normal kernel error return value. 608 * The return value is a normal kernel error return value.
609 */ 609 */
610static int sctp_outq_flush_rtx(struct sctp_outq *q, struct sctp_packet *pkt, 610static int __sctp_outq_flush_rtx(struct sctp_outq *q, struct sctp_packet *pkt,
611 int rtx_timeout, int *start_timer) 611 int rtx_timeout, int *start_timer, gfp_t gfp)
612{ 612{
613 struct sctp_transport *transport = pkt->transport; 613 struct sctp_transport *transport = pkt->transport;
614 struct sctp_chunk *chunk, *chunk1; 614 struct sctp_chunk *chunk, *chunk1;
@@ -684,12 +684,12 @@ redo:
684 * control chunks are already freed so there 684 * control chunks are already freed so there
685 * is nothing we can do. 685 * is nothing we can do.
686 */ 686 */
687 sctp_packet_transmit(pkt, GFP_ATOMIC); 687 sctp_packet_transmit(pkt, gfp);
688 goto redo; 688 goto redo;
689 } 689 }
690 690
691 /* Send this packet. */ 691 /* Send this packet. */
692 error = sctp_packet_transmit(pkt, GFP_ATOMIC); 692 error = sctp_packet_transmit(pkt, gfp);
693 693
694 /* If we are retransmitting, we should only 694 /* If we are retransmitting, we should only
695 * send a single packet. 695 * send a single packet.
@@ -705,7 +705,7 @@ redo:
705 705
706 case SCTP_XMIT_RWND_FULL: 706 case SCTP_XMIT_RWND_FULL:
707 /* Send this packet. */ 707 /* Send this packet. */
708 error = sctp_packet_transmit(pkt, GFP_ATOMIC); 708 error = sctp_packet_transmit(pkt, gfp);
709 709
710 /* Stop sending DATA as there is no more room 710 /* Stop sending DATA as there is no more room
711 * at the receiver. 711 * at the receiver.
@@ -715,7 +715,7 @@ redo:
715 715
716 case SCTP_XMIT_DELAY: 716 case SCTP_XMIT_DELAY:
717 /* Send this packet. */ 717 /* Send this packet. */
718 error = sctp_packet_transmit(pkt, GFP_ATOMIC); 718 error = sctp_packet_transmit(pkt, gfp);
719 719
720 /* Stop sending DATA because of nagle delay. */ 720 /* Stop sending DATA because of nagle delay. */
721 done = 1; 721 done = 1;
@@ -776,68 +776,43 @@ void sctp_outq_uncork(struct sctp_outq *q, gfp_t gfp)
776 sctp_outq_flush(q, 0, gfp); 776 sctp_outq_flush(q, 0, gfp);
777} 777}
778 778
779 779static int sctp_packet_singleton(struct sctp_transport *transport,
780/* 780 struct sctp_chunk *chunk, gfp_t gfp)
781 * Try to flush an outqueue.
782 *
783 * Description: Send everything in q which we legally can, subject to
784 * congestion limitations.
785 * * Note: This function can be called from multiple contexts so appropriate
786 * locking concerns must be made. Today we use the sock lock to protect
787 * this function.
788 */
789static void sctp_outq_flush(struct sctp_outq *q, int rtx_timeout, gfp_t gfp)
790{ 781{
791 struct sctp_packet *packet; 782 const struct sctp_association *asoc = transport->asoc;
783 const __u16 sport = asoc->base.bind_addr.port;
784 const __u16 dport = asoc->peer.port;
785 const __u32 vtag = asoc->peer.i.init_tag;
792 struct sctp_packet singleton; 786 struct sctp_packet singleton;
793 struct sctp_association *asoc = q->asoc;
794 __u16 sport = asoc->base.bind_addr.port;
795 __u16 dport = asoc->peer.port;
796 __u32 vtag = asoc->peer.i.init_tag;
797 struct sctp_transport *transport = NULL;
798 struct sctp_transport *new_transport;
799 struct sctp_chunk *chunk, *tmp;
800 enum sctp_xmit status;
801 int error = 0;
802 int start_timer = 0;
803 int one_packet = 0;
804 787
788 sctp_packet_init(&singleton, transport, sport, dport);
789 sctp_packet_config(&singleton, vtag, 0);
790 sctp_packet_append_chunk(&singleton, chunk);
791 return sctp_packet_transmit(&singleton, gfp);
792}
793
794/* Struct to hold the context during sctp outq flush */
795struct sctp_flush_ctx {
796 struct sctp_outq *q;
797 /* Current transport being used. It's NOT the same as curr active one */
798 struct sctp_transport *transport;
805 /* These transports have chunks to send. */ 799 /* These transports have chunks to send. */
806 struct list_head transport_list; 800 struct list_head transport_list;
807 struct list_head *ltransport; 801 struct sctp_association *asoc;
808 802 /* Packet on the current transport above */
809 INIT_LIST_HEAD(&transport_list); 803 struct sctp_packet *packet;
810 packet = NULL; 804 gfp_t gfp;
811 805};
812 /*
813 * 6.10 Bundling
814 * ...
815 * When bundling control chunks with DATA chunks, an
816 * endpoint MUST place control chunks first in the outbound
817 * SCTP packet. The transmitter MUST transmit DATA chunks
818 * within a SCTP packet in increasing order of TSN.
819 * ...
820 */
821
822 list_for_each_entry_safe(chunk, tmp, &q->control_chunk_list, list) {
823 /* RFC 5061, 5.3
824 * F1) This means that until such time as the ASCONF
825 * containing the add is acknowledged, the sender MUST
826 * NOT use the new IP address as a source for ANY SCTP
827 * packet except on carrying an ASCONF Chunk.
828 */
829 if (asoc->src_out_of_asoc_ok &&
830 chunk->chunk_hdr->type != SCTP_CID_ASCONF)
831 continue;
832
833 list_del_init(&chunk->list);
834 806
835 /* Pick the right transport to use. */ 807/* transport: current transport */
836 new_transport = chunk->transport; 808static void sctp_outq_select_transport(struct sctp_flush_ctx *ctx,
809 struct sctp_chunk *chunk)
810{
811 struct sctp_transport *new_transport = chunk->transport;
837 812
838 if (!new_transport) { 813 if (!new_transport) {
839 /* 814 if (!sctp_chunk_is_data(chunk)) {
840 * If we have a prior transport pointer, see if 815 /* If we have a prior transport pointer, see if
841 * the destination address of the chunk 816 * the destination address of the chunk
842 * matches the destination address of the 817 * matches the destination address of the
843 * current transport. If not a match, then 818 * current transport. If not a match, then
@@ -846,22 +821,26 @@ static void sctp_outq_flush(struct sctp_outq *q, int rtx_timeout, gfp_t gfp)
846 * after processing ASCONFs, we may have new 821 * after processing ASCONFs, we may have new
847 * transports created. 822 * transports created.
848 */ 823 */
849 if (transport && 824 if (ctx->transport && sctp_cmp_addr_exact(&chunk->dest,
850 sctp_cmp_addr_exact(&chunk->dest, 825 &ctx->transport->ipaddr))
851 &transport->ipaddr)) 826 new_transport = ctx->transport;
852 new_transport = transport;
853 else 827 else
854 new_transport = sctp_assoc_lookup_paddr(asoc, 828 new_transport = sctp_assoc_lookup_paddr(ctx->asoc,
855 &chunk->dest); 829 &chunk->dest);
830 }
856 831
857 /* if we still don't have a new transport, then 832 /* if we still don't have a new transport, then
858 * use the current active path. 833 * use the current active path.
859 */ 834 */
860 if (!new_transport) 835 if (!new_transport)
861 new_transport = asoc->peer.active_path; 836 new_transport = ctx->asoc->peer.active_path;
862 } else if ((new_transport->state == SCTP_INACTIVE) || 837 } else {
863 (new_transport->state == SCTP_UNCONFIRMED) || 838 __u8 type;
864 (new_transport->state == SCTP_PF)) { 839
840 switch (new_transport->state) {
841 case SCTP_INACTIVE:
842 case SCTP_UNCONFIRMED:
843 case SCTP_PF:
865 /* If the chunk is Heartbeat or Heartbeat Ack, 844 /* If the chunk is Heartbeat or Heartbeat Ack,
866 * send it to chunk->transport, even if it's 845 * send it to chunk->transport, even if it's
867 * inactive. 846 * inactive.
@@ -875,29 +854,64 @@ static void sctp_outq_flush(struct sctp_outq *q, int rtx_timeout, gfp_t gfp)
875 * 854 *
876 * ASCONF_ACKs also must be sent to the source. 855 * ASCONF_ACKs also must be sent to the source.
877 */ 856 */
878 if (chunk->chunk_hdr->type != SCTP_CID_HEARTBEAT && 857 type = chunk->chunk_hdr->type;
879 chunk->chunk_hdr->type != SCTP_CID_HEARTBEAT_ACK && 858 if (type != SCTP_CID_HEARTBEAT &&
880 chunk->chunk_hdr->type != SCTP_CID_ASCONF_ACK) 859 type != SCTP_CID_HEARTBEAT_ACK &&
881 new_transport = asoc->peer.active_path; 860 type != SCTP_CID_ASCONF_ACK)
861 new_transport = ctx->asoc->peer.active_path;
862 break;
863 default:
864 break;
882 } 865 }
866 }
867
868 /* Are we switching transports? Take care of transport locks. */
869 if (new_transport != ctx->transport) {
870 ctx->transport = new_transport;
871 ctx->packet = &ctx->transport->packet;
883 872
884 /* Are we switching transports? 873 if (list_empty(&ctx->transport->send_ready))
885 * Take care of transport locks. 874 list_add_tail(&ctx->transport->send_ready,
875 &ctx->transport_list);
876
877 sctp_packet_config(ctx->packet,
878 ctx->asoc->peer.i.init_tag,
879 ctx->asoc->peer.ecn_capable);
880 /* We've switched transports, so apply the
881 * Burst limit to the new transport.
886 */ 882 */
887 if (new_transport != transport) { 883 sctp_transport_burst_limited(ctx->transport);
888 transport = new_transport; 884 }
889 if (list_empty(&transport->send_ready)) { 885}
890 list_add_tail(&transport->send_ready, 886
891 &transport_list); 887static void sctp_outq_flush_ctrl(struct sctp_flush_ctx *ctx)
892 } 888{
893 packet = &transport->packet; 889 struct sctp_chunk *chunk, *tmp;
894 sctp_packet_config(packet, vtag, 890 enum sctp_xmit status;
895 asoc->peer.ecn_capable); 891 int one_packet, error;
896 } 892
893 list_for_each_entry_safe(chunk, tmp, &ctx->q->control_chunk_list, list) {
894 one_packet = 0;
895
896 /* RFC 5061, 5.3
897 * F1) This means that until such time as the ASCONF
898 * containing the add is acknowledged, the sender MUST
899 * NOT use the new IP address as a source for ANY SCTP
900 * packet except on carrying an ASCONF Chunk.
901 */
902 if (ctx->asoc->src_out_of_asoc_ok &&
903 chunk->chunk_hdr->type != SCTP_CID_ASCONF)
904 continue;
905
906 list_del_init(&chunk->list);
907
908 /* Pick the right transport to use. Should always be true for
909 * the first chunk as we don't have a transport by then.
910 */
911 sctp_outq_select_transport(ctx, chunk);
897 912
898 switch (chunk->chunk_hdr->type) { 913 switch (chunk->chunk_hdr->type) {
899 /* 914 /* 6.10 Bundling
900 * 6.10 Bundling
901 * ... 915 * ...
902 * An endpoint MUST NOT bundle INIT, INIT ACK or SHUTDOWN 916 * An endpoint MUST NOT bundle INIT, INIT ACK or SHUTDOWN
903 * COMPLETE with any other chunks. [Send them immediately.] 917 * COMPLETE with any other chunks. [Send them immediately.]
@@ -905,20 +919,19 @@ static void sctp_outq_flush(struct sctp_outq *q, int rtx_timeout, gfp_t gfp)
905 case SCTP_CID_INIT: 919 case SCTP_CID_INIT:
906 case SCTP_CID_INIT_ACK: 920 case SCTP_CID_INIT_ACK:
907 case SCTP_CID_SHUTDOWN_COMPLETE: 921 case SCTP_CID_SHUTDOWN_COMPLETE:
908 sctp_packet_init(&singleton, transport, sport, dport); 922 error = sctp_packet_singleton(ctx->transport, chunk,
909 sctp_packet_config(&singleton, vtag, 0); 923 ctx->gfp);
910 sctp_packet_append_chunk(&singleton, chunk);
911 error = sctp_packet_transmit(&singleton, gfp);
912 if (error < 0) { 924 if (error < 0) {
913 asoc->base.sk->sk_err = -error; 925 ctx->asoc->base.sk->sk_err = -error;
914 return; 926 return;
915 } 927 }
916 break; 928 break;
917 929
918 case SCTP_CID_ABORT: 930 case SCTP_CID_ABORT:
919 if (sctp_test_T_bit(chunk)) 931 if (sctp_test_T_bit(chunk))
920 packet->vtag = asoc->c.my_vtag; 932 ctx->packet->vtag = ctx->asoc->c.my_vtag;
921 /* fallthru */ 933 /* fallthru */
934
922 /* The following chunks are "response" chunks, i.e. 935 /* The following chunks are "response" chunks, i.e.
923 * they are generated in response to something we 936 * they are generated in response to something we
924 * received. If we are sending these, then we can 937 * received. If we are sending these, then we can
@@ -942,27 +955,27 @@ static void sctp_outq_flush(struct sctp_outq *q, int rtx_timeout, gfp_t gfp)
942 case SCTP_CID_FWD_TSN: 955 case SCTP_CID_FWD_TSN:
943 case SCTP_CID_I_FWD_TSN: 956 case SCTP_CID_I_FWD_TSN:
944 case SCTP_CID_RECONF: 957 case SCTP_CID_RECONF:
945 status = sctp_packet_transmit_chunk(packet, chunk, 958 status = sctp_packet_transmit_chunk(ctx->packet, chunk,
946 one_packet, gfp); 959 one_packet, ctx->gfp);
947 if (status != SCTP_XMIT_OK) { 960 if (status != SCTP_XMIT_OK) {
948 /* put the chunk back */ 961 /* put the chunk back */
949 list_add(&chunk->list, &q->control_chunk_list); 962 list_add(&chunk->list, &ctx->q->control_chunk_list);
950 break; 963 break;
951 } 964 }
952 965
953 asoc->stats.octrlchunks++; 966 ctx->asoc->stats.octrlchunks++;
954 /* PR-SCTP C5) If a FORWARD TSN is sent, the 967 /* PR-SCTP C5) If a FORWARD TSN is sent, the
955 * sender MUST assure that at least one T3-rtx 968 * sender MUST assure that at least one T3-rtx
956 * timer is running. 969 * timer is running.
957 */ 970 */
958 if (chunk->chunk_hdr->type == SCTP_CID_FWD_TSN || 971 if (chunk->chunk_hdr->type == SCTP_CID_FWD_TSN ||
959 chunk->chunk_hdr->type == SCTP_CID_I_FWD_TSN) { 972 chunk->chunk_hdr->type == SCTP_CID_I_FWD_TSN) {
960 sctp_transport_reset_t3_rtx(transport); 973 sctp_transport_reset_t3_rtx(ctx->transport);
961 transport->last_time_sent = jiffies; 974 ctx->transport->last_time_sent = jiffies;
962 } 975 }
963 976
964 if (chunk == asoc->strreset_chunk) 977 if (chunk == ctx->asoc->strreset_chunk)
965 sctp_transport_reset_reconf_timer(transport); 978 sctp_transport_reset_reconf_timer(ctx->transport);
966 979
967 break; 980 break;
968 981
@@ -971,232 +984,186 @@ static void sctp_outq_flush(struct sctp_outq *q, int rtx_timeout, gfp_t gfp)
971 BUG(); 984 BUG();
972 } 985 }
973 } 986 }
987}
974 988
975 if (q->asoc->src_out_of_asoc_ok) 989/* Returns false if new data shouldn't be sent */
976 goto sctp_flush_out; 990static bool sctp_outq_flush_rtx(struct sctp_flush_ctx *ctx,
991 int rtx_timeout)
992{
993 int error, start_timer = 0;
994
995 if (ctx->asoc->peer.retran_path->state == SCTP_UNCONFIRMED)
996 return false;
997
998 if (ctx->transport != ctx->asoc->peer.retran_path) {
999 /* Switch transports & prepare the packet. */
1000 ctx->transport = ctx->asoc->peer.retran_path;
1001 ctx->packet = &ctx->transport->packet;
1002
1003 if (list_empty(&ctx->transport->send_ready))
1004 list_add_tail(&ctx->transport->send_ready,
1005 &ctx->transport_list);
1006
1007 sctp_packet_config(ctx->packet, ctx->asoc->peer.i.init_tag,
1008 ctx->asoc->peer.ecn_capable);
1009 }
1010
1011 error = __sctp_outq_flush_rtx(ctx->q, ctx->packet, rtx_timeout,
1012 &start_timer, ctx->gfp);
1013 if (error < 0)
1014 ctx->asoc->base.sk->sk_err = -error;
1015
1016 if (start_timer) {
1017 sctp_transport_reset_t3_rtx(ctx->transport);
1018 ctx->transport->last_time_sent = jiffies;
1019 }
1020
1021 /* This can happen on COOKIE-ECHO resend. Only
1022 * one chunk can get bundled with a COOKIE-ECHO.
1023 */
1024 if (ctx->packet->has_cookie_echo)
1025 return false;
1026
1027 /* Don't send new data if there is still data
1028 * waiting to retransmit.
1029 */
1030 if (!list_empty(&ctx->q->retransmit))
1031 return false;
1032
1033 return true;
1034}
1035
1036static void sctp_outq_flush_data(struct sctp_flush_ctx *ctx,
1037 int rtx_timeout)
1038{
1039 struct sctp_chunk *chunk;
1040 enum sctp_xmit status;
977 1041
978 /* Is it OK to send data chunks? */ 1042 /* Is it OK to send data chunks? */
979 switch (asoc->state) { 1043 switch (ctx->asoc->state) {
980 case SCTP_STATE_COOKIE_ECHOED: 1044 case SCTP_STATE_COOKIE_ECHOED:
981 /* Only allow bundling when this packet has a COOKIE-ECHO 1045 /* Only allow bundling when this packet has a COOKIE-ECHO
982 * chunk. 1046 * chunk.
983 */ 1047 */
984 if (!packet || !packet->has_cookie_echo) 1048 if (!ctx->packet || !ctx->packet->has_cookie_echo)
985 break; 1049 return;
986 1050
987 /* fallthru */ 1051 /* fallthru */
988 case SCTP_STATE_ESTABLISHED: 1052 case SCTP_STATE_ESTABLISHED:
989 case SCTP_STATE_SHUTDOWN_PENDING: 1053 case SCTP_STATE_SHUTDOWN_PENDING:
990 case SCTP_STATE_SHUTDOWN_RECEIVED: 1054 case SCTP_STATE_SHUTDOWN_RECEIVED:
991 /* 1055 break;
992 * RFC 2960 6.1 Transmission of DATA Chunks
993 *
994 * C) When the time comes for the sender to transmit,
995 * before sending new DATA chunks, the sender MUST
996 * first transmit any outstanding DATA chunks which
997 * are marked for retransmission (limited by the
998 * current cwnd).
999 */
1000 if (!list_empty(&q->retransmit)) {
1001 if (asoc->peer.retran_path->state == SCTP_UNCONFIRMED)
1002 goto sctp_flush_out;
1003 if (transport == asoc->peer.retran_path)
1004 goto retran;
1005
1006 /* Switch transports & prepare the packet. */
1007
1008 transport = asoc->peer.retran_path;
1009 1056
1010 if (list_empty(&transport->send_ready)) { 1057 default:
1011 list_add_tail(&transport->send_ready, 1058 /* Do nothing. */
1012 &transport_list); 1059 return;
1013 } 1060 }
1014 1061
1015 packet = &transport->packet; 1062 /* RFC 2960 6.1 Transmission of DATA Chunks
1016 sctp_packet_config(packet, vtag, 1063 *
1017 asoc->peer.ecn_capable); 1064 * C) When the time comes for the sender to transmit,
1018 retran: 1065 * before sending new DATA chunks, the sender MUST
1019 error = sctp_outq_flush_rtx(q, packet, 1066 * first transmit any outstanding DATA chunks which
1020 rtx_timeout, &start_timer); 1067 * are marked for retransmission (limited by the
1021 if (error < 0) 1068 * current cwnd).
1022 asoc->base.sk->sk_err = -error; 1069 */
1070 if (!list_empty(&ctx->q->retransmit) &&
1071 !sctp_outq_flush_rtx(ctx, rtx_timeout))
1072 return;
1023 1073
1024 if (start_timer) { 1074 /* Apply Max.Burst limitation to the current transport in
1025 sctp_transport_reset_t3_rtx(transport); 1075 * case it will be used for new data. We are going to
1026 transport->last_time_sent = jiffies; 1076 * rest it before we return, but we want to apply the limit
1027 } 1077 * to the currently queued data.
1078 */
1079 if (ctx->transport)
1080 sctp_transport_burst_limited(ctx->transport);
1028 1081
1029 /* This can happen on COOKIE-ECHO resend. Only 1082 /* Finally, transmit new packets. */
1030 * one chunk can get bundled with a COOKIE-ECHO. 1083 while ((chunk = sctp_outq_dequeue_data(ctx->q)) != NULL) {
1031 */ 1084 __u32 sid = ntohs(chunk->subh.data_hdr->stream);
1032 if (packet->has_cookie_echo)
1033 goto sctp_flush_out;
1034 1085
1035 /* Don't send new data if there is still data 1086 /* Has this chunk expired? */
1036 * waiting to retransmit. 1087 if (sctp_chunk_abandoned(chunk)) {
1037 */ 1088 sctp_sched_dequeue_done(ctx->q, chunk);
1038 if (!list_empty(&q->retransmit)) 1089 sctp_chunk_fail(chunk, 0);
1039 goto sctp_flush_out; 1090 sctp_chunk_free(chunk);
1091 continue;
1040 } 1092 }
1041 1093
1042 /* Apply Max.Burst limitation to the current transport in 1094 if (ctx->asoc->stream.out[sid].state == SCTP_STREAM_CLOSED) {
1043 * case it will be used for new data. We are going to 1095 sctp_outq_head_data(ctx->q, chunk);
1044 * rest it before we return, but we want to apply the limit 1096 break;
1045 * to the currently queued data. 1097 }
1046 */
1047 if (transport)
1048 sctp_transport_burst_limited(transport);
1049
1050 /* Finally, transmit new packets. */
1051 while ((chunk = sctp_outq_dequeue_data(q)) != NULL) {
1052 __u32 sid = ntohs(chunk->subh.data_hdr->stream);
1053
1054 /* Has this chunk expired? */
1055 if (sctp_chunk_abandoned(chunk)) {
1056 sctp_sched_dequeue_done(q, chunk);
1057 sctp_chunk_fail(chunk, 0);
1058 sctp_chunk_free(chunk);
1059 continue;
1060 }
1061 1098
1062 if (asoc->stream.out[sid].state == SCTP_STREAM_CLOSED) { 1099 sctp_outq_select_transport(ctx, chunk);
1063 sctp_outq_head_data(q, chunk);
1064 goto sctp_flush_out;
1065 }
1066 1100
1067 /* If there is a specified transport, use it. 1101 pr_debug("%s: outq:%p, chunk:%p[%s], tx-tsn:0x%x skb->head:%p skb->users:%d\n",
1068 * Otherwise, we want to use the active path. 1102 __func__, ctx->q, chunk, chunk && chunk->chunk_hdr ?
1103 sctp_cname(SCTP_ST_CHUNK(chunk->chunk_hdr->type)) :
1104 "illegal chunk", ntohl(chunk->subh.data_hdr->tsn),
1105 chunk->skb ? chunk->skb->head : NULL, chunk->skb ?
1106 refcount_read(&chunk->skb->users) : -1);
1107
1108 /* Add the chunk to the packet. */
1109 status = sctp_packet_transmit_chunk(ctx->packet, chunk, 0,
1110 ctx->gfp);
1111 if (status != SCTP_XMIT_OK) {
1112 /* We could not append this chunk, so put
1113 * the chunk back on the output queue.
1069 */ 1114 */
1070 new_transport = chunk->transport; 1115 pr_debug("%s: could not transmit tsn:0x%x, status:%d\n",
1071 if (!new_transport || 1116 __func__, ntohl(chunk->subh.data_hdr->tsn),
1072 ((new_transport->state == SCTP_INACTIVE) || 1117 status);
1073 (new_transport->state == SCTP_UNCONFIRMED) ||
1074 (new_transport->state == SCTP_PF)))
1075 new_transport = asoc->peer.active_path;
1076 if (new_transport->state == SCTP_UNCONFIRMED) {
1077 WARN_ONCE(1, "Attempt to send packet on unconfirmed path.");
1078 sctp_sched_dequeue_done(q, chunk);
1079 sctp_chunk_fail(chunk, 0);
1080 sctp_chunk_free(chunk);
1081 continue;
1082 }
1083
1084 /* Change packets if necessary. */
1085 if (new_transport != transport) {
1086 transport = new_transport;
1087 1118
1088 /* Schedule to have this transport's 1119 sctp_outq_head_data(ctx->q, chunk);
1089 * packet flushed. 1120 break;
1090 */ 1121 }
1091 if (list_empty(&transport->send_ready)) {
1092 list_add_tail(&transport->send_ready,
1093 &transport_list);
1094 }
1095
1096 packet = &transport->packet;
1097 sctp_packet_config(packet, vtag,
1098 asoc->peer.ecn_capable);
1099 /* We've switched transports, so apply the
1100 * Burst limit to the new transport.
1101 */
1102 sctp_transport_burst_limited(transport);
1103 }
1104
1105 pr_debug("%s: outq:%p, chunk:%p[%s], tx-tsn:0x%x skb->head:%p "
1106 "skb->users:%d\n",
1107 __func__, q, chunk, chunk && chunk->chunk_hdr ?
1108 sctp_cname(SCTP_ST_CHUNK(chunk->chunk_hdr->type)) :
1109 "illegal chunk", ntohl(chunk->subh.data_hdr->tsn),
1110 chunk->skb ? chunk->skb->head : NULL, chunk->skb ?
1111 refcount_read(&chunk->skb->users) : -1);
1112
1113 /* Add the chunk to the packet. */
1114 status = sctp_packet_transmit_chunk(packet, chunk, 0, gfp);
1115
1116 switch (status) {
1117 case SCTP_XMIT_PMTU_FULL:
1118 case SCTP_XMIT_RWND_FULL:
1119 case SCTP_XMIT_DELAY:
1120 /* We could not append this chunk, so put
1121 * the chunk back on the output queue.
1122 */
1123 pr_debug("%s: could not transmit tsn:0x%x, status:%d\n",
1124 __func__, ntohl(chunk->subh.data_hdr->tsn),
1125 status);
1126
1127 sctp_outq_head_data(q, chunk);
1128 goto sctp_flush_out;
1129
1130 case SCTP_XMIT_OK:
1131 /* The sender is in the SHUTDOWN-PENDING state,
1132 * The sender MAY set the I-bit in the DATA
1133 * chunk header.
1134 */
1135 if (asoc->state == SCTP_STATE_SHUTDOWN_PENDING)
1136 chunk->chunk_hdr->flags |= SCTP_DATA_SACK_IMM;
1137 if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED)
1138 asoc->stats.ouodchunks++;
1139 else
1140 asoc->stats.oodchunks++;
1141
1142 /* Only now it's safe to consider this
1143 * chunk as sent, sched-wise.
1144 */
1145 sctp_sched_dequeue_done(q, chunk);
1146
1147 break;
1148 1122
1149 default: 1123 /* The sender is in the SHUTDOWN-PENDING state,
1150 BUG(); 1124 * The sender MAY set the I-bit in the DATA
1151 } 1125 * chunk header.
1126 */
1127 if (ctx->asoc->state == SCTP_STATE_SHUTDOWN_PENDING)
1128 chunk->chunk_hdr->flags |= SCTP_DATA_SACK_IMM;
1129 if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED)
1130 ctx->asoc->stats.ouodchunks++;
1131 else
1132 ctx->asoc->stats.oodchunks++;
1152 1133
1153 /* BUG: We assume that the sctp_packet_transmit() 1134 /* Only now it's safe to consider this
1154 * call below will succeed all the time and add the 1135 * chunk as sent, sched-wise.
1155 * chunk to the transmitted list and restart the 1136 */
1156 * timers. 1137 sctp_sched_dequeue_done(ctx->q, chunk);
1157 * It is possible that the call can fail under OOM
1158 * conditions.
1159 *
1160 * Is this really a problem? Won't this behave
1161 * like a lost TSN?
1162 */
1163 list_add_tail(&chunk->transmitted_list,
1164 &transport->transmitted);
1165 1138
1166 sctp_transport_reset_t3_rtx(transport); 1139 list_add_tail(&chunk->transmitted_list,
1167 transport->last_time_sent = jiffies; 1140 &ctx->transport->transmitted);
1168 1141
1169 /* Only let one DATA chunk get bundled with a 1142 sctp_transport_reset_t3_rtx(ctx->transport);
1170 * COOKIE-ECHO chunk. 1143 ctx->transport->last_time_sent = jiffies;
1171 */
1172 if (packet->has_cookie_echo)
1173 goto sctp_flush_out;
1174 }
1175 break;
1176 1144
1177 default: 1145 /* Only let one DATA chunk get bundled with a
1178 /* Do nothing. */ 1146 * COOKIE-ECHO chunk.
1179 break; 1147 */
1148 if (ctx->packet->has_cookie_echo)
1149 break;
1180 } 1150 }
1151}
1181 1152
1182sctp_flush_out: 1153static void sctp_outq_flush_transports(struct sctp_flush_ctx *ctx)
1154{
1155 struct list_head *ltransport;
1156 struct sctp_packet *packet;
1157 struct sctp_transport *t;
1158 int error = 0;
1183 1159
1184 /* Before returning, examine all the transports touched in 1160 while ((ltransport = sctp_list_dequeue(&ctx->transport_list)) != NULL) {
1185 * this call. Right now, we bluntly force clear all the 1161 t = list_entry(ltransport, struct sctp_transport, send_ready);
1186 * transports. Things might change after we implement Nagle.
1187 * But such an examination is still required.
1188 *
1189 * --xguo
1190 */
1191 while ((ltransport = sctp_list_dequeue(&transport_list)) != NULL) {
1192 struct sctp_transport *t = list_entry(ltransport,
1193 struct sctp_transport,
1194 send_ready);
1195 packet = &t->packet; 1162 packet = &t->packet;
1196 if (!sctp_packet_empty(packet)) { 1163 if (!sctp_packet_empty(packet)) {
1197 error = sctp_packet_transmit(packet, gfp); 1164 error = sctp_packet_transmit(packet, ctx->gfp);
1198 if (error < 0) 1165 if (error < 0)
1199 asoc->base.sk->sk_err = -error; 1166 ctx->q->asoc->base.sk->sk_err = -error;
1200 } 1167 }
1201 1168
1202 /* Clear the burst limited state, if any */ 1169 /* Clear the burst limited state, if any */
@@ -1204,6 +1171,47 @@ sctp_flush_out:
1204 } 1171 }
1205} 1172}
1206 1173
1174/* Try to flush an outqueue.
1175 *
1176 * Description: Send everything in q which we legally can, subject to
1177 * congestion limitations.
1178 * * Note: This function can be called from multiple contexts so appropriate
1179 * locking concerns must be made. Today we use the sock lock to protect
1180 * this function.
1181 */
1182
1183static void sctp_outq_flush(struct sctp_outq *q, int rtx_timeout, gfp_t gfp)
1184{
1185 struct sctp_flush_ctx ctx = {
1186 .q = q,
1187 .transport = NULL,
1188 .transport_list = LIST_HEAD_INIT(ctx.transport_list),
1189 .asoc = q->asoc,
1190 .packet = NULL,
1191 .gfp = gfp,
1192 };
1193
1194 /* 6.10 Bundling
1195 * ...
1196 * When bundling control chunks with DATA chunks, an
1197 * endpoint MUST place control chunks first in the outbound
1198 * SCTP packet. The transmitter MUST transmit DATA chunks
1199 * within a SCTP packet in increasing order of TSN.
1200 * ...
1201 */
1202
1203 sctp_outq_flush_ctrl(&ctx);
1204
1205 if (q->asoc->src_out_of_asoc_ok)
1206 goto sctp_flush_out;
1207
1208 sctp_outq_flush_data(&ctx, rtx_timeout);
1209
1210sctp_flush_out:
1211
1212 sctp_outq_flush_transports(&ctx);
1213}
1214
1207/* Update unack_data based on the incoming SACK chunk */ 1215/* Update unack_data based on the incoming SACK chunk */
1208static void sctp_sack_update_unack_data(struct sctp_association *assoc, 1216static void sctp_sack_update_unack_data(struct sctp_association *assoc,
1209 struct sctp_sackhdr *sack) 1217 struct sctp_sackhdr *sack)
@@ -1457,7 +1465,7 @@ static void sctp_check_transmitted(struct sctp_outq *q,
1457 * the outstanding bytes for this chunk, so only 1465 * the outstanding bytes for this chunk, so only
1458 * count bytes associated with a transport. 1466 * count bytes associated with a transport.
1459 */ 1467 */
1460 if (transport) { 1468 if (transport && !tchunk->tsn_gap_acked) {
1461 /* If this chunk is being used for RTT 1469 /* If this chunk is being used for RTT
1462 * measurement, calculate the RTT and update 1470 * measurement, calculate the RTT and update
1463 * the RTO using this value. 1471 * the RTO using this value.
@@ -1469,14 +1477,34 @@ static void sctp_check_transmitted(struct sctp_outq *q,
1469 * first instance of the packet or a later 1477 * first instance of the packet or a later
1470 * instance). 1478 * instance).
1471 */ 1479 */
1472 if (!tchunk->tsn_gap_acked && 1480 if (!sctp_chunk_retransmitted(tchunk) &&
1473 !sctp_chunk_retransmitted(tchunk) &&
1474 tchunk->rtt_in_progress) { 1481 tchunk->rtt_in_progress) {
1475 tchunk->rtt_in_progress = 0; 1482 tchunk->rtt_in_progress = 0;
1476 rtt = jiffies - tchunk->sent_at; 1483 rtt = jiffies - tchunk->sent_at;
1477 sctp_transport_update_rto(transport, 1484 sctp_transport_update_rto(transport,
1478 rtt); 1485 rtt);
1479 } 1486 }
1487
1488 if (TSN_lte(tsn, sack_ctsn)) {
1489 /*
1490 * SFR-CACC algorithm:
1491 * 2) If the SACK contains gap acks
1492 * and the flag CHANGEOVER_ACTIVE is
1493 * set the receiver of the SACK MUST
1494 * take the following action:
1495 *
1496 * B) For each TSN t being acked that
1497 * has not been acked in any SACK so
1498 * far, set cacc_saw_newack to 1 for
1499 * the destination that the TSN was
1500 * sent to.
1501 */
1502 if (sack->num_gap_ack_blocks &&
1503 q->asoc->peer.primary_path->cacc.
1504 changeover_active)
1505 transport->cacc.cacc_saw_newack
1506 = 1;
1507 }
1480 } 1508 }
1481 1509
1482 /* If the chunk hasn't been marked as ACKED, 1510 /* If the chunk hasn't been marked as ACKED,
@@ -1508,28 +1536,6 @@ static void sctp_check_transmitted(struct sctp_outq *q,
1508 restart_timer = 1; 1536 restart_timer = 1;
1509 forward_progress = true; 1537 forward_progress = true;
1510 1538
1511 if (!tchunk->tsn_gap_acked) {
1512 /*
1513 * SFR-CACC algorithm:
1514 * 2) If the SACK contains gap acks
1515 * and the flag CHANGEOVER_ACTIVE is
1516 * set the receiver of the SACK MUST
1517 * take the following action:
1518 *
1519 * B) For each TSN t being acked that
1520 * has not been acked in any SACK so
1521 * far, set cacc_saw_newack to 1 for
1522 * the destination that the TSN was
1523 * sent to.
1524 */
1525 if (transport &&
1526 sack->num_gap_ack_blocks &&
1527 q->asoc->peer.primary_path->cacc.
1528 changeover_active)
1529 transport->cacc.cacc_saw_newack
1530 = 1;
1531 }
1532
1533 list_add_tail(&tchunk->transmitted_list, 1539 list_add_tail(&tchunk->transmitted_list,
1534 &q->sacked); 1540 &q->sacked);
1535 } else { 1541 } else {
@@ -1756,7 +1762,7 @@ static int sctp_acked(struct sctp_sackhdr *sack, __u32 tsn)
1756 if (TSN_lte(tsn, ctsn)) 1762 if (TSN_lte(tsn, ctsn))
1757 goto pass; 1763 goto pass;
1758 1764
1759 /* 3.3.4 Selective Acknowledgement (SACK) (3): 1765 /* 3.3.4 Selective Acknowledgment (SACK) (3):
1760 * 1766 *
1761 * Gap Ack Blocks: 1767 * Gap Ack Blocks:
1762 * These fields contain the Gap Ack Blocks. They are repeated 1768 * These fields contain the Gap Ack Blocks. They are repeated