sctp_output.c revision 5dd46ab5742d7db1cbb08dec7b64fa14930c02f7
f8d2de6bd2421da1926f3daa456d161670decdf7jchu/*
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * CDDL HEADER START
f8d2de6bd2421da1926f3daa456d161670decdf7jchu *
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * The contents of this file are subject to the terms of the
0168954460bd77d83497a4a6aa9c3f34c55dba25jchu * Common Development and Distribution License (the "License").
0168954460bd77d83497a4a6aa9c3f34c55dba25jchu * You may not use this file except in compliance with the License.
f8d2de6bd2421da1926f3daa456d161670decdf7jchu *
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * or http://www.opensolaris.org/os/licensing.
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * See the License for the specific language governing permissions
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * and limitations under the License.
f8d2de6bd2421da1926f3daa456d161670decdf7jchu *
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * When distributing Covered Code, include this CDDL HEADER in each
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * If applicable, add the following below this CDDL HEADER, with the
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * fields enclosed by brackets "[]" replaced with your own identifying
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * information: Portions Copyright [yyyy] [name of copyright owner]
f8d2de6bd2421da1926f3daa456d161670decdf7jchu *
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * CDDL HEADER END
f8d2de6bd2421da1926f3daa456d161670decdf7jchu */
07d06da50d310a325b457d6330165aebab1e0064Surya Prakki
f8d2de6bd2421da1926f3daa456d161670decdf7jchu/*
5613d828c3413db2a71d47fbbc385a3f7a23d908Krishna Elango * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
f8d2de6bd2421da1926f3daa456d161670decdf7jchu */
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchu#include <sys/types.h>
f8d2de6bd2421da1926f3daa456d161670decdf7jchu#include <sys/systm.h>
f8d2de6bd2421da1926f3daa456d161670decdf7jchu#include <sys/stream.h>
f8d2de6bd2421da1926f3daa456d161670decdf7jchu#include <sys/cmn_err.h>
f8d2de6bd2421da1926f3daa456d161670decdf7jchu#define _SUN_TPI_VERSION 2
f8d2de6bd2421da1926f3daa456d161670decdf7jchu#include <sys/tihdr.h>
f8d2de6bd2421da1926f3daa456d161670decdf7jchu#include <sys/socket.h>
f8d2de6bd2421da1926f3daa456d161670decdf7jchu#include <sys/stropts.h>
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae#include <sys/strsun.h>
f8d2de6bd2421da1926f3daa456d161670decdf7jchu#include <sys/strsubr.h>
f8d2de6bd2421da1926f3daa456d161670decdf7jchu#include <sys/socketvar.h>
f8d2de6bd2421da1926f3daa456d161670decdf7jchu#include <inet/common.h>
f8d2de6bd2421da1926f3daa456d161670decdf7jchu#include <inet/mi.h>
f8d2de6bd2421da1926f3daa456d161670decdf7jchu#include <inet/ip.h>
f8d2de6bd2421da1926f3daa456d161670decdf7jchu#include <inet/ip_ire.h>
f8d2de6bd2421da1926f3daa456d161670decdf7jchu#include <inet/ip6.h>
f8d2de6bd2421da1926f3daa456d161670decdf7jchu#include <inet/sctp_ip.h>
25cf1a301a396c38e8adf52c15f537b80d2483f7jl#include <inet/ipclassifier.h>
25cf1a301a396c38e8adf52c15f537b80d2483f7jl
f8d2de6bd2421da1926f3daa456d161670decdf7jchu/*
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * PR-SCTP comments.
f8d2de6bd2421da1926f3daa456d161670decdf7jchu *
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * A message can expire before it gets to the transmit list (i.e. it is still
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * in the unsent list - unchunked), after it gets to the transmit list, but
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * before transmission has actually started, or after transmission has begun.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Accordingly, we check for the status of a message in sctp_chunkify() when
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * the message is being transferred from the unsent list to the transmit list;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * in sctp_get_msg_to_send(), when we get the next chunk from the transmit
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * list and in sctp_rexmit() when we get the next chunk to be (re)transmitted.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * When we nuke a message in sctp_chunkify(), all we need to do is take it
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * out of the unsent list and update sctp_unsent; when a message is deemed
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * timed-out in sctp_get_msg_to_send() we can just take it out of the transmit
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * list, update sctp_unsent IFF transmission for the message has not yet begun
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * (i.e. !SCTP_CHUNK_ISSENT(meta->b_cont)). However, if transmission for the
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * message has started, then we cannot just take it out of the list, we need
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * to send Forward TSN chunk to the peer so that the peer can clear its
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * fragment list for this message. However, we cannot just send the Forward
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * TSN in sctp_get_msg_to_send() because there might be unacked chunks for
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * messages preceeding this abandoned message. So, we send a Forward TSN
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * IFF all messages prior to this abandoned message has been SACKd, if not
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * we defer sending the Forward TSN to sctp_cumack(), which will check for
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * this condition and send the Forward TSN via sctp_check_abandoned_msg(). In
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * sctp_rexmit() when we check for retransmissions, we need to determine if
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * the advanced peer ack point can be moved ahead, and if so, send a Forward
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * TSN to the peer instead of retransmitting the chunk. Note that when
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * we send a Forward TSN for a message, there may be yet unsent chunks for
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * this message; we need to mark all such chunks as abandoned, so that
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * sctp_cumack() can take the message out of the transmit list, additionally
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * sctp_unsent need to be adjusted. Whenever sctp_unsent is updated (i.e.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * decremented when a message/chunk is deemed abandoned), sockfs needs to
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * be notified so that it can adjust its idea of the queued message.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl
25cf1a301a396c38e8adf52c15f537b80d2483f7jl#include "sctp_impl.h"
25cf1a301a396c38e8adf52c15f537b80d2483f7jl
25cf1a301a396c38e8adf52c15f537b80d2483f7jlstatic struct kmem_cache *sctp_kmem_ftsn_set_cache;
25cf1a301a396c38e8adf52c15f537b80d2483f7jlstatic mblk_t *sctp_chunkify(sctp_t *, int, int, int);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl
25cf1a301a396c38e8adf52c15f537b80d2483f7jl#ifdef DEBUG
25cf1a301a396c38e8adf52c15f537b80d2483f7jlstatic boolean_t sctp_verify_chain(mblk_t *, mblk_t *);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl#endif
25cf1a301a396c38e8adf52c15f537b80d2483f7jl
25cf1a301a396c38e8adf52c15f537b80d2483f7jl/*
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Called to allocate a header mblk when sending data to SCTP.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Data will follow in b_cont of this mblk.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl */
25cf1a301a396c38e8adf52c15f537b80d2483f7jlmblk_t *
25cf1a301a396c38e8adf52c15f537b80d2483f7jlsctp_alloc_hdr(const char *name, int nlen, const char *control, int clen,
25cf1a301a396c38e8adf52c15f537b80d2483f7jl int flags)
25cf1a301a396c38e8adf52c15f537b80d2483f7jl{
25cf1a301a396c38e8adf52c15f537b80d2483f7jl mblk_t *mp;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl struct T_unitdata_req *tudr;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl size_t size;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl int error;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl
25cf1a301a396c38e8adf52c15f537b80d2483f7jl size = sizeof (*tudr) + _TPI_ALIGN_TOPT(nlen) + clen;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl size = MAX(size, sizeof (sctp_msg_hdr_t));
25cf1a301a396c38e8adf52c15f537b80d2483f7jl if (flags & SCTP_CAN_BLOCK) {
25cf1a301a396c38e8adf52c15f537b80d2483f7jl mp = allocb_wait(size, BPRI_MED, 0, &error);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl } else {
25cf1a301a396c38e8adf52c15f537b80d2483f7jl mp = allocb(size, BPRI_MED);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl }
25cf1a301a396c38e8adf52c15f537b80d2483f7jl if (mp) {
25cf1a301a396c38e8adf52c15f537b80d2483f7jl tudr = (struct T_unitdata_req *)mp->b_rptr;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl tudr->PRIM_type = T_UNITDATA_REQ;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl tudr->DEST_length = nlen;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl tudr->DEST_offset = sizeof (*tudr);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl tudr->OPT_length = clen;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl tudr->OPT_offset = (t_scalar_t)(sizeof (*tudr) +
25cf1a301a396c38e8adf52c15f537b80d2483f7jl _TPI_ALIGN_TOPT(nlen));
25cf1a301a396c38e8adf52c15f537b80d2483f7jl if (nlen > 0)
25cf1a301a396c38e8adf52c15f537b80d2483f7jl bcopy(name, tudr + 1, nlen);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl if (clen > 0)
f8d2de6bd2421da1926f3daa456d161670decdf7jchu bcopy(control, (char *)tudr + tudr->OPT_offset, clen);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mp->b_wptr += (tudr ->OPT_offset + clen);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mp->b_datap->db_type = M_PROTO;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu return (mp);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu}
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchu/*ARGSUSED2*/
f8d2de6bd2421da1926f3daa456d161670decdf7jchuint
8c3348818856b8366c07db7214dd7746a0aa3a07jchusctp_sendmsg(sctp_t *sctp, mblk_t *mp, int flags)
8c3348818856b8366c07db7214dd7746a0aa3a07jchu{
8c3348818856b8366c07db7214dd7746a0aa3a07jchu sctp_faddr_t *fp = NULL;
8c3348818856b8366c07db7214dd7746a0aa3a07jchu struct T_unitdata_req *tudr;
8c3348818856b8366c07db7214dd7746a0aa3a07jchu int error = 0;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mblk_t *mproto = mp;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl in6_addr_t *addr;
bf8fc2340620695a402331e5da7c7db43264174det in6_addr_t tmpaddr;
bf8fc2340620695a402331e5da7c7db43264174det uint16_t sid = sctp->sctp_def_stream;
bf8fc2340620695a402331e5da7c7db43264174det uint32_t ppid = sctp->sctp_def_ppid;
bf8fc2340620695a402331e5da7c7db43264174det uint32_t context = sctp->sctp_def_context;
bf8fc2340620695a402331e5da7c7db43264174det uint16_t msg_flags = sctp->sctp_def_flags;
bf8fc2340620695a402331e5da7c7db43264174det sctp_msg_hdr_t *sctp_msg_hdr;
bf8fc2340620695a402331e5da7c7db43264174det uint32_t msg_len = 0;
bf8fc2340620695a402331e5da7c7db43264174det uint32_t timetolive = sctp->sctp_def_timetolive;
bf8fc2340620695a402331e5da7c7db43264174det conn_t *connp = sctp->sctp_connp;
bf8fc2340620695a402331e5da7c7db43264174det
f8d2de6bd2421da1926f3daa456d161670decdf7jchu ASSERT(DB_TYPE(mproto) == M_PROTO);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mp = mp->b_cont;
bf8fc2340620695a402331e5da7c7db43264174det ASSERT(mp == NULL || DB_TYPE(mp) == M_DATA);
bf8fc2340620695a402331e5da7c7db43264174det
bf8fc2340620695a402331e5da7c7db43264174det tudr = (struct T_unitdata_req *)mproto->b_rptr;
bf8fc2340620695a402331e5da7c7db43264174det ASSERT(tudr->PRIM_type == T_UNITDATA_REQ);
bf8fc2340620695a402331e5da7c7db43264174det
bf8fc2340620695a402331e5da7c7db43264174det /* Get destination address, if specified */
bf8fc2340620695a402331e5da7c7db43264174det if (tudr->DEST_length > 0) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sin_t *sin;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sin6_t *sin6;
bf8fc2340620695a402331e5da7c7db43264174det
bf8fc2340620695a402331e5da7c7db43264174det sin = (struct sockaddr_in *)
bf8fc2340620695a402331e5da7c7db43264174det (mproto->b_rptr + tudr->DEST_offset);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu switch (sin->sin_family) {
bf8fc2340620695a402331e5da7c7db43264174det case AF_INET:
bf8fc2340620695a402331e5da7c7db43264174det if (tudr->DEST_length < sizeof (*sin)) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu return (EINVAL);
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz }
bf8fc2340620695a402331e5da7c7db43264174det IN6_IPADDR_TO_V4MAPPED(sin->sin_addr.s_addr, &tmpaddr);
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz addr = &tmpaddr;
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz break;
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz case AF_INET6:
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz if (tudr->DEST_length < sizeof (*sin6)) {
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz return (EINVAL);
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz }
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz sin6 = (struct sockaddr_in6 *)
f8d2de6bd2421da1926f3daa456d161670decdf7jchu (mproto->b_rptr + tudr->DEST_offset);
bf8fc2340620695a402331e5da7c7db43264174det addr = &sin6->sin6_addr;
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz break;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu default:
bf8fc2340620695a402331e5da7c7db43264174det return (EAFNOSUPPORT);
bf8fc2340620695a402331e5da7c7db43264174det }
bf8fc2340620695a402331e5da7c7db43264174det fp = sctp_lookup_faddr(sctp, addr);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (fp == NULL) {
bf8fc2340620695a402331e5da7c7db43264174det return (EINVAL);
bf8fc2340620695a402331e5da7c7db43264174det }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu /* Ancillary Data? */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl if (tudr->OPT_length > 0) {
25cf1a301a396c38e8adf52c15f537b80d2483f7jl struct cmsghdr *cmsg;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl char *cend;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl struct sctp_sndrcvinfo *sndrcv;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl
25cf1a301a396c38e8adf52c15f537b80d2483f7jl cmsg = (struct cmsghdr *)(mproto->b_rptr + tudr->OPT_offset);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl cend = ((char *)cmsg + tudr->OPT_length);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl ASSERT(cend <= (char *)mproto->b_wptr);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl
25cf1a301a396c38e8adf52c15f537b80d2483f7jl for (;;) {
25cf1a301a396c38e8adf52c15f537b80d2483f7jl if ((char *)(cmsg + 1) > cend ||
25cf1a301a396c38e8adf52c15f537b80d2483f7jl ((char *)cmsg + cmsg->cmsg_len) > cend) {
25cf1a301a396c38e8adf52c15f537b80d2483f7jl break;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl }
25cf1a301a396c38e8adf52c15f537b80d2483f7jl if ((cmsg->cmsg_level == IPPROTO_SCTP) &&
25cf1a301a396c38e8adf52c15f537b80d2483f7jl (cmsg->cmsg_type == SCTP_SNDRCV)) {
25cf1a301a396c38e8adf52c15f537b80d2483f7jl if (cmsg->cmsg_len <
25cf1a301a396c38e8adf52c15f537b80d2483f7jl (sizeof (*sndrcv) + sizeof (*cmsg))) {
25cf1a301a396c38e8adf52c15f537b80d2483f7jl return (EINVAL);
bf8fc2340620695a402331e5da7c7db43264174det }
bf8fc2340620695a402331e5da7c7db43264174det sndrcv = (struct sctp_sndrcvinfo *)(cmsg + 1);
bf8fc2340620695a402331e5da7c7db43264174det sid = sndrcv->sinfo_stream;
bf8fc2340620695a402331e5da7c7db43264174det msg_flags = sndrcv->sinfo_flags;
bf8fc2340620695a402331e5da7c7db43264174det ppid = sndrcv->sinfo_ppid;
bf8fc2340620695a402331e5da7c7db43264174det context = sndrcv->sinfo_context;
bf8fc2340620695a402331e5da7c7db43264174det timetolive = sndrcv->sinfo_timetolive;
bf8fc2340620695a402331e5da7c7db43264174det break;
bf8fc2340620695a402331e5da7c7db43264174det }
bf8fc2340620695a402331e5da7c7db43264174det if (cmsg->cmsg_len > 0)
bf8fc2340620695a402331e5da7c7db43264174det cmsg = CMSG_NEXT(cmsg);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl else
25cf1a301a396c38e8adf52c15f537b80d2483f7jl break;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl }
25cf1a301a396c38e8adf52c15f537b80d2483f7jl }
25cf1a301a396c38e8adf52c15f537b80d2483f7jl if (msg_flags & MSG_ABORT) {
25cf1a301a396c38e8adf52c15f537b80d2483f7jl if (mp && mp->b_cont) {
25cf1a301a396c38e8adf52c15f537b80d2483f7jl mblk_t *pump = msgpullup(mp, -1);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl if (!pump) {
25cf1a301a396c38e8adf52c15f537b80d2483f7jl return (ENOMEM);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl }
25cf1a301a396c38e8adf52c15f537b80d2483f7jl freemsg(mp);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl mp = pump;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl mproto->b_cont = mp;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu RUN_SCTP(sctp);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp_user_abort(sctp, mp);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu freemsg(mproto);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu goto done2;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (mp == NULL)
f8d2de6bd2421da1926f3daa456d161670decdf7jchu goto done;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
8c3348818856b8366c07db7214dd7746a0aa3a07jchu RUN_SCTP(sctp);
8c3348818856b8366c07db7214dd7746a0aa3a07jchu
8c3348818856b8366c07db7214dd7746a0aa3a07jchu /* Reject any new data requests if we are shutting down */
8c3348818856b8366c07db7214dd7746a0aa3a07jchu if (sctp->sctp_state > SCTPS_ESTABLISHED ||
8c3348818856b8366c07db7214dd7746a0aa3a07jchu (sctp->sctp_connp->conn_state_flags & CONN_CLOSING)) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu error = EPIPE;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu goto unlock_done;
bf8fc2340620695a402331e5da7c7db43264174det }
bf8fc2340620695a402331e5da7c7db43264174det
bf8fc2340620695a402331e5da7c7db43264174det /* Re-use the mproto to store relevant info. */
bf8fc2340620695a402331e5da7c7db43264174det ASSERT(MBLKSIZE(mproto) >= sizeof (*sctp_msg_hdr));
bf8fc2340620695a402331e5da7c7db43264174det
bf8fc2340620695a402331e5da7c7db43264174det mproto->b_rptr = mproto->b_datap->db_base;
bf8fc2340620695a402331e5da7c7db43264174det mproto->b_wptr = mproto->b_rptr + sizeof (*sctp_msg_hdr);
bf8fc2340620695a402331e5da7c7db43264174det
bf8fc2340620695a402331e5da7c7db43264174det sctp_msg_hdr = (sctp_msg_hdr_t *)mproto->b_rptr;
bf8fc2340620695a402331e5da7c7db43264174det bzero(sctp_msg_hdr, sizeof (*sctp_msg_hdr));
bf8fc2340620695a402331e5da7c7db43264174det sctp_msg_hdr->smh_context = context;
6e8a7b447bf994515a78a52e5b06ed1eec552e9ejchu sctp_msg_hdr->smh_sid = sid;
bf8fc2340620695a402331e5da7c7db43264174det sctp_msg_hdr->smh_ppid = ppid;
bf8fc2340620695a402331e5da7c7db43264174det sctp_msg_hdr->smh_flags = msg_flags;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp_msg_hdr->smh_ttl = MSEC_TO_TICK(timetolive);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp_msg_hdr->smh_tob = ddi_get_lbolt64();
f8d2de6bd2421da1926f3daa456d161670decdf7jchu for (; mp != NULL; mp = mp->b_cont)
f8d2de6bd2421da1926f3daa456d161670decdf7jchu msg_len += MBLKL(mp);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp_msg_hdr->smh_msglen = msg_len;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchu /* User requested specific destination */
f8d2de6bd2421da1926f3daa456d161670decdf7jchu SCTP_SET_CHUNK_DEST(mproto, fp);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (sctp->sctp_state >= SCTPS_COOKIE_ECHOED &&
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sid >= sctp->sctp_num_ostr) {
8c3348818856b8366c07db7214dd7746a0aa3a07jchu /* Send sendfail event */
8c3348818856b8366c07db7214dd7746a0aa3a07jchu sctp_sendfail_event(sctp, dupmsg(mproto), SCTP_ERR_BAD_SID,
8c3348818856b8366c07db7214dd7746a0aa3a07jchu B_FALSE);
8c3348818856b8366c07db7214dd7746a0aa3a07jchu error = EINVAL;
8c3348818856b8366c07db7214dd7746a0aa3a07jchu goto unlock_done;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
bf8fc2340620695a402331e5da7c7db43264174det /* no data */
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (msg_len == 0) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp_sendfail_event(sctp, dupmsg(mproto),
bf8fc2340620695a402331e5da7c7db43264174det SCTP_ERR_NO_USR_DATA, B_FALSE);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu error = EINVAL;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu goto unlock_done;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
bf8fc2340620695a402331e5da7c7db43264174det
bf8fc2340620695a402331e5da7c7db43264174det /* Add it to the unsent list */
bf8fc2340620695a402331e5da7c7db43264174det if (sctp->sctp_xmit_unsent == NULL) {
bf8fc2340620695a402331e5da7c7db43264174det sctp->sctp_xmit_unsent = sctp->sctp_xmit_unsent_tail = mproto;
bf8fc2340620695a402331e5da7c7db43264174det } else {
bf8fc2340620695a402331e5da7c7db43264174det sctp->sctp_xmit_unsent_tail->b_next = mproto;
bf8fc2340620695a402331e5da7c7db43264174det sctp->sctp_xmit_unsent_tail = mproto;
bf8fc2340620695a402331e5da7c7db43264174det }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp->sctp_unsent += msg_len;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu BUMP_LOCAL(sctp->sctp_msgcount);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu /*
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Notify sockfs if the tx queue is full.
f8d2de6bd2421da1926f3daa456d161670decdf7jchu */
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (SCTP_TXQ_LEN(sctp) >= connp->conn_sndbuf) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp->sctp_txq_full = 1;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp->sctp_ulp_xmitted(sctp->sctp_ulpd, B_TRUE);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (sctp->sctp_state == SCTPS_ESTABLISHED)
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp_output(sctp, UINT_MAX);
f8d2de6bd2421da1926f3daa456d161670decdf7jchudone2:
8c3348818856b8366c07db7214dd7746a0aa3a07jchu WAKE_SCTP(sctp);
8c3348818856b8366c07db7214dd7746a0aa3a07jchu return (0);
8c3348818856b8366c07db7214dd7746a0aa3a07jchuunlock_done:
8c3348818856b8366c07db7214dd7746a0aa3a07jchu WAKE_SCTP(sctp);
8c3348818856b8366c07db7214dd7746a0aa3a07jchudone:
f8d2de6bd2421da1926f3daa456d161670decdf7jchu return (error);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu}
bf8fc2340620695a402331e5da7c7db43264174det
bf8fc2340620695a402331e5da7c7db43264174det/*
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * While there are messages on sctp_xmit_unsent, detach each one. For each:
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * allocate space for the chunk header, fill in the data chunk, and fill in
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * the chunk header. Then append it to sctp_xmit_tail.
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * Return after appending as many bytes as required (bytes_to_send).
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * We also return if we've appended one or more chunks, and find a subsequent
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * unsent message is too big to fit in the segment.
8bc7d88a7ed8565440a3cb4d316b626938433668et */
f8d2de6bd2421da1926f3daa456d161670decdf7jchumblk_t *
f8d2de6bd2421da1926f3daa456d161670decdf7jchusctp_chunkify(sctp_t *sctp, int mss, int firstseg_len, int bytes_to_send)
f8d2de6bd2421da1926f3daa456d161670decdf7jchu{
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mblk_t *mp;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mblk_t *chunk_mp;
8bc7d88a7ed8565440a3cb4d316b626938433668et mblk_t *chunk_head;
8bc7d88a7ed8565440a3cb4d316b626938433668et mblk_t *chunk_hdr;
8bc7d88a7ed8565440a3cb4d316b626938433668et mblk_t *chunk_tail = NULL;
8bc7d88a7ed8565440a3cb4d316b626938433668et int count;
8bc7d88a7ed8565440a3cb4d316b626938433668et int chunksize;
8bc7d88a7ed8565440a3cb4d316b626938433668et sctp_data_hdr_t *sdc;
8bc7d88a7ed8565440a3cb4d316b626938433668et mblk_t *mdblk = sctp->sctp_xmit_unsent;
8bc7d88a7ed8565440a3cb4d316b626938433668et sctp_faddr_t *fp;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl sctp_faddr_t *fp1;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl size_t xtralen;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl sctp_msg_hdr_t *msg_hdr;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl sctp_stack_t *sctps = sctp->sctp_sctps;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl sctp_msg_hdr_t *next_msg_hdr;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl size_t nextlen;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl int remaining_len = mss - firstseg_len;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl
25cf1a301a396c38e8adf52c15f537b80d2483f7jl ASSERT(remaining_len >= 0);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl
197d4443276c4a57677f6e77c3308cfb01d63346danice fp = SCTP_CHUNK_DEST(mdblk);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (fp == NULL)
bf8fc2340620695a402331e5da7c7db43264174det fp = sctp->sctp_current;
8bc7d88a7ed8565440a3cb4d316b626938433668et if (fp->isv4)
8bc7d88a7ed8565440a3cb4d316b626938433668et xtralen = sctp->sctp_hdr_len + sctps->sctps_wroff_xtra +
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sizeof (*sdc);
bf8fc2340620695a402331e5da7c7db43264174det else
25cf1a301a396c38e8adf52c15f537b80d2483f7jl xtralen = sctp->sctp_hdr6_len + sctps->sctps_wroff_xtra +
8bc7d88a7ed8565440a3cb4d316b626938433668et sizeof (*sdc);
8bc7d88a7ed8565440a3cb4d316b626938433668et count = chunksize = remaining_len - sizeof (*sdc);
f8d2de6bd2421da1926f3daa456d161670decdf7jchunextmsg:
bf8fc2340620695a402331e5da7c7db43264174det next_msg_hdr = (sctp_msg_hdr_t *)sctp->sctp_xmit_unsent->b_rptr;
8bc7d88a7ed8565440a3cb4d316b626938433668et nextlen = next_msg_hdr->smh_msglen;
8bc7d88a7ed8565440a3cb4d316b626938433668et /*
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * Will the entire next message fit in the current packet ?
bf8fc2340620695a402331e5da7c7db43264174det * if not, leave it on the unsent list.
8bc7d88a7ed8565440a3cb4d316b626938433668et */
8bc7d88a7ed8565440a3cb4d316b626938433668et if ((firstseg_len != 0) && (nextlen > remaining_len))
8bc7d88a7ed8565440a3cb4d316b626938433668et return (NULL);
8bc7d88a7ed8565440a3cb4d316b626938433668et
8bc7d88a7ed8565440a3cb4d316b626938433668et chunk_mp = mdblk->b_cont;
8bc7d88a7ed8565440a3cb4d316b626938433668et
f8d2de6bd2421da1926f3daa456d161670decdf7jchu /*
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * If this partially chunked, we ignore the next one for now and
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * use the one already present. For the unchunked bits, we use the
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * length of the last chunk.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl */
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (SCTP_IS_MSG_CHUNKED(mdblk)) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu int chunk_len;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchu ASSERT(chunk_mp->b_next != NULL);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mdblk->b_cont = chunk_mp->b_next;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu chunk_mp->b_next = NULL;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu SCTP_MSG_CLEAR_CHUNKED(mdblk);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mp = mdblk->b_cont;
8bc7d88a7ed8565440a3cb4d316b626938433668et while (mp->b_next != NULL)
8bc7d88a7ed8565440a3cb4d316b626938433668et mp = mp->b_next;
8bc7d88a7ed8565440a3cb4d316b626938433668et chunk_len = ntohs(((sctp_data_hdr_t *)mp->b_rptr)->sdh_len);
8bc7d88a7ed8565440a3cb4d316b626938433668et if (fp->sfa_pmss - chunk_len > sizeof (*sdc))
8bc7d88a7ed8565440a3cb4d316b626938433668et count = chunksize = fp->sfa_pmss - chunk_len;
8bc7d88a7ed8565440a3cb4d316b626938433668et else
8bc7d88a7ed8565440a3cb4d316b626938433668et count = chunksize = fp->sfa_pmss;
8bc7d88a7ed8565440a3cb4d316b626938433668et count = chunksize = count - sizeof (*sdc);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu } else {
bf8fc2340620695a402331e5da7c7db43264174det msg_hdr = (sctp_msg_hdr_t *)mdblk->b_rptr;
8bc7d88a7ed8565440a3cb4d316b626938433668et if (SCTP_MSG_TO_BE_ABANDONED(mdblk, msg_hdr, sctp)) {
8bc7d88a7ed8565440a3cb4d316b626938433668et sctp->sctp_xmit_unsent = mdblk->b_next;
8bc7d88a7ed8565440a3cb4d316b626938433668et if (sctp->sctp_xmit_unsent == NULL)
8bc7d88a7ed8565440a3cb4d316b626938433668et sctp->sctp_xmit_unsent_tail = NULL;
8bc7d88a7ed8565440a3cb4d316b626938433668et ASSERT(sctp->sctp_unsent >= msg_hdr->smh_msglen);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp->sctp_unsent -= msg_hdr->smh_msglen;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mdblk->b_next = NULL;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu BUMP_LOCAL(sctp->sctp_prsctpdrop);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu /*
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Update ULP the amount of queued data, which is
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * sent-unack'ed + unsent.
f8d2de6bd2421da1926f3daa456d161670decdf7jchu */
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (!SCTP_IS_DETACHED(sctp))
f8d2de6bd2421da1926f3daa456d161670decdf7jchu SCTP_TXQ_UPDATE(sctp);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp_sendfail_event(sctp, mdblk, 0, B_FALSE);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu goto try_next;
8c3348818856b8366c07db7214dd7746a0aa3a07jchu }
8c3348818856b8366c07db7214dd7746a0aa3a07jchu mdblk->b_cont = NULL;
8c3348818856b8366c07db7214dd7746a0aa3a07jchu }
8c3348818856b8366c07db7214dd7746a0aa3a07jchu msg_hdr = (sctp_msg_hdr_t *)mdblk->b_rptr;
8c3348818856b8366c07db7214dd7746a0aa3a07jchunextchunk:
f8d2de6bd2421da1926f3daa456d161670decdf7jchu chunk_head = chunk_mp;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl chunk_tail = NULL;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl
25cf1a301a396c38e8adf52c15f537b80d2483f7jl /* Skip as many mblk's as we need */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl while (chunk_mp != NULL && ((count - MBLKL(chunk_mp)) >= 0)) {
25cf1a301a396c38e8adf52c15f537b80d2483f7jl count -= MBLKL(chunk_mp);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl chunk_tail = chunk_mp;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl chunk_mp = chunk_mp->b_cont;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl }
25cf1a301a396c38e8adf52c15f537b80d2483f7jl /* Split the chain, if needed */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl if (chunk_mp != NULL) {
25cf1a301a396c38e8adf52c15f537b80d2483f7jl if (count > 0) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mblk_t *split_mp = dupb(chunk_mp);
bf8fc2340620695a402331e5da7c7db43264174det
bf8fc2340620695a402331e5da7c7db43264174det if (split_mp == NULL) {
bf8fc2340620695a402331e5da7c7db43264174det if (mdblk->b_cont == NULL) {
bf8fc2340620695a402331e5da7c7db43264174det mdblk->b_cont = chunk_head;
bf8fc2340620695a402331e5da7c7db43264174det } else {
bf8fc2340620695a402331e5da7c7db43264174det SCTP_MSG_SET_CHUNKED(mdblk);
bf8fc2340620695a402331e5da7c7db43264174det ASSERT(chunk_head->b_next == NULL);
bf8fc2340620695a402331e5da7c7db43264174det chunk_head->b_next = mdblk->b_cont;
bf8fc2340620695a402331e5da7c7db43264174det mdblk->b_cont = chunk_head;
bf8fc2340620695a402331e5da7c7db43264174det }
bf8fc2340620695a402331e5da7c7db43264174det return (sctp->sctp_xmit_tail);
bf8fc2340620695a402331e5da7c7db43264174det }
bf8fc2340620695a402331e5da7c7db43264174det if (chunk_tail != NULL) {
bf8fc2340620695a402331e5da7c7db43264174det chunk_tail->b_cont = split_mp;
bf8fc2340620695a402331e5da7c7db43264174det chunk_tail = chunk_tail->b_cont;
f9721e075222d67dfc8cab85ccca4a17f1eb8325jchu } else {
f9721e075222d67dfc8cab85ccca4a17f1eb8325jchu chunk_head = chunk_tail = split_mp;
bf8fc2340620695a402331e5da7c7db43264174det }
bf8fc2340620695a402331e5da7c7db43264174det chunk_tail->b_wptr = chunk_tail->b_rptr + count;
bf8fc2340620695a402331e5da7c7db43264174det chunk_mp->b_rptr = chunk_tail->b_wptr;
bf8fc2340620695a402331e5da7c7db43264174det count = 0;
bf8fc2340620695a402331e5da7c7db43264174det } else if (chunk_tail == NULL) {
bf8fc2340620695a402331e5da7c7db43264174det goto next;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu } else {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu chunk_tail->b_cont = NULL;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu /* Alloc chunk hdr, if needed */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl if (DB_REF(chunk_head) > 1 ||
f8d2de6bd2421da1926f3daa456d161670decdf7jchu ((intptr_t)chunk_head->b_rptr) & (SCTP_ALIGN - 1) ||
f8d2de6bd2421da1926f3daa456d161670decdf7jchu MBLKHEAD(chunk_head) < sizeof (*sdc)) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if ((chunk_hdr = allocb(xtralen, BPRI_MED)) == NULL) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (mdblk->b_cont == NULL) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (chunk_mp != NULL)
f8d2de6bd2421da1926f3daa456d161670decdf7jchu linkb(chunk_head, chunk_mp);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mdblk->b_cont = chunk_head;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu } else {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu SCTP_MSG_SET_CHUNKED(mdblk);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (chunk_mp != NULL)
f8d2de6bd2421da1926f3daa456d161670decdf7jchu linkb(chunk_head, chunk_mp);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu ASSERT(chunk_head->b_next == NULL);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu chunk_head->b_next = mdblk->b_cont;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mdblk->b_cont = chunk_head;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu return (sctp->sctp_xmit_tail);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu chunk_hdr->b_rptr += xtralen - sizeof (*sdc);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu chunk_hdr->b_wptr = chunk_hdr->b_rptr + sizeof (*sdc);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu chunk_hdr->b_cont = chunk_head;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu } else {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu chunk_hdr = chunk_head;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu chunk_hdr->b_rptr -= sizeof (*sdc);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu ASSERT(chunk_hdr->b_datap->db_ref == 1);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sdc = (sctp_data_hdr_t *)chunk_hdr->b_rptr;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sdc->sdh_id = CHUNK_DATA;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sdc->sdh_flags = 0;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sdc->sdh_len = htons(sizeof (*sdc) + chunksize - count);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu ASSERT(sdc->sdh_len);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sdc->sdh_sid = htons(msg_hdr->smh_sid);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu /*
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * We defer assigning the SSN just before sending the chunk, else
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * if we drop the chunk in sctp_get_msg_to_send(), we would need
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * to send a Forward TSN to let the peer know. Some more comments
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * about this in sctp_impl.h for SCTP_CHUNK_SENT.
f8d2de6bd2421da1926f3daa456d161670decdf7jchu */
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sdc->sdh_payload_id = msg_hdr->smh_ppid;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (mdblk->b_cont == NULL) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mdblk->b_cont = chunk_hdr;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu SCTP_DATA_SET_BBIT(sdc);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu } else {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mp = mdblk->b_cont;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu while (mp->b_next != NULL)
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mp = mp->b_next;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mp->b_next = chunk_hdr;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchu bytes_to_send -= (chunksize - count);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (chunk_mp != NULL) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchunext:
f8d2de6bd2421da1926f3daa456d161670decdf7jchu count = chunksize = fp->sfa_pmss - sizeof (*sdc);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu goto nextchunk;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu SCTP_DATA_SET_EBIT(sdc);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp->sctp_xmit_unsent = mdblk->b_next;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (mdblk->b_next == NULL) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp->sctp_xmit_unsent_tail = NULL;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mdblk->b_next = NULL;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (sctp->sctp_xmit_tail == NULL) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp->sctp_xmit_head = sctp->sctp_xmit_tail = mdblk;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu } else {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mp = sctp->sctp_xmit_tail;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu while (mp->b_next != NULL)
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mp = mp->b_next;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mp->b_next = mdblk;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mdblk->b_prev = mp;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchutry_next:
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (bytes_to_send > 0 && sctp->sctp_xmit_unsent != NULL) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mdblk = sctp->sctp_xmit_unsent;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu fp1 = SCTP_CHUNK_DEST(mdblk);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (fp1 == NULL)
f8d2de6bd2421da1926f3daa456d161670decdf7jchu fp1 = sctp->sctp_current;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (fp == fp1) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu size_t len = MBLKL(mdblk->b_cont);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if ((count > 0) &&
f8d2de6bd2421da1926f3daa456d161670decdf7jchu ((len > fp->sfa_pmss - sizeof (*sdc)) ||
f8d2de6bd2421da1926f3daa456d161670decdf7jchu (len <= count))) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu count -= sizeof (*sdc);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu count = chunksize = count - (count & 0x3);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu } else {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu count = chunksize = fp->sfa_pmss -
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sizeof (*sdc);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu } else {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (fp1->isv4)
f8d2de6bd2421da1926f3daa456d161670decdf7jchu xtralen = sctp->sctp_hdr_len;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu else
f8d2de6bd2421da1926f3daa456d161670decdf7jchu xtralen = sctp->sctp_hdr6_len;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu xtralen += sctps->sctps_wroff_xtra + sizeof (*sdc);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu count = chunksize = fp1->sfa_pmss - sizeof (*sdc);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu fp = fp1;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu goto nextmsg;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu return (sctp->sctp_xmit_tail);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu}
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchuvoid
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartzsctp_free_msg(mblk_t *ump)
f8d2de6bd2421da1926f3daa456d161670decdf7jchu{
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mblk_t *mp, *nmp;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchu for (mp = ump->b_cont; mp; mp = nmp) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu nmp = mp->b_next;
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz mp->b_next = mp->b_prev = NULL;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu freemsg(mp);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz ASSERT(!ump->b_prev);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl ump->b_next = NULL;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl freeb(ump);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl}
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartzmblk_t *
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartzsctp_add_proto_hdr(sctp_t *sctp, sctp_faddr_t *fp, mblk_t *mp, int sacklen,
25cf1a301a396c38e8adf52c15f537b80d2483f7jl int *error)
25cf1a301a396c38e8adf52c15f537b80d2483f7jl{
f8d2de6bd2421da1926f3daa456d161670decdf7jchu int hdrlen;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu uchar_t *hdr;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu int isv4 = fp->isv4;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp_stack_t *sctps = sctp->sctp_sctps;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (error != NULL)
f8d2de6bd2421da1926f3daa456d161670decdf7jchu *error = 0;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (isv4) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu hdrlen = sctp->sctp_hdr_len;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu hdr = sctp->sctp_iphc;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu } else {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu hdrlen = sctp->sctp_hdr6_len;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu hdr = sctp->sctp_iphc6;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu /*
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * A reject|blackhole could mean that the address is 'down'. Similarly,
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * it is possible that the address went down, we tried to send an
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * heartbeat and ended up setting fp->saddr as unspec because we
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * didn't have any usable source address. In either case
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * sctp_get_dest() will try find an IRE, if available, and set
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * the source address, if needed. If we still don't have any
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * usable source address, fp->state will be SCTP_FADDRS_UNREACH and
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * we return EHOSTUNREACH.
f8d2de6bd2421da1926f3daa456d161670decdf7jchu */
f8d2de6bd2421da1926f3daa456d161670decdf7jchu ASSERT(fp->ixa->ixa_ire != NULL);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if ((fp->ixa->ixa_ire->ire_flags & (RTF_REJECT|RTF_BLACKHOLE)) ||
f8d2de6bd2421da1926f3daa456d161670decdf7jchu SCTP_IS_ADDR_UNSPEC(fp->isv4, fp->saddr)) {
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz sctp_get_dest(sctp, fp);
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz if (fp->state == SCTP_FADDRS_UNREACH) {
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz if (error != NULL)
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz *error = EHOSTUNREACH;
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz return (NULL);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu /* Copy in IP header. */
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if ((mp->b_rptr - mp->b_datap->db_base) <
f8d2de6bd2421da1926f3daa456d161670decdf7jchu (sctps->sctps_wroff_xtra + hdrlen + sacklen) || DB_REF(mp) > 2) {
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz mblk_t *nmp;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz /*
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz * This can happen if IP headers are adjusted after
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz * data was moved into chunks, or during retransmission,
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz * or things like snoop is running.
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz */
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz nmp = allocb(sctps->sctps_wroff_xtra + hdrlen + sacklen,
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz BPRI_MED);
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz if (nmp == NULL) {
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz if (error != NULL)
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz *error = ENOMEM;
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz return (NULL);
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz }
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz nmp->b_rptr += sctps->sctps_wroff_xtra;
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz nmp->b_wptr = nmp->b_rptr + hdrlen + sacklen;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu nmp->b_cont = mp;
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz mp = nmp;
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz } else {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mp->b_rptr -= (hdrlen + sacklen);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu bcopy(hdr, mp->b_rptr, hdrlen);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (sacklen) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp_fill_sack(sctp, mp->b_rptr + hdrlen, sacklen);
bf8fc2340620695a402331e5da7c7db43264174det }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (fp != sctp->sctp_current) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu /* change addresses in header */
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (isv4) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu ipha_t *iph = (ipha_t *)mp->b_rptr;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchu IN6_V4MAPPED_TO_IPADDR(&fp->faddr, iph->ipha_dst);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (!IN6_IS_ADDR_V4MAPPED_ANY(&fp->saddr)) {
25cf1a301a396c38e8adf52c15f537b80d2483f7jl IN6_V4MAPPED_TO_IPADDR(&fp->saddr,
f8d2de6bd2421da1926f3daa456d161670decdf7jchu iph->ipha_src);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu } else if (sctp->sctp_bound_to_all) {
bf8fc2340620695a402331e5da7c7db43264174det iph->ipha_src = INADDR_ANY;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu } else {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu ip6_t *ip6h = (ip6_t *)mp->b_rptr;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchu ip6h->ip6_dst = fp->faddr;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (!IN6_IS_ADDR_UNSPECIFIED(&fp->saddr)) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu ip6h->ip6_src = fp->saddr;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu } else if (sctp->sctp_bound_to_all) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu ip6h->ip6_src = ipv6_all_zeros;
bf8fc2340620695a402331e5da7c7db43264174det }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu return (mp);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu}
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchu/*
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * SCTP requires every chunk to be padded so that the total length
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * is a multiple of SCTP_ALIGN. This function returns a mblk with
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae * the specified pad length.
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae */
f8d2de6bd2421da1926f3daa456d161670decdf7jchustatic mblk_t *
bf8fc2340620695a402331e5da7c7db43264174detsctp_get_padding(sctp_t *sctp, int pad)
f8d2de6bd2421da1926f3daa456d161670decdf7jchu{
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mblk_t *fill;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae ASSERT(pad < SCTP_ALIGN);
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae ASSERT(sctp->sctp_pad_mp != NULL);
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae if ((fill = dupb(sctp->sctp_pad_mp)) != NULL) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu fill->b_wptr += pad;
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae return (fill);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchu /*
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * The memory saving path of reusing the sctp_pad_mp
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * fails may be because it has been dupb() too
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * many times (DBLK_REFMAX). Use the memory consuming
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * path of allocating the pad mblk.
f8d2de6bd2421da1926f3daa456d161670decdf7jchu */
bf8fc2340620695a402331e5da7c7db43264174det if ((fill = allocb(SCTP_ALIGN, BPRI_MED)) != NULL) {
bf8fc2340620695a402331e5da7c7db43264174det /* Zero it out. SCTP_ALIGN is sizeof (int32_t) */
f8d2de6bd2421da1926f3daa456d161670decdf7jchu *(int32_t *)fill->b_rptr = 0;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu fill->b_wptr += pad;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu return (fill);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu}
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchustatic mblk_t *
f8d2de6bd2421da1926f3daa456d161670decdf7jchusctp_find_fast_rexmit_mblks(sctp_t *sctp, int *total, sctp_faddr_t **fp)
f8d2de6bd2421da1926f3daa456d161670decdf7jchu{
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae mblk_t *meta;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mblk_t *start_mp = NULL;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mblk_t *end_mp = NULL;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mblk_t *mp, *nmp;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mblk_t *fill;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp_data_hdr_t *sdh;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu int msglen;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu int extra;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp_msg_hdr_t *msg_hdr;
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae sctp_faddr_t *old_fp = NULL;
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae sctp_faddr_t *chunk_fp;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp_stack_t *sctps = sctp->sctp_sctps;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
bf8fc2340620695a402331e5da7c7db43264174det for (meta = sctp->sctp_xmit_head; meta != NULL; meta = meta->b_next) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu msg_hdr = (sctp_msg_hdr_t *)meta->b_rptr;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (SCTP_IS_MSG_ABANDONED(meta) ||
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae SCTP_MSG_TO_BE_ABANDONED(meta, msg_hdr, sctp)) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu continue;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu for (mp = meta->b_cont; mp != NULL; mp = mp->b_next) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (SCTP_CHUNK_WANT_REXMIT(mp)) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu /*
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae * Use the same peer address to do fast
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae * retransmission. If the original peer
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae * address is dead, switch to the current
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * one. Record the old one so that we
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae * will pick the chunks sent to the old
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * one for fast retransmission.
f8d2de6bd2421da1926f3daa456d161670decdf7jchu */
f8d2de6bd2421da1926f3daa456d161670decdf7jchu chunk_fp = SCTP_CHUNK_DEST(mp);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (*fp == NULL) {
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz *fp = chunk_fp;
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz if ((*fp)->state != SCTP_FADDRS_ALIVE) {
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz old_fp = *fp;
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz *fp = sctp->sctp_current;
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz }
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz } else if (old_fp == NULL && *fp != chunk_fp) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu continue;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu } else if (old_fp != NULL &&
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz old_fp != chunk_fp) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu continue;
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz }
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz sdh = (sctp_data_hdr_t *)mp->b_rptr;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu msglen = ntohs(sdh->sdh_len);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if ((extra = msglen & (SCTP_ALIGN - 1)) != 0) {
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz extra = SCTP_ALIGN - extra;
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchu /*
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * We still return at least the first message
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * even if that message cannot fit in as
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * PMTU may have changed.
f8d2de6bd2421da1926f3daa456d161670decdf7jchu */
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (*total + msglen + extra >
f8d2de6bd2421da1926f3daa456d161670decdf7jchu (*fp)->sfa_pmss && start_mp != NULL) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu return (start_mp);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz if ((nmp = dupmsg(mp)) == NULL)
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz return (start_mp);
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz if (extra > 0) {
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz fill = sctp_get_padding(sctp, extra);
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz if (fill != NULL) {
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz linkb(nmp, fill);
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz } else {
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz return (start_mp);
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz }
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz }
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz SCTPS_BUMP_MIB(sctps, sctpOutFastRetrans);
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz BUMP_LOCAL(sctp->sctp_rxtchunks);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu SCTP_CHUNK_CLEAR_REXMIT(mp);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (start_mp == NULL) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu start_mp = nmp;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu } else {
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz linkb(end_mp, nmp);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz end_mp = nmp;
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz *total += msglen + extra;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu dprint(2, ("sctp_find_fast_rexmit_mblks: "
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz "tsn %x\n", sdh->sdh_tsn));
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz }
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz }
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz }
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz /* Clear the flag as there is no more message to be fast rexmitted. */
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz sctp->sctp_chk_fast_rexmit = B_FALSE;
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz return (start_mp);
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz}
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz/* A debug function just to make sure that a mblk chain is not broken */
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz#ifdef DEBUG
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartzstatic boolean_t
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartzsctp_verify_chain(mblk_t *head, mblk_t *tail)
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz{
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz mblk_t *mp = head;
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz if (head == NULL || tail == NULL)
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz return (B_TRUE);
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz while (mp != NULL) {
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz if (mp == tail)
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz return (B_TRUE);
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz mp = mp->b_next;
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz }
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz return (B_FALSE);
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz}
f8d2de6bd2421da1926f3daa456d161670decdf7jchu#endif
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchu/*
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * Gets the next unsent chunk to transmit. Messages that are abandoned are
bf8fc2340620695a402331e5da7c7db43264174det * skipped. A message can be abandoned if it has a non-zero timetolive and
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * transmission has not yet started or if it is a partially reliable
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * message and its time is up (assuming we are PR-SCTP aware).
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * We only return a chunk if it will fit entirely in the current packet.
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * 'cansend' is used to determine if need to try and chunkify messages from
bf8fc2340620695a402331e5da7c7db43264174det * the unsent list, if any, and also as an input to sctp_chunkify() if so.
bf8fc2340620695a402331e5da7c7db43264174det *
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * firstseg_len indicates the space already used, cansend represents remaining
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * space in the window, ((sfa_pmss - firstseg_len) can therefore reasonably
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * be used to compute the cansend arg).
f8d2de6bd2421da1926f3daa456d161670decdf7jchu */
f8d2de6bd2421da1926f3daa456d161670decdf7jchumblk_t *
bf8fc2340620695a402331e5da7c7db43264174detsctp_get_msg_to_send(sctp_t *sctp, mblk_t **mp, mblk_t *meta, int *error,
bf8fc2340620695a402331e5da7c7db43264174det int32_t firstseg_len, uint32_t cansend, sctp_faddr_t *fp)
f8d2de6bd2421da1926f3daa456d161670decdf7jchu{
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mblk_t *mp1;
bf8fc2340620695a402331e5da7c7db43264174det sctp_msg_hdr_t *msg_hdr;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mblk_t *tmp_meta;
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz sctp_faddr_t *fp1;
bf8fc2340620695a402331e5da7c7db43264174det
f8d2de6bd2421da1926f3daa456d161670decdf7jchu ASSERT(error != NULL && mp != NULL);
0168954460bd77d83497a4a6aa9c3f34c55dba25jchu *error = 0;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchu ASSERT(sctp->sctp_current != NULL);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchuchunkified:
7ea9b230eb477df11737d2c1852f0370a6d7db91et while (meta != NULL) {
7ea9b230eb477df11737d2c1852f0370a6d7db91et tmp_meta = meta->b_next;
7ea9b230eb477df11737d2c1852f0370a6d7db91et msg_hdr = (sctp_msg_hdr_t *)meta->b_rptr;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mp1 = meta->b_cont;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (SCTP_IS_MSG_ABANDONED(meta))
f8d2de6bd2421da1926f3daa456d161670decdf7jchu goto next_msg;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (!SCTP_MSG_TO_BE_ABANDONED(meta, msg_hdr, sctp)) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu while (mp1 != NULL) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (SCTP_CHUNK_CANSEND(mp1)) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu *mp = mp1;
bf8fc2340620695a402331e5da7c7db43264174det#ifdef DEBUG
f8d2de6bd2421da1926f3daa456d161670decdf7jchu ASSERT(sctp_verify_chain(
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp->sctp_xmit_head, meta));
f8d2de6bd2421da1926f3daa456d161670decdf7jchu#endif
1a887b2e15e4d9b63b5add57f3334b5b31960018jchu return (meta);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mp1 = mp1->b_next;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu goto next_msg;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu /*
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * If we come here and the first chunk is sent, then we
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * we are PR-SCTP aware, in which case if the cumulative
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * TSN has moved upto or beyond the first chunk (which
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * means all the previous messages have been cumulative
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * SACK'd), then we send a Forward TSN with the last
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * chunk that was sent in this message. If we can't send
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * a Forward TSN because previous non-abandoned messages
bf8fc2340620695a402331e5da7c7db43264174det * have not been acked then we will defer the Forward TSN
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * to sctp_rexmit() or sctp_cumack().
f8d2de6bd2421da1926f3daa456d161670decdf7jchu */
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (SCTP_CHUNK_ISSENT(mp1)) {
25cf1a301a396c38e8adf52c15f537b80d2483f7jl *error = sctp_check_abandoned_msg(sctp, meta);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (*error != 0) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu#ifdef DEBUG
bf8fc2340620695a402331e5da7c7db43264174det ASSERT(sctp_verify_chain(sctp->sctp_xmit_head,
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp->sctp_xmit_tail));
f8d2de6bd2421da1926f3daa456d161670decdf7jchu#endif
f8d2de6bd2421da1926f3daa456d161670decdf7jchu return (NULL);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
bf8fc2340620695a402331e5da7c7db43264174det goto next_msg;
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz }
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz BUMP_LOCAL(sctp->sctp_prsctpdrop);
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz ASSERT(sctp->sctp_unsent >= msg_hdr->smh_msglen);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (meta->b_prev == NULL) {
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz ASSERT(sctp->sctp_xmit_head == meta);
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz sctp->sctp_xmit_head = tmp_meta;
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz if (sctp->sctp_xmit_tail == meta)
bf8fc2340620695a402331e5da7c7db43264174det sctp->sctp_xmit_tail = tmp_meta;
bf8fc2340620695a402331e5da7c7db43264174det meta->b_next = NULL;
bf8fc2340620695a402331e5da7c7db43264174det if (tmp_meta != NULL)
bf8fc2340620695a402331e5da7c7db43264174det tmp_meta->b_prev = NULL;
bf8fc2340620695a402331e5da7c7db43264174det } else if (meta->b_next == NULL) {
bf8fc2340620695a402331e5da7c7db43264174det if (sctp->sctp_xmit_tail == meta)
bf8fc2340620695a402331e5da7c7db43264174det sctp->sctp_xmit_tail = meta->b_prev;
bf8fc2340620695a402331e5da7c7db43264174det meta->b_prev->b_next = NULL;
bf8fc2340620695a402331e5da7c7db43264174det meta->b_prev = NULL;
bf8fc2340620695a402331e5da7c7db43264174det } else {
bf8fc2340620695a402331e5da7c7db43264174det meta->b_prev->b_next = tmp_meta;
bf8fc2340620695a402331e5da7c7db43264174det tmp_meta->b_prev = meta->b_prev;
bf8fc2340620695a402331e5da7c7db43264174det if (sctp->sctp_xmit_tail == meta)
bf8fc2340620695a402331e5da7c7db43264174det sctp->sctp_xmit_tail = tmp_meta;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu meta->b_prev = NULL;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu meta->b_next = NULL;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp->sctp_unsent -= msg_hdr->smh_msglen;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu /*
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * Update ULP the amount of queued data, which is
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * sent-unack'ed + unsent.
f8d2de6bd2421da1926f3daa456d161670decdf7jchu */
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (!SCTP_IS_DETACHED(sctp))
f8d2de6bd2421da1926f3daa456d161670decdf7jchu SCTP_TXQ_UPDATE(sctp);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp_sendfail_event(sctp, meta, 0, B_TRUE);
f8d2de6bd2421da1926f3daa456d161670decdf7jchunext_msg:
f8d2de6bd2421da1926f3daa456d161670decdf7jchu meta = tmp_meta;
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu /* chunkify, if needed */
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (cansend > 0 && sctp->sctp_xmit_unsent != NULL) {
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz ASSERT(sctp->sctp_unsent > 0);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (fp == NULL) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu fp = SCTP_CHUNK_DEST(sctp->sctp_xmit_unsent);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (fp == NULL || fp->state != SCTP_FADDRS_ALIVE)
f8d2de6bd2421da1926f3daa456d161670decdf7jchu fp = sctp->sctp_current;
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz } else {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu /*
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * If user specified destination, try to honor that.
f8d2de6bd2421da1926f3daa456d161670decdf7jchu */
bf8fc2340620695a402331e5da7c7db43264174det fp1 = SCTP_CHUNK_DEST(sctp->sctp_xmit_unsent);
bf8fc2340620695a402331e5da7c7db43264174det if (fp1 != NULL && fp1->state == SCTP_FADDRS_ALIVE &&
f8d2de6bd2421da1926f3daa456d161670decdf7jchu fp1 != fp) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu goto chunk_done;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
bf8fc2340620695a402331e5da7c7db43264174det meta = sctp_chunkify(sctp, fp->sfa_pmss, firstseg_len, cansend);
bf8fc2340620695a402331e5da7c7db43264174det if (meta == NULL)
bf8fc2340620695a402331e5da7c7db43264174det goto chunk_done;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu /*
0168954460bd77d83497a4a6aa9c3f34c55dba25jchu * sctp_chunkify() won't advance sctp_xmit_tail if it adds
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * new chunk(s) to the tail, so we need to skip the
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * sctp_xmit_tail, which would have already been processed.
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz * This could happen when there is unacked chunks, but
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * nothing new to send.
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * When sctp_chunkify() is called when the transmit queue
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * is empty then we need to start from sctp_xmit_tail.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl */
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz if (SCTP_CHUNK_ISSENT(sctp->sctp_xmit_tail->b_cont)) {
25cf1a301a396c38e8adf52c15f537b80d2483f7jl#ifdef DEBUG
25cf1a301a396c38e8adf52c15f537b80d2483f7jl mp1 = sctp->sctp_xmit_tail->b_cont;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu while (mp1 != NULL) {
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz ASSERT(!SCTP_CHUNK_CANSEND(mp1));
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mp1 = mp1->b_next;
bf8fc2340620695a402331e5da7c7db43264174det }
bf8fc2340620695a402331e5da7c7db43264174det#endif
bf8fc2340620695a402331e5da7c7db43264174det if ((meta = sctp->sctp_xmit_tail->b_next) == NULL)
bf8fc2340620695a402331e5da7c7db43264174det goto chunk_done;
bf8fc2340620695a402331e5da7c7db43264174det }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu goto chunkified;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchuchunk_done:
f8d2de6bd2421da1926f3daa456d161670decdf7jchu#ifdef DEBUG
f8d2de6bd2421da1926f3daa456d161670decdf7jchu ASSERT(sctp_verify_chain(sctp->sctp_xmit_head, sctp->sctp_xmit_tail));
f8d2de6bd2421da1926f3daa456d161670decdf7jchu#endif
f8d2de6bd2421da1926f3daa456d161670decdf7jchu return (NULL);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu}
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz
f8d2de6bd2421da1926f3daa456d161670decdf7jchuvoid
f8d2de6bd2421da1926f3daa456d161670decdf7jchusctp_fast_rexmit(sctp_t *sctp)
f8d2de6bd2421da1926f3daa456d161670decdf7jchu{
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mblk_t *mp, *head;
bf8fc2340620695a402331e5da7c7db43264174det int pktlen = 0;
bf8fc2340620695a402331e5da7c7db43264174det sctp_faddr_t *fp = NULL;
bf8fc2340620695a402331e5da7c7db43264174det sctp_stack_t *sctps = sctp->sctp_sctps;
bf8fc2340620695a402331e5da7c7db43264174det
bf8fc2340620695a402331e5da7c7db43264174det ASSERT(sctp->sctp_xmit_head != NULL);
bf8fc2340620695a402331e5da7c7db43264174det mp = sctp_find_fast_rexmit_mblks(sctp, &pktlen, &fp);
bf8fc2340620695a402331e5da7c7db43264174det if (mp == NULL) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu SCTP_KSTAT(sctps, sctp_fr_not_found);
bf8fc2340620695a402331e5da7c7db43264174det return;
bf8fc2340620695a402331e5da7c7db43264174det }
bf8fc2340620695a402331e5da7c7db43264174det if ((head = sctp_add_proto_hdr(sctp, fp, mp, 0, NULL)) == NULL) {
bf8fc2340620695a402331e5da7c7db43264174det freemsg(mp);
bf8fc2340620695a402331e5da7c7db43264174det SCTP_KSTAT(sctps, sctp_fr_add_hdr);
bf8fc2340620695a402331e5da7c7db43264174det return;
bf8fc2340620695a402331e5da7c7db43264174det }
bf8fc2340620695a402331e5da7c7db43264174det if ((pktlen > fp->sfa_pmss) && fp->isv4) {
bf8fc2340620695a402331e5da7c7db43264174det ipha_t *iph = (ipha_t *)head->b_rptr;
bf8fc2340620695a402331e5da7c7db43264174det
bf8fc2340620695a402331e5da7c7db43264174det iph->ipha_fragment_offset_and_flags = 0;
bf8fc2340620695a402331e5da7c7db43264174det }
bf8fc2340620695a402331e5da7c7db43264174det
bf8fc2340620695a402331e5da7c7db43264174det sctp_set_iplen(sctp, head, fp->ixa);
bf8fc2340620695a402331e5da7c7db43264174det (void) conn_ip_output(head, fp->ixa);
bf8fc2340620695a402331e5da7c7db43264174det BUMP_LOCAL(sctp->sctp_opkts);
bf8fc2340620695a402331e5da7c7db43264174det sctp->sctp_active = fp->lastactive = ddi_get_lbolt64();
bf8fc2340620695a402331e5da7c7db43264174det}
bf8fc2340620695a402331e5da7c7db43264174det
bf8fc2340620695a402331e5da7c7db43264174detvoid
bf8fc2340620695a402331e5da7c7db43264174detsctp_output(sctp_t *sctp, uint_t num_pkt)
bf8fc2340620695a402331e5da7c7db43264174det{
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mblk_t *mp = NULL;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mblk_t *nmp;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mblk_t *head;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mblk_t *meta = sctp->sctp_xmit_tail;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mblk_t *fill = NULL;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu uint16_t chunklen;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu uint32_t cansend;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu int32_t seglen;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu int32_t xtralen;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu int32_t sacklen;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu int32_t pad = 0;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu int32_t pathmax;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu int extra;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu int64_t now = LBOLT_FASTPATH64;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp_faddr_t *fp;
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz sctp_faddr_t *lfp;
08a74c0d0f6c3b94aa21216885efa4387c3d375cschwartz sctp_data_hdr_t *sdc;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu int error;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu boolean_t notsent = B_TRUE;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp_stack_t *sctps = sctp->sctp_sctps;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu uint32_t tsn;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (sctp->sctp_ftsn == sctp->sctp_lastacked + 1) {
1a887b2e15e4d9b63b5add57f3334b5b31960018jchu sacklen = 0;
bf8fc2340620695a402331e5da7c7db43264174det } else {
bf8fc2340620695a402331e5da7c7db43264174det /* send a SACK chunk */
bf8fc2340620695a402331e5da7c7db43264174det sacklen = sizeof (sctp_chunk_hdr_t) +
bf8fc2340620695a402331e5da7c7db43264174det sizeof (sctp_sack_chunk_t) +
bf8fc2340620695a402331e5da7c7db43264174det (sizeof (sctp_sack_frag_t) * sctp->sctp_sack_gaps);
bf8fc2340620695a402331e5da7c7db43264174det lfp = sctp->sctp_lastdata;
1a887b2e15e4d9b63b5add57f3334b5b31960018jchu ASSERT(lfp != NULL);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (lfp->state != SCTP_FADDRS_ALIVE)
f8d2de6bd2421da1926f3daa456d161670decdf7jchu lfp = sctp->sctp_current;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchu cansend = sctp->sctp_frwnd;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (sctp->sctp_unsent < cansend)
f8d2de6bd2421da1926f3daa456d161670decdf7jchu cansend = sctp->sctp_unsent;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchu /*
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * Start persist timer if unable to send or when
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * trying to send into a zero window. This timer
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * ensures the blocked send attempt is retried.
f8d2de6bd2421da1926f3daa456d161670decdf7jchu */
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if ((cansend < sctp->sctp_current->sfa_pmss / 2) &&
f8d2de6bd2421da1926f3daa456d161670decdf7jchu (sctp->sctp_unacked != 0) &&
f8d2de6bd2421da1926f3daa456d161670decdf7jchu (sctp->sctp_unacked < sctp->sctp_current->sfa_pmss) &&
f8d2de6bd2421da1926f3daa456d161670decdf7jchu !sctp->sctp_ndelay ||
f8d2de6bd2421da1926f3daa456d161670decdf7jchu (cansend == 0 && sctp->sctp_unacked == 0 &&
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp->sctp_unsent != 0)) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu head = NULL;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu fp = sctp->sctp_current;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu goto unsent_data;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (meta != NULL)
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mp = meta->b_cont;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu while (cansend > 0 && num_pkt-- != 0) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu pad = 0;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchu /*
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * Find first segment eligible for transmit.
f8d2de6bd2421da1926f3daa456d161670decdf7jchu */
f8d2de6bd2421da1926f3daa456d161670decdf7jchu while (mp != NULL) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (SCTP_CHUNK_CANSEND(mp))
bf8fc2340620695a402331e5da7c7db43264174det break;
bf8fc2340620695a402331e5da7c7db43264174det mp = mp->b_next;
bf8fc2340620695a402331e5da7c7db43264174det }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (mp == NULL) {
1a887b2e15e4d9b63b5add57f3334b5b31960018jchu meta = sctp_get_msg_to_send(sctp, &mp,
f8d2de6bd2421da1926f3daa456d161670decdf7jchu meta == NULL ? NULL : meta->b_next, &error, sacklen,
f8d2de6bd2421da1926f3daa456d161670decdf7jchu cansend, NULL);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (error != 0 || meta == NULL) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu head = NULL;
bf8fc2340620695a402331e5da7c7db43264174det fp = sctp->sctp_current;
bf8fc2340620695a402331e5da7c7db43264174det goto unsent_data;
bf8fc2340620695a402331e5da7c7db43264174det }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp->sctp_xmit_tail = meta;
bf8fc2340620695a402331e5da7c7db43264174det }
bf8fc2340620695a402331e5da7c7db43264174det
bf8fc2340620695a402331e5da7c7db43264174det sdc = (sctp_data_hdr_t *)mp->b_rptr;
bf8fc2340620695a402331e5da7c7db43264174det seglen = ntohs(sdc->sdh_len);
bf8fc2340620695a402331e5da7c7db43264174det xtralen = sizeof (*sdc);
bf8fc2340620695a402331e5da7c7db43264174det chunklen = seglen - xtralen;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchu /*
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * Check rwnd.
f8d2de6bd2421da1926f3daa456d161670decdf7jchu */
bf8fc2340620695a402331e5da7c7db43264174det if (chunklen > cansend) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu head = NULL;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu fp = SCTP_CHUNK_DEST(meta);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (fp == NULL || fp->state != SCTP_FADDRS_ALIVE)
bf8fc2340620695a402331e5da7c7db43264174det fp = sctp->sctp_current;
bf8fc2340620695a402331e5da7c7db43264174det goto unsent_data;
bf8fc2340620695a402331e5da7c7db43264174det }
bf8fc2340620695a402331e5da7c7db43264174det if ((extra = seglen & (SCTP_ALIGN - 1)) != 0)
bf8fc2340620695a402331e5da7c7db43264174det extra = SCTP_ALIGN - extra;
bf8fc2340620695a402331e5da7c7db43264174det
f8d2de6bd2421da1926f3daa456d161670decdf7jchu /*
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * Pick destination address, and check cwnd.
f8d2de6bd2421da1926f3daa456d161670decdf7jchu */
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (sacklen > 0 && (seglen + extra <= lfp->cwnd - lfp->suna) &&
bf8fc2340620695a402331e5da7c7db43264174det (seglen + sacklen + extra <= lfp->sfa_pmss)) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu /*
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * Only include SACK chunk if it can be bundled
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * with a data chunk, and sent to sctp_lastdata.
bf8fc2340620695a402331e5da7c7db43264174det */
bf8fc2340620695a402331e5da7c7db43264174det pathmax = lfp->cwnd - lfp->suna;
bf8fc2340620695a402331e5da7c7db43264174det
bf8fc2340620695a402331e5da7c7db43264174det fp = lfp;
bf8fc2340620695a402331e5da7c7db43264174det if ((nmp = dupmsg(mp)) == NULL) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu head = NULL;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu goto unsent_data;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu SCTP_CHUNK_CLEAR_FLAGS(nmp);
bf8fc2340620695a402331e5da7c7db43264174det head = sctp_add_proto_hdr(sctp, fp, nmp, sacklen,
f8d2de6bd2421da1926f3daa456d161670decdf7jchu &error);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (head == NULL) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu /*
bf8fc2340620695a402331e5da7c7db43264174det * If none of the source addresses are
bf8fc2340620695a402331e5da7c7db43264174det * available (i.e error == EHOSTUNREACH),
bf8fc2340620695a402331e5da7c7db43264174det * pretend we have sent the data. We will
bf8fc2340620695a402331e5da7c7db43264174det * eventually time out trying to retramsmit
bf8fc2340620695a402331e5da7c7db43264174det * the data if the interface never comes up.
bf8fc2340620695a402331e5da7c7db43264174det * If we have already sent some stuff (i.e.,
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * notsent is B_FALSE) then we are fine, else
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * just mark this packet as sent.
f8d2de6bd2421da1926f3daa456d161670decdf7jchu */
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (notsent && error == EHOSTUNREACH) {
bf8fc2340620695a402331e5da7c7db43264174det SCTP_CHUNK_SENT(sctp, mp, sdc,
f8d2de6bd2421da1926f3daa456d161670decdf7jchu fp, chunklen, meta);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu freemsg(nmp);
bf8fc2340620695a402331e5da7c7db43264174det SCTP_KSTAT(sctps, sctp_output_failed);
bf8fc2340620695a402331e5da7c7db43264174det goto unsent_data;
bf8fc2340620695a402331e5da7c7db43264174det }
bf8fc2340620695a402331e5da7c7db43264174det seglen += sacklen;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu xtralen += sacklen;
bf8fc2340620695a402331e5da7c7db43264174det sacklen = 0;
e51949e6deb4cb79dcb0772d225868626ae52517dduvall } else {
3d9c56a157784839d32b49e03a3468a72c53f2dcet fp = SCTP_CHUNK_DEST(meta);
e51949e6deb4cb79dcb0772d225868626ae52517dduvall if (fp == NULL || fp->state != SCTP_FADDRS_ALIVE)
e51949e6deb4cb79dcb0772d225868626ae52517dduvall fp = sctp->sctp_current;
bf8fc2340620695a402331e5da7c7db43264174det /*
bf8fc2340620695a402331e5da7c7db43264174det * If we haven't sent data to this destination for
bf8fc2340620695a402331e5da7c7db43264174det * a while, do slow start again.
e51949e6deb4cb79dcb0772d225868626ae52517dduvall */
bf8fc2340620695a402331e5da7c7db43264174det if (now - fp->lastactive > fp->rto) {
bf8fc2340620695a402331e5da7c7db43264174det SET_CWND(fp, fp->sfa_pmss,
bf8fc2340620695a402331e5da7c7db43264174det sctps->sctps_slow_start_after_idle);
bf8fc2340620695a402331e5da7c7db43264174det }
bf8fc2340620695a402331e5da7c7db43264174det
bf8fc2340620695a402331e5da7c7db43264174det pathmax = fp->cwnd - fp->suna;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (seglen + extra > pathmax) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu head = NULL;
8bc7d88a7ed8565440a3cb4d316b626938433668et goto unsent_data;
8bc7d88a7ed8565440a3cb4d316b626938433668et }
8bc7d88a7ed8565440a3cb4d316b626938433668et if ((nmp = dupmsg(mp)) == NULL) {
bf8fc2340620695a402331e5da7c7db43264174det head = NULL;
8bc7d88a7ed8565440a3cb4d316b626938433668et goto unsent_data;
8bc7d88a7ed8565440a3cb4d316b626938433668et }
81f63062a60a29358c252e0d10807f8a8547fbb5arutz SCTP_CHUNK_CLEAR_FLAGS(nmp);
81f63062a60a29358c252e0d10807f8a8547fbb5arutz head = sctp_add_proto_hdr(sctp, fp, nmp, 0, &error);
81f63062a60a29358c252e0d10807f8a8547fbb5arutz if (head == NULL) {
81f63062a60a29358c252e0d10807f8a8547fbb5arutz /*
81f63062a60a29358c252e0d10807f8a8547fbb5arutz * If none of the source addresses are
81f63062a60a29358c252e0d10807f8a8547fbb5arutz * available (i.e error == EHOSTUNREACH),
81f63062a60a29358c252e0d10807f8a8547fbb5arutz * pretend we have sent the data. We will
81f63062a60a29358c252e0d10807f8a8547fbb5arutz * eventually time out trying to retramsmit
81f63062a60a29358c252e0d10807f8a8547fbb5arutz * the data if the interface never comes up.
81f63062a60a29358c252e0d10807f8a8547fbb5arutz * If we have already sent some stuff (i.e.,
81f63062a60a29358c252e0d10807f8a8547fbb5arutz * notsent is B_FALSE) then we are fine, else
81f63062a60a29358c252e0d10807f8a8547fbb5arutz * just mark this packet as sent.
81f63062a60a29358c252e0d10807f8a8547fbb5arutz */
81f63062a60a29358c252e0d10807f8a8547fbb5arutz if (notsent && error == EHOSTUNREACH) {
81f63062a60a29358c252e0d10807f8a8547fbb5arutz SCTP_CHUNK_SENT(sctp, mp, sdc,
81f63062a60a29358c252e0d10807f8a8547fbb5arutz fp, chunklen, meta);
81f63062a60a29358c252e0d10807f8a8547fbb5arutz }
81f63062a60a29358c252e0d10807f8a8547fbb5arutz freemsg(nmp);
81f63062a60a29358c252e0d10807f8a8547fbb5arutz SCTP_KSTAT(sctps, sctp_output_failed);
bf8fc2340620695a402331e5da7c7db43264174det goto unsent_data;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl }
25cf1a301a396c38e8adf52c15f537b80d2483f7jl }
25cf1a301a396c38e8adf52c15f537b80d2483f7jl fp->lastactive = now;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl if (pathmax > fp->sfa_pmss)
25cf1a301a396c38e8adf52c15f537b80d2483f7jl pathmax = fp->sfa_pmss;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl SCTP_CHUNK_SENT(sctp, mp, sdc, fp, chunklen, meta);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl mp = mp->b_next;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl
25cf1a301a396c38e8adf52c15f537b80d2483f7jl /*
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Use this chunk to measure RTT?
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Must not be a retransmision of an earlier chunk,
81f63062a60a29358c252e0d10807f8a8547fbb5arutz * ensure the tsn is current.
81f63062a60a29358c252e0d10807f8a8547fbb5arutz */
81f63062a60a29358c252e0d10807f8a8547fbb5arutz tsn = ntohl(sdc->sdh_tsn);
81f63062a60a29358c252e0d10807f8a8547fbb5arutz if (sctp->sctp_out_time == 0 && tsn == (sctp->sctp_ltsn - 1)) {
25cf1a301a396c38e8adf52c15f537b80d2483f7jl sctp->sctp_out_time = now;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl sctp->sctp_rtt_tsn = tsn;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl }
25cf1a301a396c38e8adf52c15f537b80d2483f7jl if (extra > 0) {
25cf1a301a396c38e8adf52c15f537b80d2483f7jl fill = sctp_get_padding(sctp, extra);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl if (fill != NULL) {
25cf1a301a396c38e8adf52c15f537b80d2483f7jl linkb(head, fill);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl pad = extra;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl seglen += extra;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl } else {
25cf1a301a396c38e8adf52c15f537b80d2483f7jl goto unsent_data;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl }
25cf1a301a396c38e8adf52c15f537b80d2483f7jl }
25cf1a301a396c38e8adf52c15f537b80d2483f7jl /*
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Bundle chunks. We linkb() the chunks together to send
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * downstream in a single packet.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Partial chunks MUST NOT be bundled with full chunks, so we
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * rely on sctp_get_msg_to_send() to only return messages that
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * will fit entirely in the current packet.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl while (seglen < pathmax) {
25cf1a301a396c38e8adf52c15f537b80d2483f7jl int32_t new_len;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl int32_t new_xtralen;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl
25cf1a301a396c38e8adf52c15f537b80d2483f7jl while (mp != NULL) {
25cf1a301a396c38e8adf52c15f537b80d2483f7jl if (SCTP_CHUNK_CANSEND(mp))
25cf1a301a396c38e8adf52c15f537b80d2483f7jl break;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl mp = mp->b_next;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl }
25cf1a301a396c38e8adf52c15f537b80d2483f7jl if (mp == NULL) {
25cf1a301a396c38e8adf52c15f537b80d2483f7jl meta = sctp_get_msg_to_send(sctp, &mp,
1ff6511282dda236fdea133a0fc53438d8c4f5fdegillett meta->b_next, &error, seglen,
25cf1a301a396c38e8adf52c15f537b80d2483f7jl (seglen - xtralen) >= cansend ? 0 :
25cf1a301a396c38e8adf52c15f537b80d2483f7jl cansend - seglen, fp);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl if (error != 0)
25cf1a301a396c38e8adf52c15f537b80d2483f7jl break;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl /* If no more eligible chunks, cease bundling */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl if (meta == NULL)
25cf1a301a396c38e8adf52c15f537b80d2483f7jl break;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl sctp->sctp_xmit_tail = meta;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl }
25cf1a301a396c38e8adf52c15f537b80d2483f7jl ASSERT(mp != NULL);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl if (!SCTP_CHUNK_ISSENT(mp) && SCTP_CHUNK_DEST(meta) &&
25cf1a301a396c38e8adf52c15f537b80d2483f7jl fp != SCTP_CHUNK_DEST(meta)) {
25cf1a301a396c38e8adf52c15f537b80d2483f7jl break;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl }
25cf1a301a396c38e8adf52c15f537b80d2483f7jl sdc = (sctp_data_hdr_t *)mp->b_rptr;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl chunklen = ntohs(sdc->sdh_len);
81f63062a60a29358c252e0d10807f8a8547fbb5arutz if ((extra = chunklen & (SCTP_ALIGN - 1)) != 0)
81f63062a60a29358c252e0d10807f8a8547fbb5arutz extra = SCTP_ALIGN - extra;
81f63062a60a29358c252e0d10807f8a8547fbb5arutz
81f63062a60a29358c252e0d10807f8a8547fbb5arutz new_len = seglen + chunklen;
81f63062a60a29358c252e0d10807f8a8547fbb5arutz new_xtralen = xtralen + sizeof (*sdc);
81f63062a60a29358c252e0d10807f8a8547fbb5arutz chunklen -= sizeof (*sdc);
81f63062a60a29358c252e0d10807f8a8547fbb5arutz
81f63062a60a29358c252e0d10807f8a8547fbb5arutz if (new_len - new_xtralen > cansend ||
81f63062a60a29358c252e0d10807f8a8547fbb5arutz new_len + extra > pathmax) {
81f63062a60a29358c252e0d10807f8a8547fbb5arutz break;
81f63062a60a29358c252e0d10807f8a8547fbb5arutz }
81f63062a60a29358c252e0d10807f8a8547fbb5arutz if ((nmp = dupmsg(mp)) == NULL)
81f63062a60a29358c252e0d10807f8a8547fbb5arutz break;
81f63062a60a29358c252e0d10807f8a8547fbb5arutz if (extra > 0) {
81f63062a60a29358c252e0d10807f8a8547fbb5arutz fill = sctp_get_padding(sctp, extra);
81f63062a60a29358c252e0d10807f8a8547fbb5arutz if (fill != NULL) {
81f63062a60a29358c252e0d10807f8a8547fbb5arutz pad += extra;
81f63062a60a29358c252e0d10807f8a8547fbb5arutz new_len += extra;
81f63062a60a29358c252e0d10807f8a8547fbb5arutz linkb(nmp, fill);
81f63062a60a29358c252e0d10807f8a8547fbb5arutz } else {
81f63062a60a29358c252e0d10807f8a8547fbb5arutz freemsg(nmp);
81f63062a60a29358c252e0d10807f8a8547fbb5arutz break;
81f63062a60a29358c252e0d10807f8a8547fbb5arutz }
81f63062a60a29358c252e0d10807f8a8547fbb5arutz }
81f63062a60a29358c252e0d10807f8a8547fbb5arutz seglen = new_len;
81f63062a60a29358c252e0d10807f8a8547fbb5arutz xtralen = new_xtralen;
81f63062a60a29358c252e0d10807f8a8547fbb5arutz SCTP_CHUNK_CLEAR_FLAGS(nmp);
81f63062a60a29358c252e0d10807f8a8547fbb5arutz SCTP_CHUNK_SENT(sctp, mp, sdc, fp, chunklen, meta);
81f63062a60a29358c252e0d10807f8a8547fbb5arutz linkb(head, nmp);
81f63062a60a29358c252e0d10807f8a8547fbb5arutz mp = mp->b_next;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl }
25cf1a301a396c38e8adf52c15f537b80d2483f7jl if ((seglen > fp->sfa_pmss) && fp->isv4) {
25cf1a301a396c38e8adf52c15f537b80d2483f7jl ipha_t *iph = (ipha_t *)head->b_rptr;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl
25cf1a301a396c38e8adf52c15f537b80d2483f7jl /*
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Path MTU is different from what we thought it would
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * be when we created chunks, or IP headers have grown.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Need to clear the DF bit.
81f63062a60a29358c252e0d10807f8a8547fbb5arutz */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl iph->ipha_fragment_offset_and_flags = 0;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl }
25cf1a301a396c38e8adf52c15f537b80d2483f7jl /* xmit segment */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl ASSERT(cansend >= seglen - pad - xtralen);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl cansend -= (seglen - pad - xtralen);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl dprint(2, ("sctp_output: Sending packet %d bytes, tsn %x "
25cf1a301a396c38e8adf52c15f537b80d2483f7jl "ssn %d to %p (rwnd %d, cansend %d, lastack_rxd %x)\n",
25cf1a301a396c38e8adf52c15f537b80d2483f7jl seglen - xtralen, ntohl(sdc->sdh_tsn),
25cf1a301a396c38e8adf52c15f537b80d2483f7jl ntohs(sdc->sdh_ssn), (void *)fp, sctp->sctp_frwnd,
25cf1a301a396c38e8adf52c15f537b80d2483f7jl cansend, sctp->sctp_lastack_rxd));
25cf1a301a396c38e8adf52c15f537b80d2483f7jl sctp_set_iplen(sctp, head, fp->ixa);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl (void) conn_ip_output(head, fp->ixa);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl BUMP_LOCAL(sctp->sctp_opkts);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl /* arm rto timer (if not set) */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl if (!fp->timer_running)
25cf1a301a396c38e8adf52c15f537b80d2483f7jl SCTP_FADDR_TIMER_RESTART(sctp, fp, fp->rto);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl notsent = B_FALSE;
81f63062a60a29358c252e0d10807f8a8547fbb5arutz }
25cf1a301a396c38e8adf52c15f537b80d2483f7jl sctp->sctp_active = now;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl return;
25cf1a301a396c38e8adf52c15f537b80d2483f7jlunsent_data:
25cf1a301a396c38e8adf52c15f537b80d2483f7jl /* arm persist timer (if rto timer not set) */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl if (!fp->timer_running)
25cf1a301a396c38e8adf52c15f537b80d2483f7jl SCTP_FADDR_TIMER_RESTART(sctp, fp, fp->rto);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl if (head != NULL)
25cf1a301a396c38e8adf52c15f537b80d2483f7jl freemsg(head);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl}
bf8fc2340620695a402331e5da7c7db43264174det
25cf1a301a396c38e8adf52c15f537b80d2483f7jl/*
8bc7d88a7ed8565440a3cb4d316b626938433668et * The following two functions initialize and destroy the cache
bf8fc2340620695a402331e5da7c7db43264174det * associated with the sets used for PR-SCTP.
f8d2de6bd2421da1926f3daa456d161670decdf7jchu */
f8d2de6bd2421da1926f3daa456d161670decdf7jchuvoid
f8d2de6bd2421da1926f3daa456d161670decdf7jchusctp_ftsn_sets_init(void)
8c3348818856b8366c07db7214dd7746a0aa3a07jchu{
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp_kmem_ftsn_set_cache = kmem_cache_create("sctp_ftsn_set_cache",
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sizeof (sctp_ftsn_set_t), 0, NULL, NULL, NULL, NULL,
f8d2de6bd2421da1926f3daa456d161670decdf7jchu NULL, 0);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu}
8c3348818856b8366c07db7214dd7746a0aa3a07jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchuvoid
f8d2de6bd2421da1926f3daa456d161670decdf7jchusctp_ftsn_sets_fini(void)
f8d2de6bd2421da1926f3daa456d161670decdf7jchu{
f8d2de6bd2421da1926f3daa456d161670decdf7jchu kmem_cache_destroy(sctp_kmem_ftsn_set_cache);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu}
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchu/* Free PR-SCTP sets */
f8d2de6bd2421da1926f3daa456d161670decdf7jchuvoid
f8d2de6bd2421da1926f3daa456d161670decdf7jchusctp_free_ftsn_set(sctp_ftsn_set_t *s)
f8d2de6bd2421da1926f3daa456d161670decdf7jchu{
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp_ftsn_set_t *p;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchu while (s != NULL) {
bf8fc2340620695a402331e5da7c7db43264174det p = s->next;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu s->next = NULL;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu kmem_cache_free(sctp_kmem_ftsn_set_cache, s);
bf8fc2340620695a402331e5da7c7db43264174det s = p;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu}
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
8c3348818856b8366c07db7214dd7746a0aa3a07jchu/*
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * Given a message meta block, meta, this routine creates or modifies
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * the set that will be used to generate a Forward TSN chunk. If the
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * entry for stream id, sid, for this message already exists, the
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * sequence number, ssn, is updated if it is greater than the existing
8c3348818856b8366c07db7214dd7746a0aa3a07jchu * one. If an entry for this sid does not exist, one is created if
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * the size does not exceed fp->sfa_pmss. We return false in case
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * or an error.
f8d2de6bd2421da1926f3daa456d161670decdf7jchu */
f8d2de6bd2421da1926f3daa456d161670decdf7jchuboolean_t
f8d2de6bd2421da1926f3daa456d161670decdf7jchusctp_add_ftsn_set(sctp_ftsn_set_t **s, sctp_faddr_t *fp, mblk_t *meta,
f8d2de6bd2421da1926f3daa456d161670decdf7jchu uint_t *nsets, uint32_t *slen)
f8d2de6bd2421da1926f3daa456d161670decdf7jchu{
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp_ftsn_set_t *p;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp_msg_hdr_t *msg_hdr = (sctp_msg_hdr_t *)meta->b_rptr;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu uint16_t sid = htons(msg_hdr->smh_sid);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu /* msg_hdr->smh_ssn is already in NBO */
f8d2de6bd2421da1926f3daa456d161670decdf7jchu uint16_t ssn = msg_hdr->smh_ssn;
bf8fc2340620695a402331e5da7c7db43264174det
f8d2de6bd2421da1926f3daa456d161670decdf7jchu ASSERT(s != NULL && nsets != NULL);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu ASSERT((*nsets == 0 && *s == NULL) || (*nsets > 0 && *s != NULL));
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
bf8fc2340620695a402331e5da7c7db43264174det if (*s == NULL) {
bf8fc2340620695a402331e5da7c7db43264174det ASSERT((*slen + sizeof (uint32_t)) <= fp->sfa_pmss);
bf8fc2340620695a402331e5da7c7db43264174det *s = kmem_cache_alloc(sctp_kmem_ftsn_set_cache, KM_NOSLEEP);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (*s == NULL)
f8d2de6bd2421da1926f3daa456d161670decdf7jchu return (B_FALSE);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu (*s)->ftsn_entries.ftsn_sid = sid;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu (*s)->ftsn_entries.ftsn_ssn = ssn;
bf8fc2340620695a402331e5da7c7db43264174det (*s)->next = NULL;
bf8fc2340620695a402331e5da7c7db43264174det *nsets = 1;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu *slen += sizeof (uint32_t);
bf8fc2340620695a402331e5da7c7db43264174det return (B_TRUE);
bf8fc2340620695a402331e5da7c7db43264174det }
bf8fc2340620695a402331e5da7c7db43264174det for (p = *s; p->next != NULL; p = p->next) {
bf8fc2340620695a402331e5da7c7db43264174det if (p->ftsn_entries.ftsn_sid == sid) {
bf8fc2340620695a402331e5da7c7db43264174det if (SSN_GT(ssn, p->ftsn_entries.ftsn_ssn))
bf8fc2340620695a402331e5da7c7db43264174det p->ftsn_entries.ftsn_ssn = ssn;
bf8fc2340620695a402331e5da7c7db43264174det return (B_TRUE);
bf8fc2340620695a402331e5da7c7db43264174det }
bf8fc2340620695a402331e5da7c7db43264174det }
bf8fc2340620695a402331e5da7c7db43264174det /* the last one */
bf8fc2340620695a402331e5da7c7db43264174det if (p->ftsn_entries.ftsn_sid == sid) {
bf8fc2340620695a402331e5da7c7db43264174det if (SSN_GT(ssn, p->ftsn_entries.ftsn_ssn))
bf8fc2340620695a402331e5da7c7db43264174det p->ftsn_entries.ftsn_ssn = ssn;
bf8fc2340620695a402331e5da7c7db43264174det } else {
1ff6511282dda236fdea133a0fc53438d8c4f5fdegillett if ((*slen + sizeof (uint32_t)) > fp->sfa_pmss)
f8d2de6bd2421da1926f3daa456d161670decdf7jchu return (B_FALSE);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu p->next = kmem_cache_alloc(sctp_kmem_ftsn_set_cache,
bf8fc2340620695a402331e5da7c7db43264174det KM_NOSLEEP);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (p->next == NULL)
f8d2de6bd2421da1926f3daa456d161670decdf7jchu return (B_FALSE);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu p = p->next;
8c3348818856b8366c07db7214dd7746a0aa3a07jchu p->ftsn_entries.ftsn_sid = sid;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu p->ftsn_entries.ftsn_ssn = ssn;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu p->next = NULL;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu (*nsets)++;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu *slen += sizeof (uint32_t);
8c3348818856b8366c07db7214dd7746a0aa3a07jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu return (B_TRUE);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu}
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchu/*
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * Given a set of stream id - sequence number pairs, this routing creates
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * a Forward TSN chunk. The cumulative TSN (advanced peer ack point)
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * for the chunk is obtained from sctp->sctp_adv_pap. The caller
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * will add the IP/SCTP header.
f8d2de6bd2421da1926f3daa456d161670decdf7jchu */
f8d2de6bd2421da1926f3daa456d161670decdf7jchumblk_t *
f8d2de6bd2421da1926f3daa456d161670decdf7jchusctp_make_ftsn_chunk(sctp_t *sctp, sctp_faddr_t *fp, sctp_ftsn_set_t *sets,
f8d2de6bd2421da1926f3daa456d161670decdf7jchu uint_t nsets, uint32_t seglen)
f8d2de6bd2421da1926f3daa456d161670decdf7jchu{
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mblk_t *ftsn_mp;
bf8fc2340620695a402331e5da7c7db43264174det sctp_chunk_hdr_t *ch_hdr;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu uint32_t *advtsn;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu uint16_t schlen;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu size_t xtralen;
bf8fc2340620695a402331e5da7c7db43264174det ftsn_entry_t *ftsn_entry;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp_stack_t *sctps = sctp->sctp_sctps;
bf8fc2340620695a402331e5da7c7db43264174det
bf8fc2340620695a402331e5da7c7db43264174det seglen += sizeof (sctp_chunk_hdr_t);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (fp->isv4)
f8d2de6bd2421da1926f3daa456d161670decdf7jchu xtralen = sctp->sctp_hdr_len + sctps->sctps_wroff_xtra;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu else
f8d2de6bd2421da1926f3daa456d161670decdf7jchu xtralen = sctp->sctp_hdr6_len + sctps->sctps_wroff_xtra;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu ftsn_mp = allocb(xtralen + seglen, BPRI_MED);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (ftsn_mp == NULL)
bf8fc2340620695a402331e5da7c7db43264174det return (NULL);
bf8fc2340620695a402331e5da7c7db43264174det ftsn_mp->b_rptr += xtralen;
bf8fc2340620695a402331e5da7c7db43264174det ftsn_mp->b_wptr = ftsn_mp->b_rptr + seglen;
bf8fc2340620695a402331e5da7c7db43264174det
bf8fc2340620695a402331e5da7c7db43264174det ch_hdr = (sctp_chunk_hdr_t *)ftsn_mp->b_rptr;
bf8fc2340620695a402331e5da7c7db43264174det ch_hdr->sch_id = CHUNK_FORWARD_TSN;
bf8fc2340620695a402331e5da7c7db43264174det ch_hdr->sch_flags = 0;
bf8fc2340620695a402331e5da7c7db43264174det /*
bf8fc2340620695a402331e5da7c7db43264174det * The cast here should not be an issue since seglen is
bf8fc2340620695a402331e5da7c7db43264174det * the length of the Forward TSN chunk.
bf8fc2340620695a402331e5da7c7db43264174det */
bf8fc2340620695a402331e5da7c7db43264174det schlen = (uint16_t)seglen;
bf8fc2340620695a402331e5da7c7db43264174det U16_TO_ABE16(schlen, &(ch_hdr->sch_len));
bf8fc2340620695a402331e5da7c7db43264174det
1ff6511282dda236fdea133a0fc53438d8c4f5fdegillett advtsn = (uint32_t *)(ch_hdr + 1);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu U32_TO_ABE32(sctp->sctp_adv_pap, advtsn);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu ftsn_entry = (ftsn_entry_t *)(advtsn + 1);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu while (nsets > 0) {
bf8fc2340620695a402331e5da7c7db43264174det ASSERT((uchar_t *)&ftsn_entry[1] <= ftsn_mp->b_wptr);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu ftsn_entry->ftsn_sid = sets->ftsn_entries.ftsn_sid;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu ftsn_entry->ftsn_ssn = sets->ftsn_entries.ftsn_ssn;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu ftsn_entry++;
8c3348818856b8366c07db7214dd7746a0aa3a07jchu sets = sets->next;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu nsets--;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu return (ftsn_mp);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu}
8c3348818856b8366c07db7214dd7746a0aa3a07jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchu/*
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * Given a starting message, the routine steps through all the
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * messages whose TSN is less than sctp->sctp_adv_pap and creates
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * ftsn sets. The ftsn sets is then used to create an Forward TSN
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * chunk. All the messages, that have chunks that are included in the
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * ftsn sets, are flagged abandonded. If a message is partially sent
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * and is deemed abandoned, all remaining unsent chunks are marked
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * abandoned and are deducted from sctp_unsent.
f8d2de6bd2421da1926f3daa456d161670decdf7jchu */
f8d2de6bd2421da1926f3daa456d161670decdf7jchuvoid
f8d2de6bd2421da1926f3daa456d161670decdf7jchusctp_make_ftsns(sctp_t *sctp, mblk_t *meta, mblk_t *mp, mblk_t **nmp,
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp_faddr_t *fp, uint32_t *seglen)
f8d2de6bd2421da1926f3daa456d161670decdf7jchu{
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mblk_t *mp1 = mp;
bf8fc2340620695a402331e5da7c7db43264174det mblk_t *mp_head = mp;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mblk_t *meta_head = meta;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mblk_t *head;
bf8fc2340620695a402331e5da7c7db43264174det sctp_ftsn_set_t *sets = NULL;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu uint_t nsets = 0;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu uint16_t clen;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp_data_hdr_t *sdc;
8c3348818856b8366c07db7214dd7746a0aa3a07jchu uint32_t sacklen;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu uint32_t adv_pap = sctp->sctp_adv_pap;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu uint32_t unsent = 0;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu boolean_t ubit;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp_stack_t *sctps = sctp->sctp_sctps;
8c3348818856b8366c07db7214dd7746a0aa3a07jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchu *seglen = sizeof (uint32_t);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sdc = (sctp_data_hdr_t *)mp1->b_rptr;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu while (meta != NULL &&
f8d2de6bd2421da1926f3daa456d161670decdf7jchu SEQ_GEQ(sctp->sctp_adv_pap, ntohl(sdc->sdh_tsn))) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu /*
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * Skip adding FTSN sets for un-ordered messages as they do
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * not have SSNs.
f8d2de6bd2421da1926f3daa456d161670decdf7jchu */
f8d2de6bd2421da1926f3daa456d161670decdf7jchu ubit = SCTP_DATA_GET_UBIT(sdc);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (!ubit &&
f8d2de6bd2421da1926f3daa456d161670decdf7jchu !sctp_add_ftsn_set(&sets, fp, meta, &nsets, seglen)) {
bf8fc2340620695a402331e5da7c7db43264174det meta = NULL;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp->sctp_adv_pap = adv_pap;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu goto ftsn_done;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu while (mp1 != NULL && SCTP_CHUNK_ISSENT(mp1)) {
bf8fc2340620695a402331e5da7c7db43264174det sdc = (sctp_data_hdr_t *)mp1->b_rptr;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu adv_pap = ntohl(sdc->sdh_tsn);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mp1 = mp1->b_next;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu meta = meta->b_next;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (meta != NULL) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mp1 = meta->b_cont;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (!SCTP_CHUNK_ISSENT(mp1))
bf8fc2340620695a402331e5da7c7db43264174det break;
bf8fc2340620695a402331e5da7c7db43264174det sdc = (sctp_data_hdr_t *)mp1->b_rptr;
bf8fc2340620695a402331e5da7c7db43264174det }
bf8fc2340620695a402331e5da7c7db43264174det }
bf8fc2340620695a402331e5da7c7db43264174detftsn_done:
bf8fc2340620695a402331e5da7c7db43264174det /*
bf8fc2340620695a402331e5da7c7db43264174det * Can't compare with sets == NULL, since we don't add any
bf8fc2340620695a402331e5da7c7db43264174det * sets for un-ordered messages.
bf8fc2340620695a402331e5da7c7db43264174det */
bf8fc2340620695a402331e5da7c7db43264174det if (meta == meta_head)
bf8fc2340620695a402331e5da7c7db43264174det return;
bf8fc2340620695a402331e5da7c7db43264174det *nmp = sctp_make_ftsn_chunk(sctp, fp, sets, nsets, *seglen);
bf8fc2340620695a402331e5da7c7db43264174det sctp_free_ftsn_set(sets);
bf8fc2340620695a402331e5da7c7db43264174det if (*nmp == NULL)
1ff6511282dda236fdea133a0fc53438d8c4f5fdegillett return;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (sctp->sctp_ftsn == sctp->sctp_lastacked + 1) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sacklen = 0;
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz } else {
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz sacklen = sizeof (sctp_chunk_hdr_t) +
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz sizeof (sctp_sack_chunk_t) +
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz (sizeof (sctp_sack_frag_t) * sctp->sctp_sack_gaps);
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz if (*seglen + sacklen > sctp->sctp_lastdata->sfa_pmss) {
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz /* piggybacked SACK doesn't fit */
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz sacklen = 0;
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz } else {
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz fp = sctp->sctp_lastdata;
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz }
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz }
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz head = sctp_add_proto_hdr(sctp, fp, *nmp, sacklen, NULL);
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz if (head == NULL) {
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz freemsg(*nmp);
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz *nmp = NULL;
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz SCTP_KSTAT(sctps, sctp_send_ftsn_failed);
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz return;
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz }
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz *seglen += sacklen;
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz *nmp = head;
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz /*
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz * XXXNeed to optimise this, the reason it is done here is so
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz * that we don't have to undo in case of failure.
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz */
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz mp1 = mp_head;
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz sdc = (sctp_data_hdr_t *)mp1->b_rptr;
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz while (meta_head != NULL &&
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz SEQ_GEQ(sctp->sctp_adv_pap, ntohl(sdc->sdh_tsn))) {
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz if (!SCTP_IS_MSG_ABANDONED(meta_head))
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz SCTP_MSG_SET_ABANDONED(meta_head);
bf8fc2340620695a402331e5da7c7db43264174det while (mp1 != NULL && SCTP_CHUNK_ISSENT(mp1)) {
1ff6511282dda236fdea133a0fc53438d8c4f5fdegillett sdc = (sctp_data_hdr_t *)mp1->b_rptr;
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz if (!SCTP_CHUNK_ISACKED(mp1)) {
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz clen = ntohs(sdc->sdh_len) - sizeof (*sdc);
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz SCTP_CHUNK_SENT(sctp, mp1, sdc, fp, clen,
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz meta_head);
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz }
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz mp1 = mp1->b_next;
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz }
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz while (mp1 != NULL) {
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz sdc = (sctp_data_hdr_t *)mp1->b_rptr;
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz if (!SCTP_CHUNK_ABANDONED(mp1)) {
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz ASSERT(!SCTP_CHUNK_ISSENT(mp1));
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz unsent += ntohs(sdc->sdh_len) - sizeof (*sdc);
bf8fc2340620695a402331e5da7c7db43264174det SCTP_ABANDON_CHUNK(mp1);
1ff6511282dda236fdea133a0fc53438d8c4f5fdegillett }
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz mp1 = mp1->b_next;
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz }
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz meta_head = meta_head->b_next;
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz if (meta_head != NULL) {
f0a73f0415a4150b270534bc7ed2cbb77d87c5a2schwartz mp1 = meta_head->b_cont;
bf8fc2340620695a402331e5da7c7db43264174det if (!SCTP_CHUNK_ISSENT(mp1))
f8d2de6bd2421da1926f3daa456d161670decdf7jchu break;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sdc = (sctp_data_hdr_t *)mp1->b_rptr;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
8c3348818856b8366c07db7214dd7746a0aa3a07jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (unsent > 0) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu ASSERT(sctp->sctp_unsent >= unsent);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp->sctp_unsent -= unsent;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu /*
8c3348818856b8366c07db7214dd7746a0aa3a07jchu * Update ULP the amount of queued data, which is
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * sent-unack'ed + unsent.
f8d2de6bd2421da1926f3daa456d161670decdf7jchu */
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (!SCTP_IS_DETACHED(sctp))
f8d2de6bd2421da1926f3daa456d161670decdf7jchu SCTP_TXQ_UPDATE(sctp);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu}
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchu/*
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * This function steps through messages starting at meta and checks if
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * the message is abandoned. It stops when it hits an unsent chunk or
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * a message that has all its chunk acked. This is the only place
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * where the sctp_adv_pap is moved forward to indicated abandoned
bf8fc2340620695a402331e5da7c7db43264174det * messages.
f8d2de6bd2421da1926f3daa456d161670decdf7jchu */
f8d2de6bd2421da1926f3daa456d161670decdf7jchuvoid
bf8fc2340620695a402331e5da7c7db43264174detsctp_check_adv_ack_pt(sctp_t *sctp, mblk_t *meta, mblk_t *mp)
f8d2de6bd2421da1926f3daa456d161670decdf7jchu{
f8d2de6bd2421da1926f3daa456d161670decdf7jchu uint32_t tsn = sctp->sctp_adv_pap;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp_data_hdr_t *sdc;
8c3348818856b8366c07db7214dd7746a0aa3a07jchu sctp_msg_hdr_t *msg_hdr;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchu ASSERT(mp != NULL);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sdc = (sctp_data_hdr_t *)mp->b_rptr;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu ASSERT(SEQ_GT(ntohl(sdc->sdh_tsn), sctp->sctp_lastack_rxd));
8c3348818856b8366c07db7214dd7746a0aa3a07jchu msg_hdr = (sctp_msg_hdr_t *)meta->b_rptr;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (!SCTP_IS_MSG_ABANDONED(meta) &&
f8d2de6bd2421da1926f3daa456d161670decdf7jchu !SCTP_MSG_TO_BE_ABANDONED(meta, msg_hdr, sctp)) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu return;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu while (meta != NULL) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu while (mp != NULL && SCTP_CHUNK_ISSENT(mp)) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sdc = (sctp_data_hdr_t *)mp->b_rptr;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu tsn = ntohl(sdc->sdh_tsn);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mp = mp->b_next;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (mp != NULL)
f8d2de6bd2421da1926f3daa456d161670decdf7jchu break;
bf8fc2340620695a402331e5da7c7db43264174det /*
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * We continue checking for successive messages only if there
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * is a chunk marked for retransmission. Else, we might
bf8fc2340620695a402331e5da7c7db43264174det * end up sending FTSN prematurely for chunks that have been
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * sent, but not yet acked.
f8d2de6bd2421da1926f3daa456d161670decdf7jchu */
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if ((meta = meta->b_next) != NULL) {
8c3348818856b8366c07db7214dd7746a0aa3a07jchu msg_hdr = (sctp_msg_hdr_t *)meta->b_rptr;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (!SCTP_IS_MSG_ABANDONED(meta) &&
f8d2de6bd2421da1926f3daa456d161670decdf7jchu !SCTP_MSG_TO_BE_ABANDONED(meta, msg_hdr, sctp)) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu break;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
8c3348818856b8366c07db7214dd7746a0aa3a07jchu for (mp = meta->b_cont; mp != NULL; mp = mp->b_next) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (!SCTP_CHUNK_ISSENT(mp)) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp->sctp_adv_pap = tsn;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu return;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (SCTP_CHUNK_WANT_REXMIT(mp))
f8d2de6bd2421da1926f3daa456d161670decdf7jchu break;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (mp == NULL)
f8d2de6bd2421da1926f3daa456d161670decdf7jchu break;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp->sctp_adv_pap = tsn;
bf8fc2340620695a402331e5da7c7db43264174det}
1a887b2e15e4d9b63b5add57f3334b5b31960018jchu
1a887b2e15e4d9b63b5add57f3334b5b31960018jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchu/*
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * Determine if we should bundle a data chunk with the chunk being
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * retransmitted. We bundle if
f8d2de6bd2421da1926f3daa456d161670decdf7jchu *
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * - the chunk is sent to the same destination and unack'ed.
f8d2de6bd2421da1926f3daa456d161670decdf7jchu *
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * OR
bf8fc2340620695a402331e5da7c7db43264174det *
bf8fc2340620695a402331e5da7c7db43264174det * - the chunk is unsent, i.e. new data.
bf8fc2340620695a402331e5da7c7db43264174det */
e51949e6deb4cb79dcb0772d225868626ae52517dduvall#define SCTP_CHUNK_RX_CANBUNDLE(mp, fp) \
bf8fc2340620695a402331e5da7c7db43264174det (!SCTP_CHUNK_ABANDONED((mp)) && \
bf8fc2340620695a402331e5da7c7db43264174det ((SCTP_CHUNK_ISSENT((mp)) && (SCTP_CHUNK_DEST(mp) == (fp) && \
1ff6511282dda236fdea133a0fc53438d8c4f5fdegillett !SCTP_CHUNK_ISACKED(mp))) || \
bf8fc2340620695a402331e5da7c7db43264174det (((mp)->b_flag & (SCTP_CHUNK_FLAG_REXMIT|SCTP_CHUNK_FLAG_SENT)) != \
bf8fc2340620695a402331e5da7c7db43264174det SCTP_CHUNK_FLAG_SENT)))
1ff6511282dda236fdea133a0fc53438d8c4f5fdegillett
bf8fc2340620695a402331e5da7c7db43264174det/*
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * Retransmit first segment which hasn't been acked with cumtsn or send
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * a Forward TSN chunk, if appropriate.
bf8fc2340620695a402331e5da7c7db43264174det */
f8d2de6bd2421da1926f3daa456d161670decdf7jchuvoid
f8d2de6bd2421da1926f3daa456d161670decdf7jchusctp_rexmit(sctp_t *sctp, sctp_faddr_t *oldfp)
f8d2de6bd2421da1926f3daa456d161670decdf7jchu{
8c3348818856b8366c07db7214dd7746a0aa3a07jchu mblk_t *mp;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mblk_t *nmp = NULL;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mblk_t *head;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mblk_t *meta = sctp->sctp_xmit_head;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mblk_t *fill;
8c3348818856b8366c07db7214dd7746a0aa3a07jchu uint32_t seglen = 0;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu uint32_t sacklen;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu uint16_t chunklen;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu int extra;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp_data_hdr_t *sdc;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp_faddr_t *fp;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu uint32_t adv_pap = sctp->sctp_adv_pap;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu boolean_t do_ftsn = B_FALSE;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu boolean_t ftsn_check = B_TRUE;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu uint32_t first_ua_tsn;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp_msg_hdr_t *mhdr;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp_stack_t *sctps = sctp->sctp_sctps;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu int error;
bf8fc2340620695a402331e5da7c7db43264174det
f8d2de6bd2421da1926f3daa456d161670decdf7jchu while (meta != NULL) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu for (mp = meta->b_cont; mp != NULL; mp = mp->b_next) {
bf8fc2340620695a402331e5da7c7db43264174det uint32_t tsn;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (!SCTP_CHUNK_ISSENT(mp))
f8d2de6bd2421da1926f3daa456d161670decdf7jchu goto window_probe;
8c3348818856b8366c07db7214dd7746a0aa3a07jchu /*
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * We break in the following cases -
f8d2de6bd2421da1926f3daa456d161670decdf7jchu *
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * if the advanced peer ack point includes the next
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * chunk to be retransmited - possibly the Forward
8c3348818856b8366c07db7214dd7746a0aa3a07jchu * TSN was lost.
f8d2de6bd2421da1926f3daa456d161670decdf7jchu *
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * if we are PRSCTP aware and the next chunk to be
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * retransmitted is now abandoned
f8d2de6bd2421da1926f3daa456d161670decdf7jchu *
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * if the next chunk to be retransmitted is for
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * the dest on which the timer went off. (this
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * message is not abandoned).
f8d2de6bd2421da1926f3daa456d161670decdf7jchu *
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * We check for Forward TSN only for the first
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * eligible chunk to be retransmitted. The reason
bf8fc2340620695a402331e5da7c7db43264174det * being if the first eligible chunk is skipped (say
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * it was sent to a destination other than oldfp)
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * then we cannot advance the cum TSN via Forward
bf8fc2340620695a402331e5da7c7db43264174det * TSN chunk.
f8d2de6bd2421da1926f3daa456d161670decdf7jchu *
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * Also, ftsn_check is B_TRUE only for the first
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * eligible chunk, it will be B_FALSE for all
8c3348818856b8366c07db7214dd7746a0aa3a07jchu * subsequent candidate messages for retransmission.
bf8fc2340620695a402331e5da7c7db43264174det */
c85864d8472aaccb47ceb468ebd9b3a85b66d161Krishna Elango sdc = (sctp_data_hdr_t *)mp->b_rptr;
bf8fc2340620695a402331e5da7c7db43264174det tsn = ntohl(sdc->sdh_tsn);
bf8fc2340620695a402331e5da7c7db43264174det if (SEQ_GT(tsn, sctp->sctp_lastack_rxd)) {
bf8fc2340620695a402331e5da7c7db43264174det if (sctp->sctp_prsctp_aware && ftsn_check) {
bf8fc2340620695a402331e5da7c7db43264174det if (SEQ_GEQ(sctp->sctp_adv_pap, tsn)) {
bf8fc2340620695a402331e5da7c7db43264174det ASSERT(sctp->sctp_prsctp_aware);
bf8fc2340620695a402331e5da7c7db43264174det do_ftsn = B_TRUE;
bf8fc2340620695a402331e5da7c7db43264174det goto out;
bf8fc2340620695a402331e5da7c7db43264174det } else {
bf8fc2340620695a402331e5da7c7db43264174det sctp_check_adv_ack_pt(sctp,
bf8fc2340620695a402331e5da7c7db43264174det meta, mp);
bf8fc2340620695a402331e5da7c7db43264174det if (SEQ_GT(sctp->sctp_adv_pap,
f8d2de6bd2421da1926f3daa456d161670decdf7jchu adv_pap)) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu do_ftsn = B_TRUE;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl goto out;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
8c3348818856b8366c07db7214dd7746a0aa3a07jchu ftsn_check = B_FALSE;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (SCTP_CHUNK_DEST(mp) == oldfp)
f8d2de6bd2421da1926f3daa456d161670decdf7jchu goto out;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu meta = meta->b_next;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (meta != NULL && sctp->sctp_prsctp_aware) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mhdr = (sctp_msg_hdr_t *)meta->b_rptr;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchu while (meta != NULL && (SCTP_IS_MSG_ABANDONED(meta) ||
f8d2de6bd2421da1926f3daa456d161670decdf7jchu SCTP_MSG_TO_BE_ABANDONED(meta, mhdr, sctp))) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu meta = meta->b_next;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
bf8fc2340620695a402331e5da7c7db43264174det }
f8d2de6bd2421da1926f3daa456d161670decdf7jchuwindow_probe:
f8d2de6bd2421da1926f3daa456d161670decdf7jchu /*
bf8fc2340620695a402331e5da7c7db43264174det * Retransmit fired for a destination which didn't have
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * any unacked data pending.
f8d2de6bd2421da1926f3daa456d161670decdf7jchu */
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (sctp->sctp_unacked == 0 && sctp->sctp_unsent != 0) {
8c3348818856b8366c07db7214dd7746a0aa3a07jchu /*
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * Send a window probe. Inflate frwnd to allow
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * sending one segment.
f8d2de6bd2421da1926f3daa456d161670decdf7jchu */
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (sctp->sctp_frwnd < (oldfp->sfa_pmss - sizeof (*sdc)))
8c3348818856b8366c07db7214dd7746a0aa3a07jchu sctp->sctp_frwnd = oldfp->sfa_pmss - sizeof (*sdc);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchu /* next TSN to send */
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp->sctp_rxt_nxttsn = sctp->sctp_ltsn;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchu /*
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * The above sctp_frwnd adjustment is coarse. The "changed"
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * sctp_frwnd may allow us to send more than 1 packet. So
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * tell sctp_output() to send only 1 packet.
f8d2de6bd2421da1926f3daa456d161670decdf7jchu */
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp_output(sctp, 1);
bf8fc2340620695a402331e5da7c7db43264174det
f8d2de6bd2421da1926f3daa456d161670decdf7jchu /* Last sent TSN */
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp->sctp_rxt_maxtsn = sctp->sctp_ltsn - 1;
bf8fc2340620695a402331e5da7c7db43264174det ASSERT(sctp->sctp_rxt_maxtsn >= sctp->sctp_rxt_nxttsn);
bf8fc2340620695a402331e5da7c7db43264174det sctp->sctp_zero_win_probe = B_TRUE;
bf8fc2340620695a402331e5da7c7db43264174det SCTPS_BUMP_MIB(sctps, sctpOutWinProbe);
bf8fc2340620695a402331e5da7c7db43264174det }
bf8fc2340620695a402331e5da7c7db43264174det return;
bf8fc2340620695a402331e5da7c7db43264174detout:
bf8fc2340620695a402331e5da7c7db43264174det /*
bf8fc2340620695a402331e5da7c7db43264174det * After a time out, assume that everything has left the network. So
bf8fc2340620695a402331e5da7c7db43264174det * we can clear rxt_unacked for the original peer address.
bf8fc2340620695a402331e5da7c7db43264174det */
bf8fc2340620695a402331e5da7c7db43264174det oldfp->rxt_unacked = 0;
bf8fc2340620695a402331e5da7c7db43264174det
f8d2de6bd2421da1926f3daa456d161670decdf7jchu /*
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * If we were probing for zero window, don't adjust retransmission
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * variables, but the timer is still backed off.
f8d2de6bd2421da1926f3daa456d161670decdf7jchu */
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (sctp->sctp_zero_win_probe) {
bf8fc2340620695a402331e5da7c7db43264174det mblk_t *pkt;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu uint_t pkt_len;
bf8fc2340620695a402331e5da7c7db43264174det
bf8fc2340620695a402331e5da7c7db43264174det /*
8c3348818856b8366c07db7214dd7746a0aa3a07jchu * Get the Zero Win Probe for retrasmission, sctp_rxt_nxttsn
bf8fc2340620695a402331e5da7c7db43264174det * and sctp_rxt_maxtsn will specify the ZWP packet.
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae */
bf8fc2340620695a402331e5da7c7db43264174det fp = oldfp;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (oldfp->state != SCTP_FADDRS_ALIVE)
bf8fc2340620695a402331e5da7c7db43264174det fp = sctp_rotate_faddr(sctp, oldfp);
bf8fc2340620695a402331e5da7c7db43264174det pkt = sctp_rexmit_packet(sctp, &meta, &mp, fp, &pkt_len);
1ff6511282dda236fdea133a0fc53438d8c4f5fdegillett if (pkt != NULL) {
bf8fc2340620695a402331e5da7c7db43264174det ASSERT(pkt_len <= fp->sfa_pmss);
3677cad460dda50d22a04d36a3f544a82344d940et sctp_set_iplen(sctp, pkt, fp->ixa);
bf8fc2340620695a402331e5da7c7db43264174det (void) conn_ip_output(pkt, fp->ixa);
bf8fc2340620695a402331e5da7c7db43264174det BUMP_LOCAL(sctp->sctp_opkts);
bf8fc2340620695a402331e5da7c7db43264174det } else {
bf8fc2340620695a402331e5da7c7db43264174det SCTP_KSTAT(sctps, sctp_ss_rexmit_failed);
bf8fc2340620695a402331e5da7c7db43264174det }
bf8fc2340620695a402331e5da7c7db43264174det
bf8fc2340620695a402331e5da7c7db43264174det /*
bf8fc2340620695a402331e5da7c7db43264174det * The strikes will be clear by sctp_faddr_alive() when the
bf8fc2340620695a402331e5da7c7db43264174det * other side sends us an ack.
bf8fc2340620695a402331e5da7c7db43264174det */
bf8fc2340620695a402331e5da7c7db43264174det oldfp->strikes++;
bf8fc2340620695a402331e5da7c7db43264174det sctp->sctp_strikes++;
bf8fc2340620695a402331e5da7c7db43264174det
bf8fc2340620695a402331e5da7c7db43264174det SCTP_CALC_RXT(sctp, oldfp, sctp->sctp_rto_max);
bf8fc2340620695a402331e5da7c7db43264174det if (oldfp != fp && oldfp->suna != 0)
bf8fc2340620695a402331e5da7c7db43264174det SCTP_FADDR_TIMER_RESTART(sctp, oldfp, fp->rto);
bf8fc2340620695a402331e5da7c7db43264174det SCTP_FADDR_TIMER_RESTART(sctp, fp, fp->rto);
bf8fc2340620695a402331e5da7c7db43264174det SCTPS_BUMP_MIB(sctps, sctpOutWinProbe);
e51949e6deb4cb79dcb0772d225868626ae52517dduvall return;
bf8fc2340620695a402331e5da7c7db43264174det }
bf8fc2340620695a402331e5da7c7db43264174det
e51949e6deb4cb79dcb0772d225868626ae52517dduvall /*
bf8fc2340620695a402331e5da7c7db43264174det * Enter slowstart for this destination
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae */
bf8fc2340620695a402331e5da7c7db43264174det oldfp->ssthresh = oldfp->cwnd / 2;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (oldfp->ssthresh < 2 * oldfp->sfa_pmss)
bf8fc2340620695a402331e5da7c7db43264174det oldfp->ssthresh = 2 * oldfp->sfa_pmss;
bf8fc2340620695a402331e5da7c7db43264174det oldfp->cwnd = oldfp->sfa_pmss;
1ff6511282dda236fdea133a0fc53438d8c4f5fdegillett oldfp->pba = 0;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu fp = sctp_rotate_faddr(sctp, oldfp);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu ASSERT(fp != NULL);
bf8fc2340620695a402331e5da7c7db43264174det sdc = (sctp_data_hdr_t *)mp->b_rptr;
bf8fc2340620695a402331e5da7c7db43264174det
bf8fc2340620695a402331e5da7c7db43264174det first_ua_tsn = ntohl(sdc->sdh_tsn);
bf8fc2340620695a402331e5da7c7db43264174det if (do_ftsn) {
bf8fc2340620695a402331e5da7c7db43264174det sctp_make_ftsns(sctp, meta, mp, &nmp, fp, &seglen);
bf8fc2340620695a402331e5da7c7db43264174det if (nmp == NULL) {
bf8fc2340620695a402331e5da7c7db43264174det sctp->sctp_adv_pap = adv_pap;
bf8fc2340620695a402331e5da7c7db43264174det goto restart_timer;
bf8fc2340620695a402331e5da7c7db43264174det }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu head = nmp;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu /*
bf8fc2340620695a402331e5da7c7db43264174det * Move to the next unabandoned chunk. XXXCheck if meta will
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * always be marked abandoned.
f8d2de6bd2421da1926f3daa456d161670decdf7jchu */
f8d2de6bd2421da1926f3daa456d161670decdf7jchu while (meta != NULL && SCTP_IS_MSG_ABANDONED(meta))
bf8fc2340620695a402331e5da7c7db43264174det meta = meta->b_next;
bf8fc2340620695a402331e5da7c7db43264174det if (meta != NULL)
1ff6511282dda236fdea133a0fc53438d8c4f5fdegillett mp = mp->b_cont;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu else
bf8fc2340620695a402331e5da7c7db43264174det mp = NULL;
bf8fc2340620695a402331e5da7c7db43264174det goto try_bundle;
8c3348818856b8366c07db7214dd7746a0aa3a07jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu seglen = ntohs(sdc->sdh_len);
bf8fc2340620695a402331e5da7c7db43264174det chunklen = seglen - sizeof (*sdc);
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae if ((extra = seglen & (SCTP_ALIGN - 1)) != 0)
bf8fc2340620695a402331e5da7c7db43264174det extra = SCTP_ALIGN - extra;
bf8fc2340620695a402331e5da7c7db43264174det
bf8fc2340620695a402331e5da7c7db43264174det /* Find out if we need to piggyback SACK. */
1ff6511282dda236fdea133a0fc53438d8c4f5fdegillett if (sctp->sctp_ftsn == sctp->sctp_lastacked + 1) {
bf8fc2340620695a402331e5da7c7db43264174det sacklen = 0;
1ff6511282dda236fdea133a0fc53438d8c4f5fdegillett } else {
bf8fc2340620695a402331e5da7c7db43264174det sacklen = sizeof (sctp_chunk_hdr_t) +
bf8fc2340620695a402331e5da7c7db43264174det sizeof (sctp_sack_chunk_t) +
1ff6511282dda236fdea133a0fc53438d8c4f5fdegillett (sizeof (sctp_sack_frag_t) * sctp->sctp_sack_gaps);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (seglen + sacklen > sctp->sctp_lastdata->sfa_pmss) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu /* piggybacked SACK doesn't fit */
bf8fc2340620695a402331e5da7c7db43264174det sacklen = 0;
bf8fc2340620695a402331e5da7c7db43264174det } else {
bf8fc2340620695a402331e5da7c7db43264174det /*
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * OK, we have room to send SACK back. But we
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * should send it back to the last fp where we
bf8fc2340620695a402331e5da7c7db43264174det * receive data from, unless sctp_lastdata equals
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * oldfp, then we should probably not send it
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * back to that fp. Also we should check that
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * the fp is alive.
bf8fc2340620695a402331e5da7c7db43264174det */
bf8fc2340620695a402331e5da7c7db43264174det if (sctp->sctp_lastdata != oldfp &&
bf8fc2340620695a402331e5da7c7db43264174det sctp->sctp_lastdata->state == SCTP_FADDRS_ALIVE) {
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae fp = sctp->sctp_lastdata;
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae }
bf8fc2340620695a402331e5da7c7db43264174det }
bf8fc2340620695a402331e5da7c7db43264174det }
bf8fc2340620695a402331e5da7c7db43264174det
bf8fc2340620695a402331e5da7c7db43264174det /*
bf8fc2340620695a402331e5da7c7db43264174det * Cancel RTT measurement if the retransmitted TSN is before the
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae * TSN used for timimg.
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae */
bf8fc2340620695a402331e5da7c7db43264174det if (sctp->sctp_out_time != 0 &&
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae SEQ_GEQ(sctp->sctp_rtt_tsn, sdc->sdh_tsn)) {
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae sctp->sctp_out_time = 0;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
07d06da50d310a325b457d6330165aebab1e0064Surya Prakki /* Clear the counter as the RTT calculation may be off. */
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae fp->rtt_updates = 0;
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae oldfp->rtt_updates = 0;
bf8fc2340620695a402331e5da7c7db43264174det
bf8fc2340620695a402331e5da7c7db43264174det /*
bf8fc2340620695a402331e5da7c7db43264174det * After a timeout, we should change the current faddr so that
1ff6511282dda236fdea133a0fc53438d8c4f5fdegillett * new chunks will be sent to the alternate address.
e51949e6deb4cb79dcb0772d225868626ae52517dduvall */
bf8fc2340620695a402331e5da7c7db43264174det sctp_set_faddr_current(sctp, fp);
1ff6511282dda236fdea133a0fc53438d8c4f5fdegillett
f8d2de6bd2421da1926f3daa456d161670decdf7jchu nmp = dupmsg(mp);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (nmp == NULL)
1a887b2e15e4d9b63b5add57f3334b5b31960018jchu goto restart_timer;
f9721e075222d67dfc8cab85ccca4a17f1eb8325jchu if (extra > 0) {
f9721e075222d67dfc8cab85ccca4a17f1eb8325jchu fill = sctp_get_padding(sctp, extra);
1a887b2e15e4d9b63b5add57f3334b5b31960018jchu if (fill != NULL) {
1a887b2e15e4d9b63b5add57f3334b5b31960018jchu linkb(nmp, fill);
1a887b2e15e4d9b63b5add57f3334b5b31960018jchu seglen += extra;
1a887b2e15e4d9b63b5add57f3334b5b31960018jchu } else {
1a887b2e15e4d9b63b5add57f3334b5b31960018jchu freemsg(nmp);
1a887b2e15e4d9b63b5add57f3334b5b31960018jchu goto restart_timer;
1a887b2e15e4d9b63b5add57f3334b5b31960018jchu }
1a887b2e15e4d9b63b5add57f3334b5b31960018jchu }
1a887b2e15e4d9b63b5add57f3334b5b31960018jchu SCTP_CHUNK_CLEAR_FLAGS(nmp);
1a887b2e15e4d9b63b5add57f3334b5b31960018jchu head = sctp_add_proto_hdr(sctp, fp, nmp, sacklen, NULL);
f9721e075222d67dfc8cab85ccca4a17f1eb8325jchu if (head == NULL) {
f9721e075222d67dfc8cab85ccca4a17f1eb8325jchu freemsg(nmp);
f9721e075222d67dfc8cab85ccca4a17f1eb8325jchu SCTP_KSTAT(sctps, sctp_rexmit_failed);
f9721e075222d67dfc8cab85ccca4a17f1eb8325jchu goto restart_timer;
1a887b2e15e4d9b63b5add57f3334b5b31960018jchu }
f9721e075222d67dfc8cab85ccca4a17f1eb8325jchu seglen += sacklen;
bf8fc2340620695a402331e5da7c7db43264174det
f9721e075222d67dfc8cab85ccca4a17f1eb8325jchu SCTP_CHUNK_SENT(sctp, mp, sdc, fp, chunklen, meta);
1a887b2e15e4d9b63b5add57f3334b5b31960018jchu
f9721e075222d67dfc8cab85ccca4a17f1eb8325jchu mp = mp->b_next;
f9721e075222d67dfc8cab85ccca4a17f1eb8325jchu
f9721e075222d67dfc8cab85ccca4a17f1eb8325jchutry_bundle:
f9721e075222d67dfc8cab85ccca4a17f1eb8325jchu /* We can at least and at most send 1 packet at timeout. */
f9721e075222d67dfc8cab85ccca4a17f1eb8325jchu while (seglen < fp->sfa_pmss) {
f9721e075222d67dfc8cab85ccca4a17f1eb8325jchu int32_t new_len;
f9721e075222d67dfc8cab85ccca4a17f1eb8325jchu
f9721e075222d67dfc8cab85ccca4a17f1eb8325jchu /* Go through the list to find more chunks to be bundled. */
f9721e075222d67dfc8cab85ccca4a17f1eb8325jchu while (mp != NULL) {
f9721e075222d67dfc8cab85ccca4a17f1eb8325jchu /* Check if the chunk can be bundled. */
f9721e075222d67dfc8cab85ccca4a17f1eb8325jchu if (SCTP_CHUNK_RX_CANBUNDLE(mp, oldfp))
bf8fc2340620695a402331e5da7c7db43264174det break;
bf8fc2340620695a402331e5da7c7db43264174det mp = mp->b_next;
1a887b2e15e4d9b63b5add57f3334b5b31960018jchu }
1a887b2e15e4d9b63b5add57f3334b5b31960018jchu /* Go to the next message. */
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (mp == NULL) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu for (meta = meta->b_next; meta != NULL;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu meta = meta->b_next) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mhdr = (sctp_msg_hdr_t *)meta->b_rptr;
8c3348818856b8366c07db7214dd7746a0aa3a07jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (SCTP_IS_MSG_ABANDONED(meta) ||
f8d2de6bd2421da1926f3daa456d161670decdf7jchu SCTP_MSG_TO_BE_ABANDONED(meta, mhdr,
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp)) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu continue;
8c3348818856b8366c07db7214dd7746a0aa3a07jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchu mp = meta->b_cont;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu goto try_bundle;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu /*
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * Check if there is a new message which potentially
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * could be bundled with this retransmission.
f8d2de6bd2421da1926f3daa456d161670decdf7jchu */
f8d2de6bd2421da1926f3daa456d161670decdf7jchu meta = sctp_get_msg_to_send(sctp, &mp, NULL, &error,
f8d2de6bd2421da1926f3daa456d161670decdf7jchu seglen, fp->sfa_pmss - seglen, NULL);
bf8fc2340620695a402331e5da7c7db43264174det if (error != 0 || meta == NULL) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu /* No more chunk to be bundled. */
f8d2de6bd2421da1926f3daa456d161670decdf7jchu break;
8bc7d88a7ed8565440a3cb4d316b626938433668et } else {
8bc7d88a7ed8565440a3cb4d316b626938433668et goto try_bundle;
b40cec45c74e847c9d8b99b835ab69a64e7d1a59krishnae }
8bc7d88a7ed8565440a3cb4d316b626938433668et }
8bc7d88a7ed8565440a3cb4d316b626938433668et
8bc7d88a7ed8565440a3cb4d316b626938433668et sdc = (sctp_data_hdr_t *)mp->b_rptr;
8bc7d88a7ed8565440a3cb4d316b626938433668et new_len = ntohs(sdc->sdh_len);
bf8fc2340620695a402331e5da7c7db43264174det chunklen = new_len - sizeof (*sdc);
bf8fc2340620695a402331e5da7c7db43264174det
bf8fc2340620695a402331e5da7c7db43264174det if ((extra = new_len & (SCTP_ALIGN - 1)) != 0)
bf8fc2340620695a402331e5da7c7db43264174det extra = SCTP_ALIGN - extra;
bf8fc2340620695a402331e5da7c7db43264174det if ((new_len = seglen + new_len + extra) > fp->sfa_pmss)
bf8fc2340620695a402331e5da7c7db43264174det break;
bf8fc2340620695a402331e5da7c7db43264174det if ((nmp = dupmsg(mp)) == NULL)
bf8fc2340620695a402331e5da7c7db43264174det break;
bf8fc2340620695a402331e5da7c7db43264174det
bf8fc2340620695a402331e5da7c7db43264174det if (extra > 0) {
bf8fc2340620695a402331e5da7c7db43264174det fill = sctp_get_padding(sctp, extra);
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae if (fill != NULL) {
bf8fc2340620695a402331e5da7c7db43264174det linkb(nmp, fill);
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae } else {
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae freemsg(nmp);
bf8fc2340620695a402331e5da7c7db43264174det break;
bf8fc2340620695a402331e5da7c7db43264174det }
bf8fc2340620695a402331e5da7c7db43264174det }
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae linkb(head, nmp);
bf8fc2340620695a402331e5da7c7db43264174det
bf8fc2340620695a402331e5da7c7db43264174det SCTP_CHUNK_CLEAR_FLAGS(nmp);
bf8fc2340620695a402331e5da7c7db43264174det SCTP_CHUNK_SENT(sctp, mp, sdc, fp, chunklen, meta);
bf8fc2340620695a402331e5da7c7db43264174det
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae seglen = new_len;
bf8fc2340620695a402331e5da7c7db43264174det mp = mp->b_next;
bf8fc2340620695a402331e5da7c7db43264174det }
bf8fc2340620695a402331e5da7c7db43264174detdone_bundle:
bf8fc2340620695a402331e5da7c7db43264174det if ((seglen > fp->sfa_pmss) && fp->isv4) {
8bc7d88a7ed8565440a3cb4d316b626938433668et ipha_t *iph = (ipha_t *)head->b_rptr;
5613d828c3413db2a71d47fbbc385a3f7a23d908Krishna Elango
bf8fc2340620695a402331e5da7c7db43264174det /*
455c986069737584e38ba5b6e84f6052bebc0cf9krishnae * Path MTU is different from path we thought it would
bf8fc2340620695a402331e5da7c7db43264174det * be when we created chunks, or IP headers have grown.
1ff6511282dda236fdea133a0fc53438d8c4f5fdegillett * Need to clear the DF bit.
bf8fc2340620695a402331e5da7c7db43264174det */
bf8fc2340620695a402331e5da7c7db43264174det iph->ipha_fragment_offset_and_flags = 0;
1ff6511282dda236fdea133a0fc53438d8c4f5fdegillett }
bf8fc2340620695a402331e5da7c7db43264174det fp->rxt_unacked += seglen;
8bc7d88a7ed8565440a3cb4d316b626938433668et
8bc7d88a7ed8565440a3cb4d316b626938433668et dprint(2, ("sctp_rexmit: Sending packet %d bytes, tsn %x "
bf8fc2340620695a402331e5da7c7db43264174det "ssn %d to %p (rwnd %d, lastack_rxd %x)\n",
8bc7d88a7ed8565440a3cb4d316b626938433668et seglen, ntohl(sdc->sdh_tsn), ntohs(sdc->sdh_ssn),
8bc7d88a7ed8565440a3cb4d316b626938433668et (void *)fp, sctp->sctp_frwnd, sctp->sctp_lastack_rxd));
8bc7d88a7ed8565440a3cb4d316b626938433668et
8c3348818856b8366c07db7214dd7746a0aa3a07jchu sctp->sctp_rexmitting = B_TRUE;
8bc7d88a7ed8565440a3cb4d316b626938433668et sctp->sctp_rxt_nxttsn = first_ua_tsn;
8bc7d88a7ed8565440a3cb4d316b626938433668et sctp->sctp_rxt_maxtsn = sctp->sctp_ltsn - 1;
8bc7d88a7ed8565440a3cb4d316b626938433668et sctp_set_iplen(sctp, head, fp->ixa);
8bc7d88a7ed8565440a3cb4d316b626938433668et (void) conn_ip_output(head, fp->ixa);
8c3348818856b8366c07db7214dd7746a0aa3a07jchu BUMP_LOCAL(sctp->sctp_opkts);
8bc7d88a7ed8565440a3cb4d316b626938433668et
8bc7d88a7ed8565440a3cb4d316b626938433668et /*
8bc7d88a7ed8565440a3cb4d316b626938433668et * Restart the oldfp timer with exponential backoff and
8bc7d88a7ed8565440a3cb4d316b626938433668et * the new fp timer for the retransmitted chunks.
8bc7d88a7ed8565440a3cb4d316b626938433668et */
8bc7d88a7ed8565440a3cb4d316b626938433668etrestart_timer:
8bc7d88a7ed8565440a3cb4d316b626938433668et oldfp->strikes++;
8bc7d88a7ed8565440a3cb4d316b626938433668et sctp->sctp_strikes++;
8bc7d88a7ed8565440a3cb4d316b626938433668et SCTP_CALC_RXT(sctp, oldfp, sctp->sctp_rto_max);
8bc7d88a7ed8565440a3cb4d316b626938433668et /*
8bc7d88a7ed8565440a3cb4d316b626938433668et * If there is still some data in the oldfp, restart the
8bc7d88a7ed8565440a3cb4d316b626938433668et * retransmission timer. If there is no data, the heartbeat will
8bc7d88a7ed8565440a3cb4d316b626938433668et * continue to run so it will do its job in checking the reachability
8bc7d88a7ed8565440a3cb4d316b626938433668et * of the oldfp.
bf8fc2340620695a402331e5da7c7db43264174det */
8bc7d88a7ed8565440a3cb4d316b626938433668et if (oldfp != fp && oldfp->suna != 0)
8bc7d88a7ed8565440a3cb4d316b626938433668et SCTP_FADDR_TIMER_RESTART(sctp, oldfp, oldfp->rto);
bf8fc2340620695a402331e5da7c7db43264174det
8bc7d88a7ed8565440a3cb4d316b626938433668et /*
8bc7d88a7ed8565440a3cb4d316b626938433668et * Should we restart the timer of the new fp? If there is
8bc7d88a7ed8565440a3cb4d316b626938433668et * outstanding data to the new fp, the timer should be
8c3348818856b8366c07db7214dd7746a0aa3a07jchu * running already. So restarting it means that the timer
8bc7d88a7ed8565440a3cb4d316b626938433668et * will fire later for those outstanding data. But if
8bc7d88a7ed8565440a3cb4d316b626938433668et * we don't restart it, the timer will fire too early for the
8bc7d88a7ed8565440a3cb4d316b626938433668et * just retransmitted chunks to the new fp. The reason is that we
8bc7d88a7ed8565440a3cb4d316b626938433668et * don't keep a timestamp on when a chunk is retransmitted.
8c3348818856b8366c07db7214dd7746a0aa3a07jchu * So when the timer fires, it will just search for the
8bc7d88a7ed8565440a3cb4d316b626938433668et * chunk with the earliest TSN sent to new fp. This probably
8bc7d88a7ed8565440a3cb4d316b626938433668et * is the chunk we just retransmitted. So for now, let's
8bc7d88a7ed8565440a3cb4d316b626938433668et * be conservative and restart the timer of the new fp.
8bc7d88a7ed8565440a3cb4d316b626938433668et */
8bc7d88a7ed8565440a3cb4d316b626938433668et SCTP_FADDR_TIMER_RESTART(sctp, fp, fp->rto);
8bc7d88a7ed8565440a3cb4d316b626938433668et
8bc7d88a7ed8565440a3cb4d316b626938433668et sctp->sctp_active = ddi_get_lbolt64();
8bc7d88a7ed8565440a3cb4d316b626938433668et}
8bc7d88a7ed8565440a3cb4d316b626938433668et
8bc7d88a7ed8565440a3cb4d316b626938433668et/*
8bc7d88a7ed8565440a3cb4d316b626938433668et * This function is called by sctp_ss_rexmit() to create a packet
8bc7d88a7ed8565440a3cb4d316b626938433668et * to be retransmitted to the given fp. The given meta and mp
8bc7d88a7ed8565440a3cb4d316b626938433668et * parameters are respectively the sctp_msg_hdr_t and the mblk of the
8bc7d88a7ed8565440a3cb4d316b626938433668et * first chunk to be retransmitted. This is also called when we want
bf8fc2340620695a402331e5da7c7db43264174det * to retransmit a zero window probe from sctp_rexmit() or when we
8bc7d88a7ed8565440a3cb4d316b626938433668et * want to retransmit the zero window probe after the window has
8bc7d88a7ed8565440a3cb4d316b626938433668et * opened from sctp_got_sack().
bf8fc2340620695a402331e5da7c7db43264174det */
8bc7d88a7ed8565440a3cb4d316b626938433668etmblk_t *
8bc7d88a7ed8565440a3cb4d316b626938433668etsctp_rexmit_packet(sctp_t *sctp, mblk_t **meta, mblk_t **mp, sctp_faddr_t *fp,
8bc7d88a7ed8565440a3cb4d316b626938433668et uint_t *packet_len)
8c3348818856b8366c07db7214dd7746a0aa3a07jchu{
8bc7d88a7ed8565440a3cb4d316b626938433668et uint32_t seglen = 0;
8bc7d88a7ed8565440a3cb4d316b626938433668et uint16_t chunklen;
8bc7d88a7ed8565440a3cb4d316b626938433668et int extra;
8bc7d88a7ed8565440a3cb4d316b626938433668et mblk_t *nmp;
8c3348818856b8366c07db7214dd7746a0aa3a07jchu mblk_t *head;
8bc7d88a7ed8565440a3cb4d316b626938433668et mblk_t *fill;
8bc7d88a7ed8565440a3cb4d316b626938433668et sctp_data_hdr_t *sdc;
8bc7d88a7ed8565440a3cb4d316b626938433668et sctp_msg_hdr_t *mhdr;
8bc7d88a7ed8565440a3cb4d316b626938433668et
8bc7d88a7ed8565440a3cb4d316b626938433668et sdc = (sctp_data_hdr_t *)(*mp)->b_rptr;
8bc7d88a7ed8565440a3cb4d316b626938433668et seglen = ntohs(sdc->sdh_len);
8bc7d88a7ed8565440a3cb4d316b626938433668et chunklen = seglen - sizeof (*sdc);
8bc7d88a7ed8565440a3cb4d316b626938433668et if ((extra = seglen & (SCTP_ALIGN - 1)) != 0)
8bc7d88a7ed8565440a3cb4d316b626938433668et extra = SCTP_ALIGN - extra;
8bc7d88a7ed8565440a3cb4d316b626938433668et
8bc7d88a7ed8565440a3cb4d316b626938433668et nmp = dupmsg(*mp);
8bc7d88a7ed8565440a3cb4d316b626938433668et if (nmp == NULL)
8bc7d88a7ed8565440a3cb4d316b626938433668et return (NULL);
8bc7d88a7ed8565440a3cb4d316b626938433668et if (extra > 0) {
8bc7d88a7ed8565440a3cb4d316b626938433668et fill = sctp_get_padding(sctp, extra);
8bc7d88a7ed8565440a3cb4d316b626938433668et if (fill != NULL) {
8bc7d88a7ed8565440a3cb4d316b626938433668et linkb(nmp, fill);
8bc7d88a7ed8565440a3cb4d316b626938433668et seglen += extra;
bf8fc2340620695a402331e5da7c7db43264174det } else {
8bc7d88a7ed8565440a3cb4d316b626938433668et freemsg(nmp);
8bc7d88a7ed8565440a3cb4d316b626938433668et return (NULL);
bf8fc2340620695a402331e5da7c7db43264174det }
8bc7d88a7ed8565440a3cb4d316b626938433668et }
8bc7d88a7ed8565440a3cb4d316b626938433668et SCTP_CHUNK_CLEAR_FLAGS(nmp);
8bc7d88a7ed8565440a3cb4d316b626938433668et head = sctp_add_proto_hdr(sctp, fp, nmp, 0, NULL);
8c3348818856b8366c07db7214dd7746a0aa3a07jchu if (head == NULL) {
8bc7d88a7ed8565440a3cb4d316b626938433668et freemsg(nmp);
8bc7d88a7ed8565440a3cb4d316b626938433668et return (NULL);
8bc7d88a7ed8565440a3cb4d316b626938433668et }
8bc7d88a7ed8565440a3cb4d316b626938433668et SCTP_CHUNK_SENT(sctp, *mp, sdc, fp, chunklen, *meta);
8c3348818856b8366c07db7214dd7746a0aa3a07jchu /*
8bc7d88a7ed8565440a3cb4d316b626938433668et * Don't update the TSN if we are doing a Zero Win Probe.
8bc7d88a7ed8565440a3cb4d316b626938433668et */
8bc7d88a7ed8565440a3cb4d316b626938433668et if (!sctp->sctp_zero_win_probe)
8bc7d88a7ed8565440a3cb4d316b626938433668et sctp->sctp_rxt_nxttsn = ntohl(sdc->sdh_tsn);
8bc7d88a7ed8565440a3cb4d316b626938433668et *mp = (*mp)->b_next;
8bc7d88a7ed8565440a3cb4d316b626938433668et
8bc7d88a7ed8565440a3cb4d316b626938433668ettry_bundle:
8bc7d88a7ed8565440a3cb4d316b626938433668et while (seglen < fp->sfa_pmss) {
8bc7d88a7ed8565440a3cb4d316b626938433668et int32_t new_len;
8bc7d88a7ed8565440a3cb4d316b626938433668et
bf8fc2340620695a402331e5da7c7db43264174det /*
8bc7d88a7ed8565440a3cb4d316b626938433668et * Go through the list to find more chunks to be bundled.
8bc7d88a7ed8565440a3cb4d316b626938433668et * We should only retransmit sent by unack'ed chunks. Since
8bc7d88a7ed8565440a3cb4d316b626938433668et * they were sent before, the peer's receive window should
8bc7d88a7ed8565440a3cb4d316b626938433668et * be able to receive them.
b40cec45c74e847c9d8b99b835ab69a64e7d1a59krishnae */
8bc7d88a7ed8565440a3cb4d316b626938433668et while (*mp != NULL) {
8bc7d88a7ed8565440a3cb4d316b626938433668et /* Check if the chunk can be bundled. */
8bc7d88a7ed8565440a3cb4d316b626938433668et if (SCTP_CHUNK_ISSENT(*mp) && !SCTP_CHUNK_ISACKED(*mp))
8bc7d88a7ed8565440a3cb4d316b626938433668et break;
bf8fc2340620695a402331e5da7c7db43264174det *mp = (*mp)->b_next;
bf8fc2340620695a402331e5da7c7db43264174det }
bf8fc2340620695a402331e5da7c7db43264174det /* Go to the next message. */
bf8fc2340620695a402331e5da7c7db43264174det if (*mp == NULL) {
bf8fc2340620695a402331e5da7c7db43264174det for (*meta = (*meta)->b_next; *meta != NULL;
bf8fc2340620695a402331e5da7c7db43264174det *meta = (*meta)->b_next) {
bf8fc2340620695a402331e5da7c7db43264174det mhdr = (sctp_msg_hdr_t *)(*meta)->b_rptr;
bf8fc2340620695a402331e5da7c7db43264174det
5613d828c3413db2a71d47fbbc385a3f7a23d908Krishna Elango if (SCTP_IS_MSG_ABANDONED(*meta) ||
8bc7d88a7ed8565440a3cb4d316b626938433668et SCTP_MSG_TO_BE_ABANDONED(*meta, mhdr,
455c986069737584e38ba5b6e84f6052bebc0cf9krishnae sctp)) {
bf8fc2340620695a402331e5da7c7db43264174det continue;
1ff6511282dda236fdea133a0fc53438d8c4f5fdegillett }
bf8fc2340620695a402331e5da7c7db43264174det
bf8fc2340620695a402331e5da7c7db43264174det *mp = (*meta)->b_cont;
1ff6511282dda236fdea133a0fc53438d8c4f5fdegillett goto try_bundle;
bf8fc2340620695a402331e5da7c7db43264174det }
8bc7d88a7ed8565440a3cb4d316b626938433668et /* No more chunk to be bundled. */
8bc7d88a7ed8565440a3cb4d316b626938433668et break;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sdc = (sctp_data_hdr_t *)(*mp)->b_rptr;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu /* Don't bundle chunks beyond sctp_rxt_maxtsn. */
8c3348818856b8366c07db7214dd7746a0aa3a07jchu if (SEQ_GT(ntohl(sdc->sdh_tsn), sctp->sctp_rxt_maxtsn))
f8d2de6bd2421da1926f3daa456d161670decdf7jchu break;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu new_len = ntohs(sdc->sdh_len);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu chunklen = new_len - sizeof (*sdc);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
8c3348818856b8366c07db7214dd7746a0aa3a07jchu if ((extra = new_len & (SCTP_ALIGN - 1)) != 0)
f8d2de6bd2421da1926f3daa456d161670decdf7jchu extra = SCTP_ALIGN - extra;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if ((new_len = seglen + new_len + extra) > fp->sfa_pmss)
f8d2de6bd2421da1926f3daa456d161670decdf7jchu break;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if ((nmp = dupmsg(*mp)) == NULL)
f8d2de6bd2421da1926f3daa456d161670decdf7jchu break;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (extra > 0) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu fill = sctp_get_padding(sctp, extra);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (fill != NULL) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu linkb(nmp, fill);
bf8fc2340620695a402331e5da7c7db43264174det } else {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu freemsg(nmp);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu break;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu linkb(head, nmp);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
8c3348818856b8366c07db7214dd7746a0aa3a07jchu SCTP_CHUNK_CLEAR_FLAGS(nmp);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu SCTP_CHUNK_SENT(sctp, *mp, sdc, fp, chunklen, *meta);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu /*
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * Don't update the TSN if we are doing a Zero Win Probe.
f8d2de6bd2421da1926f3daa456d161670decdf7jchu */
8c3348818856b8366c07db7214dd7746a0aa3a07jchu if (!sctp->sctp_zero_win_probe)
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp->sctp_rxt_nxttsn = ntohl(sdc->sdh_tsn);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchu seglen = new_len;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu *mp = (*mp)->b_next;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu *packet_len = seglen;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu fp->rxt_unacked += seglen;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu return (head);
f8d2de6bd2421da1926f3daa456d161670decdf7jchu}
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
3677cad460dda50d22a04d36a3f544a82344d940et/*
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * sctp_ss_rexmit() is called when we get a SACK after a timeout which
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * advances the cum_tsn but the cum_tsn is still less than what we have sent
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * (sctp_rxt_maxtsn) at the time of the timeout. This SACK is a "partial"
bf8fc2340620695a402331e5da7c7db43264174det * SACK. We retransmit unacked chunks without having to wait for another
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * timeout. The rationale is that the SACK should not be "partial" if all the
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * lost chunks have been retransmitted. Since the SACK is "partial,"
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * the chunks between the cum_tsn and the sctp_rxt_maxtsn should still
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * be missing. It is better for us to retransmit them now instead
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * of waiting for a timeout.
f8d2de6bd2421da1926f3daa456d161670decdf7jchu */
8c3348818856b8366c07db7214dd7746a0aa3a07jchuvoid
bf8fc2340620695a402331e5da7c7db43264174detsctp_ss_rexmit(sctp_t *sctp)
bf8fc2340620695a402331e5da7c7db43264174det{
bf8fc2340620695a402331e5da7c7db43264174det mblk_t *meta;
bf8fc2340620695a402331e5da7c7db43264174det mblk_t *mp;
bf8fc2340620695a402331e5da7c7db43264174det mblk_t *pkt;
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae sctp_faddr_t *fp;
bf8fc2340620695a402331e5da7c7db43264174det uint_t pkt_len;
bf8fc2340620695a402331e5da7c7db43264174det uint32_t tot_wnd;
bf8fc2340620695a402331e5da7c7db43264174det sctp_data_hdr_t *sdc;
bf8fc2340620695a402331e5da7c7db43264174det int burst;
bf8fc2340620695a402331e5da7c7db43264174det sctp_stack_t *sctps = sctp->sctp_sctps;
bf8fc2340620695a402331e5da7c7db43264174det
bf8fc2340620695a402331e5da7c7db43264174det ASSERT(!sctp->sctp_zero_win_probe);
bf8fc2340620695a402331e5da7c7db43264174det
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae /*
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae * If the last cum ack is smaller than what we have just
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae * retransmitted, simply return.
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae */
bf8fc2340620695a402331e5da7c7db43264174det if (SEQ_GEQ(sctp->sctp_lastack_rxd, sctp->sctp_rxt_nxttsn))
bf8fc2340620695a402331e5da7c7db43264174det sctp->sctp_rxt_nxttsn = sctp->sctp_lastack_rxd + 1;
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae else
bf8fc2340620695a402331e5da7c7db43264174det return;
bf8fc2340620695a402331e5da7c7db43264174det ASSERT(SEQ_LEQ(sctp->sctp_rxt_nxttsn, sctp->sctp_rxt_maxtsn));
bf8fc2340620695a402331e5da7c7db43264174det
bf8fc2340620695a402331e5da7c7db43264174det /*
bf8fc2340620695a402331e5da7c7db43264174det * After a timer fires, sctp_current should be set to the new
bf8fc2340620695a402331e5da7c7db43264174det * fp where the retransmitted chunks are sent.
bf8fc2340620695a402331e5da7c7db43264174det */
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae fp = sctp->sctp_current;
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae /*
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae * Since we are retransmitting, we only need to use cwnd to determine
bf8fc2340620695a402331e5da7c7db43264174det * how much we can send as we were allowed (by peer's receive window)
bf8fc2340620695a402331e5da7c7db43264174det * to send those retransmitted chunks previously when they are first
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae * sent. If we record how much we have retransmitted but
bf8fc2340620695a402331e5da7c7db43264174det * unacknowledged using rxt_unacked, then the amount we can now send
bf8fc2340620695a402331e5da7c7db43264174det * is equal to cwnd minus rxt_unacked.
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae *
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae * The field rxt_unacked is incremented when we retransmit a packet
bf8fc2340620695a402331e5da7c7db43264174det * and decremented when we got a SACK acknowledging something. And
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * it is reset when the retransmission timer fires as we assume that
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * all packets have left the network after a timeout. If this
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * assumption is not true, it means that after a timeout, we can
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * get a SACK acknowledging more than rxt_unacked (its value only
8c3348818856b8366c07db7214dd7746a0aa3a07jchu * contains what is retransmitted when the timer fires). So
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * rxt_unacked will become very big (it is an unsiged int so going
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * negative means that the value is huge). This is the reason we
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * always send at least 1 MSS bytes.
f8d2de6bd2421da1926f3daa456d161670decdf7jchu *
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * The reason why we do not have an accurate count is that we
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * only know how many packets are outstanding (using the TSN numbers).
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * But we do not know how many bytes those packets contain. To
f8d2de6bd2421da1926f3daa456d161670decdf7jchu * have an accurate count, we need to walk through the send list.
bf8fc2340620695a402331e5da7c7db43264174det * As it is not really important to have an accurate count during
bf8fc2340620695a402331e5da7c7db43264174det * retransmission, we skip this walk to save some time. This should
bf8fc2340620695a402331e5da7c7db43264174det * not make the retransmission too aggressive to cause congestion.
bf8fc2340620695a402331e5da7c7db43264174det */
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (fp->cwnd <= fp->rxt_unacked)
f8d2de6bd2421da1926f3daa456d161670decdf7jchu tot_wnd = fp->sfa_pmss;
bf8fc2340620695a402331e5da7c7db43264174det else
f8d2de6bd2421da1926f3daa456d161670decdf7jchu tot_wnd = fp->cwnd - fp->rxt_unacked;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchu /* Find the first unack'ed chunk */
f8d2de6bd2421da1926f3daa456d161670decdf7jchu for (meta = sctp->sctp_xmit_head; meta != NULL; meta = meta->b_next) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sctp_msg_hdr_t *mhdr = (sctp_msg_hdr_t *)meta->b_rptr;
8c3348818856b8366c07db7214dd7746a0aa3a07jchu
8c3348818856b8366c07db7214dd7746a0aa3a07jchu if (SCTP_IS_MSG_ABANDONED(meta) ||
f8d2de6bd2421da1926f3daa456d161670decdf7jchu SCTP_MSG_TO_BE_ABANDONED(meta, mhdr, sctp)) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu continue;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
8c3348818856b8366c07db7214dd7746a0aa3a07jchu for (mp = meta->b_cont; mp != NULL; mp = mp->b_next) {
f8d2de6bd2421da1926f3daa456d161670decdf7jchu /* Again, this may not be possible */
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (!SCTP_CHUNK_ISSENT(mp))
f8d2de6bd2421da1926f3daa456d161670decdf7jchu return;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu sdc = (sctp_data_hdr_t *)mp->b_rptr;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu if (ntohl(sdc->sdh_tsn) == sctp->sctp_rxt_nxttsn)
f8d2de6bd2421da1926f3daa456d161670decdf7jchu goto found_msg;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu }
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
f8d2de6bd2421da1926f3daa456d161670decdf7jchu /* Everything is abandoned... */
bf8fc2340620695a402331e5da7c7db43264174det return;
f8d2de6bd2421da1926f3daa456d161670decdf7jchu
found_msg:
if (!fp->timer_running)
SCTP_FADDR_TIMER_RESTART(sctp, fp, fp->rto);
pkt = sctp_rexmit_packet(sctp, &meta, &mp, fp, &pkt_len);
if (pkt == NULL) {
SCTP_KSTAT(sctps, sctp_ss_rexmit_failed);
return;
}
if ((pkt_len > fp->sfa_pmss) && fp->isv4) {
ipha_t *iph = (ipha_t *)pkt->b_rptr;
/*
* Path MTU is different from path we thought it would
* be when we created chunks, or IP headers have grown.
* Need to clear the DF bit.
*/
iph->ipha_fragment_offset_and_flags = 0;
}
sctp_set_iplen(sctp, pkt, fp->ixa);
(void) conn_ip_output(pkt, fp->ixa);
BUMP_LOCAL(sctp->sctp_opkts);
/* Check and see if there is more chunk to be retransmitted. */
if (tot_wnd <= pkt_len || tot_wnd - pkt_len < fp->sfa_pmss ||
meta == NULL)
return;
if (mp == NULL)
meta = meta->b_next;
if (meta == NULL)
return;
/* Retransmit another packet if the window allows. */
for (tot_wnd -= pkt_len, burst = sctps->sctps_maxburst - 1;
meta != NULL && burst > 0; meta = meta->b_next, burst--) {
if (mp == NULL)
mp = meta->b_cont;
for (; mp != NULL; mp = mp->b_next) {
/* Again, this may not be possible */
if (!SCTP_CHUNK_ISSENT(mp))
return;
if (!SCTP_CHUNK_ISACKED(mp))
goto found_msg;
}
}
}