xref: /onnv-gate/usr/src/uts/common/inet/sctp/sctp_common.c (revision 679:f2c9450b58f4)
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
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
220Sstevel@tonic-gate /*
23116Skcpoon  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #include <sys/types.h>
300Sstevel@tonic-gate #include <sys/systm.h>
310Sstevel@tonic-gate #include <sys/stream.h>
320Sstevel@tonic-gate #include <sys/ddi.h>
330Sstevel@tonic-gate #include <sys/sunddi.h>
340Sstevel@tonic-gate #include <sys/kmem.h>
350Sstevel@tonic-gate #include <sys/socket.h>
360Sstevel@tonic-gate #include <sys/random.h>
370Sstevel@tonic-gate 
380Sstevel@tonic-gate #include <netinet/in.h>
390Sstevel@tonic-gate #include <netinet/ip6.h>
400Sstevel@tonic-gate #include <netinet/sctp.h>
410Sstevel@tonic-gate 
420Sstevel@tonic-gate #include <inet/common.h>
430Sstevel@tonic-gate #include <inet/ip.h>
440Sstevel@tonic-gate #include <inet/ip6.h>
450Sstevel@tonic-gate #include <inet/ip_ire.h>
460Sstevel@tonic-gate #include <inet/mi.h>
470Sstevel@tonic-gate #include <inet/mib2.h>
480Sstevel@tonic-gate #include <inet/nd.h>
490Sstevel@tonic-gate #include <inet/optcom.h>
500Sstevel@tonic-gate #include <inet/sctp_ip.h>
510Sstevel@tonic-gate #include <inet/ipclassifier.h>
520Sstevel@tonic-gate #include "sctp_impl.h"
530Sstevel@tonic-gate #include "sctp_addr.h"
540Sstevel@tonic-gate 
550Sstevel@tonic-gate static struct kmem_cache *sctp_kmem_faddr_cache;
560Sstevel@tonic-gate static void sctp_init_faddr(sctp_t *, sctp_faddr_t *, in6_addr_t *);
570Sstevel@tonic-gate 
580Sstevel@tonic-gate /* Set the source address.  Refer to comments in sctp_ire2faddr(). */
590Sstevel@tonic-gate static void
600Sstevel@tonic-gate set_saddr(sctp_t *sctp, sctp_faddr_t *fp, boolean_t v6)
610Sstevel@tonic-gate {
620Sstevel@tonic-gate 	if (sctp->sctp_bound_to_all) {
630Sstevel@tonic-gate 		V6_SET_ZERO(fp->saddr);
640Sstevel@tonic-gate 	} else {
650Sstevel@tonic-gate 		fp->saddr = sctp_get_valid_addr(sctp, v6);
660Sstevel@tonic-gate 		if (!v6 && IN6_IS_ADDR_V4MAPPED_ANY(&fp->saddr) ||
670Sstevel@tonic-gate 		    v6 && IN6_IS_ADDR_UNSPECIFIED(&fp->saddr)) {
680Sstevel@tonic-gate 			fp->state = SCTP_FADDRS_UNREACH;
690Sstevel@tonic-gate 			/* Disable heartbeat. */
700Sstevel@tonic-gate 			fp->hb_expiry = 0;
710Sstevel@tonic-gate 			fp->hb_pending = B_FALSE;
720Sstevel@tonic-gate 			fp->strikes = 0;
730Sstevel@tonic-gate 		}
740Sstevel@tonic-gate 	}
750Sstevel@tonic-gate }
760Sstevel@tonic-gate 
770Sstevel@tonic-gate /*
780Sstevel@tonic-gate  * Call this function to update the cached IRE of a peer addr fp.
790Sstevel@tonic-gate  */
800Sstevel@tonic-gate void
810Sstevel@tonic-gate sctp_ire2faddr(sctp_t *sctp, sctp_faddr_t *fp)
820Sstevel@tonic-gate {
830Sstevel@tonic-gate 	ire_t *ire;
840Sstevel@tonic-gate 	ipaddr_t addr4;
850Sstevel@tonic-gate 	in6_addr_t laddr;
860Sstevel@tonic-gate 	sctp_saddr_ipif_t *sp;
870Sstevel@tonic-gate 	uint_t	ipif_seqid;
880Sstevel@tonic-gate 	int hdrlen;
890Sstevel@tonic-gate 
900Sstevel@tonic-gate 	/* Remove the previous cache IRE */
910Sstevel@tonic-gate 	if ((ire = fp->ire) != NULL) {
920Sstevel@tonic-gate 		IRE_REFRELE_NOTR(ire);
930Sstevel@tonic-gate 		fp->ire = NULL;
940Sstevel@tonic-gate 	}
950Sstevel@tonic-gate 
960Sstevel@tonic-gate 	/*
970Sstevel@tonic-gate 	 * If this addr is not reachable, mark it as unconfirmed for now, the
980Sstevel@tonic-gate 	 * state will be changed back to unreachable later in this function
990Sstevel@tonic-gate 	 * if it is still the case.
1000Sstevel@tonic-gate 	 */
1010Sstevel@tonic-gate 	if (fp->state == SCTP_FADDRS_UNREACH) {
1020Sstevel@tonic-gate 		fp->state = SCTP_FADDRS_UNCONFIRMED;
1030Sstevel@tonic-gate 	}
1040Sstevel@tonic-gate 
1050Sstevel@tonic-gate 	if (fp->isv4) {
1060Sstevel@tonic-gate 		IN6_V4MAPPED_TO_IPADDR(&fp->faddr, addr4);
1070Sstevel@tonic-gate 
1080Sstevel@tonic-gate 		ire = ire_cache_lookup(addr4, sctp->sctp_zoneid);
1090Sstevel@tonic-gate 		if (ire == NULL) {
1100Sstevel@tonic-gate 			dprint(3, ("ire2faddr: no ire for %x:%x:%x:%x\n",
1110Sstevel@tonic-gate 			    SCTP_PRINTADDR(fp->faddr)));
1120Sstevel@tonic-gate 			/*
1130Sstevel@tonic-gate 			 * It is tempting to just leave the src addr
1140Sstevel@tonic-gate 			 * unspecified and let IP figure it out, but we
1150Sstevel@tonic-gate 			 * *cannot* do this, since IP may choose a src addr
1160Sstevel@tonic-gate 			 * that is not part of this association... unless
1170Sstevel@tonic-gate 			 * this sctp has bound to all addrs.  So if the ire
1180Sstevel@tonic-gate 			 * lookup fails, try to find one in our src addr
1190Sstevel@tonic-gate 			 * list, unless the sctp has bound to all addrs, in
1200Sstevel@tonic-gate 			 * which case we change the src addr to unspec.
1210Sstevel@tonic-gate 			 *
1220Sstevel@tonic-gate 			 * Note that if this is a v6 endpoint but it does
1230Sstevel@tonic-gate 			 * not have any v4 address at this point (e.g. may
1240Sstevel@tonic-gate 			 * have been  deleted), sctp_get_valid_addr() will
1250Sstevel@tonic-gate 			 * return mapped INADDR_ANY.  In this case, this
1260Sstevel@tonic-gate 			 * address should be marked not reachable so that
1270Sstevel@tonic-gate 			 * it won't be used to send data.
1280Sstevel@tonic-gate 			 */
1290Sstevel@tonic-gate 			set_saddr(sctp, fp, B_FALSE);
1300Sstevel@tonic-gate 			goto set_current;
1310Sstevel@tonic-gate 		}
1320Sstevel@tonic-gate 		ipif_seqid = ire->ire_ipif->ipif_seqid;
1330Sstevel@tonic-gate 		dprint(2, ("ire2faddr: got ire for %x:%x:%x:%x, ",
1340Sstevel@tonic-gate 			SCTP_PRINTADDR(fp->faddr)));
1350Sstevel@tonic-gate 		dprint(2, ("src = %x\n", ire->ire_src_addr));
1360Sstevel@tonic-gate 		IN6_IPADDR_TO_V4MAPPED(ire->ire_src_addr, &laddr);
1370Sstevel@tonic-gate 
1380Sstevel@tonic-gate 		/* make sure the laddr is part of this association */
1390Sstevel@tonic-gate 		if ((sp = sctp_ipif_lookup(sctp, ipif_seqid)) !=
1400Sstevel@tonic-gate 		    NULL && !sp->saddr_ipif_dontsrc) {
141432Svi117747 			if (sp->saddr_ipif_unconfirmed == 1)
142432Svi117747 				sp->saddr_ipif_unconfirmed = 0;
1430Sstevel@tonic-gate 			fp->saddr = laddr;
1440Sstevel@tonic-gate 		} else {
1450Sstevel@tonic-gate 			ip2dbg(("ire2faddr: src addr is not part of assc\n"));
1460Sstevel@tonic-gate 			set_saddr(sctp, fp, B_FALSE);
1470Sstevel@tonic-gate 		}
1480Sstevel@tonic-gate 	} else {
1490Sstevel@tonic-gate 		ire = ire_cache_lookup_v6(&fp->faddr, sctp->sctp_zoneid);
1500Sstevel@tonic-gate 		if (ire == NULL) {
1510Sstevel@tonic-gate 			dprint(3, ("ire2faddr: no ire for %x:%x:%x:%x\n",
1520Sstevel@tonic-gate 			    SCTP_PRINTADDR(fp->faddr)));
1530Sstevel@tonic-gate 			set_saddr(sctp, fp, B_TRUE);
1540Sstevel@tonic-gate 			goto set_current;
1550Sstevel@tonic-gate 		}
1560Sstevel@tonic-gate 		ipif_seqid = ire->ire_ipif->ipif_seqid;
1570Sstevel@tonic-gate 		dprint(2, ("ire2faddr: got ire for %x:%x:%x:%x, ",
1580Sstevel@tonic-gate 		    SCTP_PRINTADDR(fp->faddr)));
1590Sstevel@tonic-gate 		dprint(2, ("src=%x:%x:%x:%x\n",
1600Sstevel@tonic-gate 		    SCTP_PRINTADDR(ire->ire_src_addr_v6)));
1610Sstevel@tonic-gate 		laddr = ire->ire_src_addr_v6;
1620Sstevel@tonic-gate 
1630Sstevel@tonic-gate 		/* make sure the laddr is part of this association */
1640Sstevel@tonic-gate 
1650Sstevel@tonic-gate 		if ((sp = sctp_ipif_lookup(sctp, ipif_seqid)) !=
1660Sstevel@tonic-gate 		    NULL && !sp->saddr_ipif_dontsrc) {
167432Svi117747 			if (sp->saddr_ipif_unconfirmed == 1)
168432Svi117747 				sp->saddr_ipif_unconfirmed = 0;
1690Sstevel@tonic-gate 			fp->saddr = laddr;
1700Sstevel@tonic-gate 		} else {
1710Sstevel@tonic-gate 			dprint(2, ("ire2faddr: src addr is not part "
1720Sstevel@tonic-gate 				"of assc\n"));
1730Sstevel@tonic-gate 			set_saddr(sctp, fp, B_TRUE);
1740Sstevel@tonic-gate 		}
1750Sstevel@tonic-gate 	}
1760Sstevel@tonic-gate 
1770Sstevel@tonic-gate 	/* Cache the IRE */
1780Sstevel@tonic-gate 	IRE_REFHOLD_NOTR(ire);
1790Sstevel@tonic-gate 	fp->ire = ire;
1800Sstevel@tonic-gate 	if (fp->ire->ire_type == IRE_LOOPBACK && !sctp->sctp_loopback)
1810Sstevel@tonic-gate 		sctp->sctp_loopback = 1;
1820Sstevel@tonic-gate 	IRE_REFRELE(ire);
1830Sstevel@tonic-gate 
1840Sstevel@tonic-gate 	/*
1850Sstevel@tonic-gate 	 * Pull out RTO information for this faddr and use it if we don't
1860Sstevel@tonic-gate 	 * have any yet.
1870Sstevel@tonic-gate 	 */
1880Sstevel@tonic-gate 	if (fp->srtt == -1 && ire->ire_uinfo.iulp_rtt != 0) {
189116Skcpoon 		/* The cached value is in ms. */
190116Skcpoon 		fp->srtt = MSEC_TO_TICK(ire->ire_uinfo.iulp_rtt);
191116Skcpoon 		fp->rttvar = MSEC_TO_TICK(ire->ire_uinfo.iulp_rtt_sd);
1920Sstevel@tonic-gate 		fp->rto = 3 * fp->srtt;
1930Sstevel@tonic-gate 
1940Sstevel@tonic-gate 		/* Bound the RTO by configured min and max values */
1950Sstevel@tonic-gate 		if (fp->rto < sctp->sctp_rto_min) {
1960Sstevel@tonic-gate 			fp->rto = sctp->sctp_rto_min;
1970Sstevel@tonic-gate 		}
1980Sstevel@tonic-gate 		if (fp->rto > sctp->sctp_rto_max) {
1990Sstevel@tonic-gate 			fp->rto = sctp->sctp_rto_max;
2000Sstevel@tonic-gate 		}
2010Sstevel@tonic-gate 	}
2020Sstevel@tonic-gate 
2030Sstevel@tonic-gate 	/*
2040Sstevel@tonic-gate 	 * Record the MTU for this faddr. If the MTU for this faddr has
2050Sstevel@tonic-gate 	 * changed, check if the assc MTU will also change.
2060Sstevel@tonic-gate 	 */
2070Sstevel@tonic-gate 	if (fp->isv4) {
2080Sstevel@tonic-gate 		hdrlen = sctp->sctp_hdr_len;
2090Sstevel@tonic-gate 	} else {
2100Sstevel@tonic-gate 		hdrlen = sctp->sctp_hdr6_len;
2110Sstevel@tonic-gate 	}
2120Sstevel@tonic-gate 	if ((fp->sfa_pmss + hdrlen) != ire->ire_max_frag) {
2130Sstevel@tonic-gate 		/* Make sure that sfa_pmss is a multiple of SCTP_ALIGN. */
2140Sstevel@tonic-gate 		fp->sfa_pmss = (ire->ire_max_frag - hdrlen) & ~(SCTP_ALIGN - 1);
2150Sstevel@tonic-gate 		if (fp->cwnd < (fp->sfa_pmss * 2)) {
2160Sstevel@tonic-gate 			fp->cwnd = fp->sfa_pmss * sctp_slow_start_initial;
2170Sstevel@tonic-gate 		}
2180Sstevel@tonic-gate 	}
2190Sstevel@tonic-gate 
2200Sstevel@tonic-gate set_current:
2210Sstevel@tonic-gate 	if (fp == sctp->sctp_current) {
2220Sstevel@tonic-gate 		sctp_faddr2hdraddr(fp, sctp);
2230Sstevel@tonic-gate 		sctp->sctp_mss = fp->sfa_pmss;
2240Sstevel@tonic-gate 		if (!SCTP_IS_DETACHED(sctp)) {
2250Sstevel@tonic-gate 			sctp_set_ulp_prop(sctp);
2260Sstevel@tonic-gate 		}
2270Sstevel@tonic-gate 	}
2280Sstevel@tonic-gate }
2290Sstevel@tonic-gate 
2300Sstevel@tonic-gate /*ARGSUSED*/
2310Sstevel@tonic-gate void
2320Sstevel@tonic-gate sctp_faddr2ire(sctp_t *sctp, sctp_faddr_t *fp)
2330Sstevel@tonic-gate {
2340Sstevel@tonic-gate 	ire_t *ire;
2350Sstevel@tonic-gate 
2360Sstevel@tonic-gate 	if ((ire = fp->ire) == NULL) {
2370Sstevel@tonic-gate 		return;
2380Sstevel@tonic-gate 	}
2390Sstevel@tonic-gate 
2400Sstevel@tonic-gate 	mutex_enter(&ire->ire_lock);
2410Sstevel@tonic-gate 
2420Sstevel@tonic-gate 	/* If the cached IRE is going sway, there is no point to update it. */
2430Sstevel@tonic-gate 	if (ire->ire_marks & IRE_MARK_CONDEMNED) {
2440Sstevel@tonic-gate 		mutex_exit(&ire->ire_lock);
2450Sstevel@tonic-gate 		IRE_REFRELE_NOTR(ire);
2460Sstevel@tonic-gate 		fp->ire = NULL;
2470Sstevel@tonic-gate 		return;
2480Sstevel@tonic-gate 	}
2490Sstevel@tonic-gate 
2500Sstevel@tonic-gate 	/*
2510Sstevel@tonic-gate 	 * Only record the PMTU for this faddr if we actually have
2520Sstevel@tonic-gate 	 * done discovery. This prevents initialized default from
2530Sstevel@tonic-gate 	 * clobbering any real info that IP may have.
2540Sstevel@tonic-gate 	 */
2550Sstevel@tonic-gate 	if (fp->pmtu_discovered) {
2560Sstevel@tonic-gate 		if (fp->isv4) {
2570Sstevel@tonic-gate 			ire->ire_max_frag = fp->sfa_pmss + sctp->sctp_hdr_len;
2580Sstevel@tonic-gate 		} else {
2590Sstevel@tonic-gate 			ire->ire_max_frag = fp->sfa_pmss + sctp->sctp_hdr6_len;
2600Sstevel@tonic-gate 		}
2610Sstevel@tonic-gate 	}
2620Sstevel@tonic-gate 
263116Skcpoon 	if (sctp_rtt_updates != 0 && fp->rtt_updates >= sctp_rtt_updates) {
2640Sstevel@tonic-gate 		/*
2650Sstevel@tonic-gate 		 * If there is no old cached values, initialize them
2660Sstevel@tonic-gate 		 * conservatively.  Set them to be (1.5 * new value).
267116Skcpoon 		 * This code copied from ip_ire_advise().  The cached
268116Skcpoon 		 * value is in ms.
2690Sstevel@tonic-gate 		 */
2700Sstevel@tonic-gate 		if (ire->ire_uinfo.iulp_rtt != 0) {
2710Sstevel@tonic-gate 			ire->ire_uinfo.iulp_rtt = (ire->ire_uinfo.iulp_rtt +
272116Skcpoon 			    TICK_TO_MSEC(fp->srtt)) >> 1;
2730Sstevel@tonic-gate 		} else {
274116Skcpoon 			ire->ire_uinfo.iulp_rtt = TICK_TO_MSEC(fp->srtt +
275116Skcpoon 			    (fp->srtt >> 1));
2760Sstevel@tonic-gate 		}
2770Sstevel@tonic-gate 		if (ire->ire_uinfo.iulp_rtt_sd != 0) {
2780Sstevel@tonic-gate 			ire->ire_uinfo.iulp_rtt_sd =
2790Sstevel@tonic-gate 			    (ire->ire_uinfo.iulp_rtt_sd +
280116Skcpoon 			    TICK_TO_MSEC(fp->rttvar)) >> 1;
2810Sstevel@tonic-gate 		} else {
282116Skcpoon 			ire->ire_uinfo.iulp_rtt_sd = TICK_TO_MSEC(fp->rttvar +
283116Skcpoon 			    (fp->rttvar >> 1));
2840Sstevel@tonic-gate 		}
2850Sstevel@tonic-gate 		fp->rtt_updates = 0;
2860Sstevel@tonic-gate 	}
2870Sstevel@tonic-gate 
2880Sstevel@tonic-gate 	mutex_exit(&ire->ire_lock);
2890Sstevel@tonic-gate }
2900Sstevel@tonic-gate 
2910Sstevel@tonic-gate /*
2920Sstevel@tonic-gate  * The sender must set the total length in the IP header.
2930Sstevel@tonic-gate  * If sendto == NULL, the current will be used.
2940Sstevel@tonic-gate  */
2950Sstevel@tonic-gate mblk_t *
2960Sstevel@tonic-gate sctp_make_mp(sctp_t *sctp, sctp_faddr_t *sendto, int trailer)
2970Sstevel@tonic-gate {
2980Sstevel@tonic-gate 	mblk_t *mp;
2990Sstevel@tonic-gate 	size_t ipsctplen;
3000Sstevel@tonic-gate 	int isv4;
3010Sstevel@tonic-gate 	sctp_faddr_t *fp;
3020Sstevel@tonic-gate 
3030Sstevel@tonic-gate 	ASSERT(sctp->sctp_current != NULL || sendto != NULL);
3040Sstevel@tonic-gate 	if (sendto == NULL) {
3050Sstevel@tonic-gate 		fp = sctp->sctp_current;
3060Sstevel@tonic-gate 	} else {
3070Sstevel@tonic-gate 		fp = sendto;
3080Sstevel@tonic-gate 	}
3090Sstevel@tonic-gate 	isv4 = fp->isv4;
3100Sstevel@tonic-gate 
3110Sstevel@tonic-gate 	/* Try to look for another IRE again. */
3120Sstevel@tonic-gate 	if (fp->ire == NULL)
3130Sstevel@tonic-gate 		sctp_ire2faddr(sctp, fp);
3140Sstevel@tonic-gate 
3150Sstevel@tonic-gate 	/* There is no suitable source address to use, return. */
3160Sstevel@tonic-gate 	if (fp->state == SCTP_FADDRS_UNREACH)
3170Sstevel@tonic-gate 		return (NULL);
3180Sstevel@tonic-gate 
3190Sstevel@tonic-gate 	if (isv4) {
3200Sstevel@tonic-gate 		ipsctplen = sctp->sctp_hdr_len;
3210Sstevel@tonic-gate 	} else {
3220Sstevel@tonic-gate 		ipsctplen = sctp->sctp_hdr6_len;
3230Sstevel@tonic-gate 	}
3240Sstevel@tonic-gate 
3250Sstevel@tonic-gate 	mp = allocb(ipsctplen + sctp_wroff_xtra + trailer, BPRI_MED);
3260Sstevel@tonic-gate 	if (mp == NULL) {
3270Sstevel@tonic-gate 		ip1dbg(("sctp_make_mp: error makign mp..\n"));
3280Sstevel@tonic-gate 		return (NULL);
3290Sstevel@tonic-gate 	}
3300Sstevel@tonic-gate 	mp->b_rptr += sctp_wroff_xtra;
3310Sstevel@tonic-gate 	mp->b_wptr = mp->b_rptr + ipsctplen;
3320Sstevel@tonic-gate 
3330Sstevel@tonic-gate 	ASSERT(OK_32PTR(mp->b_wptr));
3340Sstevel@tonic-gate 
3350Sstevel@tonic-gate 	if (isv4) {
3360Sstevel@tonic-gate 		ipha_t *iph = (ipha_t *)mp->b_rptr;
3370Sstevel@tonic-gate 
3380Sstevel@tonic-gate 		bcopy(sctp->sctp_iphc, mp->b_rptr, ipsctplen);
3390Sstevel@tonic-gate 		if (fp != sctp->sctp_current) {
3400Sstevel@tonic-gate 			/* fiddle with the dst addr */
3410Sstevel@tonic-gate 			IN6_V4MAPPED_TO_IPADDR(&fp->faddr, iph->ipha_dst);
3420Sstevel@tonic-gate 			/* fix up src addr */
3430Sstevel@tonic-gate 			if (!IN6_IS_ADDR_V4MAPPED_ANY(&fp->saddr)) {
3440Sstevel@tonic-gate 				IN6_V4MAPPED_TO_IPADDR(&fp->saddr,
3450Sstevel@tonic-gate 				    iph->ipha_src);
3460Sstevel@tonic-gate 			} else if (sctp->sctp_bound_to_all) {
3470Sstevel@tonic-gate 				iph->ipha_src = INADDR_ANY;
3480Sstevel@tonic-gate 			}
3490Sstevel@tonic-gate 		}
3500Sstevel@tonic-gate 		/* set or clear the don't fragment bit */
3510Sstevel@tonic-gate 		if (fp->df) {
3520Sstevel@tonic-gate 			iph->ipha_fragment_offset_and_flags = htons(IPH_DF);
3530Sstevel@tonic-gate 		} else {
3540Sstevel@tonic-gate 			iph->ipha_fragment_offset_and_flags = 0;
3550Sstevel@tonic-gate 		}
3560Sstevel@tonic-gate 	} else {
3570Sstevel@tonic-gate 		bcopy(sctp->sctp_iphc6, mp->b_rptr, ipsctplen);
3580Sstevel@tonic-gate 		if (fp != sctp->sctp_current) {
3590Sstevel@tonic-gate 			/* fiddle with the dst addr */
3600Sstevel@tonic-gate 			((ip6_t *)(mp->b_rptr))->ip6_dst = fp->faddr;
3610Sstevel@tonic-gate 			/* fix up src addr */
3620Sstevel@tonic-gate 			if (!IN6_IS_ADDR_UNSPECIFIED(&fp->saddr)) {
3630Sstevel@tonic-gate 				((ip6_t *)(mp->b_rptr))->ip6_src = fp->saddr;
3640Sstevel@tonic-gate 			} else if (sctp->sctp_bound_to_all) {
3650Sstevel@tonic-gate 				bzero(&((ip6_t *)(mp->b_rptr))->ip6_src,
3660Sstevel@tonic-gate 				    sizeof (in6_addr_t));
3670Sstevel@tonic-gate 			}
3680Sstevel@tonic-gate 		}
3690Sstevel@tonic-gate 	}
3700Sstevel@tonic-gate 	ASSERT(sctp->sctp_connp != NULL);
3710Sstevel@tonic-gate 
3720Sstevel@tonic-gate 	/*
3730Sstevel@tonic-gate 	 * IP will not free this IRE if it is condemned.  SCTP needs to
3740Sstevel@tonic-gate 	 * free it.
3750Sstevel@tonic-gate 	 */
3760Sstevel@tonic-gate 	if ((fp->ire != NULL) && (fp->ire->ire_marks & IRE_MARK_CONDEMNED)) {
3770Sstevel@tonic-gate 		IRE_REFRELE_NOTR(fp->ire);
3780Sstevel@tonic-gate 		fp->ire = NULL;
3790Sstevel@tonic-gate 	}
3800Sstevel@tonic-gate 	/* Stash the conn and ire ptr info. for IP */
3810Sstevel@tonic-gate 	SCTP_STASH_IPINFO(mp, fp->ire);
3820Sstevel@tonic-gate 
3830Sstevel@tonic-gate 	return (mp);
3840Sstevel@tonic-gate }
3850Sstevel@tonic-gate 
3860Sstevel@tonic-gate /*
3870Sstevel@tonic-gate  * Notify upper layers about preferred write offset, write size.
3880Sstevel@tonic-gate  */
3890Sstevel@tonic-gate void
3900Sstevel@tonic-gate sctp_set_ulp_prop(sctp_t *sctp)
3910Sstevel@tonic-gate {
3920Sstevel@tonic-gate 	int hdrlen;
3930Sstevel@tonic-gate 
3940Sstevel@tonic-gate 	if (sctp->sctp_current->isv4) {
3950Sstevel@tonic-gate 		hdrlen = sctp->sctp_hdr_len;
3960Sstevel@tonic-gate 	} else {
3970Sstevel@tonic-gate 		hdrlen = sctp->sctp_hdr6_len;
3980Sstevel@tonic-gate 	}
3990Sstevel@tonic-gate 	ASSERT(sctp->sctp_ulpd);
4000Sstevel@tonic-gate 
4010Sstevel@tonic-gate 	ASSERT(sctp->sctp_current->sfa_pmss == sctp->sctp_mss);
4020Sstevel@tonic-gate 	sctp->sctp_ulp_prop(sctp->sctp_ulpd,
4030Sstevel@tonic-gate 	    sctp_wroff_xtra + hdrlen + sizeof (sctp_data_hdr_t),
4040Sstevel@tonic-gate 	    sctp->sctp_mss - sizeof (sctp_data_hdr_t));
4050Sstevel@tonic-gate }
4060Sstevel@tonic-gate 
4070Sstevel@tonic-gate void
4080Sstevel@tonic-gate sctp_set_iplen(sctp_t *sctp, mblk_t *mp)
4090Sstevel@tonic-gate {
4100Sstevel@tonic-gate 	uint16_t	sum = 0;
4110Sstevel@tonic-gate 	ipha_t		*iph;
4120Sstevel@tonic-gate 	ip6_t		*ip6h;
4130Sstevel@tonic-gate 	mblk_t		*pmp = mp;
4140Sstevel@tonic-gate 	boolean_t	isv4;
4150Sstevel@tonic-gate 
4160Sstevel@tonic-gate 	isv4 = (IPH_HDR_VERSION(mp->b_rptr) == IPV4_VERSION);
4170Sstevel@tonic-gate 	for (; pmp; pmp = pmp->b_cont)
4180Sstevel@tonic-gate 		sum += pmp->b_wptr - pmp->b_rptr;
4190Sstevel@tonic-gate 
4200Sstevel@tonic-gate 	if (isv4) {
4210Sstevel@tonic-gate 		iph = (ipha_t *)mp->b_rptr;
4220Sstevel@tonic-gate 		iph->ipha_length = htons(sum);
4230Sstevel@tonic-gate 	} else {
4240Sstevel@tonic-gate 		ip6h = (ip6_t *)mp->b_rptr;
425*679Sseb 		/*
426*679Sseb 		 * If an ip6i_t is present, the real IPv6 header
427*679Sseb 		 * immediately follows.
428*679Sseb 		 */
429*679Sseb 		if (ip6h->ip6_nxt == IPPROTO_RAW)
430*679Sseb 			ip6h = (ip6_t *)&ip6h[1];
4310Sstevel@tonic-gate 		ip6h->ip6_plen = htons(sum - ((char *)&sctp->sctp_ip6h[1] -
4320Sstevel@tonic-gate 		    sctp->sctp_iphc6));
4330Sstevel@tonic-gate 	}
4340Sstevel@tonic-gate }
4350Sstevel@tonic-gate 
4360Sstevel@tonic-gate int
4370Sstevel@tonic-gate sctp_compare_faddrsets(sctp_faddr_t *a1, sctp_faddr_t *a2)
4380Sstevel@tonic-gate {
4390Sstevel@tonic-gate 	int na1 = 0;
4400Sstevel@tonic-gate 	int overlap = 0;
4410Sstevel@tonic-gate 	int equal = 1;
4420Sstevel@tonic-gate 	int onematch;
4430Sstevel@tonic-gate 	sctp_faddr_t *fp1, *fp2;
4440Sstevel@tonic-gate 
4450Sstevel@tonic-gate 	for (fp1 = a1; fp1; fp1 = fp1->next) {
4460Sstevel@tonic-gate 		onematch = 0;
4470Sstevel@tonic-gate 		for (fp2 = a2; fp2; fp2 = fp2->next) {
4480Sstevel@tonic-gate 			if (IN6_ARE_ADDR_EQUAL(&fp1->faddr, &fp2->faddr)) {
4490Sstevel@tonic-gate 				overlap++;
4500Sstevel@tonic-gate 				onematch = 1;
4510Sstevel@tonic-gate 				break;
4520Sstevel@tonic-gate 			}
4530Sstevel@tonic-gate 			if (!onematch) {
4540Sstevel@tonic-gate 				equal = 0;
4550Sstevel@tonic-gate 			}
4560Sstevel@tonic-gate 		}
4570Sstevel@tonic-gate 		na1++;
4580Sstevel@tonic-gate 	}
4590Sstevel@tonic-gate 
4600Sstevel@tonic-gate 	if (equal) {
4610Sstevel@tonic-gate 		return (SCTP_ADDR_EQUAL);
4620Sstevel@tonic-gate 	}
4630Sstevel@tonic-gate 	if (overlap == na1) {
4640Sstevel@tonic-gate 		return (SCTP_ADDR_SUBSET);
4650Sstevel@tonic-gate 	}
4660Sstevel@tonic-gate 	if (overlap) {
4670Sstevel@tonic-gate 		return (SCTP_ADDR_OVERLAP);
4680Sstevel@tonic-gate 	}
4690Sstevel@tonic-gate 	return (SCTP_ADDR_DISJOINT);
4700Sstevel@tonic-gate }
4710Sstevel@tonic-gate 
4720Sstevel@tonic-gate /*
4730Sstevel@tonic-gate  * Returns 0 on success, -1 on memory allocation failure. If sleep
4740Sstevel@tonic-gate  * is true, should never fail.
4750Sstevel@tonic-gate  * Caller must hold conn fanout lock.
4760Sstevel@tonic-gate  */
4770Sstevel@tonic-gate int
4780Sstevel@tonic-gate sctp_add_faddr(sctp_t *sctp, in6_addr_t *addr, int sleep)
4790Sstevel@tonic-gate {
4800Sstevel@tonic-gate 	sctp_faddr_t *faddr;
4810Sstevel@tonic-gate 
4820Sstevel@tonic-gate 	dprint(4, ("add_faddr: %x:%x:%x:%x %d\n", SCTP_PRINTADDR(*addr),
4830Sstevel@tonic-gate 	    sleep));
4840Sstevel@tonic-gate 
4850Sstevel@tonic-gate 	if ((faddr = kmem_cache_alloc(sctp_kmem_faddr_cache, sleep)) == NULL) {
4860Sstevel@tonic-gate 		return (-1);
4870Sstevel@tonic-gate 	}
4880Sstevel@tonic-gate 
4890Sstevel@tonic-gate 	sctp_init_faddr(sctp, faddr, addr);
4900Sstevel@tonic-gate 	ASSERT(faddr->next == NULL);
4910Sstevel@tonic-gate 
4920Sstevel@tonic-gate 	/* tack it on to the end */
4930Sstevel@tonic-gate 	if (sctp->sctp_lastfaddr != NULL) {
4940Sstevel@tonic-gate 		sctp->sctp_lastfaddr->next = faddr;
4950Sstevel@tonic-gate 	} else {
4960Sstevel@tonic-gate 		/* list is empty */
4970Sstevel@tonic-gate 		ASSERT(sctp->sctp_faddrs == NULL);
4980Sstevel@tonic-gate 		sctp->sctp_faddrs = faddr;
4990Sstevel@tonic-gate 	}
5000Sstevel@tonic-gate 	sctp->sctp_lastfaddr = faddr;
5010Sstevel@tonic-gate 
5020Sstevel@tonic-gate 	return (0);
5030Sstevel@tonic-gate }
5040Sstevel@tonic-gate 
5050Sstevel@tonic-gate /*
5060Sstevel@tonic-gate  * Caller must hold conn fanout lock.
5070Sstevel@tonic-gate  */
5080Sstevel@tonic-gate int
5090Sstevel@tonic-gate sctp_add_faddr_first(sctp_t *sctp, in6_addr_t *addr, int sleep)
5100Sstevel@tonic-gate {
5110Sstevel@tonic-gate 	sctp_faddr_t *faddr;
5120Sstevel@tonic-gate 
5130Sstevel@tonic-gate 	dprint(4, ("add_faddr_first: %x:%x:%x:%x %d\n", SCTP_PRINTADDR(*addr),
5140Sstevel@tonic-gate 	    sleep));
5150Sstevel@tonic-gate 
5160Sstevel@tonic-gate 	if ((faddr = kmem_cache_alloc(sctp_kmem_faddr_cache, sleep)) == NULL) {
5170Sstevel@tonic-gate 		return (-1);
5180Sstevel@tonic-gate 	}
5190Sstevel@tonic-gate 	sctp_init_faddr(sctp, faddr, addr);
5200Sstevel@tonic-gate 	ASSERT(faddr->next == NULL);
5210Sstevel@tonic-gate 
5220Sstevel@tonic-gate 	/* Put it at the beginning of the list */
5230Sstevel@tonic-gate 	if (sctp->sctp_faddrs != NULL) {
5240Sstevel@tonic-gate 		faddr->next = sctp->sctp_faddrs;
5250Sstevel@tonic-gate 	} else {
5260Sstevel@tonic-gate 		sctp->sctp_lastfaddr = faddr;
5270Sstevel@tonic-gate 	}
5280Sstevel@tonic-gate 	sctp->sctp_faddrs = faddr;
5290Sstevel@tonic-gate 
5300Sstevel@tonic-gate 	return (0);
5310Sstevel@tonic-gate }
5320Sstevel@tonic-gate 
5330Sstevel@tonic-gate sctp_faddr_t *
5340Sstevel@tonic-gate sctp_lookup_faddr(sctp_t *sctp, in6_addr_t *addr)
5350Sstevel@tonic-gate {
5360Sstevel@tonic-gate 	sctp_faddr_t *fp;
5370Sstevel@tonic-gate 
5380Sstevel@tonic-gate 	for (fp = sctp->sctp_faddrs; fp != NULL; fp = fp->next) {
5390Sstevel@tonic-gate 		if (IN6_ARE_ADDR_EQUAL(&fp->faddr, addr))
5400Sstevel@tonic-gate 			break;
5410Sstevel@tonic-gate 	}
5420Sstevel@tonic-gate 
5430Sstevel@tonic-gate 	return (fp);
5440Sstevel@tonic-gate }
5450Sstevel@tonic-gate 
5460Sstevel@tonic-gate sctp_faddr_t *
5470Sstevel@tonic-gate sctp_lookup_faddr_nosctp(sctp_faddr_t *fp, in6_addr_t *addr)
5480Sstevel@tonic-gate {
5490Sstevel@tonic-gate 	for (; fp; fp = fp->next) {
5500Sstevel@tonic-gate 		if (IN6_ARE_ADDR_EQUAL(&fp->faddr, addr)) {
5510Sstevel@tonic-gate 			break;
5520Sstevel@tonic-gate 		}
5530Sstevel@tonic-gate 	}
5540Sstevel@tonic-gate 
5550Sstevel@tonic-gate 	return (fp);
5560Sstevel@tonic-gate }
5570Sstevel@tonic-gate 
5580Sstevel@tonic-gate void
5590Sstevel@tonic-gate sctp_faddr2hdraddr(sctp_faddr_t *fp, sctp_t *sctp)
5600Sstevel@tonic-gate {
5610Sstevel@tonic-gate 	if (fp->isv4) {
5620Sstevel@tonic-gate 		IN6_V4MAPPED_TO_IPADDR(&fp->faddr,
5630Sstevel@tonic-gate 		    sctp->sctp_ipha->ipha_dst);
5640Sstevel@tonic-gate 		/* Must not allow unspec src addr if not bound to all */
5650Sstevel@tonic-gate 		if (IN6_IS_ADDR_V4MAPPED_ANY(&fp->saddr) &&
5660Sstevel@tonic-gate 		    !sctp->sctp_bound_to_all) {
5670Sstevel@tonic-gate 			/*
5680Sstevel@tonic-gate 			 * set the src to the first v4 saddr and hope
5690Sstevel@tonic-gate 			 * for the best
5700Sstevel@tonic-gate 			 */
5710Sstevel@tonic-gate 			fp->saddr = sctp_get_valid_addr(sctp, B_FALSE);
5720Sstevel@tonic-gate 		}
5730Sstevel@tonic-gate 		IN6_V4MAPPED_TO_IPADDR(&fp->saddr, sctp->sctp_ipha->ipha_src);
5740Sstevel@tonic-gate 		/* update don't fragment bit */
5750Sstevel@tonic-gate 		if (fp->df) {
5760Sstevel@tonic-gate 			sctp->sctp_ipha->ipha_fragment_offset_and_flags =
5770Sstevel@tonic-gate 			    htons(IPH_DF);
5780Sstevel@tonic-gate 		} else {
5790Sstevel@tonic-gate 			sctp->sctp_ipha->ipha_fragment_offset_and_flags = 0;
5800Sstevel@tonic-gate 		}
5810Sstevel@tonic-gate 	} else {
5820Sstevel@tonic-gate 		sctp->sctp_ip6h->ip6_dst = fp->faddr;
5830Sstevel@tonic-gate 		/* Must not allow unspec src addr if not bound to all */
5840Sstevel@tonic-gate 		if (IN6_IS_ADDR_UNSPECIFIED(&fp->saddr) &&
5850Sstevel@tonic-gate 		    !sctp->sctp_bound_to_all) {
5860Sstevel@tonic-gate 			/*
5870Sstevel@tonic-gate 			 * set the src to the first v6 saddr and hope
5880Sstevel@tonic-gate 			 * for the best
5890Sstevel@tonic-gate 			 */
5900Sstevel@tonic-gate 			fp->saddr = sctp_get_valid_addr(sctp, B_TRUE);
5910Sstevel@tonic-gate 		}
5920Sstevel@tonic-gate 		sctp->sctp_ip6h->ip6_src = fp->saddr;
5930Sstevel@tonic-gate 	}
5940Sstevel@tonic-gate }
5950Sstevel@tonic-gate 
5960Sstevel@tonic-gate void
5970Sstevel@tonic-gate sctp_redo_faddr_srcs(sctp_t *sctp)
5980Sstevel@tonic-gate {
5990Sstevel@tonic-gate 	sctp_faddr_t *fp;
6000Sstevel@tonic-gate 
6010Sstevel@tonic-gate 	for (fp = sctp->sctp_faddrs; fp != NULL; fp = fp->next) {
6020Sstevel@tonic-gate 		sctp_ire2faddr(sctp, fp);
6030Sstevel@tonic-gate 	}
6040Sstevel@tonic-gate 
6050Sstevel@tonic-gate 	sctp_faddr2hdraddr(sctp->sctp_current, sctp);
6060Sstevel@tonic-gate }
6070Sstevel@tonic-gate 
6080Sstevel@tonic-gate void
6090Sstevel@tonic-gate sctp_faddr_alive(sctp_t *sctp, sctp_faddr_t *fp)
6100Sstevel@tonic-gate {
6110Sstevel@tonic-gate 	int64_t now = lbolt64;
6120Sstevel@tonic-gate 
6130Sstevel@tonic-gate 	fp->strikes = 0;
6140Sstevel@tonic-gate 	sctp->sctp_strikes = 0;
6150Sstevel@tonic-gate 	fp->lastactive = now;
6160Sstevel@tonic-gate 	fp->hb_expiry = now + SET_HB_INTVL(fp);
6170Sstevel@tonic-gate 	fp->hb_pending = B_FALSE;
6180Sstevel@tonic-gate 	if (fp->state != SCTP_FADDRS_ALIVE) {
6190Sstevel@tonic-gate 		fp->state = SCTP_FADDRS_ALIVE;
6200Sstevel@tonic-gate 		sctp_intf_event(sctp, fp->faddr, SCTP_ADDR_AVAILABLE, 0);
6210Sstevel@tonic-gate 
6220Sstevel@tonic-gate 		/* If this is the primary, switch back to it now */
6230Sstevel@tonic-gate 		if (fp == sctp->sctp_primary) {
6240Sstevel@tonic-gate 			sctp->sctp_current = fp;
6250Sstevel@tonic-gate 			sctp->sctp_mss = fp->sfa_pmss;
6260Sstevel@tonic-gate 			/* Reset the addrs in the composite header */
6270Sstevel@tonic-gate 			sctp_faddr2hdraddr(fp, sctp);
6280Sstevel@tonic-gate 			if (!SCTP_IS_DETACHED(sctp)) {
6290Sstevel@tonic-gate 				sctp_set_ulp_prop(sctp);
6300Sstevel@tonic-gate 			}
6310Sstevel@tonic-gate 		}
6320Sstevel@tonic-gate 	}
6330Sstevel@tonic-gate 	if (fp->ire == NULL) {
6340Sstevel@tonic-gate 		/* Should have a full IRE now */
6350Sstevel@tonic-gate 		sctp_ire2faddr(sctp, fp);
6360Sstevel@tonic-gate 	}
6370Sstevel@tonic-gate }
6380Sstevel@tonic-gate 
6390Sstevel@tonic-gate int
6400Sstevel@tonic-gate sctp_is_a_faddr_clean(sctp_t *sctp)
6410Sstevel@tonic-gate {
6420Sstevel@tonic-gate 	sctp_faddr_t *fp;
6430Sstevel@tonic-gate 
6440Sstevel@tonic-gate 	for (fp = sctp->sctp_faddrs; fp; fp = fp->next) {
6450Sstevel@tonic-gate 		if (fp->state == SCTP_FADDRS_ALIVE && fp->strikes == 0) {
6460Sstevel@tonic-gate 			return (1);
6470Sstevel@tonic-gate 		}
6480Sstevel@tonic-gate 	}
6490Sstevel@tonic-gate 
6500Sstevel@tonic-gate 	return (0);
6510Sstevel@tonic-gate }
6520Sstevel@tonic-gate 
6530Sstevel@tonic-gate /*
6540Sstevel@tonic-gate  * Returns 0 if there is at leave one other active faddr, -1 if there
6550Sstevel@tonic-gate  * are none. If there are none left, faddr_dead() will start killing the
6560Sstevel@tonic-gate  * association.
6570Sstevel@tonic-gate  * If the downed faddr was the current faddr, a new current faddr
6580Sstevel@tonic-gate  * will be chosen.
6590Sstevel@tonic-gate  */
6600Sstevel@tonic-gate int
6610Sstevel@tonic-gate sctp_faddr_dead(sctp_t *sctp, sctp_faddr_t *fp, int newstate)
6620Sstevel@tonic-gate {
6630Sstevel@tonic-gate 	sctp_faddr_t *ofp;
6640Sstevel@tonic-gate 
6650Sstevel@tonic-gate 	if (fp->state == SCTP_FADDRS_ALIVE) {
6660Sstevel@tonic-gate 		sctp_intf_event(sctp, fp->faddr, SCTP_ADDR_UNREACHABLE, 0);
6670Sstevel@tonic-gate 	}
6680Sstevel@tonic-gate 	fp->state = newstate;
6690Sstevel@tonic-gate 
6700Sstevel@tonic-gate 	dprint(1, ("sctp_faddr_dead: %x:%x:%x:%x down (state=%d)\n",
6710Sstevel@tonic-gate 	    SCTP_PRINTADDR(fp->faddr), newstate));
6720Sstevel@tonic-gate 
6730Sstevel@tonic-gate 	if (fp == sctp->sctp_current) {
6740Sstevel@tonic-gate 		/* Current faddr down; need to switch it */
6750Sstevel@tonic-gate 		sctp->sctp_current = NULL;
6760Sstevel@tonic-gate 	}
6770Sstevel@tonic-gate 
6780Sstevel@tonic-gate 	/* Find next alive faddr */
6790Sstevel@tonic-gate 	ofp = fp;
6800Sstevel@tonic-gate 	for (fp = fp->next; fp; fp = fp->next) {
6810Sstevel@tonic-gate 		if (fp->state == SCTP_FADDRS_ALIVE) {
6820Sstevel@tonic-gate 			break;
6830Sstevel@tonic-gate 		}
6840Sstevel@tonic-gate 	}
6850Sstevel@tonic-gate 
6860Sstevel@tonic-gate 	if (fp == NULL) {
6870Sstevel@tonic-gate 		/* Continue from beginning of list */
6880Sstevel@tonic-gate 		for (fp = sctp->sctp_faddrs; fp != ofp; fp = fp->next) {
6890Sstevel@tonic-gate 			if (fp->state == SCTP_FADDRS_ALIVE) {
6900Sstevel@tonic-gate 				break;
6910Sstevel@tonic-gate 			}
6920Sstevel@tonic-gate 		}
6930Sstevel@tonic-gate 	}
6940Sstevel@tonic-gate 
6950Sstevel@tonic-gate 	if (fp != ofp) {
6960Sstevel@tonic-gate 		if (sctp->sctp_current == NULL) {
6970Sstevel@tonic-gate 			dprint(1, ("sctp_faddr_dead: failover->%x:%x:%x:%x\n",
6980Sstevel@tonic-gate 			    SCTP_PRINTADDR(fp->faddr)));
6990Sstevel@tonic-gate 			sctp->sctp_current = fp;
7000Sstevel@tonic-gate 			sctp->sctp_mss = fp->sfa_pmss;
7010Sstevel@tonic-gate 
7020Sstevel@tonic-gate 			/* Reset the addrs in the composite header */
7030Sstevel@tonic-gate 			sctp_faddr2hdraddr(fp, sctp);
7040Sstevel@tonic-gate 
7050Sstevel@tonic-gate 			if (!SCTP_IS_DETACHED(sctp)) {
7060Sstevel@tonic-gate 				sctp_set_ulp_prop(sctp);
7070Sstevel@tonic-gate 			}
7080Sstevel@tonic-gate 		}
7090Sstevel@tonic-gate 		return (0);
7100Sstevel@tonic-gate 	}
7110Sstevel@tonic-gate 
7120Sstevel@tonic-gate 
7130Sstevel@tonic-gate 	/* All faddrs are down; kill the association */
7140Sstevel@tonic-gate 	dprint(1, ("sctp_faddr_dead: all faddrs down, killing assoc\n"));
7150Sstevel@tonic-gate 	BUMP_MIB(&sctp_mib, sctpAborted);
7160Sstevel@tonic-gate 	sctp_assoc_event(sctp, sctp->sctp_state < SCTPS_ESTABLISHED ?
7170Sstevel@tonic-gate 	    SCTP_CANT_STR_ASSOC : SCTP_COMM_LOST, 0, NULL);
7180Sstevel@tonic-gate 	sctp_clean_death(sctp, sctp->sctp_client_errno ?
7190Sstevel@tonic-gate 	    sctp->sctp_client_errno : ETIMEDOUT);
7200Sstevel@tonic-gate 
7210Sstevel@tonic-gate 	return (-1);
7220Sstevel@tonic-gate }
7230Sstevel@tonic-gate 
7240Sstevel@tonic-gate sctp_faddr_t *
7250Sstevel@tonic-gate sctp_rotate_faddr(sctp_t *sctp, sctp_faddr_t *ofp)
7260Sstevel@tonic-gate {
7270Sstevel@tonic-gate 	sctp_faddr_t *nfp = NULL;
7280Sstevel@tonic-gate 
7290Sstevel@tonic-gate 	if (ofp == NULL) {
7300Sstevel@tonic-gate 		ofp = sctp->sctp_current;
7310Sstevel@tonic-gate 	}
7320Sstevel@tonic-gate 
7330Sstevel@tonic-gate 	/* Find the next live one */
7340Sstevel@tonic-gate 	for (nfp = ofp->next; nfp != NULL; nfp = nfp->next) {
7350Sstevel@tonic-gate 		if (nfp->state == SCTP_FADDRS_ALIVE) {
7360Sstevel@tonic-gate 			break;
7370Sstevel@tonic-gate 		}
7380Sstevel@tonic-gate 	}
7390Sstevel@tonic-gate 
7400Sstevel@tonic-gate 	if (nfp == NULL) {
7410Sstevel@tonic-gate 		/* Continue from beginning of list */
7420Sstevel@tonic-gate 		for (nfp = sctp->sctp_faddrs; nfp != ofp; nfp = nfp->next) {
7430Sstevel@tonic-gate 			if (nfp->state == SCTP_FADDRS_ALIVE) {
7440Sstevel@tonic-gate 				break;
7450Sstevel@tonic-gate 			}
7460Sstevel@tonic-gate 		}
7470Sstevel@tonic-gate 	}
7480Sstevel@tonic-gate 
7490Sstevel@tonic-gate 	/*
7500Sstevel@tonic-gate 	 * nfp could only be NULL if all faddrs are down, and when
7510Sstevel@tonic-gate 	 * this happens, faddr_dead() should have killed the
7520Sstevel@tonic-gate 	 * association. Hence this assertion...
7530Sstevel@tonic-gate 	 */
7540Sstevel@tonic-gate 	ASSERT(nfp != NULL);
7550Sstevel@tonic-gate 	return (nfp);
7560Sstevel@tonic-gate }
7570Sstevel@tonic-gate 
7580Sstevel@tonic-gate void
7590Sstevel@tonic-gate sctp_unlink_faddr(sctp_t *sctp, sctp_faddr_t *fp)
7600Sstevel@tonic-gate {
7610Sstevel@tonic-gate 	sctp_faddr_t *fpp;
7620Sstevel@tonic-gate 
7630Sstevel@tonic-gate 	if (!sctp->sctp_faddrs) {
7640Sstevel@tonic-gate 		return;
7650Sstevel@tonic-gate 	}
7660Sstevel@tonic-gate 
7670Sstevel@tonic-gate 	if (fp->timer_mp != NULL) {
7680Sstevel@tonic-gate 		sctp_timer_free(fp->timer_mp);
7690Sstevel@tonic-gate 		fp->timer_mp = NULL;
7700Sstevel@tonic-gate 		fp->timer_running = 0;
7710Sstevel@tonic-gate 	}
7720Sstevel@tonic-gate 	if (fp->rc_timer_mp != NULL) {
7730Sstevel@tonic-gate 		sctp_timer_free(fp->rc_timer_mp);
7740Sstevel@tonic-gate 		fp->rc_timer_mp = NULL;
7750Sstevel@tonic-gate 		fp->rc_timer_running = 0;
7760Sstevel@tonic-gate 	}
7770Sstevel@tonic-gate 	if (fp->ire != NULL) {
7780Sstevel@tonic-gate 		IRE_REFRELE_NOTR(fp->ire);
7790Sstevel@tonic-gate 		fp->ire = NULL;
7800Sstevel@tonic-gate 	}
7810Sstevel@tonic-gate 
7820Sstevel@tonic-gate 	if (fp == sctp->sctp_faddrs) {
7830Sstevel@tonic-gate 		goto gotit;
7840Sstevel@tonic-gate 	}
7850Sstevel@tonic-gate 
7860Sstevel@tonic-gate 	for (fpp = sctp->sctp_faddrs; fpp->next != fp; fpp = fpp->next)
7870Sstevel@tonic-gate 		;
7880Sstevel@tonic-gate 
7890Sstevel@tonic-gate gotit:
7900Sstevel@tonic-gate 	ASSERT(sctp->sctp_conn_tfp != NULL);
7910Sstevel@tonic-gate 	mutex_enter(&sctp->sctp_conn_tfp->tf_lock);
7920Sstevel@tonic-gate 	if (fp == sctp->sctp_faddrs) {
7930Sstevel@tonic-gate 		sctp->sctp_faddrs = fp->next;
7940Sstevel@tonic-gate 	} else {
7950Sstevel@tonic-gate 		fpp->next = fp->next;
7960Sstevel@tonic-gate 	}
7970Sstevel@tonic-gate 	mutex_exit(&sctp->sctp_conn_tfp->tf_lock);
7980Sstevel@tonic-gate 	/* XXX faddr2ire? */
7990Sstevel@tonic-gate 	kmem_cache_free(sctp_kmem_faddr_cache, fp);
8000Sstevel@tonic-gate }
8010Sstevel@tonic-gate 
8020Sstevel@tonic-gate void
8030Sstevel@tonic-gate sctp_zap_faddrs(sctp_t *sctp, int caller_holds_lock)
8040Sstevel@tonic-gate {
8050Sstevel@tonic-gate 	sctp_faddr_t *fp, *fpn;
8060Sstevel@tonic-gate 
8070Sstevel@tonic-gate 	if (sctp->sctp_faddrs == NULL) {
8080Sstevel@tonic-gate 		ASSERT(sctp->sctp_lastfaddr == NULL);
8090Sstevel@tonic-gate 		return;
8100Sstevel@tonic-gate 	}
8110Sstevel@tonic-gate 
8120Sstevel@tonic-gate 	ASSERT(sctp->sctp_lastfaddr != NULL);
8130Sstevel@tonic-gate 	sctp->sctp_lastfaddr = NULL;
8140Sstevel@tonic-gate 	sctp->sctp_current = NULL;
8150Sstevel@tonic-gate 	sctp->sctp_primary = NULL;
8160Sstevel@tonic-gate 
8170Sstevel@tonic-gate 	sctp_free_faddr_timers(sctp);
8180Sstevel@tonic-gate 
8190Sstevel@tonic-gate 	if (sctp->sctp_conn_tfp != NULL && !caller_holds_lock) {
8200Sstevel@tonic-gate 		/* in conn fanout; need to hold lock */
8210Sstevel@tonic-gate 		mutex_enter(&sctp->sctp_conn_tfp->tf_lock);
8220Sstevel@tonic-gate 	}
8230Sstevel@tonic-gate 
8240Sstevel@tonic-gate 	for (fp = sctp->sctp_faddrs; fp; fp = fpn) {
8250Sstevel@tonic-gate 		fpn = fp->next;
8260Sstevel@tonic-gate 		if (fp->ire != NULL)
8270Sstevel@tonic-gate 			IRE_REFRELE_NOTR(fp->ire);
8280Sstevel@tonic-gate 		kmem_cache_free(sctp_kmem_faddr_cache, fp);
8290Sstevel@tonic-gate 	}
8300Sstevel@tonic-gate 
8310Sstevel@tonic-gate 	sctp->sctp_faddrs = NULL;
8320Sstevel@tonic-gate 
8330Sstevel@tonic-gate 	if (sctp->sctp_conn_tfp != NULL && !caller_holds_lock) {
8340Sstevel@tonic-gate 		mutex_exit(&sctp->sctp_conn_tfp->tf_lock);
8350Sstevel@tonic-gate 	}
8360Sstevel@tonic-gate 
8370Sstevel@tonic-gate }
8380Sstevel@tonic-gate 
8390Sstevel@tonic-gate void
8400Sstevel@tonic-gate sctp_zap_addrs(sctp_t *sctp)
8410Sstevel@tonic-gate {
8420Sstevel@tonic-gate 	sctp_zap_faddrs(sctp, 0);
8430Sstevel@tonic-gate 	sctp_free_saddrs(sctp);
8440Sstevel@tonic-gate }
8450Sstevel@tonic-gate 
8460Sstevel@tonic-gate /*
8470Sstevel@tonic-gate  * Initialize the IPv4 header. Loses any record of any IP options.
8480Sstevel@tonic-gate  */
8490Sstevel@tonic-gate int
8500Sstevel@tonic-gate sctp_header_init_ipv4(sctp_t *sctp, int sleep)
8510Sstevel@tonic-gate {
8520Sstevel@tonic-gate 	sctp_hdr_t	*sctph;
8530Sstevel@tonic-gate 
8540Sstevel@tonic-gate 	/*
8550Sstevel@tonic-gate 	 * This is a simple initialization. If there's
8560Sstevel@tonic-gate 	 * already a template, it should never be too small,
8570Sstevel@tonic-gate 	 * so reuse it.  Otherwise, allocate space for the new one.
8580Sstevel@tonic-gate 	 */
8590Sstevel@tonic-gate 	if (sctp->sctp_iphc != NULL) {
8600Sstevel@tonic-gate 		ASSERT(sctp->sctp_iphc_len >= SCTP_MAX_COMBINED_HEADER_LENGTH);
8610Sstevel@tonic-gate 		bzero(sctp->sctp_iphc, sctp->sctp_iphc_len);
8620Sstevel@tonic-gate 	} else {
8630Sstevel@tonic-gate 		sctp->sctp_iphc_len = SCTP_MAX_COMBINED_HEADER_LENGTH;
8640Sstevel@tonic-gate 		sctp->sctp_iphc = kmem_zalloc(sctp->sctp_iphc_len, sleep);
8650Sstevel@tonic-gate 		if (sctp->sctp_iphc == NULL) {
8660Sstevel@tonic-gate 			sctp->sctp_iphc_len = 0;
8670Sstevel@tonic-gate 			return (ENOMEM);
8680Sstevel@tonic-gate 		}
8690Sstevel@tonic-gate 	}
8700Sstevel@tonic-gate 
8710Sstevel@tonic-gate 	sctp->sctp_ipha = (ipha_t *)sctp->sctp_iphc;
8720Sstevel@tonic-gate 
8730Sstevel@tonic-gate 	sctp->sctp_hdr_len = sizeof (ipha_t) + sizeof (sctp_hdr_t);
8740Sstevel@tonic-gate 	sctp->sctp_ip_hdr_len = sizeof (ipha_t);
8750Sstevel@tonic-gate 	sctp->sctp_ipha->ipha_length = htons(sizeof (ipha_t) +
8760Sstevel@tonic-gate 	    sizeof (sctp_hdr_t));
8770Sstevel@tonic-gate 	sctp->sctp_ipha->ipha_version_and_hdr_length
8780Sstevel@tonic-gate 		= (IP_VERSION << 4) | IP_SIMPLE_HDR_LENGTH_IN_WORDS;
8790Sstevel@tonic-gate 
8800Sstevel@tonic-gate 	/*
8810Sstevel@tonic-gate 	 * These two fields should be zero, and are already set above.
8820Sstevel@tonic-gate 	 *
8830Sstevel@tonic-gate 	 * sctp->sctp_ipha->ipha_ident,
8840Sstevel@tonic-gate 	 * sctp->sctp_ipha->ipha_fragment_offset_and_flags.
8850Sstevel@tonic-gate 	 */
8860Sstevel@tonic-gate 
8870Sstevel@tonic-gate 	sctp->sctp_ipha->ipha_ttl = sctp_ipv4_ttl;
8880Sstevel@tonic-gate 	sctp->sctp_ipha->ipha_protocol = IPPROTO_SCTP;
8890Sstevel@tonic-gate 
8900Sstevel@tonic-gate 	sctph = (sctp_hdr_t *)(sctp->sctp_iphc + sizeof (ipha_t));
8910Sstevel@tonic-gate 	sctp->sctp_sctph = sctph;
8920Sstevel@tonic-gate 
8930Sstevel@tonic-gate 	return (0);
8940Sstevel@tonic-gate }
8950Sstevel@tonic-gate 
8960Sstevel@tonic-gate /*
8970Sstevel@tonic-gate  * Update sctp_sticky_hdrs based on sctp_sticky_ipp.
8980Sstevel@tonic-gate  * The headers include ip6i_t (if needed), ip6_t, any sticky extension
8990Sstevel@tonic-gate  * headers, and the maximum size sctp header (to avoid reallocation
9000Sstevel@tonic-gate  * on the fly for additional sctp options).
9010Sstevel@tonic-gate  * Returns failure if can't allocate memory.
9020Sstevel@tonic-gate  */
9030Sstevel@tonic-gate int
9040Sstevel@tonic-gate sctp_build_hdrs(sctp_t *sctp)
9050Sstevel@tonic-gate {
9060Sstevel@tonic-gate 	char		*hdrs;
9070Sstevel@tonic-gate 	uint_t		hdrs_len;
9080Sstevel@tonic-gate 	ip6i_t		*ip6i;
9090Sstevel@tonic-gate 	char		buf[SCTP_MAX_HDR_LENGTH];
9100Sstevel@tonic-gate 	ip6_pkt_t	*ipp = &sctp->sctp_sticky_ipp;
9110Sstevel@tonic-gate 	in6_addr_t	src;
9120Sstevel@tonic-gate 	in6_addr_t	dst;
9130Sstevel@tonic-gate 	/*
9140Sstevel@tonic-gate 	 * save the existing sctp header and source/dest IP addresses
9150Sstevel@tonic-gate 	 */
9160Sstevel@tonic-gate 	bcopy(sctp->sctp_sctph6, buf, sizeof (sctp_hdr_t));
9170Sstevel@tonic-gate 	src = sctp->sctp_ip6h->ip6_src;
9180Sstevel@tonic-gate 	dst = sctp->sctp_ip6h->ip6_dst;
9190Sstevel@tonic-gate 	hdrs_len = ip_total_hdrs_len_v6(ipp) + SCTP_MAX_HDR_LENGTH;
9200Sstevel@tonic-gate 	ASSERT(hdrs_len != 0);
9210Sstevel@tonic-gate 	if (hdrs_len > sctp->sctp_iphc6_len) {
9220Sstevel@tonic-gate 		/* Need to reallocate */
9230Sstevel@tonic-gate 		hdrs = kmem_zalloc(hdrs_len, KM_NOSLEEP);
9240Sstevel@tonic-gate 		if (hdrs == NULL)
9250Sstevel@tonic-gate 			return (ENOMEM);
9260Sstevel@tonic-gate 
9270Sstevel@tonic-gate 		if (sctp->sctp_iphc6_len != 0)
9280Sstevel@tonic-gate 			kmem_free(sctp->sctp_iphc6, sctp->sctp_iphc6_len);
9290Sstevel@tonic-gate 		sctp->sctp_iphc6 = hdrs;
9300Sstevel@tonic-gate 		sctp->sctp_iphc6_len = hdrs_len;
9310Sstevel@tonic-gate 	}
9320Sstevel@tonic-gate 	ip_build_hdrs_v6((uchar_t *)sctp->sctp_iphc6,
9330Sstevel@tonic-gate 	    hdrs_len - SCTP_MAX_HDR_LENGTH, ipp, IPPROTO_SCTP);
9340Sstevel@tonic-gate 
9350Sstevel@tonic-gate 	/* Set header fields not in ipp */
9360Sstevel@tonic-gate 	if (ipp->ipp_fields & IPPF_HAS_IP6I) {
9370Sstevel@tonic-gate 		ip6i = (ip6i_t *)sctp->sctp_iphc6;
9380Sstevel@tonic-gate 		sctp->sctp_ip6h = (ip6_t *)&ip6i[1];
9390Sstevel@tonic-gate 	} else {
9400Sstevel@tonic-gate 		sctp->sctp_ip6h = (ip6_t *)sctp->sctp_iphc6;
9410Sstevel@tonic-gate 	}
9420Sstevel@tonic-gate 	/*
9430Sstevel@tonic-gate 	 * sctp->sctp_ip_hdr_len will include ip6i_t if there is one.
9440Sstevel@tonic-gate 	 */
9450Sstevel@tonic-gate 	sctp->sctp_ip_hdr6_len = hdrs_len - SCTP_MAX_HDR_LENGTH;
9460Sstevel@tonic-gate 	sctp->sctp_sctph6 = (sctp_hdr_t *)(sctp->sctp_iphc6 +
9470Sstevel@tonic-gate 	    sctp->sctp_ip_hdr6_len);
9480Sstevel@tonic-gate 	sctp->sctp_hdr6_len = sctp->sctp_ip_hdr6_len + sizeof (sctp_hdr_t);
9490Sstevel@tonic-gate 
9500Sstevel@tonic-gate 	bcopy(buf, sctp->sctp_sctph6, sizeof (sctp_hdr_t));
9510Sstevel@tonic-gate 
9520Sstevel@tonic-gate 	sctp->sctp_ip6h->ip6_src = src;
9530Sstevel@tonic-gate 	sctp->sctp_ip6h->ip6_dst = dst;
9540Sstevel@tonic-gate 	/*
955*679Sseb 	 * If the hoplimit was not set by ip_build_hdrs_v6(), we need to
956*679Sseb 	 * set it to the default value for SCTP.
9570Sstevel@tonic-gate 	 */
958*679Sseb 	if (!(ipp->ipp_fields & IPPF_UNICAST_HOPS))
959*679Sseb 		sctp->sctp_ip6h->ip6_hops = sctp_ipv6_hoplimit;
9600Sstevel@tonic-gate 	/*
9610Sstevel@tonic-gate 	 * If we're setting extension headers after a connection
9620Sstevel@tonic-gate 	 * has been established, and if we have a routing header
9630Sstevel@tonic-gate 	 * among the extension headers, call ip_massage_options_v6 to
9640Sstevel@tonic-gate 	 * manipulate the routing header/ip6_dst set the checksum
9650Sstevel@tonic-gate 	 * difference in the sctp header template.
9660Sstevel@tonic-gate 	 * (This happens in sctp_connect_ipv6 if the routing header
9670Sstevel@tonic-gate 	 * is set prior to the connect.)
9680Sstevel@tonic-gate 	 */
9690Sstevel@tonic-gate 
9700Sstevel@tonic-gate 	if ((sctp->sctp_state >= SCTPS_COOKIE_WAIT) &&
9710Sstevel@tonic-gate 	    (sctp->sctp_sticky_ipp.ipp_fields & IPPF_RTHDR)) {
9720Sstevel@tonic-gate 		ip6_rthdr_t *rth;
9730Sstevel@tonic-gate 
9740Sstevel@tonic-gate 		rth = ip_find_rthdr_v6(sctp->sctp_ip6h,
9750Sstevel@tonic-gate 		    (uint8_t *)sctp->sctp_sctph6);
9760Sstevel@tonic-gate 		if (rth != NULL)
9770Sstevel@tonic-gate 			(void) ip_massage_options_v6(sctp->sctp_ip6h, rth);
9780Sstevel@tonic-gate 	}
9790Sstevel@tonic-gate 	return (0);
9800Sstevel@tonic-gate }
9810Sstevel@tonic-gate 
9820Sstevel@tonic-gate /*
9830Sstevel@tonic-gate  * Initialize the IPv6 header. Loses any record of any IPv6 extension headers.
9840Sstevel@tonic-gate  */
9850Sstevel@tonic-gate int
9860Sstevel@tonic-gate sctp_header_init_ipv6(sctp_t *sctp, int sleep)
9870Sstevel@tonic-gate {
9880Sstevel@tonic-gate 	sctp_hdr_t	*sctph;
9890Sstevel@tonic-gate 
9900Sstevel@tonic-gate 	/*
9910Sstevel@tonic-gate 	 * This is a simple initialization. If there's
9920Sstevel@tonic-gate 	 * already a template, it should never be too small,
9930Sstevel@tonic-gate 	 * so reuse it. Otherwise, allocate space for the new one.
9940Sstevel@tonic-gate 	 * Ensure that there is enough space to "downgrade" the sctp_t
9950Sstevel@tonic-gate 	 * to an IPv4 sctp_t. This requires having space for a full load
9960Sstevel@tonic-gate 	 * of IPv4 options
9970Sstevel@tonic-gate 	 */
9980Sstevel@tonic-gate 	if (sctp->sctp_iphc6 != NULL) {
9990Sstevel@tonic-gate 		ASSERT(sctp->sctp_iphc6_len >=
10000Sstevel@tonic-gate 		    SCTP_MAX_COMBINED_HEADER_LENGTH);
10010Sstevel@tonic-gate 		bzero(sctp->sctp_iphc6, sctp->sctp_iphc6_len);
10020Sstevel@tonic-gate 	} else {
10030Sstevel@tonic-gate 		sctp->sctp_iphc6_len = SCTP_MAX_COMBINED_HEADER_LENGTH;
10040Sstevel@tonic-gate 		sctp->sctp_iphc6 = kmem_zalloc(sctp->sctp_iphc_len, sleep);
10050Sstevel@tonic-gate 		if (sctp->sctp_iphc6 == NULL) {
10060Sstevel@tonic-gate 			sctp->sctp_iphc6_len = 0;
10070Sstevel@tonic-gate 			return (ENOMEM);
10080Sstevel@tonic-gate 		}
10090Sstevel@tonic-gate 	}
10100Sstevel@tonic-gate 	sctp->sctp_hdr6_len = IPV6_HDR_LEN + sizeof (sctp_hdr_t);
10110Sstevel@tonic-gate 	sctp->sctp_ip_hdr6_len = IPV6_HDR_LEN;
10120Sstevel@tonic-gate 	sctp->sctp_ip6h = (ip6_t *)sctp->sctp_iphc6;
10130Sstevel@tonic-gate 
10140Sstevel@tonic-gate 	/* Initialize the header template */
10150Sstevel@tonic-gate 
10160Sstevel@tonic-gate 	sctp->sctp_ip6h->ip6_vcf = IPV6_DEFAULT_VERS_AND_FLOW;
10170Sstevel@tonic-gate 	sctp->sctp_ip6h->ip6_plen = ntohs(sizeof (sctp_hdr_t));
10180Sstevel@tonic-gate 	sctp->sctp_ip6h->ip6_nxt = IPPROTO_SCTP;
10190Sstevel@tonic-gate 	sctp->sctp_ip6h->ip6_hops = sctp_ipv6_hoplimit;
10200Sstevel@tonic-gate 
10210Sstevel@tonic-gate 	sctph = (sctp_hdr_t *)(sctp->sctp_iphc6 + IPV6_HDR_LEN);
10220Sstevel@tonic-gate 	sctp->sctp_sctph6 = sctph;
10230Sstevel@tonic-gate 
10240Sstevel@tonic-gate 	return (0);
10250Sstevel@tonic-gate }
10260Sstevel@tonic-gate 
10270Sstevel@tonic-gate /*
10280Sstevel@tonic-gate  * XXX implement more sophisticated logic
10290Sstevel@tonic-gate  */
10300Sstevel@tonic-gate void
10310Sstevel@tonic-gate sctp_set_hdraddrs(sctp_t *sctp)
10320Sstevel@tonic-gate {
10330Sstevel@tonic-gate 	sctp_faddr_t *fp;
10340Sstevel@tonic-gate 	int gotv4 = 0;
10350Sstevel@tonic-gate 	int gotv6 = 0;
10360Sstevel@tonic-gate 
10370Sstevel@tonic-gate 	ASSERT(sctp->sctp_faddrs != NULL);
10380Sstevel@tonic-gate 	ASSERT(sctp->sctp_nsaddrs > 0);
10390Sstevel@tonic-gate 
10400Sstevel@tonic-gate 	/* Set up using the primary first */
10410Sstevel@tonic-gate 	if (IN6_IS_ADDR_V4MAPPED(&sctp->sctp_primary->faddr)) {
10420Sstevel@tonic-gate 		IN6_V4MAPPED_TO_IPADDR(&sctp->sctp_primary->faddr,
10430Sstevel@tonic-gate 		    sctp->sctp_ipha->ipha_dst);
10440Sstevel@tonic-gate 		/* saddr may be unspec; make_mp() will handle this */
10450Sstevel@tonic-gate 		IN6_V4MAPPED_TO_IPADDR(&sctp->sctp_primary->saddr,
10460Sstevel@tonic-gate 		    sctp->sctp_ipha->ipha_src);
10470Sstevel@tonic-gate 		gotv4 = 1;
10480Sstevel@tonic-gate 		if (sctp->sctp_ipversion == IPV4_VERSION) {
10490Sstevel@tonic-gate 			goto copyports;
10500Sstevel@tonic-gate 		}
10510Sstevel@tonic-gate 	} else {
10520Sstevel@tonic-gate 		sctp->sctp_ip6h->ip6_dst = sctp->sctp_primary->faddr;
10530Sstevel@tonic-gate 		/* saddr may be unspec; make_mp() will handle this */
10540Sstevel@tonic-gate 		sctp->sctp_ip6h->ip6_src = sctp->sctp_primary->saddr;
10550Sstevel@tonic-gate 		gotv6 = 1;
10560Sstevel@tonic-gate 	}
10570Sstevel@tonic-gate 
10580Sstevel@tonic-gate 	for (fp = sctp->sctp_faddrs; fp; fp = fp->next) {
10590Sstevel@tonic-gate 		if (!gotv4 && IN6_IS_ADDR_V4MAPPED(&fp->faddr)) {
10600Sstevel@tonic-gate 			IN6_V4MAPPED_TO_IPADDR(&fp->faddr,
10610Sstevel@tonic-gate 			    sctp->sctp_ipha->ipha_dst);
10620Sstevel@tonic-gate 			/* copy in the faddr_t's saddr */
10630Sstevel@tonic-gate 			IN6_V4MAPPED_TO_IPADDR(&fp->saddr,
10640Sstevel@tonic-gate 			    sctp->sctp_ipha->ipha_src);
10650Sstevel@tonic-gate 			gotv4 = 1;
10660Sstevel@tonic-gate 			if (sctp->sctp_ipversion == IPV4_VERSION || gotv6) {
10670Sstevel@tonic-gate 				break;
10680Sstevel@tonic-gate 			}
10690Sstevel@tonic-gate 		} else if (!gotv6) {
10700Sstevel@tonic-gate 			sctp->sctp_ip6h->ip6_dst = fp->faddr;
10710Sstevel@tonic-gate 			/* copy in the faddr_t's saddr */
10720Sstevel@tonic-gate 			sctp->sctp_ip6h->ip6_src = fp->saddr;
10730Sstevel@tonic-gate 			gotv6 = 1;
10740Sstevel@tonic-gate 			if (gotv4) {
10750Sstevel@tonic-gate 				break;
10760Sstevel@tonic-gate 			}
10770Sstevel@tonic-gate 		}
10780Sstevel@tonic-gate 	}
10790Sstevel@tonic-gate 
10800Sstevel@tonic-gate copyports:
10810Sstevel@tonic-gate 	/* copy in the ports for good measure */
10820Sstevel@tonic-gate 	sctp->sctp_sctph->sh_sport = sctp->sctp_lport;
10830Sstevel@tonic-gate 	sctp->sctp_sctph->sh_dport = sctp->sctp_fport;
10840Sstevel@tonic-gate 
10850Sstevel@tonic-gate 	sctp->sctp_sctph6->sh_sport = sctp->sctp_lport;
10860Sstevel@tonic-gate 	sctp->sctp_sctph6->sh_dport = sctp->sctp_fport;
10870Sstevel@tonic-gate }
10880Sstevel@tonic-gate 
10890Sstevel@tonic-gate void
10900Sstevel@tonic-gate sctp_add_unrec_parm(sctp_parm_hdr_t *uph, mblk_t **errmp)
10910Sstevel@tonic-gate {
10920Sstevel@tonic-gate 	mblk_t *mp;
10930Sstevel@tonic-gate 	sctp_parm_hdr_t *ph;
10940Sstevel@tonic-gate 	size_t len;
10950Sstevel@tonic-gate 	int pad;
10960Sstevel@tonic-gate 
10970Sstevel@tonic-gate 	len = sizeof (*ph) + ntohs(uph->sph_len);
10980Sstevel@tonic-gate 	if ((pad = len % 4) != 0) {
10990Sstevel@tonic-gate 		pad = 4 - pad;
11000Sstevel@tonic-gate 		len += pad;
11010Sstevel@tonic-gate 	}
11020Sstevel@tonic-gate 	mp = allocb(len, BPRI_MED);
11030Sstevel@tonic-gate 	if (mp == NULL) {
11040Sstevel@tonic-gate 		return;
11050Sstevel@tonic-gate 	}
11060Sstevel@tonic-gate 
11070Sstevel@tonic-gate 	ph = (sctp_parm_hdr_t *)(mp->b_rptr);
11080Sstevel@tonic-gate 	ph->sph_type = htons(PARM_UNRECOGNIZED);
11090Sstevel@tonic-gate 	ph->sph_len = htons(len - pad);
11100Sstevel@tonic-gate 
11110Sstevel@tonic-gate 	/* copy in the unrecognized parameter */
11120Sstevel@tonic-gate 	bcopy(uph, ph + 1, ntohs(uph->sph_len));
11130Sstevel@tonic-gate 
11140Sstevel@tonic-gate 	mp->b_wptr = mp->b_rptr + len;
11150Sstevel@tonic-gate 	if (*errmp != NULL) {
11160Sstevel@tonic-gate 		linkb(*errmp, mp);
11170Sstevel@tonic-gate 	} else {
11180Sstevel@tonic-gate 		*errmp = mp;
11190Sstevel@tonic-gate 	}
11200Sstevel@tonic-gate }
11210Sstevel@tonic-gate 
11220Sstevel@tonic-gate /*
11230Sstevel@tonic-gate  * o Bounds checking
11240Sstevel@tonic-gate  * o Updates remaining
11250Sstevel@tonic-gate  * o Checks alignment
11260Sstevel@tonic-gate  */
11270Sstevel@tonic-gate sctp_parm_hdr_t *
11280Sstevel@tonic-gate sctp_next_parm(sctp_parm_hdr_t *current, ssize_t *remaining)
11290Sstevel@tonic-gate {
11300Sstevel@tonic-gate 	int pad;
11310Sstevel@tonic-gate 	uint16_t len;
11320Sstevel@tonic-gate 
11330Sstevel@tonic-gate 	len = ntohs(current->sph_len);
11340Sstevel@tonic-gate 	*remaining -= len;
11350Sstevel@tonic-gate 	if (*remaining < sizeof (*current) || len < sizeof (*current)) {
11360Sstevel@tonic-gate 		return (NULL);
11370Sstevel@tonic-gate 	}
11380Sstevel@tonic-gate 	if ((pad = len & (SCTP_ALIGN - 1)) != 0) {
11390Sstevel@tonic-gate 		pad = SCTP_ALIGN - pad;
11400Sstevel@tonic-gate 		*remaining -= pad;
11410Sstevel@tonic-gate 	}
11420Sstevel@tonic-gate 	/*LINTED pointer cast may result in improper alignment*/
11430Sstevel@tonic-gate 	current = (sctp_parm_hdr_t *)((char *)current + len + pad);
11440Sstevel@tonic-gate 	return (current);
11450Sstevel@tonic-gate }
11460Sstevel@tonic-gate 
11470Sstevel@tonic-gate /*
11480Sstevel@tonic-gate  * Sets the address parameters given in the INIT chunk into sctp's
11490Sstevel@tonic-gate  * faddrs; if psctp is non-NULL, copies psctp's saddrs. If there are
11500Sstevel@tonic-gate  * no address parameters in the INIT chunk, a single faddr is created
11510Sstevel@tonic-gate  * from the ip hdr at the beginning of pkt.
11520Sstevel@tonic-gate  * If there already are existing addresses hanging from sctp, merge
11530Sstevel@tonic-gate  * them in, if the old info contains addresses which are not present
11540Sstevel@tonic-gate  * in this new info, get rid of them, and clean the pointers if there's
11550Sstevel@tonic-gate  * messages which have this as their target address.
11560Sstevel@tonic-gate  *
1157432Svi117747  * We also re-adjust the source address list here since the list may
1158432Svi117747  * contain more than what is actually part of the association. If
1159432Svi117747  * we get here from sctp_send_cookie_echo(), we are on the active
1160432Svi117747  * side and psctp will be NULL and ich will be the INIT-ACK chunk.
1161432Svi117747  * If we get here from sctp_accept_comm(), ich will be the INIT chunk
1162432Svi117747  * and psctp will the listening endpoint.
1163432Svi117747  *
1164432Svi117747  * INIT processing: When processing the INIT we inherit the src address
1165432Svi117747  * list from the listener. For a loopback or linklocal association, we
1166432Svi117747  * delete the list and just take the address from the IP header (since
1167432Svi117747  * that's how we created the INIT-ACK). Additionally, for loopback we
1168432Svi117747  * ignore the address params in the INIT. For determining which address
1169432Svi117747  * types were sent in the INIT-ACK we follow the same logic as in
1170432Svi117747  * creating the INIT-ACK. We delete addresses of the type that are not
1171432Svi117747  * supported by the peer.
1172432Svi117747  *
1173432Svi117747  * INIT-ACK processing: When processing the INIT-ACK since we had not
1174432Svi117747  * included addr params for loopback or linklocal addresses when creating
1175432Svi117747  * the INIT, we just use the address from the IP header. Further, for
1176432Svi117747  * loopback we ignore the addr param list. We mark addresses of the
1177432Svi117747  * type not supported by the peer as unconfirmed.
1178432Svi117747  *
1179432Svi117747  * In case of INIT processing we look for supported address types in the
1180432Svi117747  * supported address param, if present. In both cases the address type in
1181432Svi117747  * the IP header is supported as well as types for addresses in the param
1182432Svi117747  * list, if any.
1183432Svi117747  *
1184432Svi117747  * Once we have the supported address types sctp_check_saddr() runs through
1185432Svi117747  * the source address list and deletes or marks as unconfirmed address of
1186432Svi117747  * types not supported by the peer.
1187432Svi117747  *
11880Sstevel@tonic-gate  * Returns 0 on success, sys errno on failure
11890Sstevel@tonic-gate  */
11900Sstevel@tonic-gate int
11910Sstevel@tonic-gate sctp_get_addrparams(sctp_t *sctp, sctp_t *psctp, mblk_t *pkt,
11920Sstevel@tonic-gate     sctp_chunk_hdr_t *ich, uint_t *sctp_options)
11930Sstevel@tonic-gate {
11940Sstevel@tonic-gate 	sctp_init_chunk_t	*init;
11950Sstevel@tonic-gate 	ipha_t			*iph;
11960Sstevel@tonic-gate 	ip6_t			*ip6h;
1197432Svi117747 	in6_addr_t		hdrsaddr[1];
1198432Svi117747 	in6_addr_t		hdrdaddr[1];
11990Sstevel@tonic-gate 	sctp_parm_hdr_t		*ph;
12000Sstevel@tonic-gate 	ssize_t			remaining;
12010Sstevel@tonic-gate 	int			isv4;
12020Sstevel@tonic-gate 	int			err;
12030Sstevel@tonic-gate 	sctp_faddr_t		*fp;
1204432Svi117747 	int			supp_af = 0;
1205432Svi117747 	boolean_t		check_saddr = B_TRUE;
12060Sstevel@tonic-gate 
12070Sstevel@tonic-gate 	if (sctp_options != NULL)
12080Sstevel@tonic-gate 		*sctp_options = 0;
12090Sstevel@tonic-gate 
1210432Svi117747 	/* extract the address from the IP header */
1211432Svi117747 	isv4 = (IPH_HDR_VERSION(pkt->b_rptr) == IPV4_VERSION);
1212432Svi117747 	if (isv4) {
1213432Svi117747 		iph = (ipha_t *)pkt->b_rptr;
1214432Svi117747 		IN6_IPADDR_TO_V4MAPPED(iph->ipha_src, hdrsaddr);
1215432Svi117747 		IN6_IPADDR_TO_V4MAPPED(iph->ipha_dst, hdrdaddr);
1216432Svi117747 		supp_af |= PARM_SUPP_V4;
1217432Svi117747 	} else {
1218432Svi117747 		ip6h = (ip6_t *)pkt->b_rptr;
1219432Svi117747 		hdrsaddr[0] = ip6h->ip6_src;
1220432Svi117747 		hdrdaddr[0] = ip6h->ip6_dst;
1221432Svi117747 		supp_af |= PARM_SUPP_V6;
1222432Svi117747 	}
1223432Svi117747 
1224432Svi117747 	/*
1225432Svi117747 	 * Unfortunately, we can't delay this because adding an faddr
1226432Svi117747 	 * looks for the presence of the source address (from the ire
1227432Svi117747 	 * for the faddr) in the source address list. We could have
1228432Svi117747 	 * delayed this if, say, this was a loopback/linklocal connection.
1229432Svi117747 	 * Now, we just end up nuking this list and taking the addr from
1230432Svi117747 	 * the IP header for loopback/linklocal.
1231432Svi117747 	 */
12320Sstevel@tonic-gate 	if (psctp != NULL && psctp->sctp_nsaddrs > 0) {
12330Sstevel@tonic-gate 		ASSERT(sctp->sctp_nsaddrs == 0);
12340Sstevel@tonic-gate 
12350Sstevel@tonic-gate 		err = sctp_dup_saddrs(psctp, sctp, KM_NOSLEEP);
12360Sstevel@tonic-gate 		if (err != 0)
12370Sstevel@tonic-gate 			return (err);
12380Sstevel@tonic-gate 	}
1239432Svi117747 	/*
1240432Svi117747 	 * We will add the faddr before parsing the address list as this
1241432Svi117747 	 * might be a loopback connection and we would not have to
1242432Svi117747 	 * go through the list.
1243432Svi117747 	 *
1244432Svi117747 	 * Make sure the header's addr is in the list
1245432Svi117747 	 */
1246432Svi117747 	fp = sctp_lookup_faddr(sctp, hdrsaddr);
1247432Svi117747 	if (fp == NULL) {
1248432Svi117747 		/* not included; add it now */
1249432Svi117747 		if (sctp_add_faddr_first(sctp, hdrsaddr, KM_NOSLEEP) == -1)
1250432Svi117747 			return (ENOMEM);
12510Sstevel@tonic-gate 
1252432Svi117747 		/* sctp_faddrs will be the hdr addr */
1253432Svi117747 		fp = sctp->sctp_faddrs;
12540Sstevel@tonic-gate 	}
1255432Svi117747 	/* make the header addr the primary */
1256432Svi117747 	sctp->sctp_primary = fp;
1257432Svi117747 	sctp->sctp_current = fp;
1258432Svi117747 	sctp->sctp_mss = fp->sfa_pmss;
12590Sstevel@tonic-gate 
1260432Svi117747 	/* For loopback connections & linklocal get address from the header */
1261432Svi117747 	if (sctp->sctp_loopback || sctp->sctp_linklocal) {
1262432Svi117747 		if (sctp->sctp_nsaddrs != 0)
1263432Svi117747 			sctp_free_saddrs(sctp);
1264432Svi117747 		if ((err = sctp_saddr_add_addr(sctp, hdrdaddr)) != 0)
1265432Svi117747 			return (err);
1266432Svi117747 		/* For loopback ignore address list */
1267432Svi117747 		if (sctp->sctp_loopback)
1268432Svi117747 			return (0);
1269432Svi117747 		check_saddr = B_FALSE;
1270432Svi117747 	}
12710Sstevel@tonic-gate 
12720Sstevel@tonic-gate 	/* Walk the params in the INIT [ACK], pulling out addr params */
12730Sstevel@tonic-gate 	remaining = ntohs(ich->sch_len) - sizeof (*ich) -
12740Sstevel@tonic-gate 	    sizeof (sctp_init_chunk_t);
12750Sstevel@tonic-gate 	if (remaining < sizeof (*ph)) {
1276432Svi117747 		if (check_saddr) {
1277432Svi117747 			sctp_check_saddr(sctp, supp_af, psctp == NULL ?
1278432Svi117747 			    B_FALSE : B_TRUE);
1279432Svi117747 		}
1280432Svi117747 		ASSERT(sctp_saddr_lookup(sctp, hdrdaddr) != NULL);
1281432Svi117747 		return (0);
12820Sstevel@tonic-gate 	}
1283432Svi117747 
12840Sstevel@tonic-gate 	init = (sctp_init_chunk_t *)(ich + 1);
12850Sstevel@tonic-gate 	ph = (sctp_parm_hdr_t *)(init + 1);
12860Sstevel@tonic-gate 
1287432Svi117747 	/* params will have already been byteordered when validating */
12880Sstevel@tonic-gate 	while (ph != NULL) {
1289432Svi117747 		if (ph->sph_type == htons(PARM_SUPP_ADDRS)) {
1290432Svi117747 			int		plen;
1291432Svi117747 			uint16_t	*p;
1292432Svi117747 			uint16_t	addrtype;
1293432Svi117747 
1294432Svi117747 			ASSERT(psctp != NULL);
1295432Svi117747 			plen = ntohs(ph->sph_len);
1296432Svi117747 			p = (uint16_t *)(ph + 1);
1297432Svi117747 			while (plen > 0) {
1298432Svi117747 				addrtype = ntohs(*p);
1299432Svi117747 				switch (addrtype) {
1300432Svi117747 					case PARM_ADDR6:
1301432Svi117747 						supp_af |= PARM_SUPP_V6;
1302432Svi117747 						break;
1303432Svi117747 					case PARM_ADDR4:
1304432Svi117747 						supp_af |= PARM_SUPP_V4;
1305432Svi117747 						break;
1306432Svi117747 					default:
1307432Svi117747 						break;
1308432Svi117747 				}
1309432Svi117747 				p++;
1310432Svi117747 				plen -= sizeof (*p);
1311432Svi117747 			}
1312432Svi117747 		} else if (ph->sph_type == htons(PARM_ADDR4)) {
13130Sstevel@tonic-gate 			if (remaining >= PARM_ADDR4_LEN) {
13140Sstevel@tonic-gate 				in6_addr_t addr;
13150Sstevel@tonic-gate 				ipaddr_t ta;
13160Sstevel@tonic-gate 
1317432Svi117747 				supp_af |= PARM_SUPP_V4;
13180Sstevel@tonic-gate 				/*
13190Sstevel@tonic-gate 				 * Screen out broad/multicasts & loopback.
13200Sstevel@tonic-gate 				 * If the endpoint only accepts v6 address,
13210Sstevel@tonic-gate 				 * go to the next one.
13220Sstevel@tonic-gate 				 */
13230Sstevel@tonic-gate 				bcopy(ph + 1, &ta, sizeof (ta));
13240Sstevel@tonic-gate 				if (ta == 0 ||
13250Sstevel@tonic-gate 				    ta == INADDR_BROADCAST ||
13260Sstevel@tonic-gate 				    ta == htonl(INADDR_LOOPBACK) ||
13270Sstevel@tonic-gate 				    IN_MULTICAST(ta) ||
13280Sstevel@tonic-gate 				    sctp->sctp_connp->conn_ipv6_v6only) {
13290Sstevel@tonic-gate 					goto next;
13300Sstevel@tonic-gate 				}
13310Sstevel@tonic-gate 				/*
13320Sstevel@tonic-gate 				 * XXX also need to check for subnet
13330Sstevel@tonic-gate 				 * broadcasts. This should probably
13340Sstevel@tonic-gate 				 * wait until we have full access
13350Sstevel@tonic-gate 				 * to the ILL tables.
13360Sstevel@tonic-gate 				 */
13370Sstevel@tonic-gate 
13380Sstevel@tonic-gate 				IN6_INADDR_TO_V4MAPPED((struct in_addr *)
13390Sstevel@tonic-gate 				    (ph + 1), &addr);
13400Sstevel@tonic-gate 				/* Check for duplicate. */
13410Sstevel@tonic-gate 				if (sctp_lookup_faddr(sctp, &addr) != NULL)
13420Sstevel@tonic-gate 					goto next;
13430Sstevel@tonic-gate 
13440Sstevel@tonic-gate 				/* OK, add it to the faddr set */
13450Sstevel@tonic-gate 				if (sctp_add_faddr(sctp, &addr,
13460Sstevel@tonic-gate 					KM_NOSLEEP) != 0) {
13470Sstevel@tonic-gate 					return (ENOMEM);
13480Sstevel@tonic-gate 				}
13490Sstevel@tonic-gate 			}
13500Sstevel@tonic-gate 		} else if (ph->sph_type == htons(PARM_ADDR6) &&
13510Sstevel@tonic-gate 		    sctp->sctp_family == AF_INET6) {
13520Sstevel@tonic-gate 			/* An v4 socket should not take v6 addresses. */
13530Sstevel@tonic-gate 			if (remaining >= PARM_ADDR6_LEN) {
13540Sstevel@tonic-gate 				in6_addr_t *addr6;
13550Sstevel@tonic-gate 
1356432Svi117747 				supp_af |= PARM_SUPP_V6;
13570Sstevel@tonic-gate 				addr6 = (in6_addr_t *)(ph + 1);
13580Sstevel@tonic-gate 				/*
13590Sstevel@tonic-gate 				 * Screen out link locals, mcast, loopback
13600Sstevel@tonic-gate 				 * and bogus v6 address.
13610Sstevel@tonic-gate 				 */
13620Sstevel@tonic-gate 				if (IN6_IS_ADDR_LINKLOCAL(addr6) ||
13630Sstevel@tonic-gate 				    IN6_IS_ADDR_MULTICAST(addr6) ||
13640Sstevel@tonic-gate 				    IN6_IS_ADDR_LOOPBACK(addr6) ||
13650Sstevel@tonic-gate 				    IN6_IS_ADDR_V4MAPPED(addr6)) {
13660Sstevel@tonic-gate 					goto next;
13670Sstevel@tonic-gate 				}
13680Sstevel@tonic-gate 				/* Check for duplicate. */
13690Sstevel@tonic-gate 				if (sctp_lookup_faddr(sctp, addr6) != NULL)
13700Sstevel@tonic-gate 					goto next;
13710Sstevel@tonic-gate 
13720Sstevel@tonic-gate 				if (sctp_add_faddr(sctp,
13730Sstevel@tonic-gate 				    (in6_addr_t *)(ph + 1), KM_NOSLEEP) != 0) {
13740Sstevel@tonic-gate 					return (ENOMEM);
13750Sstevel@tonic-gate 				}
13760Sstevel@tonic-gate 			}
13770Sstevel@tonic-gate 		} else if (ph->sph_type == htons(PARM_FORWARD_TSN)) {
13780Sstevel@tonic-gate 			if (sctp_options != NULL)
13790Sstevel@tonic-gate 				*sctp_options |= SCTP_PRSCTP_OPTION;
13800Sstevel@tonic-gate 		} /* else; skip */
13810Sstevel@tonic-gate 
13820Sstevel@tonic-gate next:
13830Sstevel@tonic-gate 		ph = sctp_next_parm(ph, &remaining);
13840Sstevel@tonic-gate 	}
1385432Svi117747 	if (check_saddr) {
1386432Svi117747 		sctp_check_saddr(sctp, supp_af, psctp == NULL ? B_FALSE :
1387432Svi117747 		    B_TRUE);
13880Sstevel@tonic-gate 	}
1389432Svi117747 	ASSERT(sctp_saddr_lookup(sctp, hdrdaddr) != NULL);
13900Sstevel@tonic-gate 	return (0);
13910Sstevel@tonic-gate }
13920Sstevel@tonic-gate 
13930Sstevel@tonic-gate /*
13940Sstevel@tonic-gate  * Returns 0 if the check failed and the restart should be refused,
13950Sstevel@tonic-gate  * 1 if the check succeeded.
13960Sstevel@tonic-gate  */
13970Sstevel@tonic-gate int
13980Sstevel@tonic-gate sctp_secure_restart_check(mblk_t *pkt, sctp_chunk_hdr_t *ich, uint32_t ports,
13990Sstevel@tonic-gate     int sleep)
14000Sstevel@tonic-gate {
14010Sstevel@tonic-gate 	sctp_faddr_t *fp, *fpa, *fphead = NULL;
14020Sstevel@tonic-gate 	sctp_parm_hdr_t *ph;
14030Sstevel@tonic-gate 	ssize_t remaining;
14040Sstevel@tonic-gate 	int isv4;
14050Sstevel@tonic-gate 	ipha_t *iph;
14060Sstevel@tonic-gate 	ip6_t *ip6h;
14070Sstevel@tonic-gate 	in6_addr_t hdraddr[1];
14080Sstevel@tonic-gate 	int retval = 0;
14090Sstevel@tonic-gate 	sctp_tf_t *tf;
14100Sstevel@tonic-gate 	sctp_t *sctp;
14110Sstevel@tonic-gate 	int compres;
14120Sstevel@tonic-gate 	sctp_init_chunk_t *init;
14130Sstevel@tonic-gate 	int nadded = 0;
14140Sstevel@tonic-gate 
14150Sstevel@tonic-gate 	/* extract the address from the IP header */
14160Sstevel@tonic-gate 	isv4 = (IPH_HDR_VERSION(pkt->b_rptr) == IPV4_VERSION);
14170Sstevel@tonic-gate 	if (isv4) {
14180Sstevel@tonic-gate 		iph = (ipha_t *)pkt->b_rptr;
14190Sstevel@tonic-gate 		IN6_IPADDR_TO_V4MAPPED(iph->ipha_src, hdraddr);
14200Sstevel@tonic-gate 	} else {
14210Sstevel@tonic-gate 		ip6h = (ip6_t *)pkt->b_rptr;
14220Sstevel@tonic-gate 		hdraddr[0] = ip6h->ip6_src;
14230Sstevel@tonic-gate 	}
14240Sstevel@tonic-gate 
14250Sstevel@tonic-gate 	/* Walk the params in the INIT [ACK], pulling out addr params */
14260Sstevel@tonic-gate 	remaining = ntohs(ich->sch_len) - sizeof (*ich) -
14270Sstevel@tonic-gate 	    sizeof (sctp_init_chunk_t);
14280Sstevel@tonic-gate 	if (remaining < sizeof (*ph)) {
14290Sstevel@tonic-gate 		/* no parameters; restart OK */
14300Sstevel@tonic-gate 		return (1);
14310Sstevel@tonic-gate 	}
14320Sstevel@tonic-gate 	init = (sctp_init_chunk_t *)(ich + 1);
14330Sstevel@tonic-gate 	ph = (sctp_parm_hdr_t *)(init + 1);
14340Sstevel@tonic-gate 
14350Sstevel@tonic-gate 	while (ph != NULL) {
14360Sstevel@tonic-gate 		/* params will have already been byteordered when validating */
14370Sstevel@tonic-gate 		if (ph->sph_type == htons(PARM_ADDR4)) {
14380Sstevel@tonic-gate 			if (remaining >= PARM_ADDR4_LEN) {
14390Sstevel@tonic-gate 				in6_addr_t addr;
14400Sstevel@tonic-gate 				IN6_INADDR_TO_V4MAPPED((struct in_addr *)
14410Sstevel@tonic-gate 				    (ph + 1), &addr);
14420Sstevel@tonic-gate 				fpa = kmem_cache_alloc(sctp_kmem_faddr_cache,
14430Sstevel@tonic-gate 				    sleep);
14440Sstevel@tonic-gate 				if (!fpa) {
14450Sstevel@tonic-gate 					goto done;
14460Sstevel@tonic-gate 				}
14470Sstevel@tonic-gate 				bzero(fpa, sizeof (*fpa));
14480Sstevel@tonic-gate 				fpa->faddr = addr;
14490Sstevel@tonic-gate 				fpa->next = NULL;
14500Sstevel@tonic-gate 			}
14510Sstevel@tonic-gate 		} else if (ph->sph_type == htons(PARM_ADDR6)) {
14520Sstevel@tonic-gate 			if (remaining >= PARM_ADDR6_LEN) {
14530Sstevel@tonic-gate 				fpa = kmem_cache_alloc(sctp_kmem_faddr_cache,
14540Sstevel@tonic-gate 				    sleep);
14550Sstevel@tonic-gate 				if (!fpa) {
14560Sstevel@tonic-gate 					goto done;
14570Sstevel@tonic-gate 				}
14580Sstevel@tonic-gate 				bzero(fpa, sizeof (*fpa));
14590Sstevel@tonic-gate 				bcopy(ph + 1, &fpa->faddr,
14600Sstevel@tonic-gate 				    sizeof (fpa->faddr));
14610Sstevel@tonic-gate 				fpa->next = NULL;
14620Sstevel@tonic-gate 			}
14630Sstevel@tonic-gate 		} else {
14640Sstevel@tonic-gate 			/* else not addr param; skip */
14650Sstevel@tonic-gate 			fpa = NULL;
14660Sstevel@tonic-gate 		}
14670Sstevel@tonic-gate 		/* link in the new addr, if it was an addr param */
14680Sstevel@tonic-gate 		if (fpa) {
14690Sstevel@tonic-gate 			if (!fphead) {
14700Sstevel@tonic-gate 				fphead = fpa;
14710Sstevel@tonic-gate 				fp = fphead;
14720Sstevel@tonic-gate 			} else {
14730Sstevel@tonic-gate 				fp->next = fpa;
14740Sstevel@tonic-gate 				fp = fpa;
14750Sstevel@tonic-gate 			}
14760Sstevel@tonic-gate 		}
14770Sstevel@tonic-gate 
14780Sstevel@tonic-gate 		ph = sctp_next_parm(ph, &remaining);
14790Sstevel@tonic-gate 	}
14800Sstevel@tonic-gate 
14810Sstevel@tonic-gate 	if (fphead == NULL) {
14820Sstevel@tonic-gate 		/* no addr parameters; restart OK */
14830Sstevel@tonic-gate 		return (1);
14840Sstevel@tonic-gate 	}
14850Sstevel@tonic-gate 
14860Sstevel@tonic-gate 	/*
14870Sstevel@tonic-gate 	 * got at least one; make sure the header's addr is
14880Sstevel@tonic-gate 	 * in the list
14890Sstevel@tonic-gate 	 */
14900Sstevel@tonic-gate 	fp = sctp_lookup_faddr_nosctp(fphead, hdraddr);
14910Sstevel@tonic-gate 	if (!fp) {
14920Sstevel@tonic-gate 		/* not included; add it now */
14930Sstevel@tonic-gate 		fp = kmem_cache_alloc(sctp_kmem_faddr_cache, sleep);
14940Sstevel@tonic-gate 		if (!fp) {
14950Sstevel@tonic-gate 			goto done;
14960Sstevel@tonic-gate 		}
14970Sstevel@tonic-gate 		bzero(fp, sizeof (*fp));
14980Sstevel@tonic-gate 		fp->faddr = *hdraddr;
14990Sstevel@tonic-gate 		fp->next = fphead;
15000Sstevel@tonic-gate 		fphead = fp;
15010Sstevel@tonic-gate 	}
15020Sstevel@tonic-gate 
15030Sstevel@tonic-gate 	/*
15040Sstevel@tonic-gate 	 * Now, we can finally do the check: For each sctp instance
15050Sstevel@tonic-gate 	 * on the hash line for ports, compare its faddr set against
15060Sstevel@tonic-gate 	 * the new one. If the new one is a strict subset of any
15070Sstevel@tonic-gate 	 * existing sctp's faddrs, the restart is OK. However, if there
15080Sstevel@tonic-gate 	 * is an overlap, this could be an attack, so return failure.
15090Sstevel@tonic-gate 	 * If all sctp's faddrs are disjoint, this is a legitimate new
15100Sstevel@tonic-gate 	 * association.
15110Sstevel@tonic-gate 	 */
15120Sstevel@tonic-gate 	tf = &(sctp_conn_fanout[SCTP_CONN_HASH(ports)]);
15130Sstevel@tonic-gate 	mutex_enter(&tf->tf_lock);
15140Sstevel@tonic-gate 
15150Sstevel@tonic-gate 	for (sctp = tf->tf_sctp; sctp; sctp = sctp->sctp_conn_hash_next) {
15160Sstevel@tonic-gate 		if (ports != sctp->sctp_ports) {
15170Sstevel@tonic-gate 			continue;
15180Sstevel@tonic-gate 		}
15190Sstevel@tonic-gate 		compres = sctp_compare_faddrsets(fphead, sctp->sctp_faddrs);
15200Sstevel@tonic-gate 		if (compres <= SCTP_ADDR_SUBSET) {
15210Sstevel@tonic-gate 			retval = 1;
15220Sstevel@tonic-gate 			mutex_exit(&tf->tf_lock);
15230Sstevel@tonic-gate 			goto done;
15240Sstevel@tonic-gate 		}
15250Sstevel@tonic-gate 		if (compres == SCTP_ADDR_OVERLAP) {
15260Sstevel@tonic-gate 			dprint(1,
15270Sstevel@tonic-gate 			    ("new assoc from %x:%x:%x:%x overlaps with %p\n",
15280Sstevel@tonic-gate 			    SCTP_PRINTADDR(*hdraddr), sctp));
15290Sstevel@tonic-gate 			/*
15300Sstevel@tonic-gate 			 * While we still hold the lock, we need to
15310Sstevel@tonic-gate 			 * figure out which addresses have been
15320Sstevel@tonic-gate 			 * added so we can include them in the abort
15330Sstevel@tonic-gate 			 * we will send back. Since these faddrs will
15340Sstevel@tonic-gate 			 * never be used, we overload the rto field
15350Sstevel@tonic-gate 			 * here, setting it to 0 if the address was
15360Sstevel@tonic-gate 			 * not added, 1 if it was added.
15370Sstevel@tonic-gate 			 */
15380Sstevel@tonic-gate 			for (fp = fphead; fp; fp = fp->next) {
15390Sstevel@tonic-gate 				if (sctp_lookup_faddr(sctp, &fp->faddr)) {
15400Sstevel@tonic-gate 					fp->rto = 0;
15410Sstevel@tonic-gate 				} else {
15420Sstevel@tonic-gate 					fp->rto = 1;
15430Sstevel@tonic-gate 					nadded++;
15440Sstevel@tonic-gate 				}
15450Sstevel@tonic-gate 			}
15460Sstevel@tonic-gate 			mutex_exit(&tf->tf_lock);
15470Sstevel@tonic-gate 			goto done;
15480Sstevel@tonic-gate 		}
15490Sstevel@tonic-gate 	}
15500Sstevel@tonic-gate 	mutex_exit(&tf->tf_lock);
15510Sstevel@tonic-gate 
15520Sstevel@tonic-gate 	/* All faddrs are disjoint; legit new association */
15530Sstevel@tonic-gate 	retval = 1;
15540Sstevel@tonic-gate 
15550Sstevel@tonic-gate done:
15560Sstevel@tonic-gate 	/* If are attempted adds, send back an abort listing the addrs */
15570Sstevel@tonic-gate 	if (nadded > 0) {
15580Sstevel@tonic-gate 		void *dtail;
15590Sstevel@tonic-gate 		size_t dlen;
15600Sstevel@tonic-gate 
15610Sstevel@tonic-gate 		dtail = kmem_alloc(PARM_ADDR6_LEN * nadded, KM_NOSLEEP);
15620Sstevel@tonic-gate 		if (dtail == NULL) {
15630Sstevel@tonic-gate 			goto cleanup;
15640Sstevel@tonic-gate 		}
15650Sstevel@tonic-gate 
15660Sstevel@tonic-gate 		ph = dtail;
15670Sstevel@tonic-gate 		dlen = 0;
15680Sstevel@tonic-gate 		for (fp = fphead; fp; fp = fp->next) {
15690Sstevel@tonic-gate 			if (fp->rto == 0) {
15700Sstevel@tonic-gate 				continue;
15710Sstevel@tonic-gate 			}
15720Sstevel@tonic-gate 			if (IN6_IS_ADDR_V4MAPPED(&fp->faddr)) {
15730Sstevel@tonic-gate 				ipaddr_t addr4;
15740Sstevel@tonic-gate 
15750Sstevel@tonic-gate 				ph->sph_type = htons(PARM_ADDR4);
15760Sstevel@tonic-gate 				ph->sph_len = htons(PARM_ADDR4_LEN);
15770Sstevel@tonic-gate 				IN6_V4MAPPED_TO_IPADDR(&fp->faddr, addr4);
15780Sstevel@tonic-gate 				ph++;
15790Sstevel@tonic-gate 				bcopy(&addr4, ph, sizeof (addr4));
15800Sstevel@tonic-gate 				ph = (sctp_parm_hdr_t *)
15810Sstevel@tonic-gate 				    ((char *)ph + sizeof (addr4));
15820Sstevel@tonic-gate 				dlen += PARM_ADDR4_LEN;
15830Sstevel@tonic-gate 			} else {
15840Sstevel@tonic-gate 				ph->sph_type = htons(PARM_ADDR6);
15850Sstevel@tonic-gate 				ph->sph_len = htons(PARM_ADDR6_LEN);
15860Sstevel@tonic-gate 				ph++;
15870Sstevel@tonic-gate 				bcopy(&fp->faddr, ph, sizeof (fp->faddr));
15880Sstevel@tonic-gate 				ph = (sctp_parm_hdr_t *)
15890Sstevel@tonic-gate 				    ((char *)ph + sizeof (fp->faddr));
15900Sstevel@tonic-gate 				dlen += PARM_ADDR6_LEN;
15910Sstevel@tonic-gate 			}
15920Sstevel@tonic-gate 		}
15930Sstevel@tonic-gate 
15940Sstevel@tonic-gate 		/* Send off the abort */
15950Sstevel@tonic-gate 		sctp_send_abort(sctp, sctp_init2vtag(ich),
15960Sstevel@tonic-gate 		    SCTP_ERR_RESTART_NEW_ADDRS, dtail, dlen, pkt, 0, B_TRUE);
15970Sstevel@tonic-gate 
15980Sstevel@tonic-gate 		kmem_free(dtail, PARM_ADDR6_LEN * nadded);
15990Sstevel@tonic-gate 	}
16000Sstevel@tonic-gate 
16010Sstevel@tonic-gate cleanup:
16020Sstevel@tonic-gate 	/* Clean up */
16030Sstevel@tonic-gate 	if (fphead) {
16040Sstevel@tonic-gate 		sctp_faddr_t *fpn;
16050Sstevel@tonic-gate 		for (fp = fphead; fp; fp = fpn) {
16060Sstevel@tonic-gate 			fpn = fp->next;
16070Sstevel@tonic-gate 			kmem_cache_free(sctp_kmem_faddr_cache, fp);
16080Sstevel@tonic-gate 		}
16090Sstevel@tonic-gate 	}
16100Sstevel@tonic-gate 
16110Sstevel@tonic-gate 	return (retval);
16120Sstevel@tonic-gate }
16130Sstevel@tonic-gate 
16140Sstevel@tonic-gate void
16150Sstevel@tonic-gate sctp_congest_reset(sctp_t *sctp)
16160Sstevel@tonic-gate {
16170Sstevel@tonic-gate 	sctp_faddr_t *fp;
16180Sstevel@tonic-gate 
16190Sstevel@tonic-gate 	for (fp = sctp->sctp_faddrs; fp; fp = fp->next) {
16200Sstevel@tonic-gate 		fp->ssthresh = sctp_initial_mtu;
16210Sstevel@tonic-gate 		fp->cwnd = fp->sfa_pmss * sctp_slow_start_initial;
16220Sstevel@tonic-gate 		fp->suna = 0;
16230Sstevel@tonic-gate 		fp->pba = 0;
16240Sstevel@tonic-gate 	}
16250Sstevel@tonic-gate }
16260Sstevel@tonic-gate 
16270Sstevel@tonic-gate /*
16280Sstevel@tonic-gate  * Return zero if the buffers are identical in length and content.
16290Sstevel@tonic-gate  * This is used for comparing extension header buffers.
16300Sstevel@tonic-gate  * Note that an extension header would be declared different
16310Sstevel@tonic-gate  * even if all that changed was the next header value in that header i.e.
16320Sstevel@tonic-gate  * what really changed is the next extension header.
16330Sstevel@tonic-gate  */
16340Sstevel@tonic-gate boolean_t
16350Sstevel@tonic-gate sctp_cmpbuf(void *a, uint_t alen, boolean_t b_valid, void *b, uint_t blen)
16360Sstevel@tonic-gate {
16370Sstevel@tonic-gate 	if (!b_valid)
16380Sstevel@tonic-gate 		blen = 0;
16390Sstevel@tonic-gate 
16400Sstevel@tonic-gate 	if (alen != blen)
16410Sstevel@tonic-gate 		return (B_TRUE);
16420Sstevel@tonic-gate 	if (alen == 0)
16430Sstevel@tonic-gate 		return (B_FALSE);	/* Both zero length */
16440Sstevel@tonic-gate 	return (bcmp(a, b, alen));
16450Sstevel@tonic-gate }
16460Sstevel@tonic-gate 
16470Sstevel@tonic-gate /*
16480Sstevel@tonic-gate  * Preallocate memory for sctp_savebuf(). Returns B_TRUE if ok.
16490Sstevel@tonic-gate  * Return B_FALSE if memory allocation fails - don't change any state!
16500Sstevel@tonic-gate  */
16510Sstevel@tonic-gate boolean_t
16520Sstevel@tonic-gate sctp_allocbuf(void **dstp, uint_t *dstlenp, boolean_t src_valid,
16530Sstevel@tonic-gate     void *src, uint_t srclen)
16540Sstevel@tonic-gate {
16550Sstevel@tonic-gate 	void *dst;
16560Sstevel@tonic-gate 
16570Sstevel@tonic-gate 	if (!src_valid)
16580Sstevel@tonic-gate 		srclen = 0;
16590Sstevel@tonic-gate 
16600Sstevel@tonic-gate 	ASSERT(*dstlenp == 0);
16610Sstevel@tonic-gate 	if (src != NULL && srclen != 0) {
16620Sstevel@tonic-gate 		dst = mi_zalloc(srclen);
16630Sstevel@tonic-gate 		if (dst == NULL)
16640Sstevel@tonic-gate 			return (B_FALSE);
16650Sstevel@tonic-gate 	} else {
16660Sstevel@tonic-gate 		dst = NULL;
16670Sstevel@tonic-gate 	}
16680Sstevel@tonic-gate 	if (*dstp != NULL) {
16690Sstevel@tonic-gate 		mi_free(*dstp);
16700Sstevel@tonic-gate 		*dstp = NULL;
16710Sstevel@tonic-gate 		*dstlenp = 0;
16720Sstevel@tonic-gate 	}
16730Sstevel@tonic-gate 	*dstp = dst;
16740Sstevel@tonic-gate 	if (dst != NULL)
16750Sstevel@tonic-gate 		*dstlenp = srclen;
16760Sstevel@tonic-gate 	else
16770Sstevel@tonic-gate 		*dstlenp = 0;
16780Sstevel@tonic-gate 	return (B_TRUE);
16790Sstevel@tonic-gate }
16800Sstevel@tonic-gate 
16810Sstevel@tonic-gate /*
16820Sstevel@tonic-gate  * Replace what is in *dst, *dstlen with the source.
16830Sstevel@tonic-gate  * Assumes sctp_allocbuf has already been called.
16840Sstevel@tonic-gate  */
16850Sstevel@tonic-gate void
16860Sstevel@tonic-gate sctp_savebuf(void **dstp, uint_t *dstlenp, boolean_t src_valid,
16870Sstevel@tonic-gate     void *src, uint_t srclen)
16880Sstevel@tonic-gate {
16890Sstevel@tonic-gate 	if (!src_valid)
16900Sstevel@tonic-gate 		srclen = 0;
16910Sstevel@tonic-gate 
16920Sstevel@tonic-gate 	ASSERT(*dstlenp == srclen);
16930Sstevel@tonic-gate 	if (src != NULL && srclen != 0) {
16940Sstevel@tonic-gate 		bcopy(src, *dstp, srclen);
16950Sstevel@tonic-gate 	}
16960Sstevel@tonic-gate }
16970Sstevel@tonic-gate 
16980Sstevel@tonic-gate static void
16990Sstevel@tonic-gate sctp_init_faddr(sctp_t *sctp, sctp_faddr_t *fp, in6_addr_t *addr)
17000Sstevel@tonic-gate {
17010Sstevel@tonic-gate 	bcopy(addr, &fp->faddr, sizeof (*addr));
17020Sstevel@tonic-gate 	if (IN6_IS_ADDR_V4MAPPED(addr)) {
17030Sstevel@tonic-gate 		fp->isv4 = 1;
17040Sstevel@tonic-gate 		/* Make sure that sfa_pmss is a multiple of SCTP_ALIGN. */
17050Sstevel@tonic-gate 		fp->sfa_pmss = (sctp_initial_mtu - sctp->sctp_hdr_len) &
17060Sstevel@tonic-gate 			~(SCTP_ALIGN - 1);
17070Sstevel@tonic-gate 	} else {
17080Sstevel@tonic-gate 		fp->isv4 = 0;
17090Sstevel@tonic-gate 		fp->sfa_pmss = (sctp_initial_mtu - sctp->sctp_hdr6_len) &
17100Sstevel@tonic-gate 			~(SCTP_ALIGN - 1);
17110Sstevel@tonic-gate 	}
17120Sstevel@tonic-gate 	fp->cwnd = sctp_slow_start_initial * fp->sfa_pmss;
17130Sstevel@tonic-gate 	fp->rto = MIN(sctp->sctp_rto_initial, sctp->sctp_init_rto_max);
17140Sstevel@tonic-gate 	fp->srtt = -1;
17150Sstevel@tonic-gate 	fp->rtt_updates = 0;
17160Sstevel@tonic-gate 	fp->strikes = 0;
17170Sstevel@tonic-gate 	fp->max_retr = sctp->sctp_pp_max_rxt;
17180Sstevel@tonic-gate 	/* Mark it as not confirmed. */
17190Sstevel@tonic-gate 	fp->state = SCTP_FADDRS_UNCONFIRMED;
17200Sstevel@tonic-gate 	fp->hb_interval = sctp->sctp_hb_interval;
17210Sstevel@tonic-gate 	fp->ssthresh = sctp_initial_ssthresh;
17220Sstevel@tonic-gate 	fp->suna = 0;
17230Sstevel@tonic-gate 	fp->pba = 0;
17240Sstevel@tonic-gate 	fp->acked = 0;
17250Sstevel@tonic-gate 	fp->lastactive = lbolt64;
17260Sstevel@tonic-gate 	fp->timer_mp = NULL;
17270Sstevel@tonic-gate 	fp->hb_pending = B_FALSE;
17280Sstevel@tonic-gate 	fp->timer_running = 0;
17290Sstevel@tonic-gate 	fp->df = 1;
17300Sstevel@tonic-gate 	fp->pmtu_discovered = 0;
17310Sstevel@tonic-gate 	fp->rc_timer_mp = NULL;
17320Sstevel@tonic-gate 	fp->rc_timer_running = 0;
17330Sstevel@tonic-gate 	fp->next = NULL;
17340Sstevel@tonic-gate 	fp->ire = NULL;
17350Sstevel@tonic-gate 	fp->T3expire = 0;
17360Sstevel@tonic-gate 	(void) random_get_pseudo_bytes((uint8_t *)&fp->hb_secret,
17370Sstevel@tonic-gate 	    sizeof (fp->hb_secret));
17380Sstevel@tonic-gate 	fp->hb_expiry = lbolt64;
17390Sstevel@tonic-gate 
17400Sstevel@tonic-gate 	sctp_ire2faddr(sctp, fp);
17410Sstevel@tonic-gate }
17420Sstevel@tonic-gate 
17430Sstevel@tonic-gate /*ARGSUSED*/
17440Sstevel@tonic-gate static void
17450Sstevel@tonic-gate faddr_destructor(void *buf, void *cdrarg)
17460Sstevel@tonic-gate {
17470Sstevel@tonic-gate 	sctp_faddr_t *fp = buf;
17480Sstevel@tonic-gate 
17490Sstevel@tonic-gate 	ASSERT(fp->timer_mp == NULL);
17500Sstevel@tonic-gate 	ASSERT(fp->timer_running == 0);
17510Sstevel@tonic-gate 
17520Sstevel@tonic-gate 	ASSERT(fp->rc_timer_mp == NULL);
17530Sstevel@tonic-gate 	ASSERT(fp->rc_timer_running == 0);
17540Sstevel@tonic-gate }
17550Sstevel@tonic-gate 
17560Sstevel@tonic-gate void
17570Sstevel@tonic-gate sctp_faddr_init()
17580Sstevel@tonic-gate {
17590Sstevel@tonic-gate 	sctp_kmem_faddr_cache = kmem_cache_create("sctp_faddr_cache",
17600Sstevel@tonic-gate 	    sizeof (sctp_faddr_t), 0, NULL, faddr_destructor,
17610Sstevel@tonic-gate 	    NULL, NULL, NULL, 0);
17620Sstevel@tonic-gate }
17630Sstevel@tonic-gate 
17640Sstevel@tonic-gate void
17650Sstevel@tonic-gate sctp_faddr_fini()
17660Sstevel@tonic-gate {
17670Sstevel@tonic-gate 	kmem_cache_destroy(sctp_kmem_faddr_cache);
17680Sstevel@tonic-gate }
1769