1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 30*7c478bd9Sstevel@tonic-gate #include <sys/socket.h> 31*7c478bd9Sstevel@tonic-gate #include <sys/stropts.h> 32*7c478bd9Sstevel@tonic-gate #include <sys/stream.h> 33*7c478bd9Sstevel@tonic-gate #include <sys/socketvar.h> 34*7c478bd9Sstevel@tonic-gate #include <sys/sockio.h> 35*7c478bd9Sstevel@tonic-gate 36*7c478bd9Sstevel@tonic-gate #include <errno.h> 37*7c478bd9Sstevel@tonic-gate #include <stdlib.h> 38*7c478bd9Sstevel@tonic-gate #include <unistd.h> 39*7c478bd9Sstevel@tonic-gate #include <stropts.h> 40*7c478bd9Sstevel@tonic-gate #include <stdio.h> 41*7c478bd9Sstevel@tonic-gate #include <strings.h> 42*7c478bd9Sstevel@tonic-gate #include <netinet/sctp.h> 43*7c478bd9Sstevel@tonic-gate 44*7c478bd9Sstevel@tonic-gate #pragma weak bind = _bind 45*7c478bd9Sstevel@tonic-gate #pragma weak listen = _listen 46*7c478bd9Sstevel@tonic-gate #pragma weak accept = _accept 47*7c478bd9Sstevel@tonic-gate #pragma weak connect = _connect 48*7c478bd9Sstevel@tonic-gate #pragma weak shutdown = _shutdown 49*7c478bd9Sstevel@tonic-gate #pragma weak recv = _recv 50*7c478bd9Sstevel@tonic-gate #pragma weak recvfrom = _recvfrom 51*7c478bd9Sstevel@tonic-gate #pragma weak recvmsg = _recvmsg 52*7c478bd9Sstevel@tonic-gate #pragma weak send = _send 53*7c478bd9Sstevel@tonic-gate #pragma weak sendmsg = _sendmsg 54*7c478bd9Sstevel@tonic-gate #pragma weak sendto = _sendto 55*7c478bd9Sstevel@tonic-gate #pragma weak getpeername = _getpeername 56*7c478bd9Sstevel@tonic-gate #pragma weak getsockname = _getsockname 57*7c478bd9Sstevel@tonic-gate #pragma weak getsockopt = _getsockopt 58*7c478bd9Sstevel@tonic-gate #pragma weak setsockopt = _setsockopt 59*7c478bd9Sstevel@tonic-gate 60*7c478bd9Sstevel@tonic-gate extern int _so_bind(); 61*7c478bd9Sstevel@tonic-gate extern int _so_listen(); 62*7c478bd9Sstevel@tonic-gate extern int _so_accept(); 63*7c478bd9Sstevel@tonic-gate extern int _so_connect(); 64*7c478bd9Sstevel@tonic-gate extern int _so_shutdown(); 65*7c478bd9Sstevel@tonic-gate extern int _so_recv(); 66*7c478bd9Sstevel@tonic-gate extern int _so_recvfrom(); 67*7c478bd9Sstevel@tonic-gate extern int _so_recvmsg(); 68*7c478bd9Sstevel@tonic-gate extern int _so_send(); 69*7c478bd9Sstevel@tonic-gate extern int _so_sendmsg(); 70*7c478bd9Sstevel@tonic-gate extern int _so_sendto(); 71*7c478bd9Sstevel@tonic-gate extern int _so_getpeername(); 72*7c478bd9Sstevel@tonic-gate extern int _so_getsockopt(); 73*7c478bd9Sstevel@tonic-gate extern int _so_setsockopt(); 74*7c478bd9Sstevel@tonic-gate extern int _so_setsockname(); 75*7c478bd9Sstevel@tonic-gate extern int _so_getsockname(); 76*7c478bd9Sstevel@tonic-gate 77*7c478bd9Sstevel@tonic-gate /* 78*7c478bd9Sstevel@tonic-gate * Note that regular sockets use SOV_SOCKBSD here to not allow a rebind of an 79*7c478bd9Sstevel@tonic-gate * already bound socket. 80*7c478bd9Sstevel@tonic-gate */ 81*7c478bd9Sstevel@tonic-gate int 82*7c478bd9Sstevel@tonic-gate _bind(int sock, struct sockaddr *addr, int addrlen) 83*7c478bd9Sstevel@tonic-gate { 84*7c478bd9Sstevel@tonic-gate return (_so_bind(sock, addr, addrlen, SOV_SOCKBSD)); 85*7c478bd9Sstevel@tonic-gate } 86*7c478bd9Sstevel@tonic-gate 87*7c478bd9Sstevel@tonic-gate int 88*7c478bd9Sstevel@tonic-gate _listen(int sock, int backlog) 89*7c478bd9Sstevel@tonic-gate { 90*7c478bd9Sstevel@tonic-gate return (_so_listen(sock, backlog, SOV_DEFAULT)); 91*7c478bd9Sstevel@tonic-gate } 92*7c478bd9Sstevel@tonic-gate 93*7c478bd9Sstevel@tonic-gate int 94*7c478bd9Sstevel@tonic-gate _accept(int sock, struct sockaddr *addr, int *addrlen) 95*7c478bd9Sstevel@tonic-gate { 96*7c478bd9Sstevel@tonic-gate return (_so_accept(sock, addr, addrlen, SOV_DEFAULT)); 97*7c478bd9Sstevel@tonic-gate } 98*7c478bd9Sstevel@tonic-gate 99*7c478bd9Sstevel@tonic-gate int 100*7c478bd9Sstevel@tonic-gate _connect(int sock, struct sockaddr *addr, int addrlen) 101*7c478bd9Sstevel@tonic-gate { 102*7c478bd9Sstevel@tonic-gate return (_so_connect(sock, addr, addrlen, SOV_DEFAULT)); 103*7c478bd9Sstevel@tonic-gate } 104*7c478bd9Sstevel@tonic-gate 105*7c478bd9Sstevel@tonic-gate int 106*7c478bd9Sstevel@tonic-gate _shutdown(int sock, int how) 107*7c478bd9Sstevel@tonic-gate { 108*7c478bd9Sstevel@tonic-gate return (_so_shutdown(sock, how, SOV_DEFAULT)); 109*7c478bd9Sstevel@tonic-gate } 110*7c478bd9Sstevel@tonic-gate 111*7c478bd9Sstevel@tonic-gate int 112*7c478bd9Sstevel@tonic-gate _recv(int sock, char *buf, int len, int flags) 113*7c478bd9Sstevel@tonic-gate { 114*7c478bd9Sstevel@tonic-gate return (_so_recv(sock, buf, len, flags & ~MSG_XPG4_2)); 115*7c478bd9Sstevel@tonic-gate } 116*7c478bd9Sstevel@tonic-gate 117*7c478bd9Sstevel@tonic-gate int 118*7c478bd9Sstevel@tonic-gate _recvfrom(int sock, char *buf, int len, int flags, 119*7c478bd9Sstevel@tonic-gate struct sockaddr *addr, int *addrlen) 120*7c478bd9Sstevel@tonic-gate { 121*7c478bd9Sstevel@tonic-gate return (_so_recvfrom(sock, buf, len, flags & ~MSG_XPG4_2, 122*7c478bd9Sstevel@tonic-gate addr, addrlen)); 123*7c478bd9Sstevel@tonic-gate } 124*7c478bd9Sstevel@tonic-gate 125*7c478bd9Sstevel@tonic-gate int 126*7c478bd9Sstevel@tonic-gate _recvmsg(int sock, struct msghdr *msg, int flags) 127*7c478bd9Sstevel@tonic-gate { 128*7c478bd9Sstevel@tonic-gate return (_so_recvmsg(sock, msg, flags & ~MSG_XPG4_2)); 129*7c478bd9Sstevel@tonic-gate } 130*7c478bd9Sstevel@tonic-gate 131*7c478bd9Sstevel@tonic-gate int 132*7c478bd9Sstevel@tonic-gate _send(int sock, char *buf, int len, int flags) 133*7c478bd9Sstevel@tonic-gate { 134*7c478bd9Sstevel@tonic-gate return (_so_send(sock, buf, len, flags & ~MSG_XPG4_2)); 135*7c478bd9Sstevel@tonic-gate } 136*7c478bd9Sstevel@tonic-gate 137*7c478bd9Sstevel@tonic-gate int 138*7c478bd9Sstevel@tonic-gate _sendmsg(int sock, struct msghdr *msg, int flags) 139*7c478bd9Sstevel@tonic-gate { 140*7c478bd9Sstevel@tonic-gate return (_so_sendmsg(sock, msg, flags & ~MSG_XPG4_2)); 141*7c478bd9Sstevel@tonic-gate } 142*7c478bd9Sstevel@tonic-gate 143*7c478bd9Sstevel@tonic-gate int 144*7c478bd9Sstevel@tonic-gate _sendto(int sock, char *buf, int len, int flags, 145*7c478bd9Sstevel@tonic-gate struct sockaddr *addr, int *addrlen) 146*7c478bd9Sstevel@tonic-gate { 147*7c478bd9Sstevel@tonic-gate return (_so_sendto(sock, buf, len, flags & ~MSG_XPG4_2, 148*7c478bd9Sstevel@tonic-gate addr, addrlen)); 149*7c478bd9Sstevel@tonic-gate } 150*7c478bd9Sstevel@tonic-gate 151*7c478bd9Sstevel@tonic-gate int 152*7c478bd9Sstevel@tonic-gate _getpeername(int sock, struct sockaddr *name, int *namelen) 153*7c478bd9Sstevel@tonic-gate { 154*7c478bd9Sstevel@tonic-gate return (_so_getpeername(sock, name, namelen, SOV_DEFAULT)); 155*7c478bd9Sstevel@tonic-gate } 156*7c478bd9Sstevel@tonic-gate 157*7c478bd9Sstevel@tonic-gate int 158*7c478bd9Sstevel@tonic-gate _getsockname(int sock, struct sockaddr *name, int *namelen) 159*7c478bd9Sstevel@tonic-gate { 160*7c478bd9Sstevel@tonic-gate return (_so_getsockname(sock, name, namelen, SOV_DEFAULT)); 161*7c478bd9Sstevel@tonic-gate } 162*7c478bd9Sstevel@tonic-gate 163*7c478bd9Sstevel@tonic-gate int 164*7c478bd9Sstevel@tonic-gate _getsockopt(int sock, int level, int optname, char *optval, int *optlen) 165*7c478bd9Sstevel@tonic-gate { 166*7c478bd9Sstevel@tonic-gate if (level == IPPROTO_SCTP) { 167*7c478bd9Sstevel@tonic-gate sctp_assoc_t id = 0; 168*7c478bd9Sstevel@tonic-gate socklen_t len = *optlen; 169*7c478bd9Sstevel@tonic-gate int err = 0; 170*7c478bd9Sstevel@tonic-gate struct sctpopt sopt; 171*7c478bd9Sstevel@tonic-gate 172*7c478bd9Sstevel@tonic-gate switch (optname) { 173*7c478bd9Sstevel@tonic-gate case SCTP_RTOINFO: 174*7c478bd9Sstevel@tonic-gate case SCTP_ASSOCINFO: 175*7c478bd9Sstevel@tonic-gate case SCTP_SET_PEER_PRIMARY_ADDR: 176*7c478bd9Sstevel@tonic-gate case SCTP_PRIMARY_ADDR: 177*7c478bd9Sstevel@tonic-gate case SCTP_PEER_ADDR_PARAMS: 178*7c478bd9Sstevel@tonic-gate case SCTP_STATUS: 179*7c478bd9Sstevel@tonic-gate case SCTP_GET_PEER_ADDR_INFO: 180*7c478bd9Sstevel@tonic-gate /* 181*7c478bd9Sstevel@tonic-gate * Association ID is the first element params struct 182*7c478bd9Sstevel@tonic-gate */ 183*7c478bd9Sstevel@tonic-gate bcopy(optval, &id, sizeof (id)); 184*7c478bd9Sstevel@tonic-gate break; 185*7c478bd9Sstevel@tonic-gate case SCTP_DEFAULT_SEND_PARAM: 186*7c478bd9Sstevel@tonic-gate bcopy(&((struct sctp_sndrcvinfo *) 187*7c478bd9Sstevel@tonic-gate optval)->sinfo_assoc_id, &id, sizeof (id)); 188*7c478bd9Sstevel@tonic-gate break; 189*7c478bd9Sstevel@tonic-gate } 190*7c478bd9Sstevel@tonic-gate 191*7c478bd9Sstevel@tonic-gate sopt.sopt_aid = id; 192*7c478bd9Sstevel@tonic-gate sopt.sopt_name = optname; 193*7c478bd9Sstevel@tonic-gate sopt.sopt_val = optval; 194*7c478bd9Sstevel@tonic-gate sopt.sopt_len = len; 195*7c478bd9Sstevel@tonic-gate if (ioctl(sock, SIOCSCTPGOPT, &sopt) == -1) { 196*7c478bd9Sstevel@tonic-gate err = -1; 197*7c478bd9Sstevel@tonic-gate } else { 198*7c478bd9Sstevel@tonic-gate *optlen = sopt.sopt_len; 199*7c478bd9Sstevel@tonic-gate } 200*7c478bd9Sstevel@tonic-gate return (err); 201*7c478bd9Sstevel@tonic-gate } else { 202*7c478bd9Sstevel@tonic-gate return (_so_getsockopt(sock, level, optname, optval, optlen, 203*7c478bd9Sstevel@tonic-gate SOV_DEFAULT)); 204*7c478bd9Sstevel@tonic-gate } 205*7c478bd9Sstevel@tonic-gate } 206*7c478bd9Sstevel@tonic-gate 207*7c478bd9Sstevel@tonic-gate int 208*7c478bd9Sstevel@tonic-gate _setsockopt(int sock, int level, int optname, char *optval, int optlen) 209*7c478bd9Sstevel@tonic-gate { 210*7c478bd9Sstevel@tonic-gate return (_so_setsockopt(sock, level, optname, optval, optlen, 211*7c478bd9Sstevel@tonic-gate SOV_DEFAULT)); 212*7c478bd9Sstevel@tonic-gate } 213*7c478bd9Sstevel@tonic-gate 214*7c478bd9Sstevel@tonic-gate int 215*7c478bd9Sstevel@tonic-gate __xnet_bind(int sock, const struct sockaddr *addr, socklen_t addrlen) 216*7c478bd9Sstevel@tonic-gate { 217*7c478bd9Sstevel@tonic-gate return (_so_bind(sock, addr, addrlen, SOV_XPG4_2)); 218*7c478bd9Sstevel@tonic-gate } 219*7c478bd9Sstevel@tonic-gate 220*7c478bd9Sstevel@tonic-gate 221*7c478bd9Sstevel@tonic-gate int 222*7c478bd9Sstevel@tonic-gate __xnet_listen(int sock, int backlog) 223*7c478bd9Sstevel@tonic-gate { 224*7c478bd9Sstevel@tonic-gate return (_so_listen(sock, backlog, SOV_XPG4_2)); 225*7c478bd9Sstevel@tonic-gate } 226*7c478bd9Sstevel@tonic-gate 227*7c478bd9Sstevel@tonic-gate int 228*7c478bd9Sstevel@tonic-gate __xnet_connect(int sock, const struct sockaddr *addr, socklen_t addrlen) 229*7c478bd9Sstevel@tonic-gate { 230*7c478bd9Sstevel@tonic-gate return (_so_connect(sock, addr, addrlen, SOV_XPG4_2)); 231*7c478bd9Sstevel@tonic-gate } 232*7c478bd9Sstevel@tonic-gate 233*7c478bd9Sstevel@tonic-gate int 234*7c478bd9Sstevel@tonic-gate __xnet_recvmsg(int sock, struct msghdr *msg, int flags) 235*7c478bd9Sstevel@tonic-gate { 236*7c478bd9Sstevel@tonic-gate return (_so_recvmsg(sock, msg, flags | MSG_XPG4_2)); 237*7c478bd9Sstevel@tonic-gate } 238*7c478bd9Sstevel@tonic-gate 239*7c478bd9Sstevel@tonic-gate int 240*7c478bd9Sstevel@tonic-gate __xnet_sendmsg(int sock, const struct msghdr *msg, int flags) 241*7c478bd9Sstevel@tonic-gate { 242*7c478bd9Sstevel@tonic-gate return (_so_sendmsg(sock, msg, flags | MSG_XPG4_2)); 243*7c478bd9Sstevel@tonic-gate } 244*7c478bd9Sstevel@tonic-gate 245*7c478bd9Sstevel@tonic-gate int 246*7c478bd9Sstevel@tonic-gate __xnet_sendto(int sock, const void *buf, size_t len, int flags, 247*7c478bd9Sstevel@tonic-gate const struct sockaddr *addr, socklen_t addrlen) 248*7c478bd9Sstevel@tonic-gate { 249*7c478bd9Sstevel@tonic-gate return (_so_sendto(sock, buf, len, flags | MSG_XPG4_2, 250*7c478bd9Sstevel@tonic-gate addr, addrlen)); 251*7c478bd9Sstevel@tonic-gate } 252*7c478bd9Sstevel@tonic-gate 253*7c478bd9Sstevel@tonic-gate int 254*7c478bd9Sstevel@tonic-gate __xnet_getsockopt(int sock, int level, int option_name, 255*7c478bd9Sstevel@tonic-gate void *option_value, socklen_t *option_lenp) 256*7c478bd9Sstevel@tonic-gate { 257*7c478bd9Sstevel@tonic-gate if (level == IPPROTO_SCTP) { 258*7c478bd9Sstevel@tonic-gate return (_getsockopt(sock, level, option_name, option_value, 259*7c478bd9Sstevel@tonic-gate (int *)option_lenp)); 260*7c478bd9Sstevel@tonic-gate } else { 261*7c478bd9Sstevel@tonic-gate return (_so_getsockopt(sock, level, option_name, option_value, 262*7c478bd9Sstevel@tonic-gate option_lenp, SOV_XPG4_2)); 263*7c478bd9Sstevel@tonic-gate } 264*7c478bd9Sstevel@tonic-gate } 265