xref: /titanic_51/usr/src/lib/libsocket/socket/weaks.c (revision a574db851cdc636fc3939b68e80d79fe7fbd57f2)
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
5*a574db85Sraf  * Common Development and Distribution License (the "License").
6*a574db85Sraf  * 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*a574db85Sraf 
227c478bd9Sstevel@tonic-gate /*
23*a574db85Sraf  * Copyright 2008 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/socket.h>
317c478bd9Sstevel@tonic-gate #include <sys/stropts.h>
327c478bd9Sstevel@tonic-gate #include <sys/stream.h>
337c478bd9Sstevel@tonic-gate #include <sys/socketvar.h>
347c478bd9Sstevel@tonic-gate #include <sys/sockio.h>
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #include <errno.h>
377c478bd9Sstevel@tonic-gate #include <stdlib.h>
387c478bd9Sstevel@tonic-gate #include <unistd.h>
397c478bd9Sstevel@tonic-gate #include <stropts.h>
407c478bd9Sstevel@tonic-gate #include <stdio.h>
417c478bd9Sstevel@tonic-gate #include <strings.h>
427c478bd9Sstevel@tonic-gate #include <netinet/sctp.h>
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate #pragma weak bind = _bind
457c478bd9Sstevel@tonic-gate #pragma weak listen = _listen
467c478bd9Sstevel@tonic-gate #pragma weak accept = _accept
477c478bd9Sstevel@tonic-gate #pragma weak connect = _connect
487c478bd9Sstevel@tonic-gate #pragma weak shutdown = _shutdown
497c478bd9Sstevel@tonic-gate #pragma weak recv = _recv
507c478bd9Sstevel@tonic-gate #pragma weak recvfrom = _recvfrom
517c478bd9Sstevel@tonic-gate #pragma weak recvmsg = _recvmsg
527c478bd9Sstevel@tonic-gate #pragma weak send = _send
537c478bd9Sstevel@tonic-gate #pragma weak sendmsg = _sendmsg
547c478bd9Sstevel@tonic-gate #pragma weak sendto = _sendto
557c478bd9Sstevel@tonic-gate #pragma weak getpeername = _getpeername
567c478bd9Sstevel@tonic-gate #pragma weak getsockname = _getsockname
577c478bd9Sstevel@tonic-gate #pragma weak getsockopt = _getsockopt
587c478bd9Sstevel@tonic-gate #pragma weak setsockopt = _setsockopt
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate extern int _so_bind();
617c478bd9Sstevel@tonic-gate extern int _so_listen();
627c478bd9Sstevel@tonic-gate extern int _so_accept();
637c478bd9Sstevel@tonic-gate extern int _so_connect();
647c478bd9Sstevel@tonic-gate extern int _so_shutdown();
657c478bd9Sstevel@tonic-gate extern int _so_recv();
667c478bd9Sstevel@tonic-gate extern int _so_recvfrom();
677c478bd9Sstevel@tonic-gate extern int _so_recvmsg();
687c478bd9Sstevel@tonic-gate extern int _so_send();
697c478bd9Sstevel@tonic-gate extern int _so_sendmsg();
707c478bd9Sstevel@tonic-gate extern int _so_sendto();
717c478bd9Sstevel@tonic-gate extern int _so_getpeername();
727c478bd9Sstevel@tonic-gate extern int _so_getsockopt();
737c478bd9Sstevel@tonic-gate extern int _so_setsockopt();
747c478bd9Sstevel@tonic-gate extern int _so_getsockname();
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate /*
777c478bd9Sstevel@tonic-gate  * Note that regular sockets use SOV_SOCKBSD here to not allow a rebind of an
787c478bd9Sstevel@tonic-gate  * already bound socket.
797c478bd9Sstevel@tonic-gate  */
807c478bd9Sstevel@tonic-gate int
817c478bd9Sstevel@tonic-gate _bind(int sock, struct sockaddr *addr, int addrlen)
827c478bd9Sstevel@tonic-gate {
837c478bd9Sstevel@tonic-gate 	return (_so_bind(sock, addr, addrlen, SOV_SOCKBSD));
847c478bd9Sstevel@tonic-gate }
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate int
877c478bd9Sstevel@tonic-gate _listen(int sock, int backlog)
887c478bd9Sstevel@tonic-gate {
897c478bd9Sstevel@tonic-gate 	return (_so_listen(sock, backlog, SOV_DEFAULT));
907c478bd9Sstevel@tonic-gate }
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate int
937c478bd9Sstevel@tonic-gate _accept(int sock, struct sockaddr *addr, int *addrlen)
947c478bd9Sstevel@tonic-gate {
957c478bd9Sstevel@tonic-gate 	return (_so_accept(sock, addr, addrlen, SOV_DEFAULT));
967c478bd9Sstevel@tonic-gate }
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate int
997c478bd9Sstevel@tonic-gate _connect(int sock, struct sockaddr *addr, int addrlen)
1007c478bd9Sstevel@tonic-gate {
1017c478bd9Sstevel@tonic-gate 	return (_so_connect(sock, addr, addrlen, SOV_DEFAULT));
1027c478bd9Sstevel@tonic-gate }
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate int
1057c478bd9Sstevel@tonic-gate _shutdown(int sock, int how)
1067c478bd9Sstevel@tonic-gate {
1077c478bd9Sstevel@tonic-gate 	return (_so_shutdown(sock, how, SOV_DEFAULT));
1087c478bd9Sstevel@tonic-gate }
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate int
1117c478bd9Sstevel@tonic-gate _recv(int sock, char *buf, int len, int flags)
1127c478bd9Sstevel@tonic-gate {
1137c478bd9Sstevel@tonic-gate 	return (_so_recv(sock, buf, len, flags & ~MSG_XPG4_2));
1147c478bd9Sstevel@tonic-gate }
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate int
1177c478bd9Sstevel@tonic-gate _recvfrom(int sock, char *buf, int len, int flags,
1187c478bd9Sstevel@tonic-gate 	struct sockaddr *addr, int *addrlen)
1197c478bd9Sstevel@tonic-gate {
1207c478bd9Sstevel@tonic-gate 	return (_so_recvfrom(sock, buf, len, flags & ~MSG_XPG4_2,
1217c478bd9Sstevel@tonic-gate 	    addr, addrlen));
1227c478bd9Sstevel@tonic-gate }
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate int
1257c478bd9Sstevel@tonic-gate _recvmsg(int sock, struct msghdr *msg, int flags)
1267c478bd9Sstevel@tonic-gate {
1277c478bd9Sstevel@tonic-gate 	return (_so_recvmsg(sock, msg, flags & ~MSG_XPG4_2));
1287c478bd9Sstevel@tonic-gate }
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate int
1317c478bd9Sstevel@tonic-gate _send(int sock, char *buf, int len, int flags)
1327c478bd9Sstevel@tonic-gate {
1337c478bd9Sstevel@tonic-gate 	return (_so_send(sock, buf, len, flags & ~MSG_XPG4_2));
1347c478bd9Sstevel@tonic-gate }
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate int
1377c478bd9Sstevel@tonic-gate _sendmsg(int sock, struct msghdr *msg, int flags)
1387c478bd9Sstevel@tonic-gate {
1397c478bd9Sstevel@tonic-gate 	return (_so_sendmsg(sock, msg, flags & ~MSG_XPG4_2));
1407c478bd9Sstevel@tonic-gate }
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate int
1437c478bd9Sstevel@tonic-gate _sendto(int sock, char *buf, int len, int flags,
1447c478bd9Sstevel@tonic-gate 	struct sockaddr *addr, int *addrlen)
1457c478bd9Sstevel@tonic-gate {
1467c478bd9Sstevel@tonic-gate 	return (_so_sendto(sock, buf, len, flags & ~MSG_XPG4_2,
1477c478bd9Sstevel@tonic-gate 	    addr, addrlen));
1487c478bd9Sstevel@tonic-gate }
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate int
1517c478bd9Sstevel@tonic-gate _getpeername(int sock, struct sockaddr *name, int *namelen)
1527c478bd9Sstevel@tonic-gate {
1537c478bd9Sstevel@tonic-gate 	return (_so_getpeername(sock, name, namelen, SOV_DEFAULT));
1547c478bd9Sstevel@tonic-gate }
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate int
1577c478bd9Sstevel@tonic-gate _getsockname(int sock, struct sockaddr *name, int *namelen)
1587c478bd9Sstevel@tonic-gate {
1597c478bd9Sstevel@tonic-gate 	return (_so_getsockname(sock, name, namelen, SOV_DEFAULT));
1607c478bd9Sstevel@tonic-gate }
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate int
1637c478bd9Sstevel@tonic-gate _getsockopt(int sock, int level, int optname, char *optval, int *optlen)
1647c478bd9Sstevel@tonic-gate {
1657c478bd9Sstevel@tonic-gate 	if (level == IPPROTO_SCTP) {
1667c478bd9Sstevel@tonic-gate 		sctp_assoc_t id = 0;
1677c478bd9Sstevel@tonic-gate 		socklen_t len = *optlen;
1687c478bd9Sstevel@tonic-gate 		int err = 0;
1697c478bd9Sstevel@tonic-gate 		struct sctpopt sopt;
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate 		switch (optname) {
1727c478bd9Sstevel@tonic-gate 		case SCTP_RTOINFO:
1737c478bd9Sstevel@tonic-gate 		case SCTP_ASSOCINFO:
1747c478bd9Sstevel@tonic-gate 		case SCTP_SET_PEER_PRIMARY_ADDR:
1757c478bd9Sstevel@tonic-gate 		case SCTP_PRIMARY_ADDR:
1767c478bd9Sstevel@tonic-gate 		case SCTP_PEER_ADDR_PARAMS:
1777c478bd9Sstevel@tonic-gate 		case SCTP_STATUS:
1787c478bd9Sstevel@tonic-gate 		case SCTP_GET_PEER_ADDR_INFO:
1797c478bd9Sstevel@tonic-gate 			/*
1807c478bd9Sstevel@tonic-gate 			 * Association ID is the first element params struct
1817c478bd9Sstevel@tonic-gate 			 */
1827c478bd9Sstevel@tonic-gate 			bcopy(optval, &id, sizeof (id));
1837c478bd9Sstevel@tonic-gate 			break;
1847c478bd9Sstevel@tonic-gate 		case SCTP_DEFAULT_SEND_PARAM:
1857c478bd9Sstevel@tonic-gate 			bcopy(&((struct sctp_sndrcvinfo *)
1867c478bd9Sstevel@tonic-gate 			    optval)->sinfo_assoc_id, &id, sizeof (id));
1877c478bd9Sstevel@tonic-gate 			break;
1887c478bd9Sstevel@tonic-gate 		}
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate 		sopt.sopt_aid = id;
1917c478bd9Sstevel@tonic-gate 		sopt.sopt_name = optname;
1927c478bd9Sstevel@tonic-gate 		sopt.sopt_val = optval;
1937c478bd9Sstevel@tonic-gate 		sopt.sopt_len = len;
1947c478bd9Sstevel@tonic-gate 		if (ioctl(sock, SIOCSCTPGOPT, &sopt) == -1) {
1957c478bd9Sstevel@tonic-gate 			err = -1;
1967c478bd9Sstevel@tonic-gate 		} else {
1977c478bd9Sstevel@tonic-gate 			*optlen = sopt.sopt_len;
1987c478bd9Sstevel@tonic-gate 		}
1997c478bd9Sstevel@tonic-gate 		return (err);
2007c478bd9Sstevel@tonic-gate 	} else {
2017c478bd9Sstevel@tonic-gate 		return (_so_getsockopt(sock, level, optname, optval, optlen,
2027c478bd9Sstevel@tonic-gate 		    SOV_DEFAULT));
2037c478bd9Sstevel@tonic-gate 	}
2047c478bd9Sstevel@tonic-gate }
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate int
2077c478bd9Sstevel@tonic-gate _setsockopt(int sock, int level, int optname, char *optval, int optlen)
2087c478bd9Sstevel@tonic-gate {
2097c478bd9Sstevel@tonic-gate 	return (_so_setsockopt(sock, level, optname, optval, optlen,
2107c478bd9Sstevel@tonic-gate 	    SOV_DEFAULT));
2117c478bd9Sstevel@tonic-gate }
2127c478bd9Sstevel@tonic-gate 
2137c478bd9Sstevel@tonic-gate int
2147c478bd9Sstevel@tonic-gate __xnet_bind(int sock, const struct sockaddr *addr, socklen_t addrlen)
2157c478bd9Sstevel@tonic-gate {
2167c478bd9Sstevel@tonic-gate 	return (_so_bind(sock, addr, addrlen, SOV_XPG4_2));
2177c478bd9Sstevel@tonic-gate }
2187c478bd9Sstevel@tonic-gate 
2197c478bd9Sstevel@tonic-gate 
2207c478bd9Sstevel@tonic-gate int
2217c478bd9Sstevel@tonic-gate __xnet_listen(int sock, int backlog)
2227c478bd9Sstevel@tonic-gate {
2237c478bd9Sstevel@tonic-gate 	return (_so_listen(sock, backlog, SOV_XPG4_2));
2247c478bd9Sstevel@tonic-gate }
2257c478bd9Sstevel@tonic-gate 
2267c478bd9Sstevel@tonic-gate int
2277c478bd9Sstevel@tonic-gate __xnet_connect(int sock, const struct sockaddr *addr, socklen_t addrlen)
2287c478bd9Sstevel@tonic-gate {
2297c478bd9Sstevel@tonic-gate 	return (_so_connect(sock, addr, addrlen, SOV_XPG4_2));
2307c478bd9Sstevel@tonic-gate }
2317c478bd9Sstevel@tonic-gate 
2327c478bd9Sstevel@tonic-gate int
2337c478bd9Sstevel@tonic-gate __xnet_recvmsg(int sock, struct msghdr *msg, int flags)
2347c478bd9Sstevel@tonic-gate {
2357c478bd9Sstevel@tonic-gate 	return (_so_recvmsg(sock, msg, flags | MSG_XPG4_2));
2367c478bd9Sstevel@tonic-gate }
2377c478bd9Sstevel@tonic-gate 
2387c478bd9Sstevel@tonic-gate int
2397c478bd9Sstevel@tonic-gate __xnet_sendmsg(int sock, const struct msghdr *msg, int flags)
2407c478bd9Sstevel@tonic-gate {
2417c478bd9Sstevel@tonic-gate 	return (_so_sendmsg(sock, msg, flags | MSG_XPG4_2));
2427c478bd9Sstevel@tonic-gate }
2437c478bd9Sstevel@tonic-gate 
2447c478bd9Sstevel@tonic-gate int
2457c478bd9Sstevel@tonic-gate __xnet_sendto(int sock, const void *buf, size_t len, int flags,
2467c478bd9Sstevel@tonic-gate 	const struct sockaddr *addr, socklen_t addrlen)
2477c478bd9Sstevel@tonic-gate {
2487c478bd9Sstevel@tonic-gate 	return (_so_sendto(sock, buf, len, flags | MSG_XPG4_2,
2497c478bd9Sstevel@tonic-gate 	    addr, addrlen));
2507c478bd9Sstevel@tonic-gate }
2517c478bd9Sstevel@tonic-gate 
2527c478bd9Sstevel@tonic-gate int
2537c478bd9Sstevel@tonic-gate __xnet_getsockopt(int sock, int level, int option_name,
2547c478bd9Sstevel@tonic-gate 	void *option_value, socklen_t *option_lenp)
2557c478bd9Sstevel@tonic-gate {
2567c478bd9Sstevel@tonic-gate 	if (level == IPPROTO_SCTP) {
2577c478bd9Sstevel@tonic-gate 		return (_getsockopt(sock, level, option_name, option_value,
2587c478bd9Sstevel@tonic-gate 		    (int *)option_lenp));
2597c478bd9Sstevel@tonic-gate 	} else {
2607c478bd9Sstevel@tonic-gate 		return (_so_getsockopt(sock, level, option_name, option_value,
2617c478bd9Sstevel@tonic-gate 		    option_lenp, SOV_XPG4_2));
2627c478bd9Sstevel@tonic-gate 	}
2637c478bd9Sstevel@tonic-gate }
264