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 /* 238549SGeorge.Shepherd@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #include <sys/types.h> 280Sstevel@tonic-gate #include <sys/systm.h> 290Sstevel@tonic-gate #include <sys/stream.h> 301676Sjpk #include <sys/strsubr.h> 310Sstevel@tonic-gate #include <sys/ddi.h> 320Sstevel@tonic-gate #include <sys/sunddi.h> 330Sstevel@tonic-gate #include <sys/kmem.h> 340Sstevel@tonic-gate #include <sys/socket.h> 350Sstevel@tonic-gate #include <sys/random.h> 361676Sjpk #include <sys/tsol/tndb.h> 371676Sjpk #include <sys/tsol/tnet.h> 380Sstevel@tonic-gate 390Sstevel@tonic-gate #include <netinet/in.h> 400Sstevel@tonic-gate #include <netinet/ip6.h> 410Sstevel@tonic-gate #include <netinet/sctp.h> 420Sstevel@tonic-gate 430Sstevel@tonic-gate #include <inet/common.h> 440Sstevel@tonic-gate #include <inet/ip.h> 450Sstevel@tonic-gate #include <inet/ip6.h> 460Sstevel@tonic-gate #include <inet/ip_ire.h> 47*11042SErik.Nordmark@Sun.COM #include <inet/ip_if.h> 48*11042SErik.Nordmark@Sun.COM #include <inet/ip_ndp.h> 490Sstevel@tonic-gate #include <inet/mib2.h> 500Sstevel@tonic-gate #include <inet/nd.h> 510Sstevel@tonic-gate #include <inet/optcom.h> 520Sstevel@tonic-gate #include <inet/sctp_ip.h> 530Sstevel@tonic-gate #include <inet/ipclassifier.h> 541676Sjpk 550Sstevel@tonic-gate #include "sctp_impl.h" 560Sstevel@tonic-gate #include "sctp_addr.h" 571932Svi117747 #include "sctp_asconf.h" 580Sstevel@tonic-gate 590Sstevel@tonic-gate static struct kmem_cache *sctp_kmem_faddr_cache; 601735Skcpoon static void sctp_init_faddr(sctp_t *, sctp_faddr_t *, in6_addr_t *, mblk_t *); 610Sstevel@tonic-gate 62*11042SErik.Nordmark@Sun.COM /* Set the source address. Refer to comments in sctp_get_dest(). */ 631932Svi117747 void 641932Svi117747 sctp_set_saddr(sctp_t *sctp, sctp_faddr_t *fp) 650Sstevel@tonic-gate { 661719Sjarrett boolean_t v6 = !fp->isv4; 674818Skcpoon boolean_t addr_set; 681719Sjarrett 694818Skcpoon fp->saddr = sctp_get_valid_addr(sctp, v6, &addr_set); 704818Skcpoon /* 714818Skcpoon * If there is no source address avaialble, mark this peer address 724818Skcpoon * as unreachable for now. When the heartbeat timer fires, it will 73*11042SErik.Nordmark@Sun.COM * call sctp_get_dest() to re-check if there is any source address 744818Skcpoon * available. 754818Skcpoon */ 764818Skcpoon if (!addr_set) 774818Skcpoon fp->state = SCTP_FADDRS_UNREACH; 780Sstevel@tonic-gate } 790Sstevel@tonic-gate 800Sstevel@tonic-gate /* 81*11042SErik.Nordmark@Sun.COM * Call this function to get information about a peer addr fp. 82*11042SErik.Nordmark@Sun.COM * 83*11042SErik.Nordmark@Sun.COM * Uses ip_attr_connect to avoid explicit use of ire and source address 84*11042SErik.Nordmark@Sun.COM * selection. 850Sstevel@tonic-gate */ 860Sstevel@tonic-gate void 87*11042SErik.Nordmark@Sun.COM sctp_get_dest(sctp_t *sctp, sctp_faddr_t *fp) 880Sstevel@tonic-gate { 891735Skcpoon in6_addr_t laddr; 90*11042SErik.Nordmark@Sun.COM in6_addr_t nexthop; 910Sstevel@tonic-gate sctp_saddr_ipif_t *sp; 921735Skcpoon int hdrlen; 933448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 94*11042SErik.Nordmark@Sun.COM conn_t *connp = sctp->sctp_connp; 95*11042SErik.Nordmark@Sun.COM iulp_t uinfo; 96*11042SErik.Nordmark@Sun.COM uint_t pmtu; 97*11042SErik.Nordmark@Sun.COM int error; 98*11042SErik.Nordmark@Sun.COM uint32_t flags = IPDF_VERIFY_DST | IPDF_IPSEC | 99*11042SErik.Nordmark@Sun.COM IPDF_SELECT_SRC | IPDF_UNIQUE_DCE; 1000Sstevel@tonic-gate 101*11042SErik.Nordmark@Sun.COM /* 102*11042SErik.Nordmark@Sun.COM * Tell sctp_make_mp it needs to call us again should we not 103*11042SErik.Nordmark@Sun.COM * complete and set the saddr. 104*11042SErik.Nordmark@Sun.COM */ 105*11042SErik.Nordmark@Sun.COM fp->saddr = ipv6_all_zeros; 1060Sstevel@tonic-gate 1070Sstevel@tonic-gate /* 1080Sstevel@tonic-gate * If this addr is not reachable, mark it as unconfirmed for now, the 1090Sstevel@tonic-gate * state will be changed back to unreachable later in this function 1100Sstevel@tonic-gate * if it is still the case. 1110Sstevel@tonic-gate */ 1120Sstevel@tonic-gate if (fp->state == SCTP_FADDRS_UNREACH) { 1130Sstevel@tonic-gate fp->state = SCTP_FADDRS_UNCONFIRMED; 1140Sstevel@tonic-gate } 1150Sstevel@tonic-gate 116*11042SErik.Nordmark@Sun.COM /* 117*11042SErik.Nordmark@Sun.COM * Socket is connected - enable PMTU discovery. 118*11042SErik.Nordmark@Sun.COM */ 119*11042SErik.Nordmark@Sun.COM if (!sctps->sctps_ignore_path_mtu) 120*11042SErik.Nordmark@Sun.COM fp->ixa->ixa_flags |= IXAF_PMTU_DISCOVERY; 1211676Sjpk 122*11042SErik.Nordmark@Sun.COM ip_attr_nexthop(&connp->conn_xmit_ipp, fp->ixa, &fp->faddr, 123*11042SErik.Nordmark@Sun.COM &nexthop); 1240Sstevel@tonic-gate 125*11042SErik.Nordmark@Sun.COM laddr = fp->saddr; 126*11042SErik.Nordmark@Sun.COM error = ip_attr_connect(connp, fp->ixa, &laddr, &fp->faddr, &nexthop, 127*11042SErik.Nordmark@Sun.COM connp->conn_fport, &laddr, &uinfo, flags); 128*11042SErik.Nordmark@Sun.COM 129*11042SErik.Nordmark@Sun.COM if (error != 0) { 130*11042SErik.Nordmark@Sun.COM dprint(3, ("sctp_get_dest: no ire for %x:%x:%x:%x\n", 1311676Sjpk SCTP_PRINTADDR(fp->faddr))); 1321676Sjpk /* 1331676Sjpk * It is tempting to just leave the src addr 1341676Sjpk * unspecified and let IP figure it out, but we 1351676Sjpk * *cannot* do this, since IP may choose a src addr 1361676Sjpk * that is not part of this association... unless 137*11042SErik.Nordmark@Sun.COM * this sctp has bound to all addrs. So if the dest 1381676Sjpk * lookup fails, try to find one in our src addr 1391676Sjpk * list, unless the sctp has bound to all addrs, in 1401676Sjpk * which case we change the src addr to unspec. 1411676Sjpk * 1421676Sjpk * Note that if this is a v6 endpoint but it does 1431676Sjpk * not have any v4 address at this point (e.g. may 1441676Sjpk * have been deleted), sctp_get_valid_addr() will 1451676Sjpk * return mapped INADDR_ANY. In this case, this 1461676Sjpk * address should be marked not reachable so that 1471676Sjpk * it won't be used to send data. 1481676Sjpk */ 1491932Svi117747 sctp_set_saddr(sctp, fp); 1501735Skcpoon if (fp->state == SCTP_FADDRS_UNREACH) 1511735Skcpoon return; 1521735Skcpoon goto check_current; 1531676Sjpk } 154*11042SErik.Nordmark@Sun.COM ASSERT(fp->ixa->ixa_ire != NULL); 155*11042SErik.Nordmark@Sun.COM ASSERT(!(fp->ixa->ixa_ire->ire_flags & (RTF_REJECT|RTF_BLACKHOLE))); 156*11042SErik.Nordmark@Sun.COM 157*11042SErik.Nordmark@Sun.COM if (!sctp->sctp_loopback) 158*11042SErik.Nordmark@Sun.COM sctp->sctp_loopback = uinfo.iulp_loopback; 1591676Sjpk 1601735Skcpoon /* Make sure the laddr is part of this association */ 161*11042SErik.Nordmark@Sun.COM if ((sp = sctp_saddr_lookup(sctp, &laddr, 0)) != NULL && 162*11042SErik.Nordmark@Sun.COM !sp->saddr_ipif_dontsrc) { 1631676Sjpk if (sp->saddr_ipif_unconfirmed == 1) 1641676Sjpk sp->saddr_ipif_unconfirmed = 0; 165*11042SErik.Nordmark@Sun.COM /* We did IPsec policy lookup for laddr already */ 1661676Sjpk fp->saddr = laddr; 1671676Sjpk } else { 168*11042SErik.Nordmark@Sun.COM dprint(2, ("sctp_get_dest: src addr is not part of assoc " 169*11042SErik.Nordmark@Sun.COM "%x:%x:%x:%x\n", SCTP_PRINTADDR(laddr))); 1701735Skcpoon 1711735Skcpoon /* 1721735Skcpoon * Set the src to the first saddr and hope for the best. 173*11042SErik.Nordmark@Sun.COM * Note that this case should very seldomly 1741735Skcpoon * happen. One scenario this can happen is an app 1751735Skcpoon * explicitly bind() to an address. But that address is 1761735Skcpoon * not the preferred source address to send to the peer. 1771735Skcpoon */ 1781932Svi117747 sctp_set_saddr(sctp, fp); 1791735Skcpoon if (fp->state == SCTP_FADDRS_UNREACH) { 1801735Skcpoon return; 1811735Skcpoon } 1820Sstevel@tonic-gate } 1830Sstevel@tonic-gate 1841735Skcpoon /* 1850Sstevel@tonic-gate * Pull out RTO information for this faddr and use it if we don't 1860Sstevel@tonic-gate * have any yet. 1870Sstevel@tonic-gate */ 188*11042SErik.Nordmark@Sun.COM if (fp->srtt == -1 && uinfo.iulp_rtt != 0) { 189116Skcpoon /* The cached value is in ms. */ 190*11042SErik.Nordmark@Sun.COM fp->srtt = MSEC_TO_TICK(uinfo.iulp_rtt); 191*11042SErik.Nordmark@Sun.COM fp->rttvar = MSEC_TO_TICK(uinfo.iulp_rtt_sd); 1920Sstevel@tonic-gate fp->rto = 3 * fp->srtt; 1930Sstevel@tonic-gate 1940Sstevel@tonic-gate /* Bound the RTO by configured min and max values */ 1950Sstevel@tonic-gate if (fp->rto < sctp->sctp_rto_min) { 1960Sstevel@tonic-gate fp->rto = sctp->sctp_rto_min; 1970Sstevel@tonic-gate } 1980Sstevel@tonic-gate if (fp->rto > sctp->sctp_rto_max) { 1990Sstevel@tonic-gate fp->rto = sctp->sctp_rto_max; 2000Sstevel@tonic-gate } 20110212SGeorge.Shepherd@Sun.COM SCTP_MAX_RTO(sctp, fp); 2020Sstevel@tonic-gate } 203*11042SErik.Nordmark@Sun.COM pmtu = uinfo.iulp_mtu; 2040Sstevel@tonic-gate 2050Sstevel@tonic-gate /* 2060Sstevel@tonic-gate * Record the MTU for this faddr. If the MTU for this faddr has 2070Sstevel@tonic-gate * changed, check if the assc MTU will also change. 2080Sstevel@tonic-gate */ 2090Sstevel@tonic-gate if (fp->isv4) { 2100Sstevel@tonic-gate hdrlen = sctp->sctp_hdr_len; 2110Sstevel@tonic-gate } else { 2120Sstevel@tonic-gate hdrlen = sctp->sctp_hdr6_len; 2130Sstevel@tonic-gate } 214*11042SErik.Nordmark@Sun.COM if ((fp->sfa_pmss + hdrlen) != pmtu) { 2150Sstevel@tonic-gate /* Make sure that sfa_pmss is a multiple of SCTP_ALIGN. */ 216*11042SErik.Nordmark@Sun.COM fp->sfa_pmss = (pmtu - hdrlen) & ~(SCTP_ALIGN - 1); 2170Sstevel@tonic-gate if (fp->cwnd < (fp->sfa_pmss * 2)) { 2183795Skcpoon SET_CWND(fp, fp->sfa_pmss, 2193795Skcpoon sctps->sctps_slow_start_initial); 2200Sstevel@tonic-gate } 2210Sstevel@tonic-gate } 2220Sstevel@tonic-gate 2231735Skcpoon check_current: 2241735Skcpoon if (fp == sctp->sctp_current) 2251735Skcpoon sctp_set_faddr_current(sctp, fp); 2260Sstevel@tonic-gate } 2270Sstevel@tonic-gate 2280Sstevel@tonic-gate void 229*11042SErik.Nordmark@Sun.COM sctp_update_dce(sctp_t *sctp) 2300Sstevel@tonic-gate { 2311735Skcpoon sctp_faddr_t *fp; 2323448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 233*11042SErik.Nordmark@Sun.COM iulp_t uinfo; 234*11042SErik.Nordmark@Sun.COM ip_stack_t *ipst = sctps->sctps_netstack->netstack_ip; 235*11042SErik.Nordmark@Sun.COM uint_t ifindex; 2360Sstevel@tonic-gate 2371735Skcpoon for (fp = sctp->sctp_faddrs; fp != NULL; fp = fp->next) { 238*11042SErik.Nordmark@Sun.COM bzero(&uinfo, sizeof (uinfo)); 2390Sstevel@tonic-gate /* 2401735Skcpoon * Only record the PMTU for this faddr if we actually have 2411735Skcpoon * done discovery. This prevents initialized default from 2421735Skcpoon * clobbering any real info that IP may have. 2430Sstevel@tonic-gate */ 2441735Skcpoon if (fp->pmtu_discovered) { 2451735Skcpoon if (fp->isv4) { 246*11042SErik.Nordmark@Sun.COM uinfo.iulp_mtu = fp->sfa_pmss + 2471735Skcpoon sctp->sctp_hdr_len; 2481735Skcpoon } else { 249*11042SErik.Nordmark@Sun.COM uinfo.iulp_mtu = fp->sfa_pmss + 2501735Skcpoon sctp->sctp_hdr6_len; 2511735Skcpoon } 2520Sstevel@tonic-gate } 2533448Sdh155122 if (sctps->sctps_rtt_updates != 0 && 2543448Sdh155122 fp->rtt_updates >= sctps->sctps_rtt_updates) { 2551735Skcpoon /* 256*11042SErik.Nordmark@Sun.COM * dce_update_uinfo() merges these values with the 257*11042SErik.Nordmark@Sun.COM * old values. 2581735Skcpoon */ 259*11042SErik.Nordmark@Sun.COM uinfo.iulp_rtt = TICK_TO_MSEC(fp->srtt); 260*11042SErik.Nordmark@Sun.COM uinfo.iulp_rtt_sd = TICK_TO_MSEC(fp->rttvar); 2611735Skcpoon fp->rtt_updates = 0; 2620Sstevel@tonic-gate } 263*11042SErik.Nordmark@Sun.COM ifindex = 0; 264*11042SErik.Nordmark@Sun.COM if (IN6_IS_ADDR_LINKSCOPE(&fp->faddr)) { 265*11042SErik.Nordmark@Sun.COM /* 266*11042SErik.Nordmark@Sun.COM * If we are going to create a DCE we'd better have 267*11042SErik.Nordmark@Sun.COM * an ifindex 268*11042SErik.Nordmark@Sun.COM */ 269*11042SErik.Nordmark@Sun.COM if (fp->ixa->ixa_nce != NULL) { 270*11042SErik.Nordmark@Sun.COM ifindex = fp->ixa->ixa_nce->nce_common-> 271*11042SErik.Nordmark@Sun.COM ncec_ill->ill_phyint->phyint_ifindex; 272*11042SErik.Nordmark@Sun.COM } else { 273*11042SErik.Nordmark@Sun.COM continue; 274*11042SErik.Nordmark@Sun.COM } 275*11042SErik.Nordmark@Sun.COM } 276*11042SErik.Nordmark@Sun.COM 277*11042SErik.Nordmark@Sun.COM (void) dce_update_uinfo(&fp->faddr, ifindex, &uinfo, ipst); 2780Sstevel@tonic-gate } 2790Sstevel@tonic-gate } 2800Sstevel@tonic-gate 2810Sstevel@tonic-gate /* 282*11042SErik.Nordmark@Sun.COM * The sender must later set the total length in the IP header. 2830Sstevel@tonic-gate */ 2840Sstevel@tonic-gate mblk_t * 285*11042SErik.Nordmark@Sun.COM sctp_make_mp(sctp_t *sctp, sctp_faddr_t *fp, int trailer) 2860Sstevel@tonic-gate { 2870Sstevel@tonic-gate mblk_t *mp; 2880Sstevel@tonic-gate size_t ipsctplen; 2890Sstevel@tonic-gate int isv4; 2903448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 2914818Skcpoon boolean_t src_changed = B_FALSE; 2920Sstevel@tonic-gate 293*11042SErik.Nordmark@Sun.COM ASSERT(fp != NULL); 2940Sstevel@tonic-gate isv4 = fp->isv4; 2950Sstevel@tonic-gate 296*11042SErik.Nordmark@Sun.COM if (SCTP_IS_ADDR_UNSPEC(isv4, fp->saddr) || 297*11042SErik.Nordmark@Sun.COM (fp->ixa->ixa_ire->ire_flags & (RTF_REJECT|RTF_BLACKHOLE))) { 298*11042SErik.Nordmark@Sun.COM /* Need to pick a source */ 299*11042SErik.Nordmark@Sun.COM sctp_get_dest(sctp, fp); 3004818Skcpoon /* 3014818Skcpoon * Although we still may not get an IRE, the source address 3024818Skcpoon * may be changed in sctp_get_ire(). Set src_changed to 3034818Skcpoon * true so that the source address is copied again. 3044818Skcpoon */ 3054818Skcpoon src_changed = B_TRUE; 3064818Skcpoon } 3070Sstevel@tonic-gate 3080Sstevel@tonic-gate /* There is no suitable source address to use, return. */ 3090Sstevel@tonic-gate if (fp->state == SCTP_FADDRS_UNREACH) 3100Sstevel@tonic-gate return (NULL); 311*11042SErik.Nordmark@Sun.COM 312*11042SErik.Nordmark@Sun.COM ASSERT(fp->ixa->ixa_ire != NULL); 313*11042SErik.Nordmark@Sun.COM ASSERT(!SCTP_IS_ADDR_UNSPEC(isv4, fp->saddr)); 3140Sstevel@tonic-gate 3150Sstevel@tonic-gate if (isv4) { 3160Sstevel@tonic-gate ipsctplen = sctp->sctp_hdr_len; 3170Sstevel@tonic-gate } else { 3180Sstevel@tonic-gate ipsctplen = sctp->sctp_hdr6_len; 3190Sstevel@tonic-gate } 3200Sstevel@tonic-gate 321*11042SErik.Nordmark@Sun.COM mp = allocb(ipsctplen + sctps->sctps_wroff_xtra + trailer, BPRI_MED); 3220Sstevel@tonic-gate if (mp == NULL) { 3231676Sjpk ip1dbg(("sctp_make_mp: error making mp..\n")); 3240Sstevel@tonic-gate return (NULL); 3250Sstevel@tonic-gate } 3263448Sdh155122 mp->b_rptr += sctps->sctps_wroff_xtra; 3270Sstevel@tonic-gate mp->b_wptr = mp->b_rptr + ipsctplen; 3280Sstevel@tonic-gate 3290Sstevel@tonic-gate ASSERT(OK_32PTR(mp->b_wptr)); 3300Sstevel@tonic-gate 3310Sstevel@tonic-gate if (isv4) { 3320Sstevel@tonic-gate ipha_t *iph = (ipha_t *)mp->b_rptr; 3330Sstevel@tonic-gate 3340Sstevel@tonic-gate bcopy(sctp->sctp_iphc, mp->b_rptr, ipsctplen); 3354818Skcpoon if (fp != sctp->sctp_current || src_changed) { 3364818Skcpoon /* Fix the source and destination addresses. */ 3370Sstevel@tonic-gate IN6_V4MAPPED_TO_IPADDR(&fp->faddr, iph->ipha_dst); 3384818Skcpoon IN6_V4MAPPED_TO_IPADDR(&fp->saddr, iph->ipha_src); 3390Sstevel@tonic-gate } 3400Sstevel@tonic-gate /* set or clear the don't fragment bit */ 3410Sstevel@tonic-gate if (fp->df) { 3420Sstevel@tonic-gate iph->ipha_fragment_offset_and_flags = htons(IPH_DF); 3430Sstevel@tonic-gate } else { 3440Sstevel@tonic-gate iph->ipha_fragment_offset_and_flags = 0; 3450Sstevel@tonic-gate } 3460Sstevel@tonic-gate } else { 3470Sstevel@tonic-gate bcopy(sctp->sctp_iphc6, mp->b_rptr, ipsctplen); 3484818Skcpoon if (fp != sctp->sctp_current || src_changed) { 3494818Skcpoon /* Fix the source and destination addresses. */ 3500Sstevel@tonic-gate ((ip6_t *)(mp->b_rptr))->ip6_dst = fp->faddr; 3514818Skcpoon ((ip6_t *)(mp->b_rptr))->ip6_src = fp->saddr; 3520Sstevel@tonic-gate } 3530Sstevel@tonic-gate } 3540Sstevel@tonic-gate ASSERT(sctp->sctp_connp != NULL); 3550Sstevel@tonic-gate return (mp); 3560Sstevel@tonic-gate } 3570Sstevel@tonic-gate 3580Sstevel@tonic-gate /* 3590Sstevel@tonic-gate * Notify upper layers about preferred write offset, write size. 3600Sstevel@tonic-gate */ 3610Sstevel@tonic-gate void 3620Sstevel@tonic-gate sctp_set_ulp_prop(sctp_t *sctp) 3630Sstevel@tonic-gate { 3640Sstevel@tonic-gate int hdrlen; 3658348SEric.Yu@Sun.COM struct sock_proto_props sopp; 3668348SEric.Yu@Sun.COM 3673448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 3680Sstevel@tonic-gate 3690Sstevel@tonic-gate if (sctp->sctp_current->isv4) { 3700Sstevel@tonic-gate hdrlen = sctp->sctp_hdr_len; 3710Sstevel@tonic-gate } else { 3720Sstevel@tonic-gate hdrlen = sctp->sctp_hdr6_len; 3730Sstevel@tonic-gate } 3740Sstevel@tonic-gate ASSERT(sctp->sctp_ulpd); 3750Sstevel@tonic-gate 376*11042SErik.Nordmark@Sun.COM sctp->sctp_connp->conn_wroff = sctps->sctps_wroff_xtra + hdrlen + 377*11042SErik.Nordmark@Sun.COM sizeof (sctp_data_hdr_t); 378*11042SErik.Nordmark@Sun.COM 3790Sstevel@tonic-gate ASSERT(sctp->sctp_current->sfa_pmss == sctp->sctp_mss); 3808348SEric.Yu@Sun.COM bzero(&sopp, sizeof (sopp)); 3818348SEric.Yu@Sun.COM sopp.sopp_flags = SOCKOPT_MAXBLK|SOCKOPT_WROFF; 382*11042SErik.Nordmark@Sun.COM sopp.sopp_wroff = sctp->sctp_connp->conn_wroff; 3838348SEric.Yu@Sun.COM sopp.sopp_maxblk = sctp->sctp_mss - sizeof (sctp_data_hdr_t); 3848348SEric.Yu@Sun.COM sctp->sctp_ulp_prop(sctp->sctp_ulpd, &sopp); 3850Sstevel@tonic-gate } 3860Sstevel@tonic-gate 387*11042SErik.Nordmark@Sun.COM /* 388*11042SErik.Nordmark@Sun.COM * Set the lengths in the packet and the transmit attributes. 389*11042SErik.Nordmark@Sun.COM */ 3900Sstevel@tonic-gate void 391*11042SErik.Nordmark@Sun.COM sctp_set_iplen(sctp_t *sctp, mblk_t *mp, ip_xmit_attr_t *ixa) 3920Sstevel@tonic-gate { 3930Sstevel@tonic-gate uint16_t sum = 0; 3940Sstevel@tonic-gate ipha_t *iph; 3950Sstevel@tonic-gate ip6_t *ip6h; 3960Sstevel@tonic-gate mblk_t *pmp = mp; 3970Sstevel@tonic-gate boolean_t isv4; 3980Sstevel@tonic-gate 3990Sstevel@tonic-gate isv4 = (IPH_HDR_VERSION(mp->b_rptr) == IPV4_VERSION); 4000Sstevel@tonic-gate for (; pmp; pmp = pmp->b_cont) 4010Sstevel@tonic-gate sum += pmp->b_wptr - pmp->b_rptr; 4020Sstevel@tonic-gate 403*11042SErik.Nordmark@Sun.COM ixa->ixa_pktlen = sum; 4040Sstevel@tonic-gate if (isv4) { 4050Sstevel@tonic-gate iph = (ipha_t *)mp->b_rptr; 4060Sstevel@tonic-gate iph->ipha_length = htons(sum); 407*11042SErik.Nordmark@Sun.COM ixa->ixa_ip_hdr_length = sctp->sctp_ip_hdr_len; 4080Sstevel@tonic-gate } else { 4090Sstevel@tonic-gate ip6h = (ip6_t *)mp->b_rptr; 410*11042SErik.Nordmark@Sun.COM ip6h->ip6_plen = htons(sum - IPV6_HDR_LEN); 411*11042SErik.Nordmark@Sun.COM ixa->ixa_ip_hdr_length = sctp->sctp_ip_hdr6_len; 4120Sstevel@tonic-gate } 4130Sstevel@tonic-gate } 4140Sstevel@tonic-gate 4150Sstevel@tonic-gate int 4160Sstevel@tonic-gate sctp_compare_faddrsets(sctp_faddr_t *a1, sctp_faddr_t *a2) 4170Sstevel@tonic-gate { 4180Sstevel@tonic-gate int na1 = 0; 4190Sstevel@tonic-gate int overlap = 0; 4200Sstevel@tonic-gate int equal = 1; 4210Sstevel@tonic-gate int onematch; 4220Sstevel@tonic-gate sctp_faddr_t *fp1, *fp2; 4230Sstevel@tonic-gate 4240Sstevel@tonic-gate for (fp1 = a1; fp1; fp1 = fp1->next) { 4250Sstevel@tonic-gate onematch = 0; 4260Sstevel@tonic-gate for (fp2 = a2; fp2; fp2 = fp2->next) { 4270Sstevel@tonic-gate if (IN6_ARE_ADDR_EQUAL(&fp1->faddr, &fp2->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; 468*11042SErik.Nordmark@Sun.COM conn_t *connp = sctp->sctp_connp; 4690Sstevel@tonic-gate 4701676Sjpk if (is_system_labeled()) { 471*11042SErik.Nordmark@Sun.COM ip_xmit_attr_t *ixa = connp->conn_ixa; 472*11042SErik.Nordmark@Sun.COM ts_label_t *effective_tsl = NULL; 473*11042SErik.Nordmark@Sun.COM 474*11042SErik.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 * 480*11042SErik.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 482*11042SErik.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); 492*11042SErik.Nordmark@Sun.COM err = tsol_check_dest(ixa->ixa_tsl, 493*11042SErik.Nordmark@Sun.COM &dst, IPV4_VERSION, connp->conn_mac_mode, 494*11042SErik.Nordmark@Sun.COM connp->conn_zone_is_global, &effective_tsl); 4959710SKen.Powell@Sun.COM } else { 496*11042SErik.Nordmark@Sun.COM err = tsol_check_dest(ixa->ixa_tsl, 497*11042SErik.Nordmark@Sun.COM addr, IPV6_VERSION, connp->conn_mac_mode, 498*11042SErik.Nordmark@Sun.COM connp->conn_zone_is_global, &effective_tsl); 4991676Sjpk } 5009710SKen.Powell@Sun.COM if (err != 0) 5019710SKen.Powell@Sun.COM return (err); 502*11042SErik.Nordmark@Sun.COM 503*11042SErik.Nordmark@Sun.COM if (sctp->sctp_faddrs == NULL && effective_tsl != NULL) { 504*11042SErik.Nordmark@Sun.COM ip_xmit_attr_replace_tsl(ixa, effective_tsl); 505*11042SErik.Nordmark@Sun.COM } else if (effective_tsl != NULL) { 506*11042SErik.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); 513*11042SErik.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 521*11042SErik.Nordmark@Sun.COM /* Start with any options set on the conn */ 522*11042SErik.Nordmark@Sun.COM faddr->ixa = conn_get_ixa_exclusive(connp); 523*11042SErik.Nordmark@Sun.COM if (faddr->ixa == NULL) { 524*11042SErik.Nordmark@Sun.COM freemsg(timer_mp); 525*11042SErik.Nordmark@Sun.COM kmem_cache_free(sctp_kmem_faddr_cache, faddr); 526*11042SErik.Nordmark@Sun.COM return (ENOMEM); 527*11042SErik.Nordmark@Sun.COM } 528*11042SErik.Nordmark@Sun.COM faddr->ixa->ixa_notify_cookie = connp->conn_sctp; 5294818Skcpoon 530*11042SErik.Nordmark@Sun.COM sctp_init_faddr(sctp, faddr, addr, timer_mp); 531*11042SErik.Nordmark@Sun.COM ASSERT(faddr->ixa->ixa_cred != NULL); 532*11042SErik.Nordmark@Sun.COM 533*11042SErik.Nordmark@Sun.COM /* ip_attr_connect didn't allow broadcats/multicast dest */ 5340Sstevel@tonic-gate ASSERT(faddr->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); 5421676Sjpk faddr->next = sctp->sctp_faddrs; 5431676Sjpk sctp->sctp_faddrs = faddr; 5440Sstevel@tonic-gate } else { 5451676Sjpk sctp->sctp_lastfaddr->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 5580Sstevel@tonic-gate for (fp = sctp->sctp_faddrs; fp != NULL; fp = fp->next) { 5590Sstevel@tonic-gate if (IN6_ARE_ADDR_EQUAL(&fp->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 { 5690Sstevel@tonic-gate for (; fp; fp = fp->next) { 5700Sstevel@tonic-gate if (IN6_ARE_ADDR_EQUAL(&fp->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. */ 5850Sstevel@tonic-gate if (fp->isv4) { 5860Sstevel@tonic-gate IN6_V4MAPPED_TO_IPADDR(&fp->faddr, 5870Sstevel@tonic-gate sctp->sctp_ipha->ipha_dst); 5880Sstevel@tonic-gate IN6_V4MAPPED_TO_IPADDR(&fp->saddr, sctp->sctp_ipha->ipha_src); 5890Sstevel@tonic-gate /* update don't fragment bit */ 5900Sstevel@tonic-gate if (fp->df) { 5910Sstevel@tonic-gate sctp->sctp_ipha->ipha_fragment_offset_and_flags = 5920Sstevel@tonic-gate htons(IPH_DF); 5930Sstevel@tonic-gate } else { 5940Sstevel@tonic-gate sctp->sctp_ipha->ipha_fragment_offset_and_flags = 0; 5950Sstevel@tonic-gate } 5960Sstevel@tonic-gate } else { 5970Sstevel@tonic-gate sctp->sctp_ip6h->ip6_dst = fp->faddr; 5980Sstevel@tonic-gate sctp->sctp_ip6h->ip6_src = fp->saddr; 5990Sstevel@tonic-gate } 6001735Skcpoon 6011735Skcpoon sctp->sctp_current = fp; 6021735Skcpoon sctp->sctp_mss = fp->sfa_pmss; 6031735Skcpoon 6041735Skcpoon /* Update the uppper layer for the change. */ 6051735Skcpoon if (!SCTP_IS_DETACHED(sctp)) 6061735Skcpoon sctp_set_ulp_prop(sctp); 6070Sstevel@tonic-gate } 6080Sstevel@tonic-gate 6090Sstevel@tonic-gate void 6100Sstevel@tonic-gate sctp_redo_faddr_srcs(sctp_t *sctp) 6110Sstevel@tonic-gate { 6120Sstevel@tonic-gate sctp_faddr_t *fp; 6130Sstevel@tonic-gate 6140Sstevel@tonic-gate for (fp = sctp->sctp_faddrs; fp != NULL; fp = fp->next) { 615*11042SErik.Nordmark@Sun.COM sctp_get_dest(sctp, fp); 6160Sstevel@tonic-gate } 6170Sstevel@tonic-gate } 6180Sstevel@tonic-gate 6190Sstevel@tonic-gate void 6200Sstevel@tonic-gate sctp_faddr_alive(sctp_t *sctp, sctp_faddr_t *fp) 6210Sstevel@tonic-gate { 6220Sstevel@tonic-gate int64_t now = lbolt64; 6230Sstevel@tonic-gate 6240Sstevel@tonic-gate fp->strikes = 0; 6250Sstevel@tonic-gate sctp->sctp_strikes = 0; 6260Sstevel@tonic-gate fp->lastactive = now; 6270Sstevel@tonic-gate fp->hb_expiry = now + SET_HB_INTVL(fp); 6280Sstevel@tonic-gate fp->hb_pending = B_FALSE; 6290Sstevel@tonic-gate if (fp->state != SCTP_FADDRS_ALIVE) { 6300Sstevel@tonic-gate fp->state = SCTP_FADDRS_ALIVE; 6310Sstevel@tonic-gate sctp_intf_event(sctp, fp->faddr, SCTP_ADDR_AVAILABLE, 0); 6324818Skcpoon /* Should have a full IRE now */ 633*11042SErik.Nordmark@Sun.COM sctp_get_dest(sctp, fp); 6340Sstevel@tonic-gate 6351735Skcpoon /* 6361735Skcpoon * If this is the primary, switch back to it now. And 6371735Skcpoon * we probably want to reset the source addr used to reach 6381735Skcpoon * it. 639*11042SErik.Nordmark@Sun.COM * Note that if we didn't find a source in sctp_get_dest 640*11042SErik.Nordmark@Sun.COM * then we'd be unreachable at this point in time. 6411735Skcpoon */ 642*11042SErik.Nordmark@Sun.COM if (fp == sctp->sctp_primary && 643*11042SErik.Nordmark@Sun.COM fp->state != SCTP_FADDRS_UNREACH) { 6441735Skcpoon sctp_set_faddr_current(sctp, fp); 6451735Skcpoon return; 6460Sstevel@tonic-gate } 6470Sstevel@tonic-gate } 6480Sstevel@tonic-gate } 6490Sstevel@tonic-gate 6500Sstevel@tonic-gate int 6510Sstevel@tonic-gate sctp_is_a_faddr_clean(sctp_t *sctp) 6520Sstevel@tonic-gate { 6530Sstevel@tonic-gate sctp_faddr_t *fp; 6540Sstevel@tonic-gate 6550Sstevel@tonic-gate for (fp = sctp->sctp_faddrs; fp; fp = fp->next) { 6560Sstevel@tonic-gate if (fp->state == SCTP_FADDRS_ALIVE && fp->strikes == 0) { 6570Sstevel@tonic-gate return (1); 6580Sstevel@tonic-gate } 6590Sstevel@tonic-gate } 6600Sstevel@tonic-gate 6610Sstevel@tonic-gate return (0); 6620Sstevel@tonic-gate } 6630Sstevel@tonic-gate 6640Sstevel@tonic-gate /* 6650Sstevel@tonic-gate * Returns 0 if there is at leave one other active faddr, -1 if there 6660Sstevel@tonic-gate * are none. If there are none left, faddr_dead() will start killing the 6670Sstevel@tonic-gate * association. 6680Sstevel@tonic-gate * If the downed faddr was the current faddr, a new current faddr 6690Sstevel@tonic-gate * will be chosen. 6700Sstevel@tonic-gate */ 6710Sstevel@tonic-gate int 6720Sstevel@tonic-gate sctp_faddr_dead(sctp_t *sctp, sctp_faddr_t *fp, int newstate) 6730Sstevel@tonic-gate { 6740Sstevel@tonic-gate sctp_faddr_t *ofp; 6753448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 6760Sstevel@tonic-gate 6770Sstevel@tonic-gate if (fp->state == SCTP_FADDRS_ALIVE) { 6780Sstevel@tonic-gate sctp_intf_event(sctp, fp->faddr, SCTP_ADDR_UNREACHABLE, 0); 6790Sstevel@tonic-gate } 6800Sstevel@tonic-gate fp->state = newstate; 6810Sstevel@tonic-gate 6820Sstevel@tonic-gate dprint(1, ("sctp_faddr_dead: %x:%x:%x:%x down (state=%d)\n", 6830Sstevel@tonic-gate SCTP_PRINTADDR(fp->faddr), newstate)); 6840Sstevel@tonic-gate 6850Sstevel@tonic-gate if (fp == sctp->sctp_current) { 6860Sstevel@tonic-gate /* Current faddr down; need to switch it */ 6870Sstevel@tonic-gate sctp->sctp_current = NULL; 6880Sstevel@tonic-gate } 6890Sstevel@tonic-gate 6900Sstevel@tonic-gate /* Find next alive faddr */ 6910Sstevel@tonic-gate ofp = fp; 6921735Skcpoon for (fp = fp->next; fp != NULL; fp = fp->next) { 6930Sstevel@tonic-gate if (fp->state == SCTP_FADDRS_ALIVE) { 6940Sstevel@tonic-gate break; 6950Sstevel@tonic-gate } 6960Sstevel@tonic-gate } 6970Sstevel@tonic-gate 6980Sstevel@tonic-gate if (fp == NULL) { 6990Sstevel@tonic-gate /* Continue from beginning of list */ 7000Sstevel@tonic-gate for (fp = sctp->sctp_faddrs; fp != ofp; fp = fp->next) { 7010Sstevel@tonic-gate if (fp->state == SCTP_FADDRS_ALIVE) { 7020Sstevel@tonic-gate break; 7030Sstevel@tonic-gate } 7040Sstevel@tonic-gate } 7050Sstevel@tonic-gate } 7060Sstevel@tonic-gate 7071735Skcpoon /* 7081735Skcpoon * Find a new fp, so if the current faddr is dead, use the new fp 7091735Skcpoon * as the current one. 7101735Skcpoon */ 7110Sstevel@tonic-gate if (fp != ofp) { 7120Sstevel@tonic-gate if (sctp->sctp_current == NULL) { 7130Sstevel@tonic-gate dprint(1, ("sctp_faddr_dead: failover->%x:%x:%x:%x\n", 7140Sstevel@tonic-gate SCTP_PRINTADDR(fp->faddr))); 7151735Skcpoon /* 7161735Skcpoon * Note that we don't need to reset the source addr 7171735Skcpoon * of the new fp. 7181735Skcpoon */ 7191735Skcpoon sctp_set_faddr_current(sctp, fp); 7200Sstevel@tonic-gate } 7210Sstevel@tonic-gate return (0); 7220Sstevel@tonic-gate } 7230Sstevel@tonic-gate 7240Sstevel@tonic-gate 7250Sstevel@tonic-gate /* All faddrs are down; kill the association */ 7260Sstevel@tonic-gate dprint(1, ("sctp_faddr_dead: all faddrs down, killing assoc\n")); 7273448Sdh155122 BUMP_MIB(&sctps->sctps_mib, sctpAborted); 7280Sstevel@tonic-gate sctp_assoc_event(sctp, sctp->sctp_state < SCTPS_ESTABLISHED ? 7290Sstevel@tonic-gate SCTP_CANT_STR_ASSOC : SCTP_COMM_LOST, 0, NULL); 7300Sstevel@tonic-gate sctp_clean_death(sctp, sctp->sctp_client_errno ? 7310Sstevel@tonic-gate sctp->sctp_client_errno : ETIMEDOUT); 7320Sstevel@tonic-gate 7330Sstevel@tonic-gate return (-1); 7340Sstevel@tonic-gate } 7350Sstevel@tonic-gate 7360Sstevel@tonic-gate sctp_faddr_t * 7370Sstevel@tonic-gate sctp_rotate_faddr(sctp_t *sctp, sctp_faddr_t *ofp) 7380Sstevel@tonic-gate { 7390Sstevel@tonic-gate sctp_faddr_t *nfp = NULL; 7400Sstevel@tonic-gate 7410Sstevel@tonic-gate if (ofp == NULL) { 7420Sstevel@tonic-gate ofp = sctp->sctp_current; 7430Sstevel@tonic-gate } 7440Sstevel@tonic-gate 7450Sstevel@tonic-gate /* Find the next live one */ 7460Sstevel@tonic-gate for (nfp = ofp->next; nfp != NULL; nfp = nfp->next) { 7470Sstevel@tonic-gate if (nfp->state == SCTP_FADDRS_ALIVE) { 7480Sstevel@tonic-gate break; 7490Sstevel@tonic-gate } 7500Sstevel@tonic-gate } 7510Sstevel@tonic-gate 7520Sstevel@tonic-gate if (nfp == NULL) { 7530Sstevel@tonic-gate /* Continue from beginning of list */ 7540Sstevel@tonic-gate for (nfp = sctp->sctp_faddrs; nfp != ofp; nfp = nfp->next) { 7550Sstevel@tonic-gate if (nfp->state == SCTP_FADDRS_ALIVE) { 7560Sstevel@tonic-gate break; 7570Sstevel@tonic-gate } 7580Sstevel@tonic-gate } 7590Sstevel@tonic-gate } 7600Sstevel@tonic-gate 7610Sstevel@tonic-gate /* 7620Sstevel@tonic-gate * nfp could only be NULL if all faddrs are down, and when 7630Sstevel@tonic-gate * this happens, faddr_dead() should have killed the 7640Sstevel@tonic-gate * association. Hence this assertion... 7650Sstevel@tonic-gate */ 7660Sstevel@tonic-gate ASSERT(nfp != NULL); 7670Sstevel@tonic-gate return (nfp); 7680Sstevel@tonic-gate } 7690Sstevel@tonic-gate 7700Sstevel@tonic-gate void 7710Sstevel@tonic-gate sctp_unlink_faddr(sctp_t *sctp, sctp_faddr_t *fp) 7720Sstevel@tonic-gate { 7730Sstevel@tonic-gate sctp_faddr_t *fpp; 7740Sstevel@tonic-gate 7750Sstevel@tonic-gate if (!sctp->sctp_faddrs) { 7760Sstevel@tonic-gate return; 7770Sstevel@tonic-gate } 7780Sstevel@tonic-gate 7790Sstevel@tonic-gate if (fp->timer_mp != NULL) { 7800Sstevel@tonic-gate sctp_timer_free(fp->timer_mp); 7810Sstevel@tonic-gate fp->timer_mp = NULL; 7820Sstevel@tonic-gate fp->timer_running = 0; 7830Sstevel@tonic-gate } 7840Sstevel@tonic-gate if (fp->rc_timer_mp != NULL) { 7850Sstevel@tonic-gate sctp_timer_free(fp->rc_timer_mp); 7860Sstevel@tonic-gate fp->rc_timer_mp = NULL; 7870Sstevel@tonic-gate fp->rc_timer_running = 0; 7880Sstevel@tonic-gate } 789*11042SErik.Nordmark@Sun.COM if (fp->ixa != NULL) { 790*11042SErik.Nordmark@Sun.COM ixa_refrele(fp->ixa); 791*11042SErik.Nordmark@Sun.COM fp->ixa = NULL; 7920Sstevel@tonic-gate } 7930Sstevel@tonic-gate 7940Sstevel@tonic-gate if (fp == sctp->sctp_faddrs) { 7950Sstevel@tonic-gate goto gotit; 7960Sstevel@tonic-gate } 7970Sstevel@tonic-gate 7980Sstevel@tonic-gate for (fpp = sctp->sctp_faddrs; fpp->next != fp; fpp = fpp->next) 7990Sstevel@tonic-gate ; 8000Sstevel@tonic-gate 8010Sstevel@tonic-gate gotit: 8020Sstevel@tonic-gate ASSERT(sctp->sctp_conn_tfp != NULL); 8030Sstevel@tonic-gate mutex_enter(&sctp->sctp_conn_tfp->tf_lock); 8040Sstevel@tonic-gate if (fp == sctp->sctp_faddrs) { 8050Sstevel@tonic-gate sctp->sctp_faddrs = fp->next; 8060Sstevel@tonic-gate } else { 8070Sstevel@tonic-gate fpp->next = fp->next; 8080Sstevel@tonic-gate } 8090Sstevel@tonic-gate mutex_exit(&sctp->sctp_conn_tfp->tf_lock); 8100Sstevel@tonic-gate kmem_cache_free(sctp_kmem_faddr_cache, fp); 811852Svi117747 sctp->sctp_nfaddrs--; 8120Sstevel@tonic-gate } 8130Sstevel@tonic-gate 8140Sstevel@tonic-gate void 8150Sstevel@tonic-gate sctp_zap_faddrs(sctp_t *sctp, int caller_holds_lock) 8160Sstevel@tonic-gate { 8170Sstevel@tonic-gate sctp_faddr_t *fp, *fpn; 8180Sstevel@tonic-gate 8190Sstevel@tonic-gate if (sctp->sctp_faddrs == NULL) { 8200Sstevel@tonic-gate ASSERT(sctp->sctp_lastfaddr == NULL); 8210Sstevel@tonic-gate return; 8220Sstevel@tonic-gate } 8230Sstevel@tonic-gate 8240Sstevel@tonic-gate ASSERT(sctp->sctp_lastfaddr != NULL); 8250Sstevel@tonic-gate sctp->sctp_lastfaddr = NULL; 8260Sstevel@tonic-gate sctp->sctp_current = NULL; 8270Sstevel@tonic-gate sctp->sctp_primary = NULL; 8280Sstevel@tonic-gate 8290Sstevel@tonic-gate sctp_free_faddr_timers(sctp); 8300Sstevel@tonic-gate 8310Sstevel@tonic-gate if (sctp->sctp_conn_tfp != NULL && !caller_holds_lock) { 8320Sstevel@tonic-gate /* in conn fanout; need to hold lock */ 8330Sstevel@tonic-gate mutex_enter(&sctp->sctp_conn_tfp->tf_lock); 8340Sstevel@tonic-gate } 8350Sstevel@tonic-gate 8360Sstevel@tonic-gate for (fp = sctp->sctp_faddrs; fp; fp = fpn) { 8370Sstevel@tonic-gate fpn = fp->next; 838*11042SErik.Nordmark@Sun.COM if (fp->ixa != NULL) { 839*11042SErik.Nordmark@Sun.COM ixa_refrele(fp->ixa); 840*11042SErik.Nordmark@Sun.COM fp->ixa = NULL; 841*11042SErik.Nordmark@Sun.COM } 8420Sstevel@tonic-gate kmem_cache_free(sctp_kmem_faddr_cache, fp); 843852Svi117747 sctp->sctp_nfaddrs--; 8440Sstevel@tonic-gate } 8450Sstevel@tonic-gate 8460Sstevel@tonic-gate sctp->sctp_faddrs = NULL; 847852Svi117747 ASSERT(sctp->sctp_nfaddrs == 0); 8480Sstevel@tonic-gate if (sctp->sctp_conn_tfp != NULL && !caller_holds_lock) { 8490Sstevel@tonic-gate mutex_exit(&sctp->sctp_conn_tfp->tf_lock); 8500Sstevel@tonic-gate } 8510Sstevel@tonic-gate 8520Sstevel@tonic-gate } 8530Sstevel@tonic-gate 8540Sstevel@tonic-gate void 8550Sstevel@tonic-gate sctp_zap_addrs(sctp_t *sctp) 8560Sstevel@tonic-gate { 8570Sstevel@tonic-gate sctp_zap_faddrs(sctp, 0); 8580Sstevel@tonic-gate sctp_free_saddrs(sctp); 8590Sstevel@tonic-gate } 8600Sstevel@tonic-gate 8610Sstevel@tonic-gate /* 862*11042SErik.Nordmark@Sun.COM * Build two SCTP header templates; one for IPv4 and one for IPv6. 863*11042SErik.Nordmark@Sun.COM * Store them in sctp_iphc and sctp_iphc6 respectively (and related fields). 864*11042SErik.Nordmark@Sun.COM * There are no IP addresses in the templates, but the port numbers and 865*11042SErik.Nordmark@Sun.COM * verifier are field in from the conn_t and sctp_t. 866*11042SErik.Nordmark@Sun.COM * 867*11042SErik.Nordmark@Sun.COM * Returns failure if can't allocate memory, or if there is a problem 868*11042SErik.Nordmark@Sun.COM * with a routing header/option. 869*11042SErik.Nordmark@Sun.COM * 870*11042SErik.Nordmark@Sun.COM * We allocate space for the minimum sctp header (sctp_hdr_t). 871*11042SErik.Nordmark@Sun.COM * 872*11042SErik.Nordmark@Sun.COM * We massage an routing option/header. There is no checksum implication 873*11042SErik.Nordmark@Sun.COM * for a routing header for sctp. 874*11042SErik.Nordmark@Sun.COM * 875*11042SErik.Nordmark@Sun.COM * Caller needs to update conn_wroff if desired. 876*11042SErik.Nordmark@Sun.COM * 877*11042SErik.Nordmark@Sun.COM * TSol notes: This assumes that a SCTP association has a single peer label 878*11042SErik.Nordmark@Sun.COM * since we only track a single pair of ipp_label_v4/v6 and not a separate one 879*11042SErik.Nordmark@Sun.COM * for each faddr. 8800Sstevel@tonic-gate */ 8810Sstevel@tonic-gate int 882*11042SErik.Nordmark@Sun.COM sctp_build_hdrs(sctp_t *sctp, int sleep) 8830Sstevel@tonic-gate { 884*11042SErik.Nordmark@Sun.COM conn_t *connp = sctp->sctp_connp; 885*11042SErik.Nordmark@Sun.COM ip_pkt_t *ipp = &connp->conn_xmit_ipp; 886*11042SErik.Nordmark@Sun.COM uint_t ip_hdr_length; 887*11042SErik.Nordmark@Sun.COM uchar_t *hdrs; 888*11042SErik.Nordmark@Sun.COM uint_t hdrs_len; 889*11042SErik.Nordmark@Sun.COM uint_t ulp_hdr_length = sizeof (sctp_hdr_t); 890*11042SErik.Nordmark@Sun.COM ipha_t *ipha; 891*11042SErik.Nordmark@Sun.COM ip6_t *ip6h; 8920Sstevel@tonic-gate sctp_hdr_t *sctph; 893*11042SErik.Nordmark@Sun.COM in6_addr_t v6src, v6dst; 894*11042SErik.Nordmark@Sun.COM ipaddr_t v4src, v4dst; 8950Sstevel@tonic-gate 896*11042SErik.Nordmark@Sun.COM v4src = connp->conn_saddr_v4; 897*11042SErik.Nordmark@Sun.COM v4dst = connp->conn_faddr_v4; 898*11042SErik.Nordmark@Sun.COM v6src = connp->conn_saddr_v6; 899*11042SErik.Nordmark@Sun.COM v6dst = connp->conn_faddr_v6; 9000Sstevel@tonic-gate 901*11042SErik.Nordmark@Sun.COM /* First do IPv4 header */ 902*11042SErik.Nordmark@Sun.COM ip_hdr_length = ip_total_hdrs_len_v4(ipp); 9030Sstevel@tonic-gate 904*11042SErik.Nordmark@Sun.COM /* In case of TX label and IP options it can be too much */ 905*11042SErik.Nordmark@Sun.COM if (ip_hdr_length > IP_MAX_HDR_LENGTH) { 906*11042SErik.Nordmark@Sun.COM /* Preserves existing TX errno for this */ 907*11042SErik.Nordmark@Sun.COM return (EHOSTUNREACH); 908*11042SErik.Nordmark@Sun.COM } 909*11042SErik.Nordmark@Sun.COM hdrs_len = ip_hdr_length + ulp_hdr_length; 910*11042SErik.Nordmark@Sun.COM ASSERT(hdrs_len != 0); 9111676Sjpk 912*11042SErik.Nordmark@Sun.COM if (hdrs_len != sctp->sctp_iphc_len) { 913*11042SErik.Nordmark@Sun.COM /* Allocate new before we free any old */ 914*11042SErik.Nordmark@Sun.COM hdrs = kmem_alloc(hdrs_len, sleep); 9150Sstevel@tonic-gate if (hdrs == NULL) 9160Sstevel@tonic-gate return (ENOMEM); 9170Sstevel@tonic-gate 918*11042SErik.Nordmark@Sun.COM if (sctp->sctp_iphc != NULL) 919*11042SErik.Nordmark@Sun.COM kmem_free(sctp->sctp_iphc, sctp->sctp_iphc_len); 920*11042SErik.Nordmark@Sun.COM sctp->sctp_iphc = hdrs; 921*11042SErik.Nordmark@Sun.COM sctp->sctp_iphc_len = hdrs_len; 922*11042SErik.Nordmark@Sun.COM } else { 923*11042SErik.Nordmark@Sun.COM hdrs = sctp->sctp_iphc; 924*11042SErik.Nordmark@Sun.COM } 925*11042SErik.Nordmark@Sun.COM sctp->sctp_hdr_len = sctp->sctp_iphc_len; 926*11042SErik.Nordmark@Sun.COM sctp->sctp_ip_hdr_len = ip_hdr_length; 927*11042SErik.Nordmark@Sun.COM 928*11042SErik.Nordmark@Sun.COM sctph = (sctp_hdr_t *)(hdrs + ip_hdr_length); 929*11042SErik.Nordmark@Sun.COM sctp->sctp_sctph = sctph; 930*11042SErik.Nordmark@Sun.COM sctph->sh_sport = connp->conn_lport; 931*11042SErik.Nordmark@Sun.COM sctph->sh_dport = connp->conn_fport; 932*11042SErik.Nordmark@Sun.COM sctph->sh_verf = sctp->sctp_fvtag; 933*11042SErik.Nordmark@Sun.COM sctph->sh_chksum = 0; 934*11042SErik.Nordmark@Sun.COM 935*11042SErik.Nordmark@Sun.COM ipha = (ipha_t *)hdrs; 936*11042SErik.Nordmark@Sun.COM sctp->sctp_ipha = ipha; 937*11042SErik.Nordmark@Sun.COM 938*11042SErik.Nordmark@Sun.COM ipha->ipha_src = v4src; 939*11042SErik.Nordmark@Sun.COM ipha->ipha_dst = v4dst; 940*11042SErik.Nordmark@Sun.COM ip_build_hdrs_v4(hdrs, ip_hdr_length, ipp, connp->conn_proto); 941*11042SErik.Nordmark@Sun.COM ipha->ipha_length = htons(hdrs_len); 942*11042SErik.Nordmark@Sun.COM ipha->ipha_fragment_offset_and_flags = 0; 943*11042SErik.Nordmark@Sun.COM 944*11042SErik.Nordmark@Sun.COM if (ipp->ipp_fields & IPPF_IPV4_OPTIONS) 945*11042SErik.Nordmark@Sun.COM (void) ip_massage_options(ipha, connp->conn_netstack); 946*11042SErik.Nordmark@Sun.COM 947*11042SErik.Nordmark@Sun.COM /* Now IPv6 */ 948*11042SErik.Nordmark@Sun.COM ip_hdr_length = ip_total_hdrs_len_v6(ipp); 949*11042SErik.Nordmark@Sun.COM hdrs_len = ip_hdr_length + ulp_hdr_length; 950*11042SErik.Nordmark@Sun.COM ASSERT(hdrs_len != 0); 951*11042SErik.Nordmark@Sun.COM 952*11042SErik.Nordmark@Sun.COM if (hdrs_len != sctp->sctp_iphc6_len) { 953*11042SErik.Nordmark@Sun.COM /* Allocate new before we free any old */ 954*11042SErik.Nordmark@Sun.COM hdrs = kmem_alloc(hdrs_len, sleep); 955*11042SErik.Nordmark@Sun.COM if (hdrs == NULL) 956*11042SErik.Nordmark@Sun.COM return (ENOMEM); 957*11042SErik.Nordmark@Sun.COM 958*11042SErik.Nordmark@Sun.COM if (sctp->sctp_iphc6 != NULL) 9590Sstevel@tonic-gate kmem_free(sctp->sctp_iphc6, sctp->sctp_iphc6_len); 9600Sstevel@tonic-gate sctp->sctp_iphc6 = hdrs; 9610Sstevel@tonic-gate sctp->sctp_iphc6_len = hdrs_len; 962*11042SErik.Nordmark@Sun.COM } else { 963*11042SErik.Nordmark@Sun.COM hdrs = sctp->sctp_iphc6; 9640Sstevel@tonic-gate } 965*11042SErik.Nordmark@Sun.COM sctp->sctp_hdr6_len = sctp->sctp_iphc6_len; 966*11042SErik.Nordmark@Sun.COM sctp->sctp_ip_hdr6_len = ip_hdr_length; 9670Sstevel@tonic-gate 968*11042SErik.Nordmark@Sun.COM sctph = (sctp_hdr_t *)(hdrs + ip_hdr_length); 969*11042SErik.Nordmark@Sun.COM sctp->sctp_sctph6 = sctph; 970*11042SErik.Nordmark@Sun.COM sctph->sh_sport = connp->conn_lport; 971*11042SErik.Nordmark@Sun.COM sctph->sh_dport = connp->conn_fport; 972*11042SErik.Nordmark@Sun.COM sctph->sh_verf = sctp->sctp_fvtag; 973*11042SErik.Nordmark@Sun.COM sctph->sh_chksum = 0; 9740Sstevel@tonic-gate 975*11042SErik.Nordmark@Sun.COM ip6h = (ip6_t *)hdrs; 976*11042SErik.Nordmark@Sun.COM sctp->sctp_ip6h = ip6h; 9770Sstevel@tonic-gate 978*11042SErik.Nordmark@Sun.COM ip6h->ip6_src = v6src; 979*11042SErik.Nordmark@Sun.COM ip6h->ip6_dst = v6dst; 980*11042SErik.Nordmark@Sun.COM ip_build_hdrs_v6(hdrs, ip_hdr_length, ipp, connp->conn_proto, 981*11042SErik.Nordmark@Sun.COM connp->conn_flowinfo); 982*11042SErik.Nordmark@Sun.COM ip6h->ip6_plen = htons(hdrs_len - IPV6_HDR_LEN); 9830Sstevel@tonic-gate 984*11042SErik.Nordmark@Sun.COM if (ipp->ipp_fields & IPPF_RTHDR) { 985*11042SErik.Nordmark@Sun.COM uint8_t *end; 986*11042SErik.Nordmark@Sun.COM ip6_rthdr_t *rth; 9870Sstevel@tonic-gate 988*11042SErik.Nordmark@Sun.COM end = (uint8_t *)ip6h + ip_hdr_length; 989*11042SErik.Nordmark@Sun.COM rth = ip_find_rthdr_v6(ip6h, end); 990*11042SErik.Nordmark@Sun.COM if (rth != NULL) { 991*11042SErik.Nordmark@Sun.COM (void) ip_massage_options_v6(ip6h, rth, 992*11042SErik.Nordmark@Sun.COM connp->conn_netstack); 993*11042SErik.Nordmark@Sun.COM } 9941676Sjpk 995*11042SErik.Nordmark@Sun.COM /* 996*11042SErik.Nordmark@Sun.COM * Verify that the first hop isn't a mapped address. 997*11042SErik.Nordmark@Sun.COM * Routers along the path need to do this verification 998*11042SErik.Nordmark@Sun.COM * for subsequent hops. 999*11042SErik.Nordmark@Sun.COM */ 1000*11042SErik.Nordmark@Sun.COM if (IN6_IS_ADDR_V4MAPPED(&ip6h->ip6_dst)) 1001*11042SErik.Nordmark@Sun.COM return (EADDRNOTAVAIL); 10021676Sjpk } 10031676Sjpk return (0); 10041676Sjpk } 10051676Sjpk 10061676Sjpk static int 1007*11042SErik.Nordmark@Sun.COM sctp_v4_label(sctp_t *sctp, sctp_faddr_t *fp) 10081676Sjpk { 1009*11042SErik.Nordmark@Sun.COM conn_t *connp = sctp->sctp_connp; 1010*11042SErik.Nordmark@Sun.COM 1011*11042SErik.Nordmark@Sun.COM ASSERT(fp->ixa->ixa_flags & IXAF_IS_IPV4); 1012*11042SErik.Nordmark@Sun.COM return (conn_update_label(connp, fp->ixa, &fp->faddr, 1013*11042SErik.Nordmark@Sun.COM &connp->conn_xmit_ipp)); 1014*11042SErik.Nordmark@Sun.COM } 10151676Sjpk 1016*11042SErik.Nordmark@Sun.COM static int 1017*11042SErik.Nordmark@Sun.COM sctp_v6_label(sctp_t *sctp, sctp_faddr_t *fp) 1018*11042SErik.Nordmark@Sun.COM { 1019*11042SErik.Nordmark@Sun.COM conn_t *connp = sctp->sctp_connp; 1020*11042SErik.Nordmark@Sun.COM 1021*11042SErik.Nordmark@Sun.COM ASSERT(!(fp->ixa->ixa_flags & IXAF_IS_IPV4)); 1022*11042SErik.Nordmark@Sun.COM return (conn_update_label(connp, fp->ixa, &fp->faddr, 1023*11042SErik.Nordmark@Sun.COM &connp->conn_xmit_ipp)); 10241676Sjpk } 10251676Sjpk 10260Sstevel@tonic-gate /* 10270Sstevel@tonic-gate * XXX implement more sophisticated logic 1028*11042SErik.Nordmark@Sun.COM * 1029*11042SErik.Nordmark@Sun.COM * Tsol note: We have already verified the addresses using tsol_check_dest 1030*11042SErik.Nordmark@Sun.COM * in sctp_add_faddr, thus no need to redo that here. 1031*11042SErik.Nordmark@Sun.COM * We do setup ipp_label_v4 and ipp_label_v6 based on which addresses 1032*11042SErik.Nordmark@Sun.COM * we have. 10330Sstevel@tonic-gate */ 10341676Sjpk int 10351735Skcpoon sctp_set_hdraddrs(sctp_t *sctp) 10360Sstevel@tonic-gate { 10370Sstevel@tonic-gate sctp_faddr_t *fp; 10380Sstevel@tonic-gate int gotv4 = 0; 10390Sstevel@tonic-gate int gotv6 = 0; 1040*11042SErik.Nordmark@Sun.COM conn_t *connp = sctp->sctp_connp; 10410Sstevel@tonic-gate 10420Sstevel@tonic-gate ASSERT(sctp->sctp_faddrs != NULL); 10430Sstevel@tonic-gate ASSERT(sctp->sctp_nsaddrs > 0); 10440Sstevel@tonic-gate 10450Sstevel@tonic-gate /* Set up using the primary first */ 1046*11042SErik.Nordmark@Sun.COM connp->conn_faddr_v6 = sctp->sctp_primary->faddr; 1047*11042SErik.Nordmark@Sun.COM /* saddr may be unspec; make_mp() will handle this */ 1048*11042SErik.Nordmark@Sun.COM connp->conn_saddr_v6 = sctp->sctp_primary->saddr; 1049*11042SErik.Nordmark@Sun.COM connp->conn_laddr_v6 = connp->conn_saddr_v6; 10500Sstevel@tonic-gate if (IN6_IS_ADDR_V4MAPPED(&sctp->sctp_primary->faddr)) { 1051*11042SErik.Nordmark@Sun.COM if (!is_system_labeled() || 1052*11042SErik.Nordmark@Sun.COM sctp_v4_label(sctp, sctp->sctp_primary) == 0) { 10531676Sjpk gotv4 = 1; 1054*11042SErik.Nordmark@Sun.COM if (connp->conn_family == AF_INET) { 1055*11042SErik.Nordmark@Sun.COM goto done; 10561676Sjpk } 10570Sstevel@tonic-gate } 10580Sstevel@tonic-gate } else { 1059*11042SErik.Nordmark@Sun.COM if (!is_system_labeled() || 1060*11042SErik.Nordmark@Sun.COM sctp_v6_label(sctp, sctp->sctp_primary) == 0) { 10611676Sjpk gotv6 = 1; 1062*11042SErik.Nordmark@Sun.COM } 10630Sstevel@tonic-gate } 10640Sstevel@tonic-gate 10650Sstevel@tonic-gate for (fp = sctp->sctp_faddrs; fp; fp = fp->next) { 10660Sstevel@tonic-gate if (!gotv4 && IN6_IS_ADDR_V4MAPPED(&fp->faddr)) { 1067*11042SErik.Nordmark@Sun.COM if (!is_system_labeled() || 1068*11042SErik.Nordmark@Sun.COM sctp_v4_label(sctp, fp) == 0) { 10691676Sjpk gotv4 = 1; 1070*11042SErik.Nordmark@Sun.COM if (connp->conn_family == AF_INET || gotv6) { 10711676Sjpk break; 10721676Sjpk } 10730Sstevel@tonic-gate } 10742283Skp158701 } else if (!gotv6 && !IN6_IS_ADDR_V4MAPPED(&fp->faddr)) { 1075*11042SErik.Nordmark@Sun.COM if (!is_system_labeled() || 1076*11042SErik.Nordmark@Sun.COM sctp_v6_label(sctp, fp) == 0) { 10771676Sjpk gotv6 = 1; 10781676Sjpk if (gotv4) 10791676Sjpk break; 10800Sstevel@tonic-gate } 10810Sstevel@tonic-gate } 10820Sstevel@tonic-gate } 10830Sstevel@tonic-gate 1084*11042SErik.Nordmark@Sun.COM done: 10851676Sjpk if (!gotv4 && !gotv6) 10861676Sjpk return (EACCES); 10871676Sjpk 10881676Sjpk return (0); 10890Sstevel@tonic-gate } 10900Sstevel@tonic-gate 10918549SGeorge.Shepherd@Sun.COM /* 10928549SGeorge.Shepherd@Sun.COM * got_errchunk is set B_TRUE only if called from validate_init_params(), when 10938549SGeorge.Shepherd@Sun.COM * an ERROR chunk is already prepended the size of which needs updating for 10948549SGeorge.Shepherd@Sun.COM * additional unrecognized parameters. Other callers either prepend the ERROR 10958549SGeorge.Shepherd@Sun.COM * chunk with the correct size after calling this function, or they are calling 10968549SGeorge.Shepherd@Sun.COM * to add an invalid parameter to an INIT_ACK chunk, in that case no ERROR chunk 10978549SGeorge.Shepherd@Sun.COM * exists, the CAUSE blocks go into the INIT_ACK directly. 10988549SGeorge.Shepherd@Sun.COM * 10998549SGeorge.Shepherd@Sun.COM * *errmp will be non-NULL both when adding an additional CAUSE block to an 11008549SGeorge.Shepherd@Sun.COM * existing prepended COOKIE ERROR chunk (processing params of an INIT_ACK), 11018549SGeorge.Shepherd@Sun.COM * and when adding unrecognized parameters after the first, to an INIT_ACK 11028549SGeorge.Shepherd@Sun.COM * (processing params of an INIT chunk). 11038549SGeorge.Shepherd@Sun.COM */ 11040Sstevel@tonic-gate void 11058549SGeorge.Shepherd@Sun.COM sctp_add_unrec_parm(sctp_parm_hdr_t *uph, mblk_t **errmp, 11068549SGeorge.Shepherd@Sun.COM boolean_t got_errchunk) 11070Sstevel@tonic-gate { 11080Sstevel@tonic-gate mblk_t *mp; 11090Sstevel@tonic-gate sctp_parm_hdr_t *ph; 11100Sstevel@tonic-gate size_t len; 11110Sstevel@tonic-gate int pad; 11128153SGeorge.Shepherd@Sun.COM sctp_chunk_hdr_t *ecp; 11130Sstevel@tonic-gate 11140Sstevel@tonic-gate len = sizeof (*ph) + ntohs(uph->sph_len); 11158153SGeorge.Shepherd@Sun.COM if ((pad = len % SCTP_ALIGN) != 0) { 11168153SGeorge.Shepherd@Sun.COM pad = SCTP_ALIGN - pad; 11170Sstevel@tonic-gate len += pad; 11180Sstevel@tonic-gate } 11190Sstevel@tonic-gate mp = allocb(len, BPRI_MED); 11200Sstevel@tonic-gate if (mp == NULL) { 11210Sstevel@tonic-gate return; 11220Sstevel@tonic-gate } 11230Sstevel@tonic-gate 11240Sstevel@tonic-gate ph = (sctp_parm_hdr_t *)(mp->b_rptr); 11250Sstevel@tonic-gate ph->sph_type = htons(PARM_UNRECOGNIZED); 11260Sstevel@tonic-gate ph->sph_len = htons(len - pad); 11270Sstevel@tonic-gate 11280Sstevel@tonic-gate /* copy in the unrecognized parameter */ 11290Sstevel@tonic-gate bcopy(uph, ph + 1, ntohs(uph->sph_len)); 11300Sstevel@tonic-gate 11318153SGeorge.Shepherd@Sun.COM if (pad != 0) 11328153SGeorge.Shepherd@Sun.COM bzero((mp->b_rptr + len - pad), pad); 11338153SGeorge.Shepherd@Sun.COM 11340Sstevel@tonic-gate mp->b_wptr = mp->b_rptr + len; 11350Sstevel@tonic-gate if (*errmp != NULL) { 11368153SGeorge.Shepherd@Sun.COM /* 11378549SGeorge.Shepherd@Sun.COM * Update total length if an ERROR chunk, then link 11388549SGeorge.Shepherd@Sun.COM * this CAUSE block to the possible chain of CAUSE 11398549SGeorge.Shepherd@Sun.COM * blocks attached to the ERROR chunk or INIT_ACK 11408549SGeorge.Shepherd@Sun.COM * being created. 11418153SGeorge.Shepherd@Sun.COM */ 11428549SGeorge.Shepherd@Sun.COM if (got_errchunk) { 11438549SGeorge.Shepherd@Sun.COM /* ERROR chunk already prepended */ 11448549SGeorge.Shepherd@Sun.COM ecp = (sctp_chunk_hdr_t *)((*errmp)->b_rptr); 11458549SGeorge.Shepherd@Sun.COM ecp->sch_len = htons(ntohs(ecp->sch_len) + len); 11468549SGeorge.Shepherd@Sun.COM } 11470Sstevel@tonic-gate linkb(*errmp, mp); 11480Sstevel@tonic-gate } else { 11490Sstevel@tonic-gate *errmp = mp; 11500Sstevel@tonic-gate } 11510Sstevel@tonic-gate } 11520Sstevel@tonic-gate 11530Sstevel@tonic-gate /* 11540Sstevel@tonic-gate * o Bounds checking 11550Sstevel@tonic-gate * o Updates remaining 11560Sstevel@tonic-gate * o Checks alignment 11570Sstevel@tonic-gate */ 11580Sstevel@tonic-gate sctp_parm_hdr_t * 11590Sstevel@tonic-gate sctp_next_parm(sctp_parm_hdr_t *current, ssize_t *remaining) 11600Sstevel@tonic-gate { 11610Sstevel@tonic-gate int pad; 11620Sstevel@tonic-gate uint16_t len; 11630Sstevel@tonic-gate 11640Sstevel@tonic-gate len = ntohs(current->sph_len); 11650Sstevel@tonic-gate *remaining -= len; 11660Sstevel@tonic-gate if (*remaining < sizeof (*current) || len < sizeof (*current)) { 11670Sstevel@tonic-gate return (NULL); 11680Sstevel@tonic-gate } 11690Sstevel@tonic-gate if ((pad = len & (SCTP_ALIGN - 1)) != 0) { 11700Sstevel@tonic-gate pad = SCTP_ALIGN - pad; 11710Sstevel@tonic-gate *remaining -= pad; 11720Sstevel@tonic-gate } 11730Sstevel@tonic-gate /*LINTED pointer cast may result in improper alignment*/ 11740Sstevel@tonic-gate current = (sctp_parm_hdr_t *)((char *)current + len + pad); 11750Sstevel@tonic-gate return (current); 11760Sstevel@tonic-gate } 11770Sstevel@tonic-gate 11780Sstevel@tonic-gate /* 11790Sstevel@tonic-gate * Sets the address parameters given in the INIT chunk into sctp's 11800Sstevel@tonic-gate * faddrs; if psctp is non-NULL, copies psctp's saddrs. If there are 11810Sstevel@tonic-gate * no address parameters in the INIT chunk, a single faddr is created 11820Sstevel@tonic-gate * from the ip hdr at the beginning of pkt. 11830Sstevel@tonic-gate * If there already are existing addresses hanging from sctp, merge 11840Sstevel@tonic-gate * them in, if the old info contains addresses which are not present 11850Sstevel@tonic-gate * in this new info, get rid of them, and clean the pointers if there's 11860Sstevel@tonic-gate * messages which have this as their target address. 11870Sstevel@tonic-gate * 1188432Svi117747 * We also re-adjust the source address list here since the list may 1189432Svi117747 * contain more than what is actually part of the association. If 1190432Svi117747 * we get here from sctp_send_cookie_echo(), we are on the active 1191432Svi117747 * side and psctp will be NULL and ich will be the INIT-ACK chunk. 1192432Svi117747 * If we get here from sctp_accept_comm(), ich will be the INIT chunk 1193432Svi117747 * and psctp will the listening endpoint. 1194432Svi117747 * 1195432Svi117747 * INIT processing: When processing the INIT we inherit the src address 1196432Svi117747 * list from the listener. For a loopback or linklocal association, we 1197432Svi117747 * delete the list and just take the address from the IP header (since 1198432Svi117747 * that's how we created the INIT-ACK). Additionally, for loopback we 1199432Svi117747 * ignore the address params in the INIT. For determining which address 1200432Svi117747 * types were sent in the INIT-ACK we follow the same logic as in 1201432Svi117747 * creating the INIT-ACK. We delete addresses of the type that are not 1202432Svi117747 * supported by the peer. 1203432Svi117747 * 1204432Svi117747 * INIT-ACK processing: When processing the INIT-ACK since we had not 1205432Svi117747 * included addr params for loopback or linklocal addresses when creating 1206432Svi117747 * the INIT, we just use the address from the IP header. Further, for 1207432Svi117747 * loopback we ignore the addr param list. We mark addresses of the 1208432Svi117747 * type not supported by the peer as unconfirmed. 1209432Svi117747 * 1210432Svi117747 * In case of INIT processing we look for supported address types in the 1211432Svi117747 * supported address param, if present. In both cases the address type in 1212432Svi117747 * the IP header is supported as well as types for addresses in the param 1213432Svi117747 * list, if any. 1214432Svi117747 * 1215432Svi117747 * Once we have the supported address types sctp_check_saddr() runs through 1216432Svi117747 * the source address list and deletes or marks as unconfirmed address of 1217432Svi117747 * types not supported by the peer. 1218432Svi117747 * 12190Sstevel@tonic-gate * Returns 0 on success, sys errno on failure 12200Sstevel@tonic-gate */ 12210Sstevel@tonic-gate int 12220Sstevel@tonic-gate sctp_get_addrparams(sctp_t *sctp, sctp_t *psctp, mblk_t *pkt, 12230Sstevel@tonic-gate sctp_chunk_hdr_t *ich, uint_t *sctp_options) 12240Sstevel@tonic-gate { 12250Sstevel@tonic-gate sctp_init_chunk_t *init; 12260Sstevel@tonic-gate ipha_t *iph; 12270Sstevel@tonic-gate ip6_t *ip6h; 1228432Svi117747 in6_addr_t hdrsaddr[1]; 1229432Svi117747 in6_addr_t hdrdaddr[1]; 12300Sstevel@tonic-gate sctp_parm_hdr_t *ph; 12310Sstevel@tonic-gate ssize_t remaining; 12320Sstevel@tonic-gate int isv4; 12330Sstevel@tonic-gate int err; 12340Sstevel@tonic-gate sctp_faddr_t *fp; 1235432Svi117747 int supp_af = 0; 1236432Svi117747 boolean_t check_saddr = B_TRUE; 1237852Svi117747 in6_addr_t curaddr; 12383448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 1239*11042SErik.Nordmark@Sun.COM conn_t *connp = sctp->sctp_connp; 12400Sstevel@tonic-gate 12410Sstevel@tonic-gate if (sctp_options != NULL) 12420Sstevel@tonic-gate *sctp_options = 0; 12430Sstevel@tonic-gate 1244432Svi117747 /* extract the address from the IP header */ 1245432Svi117747 isv4 = (IPH_HDR_VERSION(pkt->b_rptr) == IPV4_VERSION); 1246432Svi117747 if (isv4) { 1247432Svi117747 iph = (ipha_t *)pkt->b_rptr; 1248432Svi117747 IN6_IPADDR_TO_V4MAPPED(iph->ipha_src, hdrsaddr); 1249432Svi117747 IN6_IPADDR_TO_V4MAPPED(iph->ipha_dst, hdrdaddr); 1250432Svi117747 supp_af |= PARM_SUPP_V4; 1251432Svi117747 } else { 1252432Svi117747 ip6h = (ip6_t *)pkt->b_rptr; 1253432Svi117747 hdrsaddr[0] = ip6h->ip6_src; 1254432Svi117747 hdrdaddr[0] = ip6h->ip6_dst; 1255432Svi117747 supp_af |= PARM_SUPP_V6; 1256432Svi117747 } 1257432Svi117747 1258432Svi117747 /* 1259432Svi117747 * Unfortunately, we can't delay this because adding an faddr 1260432Svi117747 * looks for the presence of the source address (from the ire 1261432Svi117747 * for the faddr) in the source address list. We could have 1262432Svi117747 * delayed this if, say, this was a loopback/linklocal connection. 1263432Svi117747 * Now, we just end up nuking this list and taking the addr from 1264432Svi117747 * the IP header for loopback/linklocal. 1265432Svi117747 */ 12660Sstevel@tonic-gate if (psctp != NULL && psctp->sctp_nsaddrs > 0) { 12670Sstevel@tonic-gate ASSERT(sctp->sctp_nsaddrs == 0); 12680Sstevel@tonic-gate 12690Sstevel@tonic-gate err = sctp_dup_saddrs(psctp, sctp, KM_NOSLEEP); 12700Sstevel@tonic-gate if (err != 0) 12710Sstevel@tonic-gate return (err); 12720Sstevel@tonic-gate } 1273432Svi117747 /* 1274432Svi117747 * We will add the faddr before parsing the address list as this 1275432Svi117747 * might be a loopback connection and we would not have to 1276432Svi117747 * go through the list. 1277432Svi117747 * 1278432Svi117747 * Make sure the header's addr is in the list 1279432Svi117747 */ 1280432Svi117747 fp = sctp_lookup_faddr(sctp, hdrsaddr); 1281432Svi117747 if (fp == NULL) { 1282432Svi117747 /* not included; add it now */ 12831735Skcpoon err = sctp_add_faddr(sctp, hdrsaddr, KM_NOSLEEP, B_TRUE); 12841676Sjpk if (err != 0) 12851676Sjpk return (err); 12860Sstevel@tonic-gate 1287432Svi117747 /* sctp_faddrs will be the hdr addr */ 1288432Svi117747 fp = sctp->sctp_faddrs; 12890Sstevel@tonic-gate } 1290432Svi117747 /* make the header addr the primary */ 1291852Svi117747 1292852Svi117747 if (cl_sctp_assoc_change != NULL && psctp == NULL) 1293852Svi117747 curaddr = sctp->sctp_current->faddr; 1294852Svi117747 1295432Svi117747 sctp->sctp_primary = fp; 1296432Svi117747 sctp->sctp_current = fp; 1297432Svi117747 sctp->sctp_mss = fp->sfa_pmss; 12980Sstevel@tonic-gate 1299432Svi117747 /* For loopback connections & linklocal get address from the header */ 1300432Svi117747 if (sctp->sctp_loopback || sctp->sctp_linklocal) { 1301432Svi117747 if (sctp->sctp_nsaddrs != 0) 1302432Svi117747 sctp_free_saddrs(sctp); 1303852Svi117747 if ((err = sctp_saddr_add_addr(sctp, hdrdaddr, 0)) != 0) 1304432Svi117747 return (err); 1305432Svi117747 /* For loopback ignore address list */ 1306432Svi117747 if (sctp->sctp_loopback) 1307432Svi117747 return (0); 1308432Svi117747 check_saddr = B_FALSE; 1309432Svi117747 } 13100Sstevel@tonic-gate 13110Sstevel@tonic-gate /* Walk the params in the INIT [ACK], pulling out addr params */ 13120Sstevel@tonic-gate remaining = ntohs(ich->sch_len) - sizeof (*ich) - 13130Sstevel@tonic-gate sizeof (sctp_init_chunk_t); 13140Sstevel@tonic-gate if (remaining < sizeof (*ph)) { 1315432Svi117747 if (check_saddr) { 1316432Svi117747 sctp_check_saddr(sctp, supp_af, psctp == NULL ? 13174818Skcpoon B_FALSE : B_TRUE, hdrdaddr); 1318432Svi117747 } 1319852Svi117747 ASSERT(sctp_saddr_lookup(sctp, hdrdaddr, 0) != NULL); 1320432Svi117747 return (0); 13210Sstevel@tonic-gate } 1322432Svi117747 13230Sstevel@tonic-gate init = (sctp_init_chunk_t *)(ich + 1); 13240Sstevel@tonic-gate ph = (sctp_parm_hdr_t *)(init + 1); 13250Sstevel@tonic-gate 1326432Svi117747 /* params will have already been byteordered when validating */ 13270Sstevel@tonic-gate while (ph != NULL) { 1328432Svi117747 if (ph->sph_type == htons(PARM_SUPP_ADDRS)) { 1329432Svi117747 int plen; 1330432Svi117747 uint16_t *p; 1331432Svi117747 uint16_t addrtype; 1332432Svi117747 1333432Svi117747 ASSERT(psctp != NULL); 1334432Svi117747 plen = ntohs(ph->sph_len); 1335432Svi117747 p = (uint16_t *)(ph + 1); 1336432Svi117747 while (plen > 0) { 1337432Svi117747 addrtype = ntohs(*p); 1338432Svi117747 switch (addrtype) { 1339432Svi117747 case PARM_ADDR6: 1340432Svi117747 supp_af |= PARM_SUPP_V6; 1341432Svi117747 break; 1342432Svi117747 case PARM_ADDR4: 1343432Svi117747 supp_af |= PARM_SUPP_V4; 1344432Svi117747 break; 1345432Svi117747 default: 1346432Svi117747 break; 1347432Svi117747 } 1348432Svi117747 p++; 1349432Svi117747 plen -= sizeof (*p); 1350432Svi117747 } 1351432Svi117747 } else if (ph->sph_type == htons(PARM_ADDR4)) { 13520Sstevel@tonic-gate if (remaining >= PARM_ADDR4_LEN) { 13530Sstevel@tonic-gate in6_addr_t addr; 13540Sstevel@tonic-gate ipaddr_t ta; 13550Sstevel@tonic-gate 1356432Svi117747 supp_af |= PARM_SUPP_V4; 13570Sstevel@tonic-gate /* 13580Sstevel@tonic-gate * Screen out broad/multicasts & loopback. 13590Sstevel@tonic-gate * If the endpoint only accepts v6 address, 13600Sstevel@tonic-gate * go to the next one. 13614818Skcpoon * 13624818Skcpoon * Subnet broadcast check is done in 13634818Skcpoon * sctp_add_faddr(). If the address is 13644818Skcpoon * a broadcast address, it won't be added. 13650Sstevel@tonic-gate */ 13660Sstevel@tonic-gate bcopy(ph + 1, &ta, sizeof (ta)); 13670Sstevel@tonic-gate if (ta == 0 || 13680Sstevel@tonic-gate ta == INADDR_BROADCAST || 13690Sstevel@tonic-gate ta == htonl(INADDR_LOOPBACK) || 1370*11042SErik.Nordmark@Sun.COM CLASSD(ta) || connp->conn_ipv6_v6only) { 13710Sstevel@tonic-gate goto next; 13720Sstevel@tonic-gate } 13730Sstevel@tonic-gate IN6_INADDR_TO_V4MAPPED((struct in_addr *) 13740Sstevel@tonic-gate (ph + 1), &addr); 13754818Skcpoon 13760Sstevel@tonic-gate /* Check for duplicate. */ 13770Sstevel@tonic-gate if (sctp_lookup_faddr(sctp, &addr) != NULL) 13780Sstevel@tonic-gate goto next; 13790Sstevel@tonic-gate 13800Sstevel@tonic-gate /* OK, add it to the faddr set */ 13811735Skcpoon err = sctp_add_faddr(sctp, &addr, KM_NOSLEEP, 13821735Skcpoon B_FALSE); 13834818Skcpoon /* Something is wrong... Try the next one. */ 13841676Sjpk if (err != 0) 13854818Skcpoon goto next; 13860Sstevel@tonic-gate } 13870Sstevel@tonic-gate } else if (ph->sph_type == htons(PARM_ADDR6) && 1388*11042SErik.Nordmark@Sun.COM connp->conn_family == AF_INET6) { 13890Sstevel@tonic-gate /* An v4 socket should not take v6 addresses. */ 13900Sstevel@tonic-gate if (remaining >= PARM_ADDR6_LEN) { 13910Sstevel@tonic-gate in6_addr_t *addr6; 13920Sstevel@tonic-gate 1393432Svi117747 supp_af |= PARM_SUPP_V6; 13940Sstevel@tonic-gate addr6 = (in6_addr_t *)(ph + 1); 13950Sstevel@tonic-gate /* 13960Sstevel@tonic-gate * Screen out link locals, mcast, loopback 13970Sstevel@tonic-gate * and bogus v6 address. 13980Sstevel@tonic-gate */ 13990Sstevel@tonic-gate if (IN6_IS_ADDR_LINKLOCAL(addr6) || 14000Sstevel@tonic-gate IN6_IS_ADDR_MULTICAST(addr6) || 14010Sstevel@tonic-gate IN6_IS_ADDR_LOOPBACK(addr6) || 14020Sstevel@tonic-gate IN6_IS_ADDR_V4MAPPED(addr6)) { 14030Sstevel@tonic-gate goto next; 14040Sstevel@tonic-gate } 14050Sstevel@tonic-gate /* Check for duplicate. */ 14060Sstevel@tonic-gate if (sctp_lookup_faddr(sctp, addr6) != NULL) 14070Sstevel@tonic-gate goto next; 14080Sstevel@tonic-gate 14091676Sjpk err = sctp_add_faddr(sctp, 14101735Skcpoon (in6_addr_t *)(ph + 1), KM_NOSLEEP, 14111735Skcpoon B_FALSE); 14124818Skcpoon /* Something is wrong... Try the next one. */ 14131676Sjpk if (err != 0) 14144818Skcpoon goto next; 14150Sstevel@tonic-gate } 14160Sstevel@tonic-gate } else if (ph->sph_type == htons(PARM_FORWARD_TSN)) { 14170Sstevel@tonic-gate if (sctp_options != NULL) 14180Sstevel@tonic-gate *sctp_options |= SCTP_PRSCTP_OPTION; 14190Sstevel@tonic-gate } /* else; skip */ 14200Sstevel@tonic-gate 14210Sstevel@tonic-gate next: 14220Sstevel@tonic-gate ph = sctp_next_parm(ph, &remaining); 14230Sstevel@tonic-gate } 1424432Svi117747 if (check_saddr) { 1425432Svi117747 sctp_check_saddr(sctp, supp_af, psctp == NULL ? B_FALSE : 14264818Skcpoon B_TRUE, hdrdaddr); 14270Sstevel@tonic-gate } 1428852Svi117747 ASSERT(sctp_saddr_lookup(sctp, hdrdaddr, 0) != NULL); 1429852Svi117747 /* 1430852Svi117747 * We have the right address list now, update clustering's 1431852Svi117747 * knowledge because when we sent the INIT we had just added 1432852Svi117747 * the address the INIT was sent to. 1433852Svi117747 */ 1434852Svi117747 if (psctp == NULL && cl_sctp_assoc_change != NULL) { 1435852Svi117747 uchar_t *alist; 1436852Svi117747 size_t asize; 1437852Svi117747 uchar_t *dlist; 1438852Svi117747 size_t dsize; 1439852Svi117747 1440852Svi117747 asize = sizeof (in6_addr_t) * sctp->sctp_nfaddrs; 1441852Svi117747 alist = kmem_alloc(asize, KM_NOSLEEP); 14421735Skcpoon if (alist == NULL) { 14433448Sdh155122 SCTP_KSTAT(sctps, sctp_cl_assoc_change); 1444852Svi117747 return (ENOMEM); 14451735Skcpoon } 1446852Svi117747 /* 1447852Svi117747 * Just include the address the INIT was sent to in the 1448852Svi117747 * delete list and send the entire faddr list. We could 1449852Svi117747 * do it differently (i.e include all the addresses in the 1450852Svi117747 * add list even if it contains the original address OR 1451852Svi117747 * remove the original address from the add list etc.), but 1452852Svi117747 * this seems reasonable enough. 1453852Svi117747 */ 1454852Svi117747 dsize = sizeof (in6_addr_t); 1455852Svi117747 dlist = kmem_alloc(dsize, KM_NOSLEEP); 1456852Svi117747 if (dlist == NULL) { 1457852Svi117747 kmem_free(alist, asize); 14583448Sdh155122 SCTP_KSTAT(sctps, sctp_cl_assoc_change); 1459852Svi117747 return (ENOMEM); 1460852Svi117747 } 1461852Svi117747 bcopy(&curaddr, dlist, sizeof (curaddr)); 1462852Svi117747 sctp_get_faddr_list(sctp, alist, asize); 1463*11042SErik.Nordmark@Sun.COM (*cl_sctp_assoc_change)(connp->conn_family, alist, asize, 1464852Svi117747 sctp->sctp_nfaddrs, dlist, dsize, 1, SCTP_CL_PADDR, 1465852Svi117747 (cl_sctp_handle_t)sctp); 1466852Svi117747 /* alist and dlist will be freed by the clustering module */ 1467852Svi117747 } 14680Sstevel@tonic-gate return (0); 14690Sstevel@tonic-gate } 14700Sstevel@tonic-gate 14710Sstevel@tonic-gate /* 14720Sstevel@tonic-gate * Returns 0 if the check failed and the restart should be refused, 14730Sstevel@tonic-gate * 1 if the check succeeded. 14740Sstevel@tonic-gate */ 14750Sstevel@tonic-gate int 14760Sstevel@tonic-gate sctp_secure_restart_check(mblk_t *pkt, sctp_chunk_hdr_t *ich, uint32_t ports, 1477*11042SErik.Nordmark@Sun.COM int sleep, sctp_stack_t *sctps, ip_recv_attr_t *ira) 14780Sstevel@tonic-gate { 14794964Skcpoon sctp_faddr_t *fp, *fphead = NULL; 14800Sstevel@tonic-gate sctp_parm_hdr_t *ph; 14810Sstevel@tonic-gate ssize_t remaining; 14820Sstevel@tonic-gate int isv4; 14830Sstevel@tonic-gate ipha_t *iph; 14840Sstevel@tonic-gate ip6_t *ip6h; 14850Sstevel@tonic-gate in6_addr_t hdraddr[1]; 14860Sstevel@tonic-gate int retval = 0; 14870Sstevel@tonic-gate sctp_tf_t *tf; 14880Sstevel@tonic-gate sctp_t *sctp; 14890Sstevel@tonic-gate int compres; 14900Sstevel@tonic-gate sctp_init_chunk_t *init; 14910Sstevel@tonic-gate int nadded = 0; 14920Sstevel@tonic-gate 14930Sstevel@tonic-gate /* extract the address from the IP header */ 14940Sstevel@tonic-gate isv4 = (IPH_HDR_VERSION(pkt->b_rptr) == IPV4_VERSION); 14950Sstevel@tonic-gate if (isv4) { 14960Sstevel@tonic-gate iph = (ipha_t *)pkt->b_rptr; 14970Sstevel@tonic-gate IN6_IPADDR_TO_V4MAPPED(iph->ipha_src, hdraddr); 14980Sstevel@tonic-gate } else { 14990Sstevel@tonic-gate ip6h = (ip6_t *)pkt->b_rptr; 15000Sstevel@tonic-gate hdraddr[0] = ip6h->ip6_src; 15010Sstevel@tonic-gate } 15020Sstevel@tonic-gate 15030Sstevel@tonic-gate /* Walk the params in the INIT [ACK], pulling out addr params */ 15040Sstevel@tonic-gate remaining = ntohs(ich->sch_len) - sizeof (*ich) - 15050Sstevel@tonic-gate sizeof (sctp_init_chunk_t); 15060Sstevel@tonic-gate if (remaining < sizeof (*ph)) { 15070Sstevel@tonic-gate /* no parameters; restart OK */ 15080Sstevel@tonic-gate return (1); 15090Sstevel@tonic-gate } 15100Sstevel@tonic-gate init = (sctp_init_chunk_t *)(ich + 1); 15110Sstevel@tonic-gate ph = (sctp_parm_hdr_t *)(init + 1); 15120Sstevel@tonic-gate 15130Sstevel@tonic-gate while (ph != NULL) { 15144964Skcpoon sctp_faddr_t *fpa = NULL; 15154964Skcpoon 15160Sstevel@tonic-gate /* params will have already been byteordered when validating */ 15170Sstevel@tonic-gate if (ph->sph_type == htons(PARM_ADDR4)) { 15180Sstevel@tonic-gate if (remaining >= PARM_ADDR4_LEN) { 15190Sstevel@tonic-gate in6_addr_t addr; 15200Sstevel@tonic-gate IN6_INADDR_TO_V4MAPPED((struct in_addr *) 15210Sstevel@tonic-gate (ph + 1), &addr); 15220Sstevel@tonic-gate fpa = kmem_cache_alloc(sctp_kmem_faddr_cache, 15230Sstevel@tonic-gate sleep); 15244964Skcpoon if (fpa == NULL) { 15250Sstevel@tonic-gate goto done; 15260Sstevel@tonic-gate } 15270Sstevel@tonic-gate bzero(fpa, sizeof (*fpa)); 15280Sstevel@tonic-gate fpa->faddr = addr; 15290Sstevel@tonic-gate fpa->next = NULL; 15300Sstevel@tonic-gate } 15310Sstevel@tonic-gate } else if (ph->sph_type == htons(PARM_ADDR6)) { 15320Sstevel@tonic-gate if (remaining >= PARM_ADDR6_LEN) { 15330Sstevel@tonic-gate fpa = kmem_cache_alloc(sctp_kmem_faddr_cache, 15340Sstevel@tonic-gate sleep); 15354964Skcpoon if (fpa == NULL) { 15360Sstevel@tonic-gate goto done; 15370Sstevel@tonic-gate } 15380Sstevel@tonic-gate bzero(fpa, sizeof (*fpa)); 15390Sstevel@tonic-gate bcopy(ph + 1, &fpa->faddr, 15400Sstevel@tonic-gate sizeof (fpa->faddr)); 15410Sstevel@tonic-gate fpa->next = NULL; 15420Sstevel@tonic-gate } 15430Sstevel@tonic-gate } 15440Sstevel@tonic-gate /* link in the new addr, if it was an addr param */ 15454964Skcpoon if (fpa != NULL) { 15464964Skcpoon if (fphead == NULL) { 15470Sstevel@tonic-gate fphead = fpa; 15480Sstevel@tonic-gate } else { 15494964Skcpoon fpa->next = fphead; 15504964Skcpoon fphead = fpa; 15510Sstevel@tonic-gate } 15520Sstevel@tonic-gate } 15530Sstevel@tonic-gate 15540Sstevel@tonic-gate ph = sctp_next_parm(ph, &remaining); 15550Sstevel@tonic-gate } 15560Sstevel@tonic-gate 15570Sstevel@tonic-gate if (fphead == NULL) { 15580Sstevel@tonic-gate /* no addr parameters; restart OK */ 15590Sstevel@tonic-gate return (1); 15600Sstevel@tonic-gate } 15610Sstevel@tonic-gate 15620Sstevel@tonic-gate /* 15630Sstevel@tonic-gate * got at least one; make sure the header's addr is 15640Sstevel@tonic-gate * in the list 15650Sstevel@tonic-gate */ 15660Sstevel@tonic-gate fp = sctp_lookup_faddr_nosctp(fphead, hdraddr); 15674964Skcpoon if (fp == NULL) { 15680Sstevel@tonic-gate /* not included; add it now */ 15690Sstevel@tonic-gate fp = kmem_cache_alloc(sctp_kmem_faddr_cache, sleep); 15704964Skcpoon if (fp == NULL) { 15710Sstevel@tonic-gate goto done; 15720Sstevel@tonic-gate } 15730Sstevel@tonic-gate bzero(fp, sizeof (*fp)); 15740Sstevel@tonic-gate fp->faddr = *hdraddr; 15750Sstevel@tonic-gate fp->next = fphead; 15760Sstevel@tonic-gate fphead = fp; 15770Sstevel@tonic-gate } 15780Sstevel@tonic-gate 15790Sstevel@tonic-gate /* 15800Sstevel@tonic-gate * Now, we can finally do the check: For each sctp instance 15810Sstevel@tonic-gate * on the hash line for ports, compare its faddr set against 15820Sstevel@tonic-gate * the new one. If the new one is a strict subset of any 15830Sstevel@tonic-gate * existing sctp's faddrs, the restart is OK. However, if there 15840Sstevel@tonic-gate * is an overlap, this could be an attack, so return failure. 15850Sstevel@tonic-gate * If all sctp's faddrs are disjoint, this is a legitimate new 15860Sstevel@tonic-gate * association. 15870Sstevel@tonic-gate */ 15883448Sdh155122 tf = &(sctps->sctps_conn_fanout[SCTP_CONN_HASH(sctps, ports)]); 15890Sstevel@tonic-gate mutex_enter(&tf->tf_lock); 15900Sstevel@tonic-gate 15910Sstevel@tonic-gate for (sctp = tf->tf_sctp; sctp; sctp = sctp->sctp_conn_hash_next) { 1592*11042SErik.Nordmark@Sun.COM if (ports != sctp->sctp_connp->conn_ports) { 15930Sstevel@tonic-gate continue; 15940Sstevel@tonic-gate } 15950Sstevel@tonic-gate compres = sctp_compare_faddrsets(fphead, sctp->sctp_faddrs); 15960Sstevel@tonic-gate if (compres <= SCTP_ADDR_SUBSET) { 15970Sstevel@tonic-gate retval = 1; 15980Sstevel@tonic-gate mutex_exit(&tf->tf_lock); 15990Sstevel@tonic-gate goto done; 16000Sstevel@tonic-gate } 16010Sstevel@tonic-gate if (compres == SCTP_ADDR_OVERLAP) { 16020Sstevel@tonic-gate dprint(1, 16030Sstevel@tonic-gate ("new assoc from %x:%x:%x:%x overlaps with %p\n", 16041676Sjpk SCTP_PRINTADDR(*hdraddr), (void *)sctp)); 16050Sstevel@tonic-gate /* 16060Sstevel@tonic-gate * While we still hold the lock, we need to 16070Sstevel@tonic-gate * figure out which addresses have been 16080Sstevel@tonic-gate * added so we can include them in the abort 16090Sstevel@tonic-gate * we will send back. Since these faddrs will 16100Sstevel@tonic-gate * never be used, we overload the rto field 16110Sstevel@tonic-gate * here, setting it to 0 if the address was 16120Sstevel@tonic-gate * not added, 1 if it was added. 16130Sstevel@tonic-gate */ 16140Sstevel@tonic-gate for (fp = fphead; fp; fp = fp->next) { 16150Sstevel@tonic-gate if (sctp_lookup_faddr(sctp, &fp->faddr)) { 16160Sstevel@tonic-gate fp->rto = 0; 16170Sstevel@tonic-gate } else { 16180Sstevel@tonic-gate fp->rto = 1; 16190Sstevel@tonic-gate nadded++; 16200Sstevel@tonic-gate } 16210Sstevel@tonic-gate } 16220Sstevel@tonic-gate mutex_exit(&tf->tf_lock); 16230Sstevel@tonic-gate goto done; 16240Sstevel@tonic-gate } 16250Sstevel@tonic-gate } 16260Sstevel@tonic-gate mutex_exit(&tf->tf_lock); 16270Sstevel@tonic-gate 16280Sstevel@tonic-gate /* All faddrs are disjoint; legit new association */ 16290Sstevel@tonic-gate retval = 1; 16300Sstevel@tonic-gate 16310Sstevel@tonic-gate done: 16320Sstevel@tonic-gate /* If are attempted adds, send back an abort listing the addrs */ 16330Sstevel@tonic-gate if (nadded > 0) { 16340Sstevel@tonic-gate void *dtail; 16350Sstevel@tonic-gate size_t dlen; 16360Sstevel@tonic-gate 16370Sstevel@tonic-gate dtail = kmem_alloc(PARM_ADDR6_LEN * nadded, KM_NOSLEEP); 16380Sstevel@tonic-gate if (dtail == NULL) { 16390Sstevel@tonic-gate goto cleanup; 16400Sstevel@tonic-gate } 16410Sstevel@tonic-gate 16420Sstevel@tonic-gate ph = dtail; 16430Sstevel@tonic-gate dlen = 0; 16440Sstevel@tonic-gate for (fp = fphead; fp; fp = fp->next) { 16450Sstevel@tonic-gate if (fp->rto == 0) { 16460Sstevel@tonic-gate continue; 16470Sstevel@tonic-gate } 16480Sstevel@tonic-gate if (IN6_IS_ADDR_V4MAPPED(&fp->faddr)) { 16490Sstevel@tonic-gate ipaddr_t addr4; 16500Sstevel@tonic-gate 16510Sstevel@tonic-gate ph->sph_type = htons(PARM_ADDR4); 16520Sstevel@tonic-gate ph->sph_len = htons(PARM_ADDR4_LEN); 16530Sstevel@tonic-gate IN6_V4MAPPED_TO_IPADDR(&fp->faddr, addr4); 16540Sstevel@tonic-gate ph++; 16550Sstevel@tonic-gate bcopy(&addr4, ph, sizeof (addr4)); 16560Sstevel@tonic-gate ph = (sctp_parm_hdr_t *) 16570Sstevel@tonic-gate ((char *)ph + sizeof (addr4)); 16580Sstevel@tonic-gate dlen += PARM_ADDR4_LEN; 16590Sstevel@tonic-gate } else { 16600Sstevel@tonic-gate ph->sph_type = htons(PARM_ADDR6); 16610Sstevel@tonic-gate ph->sph_len = htons(PARM_ADDR6_LEN); 16620Sstevel@tonic-gate ph++; 16630Sstevel@tonic-gate bcopy(&fp->faddr, ph, sizeof (fp->faddr)); 16640Sstevel@tonic-gate ph = (sctp_parm_hdr_t *) 16650Sstevel@tonic-gate ((char *)ph + sizeof (fp->faddr)); 16660Sstevel@tonic-gate dlen += PARM_ADDR6_LEN; 16670Sstevel@tonic-gate } 16680Sstevel@tonic-gate } 16690Sstevel@tonic-gate 16700Sstevel@tonic-gate /* Send off the abort */ 16710Sstevel@tonic-gate sctp_send_abort(sctp, sctp_init2vtag(ich), 1672*11042SErik.Nordmark@Sun.COM SCTP_ERR_RESTART_NEW_ADDRS, dtail, dlen, pkt, 0, B_TRUE, 1673*11042SErik.Nordmark@Sun.COM ira); 16740Sstevel@tonic-gate 16750Sstevel@tonic-gate kmem_free(dtail, PARM_ADDR6_LEN * nadded); 16760Sstevel@tonic-gate } 16770Sstevel@tonic-gate 16780Sstevel@tonic-gate cleanup: 16790Sstevel@tonic-gate /* Clean up */ 16800Sstevel@tonic-gate if (fphead) { 16810Sstevel@tonic-gate sctp_faddr_t *fpn; 16820Sstevel@tonic-gate for (fp = fphead; fp; fp = fpn) { 16830Sstevel@tonic-gate fpn = fp->next; 1684*11042SErik.Nordmark@Sun.COM if (fp->ixa != NULL) { 1685*11042SErik.Nordmark@Sun.COM ixa_refrele(fp->ixa); 1686*11042SErik.Nordmark@Sun.COM fp->ixa = NULL; 1687*11042SErik.Nordmark@Sun.COM } 16880Sstevel@tonic-gate kmem_cache_free(sctp_kmem_faddr_cache, fp); 16890Sstevel@tonic-gate } 16900Sstevel@tonic-gate } 16910Sstevel@tonic-gate 16920Sstevel@tonic-gate return (retval); 16930Sstevel@tonic-gate } 16940Sstevel@tonic-gate 16951932Svi117747 /* 16961932Svi117747 * Reset any state related to transmitted chunks. 16971932Svi117747 */ 16980Sstevel@tonic-gate void 16990Sstevel@tonic-gate sctp_congest_reset(sctp_t *sctp) 17000Sstevel@tonic-gate { 17011932Svi117747 sctp_faddr_t *fp; 17023448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 17031932Svi117747 mblk_t *mp; 17040Sstevel@tonic-gate 17051932Svi117747 for (fp = sctp->sctp_faddrs; fp != NULL; fp = fp->next) { 17063448Sdh155122 fp->ssthresh = sctps->sctps_initial_mtu; 17073795Skcpoon SET_CWND(fp, fp->sfa_pmss, sctps->sctps_slow_start_initial); 17080Sstevel@tonic-gate fp->suna = 0; 17090Sstevel@tonic-gate fp->pba = 0; 17100Sstevel@tonic-gate } 17111932Svi117747 /* 17121932Svi117747 * Clean up the transmit list as well since we have reset accounting 17131932Svi117747 * on all the fps. Send event upstream, if required. 17141932Svi117747 */ 17151932Svi117747 while ((mp = sctp->sctp_xmit_head) != NULL) { 17161932Svi117747 sctp->sctp_xmit_head = mp->b_next; 17171932Svi117747 mp->b_next = NULL; 17181932Svi117747 if (sctp->sctp_xmit_head != NULL) 17191932Svi117747 sctp->sctp_xmit_head->b_prev = NULL; 17201932Svi117747 sctp_sendfail_event(sctp, mp, 0, B_TRUE); 17211932Svi117747 } 17221932Svi117747 sctp->sctp_xmit_head = NULL; 17231932Svi117747 sctp->sctp_xmit_tail = NULL; 17241932Svi117747 sctp->sctp_xmit_unacked = NULL; 17251932Svi117747 17261932Svi117747 sctp->sctp_unacked = 0; 17271932Svi117747 /* 17281932Svi117747 * Any control message as well. We will clean-up this list as well. 17291932Svi117747 * This contains any pending ASCONF request that we have queued/sent. 17301932Svi117747 * If we do get an ACK we will just drop it. However, given that 17311932Svi117747 * we are restarting chances are we aren't going to get any. 17321932Svi117747 */ 17331932Svi117747 if (sctp->sctp_cxmit_list != NULL) 17341932Svi117747 sctp_asconf_free_cxmit(sctp, NULL); 17351932Svi117747 sctp->sctp_cxmit_list = NULL; 17361932Svi117747 sctp->sctp_cchunk_pend = 0; 17371932Svi117747 17381932Svi117747 sctp->sctp_rexmitting = B_FALSE; 17391932Svi117747 sctp->sctp_rxt_nxttsn = 0; 17401932Svi117747 sctp->sctp_rxt_maxtsn = 0; 17411932Svi117747 17421932Svi117747 sctp->sctp_zero_win_probe = B_FALSE; 17430Sstevel@tonic-gate } 17440Sstevel@tonic-gate 17450Sstevel@tonic-gate static void 17461735Skcpoon sctp_init_faddr(sctp_t *sctp, sctp_faddr_t *fp, in6_addr_t *addr, 17471735Skcpoon mblk_t *timer_mp) 17480Sstevel@tonic-gate { 17493448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 17503448Sdh155122 1751*11042SErik.Nordmark@Sun.COM ASSERT(fp->ixa != NULL); 1752*11042SErik.Nordmark@Sun.COM 17530Sstevel@tonic-gate bcopy(addr, &fp->faddr, sizeof (*addr)); 17540Sstevel@tonic-gate if (IN6_IS_ADDR_V4MAPPED(addr)) { 17550Sstevel@tonic-gate fp->isv4 = 1; 17560Sstevel@tonic-gate /* Make sure that sfa_pmss is a multiple of SCTP_ALIGN. */ 17574691Skcpoon fp->sfa_pmss = 17584691Skcpoon (sctps->sctps_initial_mtu - sctp->sctp_hdr_len) & 17594691Skcpoon ~(SCTP_ALIGN - 1); 1760*11042SErik.Nordmark@Sun.COM fp->ixa->ixa_flags |= IXAF_IS_IPV4; 17610Sstevel@tonic-gate } else { 17620Sstevel@tonic-gate fp->isv4 = 0; 17633448Sdh155122 fp->sfa_pmss = 17643448Sdh155122 (sctps->sctps_initial_mtu - sctp->sctp_hdr6_len) & 17653448Sdh155122 ~(SCTP_ALIGN - 1); 1766*11042SErik.Nordmark@Sun.COM fp->ixa->ixa_flags &= ~IXAF_IS_IPV4; 17670Sstevel@tonic-gate } 17683448Sdh155122 fp->cwnd = sctps->sctps_slow_start_initial * fp->sfa_pmss; 17690Sstevel@tonic-gate fp->rto = MIN(sctp->sctp_rto_initial, sctp->sctp_init_rto_max); 177010212SGeorge.Shepherd@Sun.COM SCTP_MAX_RTO(sctp, fp); 17710Sstevel@tonic-gate fp->srtt = -1; 17720Sstevel@tonic-gate fp->rtt_updates = 0; 17730Sstevel@tonic-gate fp->strikes = 0; 17740Sstevel@tonic-gate fp->max_retr = sctp->sctp_pp_max_rxt; 17750Sstevel@tonic-gate /* Mark it as not confirmed. */ 17760Sstevel@tonic-gate fp->state = SCTP_FADDRS_UNCONFIRMED; 17770Sstevel@tonic-gate fp->hb_interval = sctp->sctp_hb_interval; 17783448Sdh155122 fp->ssthresh = sctps->sctps_initial_ssthresh; 17790Sstevel@tonic-gate fp->suna = 0; 17800Sstevel@tonic-gate fp->pba = 0; 17810Sstevel@tonic-gate fp->acked = 0; 17820Sstevel@tonic-gate fp->lastactive = lbolt64; 17831735Skcpoon fp->timer_mp = timer_mp; 17840Sstevel@tonic-gate fp->hb_pending = B_FALSE; 17854818Skcpoon fp->hb_enabled = B_TRUE; 17860Sstevel@tonic-gate fp->df = 1; 17870Sstevel@tonic-gate fp->pmtu_discovered = 0; 17880Sstevel@tonic-gate fp->next = NULL; 17890Sstevel@tonic-gate fp->T3expire = 0; 17900Sstevel@tonic-gate (void) random_get_pseudo_bytes((uint8_t *)&fp->hb_secret, 17910Sstevel@tonic-gate sizeof (fp->hb_secret)); 17920Sstevel@tonic-gate fp->hb_expiry = lbolt64; 17933795Skcpoon fp->rxt_unacked = 0; 17940Sstevel@tonic-gate 1795*11042SErik.Nordmark@Sun.COM sctp_get_dest(sctp, fp); 17960Sstevel@tonic-gate } 17970Sstevel@tonic-gate 17980Sstevel@tonic-gate /*ARGSUSED*/ 17996712Stomee static int 18006712Stomee faddr_constructor(void *buf, void *arg, int flags) 18016712Stomee { 18026712Stomee sctp_faddr_t *fp = buf; 18036712Stomee 18046712Stomee fp->timer_mp = NULL; 18056712Stomee fp->timer_running = 0; 18066712Stomee 18076712Stomee fp->rc_timer_mp = NULL; 18086712Stomee fp->rc_timer_running = 0; 18096712Stomee 18106712Stomee return (0); 18116712Stomee } 18126712Stomee 18136712Stomee /*ARGSUSED*/ 18140Sstevel@tonic-gate static void 18156712Stomee faddr_destructor(void *buf, void *arg) 18160Sstevel@tonic-gate { 18170Sstevel@tonic-gate sctp_faddr_t *fp = buf; 18180Sstevel@tonic-gate 18190Sstevel@tonic-gate ASSERT(fp->timer_mp == NULL); 18200Sstevel@tonic-gate ASSERT(fp->timer_running == 0); 18210Sstevel@tonic-gate 18220Sstevel@tonic-gate ASSERT(fp->rc_timer_mp == NULL); 18230Sstevel@tonic-gate ASSERT(fp->rc_timer_running == 0); 18240Sstevel@tonic-gate } 18250Sstevel@tonic-gate 18260Sstevel@tonic-gate void 18271676Sjpk sctp_faddr_init(void) 18280Sstevel@tonic-gate { 18290Sstevel@tonic-gate sctp_kmem_faddr_cache = kmem_cache_create("sctp_faddr_cache", 18306712Stomee sizeof (sctp_faddr_t), 0, faddr_constructor, faddr_destructor, 18310Sstevel@tonic-gate NULL, NULL, NULL, 0); 18320Sstevel@tonic-gate } 18330Sstevel@tonic-gate 18340Sstevel@tonic-gate void 18351676Sjpk sctp_faddr_fini(void) 18360Sstevel@tonic-gate { 18370Sstevel@tonic-gate kmem_cache_destroy(sctp_kmem_faddr_cache); 18380Sstevel@tonic-gate } 1839