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