17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 545916cd2Sjpk * Common Development and Distribution License (the "License"). 645916cd2Sjpk * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 21*77c67f2fSkcpoon 227c478bd9Sstevel@tonic-gate /* 2345916cd2Sjpk * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #include <sys/types.h> 307c478bd9Sstevel@tonic-gate #include <sys/stream.h> 317c478bd9Sstevel@tonic-gate #define _SUN_TPI_VERSION 2 327c478bd9Sstevel@tonic-gate #include <sys/tihdr.h> 337c478bd9Sstevel@tonic-gate #include <sys/socket.h> 347c478bd9Sstevel@tonic-gate #include <sys/xti_inet.h> 357c478bd9Sstevel@tonic-gate #include <sys/systm.h> 367c478bd9Sstevel@tonic-gate #include <sys/ddi.h> 377c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 387c478bd9Sstevel@tonic-gate #include <sys/kmem.h> 397c478bd9Sstevel@tonic-gate #include <sys/strsubr.h> 407c478bd9Sstevel@tonic-gate #include <sys/strsun.h> 417c478bd9Sstevel@tonic-gate #include <sys/policy.h> 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate #include <inet/common.h> 447c478bd9Sstevel@tonic-gate #include <netinet/ip6.h> 457c478bd9Sstevel@tonic-gate #include <inet/ip.h> 467c478bd9Sstevel@tonic-gate #include <inet/ip_ire.h> 4743d18f1cSpriyanka #include <inet/ip_if.h> 487c478bd9Sstevel@tonic-gate #include <inet/ipclassifier.h> 497c478bd9Sstevel@tonic-gate #include <inet/ipsec_impl.h> 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate #include <netinet/in.h> 527c478bd9Sstevel@tonic-gate #include <netinet/ip.h> 537c478bd9Sstevel@tonic-gate #include <netinet/tcp.h> 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate #include <inet/common.h> 567c478bd9Sstevel@tonic-gate #include <inet/ip.h> 577c478bd9Sstevel@tonic-gate #include <inet/ip6.h> 587c478bd9Sstevel@tonic-gate #include <inet/sctp_itf.h> 597c478bd9Sstevel@tonic-gate #include "sctp_impl.h" 607c478bd9Sstevel@tonic-gate #include "sctp_asconf.h" 617c478bd9Sstevel@tonic-gate #include "sctp_addr.h" 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate static int sctp_getpeeraddrs(sctp_t *, void *, int *); 647c478bd9Sstevel@tonic-gate 657c478bd9Sstevel@tonic-gate /* 6645916cd2Sjpk * Copy the standard header into its new location, 6745916cd2Sjpk * lay in the new options and then update the relevant 6845916cd2Sjpk * fields in both sctp_t and the standard header. 6945916cd2Sjpk * Returns 0 on success, errno otherwise. 707c478bd9Sstevel@tonic-gate */ 717c478bd9Sstevel@tonic-gate static int 7245916cd2Sjpk sctp_opt_set_header(sctp_t *sctp, const void *ptr, uint_t len) 737c478bd9Sstevel@tonic-gate { 7445916cd2Sjpk uint8_t *ip_optp; 7545916cd2Sjpk sctp_hdr_t *new_sctph; 767c478bd9Sstevel@tonic-gate 7745916cd2Sjpk if ((len > SCTP_MAX_IP_OPTIONS_LENGTH) || (len & 0x3)) 7845916cd2Sjpk return (EINVAL); 797c478bd9Sstevel@tonic-gate 8045916cd2Sjpk if (len > IP_MAX_OPT_LENGTH - sctp->sctp_v4label_len) 8145916cd2Sjpk return (EINVAL); 827c478bd9Sstevel@tonic-gate 8345916cd2Sjpk ip_optp = (uint8_t *)sctp->sctp_ipha + IP_SIMPLE_HDR_LENGTH; 847c478bd9Sstevel@tonic-gate 8545916cd2Sjpk if (sctp->sctp_v4label_len > 0) { 8645916cd2Sjpk int padlen; 8745916cd2Sjpk uint8_t opt; 887c478bd9Sstevel@tonic-gate 8945916cd2Sjpk /* convert list termination to no-ops as needed */ 9045916cd2Sjpk padlen = sctp->sctp_v4label_len - ip_optp[IPOPT_OLEN]; 9145916cd2Sjpk ip_optp += ip_optp[IPOPT_OLEN]; 9245916cd2Sjpk opt = len > 0 ? IPOPT_NOP : IPOPT_EOL; 9345916cd2Sjpk while (--padlen >= 0) 9445916cd2Sjpk *ip_optp++ = opt; 9545916cd2Sjpk ASSERT(ip_optp == (uint8_t *)sctp->sctp_ipha + 9645916cd2Sjpk IP_SIMPLE_HDR_LENGTH + sctp->sctp_v4label_len); 977c478bd9Sstevel@tonic-gate } 987c478bd9Sstevel@tonic-gate 9945916cd2Sjpk /* 10045916cd2Sjpk * Move the existing SCTP header out where it belongs. 10145916cd2Sjpk */ 10245916cd2Sjpk new_sctph = (sctp_hdr_t *)(ip_optp + len); 10345916cd2Sjpk ovbcopy(sctp->sctp_sctph, new_sctph, sizeof (sctp_hdr_t)); 10445916cd2Sjpk sctp->sctp_sctph = new_sctph; 1057c478bd9Sstevel@tonic-gate 10645916cd2Sjpk /* 10745916cd2Sjpk * Insert the new user-supplied IP options. 10845916cd2Sjpk */ 10945916cd2Sjpk if (len > 0) 11045916cd2Sjpk bcopy(ptr, ip_optp, len); 1117c478bd9Sstevel@tonic-gate 11245916cd2Sjpk len += sctp->sctp_v4label_len; 1137c478bd9Sstevel@tonic-gate sctp->sctp_ip_hdr_len = len; 1147c478bd9Sstevel@tonic-gate sctp->sctp_ipha->ipha_version_and_hdr_length = 11545916cd2Sjpk (IP_VERSION << 4) | (len >> 2); 11645916cd2Sjpk sctp->sctp_hdr_len = len + sizeof (sctp_hdr_t); 1177c478bd9Sstevel@tonic-gate 1187c478bd9Sstevel@tonic-gate if (sctp->sctp_current) { 1197c478bd9Sstevel@tonic-gate /* 1207c478bd9Sstevel@tonic-gate * Could be setting options before setting up connection. 1217c478bd9Sstevel@tonic-gate */ 1227c478bd9Sstevel@tonic-gate sctp_set_ulp_prop(sctp); 1237c478bd9Sstevel@tonic-gate } 1247c478bd9Sstevel@tonic-gate return (0); 1257c478bd9Sstevel@tonic-gate } 1267c478bd9Sstevel@tonic-gate 1277c478bd9Sstevel@tonic-gate static int 1287c478bd9Sstevel@tonic-gate sctp_get_status(sctp_t *sctp, void *ptr) 1297c478bd9Sstevel@tonic-gate { 1307c478bd9Sstevel@tonic-gate struct sctp_status *sstat = ptr; 1317c478bd9Sstevel@tonic-gate sctp_faddr_t *fp; 1327c478bd9Sstevel@tonic-gate struct sockaddr_in *sin; 1337c478bd9Sstevel@tonic-gate struct sockaddr_in6 *sin6; 1347c478bd9Sstevel@tonic-gate struct sctp_paddrinfo *sp; 1357c478bd9Sstevel@tonic-gate mblk_t *meta, *mp; 1367c478bd9Sstevel@tonic-gate int i; 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate sstat->sstat_state = sctp->sctp_state; 1397c478bd9Sstevel@tonic-gate sstat->sstat_rwnd = sctp->sctp_frwnd; 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate sp = &sstat->sstat_primary; 1427c478bd9Sstevel@tonic-gate if (!sctp->sctp_primary) { 1437c478bd9Sstevel@tonic-gate bzero(sp, sizeof (*sp)); 1447c478bd9Sstevel@tonic-gate goto noprim; 1457c478bd9Sstevel@tonic-gate } 1467c478bd9Sstevel@tonic-gate fp = sctp->sctp_primary; 1477c478bd9Sstevel@tonic-gate 1487c478bd9Sstevel@tonic-gate if (fp->isv4) { 1497c478bd9Sstevel@tonic-gate sin = (struct sockaddr_in *)&sp->spinfo_address; 1507c478bd9Sstevel@tonic-gate sin->sin_family = AF_INET; 1517c478bd9Sstevel@tonic-gate sin->sin_port = sctp->sctp_fport; 1527c478bd9Sstevel@tonic-gate IN6_V4MAPPED_TO_INADDR(&fp->faddr, &sin->sin_addr); 1537c478bd9Sstevel@tonic-gate sp->spinfo_mtu = sctp->sctp_hdr_len; 1547c478bd9Sstevel@tonic-gate } else { 1557c478bd9Sstevel@tonic-gate sin6 = (struct sockaddr_in6 *)&sp->spinfo_address; 1567c478bd9Sstevel@tonic-gate sin6->sin6_family = AF_INET6; 1577c478bd9Sstevel@tonic-gate sin6->sin6_port = sctp->sctp_fport; 1587c478bd9Sstevel@tonic-gate sin6->sin6_addr = fp->faddr; 1597c478bd9Sstevel@tonic-gate sp->spinfo_mtu = sctp->sctp_hdr6_len; 1607c478bd9Sstevel@tonic-gate } 1617c478bd9Sstevel@tonic-gate sp->spinfo_state = fp->state == SCTP_FADDRS_ALIVE ? SCTP_ACTIVE : 1627c478bd9Sstevel@tonic-gate SCTP_INACTIVE; 1637c478bd9Sstevel@tonic-gate sp->spinfo_cwnd = fp->cwnd; 1647c478bd9Sstevel@tonic-gate sp->spinfo_srtt = fp->srtt; 1657c478bd9Sstevel@tonic-gate sp->spinfo_rto = fp->rto; 1667c478bd9Sstevel@tonic-gate sp->spinfo_mtu += fp->sfa_pmss; 1677c478bd9Sstevel@tonic-gate 1687c478bd9Sstevel@tonic-gate noprim: 1697c478bd9Sstevel@tonic-gate sstat->sstat_unackdata = 0; 1707c478bd9Sstevel@tonic-gate sstat->sstat_penddata = 0; 1717c478bd9Sstevel@tonic-gate sstat->sstat_instrms = sctp->sctp_num_istr; 1727c478bd9Sstevel@tonic-gate sstat->sstat_outstrms = sctp->sctp_num_ostr; 1737c478bd9Sstevel@tonic-gate sstat->sstat_fragmentation_point = sctp->sctp_mss - 1747c478bd9Sstevel@tonic-gate sizeof (sctp_data_hdr_t); 1757c478bd9Sstevel@tonic-gate 1767c478bd9Sstevel@tonic-gate /* count unack'd */ 1777c478bd9Sstevel@tonic-gate for (meta = sctp->sctp_xmit_head; meta; meta = meta->b_next) { 1787c478bd9Sstevel@tonic-gate for (mp = meta->b_cont; mp; mp = mp->b_next) { 1797c478bd9Sstevel@tonic-gate if (!SCTP_CHUNK_ISSENT(mp)) { 1807c478bd9Sstevel@tonic-gate break; 1817c478bd9Sstevel@tonic-gate } 1827c478bd9Sstevel@tonic-gate if (!SCTP_CHUNK_ISACKED(mp)) { 1837c478bd9Sstevel@tonic-gate sstat->sstat_unackdata++; 1847c478bd9Sstevel@tonic-gate } 1857c478bd9Sstevel@tonic-gate } 1867c478bd9Sstevel@tonic-gate } 1877c478bd9Sstevel@tonic-gate 1887c478bd9Sstevel@tonic-gate /* 1897c478bd9Sstevel@tonic-gate * Count penddata chunks. We can only count chunks in SCTP (not 1907c478bd9Sstevel@tonic-gate * data already delivered to socket layer). 1917c478bd9Sstevel@tonic-gate */ 1927c478bd9Sstevel@tonic-gate if (sctp->sctp_instr != NULL) { 1937c478bd9Sstevel@tonic-gate for (i = 0; i < sctp->sctp_num_istr; i++) { 1947c478bd9Sstevel@tonic-gate for (meta = sctp->sctp_instr[i].istr_reass; 1957c478bd9Sstevel@tonic-gate meta != NULL; meta = meta->b_next) { 1967c478bd9Sstevel@tonic-gate for (mp = meta->b_cont; mp; mp = mp->b_cont) { 1977c478bd9Sstevel@tonic-gate if (DB_TYPE(mp) != M_CTL) { 1987c478bd9Sstevel@tonic-gate sstat->sstat_penddata++; 1997c478bd9Sstevel@tonic-gate } 2007c478bd9Sstevel@tonic-gate } 2017c478bd9Sstevel@tonic-gate } 2027c478bd9Sstevel@tonic-gate } 2037c478bd9Sstevel@tonic-gate } 2047c478bd9Sstevel@tonic-gate /* Un-Ordered Frag list */ 2057c478bd9Sstevel@tonic-gate for (meta = sctp->sctp_uo_frags; meta != NULL; meta = meta->b_next) 2067c478bd9Sstevel@tonic-gate sstat->sstat_penddata++; 2077c478bd9Sstevel@tonic-gate 2087c478bd9Sstevel@tonic-gate return (sizeof (*sstat)); 2097c478bd9Sstevel@tonic-gate } 2107c478bd9Sstevel@tonic-gate 2117c478bd9Sstevel@tonic-gate /* 2127c478bd9Sstevel@tonic-gate * SCTP_GET_PEER_ADDR_INFO 2137c478bd9Sstevel@tonic-gate */ 2147c478bd9Sstevel@tonic-gate static int 2157c478bd9Sstevel@tonic-gate sctp_get_paddrinfo(sctp_t *sctp, void *ptr, socklen_t *optlen) 2167c478bd9Sstevel@tonic-gate { 2177c478bd9Sstevel@tonic-gate struct sctp_paddrinfo *infop = ptr; 2187c478bd9Sstevel@tonic-gate struct sockaddr_in *sin4; 2197c478bd9Sstevel@tonic-gate struct sockaddr_in6 *sin6; 2207c478bd9Sstevel@tonic-gate in6_addr_t faddr; 2217c478bd9Sstevel@tonic-gate sctp_faddr_t *fp; 2227c478bd9Sstevel@tonic-gate 2237c478bd9Sstevel@tonic-gate switch (infop->spinfo_address.ss_family) { 2247c478bd9Sstevel@tonic-gate case AF_INET: 2257c478bd9Sstevel@tonic-gate sin4 = (struct sockaddr_in *)&infop->spinfo_address; 2267c478bd9Sstevel@tonic-gate IN6_INADDR_TO_V4MAPPED(&sin4->sin_addr, &faddr); 2277c478bd9Sstevel@tonic-gate break; 2287c478bd9Sstevel@tonic-gate case AF_INET6: 2297c478bd9Sstevel@tonic-gate sin6 = (struct sockaddr_in6 *)&infop->spinfo_address; 2307c478bd9Sstevel@tonic-gate faddr = sin6->sin6_addr; 2317c478bd9Sstevel@tonic-gate break; 2327c478bd9Sstevel@tonic-gate default: 2337c478bd9Sstevel@tonic-gate return (EAFNOSUPPORT); 2347c478bd9Sstevel@tonic-gate } 2357c478bd9Sstevel@tonic-gate 2367c478bd9Sstevel@tonic-gate if ((fp = sctp_lookup_faddr(sctp, &faddr)) == NULL) 2377c478bd9Sstevel@tonic-gate return (EINVAL); 2387c478bd9Sstevel@tonic-gate 2397c478bd9Sstevel@tonic-gate infop->spinfo_state = (fp->state == SCTP_FADDRS_ALIVE) ? SCTP_ACTIVE : 2407c478bd9Sstevel@tonic-gate SCTP_INACTIVE; 2417c478bd9Sstevel@tonic-gate infop->spinfo_cwnd = fp->cwnd; 2427c478bd9Sstevel@tonic-gate infop->spinfo_srtt = TICK_TO_MSEC(fp->srtt); 2437c478bd9Sstevel@tonic-gate infop->spinfo_rto = TICK_TO_MSEC(fp->rto); 2447c478bd9Sstevel@tonic-gate infop->spinfo_mtu = fp->sfa_pmss; 2457c478bd9Sstevel@tonic-gate 2467c478bd9Sstevel@tonic-gate *optlen = sizeof (struct sctp_paddrinfo); 2477c478bd9Sstevel@tonic-gate return (0); 2487c478bd9Sstevel@tonic-gate } 2497c478bd9Sstevel@tonic-gate 2507c478bd9Sstevel@tonic-gate /* 2517c478bd9Sstevel@tonic-gate * SCTP_RTOINFO 2527c478bd9Sstevel@tonic-gate */ 2537c478bd9Sstevel@tonic-gate static int 2547c478bd9Sstevel@tonic-gate sctp_get_rtoinfo(sctp_t *sctp, void *ptr) 2557c478bd9Sstevel@tonic-gate { 2567c478bd9Sstevel@tonic-gate struct sctp_rtoinfo *srto = ptr; 2577c478bd9Sstevel@tonic-gate 2587c478bd9Sstevel@tonic-gate srto->srto_initial = TICK_TO_MSEC(sctp->sctp_rto_initial); 2597c478bd9Sstevel@tonic-gate srto->srto_max = TICK_TO_MSEC(sctp->sctp_rto_max); 2607c478bd9Sstevel@tonic-gate srto->srto_min = TICK_TO_MSEC(sctp->sctp_rto_min); 2617c478bd9Sstevel@tonic-gate 2627c478bd9Sstevel@tonic-gate return (sizeof (*srto)); 2637c478bd9Sstevel@tonic-gate } 2647c478bd9Sstevel@tonic-gate 2657c478bd9Sstevel@tonic-gate static int 2667c478bd9Sstevel@tonic-gate sctp_set_rtoinfo(sctp_t *sctp, const void *invalp, uint_t inlen) 2677c478bd9Sstevel@tonic-gate { 2687c478bd9Sstevel@tonic-gate const struct sctp_rtoinfo *srto; 2697c478bd9Sstevel@tonic-gate boolean_t ispriv; 2707c478bd9Sstevel@tonic-gate 2717c478bd9Sstevel@tonic-gate if (inlen < sizeof (*srto)) { 2727c478bd9Sstevel@tonic-gate return (EINVAL); 2737c478bd9Sstevel@tonic-gate } 2747c478bd9Sstevel@tonic-gate srto = invalp; 2757c478bd9Sstevel@tonic-gate 2767c478bd9Sstevel@tonic-gate ispriv = secpolicy_net_config(CRED(), B_TRUE) == 0; 2777c478bd9Sstevel@tonic-gate 2787c478bd9Sstevel@tonic-gate /* 2797c478bd9Sstevel@tonic-gate * Bounds checking. Priviledged user can set the RTO initial 2807c478bd9Sstevel@tonic-gate * outside the ndd boundary. 2817c478bd9Sstevel@tonic-gate */ 2827c478bd9Sstevel@tonic-gate if (srto->srto_initial != 0 && 2837c478bd9Sstevel@tonic-gate (!ispriv && (srto->srto_initial < sctp_rto_initialg_low || 2847c478bd9Sstevel@tonic-gate srto->srto_initial > sctp_rto_initialg_high))) { 2857c478bd9Sstevel@tonic-gate return (EINVAL); 2867c478bd9Sstevel@tonic-gate } 2877c478bd9Sstevel@tonic-gate if (srto->srto_max != 0 && 2887c478bd9Sstevel@tonic-gate (!ispriv && (srto->srto_max < sctp_rto_maxg_low || 2897c478bd9Sstevel@tonic-gate srto->srto_max > sctp_rto_maxg_high))) { 2907c478bd9Sstevel@tonic-gate return (EINVAL); 2917c478bd9Sstevel@tonic-gate } 2927c478bd9Sstevel@tonic-gate if (srto->srto_min != 0 && 2937c478bd9Sstevel@tonic-gate (!ispriv && (srto->srto_min < sctp_rto_ming_low || 2947c478bd9Sstevel@tonic-gate srto->srto_min > sctp_rto_ming_high))) { 2957c478bd9Sstevel@tonic-gate return (EINVAL); 2967c478bd9Sstevel@tonic-gate } 2977c478bd9Sstevel@tonic-gate 2987c478bd9Sstevel@tonic-gate if (srto->srto_initial != 0) { 2997c478bd9Sstevel@tonic-gate sctp->sctp_rto_initial = MSEC_TO_TICK(srto->srto_initial); 3007c478bd9Sstevel@tonic-gate } 3017c478bd9Sstevel@tonic-gate if (srto->srto_max != 0) { 3027c478bd9Sstevel@tonic-gate sctp->sctp_rto_max = MSEC_TO_TICK(srto->srto_max); 3037c478bd9Sstevel@tonic-gate } 3047c478bd9Sstevel@tonic-gate if (srto->srto_min != 0) { 3057c478bd9Sstevel@tonic-gate sctp->sctp_rto_min = MSEC_TO_TICK(srto->srto_min); 3067c478bd9Sstevel@tonic-gate } 3077c478bd9Sstevel@tonic-gate 3087c478bd9Sstevel@tonic-gate return (0); 3097c478bd9Sstevel@tonic-gate } 3107c478bd9Sstevel@tonic-gate 3117c478bd9Sstevel@tonic-gate /* 3127c478bd9Sstevel@tonic-gate * SCTP_ASSOCINFO 3137c478bd9Sstevel@tonic-gate */ 3147c478bd9Sstevel@tonic-gate static int 3157c478bd9Sstevel@tonic-gate sctp_get_assocparams(sctp_t *sctp, void *ptr) 3167c478bd9Sstevel@tonic-gate { 3177c478bd9Sstevel@tonic-gate struct sctp_assocparams *sap = ptr; 3187c478bd9Sstevel@tonic-gate sctp_faddr_t *fp; 3197c478bd9Sstevel@tonic-gate uint16_t i; 3207c478bd9Sstevel@tonic-gate 3217c478bd9Sstevel@tonic-gate sap->sasoc_asocmaxrxt = sctp->sctp_pa_max_rxt; 3227c478bd9Sstevel@tonic-gate 3237c478bd9Sstevel@tonic-gate /* 3247c478bd9Sstevel@tonic-gate * Count the number of peer addresses 3257c478bd9Sstevel@tonic-gate */ 3267c478bd9Sstevel@tonic-gate for (i = 0, fp = sctp->sctp_faddrs; fp != NULL; fp = fp->next) { 3277c478bd9Sstevel@tonic-gate i++; 3287c478bd9Sstevel@tonic-gate } 3297c478bd9Sstevel@tonic-gate sap->sasoc_number_peer_destinations = i; 3307c478bd9Sstevel@tonic-gate sap->sasoc_peer_rwnd = sctp->sctp_frwnd; 3317c478bd9Sstevel@tonic-gate sap->sasoc_local_rwnd = sctp->sctp_rwnd; 3327c478bd9Sstevel@tonic-gate sap->sasoc_cookie_life = TICK_TO_MSEC(sctp->sctp_cookie_lifetime); 3337c478bd9Sstevel@tonic-gate 3347c478bd9Sstevel@tonic-gate return (sizeof (*sap)); 3357c478bd9Sstevel@tonic-gate } 3367c478bd9Sstevel@tonic-gate 3377c478bd9Sstevel@tonic-gate static int 3387c478bd9Sstevel@tonic-gate sctp_set_assocparams(sctp_t *sctp, const void *invalp, uint_t inlen) 3397c478bd9Sstevel@tonic-gate { 3407c478bd9Sstevel@tonic-gate const struct sctp_assocparams *sap = invalp; 3417c478bd9Sstevel@tonic-gate uint32_t sum = 0; 3427c478bd9Sstevel@tonic-gate sctp_faddr_t *fp; 3437c478bd9Sstevel@tonic-gate 3447c478bd9Sstevel@tonic-gate if (inlen < sizeof (*sap)) { 3457c478bd9Sstevel@tonic-gate return (EINVAL); 3467c478bd9Sstevel@tonic-gate } 3477c478bd9Sstevel@tonic-gate 3487c478bd9Sstevel@tonic-gate if (sap->sasoc_asocmaxrxt) { 3497c478bd9Sstevel@tonic-gate if (sctp->sctp_faddrs) { 3507c478bd9Sstevel@tonic-gate /* 3517c478bd9Sstevel@tonic-gate * Bounds check: as per rfc2960, assoc max retr cannot 3527c478bd9Sstevel@tonic-gate * exceed the sum of all individual path max retr's. 3537c478bd9Sstevel@tonic-gate */ 3547c478bd9Sstevel@tonic-gate for (fp = sctp->sctp_faddrs; fp; fp = fp->next) { 3557c478bd9Sstevel@tonic-gate sum += fp->max_retr; 3567c478bd9Sstevel@tonic-gate } 3577c478bd9Sstevel@tonic-gate if (sap->sasoc_asocmaxrxt > sum) { 3587c478bd9Sstevel@tonic-gate return (EINVAL); 3597c478bd9Sstevel@tonic-gate } 3607c478bd9Sstevel@tonic-gate } 3617c478bd9Sstevel@tonic-gate if (sap->sasoc_asocmaxrxt < sctp_pa_max_retr_low || 3627c478bd9Sstevel@tonic-gate sap->sasoc_asocmaxrxt > sctp_pa_max_retr_high) { 3637c478bd9Sstevel@tonic-gate /* 3647c478bd9Sstevel@tonic-gate * Out of bounds. 3657c478bd9Sstevel@tonic-gate */ 3667c478bd9Sstevel@tonic-gate return (EINVAL); 3677c478bd9Sstevel@tonic-gate } 3687c478bd9Sstevel@tonic-gate } 3697c478bd9Sstevel@tonic-gate if (sap->sasoc_cookie_life != 0 && 3707c478bd9Sstevel@tonic-gate (sap->sasoc_cookie_life < sctp_cookie_life_low || 3717c478bd9Sstevel@tonic-gate sap->sasoc_cookie_life > sctp_cookie_life_high)) { 3727c478bd9Sstevel@tonic-gate return (EINVAL); 3737c478bd9Sstevel@tonic-gate } 3747c478bd9Sstevel@tonic-gate 3757c478bd9Sstevel@tonic-gate if (sap->sasoc_asocmaxrxt > 0) { 3767c478bd9Sstevel@tonic-gate sctp->sctp_pa_max_rxt = sap->sasoc_asocmaxrxt; 3777c478bd9Sstevel@tonic-gate } 3787c478bd9Sstevel@tonic-gate if (sap->sasoc_cookie_life > 0) { 3797c478bd9Sstevel@tonic-gate sctp->sctp_cookie_lifetime = MSEC_TO_TICK( 3807c478bd9Sstevel@tonic-gate sap->sasoc_cookie_life); 3817c478bd9Sstevel@tonic-gate } 3827c478bd9Sstevel@tonic-gate return (0); 3837c478bd9Sstevel@tonic-gate } 3847c478bd9Sstevel@tonic-gate 3857c478bd9Sstevel@tonic-gate /* 3867c478bd9Sstevel@tonic-gate * SCTP_INITMSG 3877c478bd9Sstevel@tonic-gate */ 3887c478bd9Sstevel@tonic-gate static int 3897c478bd9Sstevel@tonic-gate sctp_get_initmsg(sctp_t *sctp, void *ptr) 3907c478bd9Sstevel@tonic-gate { 3917c478bd9Sstevel@tonic-gate struct sctp_initmsg *si = ptr; 3927c478bd9Sstevel@tonic-gate 3937c478bd9Sstevel@tonic-gate si->sinit_num_ostreams = sctp->sctp_num_ostr; 3947c478bd9Sstevel@tonic-gate si->sinit_max_instreams = sctp->sctp_num_istr; 3957c478bd9Sstevel@tonic-gate si->sinit_max_attempts = sctp->sctp_max_init_rxt; 3967c478bd9Sstevel@tonic-gate si->sinit_max_init_timeo = TICK_TO_MSEC(sctp->sctp_init_rto_max); 3977c478bd9Sstevel@tonic-gate 3987c478bd9Sstevel@tonic-gate return (sizeof (*si)); 3997c478bd9Sstevel@tonic-gate } 4007c478bd9Sstevel@tonic-gate 4017c478bd9Sstevel@tonic-gate static int 4027c478bd9Sstevel@tonic-gate sctp_set_initmsg(sctp_t *sctp, const void *invalp, uint_t inlen) 4037c478bd9Sstevel@tonic-gate { 4047c478bd9Sstevel@tonic-gate const struct sctp_initmsg *si = invalp; 4057c478bd9Sstevel@tonic-gate 4067c478bd9Sstevel@tonic-gate if (sctp->sctp_state > SCTPS_LISTEN) { 4077c478bd9Sstevel@tonic-gate return (EINVAL); 4087c478bd9Sstevel@tonic-gate } 4097c478bd9Sstevel@tonic-gate if (inlen < sizeof (*si)) { 4107c478bd9Sstevel@tonic-gate return (EINVAL); 4117c478bd9Sstevel@tonic-gate } 4127c478bd9Sstevel@tonic-gate if (si->sinit_num_ostreams != 0 && 4137c478bd9Sstevel@tonic-gate (si->sinit_num_ostreams < sctp_initial_out_streams_low || 4147c478bd9Sstevel@tonic-gate si->sinit_num_ostreams > sctp_initial_out_streams_high)) { 4157c478bd9Sstevel@tonic-gate /* 4167c478bd9Sstevel@tonic-gate * Out of bounds. 4177c478bd9Sstevel@tonic-gate */ 4187c478bd9Sstevel@tonic-gate return (EINVAL); 4197c478bd9Sstevel@tonic-gate } 4207c478bd9Sstevel@tonic-gate if (si->sinit_max_instreams != 0 && 4217c478bd9Sstevel@tonic-gate (si->sinit_max_instreams < sctp_max_in_streams_low || 4227c478bd9Sstevel@tonic-gate si->sinit_max_instreams > sctp_max_in_streams_high)) { 4237c478bd9Sstevel@tonic-gate return (EINVAL); 4247c478bd9Sstevel@tonic-gate } 4257c478bd9Sstevel@tonic-gate if (si->sinit_max_attempts != 0 && 4267c478bd9Sstevel@tonic-gate (si->sinit_max_attempts < sctp_max_init_retr_low || 4277c478bd9Sstevel@tonic-gate si->sinit_max_attempts > sctp_max_init_retr_high)) { 4287c478bd9Sstevel@tonic-gate return (EINVAL); 4297c478bd9Sstevel@tonic-gate } 4307c478bd9Sstevel@tonic-gate if (si->sinit_max_init_timeo != 0 && 4317c478bd9Sstevel@tonic-gate (secpolicy_net_config(CRED(), B_TRUE) != 0 && 4327c478bd9Sstevel@tonic-gate (si->sinit_max_init_timeo < sctp_rto_maxg_low || 4337c478bd9Sstevel@tonic-gate si->sinit_max_init_timeo > sctp_rto_maxg_high))) { 4347c478bd9Sstevel@tonic-gate return (EINVAL); 4357c478bd9Sstevel@tonic-gate } 4367c478bd9Sstevel@tonic-gate if (si->sinit_num_ostreams != 0) 4377c478bd9Sstevel@tonic-gate sctp->sctp_num_ostr = si->sinit_num_ostreams; 4387c478bd9Sstevel@tonic-gate 4397c478bd9Sstevel@tonic-gate if (si->sinit_max_instreams != 0) 4407c478bd9Sstevel@tonic-gate sctp->sctp_num_istr = si->sinit_max_instreams; 4417c478bd9Sstevel@tonic-gate 4427c478bd9Sstevel@tonic-gate if (si->sinit_max_attempts != 0) 4437c478bd9Sstevel@tonic-gate sctp->sctp_max_init_rxt = si->sinit_max_attempts; 4447c478bd9Sstevel@tonic-gate 4457c478bd9Sstevel@tonic-gate if (si->sinit_max_init_timeo != 0) { 4467c478bd9Sstevel@tonic-gate sctp->sctp_init_rto_max = 4477c478bd9Sstevel@tonic-gate MSEC_TO_TICK(si->sinit_max_init_timeo); 4487c478bd9Sstevel@tonic-gate } 4497c478bd9Sstevel@tonic-gate return (0); 4507c478bd9Sstevel@tonic-gate } 4517c478bd9Sstevel@tonic-gate 4527c478bd9Sstevel@tonic-gate /* 4537c478bd9Sstevel@tonic-gate * SCTP_PEER_ADDR_PARAMS 4547c478bd9Sstevel@tonic-gate */ 4557c478bd9Sstevel@tonic-gate static int 4567c478bd9Sstevel@tonic-gate sctp_find_peer_fp(sctp_t *sctp, const struct sockaddr_storage *ss, 4577c478bd9Sstevel@tonic-gate sctp_faddr_t **fpp) 4587c478bd9Sstevel@tonic-gate { 4597c478bd9Sstevel@tonic-gate struct sockaddr_in *sin; 4607c478bd9Sstevel@tonic-gate struct sockaddr_in6 *sin6; 4617c478bd9Sstevel@tonic-gate in6_addr_t addr; 4627c478bd9Sstevel@tonic-gate 4637c478bd9Sstevel@tonic-gate if (ss->ss_family == AF_INET) { 4647c478bd9Sstevel@tonic-gate sin = (struct sockaddr_in *)ss; 4657c478bd9Sstevel@tonic-gate IN6_IPADDR_TO_V4MAPPED(sin->sin_addr.s_addr, &addr); 4667c478bd9Sstevel@tonic-gate } else if (ss->ss_family == AF_INET6) { 4677c478bd9Sstevel@tonic-gate sin6 = (struct sockaddr_in6 *)ss; 4687c478bd9Sstevel@tonic-gate addr = sin6->sin6_addr; 4697c478bd9Sstevel@tonic-gate } else if (ss->ss_family) { 4707c478bd9Sstevel@tonic-gate return (EAFNOSUPPORT); 4717c478bd9Sstevel@tonic-gate } 4727c478bd9Sstevel@tonic-gate 4737c478bd9Sstevel@tonic-gate if (!ss->ss_family || 4747c478bd9Sstevel@tonic-gate SCTP_IS_ADDR_UNSPEC(IN6_IS_ADDR_V4MAPPED(&addr), addr)) { 4757c478bd9Sstevel@tonic-gate *fpp = NULL; 4767c478bd9Sstevel@tonic-gate } else { 4777c478bd9Sstevel@tonic-gate *fpp = sctp_lookup_faddr(sctp, &addr); 4787c478bd9Sstevel@tonic-gate if (*fpp == NULL) { 4797c478bd9Sstevel@tonic-gate return (EINVAL); 4807c478bd9Sstevel@tonic-gate } 4817c478bd9Sstevel@tonic-gate } 4827c478bd9Sstevel@tonic-gate return (0); 4837c478bd9Sstevel@tonic-gate } 4847c478bd9Sstevel@tonic-gate 4857c478bd9Sstevel@tonic-gate static int 4867c478bd9Sstevel@tonic-gate sctp_get_peer_addr_params(sctp_t *sctp, void *ptr) 4877c478bd9Sstevel@tonic-gate { 4887c478bd9Sstevel@tonic-gate struct sctp_paddrparams *spp = ptr; 4897c478bd9Sstevel@tonic-gate sctp_faddr_t *fp; 4907c478bd9Sstevel@tonic-gate int retval; 4917c478bd9Sstevel@tonic-gate 4927c478bd9Sstevel@tonic-gate retval = sctp_find_peer_fp(sctp, &spp->spp_address, &fp); 4937c478bd9Sstevel@tonic-gate if (retval) { 4947c478bd9Sstevel@tonic-gate return (retval); 4957c478bd9Sstevel@tonic-gate } 4967c478bd9Sstevel@tonic-gate if (fp) { 4977c478bd9Sstevel@tonic-gate spp->spp_hbinterval = TICK_TO_MSEC(fp->hb_interval); 4987c478bd9Sstevel@tonic-gate spp->spp_pathmaxrxt = fp->max_retr; 4997c478bd9Sstevel@tonic-gate } else { 5007c478bd9Sstevel@tonic-gate spp->spp_hbinterval = TICK_TO_MSEC(sctp->sctp_hb_interval); 5017c478bd9Sstevel@tonic-gate spp->spp_pathmaxrxt = sctp->sctp_pp_max_rxt; 5027c478bd9Sstevel@tonic-gate } 5037c478bd9Sstevel@tonic-gate return (sizeof (*spp)); 5047c478bd9Sstevel@tonic-gate } 5057c478bd9Sstevel@tonic-gate 5067c478bd9Sstevel@tonic-gate static int 5077c478bd9Sstevel@tonic-gate sctp_set_peer_addr_params(sctp_t *sctp, const void *invalp, uint_t inlen) 5087c478bd9Sstevel@tonic-gate { 5097c478bd9Sstevel@tonic-gate const struct sctp_paddrparams *spp = invalp; 5107c478bd9Sstevel@tonic-gate sctp_faddr_t *fp, *fp2; 5117c478bd9Sstevel@tonic-gate int retval; 5127c478bd9Sstevel@tonic-gate uint32_t sum = 0; 5137c478bd9Sstevel@tonic-gate int64_t now; 5147c478bd9Sstevel@tonic-gate 5157c478bd9Sstevel@tonic-gate if (inlen < sizeof (*spp)) { 5167c478bd9Sstevel@tonic-gate return (EINVAL); 5177c478bd9Sstevel@tonic-gate } 5187c478bd9Sstevel@tonic-gate 5197c478bd9Sstevel@tonic-gate retval = sctp_find_peer_fp(sctp, &spp->spp_address, &fp); 5207c478bd9Sstevel@tonic-gate if (retval != 0) { 5217c478bd9Sstevel@tonic-gate return (retval); 5227c478bd9Sstevel@tonic-gate } 5237c478bd9Sstevel@tonic-gate 5247c478bd9Sstevel@tonic-gate if (spp->spp_hbinterval && spp->spp_hbinterval != UINT32_MAX && 5257c478bd9Sstevel@tonic-gate (spp->spp_hbinterval < sctp_heartbeat_interval_low || 5267c478bd9Sstevel@tonic-gate spp->spp_hbinterval > sctp_heartbeat_interval_high)) { 5277c478bd9Sstevel@tonic-gate return (EINVAL); 5287c478bd9Sstevel@tonic-gate } 5297c478bd9Sstevel@tonic-gate if (spp->spp_pathmaxrxt && 5307c478bd9Sstevel@tonic-gate (spp->spp_pathmaxrxt < sctp_pp_max_retr_low || 5317c478bd9Sstevel@tonic-gate spp->spp_pathmaxrxt > sctp_pp_max_retr_high)) { 5327c478bd9Sstevel@tonic-gate return (EINVAL); 5337c478bd9Sstevel@tonic-gate } 5347c478bd9Sstevel@tonic-gate if (spp->spp_pathmaxrxt && sctp->sctp_faddrs) { 5357c478bd9Sstevel@tonic-gate for (fp2 = sctp->sctp_faddrs; fp2; fp2 = fp2->next) { 5367c478bd9Sstevel@tonic-gate if (!fp || fp2 == fp) { 5377c478bd9Sstevel@tonic-gate sum += spp->spp_pathmaxrxt; 5387c478bd9Sstevel@tonic-gate } else { 5397c478bd9Sstevel@tonic-gate sum += fp2->max_retr; 5407c478bd9Sstevel@tonic-gate } 5417c478bd9Sstevel@tonic-gate } 5427c478bd9Sstevel@tonic-gate if (sctp->sctp_pa_max_rxt > sum) { 5437c478bd9Sstevel@tonic-gate return (EINVAL); 5447c478bd9Sstevel@tonic-gate } 5457c478bd9Sstevel@tonic-gate } 5467c478bd9Sstevel@tonic-gate 5477c478bd9Sstevel@tonic-gate now = lbolt64; 5487c478bd9Sstevel@tonic-gate if (fp != NULL) { 5497c478bd9Sstevel@tonic-gate if (spp->spp_hbinterval == UINT32_MAX) { 5507c478bd9Sstevel@tonic-gate /* 5517c478bd9Sstevel@tonic-gate * Send heartbeat immediatelly, don't modify the 5527c478bd9Sstevel@tonic-gate * current setting. 5537c478bd9Sstevel@tonic-gate */ 5547c478bd9Sstevel@tonic-gate sctp_send_heartbeat(sctp, fp); 5557c478bd9Sstevel@tonic-gate } else { 5567c478bd9Sstevel@tonic-gate fp->hb_interval = MSEC_TO_TICK(spp->spp_hbinterval); 5577c478bd9Sstevel@tonic-gate fp->hb_expiry = now + SET_HB_INTVL(fp); 5587c478bd9Sstevel@tonic-gate /* 5597c478bd9Sstevel@tonic-gate * Restart the heartbeat timer using the new intrvl. 5607c478bd9Sstevel@tonic-gate * We need to call sctp_heartbeat_timer() to set 5617c478bd9Sstevel@tonic-gate * the earliest heartbeat expiry time. 5627c478bd9Sstevel@tonic-gate */ 5637c478bd9Sstevel@tonic-gate sctp_heartbeat_timer(sctp); 5647c478bd9Sstevel@tonic-gate } 5657c478bd9Sstevel@tonic-gate if (spp->spp_pathmaxrxt) { 5667c478bd9Sstevel@tonic-gate fp->max_retr = spp->spp_pathmaxrxt; 5677c478bd9Sstevel@tonic-gate } 5687c478bd9Sstevel@tonic-gate } else { 5697c478bd9Sstevel@tonic-gate for (fp2 = sctp->sctp_faddrs; fp2 != NULL; fp2 = fp2->next) { 5707c478bd9Sstevel@tonic-gate if (spp->spp_hbinterval == UINT32_MAX) { 5717c478bd9Sstevel@tonic-gate /* 5727c478bd9Sstevel@tonic-gate * Send heartbeat immediatelly, don't modify 5737c478bd9Sstevel@tonic-gate * the current setting. 5747c478bd9Sstevel@tonic-gate */ 5757c478bd9Sstevel@tonic-gate sctp_send_heartbeat(sctp, fp2); 5767c478bd9Sstevel@tonic-gate } else { 5777c478bd9Sstevel@tonic-gate fp2->hb_interval = MSEC_TO_TICK( 5787c478bd9Sstevel@tonic-gate spp->spp_hbinterval); 5797c478bd9Sstevel@tonic-gate fp2->hb_expiry = now + SET_HB_INTVL(fp2); 5807c478bd9Sstevel@tonic-gate } 5817c478bd9Sstevel@tonic-gate if (spp->spp_pathmaxrxt) { 5827c478bd9Sstevel@tonic-gate fp2->max_retr = spp->spp_pathmaxrxt; 5837c478bd9Sstevel@tonic-gate } 5847c478bd9Sstevel@tonic-gate } 5857c478bd9Sstevel@tonic-gate if (spp->spp_hbinterval != UINT32_MAX) { 5867c478bd9Sstevel@tonic-gate sctp->sctp_hb_interval = MSEC_TO_TICK( 5877c478bd9Sstevel@tonic-gate spp->spp_hbinterval); 5887c478bd9Sstevel@tonic-gate /* Restart the heartbeat timer using the new intrvl. */ 5897c478bd9Sstevel@tonic-gate sctp_timer(sctp, sctp->sctp_heartbeat_mp, 5907c478bd9Sstevel@tonic-gate sctp->sctp_hb_interval); 5917c478bd9Sstevel@tonic-gate } 5927c478bd9Sstevel@tonic-gate if (spp->spp_pathmaxrxt) { 5937c478bd9Sstevel@tonic-gate sctp->sctp_pp_max_rxt = spp->spp_pathmaxrxt; 5947c478bd9Sstevel@tonic-gate } 5957c478bd9Sstevel@tonic-gate } 5967c478bd9Sstevel@tonic-gate return (0); 5977c478bd9Sstevel@tonic-gate } 5987c478bd9Sstevel@tonic-gate 5997c478bd9Sstevel@tonic-gate /* 6007c478bd9Sstevel@tonic-gate * SCTP_DEFAULT_SEND_PARAM 6017c478bd9Sstevel@tonic-gate */ 6027c478bd9Sstevel@tonic-gate static int 6037c478bd9Sstevel@tonic-gate sctp_get_def_send_params(sctp_t *sctp, void *ptr) 6047c478bd9Sstevel@tonic-gate { 6057c478bd9Sstevel@tonic-gate struct sctp_sndrcvinfo *sinfo = ptr; 6067c478bd9Sstevel@tonic-gate 6077c478bd9Sstevel@tonic-gate sinfo->sinfo_stream = sctp->sctp_def_stream; 6087c478bd9Sstevel@tonic-gate sinfo->sinfo_ssn = 0; 6097c478bd9Sstevel@tonic-gate sinfo->sinfo_flags = sctp->sctp_def_flags; 6107c478bd9Sstevel@tonic-gate sinfo->sinfo_ppid = sctp->sctp_def_ppid; 6117c478bd9Sstevel@tonic-gate sinfo->sinfo_context = sctp->sctp_def_context; 6127c478bd9Sstevel@tonic-gate sinfo->sinfo_timetolive = sctp->sctp_def_timetolive; 6137c478bd9Sstevel@tonic-gate sinfo->sinfo_tsn = 0; 6147c478bd9Sstevel@tonic-gate sinfo->sinfo_cumtsn = 0; 6157c478bd9Sstevel@tonic-gate 6167c478bd9Sstevel@tonic-gate return (sizeof (*sinfo)); 6177c478bd9Sstevel@tonic-gate } 6187c478bd9Sstevel@tonic-gate 6197c478bd9Sstevel@tonic-gate static int 6207c478bd9Sstevel@tonic-gate sctp_set_def_send_params(sctp_t *sctp, const void *invalp, uint_t inlen) 6217c478bd9Sstevel@tonic-gate { 6227c478bd9Sstevel@tonic-gate const struct sctp_sndrcvinfo *sinfo = invalp; 6237c478bd9Sstevel@tonic-gate 6247c478bd9Sstevel@tonic-gate if (inlen < sizeof (*sinfo)) { 6257c478bd9Sstevel@tonic-gate return (EINVAL); 6267c478bd9Sstevel@tonic-gate } 6277c478bd9Sstevel@tonic-gate if (sinfo->sinfo_stream >= sctp->sctp_num_ostr) { 6287c478bd9Sstevel@tonic-gate return (EINVAL); 6297c478bd9Sstevel@tonic-gate } 6307c478bd9Sstevel@tonic-gate 6317c478bd9Sstevel@tonic-gate sctp->sctp_def_stream = sinfo->sinfo_stream; 6327c478bd9Sstevel@tonic-gate sctp->sctp_def_flags = sinfo->sinfo_flags; 6337c478bd9Sstevel@tonic-gate sctp->sctp_def_ppid = sinfo->sinfo_ppid; 6347c478bd9Sstevel@tonic-gate sctp->sctp_def_context = sinfo->sinfo_context; 6357c478bd9Sstevel@tonic-gate sctp->sctp_def_timetolive = sinfo->sinfo_timetolive; 6367c478bd9Sstevel@tonic-gate 6377c478bd9Sstevel@tonic-gate return (0); 6387c478bd9Sstevel@tonic-gate } 6397c478bd9Sstevel@tonic-gate 6407c478bd9Sstevel@tonic-gate static int 6417c478bd9Sstevel@tonic-gate sctp_set_prim(sctp_t *sctp, const void *invalp, uint_t inlen) 6427c478bd9Sstevel@tonic-gate { 6437c478bd9Sstevel@tonic-gate const struct sctp_setpeerprim *pp = invalp; 6447c478bd9Sstevel@tonic-gate int retval; 6457c478bd9Sstevel@tonic-gate sctp_faddr_t *fp; 6467c478bd9Sstevel@tonic-gate 6477c478bd9Sstevel@tonic-gate if (inlen < sizeof (*pp)) { 6487c478bd9Sstevel@tonic-gate return (EINVAL); 6497c478bd9Sstevel@tonic-gate } 6507c478bd9Sstevel@tonic-gate 6517c478bd9Sstevel@tonic-gate retval = sctp_find_peer_fp(sctp, &pp->sspp_addr, &fp); 6527c478bd9Sstevel@tonic-gate if (retval) 6537c478bd9Sstevel@tonic-gate return (retval); 6547c478bd9Sstevel@tonic-gate 6557c478bd9Sstevel@tonic-gate if (fp == NULL) 6567c478bd9Sstevel@tonic-gate return (EINVAL); 6577c478bd9Sstevel@tonic-gate if (fp == sctp->sctp_primary) 6587c478bd9Sstevel@tonic-gate return (0); 6597c478bd9Sstevel@tonic-gate sctp->sctp_primary = fp; 6607c478bd9Sstevel@tonic-gate 6617c478bd9Sstevel@tonic-gate /* Only switch current if fp is alive */ 6627c478bd9Sstevel@tonic-gate if (fp->state != SCTP_FADDRS_ALIVE || fp == sctp->sctp_current) { 6637c478bd9Sstevel@tonic-gate return (0); 6647c478bd9Sstevel@tonic-gate } 665*77c67f2fSkcpoon sctp_set_faddr_current(sctp, fp); 6667c478bd9Sstevel@tonic-gate 6677c478bd9Sstevel@tonic-gate return (0); 6687c478bd9Sstevel@tonic-gate } 6697c478bd9Sstevel@tonic-gate 6707c478bd9Sstevel@tonic-gate /* Handy on off switch for socket option processing. */ 6717c478bd9Sstevel@tonic-gate #define ONOFF(x) ((x) == 0 ? 0 : 1) 6727c478bd9Sstevel@tonic-gate 6737c478bd9Sstevel@tonic-gate /* 6747c478bd9Sstevel@tonic-gate * SCTP routine to get the values of options. 6757c478bd9Sstevel@tonic-gate */ 6767c478bd9Sstevel@tonic-gate int 6777c478bd9Sstevel@tonic-gate sctp_get_opt(sctp_t *sctp, int level, int name, void *ptr, socklen_t *optlen) 6787c478bd9Sstevel@tonic-gate { 6797c478bd9Sstevel@tonic-gate int *i1 = (int *)ptr; 6807c478bd9Sstevel@tonic-gate int retval = 0; 6817c478bd9Sstevel@tonic-gate int buflen = *optlen; 68243d18f1cSpriyanka conn_t *connp = sctp->sctp_connp; 6837c478bd9Sstevel@tonic-gate ip6_pkt_t *ipp = &sctp->sctp_sticky_ipp; 6847c478bd9Sstevel@tonic-gate /* In most cases, the return buffer is just an int */ 6857c478bd9Sstevel@tonic-gate *optlen = sizeof (int32_t); 6867c478bd9Sstevel@tonic-gate 6877c478bd9Sstevel@tonic-gate RUN_SCTP(sctp); 6887c478bd9Sstevel@tonic-gate 6897c478bd9Sstevel@tonic-gate switch (level) { 6907c478bd9Sstevel@tonic-gate case SOL_SOCKET: 6917c478bd9Sstevel@tonic-gate switch (name) { 6927c478bd9Sstevel@tonic-gate case SO_LINGER: { 6937c478bd9Sstevel@tonic-gate struct linger *lgr = (struct linger *)ptr; 6947c478bd9Sstevel@tonic-gate 6957c478bd9Sstevel@tonic-gate lgr->l_onoff = sctp->sctp_linger ? SO_LINGER : 0; 6967c478bd9Sstevel@tonic-gate lgr->l_linger = TICK_TO_MSEC(sctp->sctp_lingertime); 6977c478bd9Sstevel@tonic-gate *optlen = sizeof (struct linger); 6987c478bd9Sstevel@tonic-gate break; 6997c478bd9Sstevel@tonic-gate } 7007c478bd9Sstevel@tonic-gate case SO_DEBUG: 7017c478bd9Sstevel@tonic-gate *i1 = sctp->sctp_debug ? SO_DEBUG : 0; 7027c478bd9Sstevel@tonic-gate break; 7037c478bd9Sstevel@tonic-gate case SO_DONTROUTE: 7047c478bd9Sstevel@tonic-gate *i1 = sctp->sctp_dontroute ? SO_DONTROUTE : 0; 7057c478bd9Sstevel@tonic-gate break; 7067c478bd9Sstevel@tonic-gate case SO_USELOOPBACK: 7077c478bd9Sstevel@tonic-gate *i1 = sctp->sctp_useloopback ? SO_USELOOPBACK : 0; 7087c478bd9Sstevel@tonic-gate break; 7097c478bd9Sstevel@tonic-gate case SO_BROADCAST: 7107c478bd9Sstevel@tonic-gate *i1 = sctp->sctp_broadcast ? SO_BROADCAST : 0; 7117c478bd9Sstevel@tonic-gate break; 7127c478bd9Sstevel@tonic-gate case SO_REUSEADDR: 7137c478bd9Sstevel@tonic-gate *i1 = sctp->sctp_reuseaddr ? SO_REUSEADDR : 0; 7147c478bd9Sstevel@tonic-gate break; 7157c478bd9Sstevel@tonic-gate case SO_DGRAM_ERRIND: 7167c478bd9Sstevel@tonic-gate *i1 = sctp->sctp_dgram_errind ? SO_DGRAM_ERRIND : 0; 7177c478bd9Sstevel@tonic-gate break; 7187c478bd9Sstevel@tonic-gate case SO_SNDBUF: 7197c478bd9Sstevel@tonic-gate *i1 = sctp->sctp_xmit_hiwater; 7207c478bd9Sstevel@tonic-gate break; 7217c478bd9Sstevel@tonic-gate case SO_RCVBUF: 7227c478bd9Sstevel@tonic-gate *i1 = sctp->sctp_rwnd; 7237c478bd9Sstevel@tonic-gate break; 72445916cd2Sjpk case SO_MAC_EXEMPT: 72545916cd2Sjpk *i1 = sctp->sctp_mac_exempt ? SO_MAC_EXEMPT : 0; 72645916cd2Sjpk break; 7277c478bd9Sstevel@tonic-gate default: 7287c478bd9Sstevel@tonic-gate retval = EINVAL; 7297c478bd9Sstevel@tonic-gate break; 7307c478bd9Sstevel@tonic-gate } 7317c478bd9Sstevel@tonic-gate break; 7327c478bd9Sstevel@tonic-gate 7337c478bd9Sstevel@tonic-gate case IPPROTO_SCTP: 7347c478bd9Sstevel@tonic-gate switch (name) { 7357c478bd9Sstevel@tonic-gate case SCTP_RTOINFO: 7367c478bd9Sstevel@tonic-gate if (buflen < sizeof (struct sctp_rtoinfo)) { 7377c478bd9Sstevel@tonic-gate retval = EINVAL; 7387c478bd9Sstevel@tonic-gate break; 7397c478bd9Sstevel@tonic-gate } 7407c478bd9Sstevel@tonic-gate *optlen = sctp_get_rtoinfo(sctp, ptr); 7417c478bd9Sstevel@tonic-gate break; 7427c478bd9Sstevel@tonic-gate case SCTP_ASSOCINFO: 7437c478bd9Sstevel@tonic-gate if (buflen < sizeof (struct sctp_assocparams)) { 7447c478bd9Sstevel@tonic-gate retval = EINVAL; 7457c478bd9Sstevel@tonic-gate break; 7467c478bd9Sstevel@tonic-gate } 7477c478bd9Sstevel@tonic-gate *optlen = sctp_get_assocparams(sctp, ptr); 7487c478bd9Sstevel@tonic-gate break; 7497c478bd9Sstevel@tonic-gate case SCTP_INITMSG: 7507c478bd9Sstevel@tonic-gate if (buflen < sizeof (struct sctp_initmsg)) { 7517c478bd9Sstevel@tonic-gate retval = EINVAL; 7527c478bd9Sstevel@tonic-gate break; 7537c478bd9Sstevel@tonic-gate } 7547c478bd9Sstevel@tonic-gate *optlen = sctp_get_initmsg(sctp, ptr); 7557c478bd9Sstevel@tonic-gate break; 7567c478bd9Sstevel@tonic-gate case SCTP_NODELAY: 7577c478bd9Sstevel@tonic-gate *i1 = sctp->sctp_ndelay; 7587c478bd9Sstevel@tonic-gate break; 7597c478bd9Sstevel@tonic-gate case SCTP_AUTOCLOSE: 7607c478bd9Sstevel@tonic-gate *i1 = TICK_TO_SEC(sctp->sctp_autoclose); 7617c478bd9Sstevel@tonic-gate break; 7627c478bd9Sstevel@tonic-gate case SCTP_ADAPTION_LAYER: 7637c478bd9Sstevel@tonic-gate if (buflen < sizeof (struct sctp_setadaption)) { 7647c478bd9Sstevel@tonic-gate retval = EINVAL; 7657c478bd9Sstevel@tonic-gate break; 7667c478bd9Sstevel@tonic-gate } 7677c478bd9Sstevel@tonic-gate ((struct sctp_setadaption *)ptr)->ssb_adaption_ind = 7687c478bd9Sstevel@tonic-gate sctp->sctp_tx_adaption_code; 7697c478bd9Sstevel@tonic-gate break; 7707c478bd9Sstevel@tonic-gate case SCTP_PEER_ADDR_PARAMS: 7717c478bd9Sstevel@tonic-gate if (buflen < sizeof (struct sctp_paddrparams)) { 7727c478bd9Sstevel@tonic-gate retval = EINVAL; 7737c478bd9Sstevel@tonic-gate break; 7747c478bd9Sstevel@tonic-gate } 7757c478bd9Sstevel@tonic-gate *optlen = sctp_get_peer_addr_params(sctp, ptr); 7767c478bd9Sstevel@tonic-gate break; 7777c478bd9Sstevel@tonic-gate case SCTP_DEFAULT_SEND_PARAM: 7787c478bd9Sstevel@tonic-gate if (buflen < sizeof (struct sctp_sndrcvinfo)) { 7797c478bd9Sstevel@tonic-gate retval = EINVAL; 7807c478bd9Sstevel@tonic-gate break; 7817c478bd9Sstevel@tonic-gate } 7827c478bd9Sstevel@tonic-gate *optlen = sctp_get_def_send_params(sctp, ptr); 7837c478bd9Sstevel@tonic-gate break; 7847c478bd9Sstevel@tonic-gate case SCTP_EVENTS: { 7857c478bd9Sstevel@tonic-gate struct sctp_event_subscribe *ev; 7867c478bd9Sstevel@tonic-gate 7877c478bd9Sstevel@tonic-gate if (buflen < sizeof (struct sctp_event_subscribe)) { 7887c478bd9Sstevel@tonic-gate retval = EINVAL; 7897c478bd9Sstevel@tonic-gate break; 7907c478bd9Sstevel@tonic-gate } 7917c478bd9Sstevel@tonic-gate ev = (struct sctp_event_subscribe *)ptr; 7927c478bd9Sstevel@tonic-gate ev->sctp_data_io_event = 7937c478bd9Sstevel@tonic-gate ONOFF(sctp->sctp_recvsndrcvinfo); 7947c478bd9Sstevel@tonic-gate ev->sctp_association_event = 7957c478bd9Sstevel@tonic-gate ONOFF(sctp->sctp_recvassocevnt); 7967c478bd9Sstevel@tonic-gate ev->sctp_address_event = 7977c478bd9Sstevel@tonic-gate ONOFF(sctp->sctp_recvpathevnt); 7987c478bd9Sstevel@tonic-gate ev->sctp_send_failure_event = 7997c478bd9Sstevel@tonic-gate ONOFF(sctp->sctp_recvsendfailevnt); 8007c478bd9Sstevel@tonic-gate ev->sctp_peer_error_event = 8017c478bd9Sstevel@tonic-gate ONOFF(sctp->sctp_recvpeererr); 8027c478bd9Sstevel@tonic-gate ev->sctp_shutdown_event = 8037c478bd9Sstevel@tonic-gate ONOFF(sctp->sctp_recvshutdownevnt); 8047c478bd9Sstevel@tonic-gate ev->sctp_partial_delivery_event = 8057c478bd9Sstevel@tonic-gate ONOFF(sctp->sctp_recvpdevnt); 8067c478bd9Sstevel@tonic-gate ev->sctp_adaption_layer_event = 8077c478bd9Sstevel@tonic-gate ONOFF(sctp->sctp_recvalevnt); 8087c478bd9Sstevel@tonic-gate *optlen = sizeof (struct sctp_event_subscribe); 8097c478bd9Sstevel@tonic-gate break; 8107c478bd9Sstevel@tonic-gate } 8117c478bd9Sstevel@tonic-gate case SCTP_STATUS: 8127c478bd9Sstevel@tonic-gate if (buflen < sizeof (struct sctp_status)) { 8137c478bd9Sstevel@tonic-gate retval = EINVAL; 8147c478bd9Sstevel@tonic-gate break; 8157c478bd9Sstevel@tonic-gate } 8167c478bd9Sstevel@tonic-gate *optlen = sctp_get_status(sctp, ptr); 8177c478bd9Sstevel@tonic-gate break; 8187c478bd9Sstevel@tonic-gate case SCTP_GET_PEER_ADDR_INFO: 8197c478bd9Sstevel@tonic-gate if (buflen < sizeof (struct sctp_paddrinfo)) { 8207c478bd9Sstevel@tonic-gate retval = EINVAL; 8217c478bd9Sstevel@tonic-gate break; 8227c478bd9Sstevel@tonic-gate } 8237c478bd9Sstevel@tonic-gate retval = sctp_get_paddrinfo(sctp, ptr, optlen); 8247c478bd9Sstevel@tonic-gate break; 8257c478bd9Sstevel@tonic-gate case SCTP_GET_NLADDRS: 8267c478bd9Sstevel@tonic-gate *(int32_t *)ptr = sctp->sctp_nsaddrs; 8277c478bd9Sstevel@tonic-gate break; 8287c478bd9Sstevel@tonic-gate case SCTP_GET_LADDRS: { 8297c478bd9Sstevel@tonic-gate int addr_cnt; 8307c478bd9Sstevel@tonic-gate int addr_size; 8317c478bd9Sstevel@tonic-gate 8327c478bd9Sstevel@tonic-gate if (sctp->sctp_family == AF_INET) 8337c478bd9Sstevel@tonic-gate addr_size = sizeof (struct sockaddr_in); 8347c478bd9Sstevel@tonic-gate else 8357c478bd9Sstevel@tonic-gate addr_size = sizeof (struct sockaddr_in6); 8367c478bd9Sstevel@tonic-gate addr_cnt = buflen / addr_size; 8377c478bd9Sstevel@tonic-gate retval = sctp_getmyaddrs(sctp, ptr, &addr_cnt); 8387c478bd9Sstevel@tonic-gate if (retval == 0) 8397c478bd9Sstevel@tonic-gate *optlen = addr_cnt * addr_size; 8407c478bd9Sstevel@tonic-gate break; 8417c478bd9Sstevel@tonic-gate } 8427c478bd9Sstevel@tonic-gate case SCTP_GET_NPADDRS: { 8437c478bd9Sstevel@tonic-gate int i; 8447c478bd9Sstevel@tonic-gate sctp_faddr_t *fp; 8457c478bd9Sstevel@tonic-gate 8467c478bd9Sstevel@tonic-gate for (i = 0, fp = sctp->sctp_faddrs; fp != NULL; 8477c478bd9Sstevel@tonic-gate i++, fp = fp->next) 8487c478bd9Sstevel@tonic-gate ; 8497c478bd9Sstevel@tonic-gate *(int32_t *)ptr = i; 8507c478bd9Sstevel@tonic-gate break; 8517c478bd9Sstevel@tonic-gate } 8527c478bd9Sstevel@tonic-gate case SCTP_GET_PADDRS: { 8537c478bd9Sstevel@tonic-gate int addr_cnt; 8547c478bd9Sstevel@tonic-gate int addr_size; 8557c478bd9Sstevel@tonic-gate 8567c478bd9Sstevel@tonic-gate if (sctp->sctp_family == AF_INET) 8577c478bd9Sstevel@tonic-gate addr_size = sizeof (struct sockaddr_in); 8587c478bd9Sstevel@tonic-gate else 8597c478bd9Sstevel@tonic-gate addr_size = sizeof (struct sockaddr_in6); 8607c478bd9Sstevel@tonic-gate addr_cnt = buflen / addr_size; 8617c478bd9Sstevel@tonic-gate retval = sctp_getpeeraddrs(sctp, ptr, &addr_cnt); 8627c478bd9Sstevel@tonic-gate if (retval == 0) 8637c478bd9Sstevel@tonic-gate *optlen = addr_cnt * addr_size; 8647c478bd9Sstevel@tonic-gate break; 8657c478bd9Sstevel@tonic-gate } 8667c478bd9Sstevel@tonic-gate case SCTP_PRSCTP: 8677c478bd9Sstevel@tonic-gate *i1 = sctp->sctp_prsctp_aware ? 1 : 0; 8687c478bd9Sstevel@tonic-gate break; 8697c478bd9Sstevel@tonic-gate case SCTP_I_WANT_MAPPED_V4_ADDR: 8707c478bd9Sstevel@tonic-gate case SCTP_MAXSEG: 8717c478bd9Sstevel@tonic-gate case SCTP_DISABLE_FRAGMENTS: 8727c478bd9Sstevel@tonic-gate /* Not yet supported. */ 8737c478bd9Sstevel@tonic-gate default: 8747c478bd9Sstevel@tonic-gate retval = EINVAL; 8757c478bd9Sstevel@tonic-gate break; 8767c478bd9Sstevel@tonic-gate } 8777c478bd9Sstevel@tonic-gate break; 8787c478bd9Sstevel@tonic-gate 8797c478bd9Sstevel@tonic-gate case IPPROTO_IP: 8807c478bd9Sstevel@tonic-gate if (sctp->sctp_family != AF_INET) { 8817c478bd9Sstevel@tonic-gate retval = EINVAL; 8827c478bd9Sstevel@tonic-gate break; 8837c478bd9Sstevel@tonic-gate } 8847c478bd9Sstevel@tonic-gate switch (name) { 8857c478bd9Sstevel@tonic-gate case IP_OPTIONS: 8867c478bd9Sstevel@tonic-gate case T_IP_OPTIONS: { 8877c478bd9Sstevel@tonic-gate /* 8887c478bd9Sstevel@tonic-gate * This is compatible with BSD in that in only return 8897c478bd9Sstevel@tonic-gate * the reverse source route with the final destination 8907c478bd9Sstevel@tonic-gate * as the last entry. The first 4 bytes of the option 8917c478bd9Sstevel@tonic-gate * will contain the final destination. Allocate a 8927c478bd9Sstevel@tonic-gate * buffer large enough to hold all the options, we 8937c478bd9Sstevel@tonic-gate * add IP_ADDR_LEN to SCTP_MAX_IP_OPTIONS_LENGTH since 89445916cd2Sjpk * ip_opt_get_user() adds the final destination 8957c478bd9Sstevel@tonic-gate * at the start. 8967c478bd9Sstevel@tonic-gate */ 8977c478bd9Sstevel@tonic-gate char *opt_ptr; 8987c478bd9Sstevel@tonic-gate int opt_len; 8997c478bd9Sstevel@tonic-gate uchar_t obuf[SCTP_MAX_IP_OPTIONS_LENGTH + IP_ADDR_LEN]; 9007c478bd9Sstevel@tonic-gate 9017c478bd9Sstevel@tonic-gate opt_ptr = (char *)sctp->sctp_ipha + 9027c478bd9Sstevel@tonic-gate IP_SIMPLE_HDR_LENGTH; 9037c478bd9Sstevel@tonic-gate opt_len = (char *)sctp->sctp_sctph - opt_ptr; 9047c478bd9Sstevel@tonic-gate /* Caller ensures enough space */ 9057c478bd9Sstevel@tonic-gate if (opt_len > 0) { 9067c478bd9Sstevel@tonic-gate /* 9077c478bd9Sstevel@tonic-gate * TODO: Do we have to handle getsockopt on an 9087c478bd9Sstevel@tonic-gate * initiator as well? 9097c478bd9Sstevel@tonic-gate */ 91045916cd2Sjpk opt_len = ip_opt_get_user(sctp->sctp_ipha, 9117c478bd9Sstevel@tonic-gate obuf); 9127c478bd9Sstevel@tonic-gate ASSERT(opt_len <= sizeof (obuf)); 9137c478bd9Sstevel@tonic-gate } else { 9147c478bd9Sstevel@tonic-gate opt_len = 0; 9157c478bd9Sstevel@tonic-gate } 9167c478bd9Sstevel@tonic-gate if (buflen < opt_len) { 9177c478bd9Sstevel@tonic-gate /* Silently truncate */ 9187c478bd9Sstevel@tonic-gate opt_len = buflen; 9197c478bd9Sstevel@tonic-gate } 9207c478bd9Sstevel@tonic-gate *optlen = opt_len; 9217c478bd9Sstevel@tonic-gate bcopy(obuf, ptr, opt_len); 9227c478bd9Sstevel@tonic-gate break; 9237c478bd9Sstevel@tonic-gate } 9247c478bd9Sstevel@tonic-gate case IP_TOS: 9257c478bd9Sstevel@tonic-gate case T_IP_TOS: 9267c478bd9Sstevel@tonic-gate *i1 = (int)sctp->sctp_ipha->ipha_type_of_service; 9277c478bd9Sstevel@tonic-gate break; 9287c478bd9Sstevel@tonic-gate case IP_TTL: 9297c478bd9Sstevel@tonic-gate *i1 = (int)sctp->sctp_ipha->ipha_ttl; 9307c478bd9Sstevel@tonic-gate break; 93143d18f1cSpriyanka case IP_NEXTHOP: 93243d18f1cSpriyanka if (connp->conn_nexthop_set) { 93343d18f1cSpriyanka *(ipaddr_t *)ptr = connp->conn_nexthop_v4; 93443d18f1cSpriyanka *optlen = sizeof (ipaddr_t); 93543d18f1cSpriyanka } else { 93643d18f1cSpriyanka *optlen = 0; 93743d18f1cSpriyanka } 93843d18f1cSpriyanka break; 9397c478bd9Sstevel@tonic-gate default: 9407c478bd9Sstevel@tonic-gate retval = EINVAL; 9417c478bd9Sstevel@tonic-gate break; 9427c478bd9Sstevel@tonic-gate } 9437c478bd9Sstevel@tonic-gate break; 9447c478bd9Sstevel@tonic-gate case IPPROTO_IPV6: 9457c478bd9Sstevel@tonic-gate if (sctp->sctp_family != AF_INET6) { 9467c478bd9Sstevel@tonic-gate retval = EINVAL; 9477c478bd9Sstevel@tonic-gate break; 9487c478bd9Sstevel@tonic-gate } 9497c478bd9Sstevel@tonic-gate switch (name) { 9507c478bd9Sstevel@tonic-gate case IPV6_UNICAST_HOPS: 9517c478bd9Sstevel@tonic-gate *i1 = (unsigned int) sctp->sctp_ip6h->ip6_hops; 9527c478bd9Sstevel@tonic-gate break; /* goto sizeof (int) option return */ 9537c478bd9Sstevel@tonic-gate case IPV6_RECVPKTINFO: 9547c478bd9Sstevel@tonic-gate if (sctp->sctp_ipv6_recvancillary & 9557c478bd9Sstevel@tonic-gate SCTP_IPV6_RECVPKTINFO) { 9567c478bd9Sstevel@tonic-gate *i1 = 1; 9577c478bd9Sstevel@tonic-gate } else { 9587c478bd9Sstevel@tonic-gate *i1 = 0; 9597c478bd9Sstevel@tonic-gate } 9607c478bd9Sstevel@tonic-gate break; /* goto sizeof (int) option return */ 9617c478bd9Sstevel@tonic-gate case IPV6_RECVHOPLIMIT: 9627c478bd9Sstevel@tonic-gate if (sctp->sctp_ipv6_recvancillary & 9637c478bd9Sstevel@tonic-gate SCTP_IPV6_RECVHOPLIMIT) { 9647c478bd9Sstevel@tonic-gate *i1 = 1; 9657c478bd9Sstevel@tonic-gate } else { 9667c478bd9Sstevel@tonic-gate *i1 = 0; 9677c478bd9Sstevel@tonic-gate } 9687c478bd9Sstevel@tonic-gate break; /* goto sizeof (int) option return */ 9697c478bd9Sstevel@tonic-gate case IPV6_RECVHOPOPTS: 9707c478bd9Sstevel@tonic-gate if (sctp->sctp_ipv6_recvancillary & 9717c478bd9Sstevel@tonic-gate SCTP_IPV6_RECVHOPOPTS) { 9727c478bd9Sstevel@tonic-gate *i1 = 1; 9737c478bd9Sstevel@tonic-gate } else { 9747c478bd9Sstevel@tonic-gate *i1 = 0; 9757c478bd9Sstevel@tonic-gate } 9767c478bd9Sstevel@tonic-gate break; /* goto sizeof (int) option return */ 9777c478bd9Sstevel@tonic-gate case IPV6_RECVDSTOPTS: 9787c478bd9Sstevel@tonic-gate if (sctp->sctp_ipv6_recvancillary & 9797c478bd9Sstevel@tonic-gate SCTP_IPV6_RECVDSTOPTS) { 9807c478bd9Sstevel@tonic-gate *i1 = 1; 9817c478bd9Sstevel@tonic-gate } else { 9827c478bd9Sstevel@tonic-gate *i1 = 0; 9837c478bd9Sstevel@tonic-gate } 9847c478bd9Sstevel@tonic-gate break; /* goto sizeof (int) option return */ 9857c478bd9Sstevel@tonic-gate case IPV6_RECVRTHDR: 9867c478bd9Sstevel@tonic-gate if (sctp->sctp_ipv6_recvancillary & 9877c478bd9Sstevel@tonic-gate SCTP_IPV6_RECVRTHDR) { 9887c478bd9Sstevel@tonic-gate *i1 = 1; 9897c478bd9Sstevel@tonic-gate } else { 9907c478bd9Sstevel@tonic-gate *i1 = 0; 9917c478bd9Sstevel@tonic-gate } 9927c478bd9Sstevel@tonic-gate break; /* goto sizeof (int) option return */ 9937c478bd9Sstevel@tonic-gate case IPV6_RECVRTHDRDSTOPTS: 9947c478bd9Sstevel@tonic-gate if (sctp->sctp_ipv6_recvancillary & 9957c478bd9Sstevel@tonic-gate SCTP_IPV6_RECVRTDSTOPTS) { 9967c478bd9Sstevel@tonic-gate *i1 = 1; 9977c478bd9Sstevel@tonic-gate } else { 9987c478bd9Sstevel@tonic-gate *i1 = 0; 9997c478bd9Sstevel@tonic-gate } 10007c478bd9Sstevel@tonic-gate break; /* goto sizeof (int) option return */ 10017c478bd9Sstevel@tonic-gate case IPV6_PKTINFO: { 10027c478bd9Sstevel@tonic-gate struct in6_pktinfo *pkti; 10037c478bd9Sstevel@tonic-gate 10047c478bd9Sstevel@tonic-gate if (buflen < sizeof (struct in6_pktinfo)) { 10057c478bd9Sstevel@tonic-gate retval = EINVAL; 10067c478bd9Sstevel@tonic-gate break; 10077c478bd9Sstevel@tonic-gate } 10087c478bd9Sstevel@tonic-gate pkti = (struct in6_pktinfo *)ptr; 10097c478bd9Sstevel@tonic-gate if (ipp->ipp_fields & IPPF_IFINDEX) 10107c478bd9Sstevel@tonic-gate pkti->ipi6_ifindex = ipp->ipp_ifindex; 10117c478bd9Sstevel@tonic-gate else 10127c478bd9Sstevel@tonic-gate pkti->ipi6_ifindex = 0; 10137c478bd9Sstevel@tonic-gate if (ipp->ipp_fields & IPPF_ADDR) 10147c478bd9Sstevel@tonic-gate pkti->ipi6_addr = ipp->ipp_addr; 10157c478bd9Sstevel@tonic-gate else 10167c478bd9Sstevel@tonic-gate pkti->ipi6_addr = ipv6_all_zeros; 10177c478bd9Sstevel@tonic-gate *optlen = sizeof (struct in6_pktinfo); 10187c478bd9Sstevel@tonic-gate break; 10197c478bd9Sstevel@tonic-gate } 10207c478bd9Sstevel@tonic-gate case IPV6_NEXTHOP: { 10217c478bd9Sstevel@tonic-gate sin6_t *sin6; 10227c478bd9Sstevel@tonic-gate 10237c478bd9Sstevel@tonic-gate if (buflen < sizeof (sin6_t)) { 10247c478bd9Sstevel@tonic-gate retval = EINVAL; 10257c478bd9Sstevel@tonic-gate break; 10267c478bd9Sstevel@tonic-gate } 10277c478bd9Sstevel@tonic-gate sin6 = (sin6_t *)ptr; 10287c478bd9Sstevel@tonic-gate if (!(ipp->ipp_fields & IPPF_NEXTHOP)) 10297c478bd9Sstevel@tonic-gate break; 10307c478bd9Sstevel@tonic-gate *sin6 = sctp_sin6_null; 10317c478bd9Sstevel@tonic-gate sin6->sin6_family = AF_INET6; 10327c478bd9Sstevel@tonic-gate sin6->sin6_addr = ipp->ipp_nexthop; 10337c478bd9Sstevel@tonic-gate *optlen = sizeof (sin6_t); 10347c478bd9Sstevel@tonic-gate break; 10357c478bd9Sstevel@tonic-gate } 103645916cd2Sjpk case IPV6_HOPOPTS: { 103745916cd2Sjpk int len; 103845916cd2Sjpk 10397c478bd9Sstevel@tonic-gate if (!(ipp->ipp_fields & IPPF_HOPOPTS)) 10407c478bd9Sstevel@tonic-gate break; 104145916cd2Sjpk len = ipp->ipp_hopoptslen - sctp->sctp_v6label_len; 104245916cd2Sjpk if (len <= 0) 104345916cd2Sjpk break; 104445916cd2Sjpk if (buflen < len) { 10457c478bd9Sstevel@tonic-gate retval = EINVAL; 10467c478bd9Sstevel@tonic-gate break; 10477c478bd9Sstevel@tonic-gate } 104845916cd2Sjpk bcopy((char *)ipp->ipp_hopopts + 104945916cd2Sjpk sctp->sctp_v6label_len, ptr, len); 105045916cd2Sjpk if (sctp->sctp_v6label_len > 0) { 105145916cd2Sjpk char *cptr = ptr; 105245916cd2Sjpk 105345916cd2Sjpk /* 105445916cd2Sjpk * If the label length is greater than zero, 105545916cd2Sjpk * then we need to hide the label from user. 105645916cd2Sjpk * Make it look as though a normal Hop-By-Hop 105745916cd2Sjpk * Options Header is present here. 105845916cd2Sjpk */ 105945916cd2Sjpk cptr[0] = ((char *)ipp->ipp_hopopts)[0]; 106045916cd2Sjpk cptr[1] = (len + 7) / 8 - 1; 106145916cd2Sjpk } 106245916cd2Sjpk *optlen = len; 10637c478bd9Sstevel@tonic-gate break; 106445916cd2Sjpk } 10657c478bd9Sstevel@tonic-gate case IPV6_RTHDRDSTOPTS: 10667c478bd9Sstevel@tonic-gate if (!(ipp->ipp_fields & IPPF_RTDSTOPTS)) 10677c478bd9Sstevel@tonic-gate break; 10687c478bd9Sstevel@tonic-gate if (buflen < ipp->ipp_rtdstoptslen) { 10697c478bd9Sstevel@tonic-gate retval = EINVAL; 10707c478bd9Sstevel@tonic-gate break; 10717c478bd9Sstevel@tonic-gate } 10727c478bd9Sstevel@tonic-gate bcopy(ipp->ipp_rtdstopts, ptr, ipp->ipp_rtdstoptslen); 10737c478bd9Sstevel@tonic-gate *optlen = ipp->ipp_rtdstoptslen; 10747c478bd9Sstevel@tonic-gate break; 10757c478bd9Sstevel@tonic-gate case IPV6_RTHDR: 10767c478bd9Sstevel@tonic-gate if (!(ipp->ipp_fields & IPPF_RTHDR)) 10777c478bd9Sstevel@tonic-gate break; 10787c478bd9Sstevel@tonic-gate if (buflen < ipp->ipp_rthdrlen) { 10797c478bd9Sstevel@tonic-gate retval = EINVAL; 10807c478bd9Sstevel@tonic-gate break; 10817c478bd9Sstevel@tonic-gate } 10827c478bd9Sstevel@tonic-gate bcopy(ipp->ipp_rthdr, ptr, ipp->ipp_rthdrlen); 10837c478bd9Sstevel@tonic-gate *optlen = ipp->ipp_rthdrlen; 10847c478bd9Sstevel@tonic-gate break; 10857c478bd9Sstevel@tonic-gate case IPV6_DSTOPTS: 10867c478bd9Sstevel@tonic-gate if (!(ipp->ipp_fields & IPPF_DSTOPTS)) 10877c478bd9Sstevel@tonic-gate break; 10887c478bd9Sstevel@tonic-gate if (buflen < ipp->ipp_dstoptslen) { 10897c478bd9Sstevel@tonic-gate retval = EINVAL; 10907c478bd9Sstevel@tonic-gate break; 10917c478bd9Sstevel@tonic-gate } 10927c478bd9Sstevel@tonic-gate bcopy(ipp->ipp_dstopts, ptr, ipp->ipp_dstoptslen); 10937c478bd9Sstevel@tonic-gate *optlen = ipp->ipp_dstoptslen; 10947c478bd9Sstevel@tonic-gate break; 10957c478bd9Sstevel@tonic-gate case IPV6_V6ONLY: 10967c478bd9Sstevel@tonic-gate *i1 = sctp->sctp_connp->conn_ipv6_v6only; 10977c478bd9Sstevel@tonic-gate break; 10987c478bd9Sstevel@tonic-gate default: 10997c478bd9Sstevel@tonic-gate retval = EINVAL; 11007c478bd9Sstevel@tonic-gate break; 11017c478bd9Sstevel@tonic-gate } 11027c478bd9Sstevel@tonic-gate break; 11037c478bd9Sstevel@tonic-gate 11047c478bd9Sstevel@tonic-gate default: 11057c478bd9Sstevel@tonic-gate retval = EINVAL; 11067c478bd9Sstevel@tonic-gate break; 11077c478bd9Sstevel@tonic-gate } 11087c478bd9Sstevel@tonic-gate WAKE_SCTP(sctp); 11097c478bd9Sstevel@tonic-gate return (retval); 11107c478bd9Sstevel@tonic-gate } 11117c478bd9Sstevel@tonic-gate 11127c478bd9Sstevel@tonic-gate int 11137c478bd9Sstevel@tonic-gate sctp_set_opt(sctp_t *sctp, int level, int name, const void *invalp, 11147c478bd9Sstevel@tonic-gate socklen_t inlen) 11157c478bd9Sstevel@tonic-gate { 11167c478bd9Sstevel@tonic-gate ip6_pkt_t *ipp = &sctp->sctp_sticky_ipp; 11177c478bd9Sstevel@tonic-gate int *i1 = (int *)invalp; 11187c478bd9Sstevel@tonic-gate boolean_t onoff; 11197c478bd9Sstevel@tonic-gate int retval = 0, addrcnt; 11207c478bd9Sstevel@tonic-gate conn_t *connp = sctp->sctp_connp; 11217c478bd9Sstevel@tonic-gate 11227c478bd9Sstevel@tonic-gate /* In all cases, the size of the option must be bigger than int */ 11237c478bd9Sstevel@tonic-gate if (inlen >= sizeof (int32_t)) { 11247c478bd9Sstevel@tonic-gate onoff = ONOFF(*i1); 11257c478bd9Sstevel@tonic-gate } 11267c478bd9Sstevel@tonic-gate retval = 0; 11277c478bd9Sstevel@tonic-gate 11287c478bd9Sstevel@tonic-gate RUN_SCTP(sctp); 11297c478bd9Sstevel@tonic-gate 11307c478bd9Sstevel@tonic-gate switch (level) { 11317c478bd9Sstevel@tonic-gate case SOL_SOCKET: 11327c478bd9Sstevel@tonic-gate if (inlen < sizeof (int32_t)) { 11337c478bd9Sstevel@tonic-gate retval = EINVAL; 11347c478bd9Sstevel@tonic-gate break; 11357c478bd9Sstevel@tonic-gate } 11367c478bd9Sstevel@tonic-gate switch (name) { 11377c478bd9Sstevel@tonic-gate case SO_LINGER: { 11387c478bd9Sstevel@tonic-gate struct linger *lgr; 11397c478bd9Sstevel@tonic-gate 11407c478bd9Sstevel@tonic-gate if (inlen != sizeof (struct linger)) { 11417c478bd9Sstevel@tonic-gate retval = EINVAL; 11427c478bd9Sstevel@tonic-gate break; 11437c478bd9Sstevel@tonic-gate } 11447c478bd9Sstevel@tonic-gate lgr = (struct linger *)invalp; 11457c478bd9Sstevel@tonic-gate if (lgr->l_onoff != 0) { 11467c478bd9Sstevel@tonic-gate sctp->sctp_linger = 1; 11477c478bd9Sstevel@tonic-gate sctp->sctp_lingertime = MSEC_TO_TICK( 11487c478bd9Sstevel@tonic-gate lgr->l_linger); 11497c478bd9Sstevel@tonic-gate } else { 11507c478bd9Sstevel@tonic-gate sctp->sctp_linger = 0; 11517c478bd9Sstevel@tonic-gate sctp->sctp_lingertime = 0; 11527c478bd9Sstevel@tonic-gate } 11537c478bd9Sstevel@tonic-gate break; 11547c478bd9Sstevel@tonic-gate } 11557c478bd9Sstevel@tonic-gate case SO_DEBUG: 11567c478bd9Sstevel@tonic-gate sctp->sctp_debug = onoff; 11577c478bd9Sstevel@tonic-gate break; 11587c478bd9Sstevel@tonic-gate case SO_KEEPALIVE: 11597c478bd9Sstevel@tonic-gate break; 11607c478bd9Sstevel@tonic-gate case SO_DONTROUTE: 11617c478bd9Sstevel@tonic-gate /* 11627c478bd9Sstevel@tonic-gate * SO_DONTROUTE, SO_USELOOPBACK and SO_BROADCAST are 11637c478bd9Sstevel@tonic-gate * only of interest to IP. We track them here only so 11647c478bd9Sstevel@tonic-gate * that we can report their current value. 11657c478bd9Sstevel@tonic-gate */ 11667c478bd9Sstevel@tonic-gate sctp->sctp_dontroute = onoff; 11677c478bd9Sstevel@tonic-gate connp->conn_dontroute = onoff; 11687c478bd9Sstevel@tonic-gate break; 11697c478bd9Sstevel@tonic-gate case SO_USELOOPBACK: 11707c478bd9Sstevel@tonic-gate sctp->sctp_useloopback = onoff; 11717c478bd9Sstevel@tonic-gate connp->conn_loopback = onoff; 11727c478bd9Sstevel@tonic-gate break; 11737c478bd9Sstevel@tonic-gate case SO_BROADCAST: 11747c478bd9Sstevel@tonic-gate sctp->sctp_broadcast = onoff; 11757c478bd9Sstevel@tonic-gate connp->conn_broadcast = onoff; 11767c478bd9Sstevel@tonic-gate break; 11777c478bd9Sstevel@tonic-gate case SO_REUSEADDR: 11787c478bd9Sstevel@tonic-gate sctp->sctp_reuseaddr = onoff; 11797c478bd9Sstevel@tonic-gate connp->conn_reuseaddr = onoff; 11807c478bd9Sstevel@tonic-gate break; 11817c478bd9Sstevel@tonic-gate case SO_DGRAM_ERRIND: 11827c478bd9Sstevel@tonic-gate sctp->sctp_dgram_errind = onoff; 11837c478bd9Sstevel@tonic-gate break; 11847c478bd9Sstevel@tonic-gate case SO_SNDBUF: 11857c478bd9Sstevel@tonic-gate if (*i1 > sctp_max_buf) { 11867c478bd9Sstevel@tonic-gate retval = ENOBUFS; 11877c478bd9Sstevel@tonic-gate break; 11887c478bd9Sstevel@tonic-gate } 11897c478bd9Sstevel@tonic-gate if (*i1 < 0) { 11907c478bd9Sstevel@tonic-gate retval = EINVAL; 11917c478bd9Sstevel@tonic-gate break; 11927c478bd9Sstevel@tonic-gate } 11937c478bd9Sstevel@tonic-gate sctp->sctp_xmit_hiwater = *i1; 11947c478bd9Sstevel@tonic-gate if (sctp_snd_lowat_fraction != 0) 11957c478bd9Sstevel@tonic-gate sctp->sctp_xmit_lowater = 11967c478bd9Sstevel@tonic-gate sctp->sctp_xmit_hiwater / 11977c478bd9Sstevel@tonic-gate sctp_snd_lowat_fraction; 11987c478bd9Sstevel@tonic-gate break; 11997c478bd9Sstevel@tonic-gate case SO_RCVBUF: 12007c478bd9Sstevel@tonic-gate if (*i1 > sctp_max_buf) { 12017c478bd9Sstevel@tonic-gate retval = ENOBUFS; 12027c478bd9Sstevel@tonic-gate break; 12037c478bd9Sstevel@tonic-gate } 12047c478bd9Sstevel@tonic-gate /* Silently ignore zero */ 12057c478bd9Sstevel@tonic-gate if (*i1 != 0) { 12067c478bd9Sstevel@tonic-gate /* 12077c478bd9Sstevel@tonic-gate * Insist on a receive window that is at least 12087c478bd9Sstevel@tonic-gate * sctp_recv_hiwat_minmss * MSS (default 4*MSS) 12097c478bd9Sstevel@tonic-gate * to avoid funny interactions of Nagle 12107c478bd9Sstevel@tonic-gate * algorithm, SWS avoidance and delayed 12117c478bd9Sstevel@tonic-gate * acknowledgement. 12127c478bd9Sstevel@tonic-gate */ 12137c478bd9Sstevel@tonic-gate *i1 = MAX(*i1, 12147c478bd9Sstevel@tonic-gate sctp_recv_hiwat_minmss * sctp->sctp_mss); 12157c478bd9Sstevel@tonic-gate sctp->sctp_rwnd = *i1; 12161d8c4025Svi sctp->sctp_irwnd = sctp->sctp_rwnd; 12177c478bd9Sstevel@tonic-gate } 12187c478bd9Sstevel@tonic-gate /* 12197c478bd9Sstevel@tonic-gate * XXX should we return the rwnd here 12207c478bd9Sstevel@tonic-gate * and sctp_opt_get ? 12217c478bd9Sstevel@tonic-gate */ 12227c478bd9Sstevel@tonic-gate break; 122345916cd2Sjpk case SO_MAC_EXEMPT: 122445916cd2Sjpk if (secpolicy_net_mac_aware(sctp->sctp_credp) != 0 || 122545916cd2Sjpk sctp->sctp_state >= SCTPS_BOUND) { 122645916cd2Sjpk retval = EACCES; 122745916cd2Sjpk } else { 122845916cd2Sjpk sctp->sctp_mac_exempt = onoff; 122945916cd2Sjpk connp->conn_mac_exempt = onoff; 123045916cd2Sjpk } 123145916cd2Sjpk break; 12327c478bd9Sstevel@tonic-gate default: 12337c478bd9Sstevel@tonic-gate retval = EINVAL; 12347c478bd9Sstevel@tonic-gate break; 12357c478bd9Sstevel@tonic-gate } 12367c478bd9Sstevel@tonic-gate break; 12377c478bd9Sstevel@tonic-gate 12387c478bd9Sstevel@tonic-gate case IPPROTO_SCTP: 12397c478bd9Sstevel@tonic-gate if (inlen < sizeof (int32_t)) { 12407c478bd9Sstevel@tonic-gate retval = EINVAL; 12417c478bd9Sstevel@tonic-gate break; 12427c478bd9Sstevel@tonic-gate } 12437c478bd9Sstevel@tonic-gate switch (name) { 12447c478bd9Sstevel@tonic-gate case SCTP_RTOINFO: 12457c478bd9Sstevel@tonic-gate retval = sctp_set_rtoinfo(sctp, invalp, inlen); 12467c478bd9Sstevel@tonic-gate break; 12477c478bd9Sstevel@tonic-gate case SCTP_ASSOCINFO: 12487c478bd9Sstevel@tonic-gate retval = sctp_set_assocparams(sctp, invalp, inlen); 12497c478bd9Sstevel@tonic-gate break; 12507c478bd9Sstevel@tonic-gate case SCTP_INITMSG: 12517c478bd9Sstevel@tonic-gate retval = sctp_set_initmsg(sctp, invalp, inlen); 12527c478bd9Sstevel@tonic-gate break; 12537c478bd9Sstevel@tonic-gate case SCTP_NODELAY: 12547c478bd9Sstevel@tonic-gate sctp->sctp_ndelay = ONOFF(*i1); 12557c478bd9Sstevel@tonic-gate break; 12567c478bd9Sstevel@tonic-gate case SCTP_AUTOCLOSE: 12577c478bd9Sstevel@tonic-gate if (SEC_TO_TICK(*i1) < 0) { 12587c478bd9Sstevel@tonic-gate retval = EINVAL; 12597c478bd9Sstevel@tonic-gate break; 12607c478bd9Sstevel@tonic-gate } 12617c478bd9Sstevel@tonic-gate /* Convert the number of seconds to ticks. */ 12627c478bd9Sstevel@tonic-gate sctp->sctp_autoclose = SEC_TO_TICK(*i1); 12637c478bd9Sstevel@tonic-gate sctp_heartbeat_timer(sctp); 12647c478bd9Sstevel@tonic-gate break; 12657c478bd9Sstevel@tonic-gate case SCTP_SET_PEER_PRIMARY_ADDR: 12667c478bd9Sstevel@tonic-gate retval = sctp_set_peerprim(sctp, invalp, inlen); 12677c478bd9Sstevel@tonic-gate break; 12687c478bd9Sstevel@tonic-gate case SCTP_PRIMARY_ADDR: 12697c478bd9Sstevel@tonic-gate retval = sctp_set_prim(sctp, invalp, inlen); 12707c478bd9Sstevel@tonic-gate break; 12717c478bd9Sstevel@tonic-gate case SCTP_ADAPTION_LAYER: { 12727c478bd9Sstevel@tonic-gate struct sctp_setadaption *ssb; 12737c478bd9Sstevel@tonic-gate 12747c478bd9Sstevel@tonic-gate if (inlen < sizeof (struct sctp_setadaption)) { 12757c478bd9Sstevel@tonic-gate retval = EINVAL; 12767c478bd9Sstevel@tonic-gate break; 12777c478bd9Sstevel@tonic-gate } 12787c478bd9Sstevel@tonic-gate ssb = (struct sctp_setadaption *)invalp; 12797c478bd9Sstevel@tonic-gate sctp->sctp_send_adaption = 1; 12807c478bd9Sstevel@tonic-gate sctp->sctp_tx_adaption_code = ssb->ssb_adaption_ind; 12817c478bd9Sstevel@tonic-gate break; 12827c478bd9Sstevel@tonic-gate } 12837c478bd9Sstevel@tonic-gate case SCTP_PEER_ADDR_PARAMS: 12847c478bd9Sstevel@tonic-gate retval = sctp_set_peer_addr_params(sctp, invalp, 12857c478bd9Sstevel@tonic-gate inlen); 12867c478bd9Sstevel@tonic-gate break; 12877c478bd9Sstevel@tonic-gate case SCTP_DEFAULT_SEND_PARAM: 12887c478bd9Sstevel@tonic-gate retval = sctp_set_def_send_params(sctp, invalp, inlen); 12897c478bd9Sstevel@tonic-gate break; 12907c478bd9Sstevel@tonic-gate case SCTP_EVENTS: { 12917c478bd9Sstevel@tonic-gate struct sctp_event_subscribe *ev; 12927c478bd9Sstevel@tonic-gate 12937c478bd9Sstevel@tonic-gate if (inlen < sizeof (struct sctp_event_subscribe)) { 12947c478bd9Sstevel@tonic-gate retval = EINVAL; 12957c478bd9Sstevel@tonic-gate break; 12967c478bd9Sstevel@tonic-gate } 12977c478bd9Sstevel@tonic-gate ev = (struct sctp_event_subscribe *)invalp; 12987c478bd9Sstevel@tonic-gate sctp->sctp_recvsndrcvinfo = 12997c478bd9Sstevel@tonic-gate ONOFF(ev->sctp_data_io_event); 13007c478bd9Sstevel@tonic-gate sctp->sctp_recvassocevnt = 13017c478bd9Sstevel@tonic-gate ONOFF(ev->sctp_association_event); 13027c478bd9Sstevel@tonic-gate sctp->sctp_recvpathevnt = 13037c478bd9Sstevel@tonic-gate ONOFF(ev->sctp_address_event); 13047c478bd9Sstevel@tonic-gate sctp->sctp_recvsendfailevnt = 13057c478bd9Sstevel@tonic-gate ONOFF(ev->sctp_send_failure_event); 13067c478bd9Sstevel@tonic-gate sctp->sctp_recvpeererr = 13077c478bd9Sstevel@tonic-gate ONOFF(ev->sctp_peer_error_event); 13087c478bd9Sstevel@tonic-gate sctp->sctp_recvshutdownevnt = 13097c478bd9Sstevel@tonic-gate ONOFF(ev->sctp_shutdown_event); 13107c478bd9Sstevel@tonic-gate sctp->sctp_recvpdevnt = 13117c478bd9Sstevel@tonic-gate ONOFF(ev->sctp_partial_delivery_event); 13127c478bd9Sstevel@tonic-gate sctp->sctp_recvalevnt = 13137c478bd9Sstevel@tonic-gate ONOFF(ev->sctp_adaption_layer_event); 13147c478bd9Sstevel@tonic-gate break; 13157c478bd9Sstevel@tonic-gate } 13167c478bd9Sstevel@tonic-gate case SCTP_ADD_ADDR: 13177c478bd9Sstevel@tonic-gate case SCTP_REM_ADDR: 13187c478bd9Sstevel@tonic-gate /* 13197c478bd9Sstevel@tonic-gate * The sctp_t has to be bound first before 13207c478bd9Sstevel@tonic-gate * the address list can be changed. 13217c478bd9Sstevel@tonic-gate */ 13227c478bd9Sstevel@tonic-gate if (sctp->sctp_state < SCTPS_BOUND) { 13237c478bd9Sstevel@tonic-gate retval = EINVAL; 13247c478bd9Sstevel@tonic-gate break; 13257c478bd9Sstevel@tonic-gate } 13267c478bd9Sstevel@tonic-gate if (sctp->sctp_family == AF_INET) { 13277c478bd9Sstevel@tonic-gate addrcnt = inlen / sizeof (struct sockaddr_in); 13287c478bd9Sstevel@tonic-gate } else { 13297c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_family == AF_INET6); 13307c478bd9Sstevel@tonic-gate addrcnt = inlen / sizeof (struct sockaddr_in6); 13317c478bd9Sstevel@tonic-gate } 13327c478bd9Sstevel@tonic-gate if (name == SCTP_ADD_ADDR) { 13337c478bd9Sstevel@tonic-gate retval = sctp_bind_add(sctp, invalp, addrcnt, 13341d8c4025Svi B_TRUE, sctp->sctp_lport); 13357c478bd9Sstevel@tonic-gate } else { 13367c478bd9Sstevel@tonic-gate retval = sctp_bind_del(sctp, invalp, addrcnt, 13377c478bd9Sstevel@tonic-gate B_TRUE); 13387c478bd9Sstevel@tonic-gate } 13397c478bd9Sstevel@tonic-gate break; 13407c478bd9Sstevel@tonic-gate case SCTP_UC_SWAP: { 13417c478bd9Sstevel@tonic-gate struct sctp_uc_swap *us; 13427c478bd9Sstevel@tonic-gate 13437c478bd9Sstevel@tonic-gate /* 13447c478bd9Sstevel@tonic-gate * Change handle & upcalls. 13457c478bd9Sstevel@tonic-gate */ 13467c478bd9Sstevel@tonic-gate if (inlen < sizeof (*us)) { 13477c478bd9Sstevel@tonic-gate retval = EINVAL; 13487c478bd9Sstevel@tonic-gate break; 13497c478bd9Sstevel@tonic-gate } 13507c478bd9Sstevel@tonic-gate us = (struct sctp_uc_swap *)invalp; 13517c478bd9Sstevel@tonic-gate sctp->sctp_ulpd = us->sus_handle; 13527c478bd9Sstevel@tonic-gate bcopy(us->sus_upcalls, &sctp->sctp_upcalls, 13537c478bd9Sstevel@tonic-gate sizeof (sctp_upcalls_t)); 13547c478bd9Sstevel@tonic-gate break; 13557c478bd9Sstevel@tonic-gate } 13567c478bd9Sstevel@tonic-gate case SCTP_PRSCTP: 13577c478bd9Sstevel@tonic-gate sctp->sctp_prsctp_aware = onoff; 13587c478bd9Sstevel@tonic-gate break; 13597c478bd9Sstevel@tonic-gate case SCTP_I_WANT_MAPPED_V4_ADDR: 13607c478bd9Sstevel@tonic-gate case SCTP_MAXSEG: 13617c478bd9Sstevel@tonic-gate case SCTP_DISABLE_FRAGMENTS: 13627c478bd9Sstevel@tonic-gate /* Not yet supported. */ 13637c478bd9Sstevel@tonic-gate default: 13647c478bd9Sstevel@tonic-gate retval = EINVAL; 13657c478bd9Sstevel@tonic-gate break; 13667c478bd9Sstevel@tonic-gate } 13677c478bd9Sstevel@tonic-gate break; 13687c478bd9Sstevel@tonic-gate 13697c478bd9Sstevel@tonic-gate case IPPROTO_IP: 13707c478bd9Sstevel@tonic-gate if (sctp->sctp_family != AF_INET) { 13717c478bd9Sstevel@tonic-gate retval = ENOPROTOOPT; 13727c478bd9Sstevel@tonic-gate break; 13737c478bd9Sstevel@tonic-gate } 13747c478bd9Sstevel@tonic-gate if ((name != IP_OPTIONS) && (inlen < sizeof (int32_t))) { 13757c478bd9Sstevel@tonic-gate retval = EINVAL; 13767c478bd9Sstevel@tonic-gate break; 13777c478bd9Sstevel@tonic-gate } 13787c478bd9Sstevel@tonic-gate switch (name) { 13797c478bd9Sstevel@tonic-gate case IP_OPTIONS: 13807c478bd9Sstevel@tonic-gate case T_IP_OPTIONS: 138145916cd2Sjpk retval = sctp_opt_set_header(sctp, invalp, inlen); 13827c478bd9Sstevel@tonic-gate break; 13837c478bd9Sstevel@tonic-gate case IP_TOS: 13847c478bd9Sstevel@tonic-gate case T_IP_TOS: 13857c478bd9Sstevel@tonic-gate sctp->sctp_ipha->ipha_type_of_service = (uchar_t)*i1; 13867c478bd9Sstevel@tonic-gate break; 13877c478bd9Sstevel@tonic-gate case IP_TTL: 13887c478bd9Sstevel@tonic-gate sctp->sctp_ipha->ipha_ttl = (uchar_t)*i1; 13897c478bd9Sstevel@tonic-gate break; 13907c478bd9Sstevel@tonic-gate case IP_SEC_OPT: 13917c478bd9Sstevel@tonic-gate /* 13927c478bd9Sstevel@tonic-gate * We should not allow policy setting after 13937c478bd9Sstevel@tonic-gate * we start listening for connections. 13947c478bd9Sstevel@tonic-gate */ 13957c478bd9Sstevel@tonic-gate if (sctp->sctp_state >= SCTPS_LISTEN) { 13967c478bd9Sstevel@tonic-gate retval = EINVAL; 13977c478bd9Sstevel@tonic-gate } else { 13987c478bd9Sstevel@tonic-gate retval = ipsec_set_req(sctp->sctp_credp, 13997c478bd9Sstevel@tonic-gate sctp->sctp_connp, (ipsec_req_t *)invalp); 14007c478bd9Sstevel@tonic-gate } 14017c478bd9Sstevel@tonic-gate break; 14027c478bd9Sstevel@tonic-gate /* IP level options */ 14037c478bd9Sstevel@tonic-gate case IP_RECVIF: 14047c478bd9Sstevel@tonic-gate connp->conn_recvif = onoff; 14057c478bd9Sstevel@tonic-gate break; 14067c478bd9Sstevel@tonic-gate case IP_RECVSLLA: 14077c478bd9Sstevel@tonic-gate connp->conn_recvslla = onoff; 14087c478bd9Sstevel@tonic-gate break; 14097c478bd9Sstevel@tonic-gate case IP_UNSPEC_SRC: 14107c478bd9Sstevel@tonic-gate connp->conn_unspec_src = onoff; 14117c478bd9Sstevel@tonic-gate break; 141243d18f1cSpriyanka case IP_NEXTHOP: { 141343d18f1cSpriyanka ipaddr_t addr = *i1; 141443d18f1cSpriyanka ipif_t *ipif = NULL; 141543d18f1cSpriyanka ill_t *ill; 141643d18f1cSpriyanka 141743d18f1cSpriyanka if (secpolicy_net(CRED(), OP_CONFIG, B_TRUE) == 0) { 141843d18f1cSpriyanka ipif = 141943d18f1cSpriyanka ipif_lookup_onlink_addr(addr, 142043d18f1cSpriyanka connp->conn_zoneid); 142143d18f1cSpriyanka if (ipif == NULL) { 142243d18f1cSpriyanka retval = EHOSTUNREACH; 142343d18f1cSpriyanka break; 142443d18f1cSpriyanka } 142543d18f1cSpriyanka ill = ipif->ipif_ill; 142643d18f1cSpriyanka mutex_enter(&ill->ill_lock); 142743d18f1cSpriyanka if ((ill->ill_state_flags & ILL_CONDEMNED) || 142843d18f1cSpriyanka (ipif->ipif_state_flags & IPIF_CONDEMNED)) { 142943d18f1cSpriyanka mutex_exit(&ill->ill_lock); 143043d18f1cSpriyanka ipif_refrele(ipif); 143143d18f1cSpriyanka retval = EHOSTUNREACH; 143243d18f1cSpriyanka break; 143343d18f1cSpriyanka } 143443d18f1cSpriyanka mutex_exit(&ill->ill_lock); 143543d18f1cSpriyanka ipif_refrele(ipif); 143643d18f1cSpriyanka mutex_enter(&connp->conn_lock); 143743d18f1cSpriyanka connp->conn_nexthop_v4 = addr; 143843d18f1cSpriyanka connp->conn_nexthop_set = B_TRUE; 143943d18f1cSpriyanka mutex_exit(&connp->conn_lock); 144043d18f1cSpriyanka } 144143d18f1cSpriyanka break; 144243d18f1cSpriyanka } 14437c478bd9Sstevel@tonic-gate default: 14447c478bd9Sstevel@tonic-gate retval = EINVAL; 14457c478bd9Sstevel@tonic-gate break; 14467c478bd9Sstevel@tonic-gate } 14477c478bd9Sstevel@tonic-gate break; 14487c478bd9Sstevel@tonic-gate case IPPROTO_IPV6: { 14497c478bd9Sstevel@tonic-gate if (sctp->sctp_family != AF_INET6) { 14507c478bd9Sstevel@tonic-gate retval = ENOPROTOOPT; 14517c478bd9Sstevel@tonic-gate break; 14527c478bd9Sstevel@tonic-gate } 14537c478bd9Sstevel@tonic-gate 14547c478bd9Sstevel@tonic-gate switch (name) { 14557c478bd9Sstevel@tonic-gate case IPV6_UNICAST_HOPS: 14567c478bd9Sstevel@tonic-gate if (inlen < sizeof (int32_t)) { 14577c478bd9Sstevel@tonic-gate retval = EINVAL; 14587c478bd9Sstevel@tonic-gate break; 14597c478bd9Sstevel@tonic-gate } 14607c478bd9Sstevel@tonic-gate if (*i1 < -1 || *i1 > IPV6_MAX_HOPS) { 14617c478bd9Sstevel@tonic-gate retval = EINVAL; 14627c478bd9Sstevel@tonic-gate break; 14637c478bd9Sstevel@tonic-gate } 1464b3d0fa4fSseb if (*i1 == -1) { 1465b3d0fa4fSseb ipp->ipp_unicast_hops = sctp_ipv6_hoplimit; 1466b3d0fa4fSseb ipp->ipp_fields &= ~IPPF_UNICAST_HOPS; 1467b3d0fa4fSseb } else { 1468b3d0fa4fSseb ipp->ipp_unicast_hops = (uint8_t)*i1; 1469b3d0fa4fSseb ipp->ipp_fields |= IPPF_UNICAST_HOPS; 1470b3d0fa4fSseb } 1471b3d0fa4fSseb retval = sctp_build_hdrs(sctp); 14727c478bd9Sstevel@tonic-gate break; 14737c478bd9Sstevel@tonic-gate case IPV6_UNSPEC_SRC: 14747c478bd9Sstevel@tonic-gate if (inlen < sizeof (int32_t)) { 14757c478bd9Sstevel@tonic-gate retval = EINVAL; 14767c478bd9Sstevel@tonic-gate break; 14777c478bd9Sstevel@tonic-gate } 14787c478bd9Sstevel@tonic-gate connp->conn_unspec_src = onoff; 14797c478bd9Sstevel@tonic-gate break; 14807c478bd9Sstevel@tonic-gate case IPV6_RECVPKTINFO: 14817c478bd9Sstevel@tonic-gate if (inlen < sizeof (int32_t)) { 14827c478bd9Sstevel@tonic-gate retval = EINVAL; 14837c478bd9Sstevel@tonic-gate break; 14847c478bd9Sstevel@tonic-gate } 14857c478bd9Sstevel@tonic-gate if (onoff) 14867c478bd9Sstevel@tonic-gate sctp->sctp_ipv6_recvancillary |= 14877c478bd9Sstevel@tonic-gate SCTP_IPV6_RECVPKTINFO; 14887c478bd9Sstevel@tonic-gate else 14897c478bd9Sstevel@tonic-gate sctp->sctp_ipv6_recvancillary &= 14907c478bd9Sstevel@tonic-gate ~SCTP_IPV6_RECVPKTINFO; 14917c478bd9Sstevel@tonic-gate /* Send it with the next msg */ 14927c478bd9Sstevel@tonic-gate sctp->sctp_recvifindex = 0; 14937c478bd9Sstevel@tonic-gate connp->conn_ipv6_recvpktinfo = onoff; 14947c478bd9Sstevel@tonic-gate break; 14957c478bd9Sstevel@tonic-gate case IPV6_RECVHOPLIMIT: 14967c478bd9Sstevel@tonic-gate if (inlen < sizeof (int32_t)) { 14977c478bd9Sstevel@tonic-gate retval = EINVAL; 14987c478bd9Sstevel@tonic-gate break; 14997c478bd9Sstevel@tonic-gate } 15007c478bd9Sstevel@tonic-gate if (onoff) 15017c478bd9Sstevel@tonic-gate sctp->sctp_ipv6_recvancillary |= 15027c478bd9Sstevel@tonic-gate SCTP_IPV6_RECVHOPLIMIT; 15037c478bd9Sstevel@tonic-gate else 15047c478bd9Sstevel@tonic-gate sctp->sctp_ipv6_recvancillary &= 15057c478bd9Sstevel@tonic-gate ~SCTP_IPV6_RECVHOPLIMIT; 15067c478bd9Sstevel@tonic-gate sctp->sctp_recvhops = 0xffffffffU; 15077c478bd9Sstevel@tonic-gate connp->conn_ipv6_recvhoplimit = onoff; 15087c478bd9Sstevel@tonic-gate break; 15097c478bd9Sstevel@tonic-gate case IPV6_RECVHOPOPTS: 15107c478bd9Sstevel@tonic-gate if (inlen < sizeof (int32_t)) { 15117c478bd9Sstevel@tonic-gate retval = EINVAL; 15127c478bd9Sstevel@tonic-gate break; 15137c478bd9Sstevel@tonic-gate } 15147c478bd9Sstevel@tonic-gate if (onoff) 15157c478bd9Sstevel@tonic-gate sctp->sctp_ipv6_recvancillary |= 15167c478bd9Sstevel@tonic-gate SCTP_IPV6_RECVHOPOPTS; 15177c478bd9Sstevel@tonic-gate else 15187c478bd9Sstevel@tonic-gate sctp->sctp_ipv6_recvancillary &= 15197c478bd9Sstevel@tonic-gate ~SCTP_IPV6_RECVHOPOPTS; 15207c478bd9Sstevel@tonic-gate connp->conn_ipv6_recvhopopts = onoff; 15217c478bd9Sstevel@tonic-gate break; 15227c478bd9Sstevel@tonic-gate case IPV6_RECVDSTOPTS: 15237c478bd9Sstevel@tonic-gate if (inlen < sizeof (int32_t)) { 15247c478bd9Sstevel@tonic-gate retval = EINVAL; 15257c478bd9Sstevel@tonic-gate break; 15267c478bd9Sstevel@tonic-gate } 15277c478bd9Sstevel@tonic-gate if (onoff) 15287c478bd9Sstevel@tonic-gate sctp->sctp_ipv6_recvancillary |= 15297c478bd9Sstevel@tonic-gate SCTP_IPV6_RECVDSTOPTS; 15307c478bd9Sstevel@tonic-gate else 15317c478bd9Sstevel@tonic-gate sctp->sctp_ipv6_recvancillary &= 15327c478bd9Sstevel@tonic-gate ~SCTP_IPV6_RECVDSTOPTS; 15337c478bd9Sstevel@tonic-gate connp->conn_ipv6_recvdstopts = onoff; 15347c478bd9Sstevel@tonic-gate break; 15357c478bd9Sstevel@tonic-gate case IPV6_RECVRTHDR: 15367c478bd9Sstevel@tonic-gate if (inlen < sizeof (int32_t)) { 15377c478bd9Sstevel@tonic-gate retval = EINVAL; 15387c478bd9Sstevel@tonic-gate break; 15397c478bd9Sstevel@tonic-gate } 15407c478bd9Sstevel@tonic-gate if (onoff) 15417c478bd9Sstevel@tonic-gate sctp->sctp_ipv6_recvancillary |= 15427c478bd9Sstevel@tonic-gate SCTP_IPV6_RECVRTHDR; 15437c478bd9Sstevel@tonic-gate else 15447c478bd9Sstevel@tonic-gate sctp->sctp_ipv6_recvancillary &= 15457c478bd9Sstevel@tonic-gate ~SCTP_IPV6_RECVRTHDR; 15467c478bd9Sstevel@tonic-gate connp->conn_ipv6_recvrthdr = onoff; 15477c478bd9Sstevel@tonic-gate break; 15487c478bd9Sstevel@tonic-gate case IPV6_RECVRTHDRDSTOPTS: 15497c478bd9Sstevel@tonic-gate if (inlen < sizeof (int32_t)) { 15507c478bd9Sstevel@tonic-gate retval = EINVAL; 15517c478bd9Sstevel@tonic-gate break; 15527c478bd9Sstevel@tonic-gate } 15537c478bd9Sstevel@tonic-gate if (onoff) 15547c478bd9Sstevel@tonic-gate sctp->sctp_ipv6_recvancillary |= 15557c478bd9Sstevel@tonic-gate SCTP_IPV6_RECVRTDSTOPTS; 15567c478bd9Sstevel@tonic-gate else 15577c478bd9Sstevel@tonic-gate sctp->sctp_ipv6_recvancillary &= 15587c478bd9Sstevel@tonic-gate ~SCTP_IPV6_RECVRTDSTOPTS; 15597c478bd9Sstevel@tonic-gate connp->conn_ipv6_recvrtdstopts = onoff; 15607c478bd9Sstevel@tonic-gate break; 15617c478bd9Sstevel@tonic-gate case IPV6_PKTINFO: 15627c478bd9Sstevel@tonic-gate if (inlen != 0 && 15637c478bd9Sstevel@tonic-gate inlen != sizeof (struct in6_pktinfo)) { 15647c478bd9Sstevel@tonic-gate retval = EINVAL; 15657c478bd9Sstevel@tonic-gate break; 15667c478bd9Sstevel@tonic-gate } 15677c478bd9Sstevel@tonic-gate 15687c478bd9Sstevel@tonic-gate if (inlen == 0) { 15697c478bd9Sstevel@tonic-gate ipp->ipp_fields &= ~(IPPF_IFINDEX |IPPF_ADDR); 15707c478bd9Sstevel@tonic-gate } else { 15717c478bd9Sstevel@tonic-gate struct in6_pktinfo *pkti; 15727c478bd9Sstevel@tonic-gate 15737c478bd9Sstevel@tonic-gate pkti = (struct in6_pktinfo *)invalp; 15747c478bd9Sstevel@tonic-gate /* XXX Need to check if the index exists */ 15757c478bd9Sstevel@tonic-gate ipp->ipp_ifindex = pkti->ipi6_ifindex; 15767c478bd9Sstevel@tonic-gate ipp->ipp_addr = pkti->ipi6_addr; 15777c478bd9Sstevel@tonic-gate if (ipp->ipp_ifindex != 0) 15787c478bd9Sstevel@tonic-gate ipp->ipp_fields |= IPPF_IFINDEX; 15797c478bd9Sstevel@tonic-gate else 15807c478bd9Sstevel@tonic-gate ipp->ipp_fields &= ~IPPF_IFINDEX; 15817c478bd9Sstevel@tonic-gate if (!IN6_IS_ADDR_UNSPECIFIED(&ipp->ipp_addr)) 15827c478bd9Sstevel@tonic-gate ipp->ipp_fields |= IPPF_ADDR; 15837c478bd9Sstevel@tonic-gate else 15847c478bd9Sstevel@tonic-gate ipp->ipp_fields &= ~IPPF_ADDR; 15857c478bd9Sstevel@tonic-gate } 15867c478bd9Sstevel@tonic-gate retval = sctp_build_hdrs(sctp); 15877c478bd9Sstevel@tonic-gate break; 15887c478bd9Sstevel@tonic-gate case IPV6_NEXTHOP: { 15897c478bd9Sstevel@tonic-gate struct sockaddr_in6 *sin6; 15907c478bd9Sstevel@tonic-gate 15917c478bd9Sstevel@tonic-gate if (inlen != 0 && inlen != sizeof (sin6_t)) { 15927c478bd9Sstevel@tonic-gate retval = EINVAL; 15937c478bd9Sstevel@tonic-gate break; 15947c478bd9Sstevel@tonic-gate } 15957c478bd9Sstevel@tonic-gate 15967c478bd9Sstevel@tonic-gate if (inlen == 0) { 15977c478bd9Sstevel@tonic-gate ipp->ipp_fields &= ~IPPF_NEXTHOP; 15987c478bd9Sstevel@tonic-gate } else { 15997c478bd9Sstevel@tonic-gate sin6 = (struct sockaddr_in6 *)invalp; 16007c478bd9Sstevel@tonic-gate if (sin6->sin6_family != AF_INET6) { 16017c478bd9Sstevel@tonic-gate retval = EAFNOSUPPORT; 16027c478bd9Sstevel@tonic-gate break; 16037c478bd9Sstevel@tonic-gate } 16047c478bd9Sstevel@tonic-gate if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) { 16057c478bd9Sstevel@tonic-gate retval = EADDRNOTAVAIL; 16067c478bd9Sstevel@tonic-gate break; 16077c478bd9Sstevel@tonic-gate } 16087c478bd9Sstevel@tonic-gate ipp->ipp_nexthop = sin6->sin6_addr; 16097c478bd9Sstevel@tonic-gate if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { 16107c478bd9Sstevel@tonic-gate ipp->ipp_fields &= ~IPPF_NEXTHOP; 16117c478bd9Sstevel@tonic-gate } else { 16127c478bd9Sstevel@tonic-gate ire_t *ire; 16137c478bd9Sstevel@tonic-gate 16147c478bd9Sstevel@tonic-gate ire = ire_route_lookup_v6( 161545916cd2Sjpk &sin6->sin6_addr, NULL, NULL, 0, 161645916cd2Sjpk NULL, NULL, ALL_ZONES, NULL, 161745916cd2Sjpk MATCH_IRE_DEFAULT); 16187c478bd9Sstevel@tonic-gate if (ire == NULL) { 16197c478bd9Sstevel@tonic-gate retval = EHOSTUNREACH; 16207c478bd9Sstevel@tonic-gate break; 16217c478bd9Sstevel@tonic-gate } 16227c478bd9Sstevel@tonic-gate ire_refrele(ire); 16237c478bd9Sstevel@tonic-gate ipp->ipp_fields |= IPPF_NEXTHOP; 16247c478bd9Sstevel@tonic-gate } 16257c478bd9Sstevel@tonic-gate } 16267c478bd9Sstevel@tonic-gate retval = sctp_build_hdrs(sctp); 16277c478bd9Sstevel@tonic-gate break; 16287c478bd9Sstevel@tonic-gate } 16297c478bd9Sstevel@tonic-gate case IPV6_HOPOPTS: { 16307c478bd9Sstevel@tonic-gate ip6_hbh_t *hopts = (ip6_hbh_t *)invalp; 16317c478bd9Sstevel@tonic-gate 16327c478bd9Sstevel@tonic-gate if (inlen != 0 && 16337c478bd9Sstevel@tonic-gate inlen != (8 * (hopts->ip6h_len + 1))) { 16347c478bd9Sstevel@tonic-gate retval = EINVAL; 16357c478bd9Sstevel@tonic-gate break; 16367c478bd9Sstevel@tonic-gate } 16377c478bd9Sstevel@tonic-gate 163845916cd2Sjpk retval = optcom_pkt_set((uchar_t *)invalp, inlen, 163945916cd2Sjpk B_TRUE, (uchar_t **)&ipp->ipp_hopopts, 164045916cd2Sjpk &ipp->ipp_hopoptslen, sctp->sctp_v6label_len); 164145916cd2Sjpk if (retval != 0) 164245916cd2Sjpk break; 164345916cd2Sjpk if (ipp->ipp_hopoptslen == 0) 16447c478bd9Sstevel@tonic-gate ipp->ipp_fields &= ~IPPF_HOPOPTS; 164545916cd2Sjpk else 16467c478bd9Sstevel@tonic-gate ipp->ipp_fields |= IPPF_HOPOPTS; 16477c478bd9Sstevel@tonic-gate retval = sctp_build_hdrs(sctp); 16487c478bd9Sstevel@tonic-gate break; 16497c478bd9Sstevel@tonic-gate } 16507c478bd9Sstevel@tonic-gate case IPV6_RTHDRDSTOPTS: { 16517c478bd9Sstevel@tonic-gate ip6_dest_t *dopts = (ip6_dest_t *)invalp; 16527c478bd9Sstevel@tonic-gate 16537c478bd9Sstevel@tonic-gate if (inlen != 0 && 16547c478bd9Sstevel@tonic-gate inlen != (8 * (dopts->ip6d_len + 1))) { 16557c478bd9Sstevel@tonic-gate retval = EINVAL; 16567c478bd9Sstevel@tonic-gate break; 16577c478bd9Sstevel@tonic-gate } 16587c478bd9Sstevel@tonic-gate 165945916cd2Sjpk retval = optcom_pkt_set((uchar_t *)invalp, inlen, 166045916cd2Sjpk B_TRUE, (uchar_t **)&ipp->ipp_rtdstopts, 166145916cd2Sjpk &ipp->ipp_rtdstoptslen, 0); 166245916cd2Sjpk if (retval != 0) 166345916cd2Sjpk break; 166445916cd2Sjpk if (ipp->ipp_rtdstoptslen == 0) 16657c478bd9Sstevel@tonic-gate ipp->ipp_fields &= ~IPPF_RTDSTOPTS; 166645916cd2Sjpk else 16677c478bd9Sstevel@tonic-gate ipp->ipp_fields |= IPPF_RTDSTOPTS; 16687c478bd9Sstevel@tonic-gate retval = sctp_build_hdrs(sctp); 16697c478bd9Sstevel@tonic-gate break; 16707c478bd9Sstevel@tonic-gate } 16717c478bd9Sstevel@tonic-gate case IPV6_DSTOPTS: { 16727c478bd9Sstevel@tonic-gate ip6_dest_t *dopts = (ip6_dest_t *)invalp; 16737c478bd9Sstevel@tonic-gate 16747c478bd9Sstevel@tonic-gate if (inlen != 0 && 16757c478bd9Sstevel@tonic-gate inlen != (8 * (dopts->ip6d_len + 1))) { 16767c478bd9Sstevel@tonic-gate retval = EINVAL; 16777c478bd9Sstevel@tonic-gate break; 16787c478bd9Sstevel@tonic-gate } 16797c478bd9Sstevel@tonic-gate 168045916cd2Sjpk retval = optcom_pkt_set((uchar_t *)invalp, inlen, 168145916cd2Sjpk B_TRUE, (uchar_t **)&ipp->ipp_dstopts, 168245916cd2Sjpk &ipp->ipp_dstoptslen, 0); 168345916cd2Sjpk if (retval != 0) 168445916cd2Sjpk break; 168545916cd2Sjpk if (ipp->ipp_dstoptslen == 0) 16867c478bd9Sstevel@tonic-gate ipp->ipp_fields &= ~IPPF_DSTOPTS; 168745916cd2Sjpk else 16887c478bd9Sstevel@tonic-gate ipp->ipp_fields |= IPPF_DSTOPTS; 16897c478bd9Sstevel@tonic-gate retval = sctp_build_hdrs(sctp); 16907c478bd9Sstevel@tonic-gate break; 16917c478bd9Sstevel@tonic-gate } 16927c478bd9Sstevel@tonic-gate case IPV6_RTHDR: { 16937c478bd9Sstevel@tonic-gate ip6_rthdr_t *rt = (ip6_rthdr_t *)invalp; 16947c478bd9Sstevel@tonic-gate 16957c478bd9Sstevel@tonic-gate if (inlen != 0 && 16967c478bd9Sstevel@tonic-gate inlen != (8 * (rt->ip6r_len + 1))) { 16977c478bd9Sstevel@tonic-gate retval = EINVAL; 16987c478bd9Sstevel@tonic-gate break; 16997c478bd9Sstevel@tonic-gate } 17007c478bd9Sstevel@tonic-gate 170145916cd2Sjpk retval = optcom_pkt_set((uchar_t *)invalp, inlen, 170245916cd2Sjpk B_TRUE, (uchar_t **)&ipp->ipp_rthdr, 170345916cd2Sjpk &ipp->ipp_rthdrlen, 0); 170445916cd2Sjpk if (retval != 0) 170545916cd2Sjpk break; 170645916cd2Sjpk if (ipp->ipp_rthdrlen == 0) 17077c478bd9Sstevel@tonic-gate ipp->ipp_fields &= ~IPPF_RTHDR; 170845916cd2Sjpk else 17097c478bd9Sstevel@tonic-gate ipp->ipp_fields |= IPPF_RTHDR; 17107c478bd9Sstevel@tonic-gate retval = sctp_build_hdrs(sctp); 17117c478bd9Sstevel@tonic-gate break; 17127c478bd9Sstevel@tonic-gate } 17137c478bd9Sstevel@tonic-gate case IPV6_SEC_OPT: 17147c478bd9Sstevel@tonic-gate /* 17157c478bd9Sstevel@tonic-gate * We should not allow policy setting after 17167c478bd9Sstevel@tonic-gate * we start listening for connections. 17177c478bd9Sstevel@tonic-gate */ 17187c478bd9Sstevel@tonic-gate if (sctp->sctp_state >= SCTPS_LISTEN) { 17197c478bd9Sstevel@tonic-gate retval = EINVAL; 17207c478bd9Sstevel@tonic-gate } else { 17217c478bd9Sstevel@tonic-gate retval = ipsec_set_req(sctp->sctp_credp, 17227c478bd9Sstevel@tonic-gate sctp->sctp_connp, (ipsec_req_t *)invalp); 17237c478bd9Sstevel@tonic-gate } 17247c478bd9Sstevel@tonic-gate break; 17257c478bd9Sstevel@tonic-gate case IPV6_V6ONLY: 17267c478bd9Sstevel@tonic-gate /* 17277c478bd9Sstevel@tonic-gate * After the bound state, setting the v6only option 17287c478bd9Sstevel@tonic-gate * is too late. 17297c478bd9Sstevel@tonic-gate */ 17307c478bd9Sstevel@tonic-gate if (sctp->sctp_state >= SCTPS_BOUND) { 17317c478bd9Sstevel@tonic-gate retval = EINVAL; 17327c478bd9Sstevel@tonic-gate } else { 17337c478bd9Sstevel@tonic-gate sctp->sctp_connp->conn_ipv6_v6only = onoff; 17347c478bd9Sstevel@tonic-gate } 17357c478bd9Sstevel@tonic-gate break; 17367c478bd9Sstevel@tonic-gate default: 17377c478bd9Sstevel@tonic-gate retval = EINVAL; 17387c478bd9Sstevel@tonic-gate break; 17397c478bd9Sstevel@tonic-gate } 17407c478bd9Sstevel@tonic-gate break; 17417c478bd9Sstevel@tonic-gate } 17427c478bd9Sstevel@tonic-gate default: 17437c478bd9Sstevel@tonic-gate retval = EINVAL; 17447c478bd9Sstevel@tonic-gate break; 17457c478bd9Sstevel@tonic-gate } 17467c478bd9Sstevel@tonic-gate 17477c478bd9Sstevel@tonic-gate WAKE_SCTP(sctp); 17487c478bd9Sstevel@tonic-gate return (retval); 17497c478bd9Sstevel@tonic-gate } 17507c478bd9Sstevel@tonic-gate 17517c478bd9Sstevel@tonic-gate /* 17527c478bd9Sstevel@tonic-gate * SCTP exported kernel interface for geting the first source address of 17537c478bd9Sstevel@tonic-gate * a sctp_t. The parameter addr is assumed to have enough space to hold 17547c478bd9Sstevel@tonic-gate * one socket address. 17557c478bd9Sstevel@tonic-gate */ 17567c478bd9Sstevel@tonic-gate int 17577c478bd9Sstevel@tonic-gate sctp_getsockname(sctp_t *sctp, struct sockaddr *addr, socklen_t *addrlen) 17587c478bd9Sstevel@tonic-gate { 17597c478bd9Sstevel@tonic-gate int err = 0; 17607c478bd9Sstevel@tonic-gate int addrcnt = 1; 17617c478bd9Sstevel@tonic-gate sin_t *sin4; 17627c478bd9Sstevel@tonic-gate sin6_t *sin6; 17637c478bd9Sstevel@tonic-gate 17647c478bd9Sstevel@tonic-gate ASSERT(sctp != NULL); 17657c478bd9Sstevel@tonic-gate 17667c478bd9Sstevel@tonic-gate RUN_SCTP(sctp); 17677c478bd9Sstevel@tonic-gate addr->sa_family = sctp->sctp_family; 17687c478bd9Sstevel@tonic-gate switch (sctp->sctp_family) { 17697c478bd9Sstevel@tonic-gate case AF_INET: 17707c478bd9Sstevel@tonic-gate sin4 = (sin_t *)addr; 17717c478bd9Sstevel@tonic-gate if ((sctp->sctp_state <= SCTPS_LISTEN) && 17727c478bd9Sstevel@tonic-gate sctp->sctp_bound_to_all) { 17737c478bd9Sstevel@tonic-gate sin4->sin_addr.s_addr = INADDR_ANY; 17747c478bd9Sstevel@tonic-gate sin4->sin_port = sctp->sctp_lport; 17757c478bd9Sstevel@tonic-gate } else { 17767c478bd9Sstevel@tonic-gate err = sctp_getmyaddrs(sctp, sin4, &addrcnt); 17777c478bd9Sstevel@tonic-gate if (err != 0) { 17787c478bd9Sstevel@tonic-gate *addrlen = 0; 17797c478bd9Sstevel@tonic-gate break; 17807c478bd9Sstevel@tonic-gate } 17817c478bd9Sstevel@tonic-gate } 17827c478bd9Sstevel@tonic-gate *addrlen = sizeof (struct sockaddr_in); 17837c478bd9Sstevel@tonic-gate break; 17847c478bd9Sstevel@tonic-gate case AF_INET6: 17857c478bd9Sstevel@tonic-gate sin6 = (sin6_t *)addr; 17867c478bd9Sstevel@tonic-gate if ((sctp->sctp_state <= SCTPS_LISTEN) && 17877c478bd9Sstevel@tonic-gate sctp->sctp_bound_to_all) { 17887c478bd9Sstevel@tonic-gate bzero(&sin6->sin6_addr, sizeof (sin6->sin6_addr)); 17897c478bd9Sstevel@tonic-gate sin6->sin6_port = sctp->sctp_lport; 17907c478bd9Sstevel@tonic-gate } else { 17917c478bd9Sstevel@tonic-gate err = sctp_getmyaddrs(sctp, sin6, &addrcnt); 17927c478bd9Sstevel@tonic-gate if (err != 0) { 17937c478bd9Sstevel@tonic-gate *addrlen = 0; 17947c478bd9Sstevel@tonic-gate break; 17957c478bd9Sstevel@tonic-gate } 17967c478bd9Sstevel@tonic-gate } 17977c478bd9Sstevel@tonic-gate *addrlen = sizeof (struct sockaddr_in6); 17987c478bd9Sstevel@tonic-gate sin6->sin6_flowinfo = sctp->sctp_ip6h->ip6_vcf & 17997c478bd9Sstevel@tonic-gate ~IPV6_VERS_AND_FLOW_MASK; 18007c478bd9Sstevel@tonic-gate sin6->sin6_scope_id = 0; 18017c478bd9Sstevel@tonic-gate sin6->__sin6_src_id = 0; 18027c478bd9Sstevel@tonic-gate break; 18037c478bd9Sstevel@tonic-gate } 18047c478bd9Sstevel@tonic-gate WAKE_SCTP(sctp); 18057c478bd9Sstevel@tonic-gate return (err); 18067c478bd9Sstevel@tonic-gate } 18077c478bd9Sstevel@tonic-gate 18087c478bd9Sstevel@tonic-gate /* 18097c478bd9Sstevel@tonic-gate * SCTP exported kernel interface for geting the primary peer address of 18107c478bd9Sstevel@tonic-gate * a sctp_t. The parameter addr is assumed to have enough space to hold 18117c478bd9Sstevel@tonic-gate * one socket address. 18127c478bd9Sstevel@tonic-gate */ 18137c478bd9Sstevel@tonic-gate int 18147c478bd9Sstevel@tonic-gate sctp_getpeername(sctp_t *sctp, struct sockaddr *addr, socklen_t *addrlen) 18157c478bd9Sstevel@tonic-gate { 18167c478bd9Sstevel@tonic-gate int err = 0; 18177c478bd9Sstevel@tonic-gate int addrcnt = 1; 18187c478bd9Sstevel@tonic-gate sin6_t *sin6; 18197c478bd9Sstevel@tonic-gate 18207c478bd9Sstevel@tonic-gate ASSERT(sctp != NULL); 18217c478bd9Sstevel@tonic-gate 18227c478bd9Sstevel@tonic-gate RUN_SCTP(sctp); 18237c478bd9Sstevel@tonic-gate addr->sa_family = sctp->sctp_family; 18247c478bd9Sstevel@tonic-gate switch (sctp->sctp_family) { 18257c478bd9Sstevel@tonic-gate case AF_INET: 18267c478bd9Sstevel@tonic-gate err = sctp_getpeeraddrs(sctp, addr, &addrcnt); 18277c478bd9Sstevel@tonic-gate if (err != 0) { 18287c478bd9Sstevel@tonic-gate *addrlen = 0; 18297c478bd9Sstevel@tonic-gate break; 18307c478bd9Sstevel@tonic-gate } 18317c478bd9Sstevel@tonic-gate *addrlen = sizeof (struct sockaddr_in); 18327c478bd9Sstevel@tonic-gate break; 18337c478bd9Sstevel@tonic-gate case AF_INET6: 18347c478bd9Sstevel@tonic-gate sin6 = (sin6_t *)addr; 18357c478bd9Sstevel@tonic-gate err = sctp_getpeeraddrs(sctp, sin6, &addrcnt); 18367c478bd9Sstevel@tonic-gate if (err != 0) { 18377c478bd9Sstevel@tonic-gate *addrlen = 0; 18387c478bd9Sstevel@tonic-gate break; 18397c478bd9Sstevel@tonic-gate } 18407c478bd9Sstevel@tonic-gate *addrlen = sizeof (struct sockaddr_in6); 18417c478bd9Sstevel@tonic-gate sin6->sin6_flowinfo = 0; 18427c478bd9Sstevel@tonic-gate sin6->sin6_scope_id = 0; 18437c478bd9Sstevel@tonic-gate sin6->__sin6_src_id = 0; 18447c478bd9Sstevel@tonic-gate break; 18457c478bd9Sstevel@tonic-gate } 18467c478bd9Sstevel@tonic-gate WAKE_SCTP(sctp); 18477c478bd9Sstevel@tonic-gate return (err); 18487c478bd9Sstevel@tonic-gate } 18497c478bd9Sstevel@tonic-gate 18507c478bd9Sstevel@tonic-gate /* 18517c478bd9Sstevel@tonic-gate * Return a list of IP addresses of the peer endpoint of this sctp_t. 18527c478bd9Sstevel@tonic-gate * The parameter paddrs is supposed to be either (struct sockaddr_in *) or 18537c478bd9Sstevel@tonic-gate * (struct sockaddr_in6 *) depending on the address family of the sctp_t. 18547c478bd9Sstevel@tonic-gate */ 18557c478bd9Sstevel@tonic-gate int 18567c478bd9Sstevel@tonic-gate sctp_getpeeraddrs(sctp_t *sctp, void *paddrs, int *addrcnt) 18577c478bd9Sstevel@tonic-gate { 18587c478bd9Sstevel@tonic-gate int family; 18597c478bd9Sstevel@tonic-gate struct sockaddr_in *sin4; 18607c478bd9Sstevel@tonic-gate struct sockaddr_in6 *sin6; 18617c478bd9Sstevel@tonic-gate int max; 18627c478bd9Sstevel@tonic-gate int cnt; 18637c478bd9Sstevel@tonic-gate sctp_faddr_t *fp = sctp->sctp_faddrs; 18647c478bd9Sstevel@tonic-gate in6_addr_t addr; 18657c478bd9Sstevel@tonic-gate 18667c478bd9Sstevel@tonic-gate ASSERT(sctp != NULL); 18677c478bd9Sstevel@tonic-gate 18687c478bd9Sstevel@tonic-gate if (sctp->sctp_faddrs == NULL) 18697c478bd9Sstevel@tonic-gate return (ENOTCONN); 18707c478bd9Sstevel@tonic-gate 18717c478bd9Sstevel@tonic-gate family = sctp->sctp_family; 18727c478bd9Sstevel@tonic-gate max = *addrcnt; 18737c478bd9Sstevel@tonic-gate 18747c478bd9Sstevel@tonic-gate /* If we want only one, give the primary */ 18757c478bd9Sstevel@tonic-gate if (max == 1) { 18767c478bd9Sstevel@tonic-gate addr = sctp->sctp_primary->faddr; 18777c478bd9Sstevel@tonic-gate switch (family) { 18787c478bd9Sstevel@tonic-gate case AF_INET: 18797c478bd9Sstevel@tonic-gate sin4 = paddrs; 18807c478bd9Sstevel@tonic-gate IN6_V4MAPPED_TO_INADDR(&addr, &sin4->sin_addr); 18817c478bd9Sstevel@tonic-gate sin4->sin_port = sctp->sctp_fport; 18827c478bd9Sstevel@tonic-gate sin4->sin_family = AF_INET; 18837c478bd9Sstevel@tonic-gate break; 18847c478bd9Sstevel@tonic-gate 18857c478bd9Sstevel@tonic-gate case AF_INET6: 18867c478bd9Sstevel@tonic-gate sin6 = paddrs; 18877c478bd9Sstevel@tonic-gate sin6->sin6_addr = addr; 18887c478bd9Sstevel@tonic-gate sin6->sin6_port = sctp->sctp_fport; 18897c478bd9Sstevel@tonic-gate sin6->sin6_family = AF_INET6; 18907c478bd9Sstevel@tonic-gate break; 18917c478bd9Sstevel@tonic-gate } 18927c478bd9Sstevel@tonic-gate return (0); 18937c478bd9Sstevel@tonic-gate } 18947c478bd9Sstevel@tonic-gate 18957c478bd9Sstevel@tonic-gate for (cnt = 0; cnt < max && fp != NULL; cnt++, fp = fp->next) { 18967c478bd9Sstevel@tonic-gate addr = fp->faddr; 18977c478bd9Sstevel@tonic-gate switch (family) { 18987c478bd9Sstevel@tonic-gate case AF_INET: 18997c478bd9Sstevel@tonic-gate ASSERT(IN6_IS_ADDR_V4MAPPED(&addr)); 19007c478bd9Sstevel@tonic-gate sin4 = (struct sockaddr_in *)paddrs + cnt; 19017c478bd9Sstevel@tonic-gate IN6_V4MAPPED_TO_INADDR(&addr, &sin4->sin_addr); 19027c478bd9Sstevel@tonic-gate sin4->sin_port = sctp->sctp_fport; 19037c478bd9Sstevel@tonic-gate sin4->sin_family = AF_INET; 19047c478bd9Sstevel@tonic-gate break; 19057c478bd9Sstevel@tonic-gate case AF_INET6: 19067c478bd9Sstevel@tonic-gate sin6 = (struct sockaddr_in6 *)paddrs + cnt; 19077c478bd9Sstevel@tonic-gate sin6->sin6_addr = addr; 19087c478bd9Sstevel@tonic-gate sin6->sin6_port = sctp->sctp_fport; 19097c478bd9Sstevel@tonic-gate sin6->sin6_family = AF_INET6; 19107c478bd9Sstevel@tonic-gate break; 19117c478bd9Sstevel@tonic-gate } 19127c478bd9Sstevel@tonic-gate } 19137c478bd9Sstevel@tonic-gate *addrcnt = cnt; 19147c478bd9Sstevel@tonic-gate return (0); 19157c478bd9Sstevel@tonic-gate } 1916