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 51676Sjpk * Common Development and Distribution License (the "License"). 61676Sjpk * 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 /* 2312474SGeorge.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> 291676Sjpk #include <sys/strsubr.h> 300Sstevel@tonic-gate #include <sys/ddi.h> 310Sstevel@tonic-gate #include <sys/sunddi.h> 320Sstevel@tonic-gate #include <sys/kmem.h> 330Sstevel@tonic-gate #include <sys/socket.h> 340Sstevel@tonic-gate #include <sys/random.h> 351676Sjpk #include <sys/tsol/tndb.h> 361676Sjpk #include <sys/tsol/tnet.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> 4611042SErik.Nordmark@Sun.COM #include <inet/ip_if.h> 4711042SErik.Nordmark@Sun.COM #include <inet/ip_ndp.h> 480Sstevel@tonic-gate #include <inet/mib2.h> 490Sstevel@tonic-gate #include <inet/nd.h> 500Sstevel@tonic-gate #include <inet/optcom.h> 510Sstevel@tonic-gate #include <inet/sctp_ip.h> 520Sstevel@tonic-gate #include <inet/ipclassifier.h> 531676Sjpk 540Sstevel@tonic-gate #include "sctp_impl.h" 550Sstevel@tonic-gate #include "sctp_addr.h" 561932Svi117747 #include "sctp_asconf.h" 570Sstevel@tonic-gate 580Sstevel@tonic-gate static struct kmem_cache *sctp_kmem_faddr_cache; 591735Skcpoon static void sctp_init_faddr(sctp_t *, sctp_faddr_t *, in6_addr_t *, mblk_t *); 600Sstevel@tonic-gate 6111042SErik.Nordmark@Sun.COM /* Set the source address. Refer to comments in sctp_get_dest(). */ 621932Svi117747 void 631932Svi117747 sctp_set_saddr(sctp_t *sctp, sctp_faddr_t *fp) 640Sstevel@tonic-gate { 65*13009SChandrasekar.Marimuthu@Sun.COM boolean_t v6 = !fp->sf_isv4; 664818Skcpoon boolean_t addr_set; 671719Sjarrett 68*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_saddr = sctp_get_valid_addr(sctp, v6, &addr_set); 694818Skcpoon /* 704818Skcpoon * If there is no source address avaialble, mark this peer address 714818Skcpoon * as unreachable for now. When the heartbeat timer fires, it will 7211042SErik.Nordmark@Sun.COM * call sctp_get_dest() to re-check if there is any source address 734818Skcpoon * available. 744818Skcpoon */ 754818Skcpoon if (!addr_set) 76*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_state = SCTP_FADDRS_UNREACH; 770Sstevel@tonic-gate } 780Sstevel@tonic-gate 790Sstevel@tonic-gate /* 8011042SErik.Nordmark@Sun.COM * Call this function to get information about a peer addr fp. 8111042SErik.Nordmark@Sun.COM * 8211042SErik.Nordmark@Sun.COM * Uses ip_attr_connect to avoid explicit use of ire and source address 8311042SErik.Nordmark@Sun.COM * selection. 840Sstevel@tonic-gate */ 850Sstevel@tonic-gate void 8611042SErik.Nordmark@Sun.COM sctp_get_dest(sctp_t *sctp, sctp_faddr_t *fp) 870Sstevel@tonic-gate { 881735Skcpoon in6_addr_t laddr; 8911042SErik.Nordmark@Sun.COM in6_addr_t nexthop; 900Sstevel@tonic-gate sctp_saddr_ipif_t *sp; 911735Skcpoon int hdrlen; 923448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 9311042SErik.Nordmark@Sun.COM conn_t *connp = sctp->sctp_connp; 9411042SErik.Nordmark@Sun.COM iulp_t uinfo; 9511042SErik.Nordmark@Sun.COM uint_t pmtu; 9611042SErik.Nordmark@Sun.COM int error; 9711042SErik.Nordmark@Sun.COM uint32_t flags = IPDF_VERIFY_DST | IPDF_IPSEC | 9811042SErik.Nordmark@Sun.COM IPDF_SELECT_SRC | IPDF_UNIQUE_DCE; 990Sstevel@tonic-gate 10011042SErik.Nordmark@Sun.COM /* 10111042SErik.Nordmark@Sun.COM * Tell sctp_make_mp it needs to call us again should we not 10211042SErik.Nordmark@Sun.COM * complete and set the saddr. 10311042SErik.Nordmark@Sun.COM */ 104*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_saddr = ipv6_all_zeros; 1050Sstevel@tonic-gate 1060Sstevel@tonic-gate /* 1070Sstevel@tonic-gate * If this addr is not reachable, mark it as unconfirmed for now, the 1080Sstevel@tonic-gate * state will be changed back to unreachable later in this function 1090Sstevel@tonic-gate * if it is still the case. 1100Sstevel@tonic-gate */ 111*13009SChandrasekar.Marimuthu@Sun.COM if (fp->sf_state == SCTP_FADDRS_UNREACH) { 112*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_state = SCTP_FADDRS_UNCONFIRMED; 1130Sstevel@tonic-gate } 1140Sstevel@tonic-gate 11511042SErik.Nordmark@Sun.COM /* 11611042SErik.Nordmark@Sun.COM * Socket is connected - enable PMTU discovery. 11711042SErik.Nordmark@Sun.COM */ 11811042SErik.Nordmark@Sun.COM if (!sctps->sctps_ignore_path_mtu) 119*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_ixa->ixa_flags |= IXAF_PMTU_DISCOVERY; 1201676Sjpk 121*13009SChandrasekar.Marimuthu@Sun.COM ip_attr_nexthop(&connp->conn_xmit_ipp, fp->sf_ixa, &fp->sf_faddr, 12211042SErik.Nordmark@Sun.COM &nexthop); 1230Sstevel@tonic-gate 124*13009SChandrasekar.Marimuthu@Sun.COM laddr = fp->sf_saddr; 125*13009SChandrasekar.Marimuthu@Sun.COM error = ip_attr_connect(connp, fp->sf_ixa, &laddr, &fp->sf_faddr, 126*13009SChandrasekar.Marimuthu@Sun.COM &nexthop, connp->conn_fport, &laddr, &uinfo, flags); 12711042SErik.Nordmark@Sun.COM 12811042SErik.Nordmark@Sun.COM if (error != 0) { 12911042SErik.Nordmark@Sun.COM dprint(3, ("sctp_get_dest: no ire for %x:%x:%x:%x\n", 130*13009SChandrasekar.Marimuthu@Sun.COM SCTP_PRINTADDR(fp->sf_faddr))); 1311676Sjpk /* 1321676Sjpk * It is tempting to just leave the src addr 1331676Sjpk * unspecified and let IP figure it out, but we 1341676Sjpk * *cannot* do this, since IP may choose a src addr 1351676Sjpk * that is not part of this association... unless 13611042SErik.Nordmark@Sun.COM * this sctp has bound to all addrs. So if the dest 1371676Sjpk * lookup fails, try to find one in our src addr 1381676Sjpk * list, unless the sctp has bound to all addrs, in 1391676Sjpk * which case we change the src addr to unspec. 1401676Sjpk * 1411676Sjpk * Note that if this is a v6 endpoint but it does 1421676Sjpk * not have any v4 address at this point (e.g. may 1431676Sjpk * have been deleted), sctp_get_valid_addr() will 1441676Sjpk * return mapped INADDR_ANY. In this case, this 1451676Sjpk * address should be marked not reachable so that 1461676Sjpk * it won't be used to send data. 1471676Sjpk */ 1481932Svi117747 sctp_set_saddr(sctp, fp); 149*13009SChandrasekar.Marimuthu@Sun.COM if (fp->sf_state == SCTP_FADDRS_UNREACH) 1501735Skcpoon return; 1511735Skcpoon goto check_current; 1521676Sjpk } 153*13009SChandrasekar.Marimuthu@Sun.COM ASSERT(fp->sf_ixa->ixa_ire != NULL); 154*13009SChandrasekar.Marimuthu@Sun.COM ASSERT(!(fp->sf_ixa->ixa_ire->ire_flags & (RTF_REJECT|RTF_BLACKHOLE))); 15511042SErik.Nordmark@Sun.COM 15611042SErik.Nordmark@Sun.COM if (!sctp->sctp_loopback) 15711042SErik.Nordmark@Sun.COM sctp->sctp_loopback = uinfo.iulp_loopback; 1581676Sjpk 1591735Skcpoon /* Make sure the laddr is part of this association */ 16011042SErik.Nordmark@Sun.COM if ((sp = sctp_saddr_lookup(sctp, &laddr, 0)) != NULL && 16111042SErik.Nordmark@Sun.COM !sp->saddr_ipif_dontsrc) { 1621676Sjpk if (sp->saddr_ipif_unconfirmed == 1) 1631676Sjpk sp->saddr_ipif_unconfirmed = 0; 16411042SErik.Nordmark@Sun.COM /* We did IPsec policy lookup for laddr already */ 165*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_saddr = laddr; 1661676Sjpk } else { 16711042SErik.Nordmark@Sun.COM dprint(2, ("sctp_get_dest: src addr is not part of assoc " 16811042SErik.Nordmark@Sun.COM "%x:%x:%x:%x\n", SCTP_PRINTADDR(laddr))); 1691735Skcpoon 1701735Skcpoon /* 1711735Skcpoon * Set the src to the first saddr and hope for the best. 17211042SErik.Nordmark@Sun.COM * Note that this case should very seldomly 1731735Skcpoon * happen. One scenario this can happen is an app 1741735Skcpoon * explicitly bind() to an address. But that address is 1751735Skcpoon * not the preferred source address to send to the peer. 1761735Skcpoon */ 1771932Svi117747 sctp_set_saddr(sctp, fp); 178*13009SChandrasekar.Marimuthu@Sun.COM if (fp->sf_state == SCTP_FADDRS_UNREACH) { 1791735Skcpoon return; 1801735Skcpoon } 1810Sstevel@tonic-gate } 1820Sstevel@tonic-gate 1831735Skcpoon /* 1840Sstevel@tonic-gate * Pull out RTO information for this faddr and use it if we don't 1850Sstevel@tonic-gate * have any yet. 1860Sstevel@tonic-gate */ 187*13009SChandrasekar.Marimuthu@Sun.COM if (fp->sf_srtt == -1 && uinfo.iulp_rtt != 0) { 188116Skcpoon /* The cached value is in ms. */ 189*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_srtt = MSEC_TO_TICK(uinfo.iulp_rtt); 190*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_rttvar = MSEC_TO_TICK(uinfo.iulp_rtt_sd); 191*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_rto = 3 * fp->sf_srtt; 1920Sstevel@tonic-gate 1930Sstevel@tonic-gate /* Bound the RTO by configured min and max values */ 194*13009SChandrasekar.Marimuthu@Sun.COM if (fp->sf_rto < sctp->sctp_rto_min) { 195*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_rto = sctp->sctp_rto_min; 1960Sstevel@tonic-gate } 197*13009SChandrasekar.Marimuthu@Sun.COM if (fp->sf_rto > sctp->sctp_rto_max) { 198*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_rto = sctp->sctp_rto_max; 1990Sstevel@tonic-gate } 20010212SGeorge.Shepherd@Sun.COM SCTP_MAX_RTO(sctp, fp); 2010Sstevel@tonic-gate } 20211042SErik.Nordmark@Sun.COM pmtu = uinfo.iulp_mtu; 2030Sstevel@tonic-gate 2040Sstevel@tonic-gate /* 2050Sstevel@tonic-gate * Record the MTU for this faddr. If the MTU for this faddr has 2060Sstevel@tonic-gate * changed, check if the assc MTU will also change. 2070Sstevel@tonic-gate */ 208*13009SChandrasekar.Marimuthu@Sun.COM if (fp->sf_isv4) { 2090Sstevel@tonic-gate hdrlen = sctp->sctp_hdr_len; 2100Sstevel@tonic-gate } else { 2110Sstevel@tonic-gate hdrlen = sctp->sctp_hdr6_len; 2120Sstevel@tonic-gate } 213*13009SChandrasekar.Marimuthu@Sun.COM if ((fp->sf_pmss + hdrlen) != pmtu) { 214*13009SChandrasekar.Marimuthu@Sun.COM /* Make sure that sf_pmss is a multiple of SCTP_ALIGN. */ 215*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_pmss = (pmtu - hdrlen) & ~(SCTP_ALIGN - 1); 216*13009SChandrasekar.Marimuthu@Sun.COM if (fp->sf_cwnd < (fp->sf_pmss * 2)) { 217*13009SChandrasekar.Marimuthu@Sun.COM SET_CWND(fp, fp->sf_pmss, 2183795Skcpoon sctps->sctps_slow_start_initial); 2190Sstevel@tonic-gate } 2200Sstevel@tonic-gate } 2210Sstevel@tonic-gate 2221735Skcpoon check_current: 2231735Skcpoon if (fp == sctp->sctp_current) 2241735Skcpoon sctp_set_faddr_current(sctp, fp); 2250Sstevel@tonic-gate } 2260Sstevel@tonic-gate 2270Sstevel@tonic-gate void 22811042SErik.Nordmark@Sun.COM sctp_update_dce(sctp_t *sctp) 2290Sstevel@tonic-gate { 2301735Skcpoon sctp_faddr_t *fp; 2313448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 23211042SErik.Nordmark@Sun.COM iulp_t uinfo; 23311042SErik.Nordmark@Sun.COM ip_stack_t *ipst = sctps->sctps_netstack->netstack_ip; 23411042SErik.Nordmark@Sun.COM uint_t ifindex; 2350Sstevel@tonic-gate 236*13009SChandrasekar.Marimuthu@Sun.COM for (fp = sctp->sctp_faddrs; fp != NULL; fp = fp->sf_next) { 23711042SErik.Nordmark@Sun.COM bzero(&uinfo, sizeof (uinfo)); 2380Sstevel@tonic-gate /* 2391735Skcpoon * Only record the PMTU for this faddr if we actually have 2401735Skcpoon * done discovery. This prevents initialized default from 2411735Skcpoon * clobbering any real info that IP may have. 2420Sstevel@tonic-gate */ 243*13009SChandrasekar.Marimuthu@Sun.COM if (fp->sf_pmtu_discovered) { 244*13009SChandrasekar.Marimuthu@Sun.COM if (fp->sf_isv4) { 245*13009SChandrasekar.Marimuthu@Sun.COM uinfo.iulp_mtu = fp->sf_pmss + 2461735Skcpoon sctp->sctp_hdr_len; 2471735Skcpoon } else { 248*13009SChandrasekar.Marimuthu@Sun.COM uinfo.iulp_mtu = fp->sf_pmss + 2491735Skcpoon sctp->sctp_hdr6_len; 2501735Skcpoon } 2510Sstevel@tonic-gate } 2523448Sdh155122 if (sctps->sctps_rtt_updates != 0 && 253*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_rtt_updates >= sctps->sctps_rtt_updates) { 2541735Skcpoon /* 25511042SErik.Nordmark@Sun.COM * dce_update_uinfo() merges these values with the 25611042SErik.Nordmark@Sun.COM * old values. 2571735Skcpoon */ 258*13009SChandrasekar.Marimuthu@Sun.COM uinfo.iulp_rtt = TICK_TO_MSEC(fp->sf_srtt); 259*13009SChandrasekar.Marimuthu@Sun.COM uinfo.iulp_rtt_sd = TICK_TO_MSEC(fp->sf_rttvar); 260*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_rtt_updates = 0; 2610Sstevel@tonic-gate } 26211042SErik.Nordmark@Sun.COM ifindex = 0; 263*13009SChandrasekar.Marimuthu@Sun.COM if (IN6_IS_ADDR_LINKSCOPE(&fp->sf_faddr)) { 26411042SErik.Nordmark@Sun.COM /* 26511042SErik.Nordmark@Sun.COM * If we are going to create a DCE we'd better have 26611042SErik.Nordmark@Sun.COM * an ifindex 26711042SErik.Nordmark@Sun.COM */ 268*13009SChandrasekar.Marimuthu@Sun.COM if (fp->sf_ixa->ixa_nce != NULL) { 269*13009SChandrasekar.Marimuthu@Sun.COM ifindex = fp->sf_ixa->ixa_nce->nce_common-> 27011042SErik.Nordmark@Sun.COM ncec_ill->ill_phyint->phyint_ifindex; 27111042SErik.Nordmark@Sun.COM } else { 27211042SErik.Nordmark@Sun.COM continue; 27311042SErik.Nordmark@Sun.COM } 27411042SErik.Nordmark@Sun.COM } 27511042SErik.Nordmark@Sun.COM 276*13009SChandrasekar.Marimuthu@Sun.COM (void) dce_update_uinfo(&fp->sf_faddr, ifindex, &uinfo, ipst); 2770Sstevel@tonic-gate } 2780Sstevel@tonic-gate } 2790Sstevel@tonic-gate 2800Sstevel@tonic-gate /* 28111042SErik.Nordmark@Sun.COM * The sender must later set the total length in the IP header. 2820Sstevel@tonic-gate */ 2830Sstevel@tonic-gate mblk_t * 28411042SErik.Nordmark@Sun.COM sctp_make_mp(sctp_t *sctp, sctp_faddr_t *fp, int trailer) 2850Sstevel@tonic-gate { 2860Sstevel@tonic-gate mblk_t *mp; 2870Sstevel@tonic-gate size_t ipsctplen; 2880Sstevel@tonic-gate int isv4; 2893448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 2904818Skcpoon boolean_t src_changed = B_FALSE; 2910Sstevel@tonic-gate 29211042SErik.Nordmark@Sun.COM ASSERT(fp != NULL); 293*13009SChandrasekar.Marimuthu@Sun.COM isv4 = fp->sf_isv4; 2940Sstevel@tonic-gate 295*13009SChandrasekar.Marimuthu@Sun.COM if (SCTP_IS_ADDR_UNSPEC(isv4, fp->sf_saddr) || 296*13009SChandrasekar.Marimuthu@Sun.COM (fp->sf_ixa->ixa_ire->ire_flags & (RTF_REJECT|RTF_BLACKHOLE))) { 29711042SErik.Nordmark@Sun.COM /* Need to pick a source */ 29811042SErik.Nordmark@Sun.COM sctp_get_dest(sctp, fp); 2994818Skcpoon /* 3004818Skcpoon * Although we still may not get an IRE, the source address 3014818Skcpoon * may be changed in sctp_get_ire(). Set src_changed to 3024818Skcpoon * true so that the source address is copied again. 3034818Skcpoon */ 3044818Skcpoon src_changed = B_TRUE; 3054818Skcpoon } 3060Sstevel@tonic-gate 3070Sstevel@tonic-gate /* There is no suitable source address to use, return. */ 308*13009SChandrasekar.Marimuthu@Sun.COM if (fp->sf_state == SCTP_FADDRS_UNREACH) 3090Sstevel@tonic-gate return (NULL); 31011042SErik.Nordmark@Sun.COM 311*13009SChandrasekar.Marimuthu@Sun.COM ASSERT(fp->sf_ixa->ixa_ire != NULL); 312*13009SChandrasekar.Marimuthu@Sun.COM ASSERT(!SCTP_IS_ADDR_UNSPEC(isv4, fp->sf_saddr)); 3130Sstevel@tonic-gate 3140Sstevel@tonic-gate if (isv4) { 3150Sstevel@tonic-gate ipsctplen = sctp->sctp_hdr_len; 3160Sstevel@tonic-gate } else { 3170Sstevel@tonic-gate ipsctplen = sctp->sctp_hdr6_len; 3180Sstevel@tonic-gate } 3190Sstevel@tonic-gate 32011042SErik.Nordmark@Sun.COM mp = allocb(ipsctplen + sctps->sctps_wroff_xtra + trailer, BPRI_MED); 3210Sstevel@tonic-gate if (mp == NULL) { 3221676Sjpk ip1dbg(("sctp_make_mp: error making mp..\n")); 3230Sstevel@tonic-gate return (NULL); 3240Sstevel@tonic-gate } 3253448Sdh155122 mp->b_rptr += sctps->sctps_wroff_xtra; 3260Sstevel@tonic-gate mp->b_wptr = mp->b_rptr + ipsctplen; 3270Sstevel@tonic-gate 3280Sstevel@tonic-gate ASSERT(OK_32PTR(mp->b_wptr)); 3290Sstevel@tonic-gate 3300Sstevel@tonic-gate if (isv4) { 3310Sstevel@tonic-gate ipha_t *iph = (ipha_t *)mp->b_rptr; 3320Sstevel@tonic-gate 3330Sstevel@tonic-gate bcopy(sctp->sctp_iphc, mp->b_rptr, ipsctplen); 3344818Skcpoon if (fp != sctp->sctp_current || src_changed) { 3354818Skcpoon /* Fix the source and destination addresses. */ 336*13009SChandrasekar.Marimuthu@Sun.COM IN6_V4MAPPED_TO_IPADDR(&fp->sf_faddr, iph->ipha_dst); 337*13009SChandrasekar.Marimuthu@Sun.COM IN6_V4MAPPED_TO_IPADDR(&fp->sf_saddr, iph->ipha_src); 3380Sstevel@tonic-gate } 3390Sstevel@tonic-gate /* set or clear the don't fragment bit */ 340*13009SChandrasekar.Marimuthu@Sun.COM if (fp->sf_df) { 3410Sstevel@tonic-gate iph->ipha_fragment_offset_and_flags = htons(IPH_DF); 3420Sstevel@tonic-gate } else { 3430Sstevel@tonic-gate iph->ipha_fragment_offset_and_flags = 0; 3440Sstevel@tonic-gate } 3450Sstevel@tonic-gate } else { 3460Sstevel@tonic-gate bcopy(sctp->sctp_iphc6, mp->b_rptr, ipsctplen); 3474818Skcpoon if (fp != sctp->sctp_current || src_changed) { 3484818Skcpoon /* Fix the source and destination addresses. */ 349*13009SChandrasekar.Marimuthu@Sun.COM ((ip6_t *)(mp->b_rptr))->ip6_dst = fp->sf_faddr; 350*13009SChandrasekar.Marimuthu@Sun.COM ((ip6_t *)(mp->b_rptr))->ip6_src = fp->sf_saddr; 3510Sstevel@tonic-gate } 3520Sstevel@tonic-gate } 3530Sstevel@tonic-gate ASSERT(sctp->sctp_connp != NULL); 3540Sstevel@tonic-gate return (mp); 3550Sstevel@tonic-gate } 3560Sstevel@tonic-gate 3570Sstevel@tonic-gate /* 3580Sstevel@tonic-gate * Notify upper layers about preferred write offset, write size. 3590Sstevel@tonic-gate */ 3600Sstevel@tonic-gate void 3610Sstevel@tonic-gate sctp_set_ulp_prop(sctp_t *sctp) 3620Sstevel@tonic-gate { 3630Sstevel@tonic-gate int hdrlen; 3648348SEric.Yu@Sun.COM struct sock_proto_props sopp; 3658348SEric.Yu@Sun.COM 3663448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 3670Sstevel@tonic-gate 368*13009SChandrasekar.Marimuthu@Sun.COM if (sctp->sctp_current->sf_isv4) { 3690Sstevel@tonic-gate hdrlen = sctp->sctp_hdr_len; 3700Sstevel@tonic-gate } else { 3710Sstevel@tonic-gate hdrlen = sctp->sctp_hdr6_len; 3720Sstevel@tonic-gate } 3730Sstevel@tonic-gate ASSERT(sctp->sctp_ulpd); 3740Sstevel@tonic-gate 37511042SErik.Nordmark@Sun.COM sctp->sctp_connp->conn_wroff = sctps->sctps_wroff_xtra + hdrlen + 37611042SErik.Nordmark@Sun.COM sizeof (sctp_data_hdr_t); 37711042SErik.Nordmark@Sun.COM 378*13009SChandrasekar.Marimuthu@Sun.COM ASSERT(sctp->sctp_current->sf_pmss == sctp->sctp_mss); 3798348SEric.Yu@Sun.COM bzero(&sopp, sizeof (sopp)); 3808348SEric.Yu@Sun.COM sopp.sopp_flags = SOCKOPT_MAXBLK|SOCKOPT_WROFF; 38111042SErik.Nordmark@Sun.COM sopp.sopp_wroff = sctp->sctp_connp->conn_wroff; 3828348SEric.Yu@Sun.COM sopp.sopp_maxblk = sctp->sctp_mss - sizeof (sctp_data_hdr_t); 3838348SEric.Yu@Sun.COM sctp->sctp_ulp_prop(sctp->sctp_ulpd, &sopp); 3840Sstevel@tonic-gate } 3850Sstevel@tonic-gate 38611042SErik.Nordmark@Sun.COM /* 38711042SErik.Nordmark@Sun.COM * Set the lengths in the packet and the transmit attributes. 38811042SErik.Nordmark@Sun.COM */ 3890Sstevel@tonic-gate void 39011042SErik.Nordmark@Sun.COM sctp_set_iplen(sctp_t *sctp, mblk_t *mp, ip_xmit_attr_t *ixa) 3910Sstevel@tonic-gate { 3920Sstevel@tonic-gate uint16_t sum = 0; 3930Sstevel@tonic-gate ipha_t *iph; 3940Sstevel@tonic-gate ip6_t *ip6h; 3950Sstevel@tonic-gate mblk_t *pmp = mp; 3960Sstevel@tonic-gate boolean_t isv4; 3970Sstevel@tonic-gate 3980Sstevel@tonic-gate isv4 = (IPH_HDR_VERSION(mp->b_rptr) == IPV4_VERSION); 3990Sstevel@tonic-gate for (; pmp; pmp = pmp->b_cont) 4000Sstevel@tonic-gate sum += pmp->b_wptr - pmp->b_rptr; 4010Sstevel@tonic-gate 40211042SErik.Nordmark@Sun.COM ixa->ixa_pktlen = sum; 4030Sstevel@tonic-gate if (isv4) { 4040Sstevel@tonic-gate iph = (ipha_t *)mp->b_rptr; 4050Sstevel@tonic-gate iph->ipha_length = htons(sum); 40611042SErik.Nordmark@Sun.COM ixa->ixa_ip_hdr_length = sctp->sctp_ip_hdr_len; 4070Sstevel@tonic-gate } else { 4080Sstevel@tonic-gate ip6h = (ip6_t *)mp->b_rptr; 40911042SErik.Nordmark@Sun.COM ip6h->ip6_plen = htons(sum - IPV6_HDR_LEN); 41011042SErik.Nordmark@Sun.COM ixa->ixa_ip_hdr_length = sctp->sctp_ip_hdr6_len; 4110Sstevel@tonic-gate } 4120Sstevel@tonic-gate } 4130Sstevel@tonic-gate 4140Sstevel@tonic-gate int 4150Sstevel@tonic-gate sctp_compare_faddrsets(sctp_faddr_t *a1, sctp_faddr_t *a2) 4160Sstevel@tonic-gate { 4170Sstevel@tonic-gate int na1 = 0; 4180Sstevel@tonic-gate int overlap = 0; 4190Sstevel@tonic-gate int equal = 1; 4200Sstevel@tonic-gate int onematch; 4210Sstevel@tonic-gate sctp_faddr_t *fp1, *fp2; 4220Sstevel@tonic-gate 423*13009SChandrasekar.Marimuthu@Sun.COM for (fp1 = a1; fp1; fp1 = fp1->sf_next) { 4240Sstevel@tonic-gate onematch = 0; 425*13009SChandrasekar.Marimuthu@Sun.COM for (fp2 = a2; fp2; fp2 = fp2->sf_next) { 426*13009SChandrasekar.Marimuthu@Sun.COM if (IN6_ARE_ADDR_EQUAL(&fp1->sf_faddr, 427*13009SChandrasekar.Marimuthu@Sun.COM &fp2->sf_faddr)) { 4280Sstevel@tonic-gate overlap++; 4290Sstevel@tonic-gate onematch = 1; 4300Sstevel@tonic-gate break; 4310Sstevel@tonic-gate } 4320Sstevel@tonic-gate if (!onematch) { 4330Sstevel@tonic-gate equal = 0; 4340Sstevel@tonic-gate } 4350Sstevel@tonic-gate } 4360Sstevel@tonic-gate na1++; 4370Sstevel@tonic-gate } 4380Sstevel@tonic-gate 4390Sstevel@tonic-gate if (equal) { 4400Sstevel@tonic-gate return (SCTP_ADDR_EQUAL); 4410Sstevel@tonic-gate } 4420Sstevel@tonic-gate if (overlap == na1) { 4430Sstevel@tonic-gate return (SCTP_ADDR_SUBSET); 4440Sstevel@tonic-gate } 4450Sstevel@tonic-gate if (overlap) { 4460Sstevel@tonic-gate return (SCTP_ADDR_OVERLAP); 4470Sstevel@tonic-gate } 4480Sstevel@tonic-gate return (SCTP_ADDR_DISJOINT); 4490Sstevel@tonic-gate } 4500Sstevel@tonic-gate 4510Sstevel@tonic-gate /* 4529710SKen.Powell@Sun.COM * Returns 0 on success, ENOMEM on memory allocation failure, EHOSTUNREACH 4539710SKen.Powell@Sun.COM * if the connection credentials fail remote host accreditation or 4549710SKen.Powell@Sun.COM * if the new destination does not support the previously established 4559710SKen.Powell@Sun.COM * connection security label. If sleep is true, this function should 4569710SKen.Powell@Sun.COM * never fail for a memory allocation failure. The boolean parameter 4579710SKen.Powell@Sun.COM * "first" decides whether the newly created faddr structure should be 4581735Skcpoon * added at the beginning of the list or at the end. 4591735Skcpoon * 4601735Skcpoon * Note: caller must hold conn fanout lock. 4610Sstevel@tonic-gate */ 4621735Skcpoon int 4631735Skcpoon sctp_add_faddr(sctp_t *sctp, in6_addr_t *addr, int sleep, boolean_t first) 4640Sstevel@tonic-gate { 4651735Skcpoon sctp_faddr_t *faddr; 4661735Skcpoon mblk_t *timer_mp; 4679710SKen.Powell@Sun.COM int err; 46811042SErik.Nordmark@Sun.COM conn_t *connp = sctp->sctp_connp; 4690Sstevel@tonic-gate 4701676Sjpk if (is_system_labeled()) { 47111042SErik.Nordmark@Sun.COM ip_xmit_attr_t *ixa = connp->conn_ixa; 47211042SErik.Nordmark@Sun.COM ts_label_t *effective_tsl = NULL; 47311042SErik.Nordmark@Sun.COM 47411042SErik.Nordmark@Sun.COM ASSERT(ixa->ixa_tsl != NULL); 4750Sstevel@tonic-gate 4769710SKen.Powell@Sun.COM /* 4779710SKen.Powell@Sun.COM * Verify the destination is allowed to receive packets 4789710SKen.Powell@Sun.COM * at the security label of the connection we are initiating. 4799710SKen.Powell@Sun.COM * 48011042SErik.Nordmark@Sun.COM * tsol_check_dest() will create a new effective label for 4819710SKen.Powell@Sun.COM * this connection with a modified label or label flags only 48211042SErik.Nordmark@Sun.COM * if there are changes from the original label. 4839710SKen.Powell@Sun.COM * 4849710SKen.Powell@Sun.COM * Accept whatever label we get if this is the first 4859710SKen.Powell@Sun.COM * destination address for this connection. The security 4869710SKen.Powell@Sun.COM * label and label flags must match any previuous settings 4879710SKen.Powell@Sun.COM * for all subsequent destination addresses. 4889710SKen.Powell@Sun.COM */ 4899710SKen.Powell@Sun.COM if (IN6_IS_ADDR_V4MAPPED(addr)) { 4909710SKen.Powell@Sun.COM uint32_t dst; 4919710SKen.Powell@Sun.COM IN6_V4MAPPED_TO_IPADDR(addr, dst); 49211042SErik.Nordmark@Sun.COM err = tsol_check_dest(ixa->ixa_tsl, 49311042SErik.Nordmark@Sun.COM &dst, IPV4_VERSION, connp->conn_mac_mode, 49411042SErik.Nordmark@Sun.COM connp->conn_zone_is_global, &effective_tsl); 4959710SKen.Powell@Sun.COM } else { 49611042SErik.Nordmark@Sun.COM err = tsol_check_dest(ixa->ixa_tsl, 49711042SErik.Nordmark@Sun.COM addr, IPV6_VERSION, connp->conn_mac_mode, 49811042SErik.Nordmark@Sun.COM connp->conn_zone_is_global, &effective_tsl); 4991676Sjpk } 5009710SKen.Powell@Sun.COM if (err != 0) 5019710SKen.Powell@Sun.COM return (err); 50211042SErik.Nordmark@Sun.COM 50311042SErik.Nordmark@Sun.COM if (sctp->sctp_faddrs == NULL && effective_tsl != NULL) { 50411042SErik.Nordmark@Sun.COM ip_xmit_attr_replace_tsl(ixa, effective_tsl); 50511042SErik.Nordmark@Sun.COM } else if (effective_tsl != NULL) { 50611042SErik.Nordmark@Sun.COM label_rele(effective_tsl); 5079710SKen.Powell@Sun.COM return (EHOSTUNREACH); 5089710SKen.Powell@Sun.COM } 5090Sstevel@tonic-gate } 5100Sstevel@tonic-gate 5111676Sjpk if ((faddr = kmem_cache_alloc(sctp_kmem_faddr_cache, sleep)) == NULL) 5121676Sjpk return (ENOMEM); 51311042SErik.Nordmark@Sun.COM bzero(faddr, sizeof (*faddr)); 5144691Skcpoon timer_mp = sctp_timer_alloc((sctp), sctp_rexmit_timer, sleep); 5151735Skcpoon if (timer_mp == NULL) { 5161735Skcpoon kmem_cache_free(sctp_kmem_faddr_cache, faddr); 5171735Skcpoon return (ENOMEM); 5181735Skcpoon } 5191735Skcpoon ((sctpt_t *)(timer_mp->b_rptr))->sctpt_faddr = faddr; 5201676Sjpk 52111042SErik.Nordmark@Sun.COM /* Start with any options set on the conn */ 522*13009SChandrasekar.Marimuthu@Sun.COM faddr->sf_ixa = conn_get_ixa_exclusive(connp); 523*13009SChandrasekar.Marimuthu@Sun.COM if (faddr->sf_ixa == NULL) { 52411042SErik.Nordmark@Sun.COM freemsg(timer_mp); 52511042SErik.Nordmark@Sun.COM kmem_cache_free(sctp_kmem_faddr_cache, faddr); 52611042SErik.Nordmark@Sun.COM return (ENOMEM); 52711042SErik.Nordmark@Sun.COM } 528*13009SChandrasekar.Marimuthu@Sun.COM faddr->sf_ixa->ixa_notify_cookie = connp->conn_sctp; 5294818Skcpoon 53011042SErik.Nordmark@Sun.COM sctp_init_faddr(sctp, faddr, addr, timer_mp); 531*13009SChandrasekar.Marimuthu@Sun.COM ASSERT(faddr->sf_ixa->ixa_cred != NULL); 53211042SErik.Nordmark@Sun.COM 53311042SErik.Nordmark@Sun.COM /* ip_attr_connect didn't allow broadcats/multicast dest */ 534*13009SChandrasekar.Marimuthu@Sun.COM ASSERT(faddr->sf_next == NULL); 5350Sstevel@tonic-gate 5361676Sjpk if (sctp->sctp_faddrs == NULL) { 5371676Sjpk ASSERT(sctp->sctp_lastfaddr == NULL); 5381676Sjpk /* only element on list; first and last are same */ 5391676Sjpk sctp->sctp_faddrs = sctp->sctp_lastfaddr = faddr; 5401676Sjpk } else if (first) { 5411676Sjpk ASSERT(sctp->sctp_lastfaddr != NULL); 542*13009SChandrasekar.Marimuthu@Sun.COM faddr->sf_next = sctp->sctp_faddrs; 5431676Sjpk sctp->sctp_faddrs = faddr; 5440Sstevel@tonic-gate } else { 545*13009SChandrasekar.Marimuthu@Sun.COM sctp->sctp_lastfaddr->sf_next = faddr; 5461676Sjpk sctp->sctp_lastfaddr = faddr; 5470Sstevel@tonic-gate } 548852Svi117747 sctp->sctp_nfaddrs++; 5490Sstevel@tonic-gate 5500Sstevel@tonic-gate return (0); 5510Sstevel@tonic-gate } 5520Sstevel@tonic-gate 5530Sstevel@tonic-gate sctp_faddr_t * 5540Sstevel@tonic-gate sctp_lookup_faddr(sctp_t *sctp, in6_addr_t *addr) 5550Sstevel@tonic-gate { 5560Sstevel@tonic-gate sctp_faddr_t *fp; 5570Sstevel@tonic-gate 558*13009SChandrasekar.Marimuthu@Sun.COM for (fp = sctp->sctp_faddrs; fp != NULL; fp = fp->sf_next) { 559*13009SChandrasekar.Marimuthu@Sun.COM if (IN6_ARE_ADDR_EQUAL(&fp->sf_faddr, addr)) 5600Sstevel@tonic-gate break; 5610Sstevel@tonic-gate } 5620Sstevel@tonic-gate 5630Sstevel@tonic-gate return (fp); 5640Sstevel@tonic-gate } 5650Sstevel@tonic-gate 5660Sstevel@tonic-gate sctp_faddr_t * 5670Sstevel@tonic-gate sctp_lookup_faddr_nosctp(sctp_faddr_t *fp, in6_addr_t *addr) 5680Sstevel@tonic-gate { 569*13009SChandrasekar.Marimuthu@Sun.COM for (; fp; fp = fp->sf_next) { 570*13009SChandrasekar.Marimuthu@Sun.COM if (IN6_ARE_ADDR_EQUAL(&fp->sf_faddr, addr)) { 5710Sstevel@tonic-gate break; 5720Sstevel@tonic-gate } 5730Sstevel@tonic-gate } 5740Sstevel@tonic-gate 5750Sstevel@tonic-gate return (fp); 5760Sstevel@tonic-gate } 5770Sstevel@tonic-gate 5781735Skcpoon /* 5791735Skcpoon * To change the currently used peer address to the specified one. 5801735Skcpoon */ 5810Sstevel@tonic-gate void 5821735Skcpoon sctp_set_faddr_current(sctp_t *sctp, sctp_faddr_t *fp) 5830Sstevel@tonic-gate { 5841735Skcpoon /* Now setup the composite header. */ 585*13009SChandrasekar.Marimuthu@Sun.COM if (fp->sf_isv4) { 586*13009SChandrasekar.Marimuthu@Sun.COM IN6_V4MAPPED_TO_IPADDR(&fp->sf_faddr, 5870Sstevel@tonic-gate sctp->sctp_ipha->ipha_dst); 588*13009SChandrasekar.Marimuthu@Sun.COM IN6_V4MAPPED_TO_IPADDR(&fp->sf_saddr, 589*13009SChandrasekar.Marimuthu@Sun.COM sctp->sctp_ipha->ipha_src); 5900Sstevel@tonic-gate /* update don't fragment bit */ 591*13009SChandrasekar.Marimuthu@Sun.COM if (fp->sf_df) { 5920Sstevel@tonic-gate sctp->sctp_ipha->ipha_fragment_offset_and_flags = 5930Sstevel@tonic-gate htons(IPH_DF); 5940Sstevel@tonic-gate } else { 5950Sstevel@tonic-gate sctp->sctp_ipha->ipha_fragment_offset_and_flags = 0; 5960Sstevel@tonic-gate } 5970Sstevel@tonic-gate } else { 598*13009SChandrasekar.Marimuthu@Sun.COM sctp->sctp_ip6h->ip6_dst = fp->sf_faddr; 599*13009SChandrasekar.Marimuthu@Sun.COM sctp->sctp_ip6h->ip6_src = fp->sf_saddr; 6000Sstevel@tonic-gate } 6011735Skcpoon 6021735Skcpoon sctp->sctp_current = fp; 603*13009SChandrasekar.Marimuthu@Sun.COM sctp->sctp_mss = fp->sf_pmss; 6041735Skcpoon 6051735Skcpoon /* Update the uppper layer for the change. */ 6061735Skcpoon if (!SCTP_IS_DETACHED(sctp)) 6071735Skcpoon sctp_set_ulp_prop(sctp); 6080Sstevel@tonic-gate } 6090Sstevel@tonic-gate 6100Sstevel@tonic-gate void 6110Sstevel@tonic-gate sctp_redo_faddr_srcs(sctp_t *sctp) 6120Sstevel@tonic-gate { 6130Sstevel@tonic-gate sctp_faddr_t *fp; 6140Sstevel@tonic-gate 615*13009SChandrasekar.Marimuthu@Sun.COM for (fp = sctp->sctp_faddrs; fp != NULL; fp = fp->sf_next) { 61611042SErik.Nordmark@Sun.COM sctp_get_dest(sctp, fp); 6170Sstevel@tonic-gate } 6180Sstevel@tonic-gate } 6190Sstevel@tonic-gate 6200Sstevel@tonic-gate void 6210Sstevel@tonic-gate sctp_faddr_alive(sctp_t *sctp, sctp_faddr_t *fp) 6220Sstevel@tonic-gate { 62312869SKacheong.Poon@Sun.COM int64_t now = LBOLT_FASTPATH64; 6240Sstevel@tonic-gate 62512869SKacheong.Poon@Sun.COM /* 62612869SKacheong.Poon@Sun.COM * If we are under memory pressure, we abort association waiting 62712869SKacheong.Poon@Sun.COM * in zero window probing state for too long. We do this by not 62812869SKacheong.Poon@Sun.COM * resetting sctp_strikes. So if sctp_zero_win_probe continues 62912869SKacheong.Poon@Sun.COM * while under memory pressure, this association will eventually 63012869SKacheong.Poon@Sun.COM * time out. 63112869SKacheong.Poon@Sun.COM */ 63212869SKacheong.Poon@Sun.COM if (!sctp->sctp_zero_win_probe || !sctp->sctp_sctps->sctps_reclaim) { 63312869SKacheong.Poon@Sun.COM sctp->sctp_strikes = 0; 63412869SKacheong.Poon@Sun.COM } 635*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_strikes = 0; 636*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_lastactive = now; 637*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_hb_expiry = now + SET_HB_INTVL(fp); 638*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_hb_pending = B_FALSE; 639*13009SChandrasekar.Marimuthu@Sun.COM if (fp->sf_state != SCTP_FADDRS_ALIVE) { 640*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_state = SCTP_FADDRS_ALIVE; 641*13009SChandrasekar.Marimuthu@Sun.COM sctp_intf_event(sctp, fp->sf_faddr, SCTP_ADDR_AVAILABLE, 0); 6424818Skcpoon /* Should have a full IRE now */ 64311042SErik.Nordmark@Sun.COM sctp_get_dest(sctp, fp); 6440Sstevel@tonic-gate 6451735Skcpoon /* 6461735Skcpoon * If this is the primary, switch back to it now. And 6471735Skcpoon * we probably want to reset the source addr used to reach 6481735Skcpoon * it. 64911042SErik.Nordmark@Sun.COM * Note that if we didn't find a source in sctp_get_dest 65011042SErik.Nordmark@Sun.COM * then we'd be unreachable at this point in time. 6511735Skcpoon */ 65211042SErik.Nordmark@Sun.COM if (fp == sctp->sctp_primary && 653*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_state != SCTP_FADDRS_UNREACH) { 6541735Skcpoon sctp_set_faddr_current(sctp, fp); 6551735Skcpoon return; 6560Sstevel@tonic-gate } 6570Sstevel@tonic-gate } 6580Sstevel@tonic-gate } 6590Sstevel@tonic-gate 66012869SKacheong.Poon@Sun.COM /* 66112869SKacheong.Poon@Sun.COM * Return B_TRUE if there is still an active peer address with zero strikes; 66212869SKacheong.Poon@Sun.COM * otherwise rturn B_FALSE. 66312869SKacheong.Poon@Sun.COM */ 66412869SKacheong.Poon@Sun.COM boolean_t 6650Sstevel@tonic-gate sctp_is_a_faddr_clean(sctp_t *sctp) 6660Sstevel@tonic-gate { 6670Sstevel@tonic-gate sctp_faddr_t *fp; 6680Sstevel@tonic-gate 669*13009SChandrasekar.Marimuthu@Sun.COM for (fp = sctp->sctp_faddrs; fp; fp = fp->sf_next) { 670*13009SChandrasekar.Marimuthu@Sun.COM if (fp->sf_state == SCTP_FADDRS_ALIVE && fp->sf_strikes == 0) { 67112869SKacheong.Poon@Sun.COM return (B_TRUE); 6720Sstevel@tonic-gate } 6730Sstevel@tonic-gate } 6740Sstevel@tonic-gate 67512869SKacheong.Poon@Sun.COM return (B_FALSE); 6760Sstevel@tonic-gate } 6770Sstevel@tonic-gate 6780Sstevel@tonic-gate /* 6790Sstevel@tonic-gate * Returns 0 if there is at leave one other active faddr, -1 if there 6800Sstevel@tonic-gate * are none. If there are none left, faddr_dead() will start killing the 6810Sstevel@tonic-gate * association. 6820Sstevel@tonic-gate * If the downed faddr was the current faddr, a new current faddr 6830Sstevel@tonic-gate * will be chosen. 6840Sstevel@tonic-gate */ 6850Sstevel@tonic-gate int 6860Sstevel@tonic-gate sctp_faddr_dead(sctp_t *sctp, sctp_faddr_t *fp, int newstate) 6870Sstevel@tonic-gate { 6880Sstevel@tonic-gate sctp_faddr_t *ofp; 6893448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 6900Sstevel@tonic-gate 691*13009SChandrasekar.Marimuthu@Sun.COM if (fp->sf_state == SCTP_FADDRS_ALIVE) { 692*13009SChandrasekar.Marimuthu@Sun.COM sctp_intf_event(sctp, fp->sf_faddr, SCTP_ADDR_UNREACHABLE, 0); 6930Sstevel@tonic-gate } 694*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_state = newstate; 6950Sstevel@tonic-gate 6960Sstevel@tonic-gate dprint(1, ("sctp_faddr_dead: %x:%x:%x:%x down (state=%d)\n", 697*13009SChandrasekar.Marimuthu@Sun.COM SCTP_PRINTADDR(fp->sf_faddr), newstate)); 6980Sstevel@tonic-gate 6990Sstevel@tonic-gate if (fp == sctp->sctp_current) { 7000Sstevel@tonic-gate /* Current faddr down; need to switch it */ 7010Sstevel@tonic-gate sctp->sctp_current = NULL; 7020Sstevel@tonic-gate } 7030Sstevel@tonic-gate 7040Sstevel@tonic-gate /* Find next alive faddr */ 7050Sstevel@tonic-gate ofp = fp; 706*13009SChandrasekar.Marimuthu@Sun.COM for (fp = fp->sf_next; fp != NULL; fp = fp->sf_next) { 707*13009SChandrasekar.Marimuthu@Sun.COM if (fp->sf_state == SCTP_FADDRS_ALIVE) { 7080Sstevel@tonic-gate break; 7090Sstevel@tonic-gate } 7100Sstevel@tonic-gate } 7110Sstevel@tonic-gate 7120Sstevel@tonic-gate if (fp == NULL) { 7130Sstevel@tonic-gate /* Continue from beginning of list */ 714*13009SChandrasekar.Marimuthu@Sun.COM for (fp = sctp->sctp_faddrs; fp != ofp; fp = fp->sf_next) { 715*13009SChandrasekar.Marimuthu@Sun.COM if (fp->sf_state == SCTP_FADDRS_ALIVE) { 7160Sstevel@tonic-gate break; 7170Sstevel@tonic-gate } 7180Sstevel@tonic-gate } 7190Sstevel@tonic-gate } 7200Sstevel@tonic-gate 7211735Skcpoon /* 7221735Skcpoon * Find a new fp, so if the current faddr is dead, use the new fp 7231735Skcpoon * as the current one. 7241735Skcpoon */ 7250Sstevel@tonic-gate if (fp != ofp) { 7260Sstevel@tonic-gate if (sctp->sctp_current == NULL) { 7270Sstevel@tonic-gate dprint(1, ("sctp_faddr_dead: failover->%x:%x:%x:%x\n", 728*13009SChandrasekar.Marimuthu@Sun.COM SCTP_PRINTADDR(fp->sf_faddr))); 7291735Skcpoon /* 7301735Skcpoon * Note that we don't need to reset the source addr 7311735Skcpoon * of the new fp. 7321735Skcpoon */ 7331735Skcpoon sctp_set_faddr_current(sctp, fp); 7340Sstevel@tonic-gate } 7350Sstevel@tonic-gate return (0); 7360Sstevel@tonic-gate } 7370Sstevel@tonic-gate 7380Sstevel@tonic-gate 7390Sstevel@tonic-gate /* All faddrs are down; kill the association */ 7400Sstevel@tonic-gate dprint(1, ("sctp_faddr_dead: all faddrs down, killing assoc\n")); 74112869SKacheong.Poon@Sun.COM SCTPS_BUMP_MIB(sctps, sctpAborted); 7420Sstevel@tonic-gate sctp_assoc_event(sctp, sctp->sctp_state < SCTPS_ESTABLISHED ? 7430Sstevel@tonic-gate SCTP_CANT_STR_ASSOC : SCTP_COMM_LOST, 0, NULL); 7440Sstevel@tonic-gate sctp_clean_death(sctp, sctp->sctp_client_errno ? 7450Sstevel@tonic-gate sctp->sctp_client_errno : ETIMEDOUT); 7460Sstevel@tonic-gate 7470Sstevel@tonic-gate return (-1); 7480Sstevel@tonic-gate } 7490Sstevel@tonic-gate 7500Sstevel@tonic-gate sctp_faddr_t * 7510Sstevel@tonic-gate sctp_rotate_faddr(sctp_t *sctp, sctp_faddr_t *ofp) 7520Sstevel@tonic-gate { 7530Sstevel@tonic-gate sctp_faddr_t *nfp = NULL; 75411908SGeorge.Shepherd@Sun.COM sctp_faddr_t *saved_fp = NULL; 75511908SGeorge.Shepherd@Sun.COM int min_strikes; 7560Sstevel@tonic-gate 7570Sstevel@tonic-gate if (ofp == NULL) { 7580Sstevel@tonic-gate ofp = sctp->sctp_current; 7590Sstevel@tonic-gate } 76011908SGeorge.Shepherd@Sun.COM /* Nothing to do */ 76111908SGeorge.Shepherd@Sun.COM if (sctp->sctp_nfaddrs < 2) 76211908SGeorge.Shepherd@Sun.COM return (ofp); 7630Sstevel@tonic-gate 76411908SGeorge.Shepherd@Sun.COM /* 76511908SGeorge.Shepherd@Sun.COM * Find the next live peer address with zero strikes. In case 76611908SGeorge.Shepherd@Sun.COM * there is none, find the one with the lowest number of strikes. 76711908SGeorge.Shepherd@Sun.COM */ 768*13009SChandrasekar.Marimuthu@Sun.COM min_strikes = ofp->sf_strikes; 769*13009SChandrasekar.Marimuthu@Sun.COM nfp = ofp->sf_next; 77012858SGeorge.Shepherd@Sun.COM while (nfp != ofp) { 77111908SGeorge.Shepherd@Sun.COM /* If reached end of list, continue scan from the head */ 77211908SGeorge.Shepherd@Sun.COM if (nfp == NULL) { 77311908SGeorge.Shepherd@Sun.COM nfp = sctp->sctp_faddrs; 77411908SGeorge.Shepherd@Sun.COM continue; 7750Sstevel@tonic-gate } 776*13009SChandrasekar.Marimuthu@Sun.COM if (nfp->sf_state == SCTP_FADDRS_ALIVE) { 777*13009SChandrasekar.Marimuthu@Sun.COM if (nfp->sf_strikes == 0) 7780Sstevel@tonic-gate break; 779*13009SChandrasekar.Marimuthu@Sun.COM if (nfp->sf_strikes < min_strikes) { 780*13009SChandrasekar.Marimuthu@Sun.COM min_strikes = nfp->sf_strikes; 78111908SGeorge.Shepherd@Sun.COM saved_fp = nfp; 7820Sstevel@tonic-gate } 7830Sstevel@tonic-gate } 784*13009SChandrasekar.Marimuthu@Sun.COM nfp = nfp->sf_next; 7850Sstevel@tonic-gate } 78611908SGeorge.Shepherd@Sun.COM /* If reached the old address, there is no zero strike path */ 78711908SGeorge.Shepherd@Sun.COM if (nfp == ofp) 78811908SGeorge.Shepherd@Sun.COM nfp = NULL; 7890Sstevel@tonic-gate 7900Sstevel@tonic-gate /* 79111908SGeorge.Shepherd@Sun.COM * If there is a peer address with zero strikes we use that, if not 79211908SGeorge.Shepherd@Sun.COM * return a peer address with fewer strikes than the one last used, 79311908SGeorge.Shepherd@Sun.COM * if neither exist we may as well stay with the old one. 7940Sstevel@tonic-gate */ 79511908SGeorge.Shepherd@Sun.COM if (nfp != NULL) 79611908SGeorge.Shepherd@Sun.COM return (nfp); 79711908SGeorge.Shepherd@Sun.COM if (saved_fp != NULL) 79811908SGeorge.Shepherd@Sun.COM return (saved_fp); 79911908SGeorge.Shepherd@Sun.COM return (ofp); 8000Sstevel@tonic-gate } 8010Sstevel@tonic-gate 8020Sstevel@tonic-gate void 8030Sstevel@tonic-gate sctp_unlink_faddr(sctp_t *sctp, sctp_faddr_t *fp) 8040Sstevel@tonic-gate { 8050Sstevel@tonic-gate sctp_faddr_t *fpp; 8060Sstevel@tonic-gate 8070Sstevel@tonic-gate if (!sctp->sctp_faddrs) { 8080Sstevel@tonic-gate return; 8090Sstevel@tonic-gate } 8100Sstevel@tonic-gate 811*13009SChandrasekar.Marimuthu@Sun.COM if (fp->sf_timer_mp != NULL) { 812*13009SChandrasekar.Marimuthu@Sun.COM sctp_timer_free(fp->sf_timer_mp); 813*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_timer_mp = NULL; 814*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_timer_running = 0; 8150Sstevel@tonic-gate } 816*13009SChandrasekar.Marimuthu@Sun.COM if (fp->sf_rc_timer_mp != NULL) { 817*13009SChandrasekar.Marimuthu@Sun.COM sctp_timer_free(fp->sf_rc_timer_mp); 818*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_rc_timer_mp = NULL; 819*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_rc_timer_running = 0; 8200Sstevel@tonic-gate } 821*13009SChandrasekar.Marimuthu@Sun.COM if (fp->sf_ixa != NULL) { 822*13009SChandrasekar.Marimuthu@Sun.COM ixa_refrele(fp->sf_ixa); 823*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_ixa = NULL; 8240Sstevel@tonic-gate } 8250Sstevel@tonic-gate 8260Sstevel@tonic-gate if (fp == sctp->sctp_faddrs) { 8270Sstevel@tonic-gate goto gotit; 8280Sstevel@tonic-gate } 8290Sstevel@tonic-gate 830*13009SChandrasekar.Marimuthu@Sun.COM for (fpp = sctp->sctp_faddrs; fpp->sf_next != fp; fpp = fpp->sf_next) 8310Sstevel@tonic-gate ; 8320Sstevel@tonic-gate 8330Sstevel@tonic-gate gotit: 8340Sstevel@tonic-gate ASSERT(sctp->sctp_conn_tfp != NULL); 8350Sstevel@tonic-gate mutex_enter(&sctp->sctp_conn_tfp->tf_lock); 8360Sstevel@tonic-gate if (fp == sctp->sctp_faddrs) { 837*13009SChandrasekar.Marimuthu@Sun.COM sctp->sctp_faddrs = fp->sf_next; 8380Sstevel@tonic-gate } else { 839*13009SChandrasekar.Marimuthu@Sun.COM fpp->sf_next = fp->sf_next; 8400Sstevel@tonic-gate } 8410Sstevel@tonic-gate mutex_exit(&sctp->sctp_conn_tfp->tf_lock); 8420Sstevel@tonic-gate kmem_cache_free(sctp_kmem_faddr_cache, fp); 843852Svi117747 sctp->sctp_nfaddrs--; 8440Sstevel@tonic-gate } 8450Sstevel@tonic-gate 8460Sstevel@tonic-gate void 8470Sstevel@tonic-gate sctp_zap_faddrs(sctp_t *sctp, int caller_holds_lock) 8480Sstevel@tonic-gate { 8490Sstevel@tonic-gate sctp_faddr_t *fp, *fpn; 8500Sstevel@tonic-gate 8510Sstevel@tonic-gate if (sctp->sctp_faddrs == NULL) { 8520Sstevel@tonic-gate ASSERT(sctp->sctp_lastfaddr == NULL); 8530Sstevel@tonic-gate return; 8540Sstevel@tonic-gate } 8550Sstevel@tonic-gate 8560Sstevel@tonic-gate ASSERT(sctp->sctp_lastfaddr != NULL); 8570Sstevel@tonic-gate sctp->sctp_lastfaddr = NULL; 8580Sstevel@tonic-gate sctp->sctp_current = NULL; 8590Sstevel@tonic-gate sctp->sctp_primary = NULL; 8600Sstevel@tonic-gate 8610Sstevel@tonic-gate sctp_free_faddr_timers(sctp); 8620Sstevel@tonic-gate 8630Sstevel@tonic-gate if (sctp->sctp_conn_tfp != NULL && !caller_holds_lock) { 8640Sstevel@tonic-gate /* in conn fanout; need to hold lock */ 8650Sstevel@tonic-gate mutex_enter(&sctp->sctp_conn_tfp->tf_lock); 8660Sstevel@tonic-gate } 8670Sstevel@tonic-gate 8680Sstevel@tonic-gate for (fp = sctp->sctp_faddrs; fp; fp = fpn) { 869*13009SChandrasekar.Marimuthu@Sun.COM fpn = fp->sf_next; 870*13009SChandrasekar.Marimuthu@Sun.COM if (fp->sf_ixa != NULL) { 871*13009SChandrasekar.Marimuthu@Sun.COM ixa_refrele(fp->sf_ixa); 872*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_ixa = NULL; 87311042SErik.Nordmark@Sun.COM } 8740Sstevel@tonic-gate kmem_cache_free(sctp_kmem_faddr_cache, fp); 875852Svi117747 sctp->sctp_nfaddrs--; 8760Sstevel@tonic-gate } 8770Sstevel@tonic-gate 8780Sstevel@tonic-gate sctp->sctp_faddrs = NULL; 879852Svi117747 ASSERT(sctp->sctp_nfaddrs == 0); 8800Sstevel@tonic-gate if (sctp->sctp_conn_tfp != NULL && !caller_holds_lock) { 8810Sstevel@tonic-gate mutex_exit(&sctp->sctp_conn_tfp->tf_lock); 8820Sstevel@tonic-gate } 8830Sstevel@tonic-gate 8840Sstevel@tonic-gate } 8850Sstevel@tonic-gate 8860Sstevel@tonic-gate void 8870Sstevel@tonic-gate sctp_zap_addrs(sctp_t *sctp) 8880Sstevel@tonic-gate { 8890Sstevel@tonic-gate sctp_zap_faddrs(sctp, 0); 8900Sstevel@tonic-gate sctp_free_saddrs(sctp); 8910Sstevel@tonic-gate } 8920Sstevel@tonic-gate 8930Sstevel@tonic-gate /* 89411042SErik.Nordmark@Sun.COM * Build two SCTP header templates; one for IPv4 and one for IPv6. 89511042SErik.Nordmark@Sun.COM * Store them in sctp_iphc and sctp_iphc6 respectively (and related fields). 89611042SErik.Nordmark@Sun.COM * There are no IP addresses in the templates, but the port numbers and 89711042SErik.Nordmark@Sun.COM * verifier are field in from the conn_t and sctp_t. 89811042SErik.Nordmark@Sun.COM * 89911042SErik.Nordmark@Sun.COM * Returns failure if can't allocate memory, or if there is a problem 90011042SErik.Nordmark@Sun.COM * with a routing header/option. 90111042SErik.Nordmark@Sun.COM * 90211042SErik.Nordmark@Sun.COM * We allocate space for the minimum sctp header (sctp_hdr_t). 90311042SErik.Nordmark@Sun.COM * 90411042SErik.Nordmark@Sun.COM * We massage an routing option/header. There is no checksum implication 90511042SErik.Nordmark@Sun.COM * for a routing header for sctp. 90611042SErik.Nordmark@Sun.COM * 90711042SErik.Nordmark@Sun.COM * Caller needs to update conn_wroff if desired. 90811042SErik.Nordmark@Sun.COM * 90911042SErik.Nordmark@Sun.COM * TSol notes: This assumes that a SCTP association has a single peer label 91011042SErik.Nordmark@Sun.COM * since we only track a single pair of ipp_label_v4/v6 and not a separate one 91111042SErik.Nordmark@Sun.COM * for each faddr. 9120Sstevel@tonic-gate */ 9130Sstevel@tonic-gate int 91411042SErik.Nordmark@Sun.COM sctp_build_hdrs(sctp_t *sctp, int sleep) 9150Sstevel@tonic-gate { 91611042SErik.Nordmark@Sun.COM conn_t *connp = sctp->sctp_connp; 91711042SErik.Nordmark@Sun.COM ip_pkt_t *ipp = &connp->conn_xmit_ipp; 91811042SErik.Nordmark@Sun.COM uint_t ip_hdr_length; 91911042SErik.Nordmark@Sun.COM uchar_t *hdrs; 92011042SErik.Nordmark@Sun.COM uint_t hdrs_len; 92111042SErik.Nordmark@Sun.COM uint_t ulp_hdr_length = sizeof (sctp_hdr_t); 92211042SErik.Nordmark@Sun.COM ipha_t *ipha; 92311042SErik.Nordmark@Sun.COM ip6_t *ip6h; 9240Sstevel@tonic-gate sctp_hdr_t *sctph; 92511042SErik.Nordmark@Sun.COM in6_addr_t v6src, v6dst; 92611042SErik.Nordmark@Sun.COM ipaddr_t v4src, v4dst; 9270Sstevel@tonic-gate 92811042SErik.Nordmark@Sun.COM v4src = connp->conn_saddr_v4; 92911042SErik.Nordmark@Sun.COM v4dst = connp->conn_faddr_v4; 93011042SErik.Nordmark@Sun.COM v6src = connp->conn_saddr_v6; 93111042SErik.Nordmark@Sun.COM v6dst = connp->conn_faddr_v6; 9320Sstevel@tonic-gate 93311042SErik.Nordmark@Sun.COM /* First do IPv4 header */ 93411042SErik.Nordmark@Sun.COM ip_hdr_length = ip_total_hdrs_len_v4(ipp); 9350Sstevel@tonic-gate 93611042SErik.Nordmark@Sun.COM /* In case of TX label and IP options it can be too much */ 93711042SErik.Nordmark@Sun.COM if (ip_hdr_length > IP_MAX_HDR_LENGTH) { 93811042SErik.Nordmark@Sun.COM /* Preserves existing TX errno for this */ 93911042SErik.Nordmark@Sun.COM return (EHOSTUNREACH); 94011042SErik.Nordmark@Sun.COM } 94111042SErik.Nordmark@Sun.COM hdrs_len = ip_hdr_length + ulp_hdr_length; 94211042SErik.Nordmark@Sun.COM ASSERT(hdrs_len != 0); 9431676Sjpk 94411042SErik.Nordmark@Sun.COM if (hdrs_len != sctp->sctp_iphc_len) { 94511042SErik.Nordmark@Sun.COM /* Allocate new before we free any old */ 94611042SErik.Nordmark@Sun.COM hdrs = kmem_alloc(hdrs_len, sleep); 9470Sstevel@tonic-gate if (hdrs == NULL) 9480Sstevel@tonic-gate return (ENOMEM); 9490Sstevel@tonic-gate 95011042SErik.Nordmark@Sun.COM if (sctp->sctp_iphc != NULL) 95111042SErik.Nordmark@Sun.COM kmem_free(sctp->sctp_iphc, sctp->sctp_iphc_len); 95211042SErik.Nordmark@Sun.COM sctp->sctp_iphc = hdrs; 95311042SErik.Nordmark@Sun.COM sctp->sctp_iphc_len = hdrs_len; 95411042SErik.Nordmark@Sun.COM } else { 95511042SErik.Nordmark@Sun.COM hdrs = sctp->sctp_iphc; 95611042SErik.Nordmark@Sun.COM } 95711042SErik.Nordmark@Sun.COM sctp->sctp_hdr_len = sctp->sctp_iphc_len; 95811042SErik.Nordmark@Sun.COM sctp->sctp_ip_hdr_len = ip_hdr_length; 95911042SErik.Nordmark@Sun.COM 96011042SErik.Nordmark@Sun.COM sctph = (sctp_hdr_t *)(hdrs + ip_hdr_length); 96111042SErik.Nordmark@Sun.COM sctp->sctp_sctph = sctph; 96211042SErik.Nordmark@Sun.COM sctph->sh_sport = connp->conn_lport; 96311042SErik.Nordmark@Sun.COM sctph->sh_dport = connp->conn_fport; 96411042SErik.Nordmark@Sun.COM sctph->sh_verf = sctp->sctp_fvtag; 96511042SErik.Nordmark@Sun.COM sctph->sh_chksum = 0; 96611042SErik.Nordmark@Sun.COM 96711042SErik.Nordmark@Sun.COM ipha = (ipha_t *)hdrs; 96811042SErik.Nordmark@Sun.COM sctp->sctp_ipha = ipha; 96911042SErik.Nordmark@Sun.COM 97011042SErik.Nordmark@Sun.COM ipha->ipha_src = v4src; 97111042SErik.Nordmark@Sun.COM ipha->ipha_dst = v4dst; 97211042SErik.Nordmark@Sun.COM ip_build_hdrs_v4(hdrs, ip_hdr_length, ipp, connp->conn_proto); 97311042SErik.Nordmark@Sun.COM ipha->ipha_length = htons(hdrs_len); 97411042SErik.Nordmark@Sun.COM ipha->ipha_fragment_offset_and_flags = 0; 97511042SErik.Nordmark@Sun.COM 97611042SErik.Nordmark@Sun.COM if (ipp->ipp_fields & IPPF_IPV4_OPTIONS) 97711042SErik.Nordmark@Sun.COM (void) ip_massage_options(ipha, connp->conn_netstack); 97811042SErik.Nordmark@Sun.COM 97911042SErik.Nordmark@Sun.COM /* Now IPv6 */ 98011042SErik.Nordmark@Sun.COM ip_hdr_length = ip_total_hdrs_len_v6(ipp); 98111042SErik.Nordmark@Sun.COM hdrs_len = ip_hdr_length + ulp_hdr_length; 98211042SErik.Nordmark@Sun.COM ASSERT(hdrs_len != 0); 98311042SErik.Nordmark@Sun.COM 98411042SErik.Nordmark@Sun.COM if (hdrs_len != sctp->sctp_iphc6_len) { 98511042SErik.Nordmark@Sun.COM /* Allocate new before we free any old */ 98611042SErik.Nordmark@Sun.COM hdrs = kmem_alloc(hdrs_len, sleep); 98711042SErik.Nordmark@Sun.COM if (hdrs == NULL) 98811042SErik.Nordmark@Sun.COM return (ENOMEM); 98911042SErik.Nordmark@Sun.COM 99011042SErik.Nordmark@Sun.COM if (sctp->sctp_iphc6 != NULL) 9910Sstevel@tonic-gate kmem_free(sctp->sctp_iphc6, sctp->sctp_iphc6_len); 9920Sstevel@tonic-gate sctp->sctp_iphc6 = hdrs; 9930Sstevel@tonic-gate sctp->sctp_iphc6_len = hdrs_len; 99411042SErik.Nordmark@Sun.COM } else { 99511042SErik.Nordmark@Sun.COM hdrs = sctp->sctp_iphc6; 9960Sstevel@tonic-gate } 99711042SErik.Nordmark@Sun.COM sctp->sctp_hdr6_len = sctp->sctp_iphc6_len; 99811042SErik.Nordmark@Sun.COM sctp->sctp_ip_hdr6_len = ip_hdr_length; 9990Sstevel@tonic-gate 100011042SErik.Nordmark@Sun.COM sctph = (sctp_hdr_t *)(hdrs + ip_hdr_length); 100111042SErik.Nordmark@Sun.COM sctp->sctp_sctph6 = sctph; 100211042SErik.Nordmark@Sun.COM sctph->sh_sport = connp->conn_lport; 100311042SErik.Nordmark@Sun.COM sctph->sh_dport = connp->conn_fport; 100411042SErik.Nordmark@Sun.COM sctph->sh_verf = sctp->sctp_fvtag; 100511042SErik.Nordmark@Sun.COM sctph->sh_chksum = 0; 10060Sstevel@tonic-gate 100711042SErik.Nordmark@Sun.COM ip6h = (ip6_t *)hdrs; 100811042SErik.Nordmark@Sun.COM sctp->sctp_ip6h = ip6h; 10090Sstevel@tonic-gate 101011042SErik.Nordmark@Sun.COM ip6h->ip6_src = v6src; 101111042SErik.Nordmark@Sun.COM ip6h->ip6_dst = v6dst; 101211042SErik.Nordmark@Sun.COM ip_build_hdrs_v6(hdrs, ip_hdr_length, ipp, connp->conn_proto, 101311042SErik.Nordmark@Sun.COM connp->conn_flowinfo); 101411042SErik.Nordmark@Sun.COM ip6h->ip6_plen = htons(hdrs_len - IPV6_HDR_LEN); 10150Sstevel@tonic-gate 101611042SErik.Nordmark@Sun.COM if (ipp->ipp_fields & IPPF_RTHDR) { 101711042SErik.Nordmark@Sun.COM uint8_t *end; 101811042SErik.Nordmark@Sun.COM ip6_rthdr_t *rth; 10190Sstevel@tonic-gate 102011042SErik.Nordmark@Sun.COM end = (uint8_t *)ip6h + ip_hdr_length; 102111042SErik.Nordmark@Sun.COM rth = ip_find_rthdr_v6(ip6h, end); 102211042SErik.Nordmark@Sun.COM if (rth != NULL) { 102311042SErik.Nordmark@Sun.COM (void) ip_massage_options_v6(ip6h, rth, 102411042SErik.Nordmark@Sun.COM connp->conn_netstack); 102511042SErik.Nordmark@Sun.COM } 10261676Sjpk 102711042SErik.Nordmark@Sun.COM /* 102811042SErik.Nordmark@Sun.COM * Verify that the first hop isn't a mapped address. 102911042SErik.Nordmark@Sun.COM * Routers along the path need to do this verification 103011042SErik.Nordmark@Sun.COM * for subsequent hops. 103111042SErik.Nordmark@Sun.COM */ 103211042SErik.Nordmark@Sun.COM if (IN6_IS_ADDR_V4MAPPED(&ip6h->ip6_dst)) 103311042SErik.Nordmark@Sun.COM return (EADDRNOTAVAIL); 10341676Sjpk } 10351676Sjpk return (0); 10361676Sjpk } 10371676Sjpk 10381676Sjpk static int 103911042SErik.Nordmark@Sun.COM sctp_v4_label(sctp_t *sctp, sctp_faddr_t *fp) 10401676Sjpk { 104111042SErik.Nordmark@Sun.COM conn_t *connp = sctp->sctp_connp; 104211042SErik.Nordmark@Sun.COM 1043*13009SChandrasekar.Marimuthu@Sun.COM ASSERT(fp->sf_ixa->ixa_flags & IXAF_IS_IPV4); 1044*13009SChandrasekar.Marimuthu@Sun.COM return (conn_update_label(connp, fp->sf_ixa, &fp->sf_faddr, 104511042SErik.Nordmark@Sun.COM &connp->conn_xmit_ipp)); 104611042SErik.Nordmark@Sun.COM } 10471676Sjpk 104811042SErik.Nordmark@Sun.COM static int 104911042SErik.Nordmark@Sun.COM sctp_v6_label(sctp_t *sctp, sctp_faddr_t *fp) 105011042SErik.Nordmark@Sun.COM { 105111042SErik.Nordmark@Sun.COM conn_t *connp = sctp->sctp_connp; 105211042SErik.Nordmark@Sun.COM 1053*13009SChandrasekar.Marimuthu@Sun.COM ASSERT(!(fp->sf_ixa->ixa_flags & IXAF_IS_IPV4)); 1054*13009SChandrasekar.Marimuthu@Sun.COM return (conn_update_label(connp, fp->sf_ixa, &fp->sf_faddr, 105511042SErik.Nordmark@Sun.COM &connp->conn_xmit_ipp)); 10561676Sjpk } 10571676Sjpk 10580Sstevel@tonic-gate /* 10590Sstevel@tonic-gate * XXX implement more sophisticated logic 106011042SErik.Nordmark@Sun.COM * 106111042SErik.Nordmark@Sun.COM * Tsol note: We have already verified the addresses using tsol_check_dest 106211042SErik.Nordmark@Sun.COM * in sctp_add_faddr, thus no need to redo that here. 106311042SErik.Nordmark@Sun.COM * We do setup ipp_label_v4 and ipp_label_v6 based on which addresses 106411042SErik.Nordmark@Sun.COM * we have. 10650Sstevel@tonic-gate */ 10661676Sjpk int 10671735Skcpoon sctp_set_hdraddrs(sctp_t *sctp) 10680Sstevel@tonic-gate { 10690Sstevel@tonic-gate sctp_faddr_t *fp; 10700Sstevel@tonic-gate int gotv4 = 0; 10710Sstevel@tonic-gate int gotv6 = 0; 107211042SErik.Nordmark@Sun.COM conn_t *connp = sctp->sctp_connp; 10730Sstevel@tonic-gate 10740Sstevel@tonic-gate ASSERT(sctp->sctp_faddrs != NULL); 10750Sstevel@tonic-gate ASSERT(sctp->sctp_nsaddrs > 0); 10760Sstevel@tonic-gate 10770Sstevel@tonic-gate /* Set up using the primary first */ 1078*13009SChandrasekar.Marimuthu@Sun.COM connp->conn_faddr_v6 = sctp->sctp_primary->sf_faddr; 107911042SErik.Nordmark@Sun.COM /* saddr may be unspec; make_mp() will handle this */ 1080*13009SChandrasekar.Marimuthu@Sun.COM connp->conn_saddr_v6 = sctp->sctp_primary->sf_saddr; 108111042SErik.Nordmark@Sun.COM connp->conn_laddr_v6 = connp->conn_saddr_v6; 1082*13009SChandrasekar.Marimuthu@Sun.COM if (IN6_IS_ADDR_V4MAPPED(&sctp->sctp_primary->sf_faddr)) { 108311042SErik.Nordmark@Sun.COM if (!is_system_labeled() || 108411042SErik.Nordmark@Sun.COM sctp_v4_label(sctp, sctp->sctp_primary) == 0) { 10851676Sjpk gotv4 = 1; 108611042SErik.Nordmark@Sun.COM if (connp->conn_family == AF_INET) { 108711042SErik.Nordmark@Sun.COM goto done; 10881676Sjpk } 10890Sstevel@tonic-gate } 10900Sstevel@tonic-gate } else { 109111042SErik.Nordmark@Sun.COM if (!is_system_labeled() || 109211042SErik.Nordmark@Sun.COM sctp_v6_label(sctp, sctp->sctp_primary) == 0) { 10931676Sjpk gotv6 = 1; 109411042SErik.Nordmark@Sun.COM } 10950Sstevel@tonic-gate } 10960Sstevel@tonic-gate 1097*13009SChandrasekar.Marimuthu@Sun.COM for (fp = sctp->sctp_faddrs; fp; fp = fp->sf_next) { 1098*13009SChandrasekar.Marimuthu@Sun.COM if (!gotv4 && IN6_IS_ADDR_V4MAPPED(&fp->sf_faddr)) { 109911042SErik.Nordmark@Sun.COM if (!is_system_labeled() || 110011042SErik.Nordmark@Sun.COM sctp_v4_label(sctp, fp) == 0) { 11011676Sjpk gotv4 = 1; 110211042SErik.Nordmark@Sun.COM if (connp->conn_family == AF_INET || gotv6) { 11031676Sjpk break; 11041676Sjpk } 11050Sstevel@tonic-gate } 1106*13009SChandrasekar.Marimuthu@Sun.COM } else if (!gotv6 && !IN6_IS_ADDR_V4MAPPED(&fp->sf_faddr)) { 110711042SErik.Nordmark@Sun.COM if (!is_system_labeled() || 110811042SErik.Nordmark@Sun.COM sctp_v6_label(sctp, fp) == 0) { 11091676Sjpk gotv6 = 1; 11101676Sjpk if (gotv4) 11111676Sjpk break; 11120Sstevel@tonic-gate } 11130Sstevel@tonic-gate } 11140Sstevel@tonic-gate } 11150Sstevel@tonic-gate 111611042SErik.Nordmark@Sun.COM done: 11171676Sjpk if (!gotv4 && !gotv6) 11181676Sjpk return (EACCES); 11191676Sjpk 11201676Sjpk return (0); 11210Sstevel@tonic-gate } 11220Sstevel@tonic-gate 11238549SGeorge.Shepherd@Sun.COM /* 11248549SGeorge.Shepherd@Sun.COM * got_errchunk is set B_TRUE only if called from validate_init_params(), when 11258549SGeorge.Shepherd@Sun.COM * an ERROR chunk is already prepended the size of which needs updating for 11268549SGeorge.Shepherd@Sun.COM * additional unrecognized parameters. Other callers either prepend the ERROR 11278549SGeorge.Shepherd@Sun.COM * chunk with the correct size after calling this function, or they are calling 11288549SGeorge.Shepherd@Sun.COM * to add an invalid parameter to an INIT_ACK chunk, in that case no ERROR chunk 11298549SGeorge.Shepherd@Sun.COM * exists, the CAUSE blocks go into the INIT_ACK directly. 11308549SGeorge.Shepherd@Sun.COM * 11318549SGeorge.Shepherd@Sun.COM * *errmp will be non-NULL both when adding an additional CAUSE block to an 11328549SGeorge.Shepherd@Sun.COM * existing prepended COOKIE ERROR chunk (processing params of an INIT_ACK), 11338549SGeorge.Shepherd@Sun.COM * and when adding unrecognized parameters after the first, to an INIT_ACK 11348549SGeorge.Shepherd@Sun.COM * (processing params of an INIT chunk). 11358549SGeorge.Shepherd@Sun.COM */ 11360Sstevel@tonic-gate void 11378549SGeorge.Shepherd@Sun.COM sctp_add_unrec_parm(sctp_parm_hdr_t *uph, mblk_t **errmp, 11388549SGeorge.Shepherd@Sun.COM boolean_t got_errchunk) 11390Sstevel@tonic-gate { 11400Sstevel@tonic-gate mblk_t *mp; 11410Sstevel@tonic-gate sctp_parm_hdr_t *ph; 11420Sstevel@tonic-gate size_t len; 11430Sstevel@tonic-gate int pad; 11448153SGeorge.Shepherd@Sun.COM sctp_chunk_hdr_t *ecp; 11450Sstevel@tonic-gate 11460Sstevel@tonic-gate len = sizeof (*ph) + ntohs(uph->sph_len); 11478153SGeorge.Shepherd@Sun.COM if ((pad = len % SCTP_ALIGN) != 0) { 11488153SGeorge.Shepherd@Sun.COM pad = SCTP_ALIGN - pad; 11490Sstevel@tonic-gate len += pad; 11500Sstevel@tonic-gate } 11510Sstevel@tonic-gate mp = allocb(len, BPRI_MED); 11520Sstevel@tonic-gate if (mp == NULL) { 11530Sstevel@tonic-gate return; 11540Sstevel@tonic-gate } 11550Sstevel@tonic-gate 11560Sstevel@tonic-gate ph = (sctp_parm_hdr_t *)(mp->b_rptr); 11570Sstevel@tonic-gate ph->sph_type = htons(PARM_UNRECOGNIZED); 11580Sstevel@tonic-gate ph->sph_len = htons(len - pad); 11590Sstevel@tonic-gate 11600Sstevel@tonic-gate /* copy in the unrecognized parameter */ 11610Sstevel@tonic-gate bcopy(uph, ph + 1, ntohs(uph->sph_len)); 11620Sstevel@tonic-gate 11638153SGeorge.Shepherd@Sun.COM if (pad != 0) 11648153SGeorge.Shepherd@Sun.COM bzero((mp->b_rptr + len - pad), pad); 11658153SGeorge.Shepherd@Sun.COM 11660Sstevel@tonic-gate mp->b_wptr = mp->b_rptr + len; 11670Sstevel@tonic-gate if (*errmp != NULL) { 11688153SGeorge.Shepherd@Sun.COM /* 11698549SGeorge.Shepherd@Sun.COM * Update total length if an ERROR chunk, then link 11708549SGeorge.Shepherd@Sun.COM * this CAUSE block to the possible chain of CAUSE 11718549SGeorge.Shepherd@Sun.COM * blocks attached to the ERROR chunk or INIT_ACK 11728549SGeorge.Shepherd@Sun.COM * being created. 11738153SGeorge.Shepherd@Sun.COM */ 11748549SGeorge.Shepherd@Sun.COM if (got_errchunk) { 11758549SGeorge.Shepherd@Sun.COM /* ERROR chunk already prepended */ 11768549SGeorge.Shepherd@Sun.COM ecp = (sctp_chunk_hdr_t *)((*errmp)->b_rptr); 11778549SGeorge.Shepherd@Sun.COM ecp->sch_len = htons(ntohs(ecp->sch_len) + len); 11788549SGeorge.Shepherd@Sun.COM } 11790Sstevel@tonic-gate linkb(*errmp, mp); 11800Sstevel@tonic-gate } else { 11810Sstevel@tonic-gate *errmp = mp; 11820Sstevel@tonic-gate } 11830Sstevel@tonic-gate } 11840Sstevel@tonic-gate 11850Sstevel@tonic-gate /* 11860Sstevel@tonic-gate * o Bounds checking 11870Sstevel@tonic-gate * o Updates remaining 11880Sstevel@tonic-gate * o Checks alignment 11890Sstevel@tonic-gate */ 11900Sstevel@tonic-gate sctp_parm_hdr_t * 11910Sstevel@tonic-gate sctp_next_parm(sctp_parm_hdr_t *current, ssize_t *remaining) 11920Sstevel@tonic-gate { 11930Sstevel@tonic-gate int pad; 11940Sstevel@tonic-gate uint16_t len; 11950Sstevel@tonic-gate 11960Sstevel@tonic-gate len = ntohs(current->sph_len); 11970Sstevel@tonic-gate *remaining -= len; 11980Sstevel@tonic-gate if (*remaining < sizeof (*current) || len < sizeof (*current)) { 11990Sstevel@tonic-gate return (NULL); 12000Sstevel@tonic-gate } 12010Sstevel@tonic-gate if ((pad = len & (SCTP_ALIGN - 1)) != 0) { 12020Sstevel@tonic-gate pad = SCTP_ALIGN - pad; 12030Sstevel@tonic-gate *remaining -= pad; 12040Sstevel@tonic-gate } 12050Sstevel@tonic-gate /*LINTED pointer cast may result in improper alignment*/ 12060Sstevel@tonic-gate current = (sctp_parm_hdr_t *)((char *)current + len + pad); 12070Sstevel@tonic-gate return (current); 12080Sstevel@tonic-gate } 12090Sstevel@tonic-gate 12100Sstevel@tonic-gate /* 12110Sstevel@tonic-gate * Sets the address parameters given in the INIT chunk into sctp's 12120Sstevel@tonic-gate * faddrs; if psctp is non-NULL, copies psctp's saddrs. If there are 12130Sstevel@tonic-gate * no address parameters in the INIT chunk, a single faddr is created 12140Sstevel@tonic-gate * from the ip hdr at the beginning of pkt. 12150Sstevel@tonic-gate * If there already are existing addresses hanging from sctp, merge 12160Sstevel@tonic-gate * them in, if the old info contains addresses which are not present 12170Sstevel@tonic-gate * in this new info, get rid of them, and clean the pointers if there's 12180Sstevel@tonic-gate * messages which have this as their target address. 12190Sstevel@tonic-gate * 1220432Svi117747 * We also re-adjust the source address list here since the list may 1221432Svi117747 * contain more than what is actually part of the association. If 1222432Svi117747 * we get here from sctp_send_cookie_echo(), we are on the active 1223432Svi117747 * side and psctp will be NULL and ich will be the INIT-ACK chunk. 1224432Svi117747 * If we get here from sctp_accept_comm(), ich will be the INIT chunk 1225432Svi117747 * and psctp will the listening endpoint. 1226432Svi117747 * 1227432Svi117747 * INIT processing: When processing the INIT we inherit the src address 1228432Svi117747 * list from the listener. For a loopback or linklocal association, we 1229432Svi117747 * delete the list and just take the address from the IP header (since 1230432Svi117747 * that's how we created the INIT-ACK). Additionally, for loopback we 1231432Svi117747 * ignore the address params in the INIT. For determining which address 1232432Svi117747 * types were sent in the INIT-ACK we follow the same logic as in 1233432Svi117747 * creating the INIT-ACK. We delete addresses of the type that are not 1234432Svi117747 * supported by the peer. 1235432Svi117747 * 1236432Svi117747 * INIT-ACK processing: When processing the INIT-ACK since we had not 1237432Svi117747 * included addr params for loopback or linklocal addresses when creating 1238432Svi117747 * the INIT, we just use the address from the IP header. Further, for 1239432Svi117747 * loopback we ignore the addr param list. We mark addresses of the 1240432Svi117747 * type not supported by the peer as unconfirmed. 1241432Svi117747 * 1242432Svi117747 * In case of INIT processing we look for supported address types in the 1243432Svi117747 * supported address param, if present. In both cases the address type in 1244432Svi117747 * the IP header is supported as well as types for addresses in the param 1245432Svi117747 * list, if any. 1246432Svi117747 * 1247432Svi117747 * Once we have the supported address types sctp_check_saddr() runs through 1248432Svi117747 * the source address list and deletes or marks as unconfirmed address of 1249432Svi117747 * types not supported by the peer. 1250432Svi117747 * 12510Sstevel@tonic-gate * Returns 0 on success, sys errno on failure 12520Sstevel@tonic-gate */ 12530Sstevel@tonic-gate int 12540Sstevel@tonic-gate sctp_get_addrparams(sctp_t *sctp, sctp_t *psctp, mblk_t *pkt, 12550Sstevel@tonic-gate sctp_chunk_hdr_t *ich, uint_t *sctp_options) 12560Sstevel@tonic-gate { 12570Sstevel@tonic-gate sctp_init_chunk_t *init; 12580Sstevel@tonic-gate ipha_t *iph; 12590Sstevel@tonic-gate ip6_t *ip6h; 1260432Svi117747 in6_addr_t hdrsaddr[1]; 1261432Svi117747 in6_addr_t hdrdaddr[1]; 12620Sstevel@tonic-gate sctp_parm_hdr_t *ph; 12630Sstevel@tonic-gate ssize_t remaining; 12640Sstevel@tonic-gate int isv4; 12650Sstevel@tonic-gate int err; 12660Sstevel@tonic-gate sctp_faddr_t *fp; 1267432Svi117747 int supp_af = 0; 1268432Svi117747 boolean_t check_saddr = B_TRUE; 1269852Svi117747 in6_addr_t curaddr; 12703448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 127111042SErik.Nordmark@Sun.COM conn_t *connp = sctp->sctp_connp; 12720Sstevel@tonic-gate 12730Sstevel@tonic-gate if (sctp_options != NULL) 12740Sstevel@tonic-gate *sctp_options = 0; 12750Sstevel@tonic-gate 1276432Svi117747 /* extract the address from the IP header */ 1277432Svi117747 isv4 = (IPH_HDR_VERSION(pkt->b_rptr) == IPV4_VERSION); 1278432Svi117747 if (isv4) { 1279432Svi117747 iph = (ipha_t *)pkt->b_rptr; 1280432Svi117747 IN6_IPADDR_TO_V4MAPPED(iph->ipha_src, hdrsaddr); 1281432Svi117747 IN6_IPADDR_TO_V4MAPPED(iph->ipha_dst, hdrdaddr); 1282432Svi117747 supp_af |= PARM_SUPP_V4; 1283432Svi117747 } else { 1284432Svi117747 ip6h = (ip6_t *)pkt->b_rptr; 1285432Svi117747 hdrsaddr[0] = ip6h->ip6_src; 1286432Svi117747 hdrdaddr[0] = ip6h->ip6_dst; 1287432Svi117747 supp_af |= PARM_SUPP_V6; 1288432Svi117747 } 1289432Svi117747 1290432Svi117747 /* 1291432Svi117747 * Unfortunately, we can't delay this because adding an faddr 1292432Svi117747 * looks for the presence of the source address (from the ire 1293432Svi117747 * for the faddr) in the source address list. We could have 1294432Svi117747 * delayed this if, say, this was a loopback/linklocal connection. 1295432Svi117747 * Now, we just end up nuking this list and taking the addr from 1296432Svi117747 * the IP header for loopback/linklocal. 1297432Svi117747 */ 12980Sstevel@tonic-gate if (psctp != NULL && psctp->sctp_nsaddrs > 0) { 12990Sstevel@tonic-gate ASSERT(sctp->sctp_nsaddrs == 0); 13000Sstevel@tonic-gate 13010Sstevel@tonic-gate err = sctp_dup_saddrs(psctp, sctp, KM_NOSLEEP); 13020Sstevel@tonic-gate if (err != 0) 13030Sstevel@tonic-gate return (err); 13040Sstevel@tonic-gate } 1305432Svi117747 /* 1306432Svi117747 * We will add the faddr before parsing the address list as this 1307432Svi117747 * might be a loopback connection and we would not have to 1308432Svi117747 * go through the list. 1309432Svi117747 * 1310432Svi117747 * Make sure the header's addr is in the list 1311432Svi117747 */ 1312432Svi117747 fp = sctp_lookup_faddr(sctp, hdrsaddr); 1313432Svi117747 if (fp == NULL) { 1314432Svi117747 /* not included; add it now */ 13151735Skcpoon err = sctp_add_faddr(sctp, hdrsaddr, KM_NOSLEEP, B_TRUE); 13161676Sjpk if (err != 0) 13171676Sjpk return (err); 13180Sstevel@tonic-gate 1319432Svi117747 /* sctp_faddrs will be the hdr addr */ 1320432Svi117747 fp = sctp->sctp_faddrs; 13210Sstevel@tonic-gate } 1322432Svi117747 /* make the header addr the primary */ 1323852Svi117747 1324852Svi117747 if (cl_sctp_assoc_change != NULL && psctp == NULL) 1325*13009SChandrasekar.Marimuthu@Sun.COM curaddr = sctp->sctp_current->sf_faddr; 1326852Svi117747 1327432Svi117747 sctp->sctp_primary = fp; 1328432Svi117747 sctp->sctp_current = fp; 1329*13009SChandrasekar.Marimuthu@Sun.COM sctp->sctp_mss = fp->sf_pmss; 13300Sstevel@tonic-gate 1331432Svi117747 /* For loopback connections & linklocal get address from the header */ 1332432Svi117747 if (sctp->sctp_loopback || sctp->sctp_linklocal) { 1333432Svi117747 if (sctp->sctp_nsaddrs != 0) 1334432Svi117747 sctp_free_saddrs(sctp); 1335852Svi117747 if ((err = sctp_saddr_add_addr(sctp, hdrdaddr, 0)) != 0) 1336432Svi117747 return (err); 1337432Svi117747 /* For loopback ignore address list */ 1338432Svi117747 if (sctp->sctp_loopback) 1339432Svi117747 return (0); 1340432Svi117747 check_saddr = B_FALSE; 1341432Svi117747 } 13420Sstevel@tonic-gate 13430Sstevel@tonic-gate /* Walk the params in the INIT [ACK], pulling out addr params */ 13440Sstevel@tonic-gate remaining = ntohs(ich->sch_len) - sizeof (*ich) - 13450Sstevel@tonic-gate sizeof (sctp_init_chunk_t); 13460Sstevel@tonic-gate if (remaining < sizeof (*ph)) { 1347432Svi117747 if (check_saddr) { 1348432Svi117747 sctp_check_saddr(sctp, supp_af, psctp == NULL ? 13494818Skcpoon B_FALSE : B_TRUE, hdrdaddr); 1350432Svi117747 } 1351852Svi117747 ASSERT(sctp_saddr_lookup(sctp, hdrdaddr, 0) != NULL); 1352432Svi117747 return (0); 13530Sstevel@tonic-gate } 1354432Svi117747 13550Sstevel@tonic-gate init = (sctp_init_chunk_t *)(ich + 1); 13560Sstevel@tonic-gate ph = (sctp_parm_hdr_t *)(init + 1); 13570Sstevel@tonic-gate 1358432Svi117747 /* params will have already been byteordered when validating */ 13590Sstevel@tonic-gate while (ph != NULL) { 1360432Svi117747 if (ph->sph_type == htons(PARM_SUPP_ADDRS)) { 1361432Svi117747 int plen; 1362432Svi117747 uint16_t *p; 1363432Svi117747 uint16_t addrtype; 1364432Svi117747 1365432Svi117747 ASSERT(psctp != NULL); 1366432Svi117747 plen = ntohs(ph->sph_len); 1367432Svi117747 p = (uint16_t *)(ph + 1); 1368432Svi117747 while (plen > 0) { 1369432Svi117747 addrtype = ntohs(*p); 1370432Svi117747 switch (addrtype) { 1371432Svi117747 case PARM_ADDR6: 1372432Svi117747 supp_af |= PARM_SUPP_V6; 1373432Svi117747 break; 1374432Svi117747 case PARM_ADDR4: 1375432Svi117747 supp_af |= PARM_SUPP_V4; 1376432Svi117747 break; 1377432Svi117747 default: 1378432Svi117747 break; 1379432Svi117747 } 1380432Svi117747 p++; 1381432Svi117747 plen -= sizeof (*p); 1382432Svi117747 } 1383432Svi117747 } else if (ph->sph_type == htons(PARM_ADDR4)) { 13840Sstevel@tonic-gate if (remaining >= PARM_ADDR4_LEN) { 13850Sstevel@tonic-gate in6_addr_t addr; 13860Sstevel@tonic-gate ipaddr_t ta; 13870Sstevel@tonic-gate 1388432Svi117747 supp_af |= PARM_SUPP_V4; 13890Sstevel@tonic-gate /* 13900Sstevel@tonic-gate * Screen out broad/multicasts & loopback. 13910Sstevel@tonic-gate * If the endpoint only accepts v6 address, 13920Sstevel@tonic-gate * go to the next one. 13934818Skcpoon * 13944818Skcpoon * Subnet broadcast check is done in 13954818Skcpoon * sctp_add_faddr(). If the address is 13964818Skcpoon * a broadcast address, it won't be added. 13970Sstevel@tonic-gate */ 13980Sstevel@tonic-gate bcopy(ph + 1, &ta, sizeof (ta)); 13990Sstevel@tonic-gate if (ta == 0 || 14000Sstevel@tonic-gate ta == INADDR_BROADCAST || 14010Sstevel@tonic-gate ta == htonl(INADDR_LOOPBACK) || 140211042SErik.Nordmark@Sun.COM CLASSD(ta) || connp->conn_ipv6_v6only) { 14030Sstevel@tonic-gate goto next; 14040Sstevel@tonic-gate } 14050Sstevel@tonic-gate IN6_INADDR_TO_V4MAPPED((struct in_addr *) 14060Sstevel@tonic-gate (ph + 1), &addr); 14074818Skcpoon 14080Sstevel@tonic-gate /* Check for duplicate. */ 14090Sstevel@tonic-gate if (sctp_lookup_faddr(sctp, &addr) != NULL) 14100Sstevel@tonic-gate goto next; 14110Sstevel@tonic-gate 14120Sstevel@tonic-gate /* OK, add it to the faddr set */ 14131735Skcpoon err = sctp_add_faddr(sctp, &addr, KM_NOSLEEP, 14141735Skcpoon B_FALSE); 14154818Skcpoon /* Something is wrong... Try the next one. */ 14161676Sjpk if (err != 0) 14174818Skcpoon goto next; 14180Sstevel@tonic-gate } 14190Sstevel@tonic-gate } else if (ph->sph_type == htons(PARM_ADDR6) && 142011042SErik.Nordmark@Sun.COM connp->conn_family == AF_INET6) { 14210Sstevel@tonic-gate /* An v4 socket should not take v6 addresses. */ 14220Sstevel@tonic-gate if (remaining >= PARM_ADDR6_LEN) { 14230Sstevel@tonic-gate in6_addr_t *addr6; 14240Sstevel@tonic-gate 1425432Svi117747 supp_af |= PARM_SUPP_V6; 14260Sstevel@tonic-gate addr6 = (in6_addr_t *)(ph + 1); 14270Sstevel@tonic-gate /* 14280Sstevel@tonic-gate * Screen out link locals, mcast, loopback 14290Sstevel@tonic-gate * and bogus v6 address. 14300Sstevel@tonic-gate */ 14310Sstevel@tonic-gate if (IN6_IS_ADDR_LINKLOCAL(addr6) || 14320Sstevel@tonic-gate IN6_IS_ADDR_MULTICAST(addr6) || 14330Sstevel@tonic-gate IN6_IS_ADDR_LOOPBACK(addr6) || 14340Sstevel@tonic-gate IN6_IS_ADDR_V4MAPPED(addr6)) { 14350Sstevel@tonic-gate goto next; 14360Sstevel@tonic-gate } 14370Sstevel@tonic-gate /* Check for duplicate. */ 14380Sstevel@tonic-gate if (sctp_lookup_faddr(sctp, addr6) != NULL) 14390Sstevel@tonic-gate goto next; 14400Sstevel@tonic-gate 14411676Sjpk err = sctp_add_faddr(sctp, 14421735Skcpoon (in6_addr_t *)(ph + 1), KM_NOSLEEP, 14431735Skcpoon B_FALSE); 14444818Skcpoon /* Something is wrong... Try the next one. */ 14451676Sjpk if (err != 0) 14464818Skcpoon goto next; 14470Sstevel@tonic-gate } 14480Sstevel@tonic-gate } else if (ph->sph_type == htons(PARM_FORWARD_TSN)) { 14490Sstevel@tonic-gate if (sctp_options != NULL) 14500Sstevel@tonic-gate *sctp_options |= SCTP_PRSCTP_OPTION; 14510Sstevel@tonic-gate } /* else; skip */ 14520Sstevel@tonic-gate 14530Sstevel@tonic-gate next: 14540Sstevel@tonic-gate ph = sctp_next_parm(ph, &remaining); 14550Sstevel@tonic-gate } 1456432Svi117747 if (check_saddr) { 1457432Svi117747 sctp_check_saddr(sctp, supp_af, psctp == NULL ? B_FALSE : 14584818Skcpoon B_TRUE, hdrdaddr); 14590Sstevel@tonic-gate } 1460852Svi117747 ASSERT(sctp_saddr_lookup(sctp, hdrdaddr, 0) != NULL); 1461852Svi117747 /* 1462852Svi117747 * We have the right address list now, update clustering's 1463852Svi117747 * knowledge because when we sent the INIT we had just added 1464852Svi117747 * the address the INIT was sent to. 1465852Svi117747 */ 1466852Svi117747 if (psctp == NULL && cl_sctp_assoc_change != NULL) { 1467852Svi117747 uchar_t *alist; 1468852Svi117747 size_t asize; 1469852Svi117747 uchar_t *dlist; 1470852Svi117747 size_t dsize; 1471852Svi117747 1472852Svi117747 asize = sizeof (in6_addr_t) * sctp->sctp_nfaddrs; 1473852Svi117747 alist = kmem_alloc(asize, KM_NOSLEEP); 14741735Skcpoon if (alist == NULL) { 14753448Sdh155122 SCTP_KSTAT(sctps, sctp_cl_assoc_change); 1476852Svi117747 return (ENOMEM); 14771735Skcpoon } 1478852Svi117747 /* 1479852Svi117747 * Just include the address the INIT was sent to in the 1480852Svi117747 * delete list and send the entire faddr list. We could 1481852Svi117747 * do it differently (i.e include all the addresses in the 1482852Svi117747 * add list even if it contains the original address OR 1483852Svi117747 * remove the original address from the add list etc.), but 1484852Svi117747 * this seems reasonable enough. 1485852Svi117747 */ 1486852Svi117747 dsize = sizeof (in6_addr_t); 1487852Svi117747 dlist = kmem_alloc(dsize, KM_NOSLEEP); 1488852Svi117747 if (dlist == NULL) { 1489852Svi117747 kmem_free(alist, asize); 14903448Sdh155122 SCTP_KSTAT(sctps, sctp_cl_assoc_change); 1491852Svi117747 return (ENOMEM); 1492852Svi117747 } 1493852Svi117747 bcopy(&curaddr, dlist, sizeof (curaddr)); 1494852Svi117747 sctp_get_faddr_list(sctp, alist, asize); 149511042SErik.Nordmark@Sun.COM (*cl_sctp_assoc_change)(connp->conn_family, alist, asize, 1496852Svi117747 sctp->sctp_nfaddrs, dlist, dsize, 1, SCTP_CL_PADDR, 1497852Svi117747 (cl_sctp_handle_t)sctp); 1498852Svi117747 /* alist and dlist will be freed by the clustering module */ 1499852Svi117747 } 15000Sstevel@tonic-gate return (0); 15010Sstevel@tonic-gate } 15020Sstevel@tonic-gate 15030Sstevel@tonic-gate /* 15040Sstevel@tonic-gate * Returns 0 if the check failed and the restart should be refused, 15050Sstevel@tonic-gate * 1 if the check succeeded. 15060Sstevel@tonic-gate */ 15070Sstevel@tonic-gate int 15080Sstevel@tonic-gate sctp_secure_restart_check(mblk_t *pkt, sctp_chunk_hdr_t *ich, uint32_t ports, 150911042SErik.Nordmark@Sun.COM int sleep, sctp_stack_t *sctps, ip_recv_attr_t *ira) 15100Sstevel@tonic-gate { 15114964Skcpoon sctp_faddr_t *fp, *fphead = NULL; 15120Sstevel@tonic-gate sctp_parm_hdr_t *ph; 15130Sstevel@tonic-gate ssize_t remaining; 15140Sstevel@tonic-gate int isv4; 15150Sstevel@tonic-gate ipha_t *iph; 15160Sstevel@tonic-gate ip6_t *ip6h; 15170Sstevel@tonic-gate in6_addr_t hdraddr[1]; 15180Sstevel@tonic-gate int retval = 0; 15190Sstevel@tonic-gate sctp_tf_t *tf; 15200Sstevel@tonic-gate sctp_t *sctp; 15210Sstevel@tonic-gate int compres; 15220Sstevel@tonic-gate sctp_init_chunk_t *init; 15230Sstevel@tonic-gate int nadded = 0; 15240Sstevel@tonic-gate 15250Sstevel@tonic-gate /* extract the address from the IP header */ 15260Sstevel@tonic-gate isv4 = (IPH_HDR_VERSION(pkt->b_rptr) == IPV4_VERSION); 15270Sstevel@tonic-gate if (isv4) { 15280Sstevel@tonic-gate iph = (ipha_t *)pkt->b_rptr; 15290Sstevel@tonic-gate IN6_IPADDR_TO_V4MAPPED(iph->ipha_src, hdraddr); 15300Sstevel@tonic-gate } else { 15310Sstevel@tonic-gate ip6h = (ip6_t *)pkt->b_rptr; 15320Sstevel@tonic-gate hdraddr[0] = ip6h->ip6_src; 15330Sstevel@tonic-gate } 15340Sstevel@tonic-gate 15350Sstevel@tonic-gate /* Walk the params in the INIT [ACK], pulling out addr params */ 15360Sstevel@tonic-gate remaining = ntohs(ich->sch_len) - sizeof (*ich) - 15370Sstevel@tonic-gate sizeof (sctp_init_chunk_t); 15380Sstevel@tonic-gate if (remaining < sizeof (*ph)) { 15390Sstevel@tonic-gate /* no parameters; restart OK */ 15400Sstevel@tonic-gate return (1); 15410Sstevel@tonic-gate } 15420Sstevel@tonic-gate init = (sctp_init_chunk_t *)(ich + 1); 15430Sstevel@tonic-gate ph = (sctp_parm_hdr_t *)(init + 1); 15440Sstevel@tonic-gate 15450Sstevel@tonic-gate while (ph != NULL) { 15464964Skcpoon sctp_faddr_t *fpa = NULL; 15474964Skcpoon 15480Sstevel@tonic-gate /* params will have already been byteordered when validating */ 15490Sstevel@tonic-gate if (ph->sph_type == htons(PARM_ADDR4)) { 15500Sstevel@tonic-gate if (remaining >= PARM_ADDR4_LEN) { 15510Sstevel@tonic-gate in6_addr_t addr; 15520Sstevel@tonic-gate IN6_INADDR_TO_V4MAPPED((struct in_addr *) 15530Sstevel@tonic-gate (ph + 1), &addr); 15540Sstevel@tonic-gate fpa = kmem_cache_alloc(sctp_kmem_faddr_cache, 15550Sstevel@tonic-gate sleep); 15564964Skcpoon if (fpa == NULL) { 15570Sstevel@tonic-gate goto done; 15580Sstevel@tonic-gate } 15590Sstevel@tonic-gate bzero(fpa, sizeof (*fpa)); 1560*13009SChandrasekar.Marimuthu@Sun.COM fpa->sf_faddr = addr; 1561*13009SChandrasekar.Marimuthu@Sun.COM fpa->sf_next = NULL; 15620Sstevel@tonic-gate } 15630Sstevel@tonic-gate } else if (ph->sph_type == htons(PARM_ADDR6)) { 15640Sstevel@tonic-gate if (remaining >= PARM_ADDR6_LEN) { 15650Sstevel@tonic-gate fpa = kmem_cache_alloc(sctp_kmem_faddr_cache, 15660Sstevel@tonic-gate sleep); 15674964Skcpoon if (fpa == NULL) { 15680Sstevel@tonic-gate goto done; 15690Sstevel@tonic-gate } 15700Sstevel@tonic-gate bzero(fpa, sizeof (*fpa)); 1571*13009SChandrasekar.Marimuthu@Sun.COM bcopy(ph + 1, &fpa->sf_faddr, 1572*13009SChandrasekar.Marimuthu@Sun.COM sizeof (fpa->sf_faddr)); 1573*13009SChandrasekar.Marimuthu@Sun.COM fpa->sf_next = NULL; 15740Sstevel@tonic-gate } 15750Sstevel@tonic-gate } 15760Sstevel@tonic-gate /* link in the new addr, if it was an addr param */ 15774964Skcpoon if (fpa != NULL) { 15784964Skcpoon if (fphead == NULL) { 15790Sstevel@tonic-gate fphead = fpa; 15800Sstevel@tonic-gate } else { 1581*13009SChandrasekar.Marimuthu@Sun.COM fpa->sf_next = fphead; 15824964Skcpoon fphead = fpa; 15830Sstevel@tonic-gate } 15840Sstevel@tonic-gate } 15850Sstevel@tonic-gate 15860Sstevel@tonic-gate ph = sctp_next_parm(ph, &remaining); 15870Sstevel@tonic-gate } 15880Sstevel@tonic-gate 15890Sstevel@tonic-gate if (fphead == NULL) { 15900Sstevel@tonic-gate /* no addr parameters; restart OK */ 15910Sstevel@tonic-gate return (1); 15920Sstevel@tonic-gate } 15930Sstevel@tonic-gate 15940Sstevel@tonic-gate /* 15950Sstevel@tonic-gate * got at least one; make sure the header's addr is 15960Sstevel@tonic-gate * in the list 15970Sstevel@tonic-gate */ 15980Sstevel@tonic-gate fp = sctp_lookup_faddr_nosctp(fphead, hdraddr); 15994964Skcpoon if (fp == NULL) { 16000Sstevel@tonic-gate /* not included; add it now */ 16010Sstevel@tonic-gate fp = kmem_cache_alloc(sctp_kmem_faddr_cache, sleep); 16024964Skcpoon if (fp == NULL) { 16030Sstevel@tonic-gate goto done; 16040Sstevel@tonic-gate } 16050Sstevel@tonic-gate bzero(fp, sizeof (*fp)); 1606*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_faddr = *hdraddr; 1607*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_next = fphead; 16080Sstevel@tonic-gate fphead = fp; 16090Sstevel@tonic-gate } 16100Sstevel@tonic-gate 16110Sstevel@tonic-gate /* 16120Sstevel@tonic-gate * Now, we can finally do the check: For each sctp instance 16130Sstevel@tonic-gate * on the hash line for ports, compare its faddr set against 16140Sstevel@tonic-gate * the new one. If the new one is a strict subset of any 16150Sstevel@tonic-gate * existing sctp's faddrs, the restart is OK. However, if there 16160Sstevel@tonic-gate * is an overlap, this could be an attack, so return failure. 16170Sstevel@tonic-gate * If all sctp's faddrs are disjoint, this is a legitimate new 16180Sstevel@tonic-gate * association. 16190Sstevel@tonic-gate */ 16203448Sdh155122 tf = &(sctps->sctps_conn_fanout[SCTP_CONN_HASH(sctps, ports)]); 16210Sstevel@tonic-gate mutex_enter(&tf->tf_lock); 16220Sstevel@tonic-gate 16230Sstevel@tonic-gate for (sctp = tf->tf_sctp; sctp; sctp = sctp->sctp_conn_hash_next) { 162411042SErik.Nordmark@Sun.COM if (ports != sctp->sctp_connp->conn_ports) { 16250Sstevel@tonic-gate continue; 16260Sstevel@tonic-gate } 16270Sstevel@tonic-gate compres = sctp_compare_faddrsets(fphead, sctp->sctp_faddrs); 16280Sstevel@tonic-gate if (compres <= SCTP_ADDR_SUBSET) { 16290Sstevel@tonic-gate retval = 1; 16300Sstevel@tonic-gate mutex_exit(&tf->tf_lock); 16310Sstevel@tonic-gate goto done; 16320Sstevel@tonic-gate } 16330Sstevel@tonic-gate if (compres == SCTP_ADDR_OVERLAP) { 16340Sstevel@tonic-gate dprint(1, 16350Sstevel@tonic-gate ("new assoc from %x:%x:%x:%x overlaps with %p\n", 16361676Sjpk SCTP_PRINTADDR(*hdraddr), (void *)sctp)); 16370Sstevel@tonic-gate /* 16380Sstevel@tonic-gate * While we still hold the lock, we need to 16390Sstevel@tonic-gate * figure out which addresses have been 16400Sstevel@tonic-gate * added so we can include them in the abort 16410Sstevel@tonic-gate * we will send back. Since these faddrs will 16420Sstevel@tonic-gate * never be used, we overload the rto field 16430Sstevel@tonic-gate * here, setting it to 0 if the address was 16440Sstevel@tonic-gate * not added, 1 if it was added. 16450Sstevel@tonic-gate */ 1646*13009SChandrasekar.Marimuthu@Sun.COM for (fp = fphead; fp; fp = fp->sf_next) { 1647*13009SChandrasekar.Marimuthu@Sun.COM if (sctp_lookup_faddr(sctp, &fp->sf_faddr)) { 1648*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_rto = 0; 16490Sstevel@tonic-gate } else { 1650*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_rto = 1; 16510Sstevel@tonic-gate nadded++; 16520Sstevel@tonic-gate } 16530Sstevel@tonic-gate } 16540Sstevel@tonic-gate mutex_exit(&tf->tf_lock); 16550Sstevel@tonic-gate goto done; 16560Sstevel@tonic-gate } 16570Sstevel@tonic-gate } 16580Sstevel@tonic-gate mutex_exit(&tf->tf_lock); 16590Sstevel@tonic-gate 16600Sstevel@tonic-gate /* All faddrs are disjoint; legit new association */ 16610Sstevel@tonic-gate retval = 1; 16620Sstevel@tonic-gate 16630Sstevel@tonic-gate done: 16640Sstevel@tonic-gate /* If are attempted adds, send back an abort listing the addrs */ 16650Sstevel@tonic-gate if (nadded > 0) { 16660Sstevel@tonic-gate void *dtail; 16670Sstevel@tonic-gate size_t dlen; 16680Sstevel@tonic-gate 16690Sstevel@tonic-gate dtail = kmem_alloc(PARM_ADDR6_LEN * nadded, KM_NOSLEEP); 16700Sstevel@tonic-gate if (dtail == NULL) { 16710Sstevel@tonic-gate goto cleanup; 16720Sstevel@tonic-gate } 16730Sstevel@tonic-gate 16740Sstevel@tonic-gate ph = dtail; 16750Sstevel@tonic-gate dlen = 0; 1676*13009SChandrasekar.Marimuthu@Sun.COM for (fp = fphead; fp; fp = fp->sf_next) { 1677*13009SChandrasekar.Marimuthu@Sun.COM if (fp->sf_rto == 0) { 16780Sstevel@tonic-gate continue; 16790Sstevel@tonic-gate } 1680*13009SChandrasekar.Marimuthu@Sun.COM if (IN6_IS_ADDR_V4MAPPED(&fp->sf_faddr)) { 16810Sstevel@tonic-gate ipaddr_t addr4; 16820Sstevel@tonic-gate 16830Sstevel@tonic-gate ph->sph_type = htons(PARM_ADDR4); 16840Sstevel@tonic-gate ph->sph_len = htons(PARM_ADDR4_LEN); 1685*13009SChandrasekar.Marimuthu@Sun.COM IN6_V4MAPPED_TO_IPADDR(&fp->sf_faddr, addr4); 16860Sstevel@tonic-gate ph++; 16870Sstevel@tonic-gate bcopy(&addr4, ph, sizeof (addr4)); 16880Sstevel@tonic-gate ph = (sctp_parm_hdr_t *) 16890Sstevel@tonic-gate ((char *)ph + sizeof (addr4)); 16900Sstevel@tonic-gate dlen += PARM_ADDR4_LEN; 16910Sstevel@tonic-gate } else { 16920Sstevel@tonic-gate ph->sph_type = htons(PARM_ADDR6); 16930Sstevel@tonic-gate ph->sph_len = htons(PARM_ADDR6_LEN); 16940Sstevel@tonic-gate ph++; 1695*13009SChandrasekar.Marimuthu@Sun.COM bcopy(&fp->sf_faddr, ph, sizeof (fp->sf_faddr)); 16960Sstevel@tonic-gate ph = (sctp_parm_hdr_t *) 1697*13009SChandrasekar.Marimuthu@Sun.COM ((char *)ph + sizeof (fp->sf_faddr)); 16980Sstevel@tonic-gate dlen += PARM_ADDR6_LEN; 16990Sstevel@tonic-gate } 17000Sstevel@tonic-gate } 17010Sstevel@tonic-gate 17020Sstevel@tonic-gate /* Send off the abort */ 17030Sstevel@tonic-gate sctp_send_abort(sctp, sctp_init2vtag(ich), 170411042SErik.Nordmark@Sun.COM SCTP_ERR_RESTART_NEW_ADDRS, dtail, dlen, pkt, 0, B_TRUE, 170511042SErik.Nordmark@Sun.COM ira); 17060Sstevel@tonic-gate 17070Sstevel@tonic-gate kmem_free(dtail, PARM_ADDR6_LEN * nadded); 17080Sstevel@tonic-gate } 17090Sstevel@tonic-gate 17100Sstevel@tonic-gate cleanup: 17110Sstevel@tonic-gate /* Clean up */ 17120Sstevel@tonic-gate if (fphead) { 17130Sstevel@tonic-gate sctp_faddr_t *fpn; 17140Sstevel@tonic-gate for (fp = fphead; fp; fp = fpn) { 1715*13009SChandrasekar.Marimuthu@Sun.COM fpn = fp->sf_next; 1716*13009SChandrasekar.Marimuthu@Sun.COM if (fp->sf_ixa != NULL) { 1717*13009SChandrasekar.Marimuthu@Sun.COM ixa_refrele(fp->sf_ixa); 1718*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_ixa = NULL; 171911042SErik.Nordmark@Sun.COM } 17200Sstevel@tonic-gate kmem_cache_free(sctp_kmem_faddr_cache, fp); 17210Sstevel@tonic-gate } 17220Sstevel@tonic-gate } 17230Sstevel@tonic-gate 17240Sstevel@tonic-gate return (retval); 17250Sstevel@tonic-gate } 17260Sstevel@tonic-gate 17271932Svi117747 /* 17281932Svi117747 * Reset any state related to transmitted chunks. 17291932Svi117747 */ 17300Sstevel@tonic-gate void 17310Sstevel@tonic-gate sctp_congest_reset(sctp_t *sctp) 17320Sstevel@tonic-gate { 17331932Svi117747 sctp_faddr_t *fp; 17343448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 17351932Svi117747 mblk_t *mp; 17360Sstevel@tonic-gate 1737*13009SChandrasekar.Marimuthu@Sun.COM for (fp = sctp->sctp_faddrs; fp != NULL; fp = fp->sf_next) { 1738*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_ssthresh = sctps->sctps_initial_mtu; 1739*13009SChandrasekar.Marimuthu@Sun.COM SET_CWND(fp, fp->sf_pmss, sctps->sctps_slow_start_initial); 1740*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_suna = 0; 1741*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_pba = 0; 17420Sstevel@tonic-gate } 17431932Svi117747 /* 17441932Svi117747 * Clean up the transmit list as well since we have reset accounting 17451932Svi117747 * on all the fps. Send event upstream, if required. 17461932Svi117747 */ 17471932Svi117747 while ((mp = sctp->sctp_xmit_head) != NULL) { 17481932Svi117747 sctp->sctp_xmit_head = mp->b_next; 17491932Svi117747 mp->b_next = NULL; 17501932Svi117747 if (sctp->sctp_xmit_head != NULL) 17511932Svi117747 sctp->sctp_xmit_head->b_prev = NULL; 17521932Svi117747 sctp_sendfail_event(sctp, mp, 0, B_TRUE); 17531932Svi117747 } 17541932Svi117747 sctp->sctp_xmit_head = NULL; 17551932Svi117747 sctp->sctp_xmit_tail = NULL; 17561932Svi117747 sctp->sctp_xmit_unacked = NULL; 17571932Svi117747 17581932Svi117747 sctp->sctp_unacked = 0; 17591932Svi117747 /* 17601932Svi117747 * Any control message as well. We will clean-up this list as well. 17611932Svi117747 * This contains any pending ASCONF request that we have queued/sent. 17621932Svi117747 * If we do get an ACK we will just drop it. However, given that 17631932Svi117747 * we are restarting chances are we aren't going to get any. 17641932Svi117747 */ 17651932Svi117747 if (sctp->sctp_cxmit_list != NULL) 17661932Svi117747 sctp_asconf_free_cxmit(sctp, NULL); 17671932Svi117747 sctp->sctp_cxmit_list = NULL; 17681932Svi117747 sctp->sctp_cchunk_pend = 0; 17691932Svi117747 17701932Svi117747 sctp->sctp_rexmitting = B_FALSE; 17711932Svi117747 sctp->sctp_rxt_nxttsn = 0; 17721932Svi117747 sctp->sctp_rxt_maxtsn = 0; 17731932Svi117747 17741932Svi117747 sctp->sctp_zero_win_probe = B_FALSE; 17750Sstevel@tonic-gate } 17760Sstevel@tonic-gate 17770Sstevel@tonic-gate static void 17781735Skcpoon sctp_init_faddr(sctp_t *sctp, sctp_faddr_t *fp, in6_addr_t *addr, 17791735Skcpoon mblk_t *timer_mp) 17800Sstevel@tonic-gate { 17813448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 17823448Sdh155122 1783*13009SChandrasekar.Marimuthu@Sun.COM ASSERT(fp->sf_ixa != NULL); 178411042SErik.Nordmark@Sun.COM 1785*13009SChandrasekar.Marimuthu@Sun.COM bcopy(addr, &fp->sf_faddr, sizeof (*addr)); 17860Sstevel@tonic-gate if (IN6_IS_ADDR_V4MAPPED(addr)) { 1787*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_isv4 = 1; 1788*13009SChandrasekar.Marimuthu@Sun.COM /* Make sure that sf_pmss is a multiple of SCTP_ALIGN. */ 1789*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_pmss = 17904691Skcpoon (sctps->sctps_initial_mtu - sctp->sctp_hdr_len) & 17914691Skcpoon ~(SCTP_ALIGN - 1); 1792*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_ixa->ixa_flags |= IXAF_IS_IPV4; 17930Sstevel@tonic-gate } else { 1794*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_isv4 = 0; 1795*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_pmss = 17963448Sdh155122 (sctps->sctps_initial_mtu - sctp->sctp_hdr6_len) & 17973448Sdh155122 ~(SCTP_ALIGN - 1); 1798*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_ixa->ixa_flags &= ~IXAF_IS_IPV4; 17990Sstevel@tonic-gate } 1800*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_cwnd = sctps->sctps_slow_start_initial * fp->sf_pmss; 1801*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_rto = MIN(sctp->sctp_rto_initial, sctp->sctp_rto_max_init); 180210212SGeorge.Shepherd@Sun.COM SCTP_MAX_RTO(sctp, fp); 1803*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_srtt = -1; 1804*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_rtt_updates = 0; 1805*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_strikes = 0; 1806*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_max_retr = sctp->sctp_pp_max_rxt; 18070Sstevel@tonic-gate /* Mark it as not confirmed. */ 1808*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_state = SCTP_FADDRS_UNCONFIRMED; 1809*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_hb_interval = sctp->sctp_hb_interval; 1810*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_ssthresh = sctps->sctps_initial_ssthresh; 1811*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_suna = 0; 1812*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_pba = 0; 1813*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_acked = 0; 1814*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_lastactive = fp->sf_hb_expiry = ddi_get_lbolt64(); 1815*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_timer_mp = timer_mp; 1816*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_hb_pending = B_FALSE; 1817*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_hb_enabled = B_TRUE; 1818*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_df = 1; 1819*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_pmtu_discovered = 0; 1820*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_next = NULL; 1821*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_T3expire = 0; 1822*13009SChandrasekar.Marimuthu@Sun.COM (void) random_get_pseudo_bytes((uint8_t *)&fp->sf_hb_secret, 1823*13009SChandrasekar.Marimuthu@Sun.COM sizeof (fp->sf_hb_secret)); 1824*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_rxt_unacked = 0; 18250Sstevel@tonic-gate 182611042SErik.Nordmark@Sun.COM sctp_get_dest(sctp, fp); 18270Sstevel@tonic-gate } 18280Sstevel@tonic-gate 18290Sstevel@tonic-gate /*ARGSUSED*/ 18306712Stomee static int 18316712Stomee faddr_constructor(void *buf, void *arg, int flags) 18326712Stomee { 18336712Stomee sctp_faddr_t *fp = buf; 18346712Stomee 1835*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_timer_mp = NULL; 1836*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_timer_running = 0; 18376712Stomee 1838*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_rc_timer_mp = NULL; 1839*13009SChandrasekar.Marimuthu@Sun.COM fp->sf_rc_timer_running = 0; 18406712Stomee 18416712Stomee return (0); 18426712Stomee } 18436712Stomee 18446712Stomee /*ARGSUSED*/ 18450Sstevel@tonic-gate static void 18466712Stomee faddr_destructor(void *buf, void *arg) 18470Sstevel@tonic-gate { 18480Sstevel@tonic-gate sctp_faddr_t *fp = buf; 18490Sstevel@tonic-gate 1850*13009SChandrasekar.Marimuthu@Sun.COM ASSERT(fp->sf_timer_mp == NULL); 1851*13009SChandrasekar.Marimuthu@Sun.COM ASSERT(fp->sf_timer_running == 0); 18520Sstevel@tonic-gate 1853*13009SChandrasekar.Marimuthu@Sun.COM ASSERT(fp->sf_rc_timer_mp == NULL); 1854*13009SChandrasekar.Marimuthu@Sun.COM ASSERT(fp->sf_rc_timer_running == 0); 18550Sstevel@tonic-gate } 18560Sstevel@tonic-gate 18570Sstevel@tonic-gate void 18581676Sjpk sctp_faddr_init(void) 18590Sstevel@tonic-gate { 18600Sstevel@tonic-gate sctp_kmem_faddr_cache = kmem_cache_create("sctp_faddr_cache", 18616712Stomee sizeof (sctp_faddr_t), 0, faddr_constructor, faddr_destructor, 18620Sstevel@tonic-gate NULL, NULL, NULL, 0); 18630Sstevel@tonic-gate } 18640Sstevel@tonic-gate 18650Sstevel@tonic-gate void 18661676Sjpk sctp_faddr_fini(void) 18670Sstevel@tonic-gate { 18680Sstevel@tonic-gate kmem_cache_destroy(sctp_kmem_faddr_cache); 18690Sstevel@tonic-gate } 1870