10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
51735Skcpoon * Common Development and Distribution License (the "License").
61735Skcpoon * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
211735Skcpoon
220Sstevel@tonic-gate /*
2312534SGeorge.Shepherd@Sun.COM * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate #include <sys/types.h>
270Sstevel@tonic-gate #include <sys/systm.h>
280Sstevel@tonic-gate #include <sys/stream.h>
290Sstevel@tonic-gate #include <sys/ddi.h>
300Sstevel@tonic-gate #include <sys/sunddi.h>
310Sstevel@tonic-gate #include <sys/strsubr.h>
320Sstevel@tonic-gate #include <sys/strsun.h>
330Sstevel@tonic-gate
340Sstevel@tonic-gate #include <netinet/in.h>
350Sstevel@tonic-gate #include <netinet/ip6.h>
360Sstevel@tonic-gate
3711042SErik.Nordmark@Sun.COM #include <inet/ipsec_impl.h>
380Sstevel@tonic-gate #include <inet/common.h>
390Sstevel@tonic-gate #include <inet/ip.h>
400Sstevel@tonic-gate #include <inet/ip6.h>
410Sstevel@tonic-gate #include <inet/mib2.h>
420Sstevel@tonic-gate #include <inet/nd.h>
430Sstevel@tonic-gate #include <inet/optcom.h>
440Sstevel@tonic-gate #include <inet/sctp_ip.h>
453448Sdh155122 #include <inet/ipclassifier.h>
460Sstevel@tonic-gate #include "sctp_impl.h"
470Sstevel@tonic-gate
480Sstevel@tonic-gate void
sctp_send_shutdown(sctp_t * sctp,int rexmit)490Sstevel@tonic-gate sctp_send_shutdown(sctp_t *sctp, int rexmit)
500Sstevel@tonic-gate {
510Sstevel@tonic-gate mblk_t *smp;
520Sstevel@tonic-gate mblk_t *sendmp;
530Sstevel@tonic-gate sctp_chunk_hdr_t *sch;
540Sstevel@tonic-gate uint32_t *ctsn;
550Sstevel@tonic-gate sctp_faddr_t *fp;
563448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps;
570Sstevel@tonic-gate
580Sstevel@tonic-gate if (sctp->sctp_state != SCTPS_ESTABLISHED &&
590Sstevel@tonic-gate sctp->sctp_state != SCTPS_SHUTDOWN_PENDING &&
600Sstevel@tonic-gate sctp->sctp_state != SCTPS_SHUTDOWN_SENT) {
610Sstevel@tonic-gate return;
620Sstevel@tonic-gate }
630Sstevel@tonic-gate
640Sstevel@tonic-gate if (sctp->sctp_state == SCTPS_ESTABLISHED) {
650Sstevel@tonic-gate sctp->sctp_state = SCTPS_SHUTDOWN_PENDING;
660Sstevel@tonic-gate /*
670Sstevel@tonic-gate * We set an upper bound on how long we will
680Sstevel@tonic-gate * wait for a shutdown-ack from the peer. This
690Sstevel@tonic-gate * is to prevent the receiver from attempting
700Sstevel@tonic-gate * to create a half-closed state indefinately.
710Sstevel@tonic-gate * See archive from IETF TSVWG mailing list
720Sstevel@tonic-gate * for June 2001 for more information.
730Sstevel@tonic-gate * Since we will not be calculating RTTs after
740Sstevel@tonic-gate * sending the shutdown, we can overload out_time
750Sstevel@tonic-gate * to track how long we have waited.
760Sstevel@tonic-gate */
7711066Srafael.vanoni@sun.com sctp->sctp_out_time = ddi_get_lbolt64();
780Sstevel@tonic-gate }
790Sstevel@tonic-gate
800Sstevel@tonic-gate /*
810Sstevel@tonic-gate * If there is unsent (or unacked) data, wait for it to get ack'd
820Sstevel@tonic-gate */
830Sstevel@tonic-gate if (sctp->sctp_xmit_head != NULL || sctp->sctp_xmit_unsent != NULL) {
840Sstevel@tonic-gate return;
850Sstevel@tonic-gate }
860Sstevel@tonic-gate
870Sstevel@tonic-gate /* rotate faddrs if we are retransmitting */
880Sstevel@tonic-gate if (!rexmit) {
890Sstevel@tonic-gate fp = sctp->sctp_current;
900Sstevel@tonic-gate } else {
910Sstevel@tonic-gate fp = sctp_rotate_faddr(sctp, sctp->sctp_shutdown_faddr);
920Sstevel@tonic-gate }
930Sstevel@tonic-gate
940Sstevel@tonic-gate sctp->sctp_shutdown_faddr = fp;
950Sstevel@tonic-gate
960Sstevel@tonic-gate /* Link in a SACK if resending the shutdown */
970Sstevel@tonic-gate if (sctp->sctp_state > SCTPS_SHUTDOWN_PENDING &&
980Sstevel@tonic-gate (sendmp = sctp_make_sack(sctp, fp, NULL)) != NULL) {
990Sstevel@tonic-gate
1000Sstevel@tonic-gate smp = allocb(sizeof (*sch) + sizeof (*ctsn), BPRI_MED);
1010Sstevel@tonic-gate if (smp == NULL) {
1020Sstevel@tonic-gate freemsg(sendmp);
1030Sstevel@tonic-gate goto done;
1040Sstevel@tonic-gate }
1050Sstevel@tonic-gate linkb(sendmp, smp);
1060Sstevel@tonic-gate
1070Sstevel@tonic-gate sch = (sctp_chunk_hdr_t *)smp->b_rptr;
1080Sstevel@tonic-gate smp->b_wptr = smp->b_rptr + sizeof (*sch) + sizeof (*ctsn);
1090Sstevel@tonic-gate } else {
1100Sstevel@tonic-gate sendmp = sctp_make_mp(sctp, fp,
1110Sstevel@tonic-gate sizeof (*sch) + sizeof (*ctsn));
1120Sstevel@tonic-gate if (sendmp == NULL) {
1133448Sdh155122 SCTP_KSTAT(sctps, sctp_send_shutdown_failed);
1140Sstevel@tonic-gate goto done;
1150Sstevel@tonic-gate }
1160Sstevel@tonic-gate sch = (sctp_chunk_hdr_t *)sendmp->b_wptr;
1170Sstevel@tonic-gate sendmp->b_wptr += sizeof (*sch) + sizeof (*ctsn);
1180Sstevel@tonic-gate
1190Sstevel@tonic-gate /* shutdown w/o sack, update lastacked */
1200Sstevel@tonic-gate sctp->sctp_lastacked = sctp->sctp_ftsn - 1;
1210Sstevel@tonic-gate }
1220Sstevel@tonic-gate
1230Sstevel@tonic-gate sch->sch_id = CHUNK_SHUTDOWN;
1240Sstevel@tonic-gate sch->sch_flags = 0;
1250Sstevel@tonic-gate sch->sch_len = htons(sizeof (*sch) + sizeof (*ctsn));
1260Sstevel@tonic-gate
1270Sstevel@tonic-gate ctsn = (uint32_t *)(sch + 1);
1280Sstevel@tonic-gate *ctsn = htonl(sctp->sctp_lastacked);
1290Sstevel@tonic-gate
1300Sstevel@tonic-gate /* Link the shutdown chunk in after the IP/SCTP header */
1310Sstevel@tonic-gate
1320Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_obchunks);
1330Sstevel@tonic-gate
1340Sstevel@tonic-gate /* Send the shutdown and restart the timer */
135*13009SChandrasekar.Marimuthu@Sun.COM sctp_set_iplen(sctp, sendmp, fp->sf_ixa);
136*13009SChandrasekar.Marimuthu@Sun.COM (void) conn_ip_output(sendmp, fp->sf_ixa);
13711042SErik.Nordmark@Sun.COM BUMP_LOCAL(sctp->sctp_opkts);
1380Sstevel@tonic-gate
1390Sstevel@tonic-gate done:
1400Sstevel@tonic-gate sctp->sctp_state = SCTPS_SHUTDOWN_SENT;
1410Sstevel@tonic-gate SCTP_FADDR_TIMER_RESTART(sctp, sctp->sctp_current,
142*13009SChandrasekar.Marimuthu@Sun.COM sctp->sctp_current->sf_rto);
1430Sstevel@tonic-gate }
1440Sstevel@tonic-gate
1450Sstevel@tonic-gate int
sctp_shutdown_received(sctp_t * sctp,sctp_chunk_hdr_t * sch,boolean_t crwsd,boolean_t rexmit,sctp_faddr_t * fp)1461735Skcpoon sctp_shutdown_received(sctp_t *sctp, sctp_chunk_hdr_t *sch, boolean_t crwsd,
1471735Skcpoon boolean_t rexmit, sctp_faddr_t *fp)
1480Sstevel@tonic-gate {
1490Sstevel@tonic-gate mblk_t *samp;
1500Sstevel@tonic-gate uint32_t *tsn;
1510Sstevel@tonic-gate int trysend = 0;
1520Sstevel@tonic-gate
1530Sstevel@tonic-gate if (sctp->sctp_state != SCTPS_SHUTDOWN_ACK_SENT)
1540Sstevel@tonic-gate sctp->sctp_state = SCTPS_SHUTDOWN_RECEIVED;
1550Sstevel@tonic-gate
1560Sstevel@tonic-gate /* Extract and process the TSN in the shutdown chunk */
1570Sstevel@tonic-gate if (sch != NULL) {
1580Sstevel@tonic-gate tsn = (uint32_t *)(sch + 1);
15911858SChandrasekar.Marimuthu@Sun.COM /* not already acked */
16011858SChandrasekar.Marimuthu@Sun.COM if (!SEQ_LT(ntohl(*tsn), sctp->sctp_lastack_rxd))
16111858SChandrasekar.Marimuthu@Sun.COM trysend = sctp_cumack(sctp, ntohl(*tsn), &samp);
1620Sstevel@tonic-gate }
1630Sstevel@tonic-gate
1640Sstevel@tonic-gate /* Don't allow sending new data */
1654818Skcpoon if (!SCTP_IS_DETACHED(sctp) && !sctp->sctp_ulp_discon_done) {
1668348SEric.Yu@Sun.COM sctp->sctp_ulp_opctl(sctp->sctp_ulpd, SOCK_OPCTL_SHUT_SEND, 0);
1674818Skcpoon sctp->sctp_ulp_discon_done = B_TRUE;
1684818Skcpoon }
1690Sstevel@tonic-gate
1700Sstevel@tonic-gate /*
1710Sstevel@tonic-gate * If there is unsent or unacked data, try sending them out now.
1720Sstevel@tonic-gate * The other side should acknowledge them. After we have flushed
1730Sstevel@tonic-gate * the transmit queue, we can complete the shutdown sequence.
1740Sstevel@tonic-gate */
1750Sstevel@tonic-gate if (sctp->sctp_xmit_head != NULL || sctp->sctp_xmit_unsent != NULL)
1760Sstevel@tonic-gate return (1);
1770Sstevel@tonic-gate
1781735Skcpoon if (fp == NULL) {
1791735Skcpoon /* rotate faddrs if we are retransmitting */
1801735Skcpoon if (!rexmit)
1811735Skcpoon fp = sctp->sctp_current;
1821735Skcpoon else
1831735Skcpoon fp = sctp_rotate_faddr(sctp, sctp->sctp_shutdown_faddr);
1841735Skcpoon }
1850Sstevel@tonic-gate
18612721Sanil.udupa@sun.com sctp_send_shutdown_ack(sctp, fp, crwsd);
1870Sstevel@tonic-gate
1880Sstevel@tonic-gate return (trysend);
1890Sstevel@tonic-gate }
1900Sstevel@tonic-gate
1910Sstevel@tonic-gate void
sctp_shutdown_complete(sctp_t * sctp)1920Sstevel@tonic-gate sctp_shutdown_complete(sctp_t *sctp)
1930Sstevel@tonic-gate {
1940Sstevel@tonic-gate mblk_t *scmp;
1950Sstevel@tonic-gate sctp_chunk_hdr_t *scch;
1963448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps;
1970Sstevel@tonic-gate
19811042SErik.Nordmark@Sun.COM scmp = sctp_make_mp(sctp, sctp->sctp_current, sizeof (*scch));
1990Sstevel@tonic-gate if (scmp == NULL) {
2000Sstevel@tonic-gate /* XXX use timer approach */
2013448Sdh155122 SCTP_KSTAT(sctps, sctp_send_shutdown_comp_failed);
2020Sstevel@tonic-gate return;
2030Sstevel@tonic-gate }
2040Sstevel@tonic-gate
2050Sstevel@tonic-gate scch = (sctp_chunk_hdr_t *)scmp->b_wptr;
2060Sstevel@tonic-gate scch->sch_id = CHUNK_SHUTDOWN_COMPLETE;
2070Sstevel@tonic-gate scch->sch_flags = 0;
2080Sstevel@tonic-gate scch->sch_len = htons(sizeof (*scch));
2090Sstevel@tonic-gate
2100Sstevel@tonic-gate scmp->b_wptr += sizeof (*scch);
2110Sstevel@tonic-gate
2120Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_obchunks);
2130Sstevel@tonic-gate
214*13009SChandrasekar.Marimuthu@Sun.COM sctp_set_iplen(sctp, scmp, sctp->sctp_current->sf_ixa);
215*13009SChandrasekar.Marimuthu@Sun.COM (void) conn_ip_output(scmp, sctp->sctp_current->sf_ixa);
21611042SErik.Nordmark@Sun.COM BUMP_LOCAL(sctp->sctp_opkts);
2170Sstevel@tonic-gate }
2180Sstevel@tonic-gate
2190Sstevel@tonic-gate /*
2200Sstevel@tonic-gate * Similar to sctp_shutdown_complete(), except that since this
2210Sstevel@tonic-gate * is out-of-the-blue, we can't use an sctp's association information,
2220Sstevel@tonic-gate * and instead must draw all necessary info from the incoming packet.
2230Sstevel@tonic-gate */
2240Sstevel@tonic-gate void
sctp_ootb_shutdown_ack(mblk_t * mp,uint_t ip_hdr_len,ip_recv_attr_t * ira,ip_stack_t * ipst)22511042SErik.Nordmark@Sun.COM sctp_ootb_shutdown_ack(mblk_t *mp, uint_t ip_hdr_len, ip_recv_attr_t *ira,
22611042SErik.Nordmark@Sun.COM ip_stack_t *ipst)
2270Sstevel@tonic-gate {
2280Sstevel@tonic-gate boolean_t isv4;
22911042SErik.Nordmark@Sun.COM ipha_t *ipha = NULL;
23011042SErik.Nordmark@Sun.COM ip6_t *ip6h = NULL;
2310Sstevel@tonic-gate sctp_hdr_t *insctph;
2320Sstevel@tonic-gate sctp_chunk_hdr_t *scch;
2330Sstevel@tonic-gate int i;
2340Sstevel@tonic-gate uint16_t port;
2350Sstevel@tonic-gate mblk_t *mp1;
23611042SErik.Nordmark@Sun.COM netstack_t *ns = ipst->ips_netstack;
23711042SErik.Nordmark@Sun.COM sctp_stack_t *sctps = ns->netstack_sctp;
23811042SErik.Nordmark@Sun.COM ip_xmit_attr_t ixas;
2390Sstevel@tonic-gate
24011042SErik.Nordmark@Sun.COM bzero(&ixas, sizeof (ixas));
24111042SErik.Nordmark@Sun.COM
24211042SErik.Nordmark@Sun.COM isv4 = (IPH_HDR_VERSION(mp->b_rptr) == IPV4_VERSION);
24311042SErik.Nordmark@Sun.COM
24411042SErik.Nordmark@Sun.COM ASSERT(MBLKL(mp) >= sizeof (*insctph) + sizeof (*scch) +
24511042SErik.Nordmark@Sun.COM (isv4 ? sizeof (ipha_t) : sizeof (ip6_t)));
2460Sstevel@tonic-gate
2470Sstevel@tonic-gate /*
2480Sstevel@tonic-gate * Check to see if we can reuse the incoming mblk. There should
24911042SErik.Nordmark@Sun.COM * not be other reference. Since this packet comes from below,
2500Sstevel@tonic-gate * there should be enough header space to fill in what the lower
25111042SErik.Nordmark@Sun.COM * layers want to add.
2520Sstevel@tonic-gate */
25311042SErik.Nordmark@Sun.COM if (DB_REF(mp) != 1) {
25411042SErik.Nordmark@Sun.COM mp1 = allocb(MBLKL(mp) + sctps->sctps_wroff_xtra, BPRI_MED);
2550Sstevel@tonic-gate if (mp1 == NULL) {
25611042SErik.Nordmark@Sun.COM freeb(mp);
2570Sstevel@tonic-gate return;
2580Sstevel@tonic-gate }
2593448Sdh155122 mp1->b_rptr += sctps->sctps_wroff_xtra;
26011042SErik.Nordmark@Sun.COM bcopy(mp->b_rptr, mp1->b_rptr, MBLKL(mp));
26111042SErik.Nordmark@Sun.COM freeb(mp);
26211042SErik.Nordmark@Sun.COM mp = mp1;
2631932Svi117747 } else {
26411042SErik.Nordmark@Sun.COM DB_CKSUMFLAGS(mp) = 0;
2650Sstevel@tonic-gate }
2660Sstevel@tonic-gate
26711042SErik.Nordmark@Sun.COM ixas.ixa_pktlen = ip_hdr_len + sizeof (*insctph) + sizeof (*scch);
26811042SErik.Nordmark@Sun.COM ixas.ixa_ip_hdr_length = ip_hdr_len;
26912534SGeorge.Shepherd@Sun.COM mp->b_wptr = (mp->b_rptr + ixas.ixa_pktlen);
27012534SGeorge.Shepherd@Sun.COM
2710Sstevel@tonic-gate /*
2720Sstevel@tonic-gate * We follow the logic in tcp_xmit_early_reset() in that we skip
27311042SErik.Nordmark@Sun.COM * reversing source route (i.e. replace all IP options with EOL).
2740Sstevel@tonic-gate */
2750Sstevel@tonic-gate if (isv4) {
2760Sstevel@tonic-gate ipaddr_t v4addr;
2770Sstevel@tonic-gate
27811042SErik.Nordmark@Sun.COM ipha = (ipha_t *)mp->b_rptr;
2790Sstevel@tonic-gate for (i = IP_SIMPLE_HDR_LENGTH; i < (int)ip_hdr_len; i++)
28011042SErik.Nordmark@Sun.COM mp->b_rptr[i] = IPOPT_EOL;
2810Sstevel@tonic-gate /* Swap addresses */
28211042SErik.Nordmark@Sun.COM ipha->ipha_length = htons(ixas.ixa_pktlen);
28311042SErik.Nordmark@Sun.COM v4addr = ipha->ipha_src;
28411042SErik.Nordmark@Sun.COM ipha->ipha_src = ipha->ipha_dst;
28511042SErik.Nordmark@Sun.COM ipha->ipha_dst = v4addr;
28611042SErik.Nordmark@Sun.COM ipha->ipha_ident = 0;
28711042SErik.Nordmark@Sun.COM ipha->ipha_ttl = (uchar_t)sctps->sctps_ipv4_ttl;
28811042SErik.Nordmark@Sun.COM
28911042SErik.Nordmark@Sun.COM ixas.ixa_flags = IXAF_BASIC_SIMPLE_V4;
2900Sstevel@tonic-gate } else {
2910Sstevel@tonic-gate in6_addr_t v6addr;
2920Sstevel@tonic-gate
29311042SErik.Nordmark@Sun.COM ip6h = (ip6_t *)mp->b_rptr;
2940Sstevel@tonic-gate /* Remove any extension headers assuming partial overlay */
2950Sstevel@tonic-gate if (ip_hdr_len > IPV6_HDR_LEN) {
2960Sstevel@tonic-gate uint8_t *to;
2970Sstevel@tonic-gate
29811042SErik.Nordmark@Sun.COM to = mp->b_rptr + ip_hdr_len - IPV6_HDR_LEN;
29911042SErik.Nordmark@Sun.COM ovbcopy(ip6h, to, IPV6_HDR_LEN);
30011042SErik.Nordmark@Sun.COM mp->b_rptr += ip_hdr_len - IPV6_HDR_LEN;
3010Sstevel@tonic-gate ip_hdr_len = IPV6_HDR_LEN;
30211042SErik.Nordmark@Sun.COM ip6h = (ip6_t *)mp->b_rptr;
30311042SErik.Nordmark@Sun.COM ip6h->ip6_nxt = IPPROTO_SCTP;
3040Sstevel@tonic-gate }
30511042SErik.Nordmark@Sun.COM ip6h->ip6_plen = htons(ixas.ixa_pktlen - IPV6_HDR_LEN);
30611042SErik.Nordmark@Sun.COM v6addr = ip6h->ip6_src;
30711042SErik.Nordmark@Sun.COM ip6h->ip6_src = ip6h->ip6_dst;
30811042SErik.Nordmark@Sun.COM ip6h->ip6_dst = v6addr;
30911042SErik.Nordmark@Sun.COM ip6h->ip6_hops = (uchar_t)sctps->sctps_ipv6_hoplimit;
31011042SErik.Nordmark@Sun.COM
31111042SErik.Nordmark@Sun.COM ixas.ixa_flags = IXAF_BASIC_SIMPLE_V6;
31211042SErik.Nordmark@Sun.COM if (IN6_IS_ADDR_LINKSCOPE(&ip6h->ip6_dst)) {
31311042SErik.Nordmark@Sun.COM ixas.ixa_flags |= IXAF_SCOPEID_SET;
31411042SErik.Nordmark@Sun.COM ixas.ixa_scopeid = ira->ira_ruifindex;
31511042SErik.Nordmark@Sun.COM }
3160Sstevel@tonic-gate }
31711042SErik.Nordmark@Sun.COM
31811042SErik.Nordmark@Sun.COM insctph = (sctp_hdr_t *)(mp->b_rptr + ip_hdr_len);
3190Sstevel@tonic-gate
3200Sstevel@tonic-gate /* Swap ports. Verification tag is reused. */
3210Sstevel@tonic-gate port = insctph->sh_sport;
3220Sstevel@tonic-gate insctph->sh_sport = insctph->sh_dport;
3230Sstevel@tonic-gate insctph->sh_dport = port;
3240Sstevel@tonic-gate
3250Sstevel@tonic-gate /* Lay in the shutdown complete chunk */
3260Sstevel@tonic-gate scch = (sctp_chunk_hdr_t *)(insctph + 1);
3270Sstevel@tonic-gate scch->sch_id = CHUNK_SHUTDOWN_COMPLETE;
3280Sstevel@tonic-gate scch->sch_len = htons(sizeof (*scch));
3290Sstevel@tonic-gate scch->sch_flags = 0;
3300Sstevel@tonic-gate
3310Sstevel@tonic-gate /* Set the T-bit */
3320Sstevel@tonic-gate SCTP_SET_TBIT(scch);
3330Sstevel@tonic-gate
33411042SErik.Nordmark@Sun.COM ixas.ixa_protocol = IPPROTO_SCTP;
33511042SErik.Nordmark@Sun.COM ixas.ixa_zoneid = ira->ira_zoneid;
33611042SErik.Nordmark@Sun.COM ixas.ixa_ipst = ipst;
33711042SErik.Nordmark@Sun.COM ixas.ixa_ifindex = 0;
3380Sstevel@tonic-gate
33911042SErik.Nordmark@Sun.COM if (ira->ira_flags & IRAF_IPSEC_SECURE) {
34011042SErik.Nordmark@Sun.COM /*
34111042SErik.Nordmark@Sun.COM * Apply IPsec based on how IPsec was applied to
34211042SErik.Nordmark@Sun.COM * the packet that was out of the blue.
34311042SErik.Nordmark@Sun.COM */
34411042SErik.Nordmark@Sun.COM if (!ipsec_in_to_out(ira, &ixas, mp, ipha, ip6h)) {
34511042SErik.Nordmark@Sun.COM BUMP_MIB(&ipst->ips_ip_mib, ipIfStatsOutDiscards);
34611042SErik.Nordmark@Sun.COM /* Note: mp already consumed and ip_drop_packet done */
34711042SErik.Nordmark@Sun.COM return;
34811042SErik.Nordmark@Sun.COM }
34911042SErik.Nordmark@Sun.COM } else {
35011042SErik.Nordmark@Sun.COM /*
35111042SErik.Nordmark@Sun.COM * This is in clear. The message we are building
35211042SErik.Nordmark@Sun.COM * here should go out in clear, independent of our policy.
35311042SErik.Nordmark@Sun.COM */
35411042SErik.Nordmark@Sun.COM ixas.ixa_flags |= IXAF_NO_IPSEC;
35511042SErik.Nordmark@Sun.COM }
35611042SErik.Nordmark@Sun.COM
35711042SErik.Nordmark@Sun.COM (void) ip_output_simple(mp, &ixas);
35811042SErik.Nordmark@Sun.COM ixa_cleanup(&ixas);
3590Sstevel@tonic-gate }
36012721Sanil.udupa@sun.com
36112721Sanil.udupa@sun.com /*
36212721Sanil.udupa@sun.com * Called from sctp_input_data() and sctp_shutdown_received().
36312721Sanil.udupa@sun.com * Send a SHUTDOWN ACK chunk to the peer SCTP endpoint and change SCTP state.
36412721Sanil.udupa@sun.com * This should be done after all data (unacked and unsend) has been
36512721Sanil.udupa@sun.com * acknowledged.
36612721Sanil.udupa@sun.com */
36712721Sanil.udupa@sun.com void
sctp_send_shutdown_ack(sctp_t * sctp,sctp_faddr_t * fp,boolean_t crwsd)36812721Sanil.udupa@sun.com sctp_send_shutdown_ack(sctp_t *sctp, sctp_faddr_t *fp, boolean_t crwsd)
36912721Sanil.udupa@sun.com {
37012721Sanil.udupa@sun.com mblk_t *samp;
37112721Sanil.udupa@sun.com sctp_chunk_hdr_t *sach;
37212721Sanil.udupa@sun.com sctp_stack_t *sctps = sctp->sctp_sctps;
37312721Sanil.udupa@sun.com
37412721Sanil.udupa@sun.com ASSERT(sctp->sctp_xmit_unacked == NULL);
37512721Sanil.udupa@sun.com ASSERT(sctp->sctp_lastack_rxd == (sctp->sctp_ltsn - 1));
37612721Sanil.udupa@sun.com ASSERT(fp != NULL);
37712721Sanil.udupa@sun.com
37812721Sanil.udupa@sun.com sctp->sctp_shutdown_faddr = fp;
37912721Sanil.udupa@sun.com
38012721Sanil.udupa@sun.com samp = sctp_make_mp(sctp, fp, sizeof (*sach));
38112721Sanil.udupa@sun.com if (samp == NULL) {
38212721Sanil.udupa@sun.com SCTP_KSTAT(sctps, sctp_send_shutdown_ack_failed);
38312721Sanil.udupa@sun.com goto dotimer;
38412721Sanil.udupa@sun.com }
38512721Sanil.udupa@sun.com
38612721Sanil.udupa@sun.com sach = (sctp_chunk_hdr_t *)samp->b_wptr;
38712721Sanil.udupa@sun.com sach->sch_id = CHUNK_SHUTDOWN_ACK;
38812721Sanil.udupa@sun.com sach->sch_flags = 0;
38912721Sanil.udupa@sun.com sach->sch_len = htons(sizeof (*sach));
39012721Sanil.udupa@sun.com
39112721Sanil.udupa@sun.com samp->b_wptr += sizeof (*sach);
39212721Sanil.udupa@sun.com /*
39312721Sanil.udupa@sun.com * bundle a "cookie received while shutting down" error if
39412721Sanil.udupa@sun.com * the caller asks for it.
39512721Sanil.udupa@sun.com */
39612721Sanil.udupa@sun.com if (crwsd) {
39712721Sanil.udupa@sun.com mblk_t *errmp;
39812721Sanil.udupa@sun.com
39912721Sanil.udupa@sun.com errmp = sctp_make_err(sctp, SCTP_ERR_COOKIE_SHUT, NULL, 0);
40012721Sanil.udupa@sun.com if (errmp != NULL) {
40112721Sanil.udupa@sun.com linkb(samp, errmp);
40212721Sanil.udupa@sun.com BUMP_LOCAL(sctp->sctp_obchunks);
40312721Sanil.udupa@sun.com }
40412721Sanil.udupa@sun.com }
40512721Sanil.udupa@sun.com
40612721Sanil.udupa@sun.com BUMP_LOCAL(sctp->sctp_obchunks);
40712721Sanil.udupa@sun.com
408*13009SChandrasekar.Marimuthu@Sun.COM sctp_set_iplen(sctp, samp, fp->sf_ixa);
409*13009SChandrasekar.Marimuthu@Sun.COM (void) conn_ip_output(samp, fp->sf_ixa);
41012721Sanil.udupa@sun.com BUMP_LOCAL(sctp->sctp_opkts);
41112721Sanil.udupa@sun.com
41212721Sanil.udupa@sun.com dotimer:
41312721Sanil.udupa@sun.com sctp->sctp_state = SCTPS_SHUTDOWN_ACK_SENT;
414*13009SChandrasekar.Marimuthu@Sun.COM SCTP_FADDR_TIMER_RESTART(sctp, fp, fp->sf_rto);
41512721Sanil.udupa@sun.com }
416