10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51548Srshoaib  * Common Development and Distribution License (the "License").
61548Srshoaib  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
211548Srshoaib 
220Sstevel@tonic-gate /*
236707Sbrutus  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
280Sstevel@tonic-gate /*	  All Rights Reserved  	*/
290Sstevel@tonic-gate 
300Sstevel@tonic-gate /*
310Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
320Sstevel@tonic-gate  * The Regents of the University of California
330Sstevel@tonic-gate  * All Rights Reserved
340Sstevel@tonic-gate  *
350Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
360Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
370Sstevel@tonic-gate  * contributors.
380Sstevel@tonic-gate  */
390Sstevel@tonic-gate 
400Sstevel@tonic-gate #ifndef _SYS_SOCKETVAR_H
410Sstevel@tonic-gate #define	_SYS_SOCKETVAR_H
420Sstevel@tonic-gate 
430Sstevel@tonic-gate #include <sys/types.h>
440Sstevel@tonic-gate #include <sys/stream.h>
450Sstevel@tonic-gate #include <sys/t_lock.h>
460Sstevel@tonic-gate #include <sys/cred.h>
470Sstevel@tonic-gate #include <sys/vnode.h>
480Sstevel@tonic-gate #include <sys/file.h>
490Sstevel@tonic-gate #include <sys/param.h>
500Sstevel@tonic-gate #include <sys/zone.h>
516707Sbrutus #include <sys/sodirect.h>
52898Skais #include <inet/kssl/ksslapi.h>
530Sstevel@tonic-gate 
540Sstevel@tonic-gate #ifdef	__cplusplus
550Sstevel@tonic-gate extern "C" {
560Sstevel@tonic-gate #endif
570Sstevel@tonic-gate 
580Sstevel@tonic-gate /*
590Sstevel@tonic-gate  * Internal representation used for addresses.
600Sstevel@tonic-gate  */
610Sstevel@tonic-gate struct soaddr {
620Sstevel@tonic-gate 	struct sockaddr	*soa_sa;	/* Actual address */
630Sstevel@tonic-gate 	t_uscalar_t	soa_len;	/* Length in bytes for kmem_free */
640Sstevel@tonic-gate 	t_uscalar_t	soa_maxlen;	/* Allocated length */
650Sstevel@tonic-gate };
660Sstevel@tonic-gate /* Maximum size address for transports that have ADDR_size == 1 */
670Sstevel@tonic-gate #define	SOA_DEFSIZE	128
680Sstevel@tonic-gate 
690Sstevel@tonic-gate /*
700Sstevel@tonic-gate  * Internal representation of the address used to represent addresses
710Sstevel@tonic-gate  * in the loopback transport for AF_UNIX. While the sockaddr_un is used
720Sstevel@tonic-gate  * as the sockfs layer address for AF_UNIX the pathnames contained in
730Sstevel@tonic-gate  * these addresses are not unique (due to relative pathnames) thus can not
740Sstevel@tonic-gate  * be used in the transport.
750Sstevel@tonic-gate  *
760Sstevel@tonic-gate  * The transport level address consists of a magic number (used to separate the
770Sstevel@tonic-gate  * name space for specific and implicit binds). For a specific bind
780Sstevel@tonic-gate  * this is followed by a "vnode *" which ensures that all specific binds
790Sstevel@tonic-gate  * have a unique transport level address. For implicit binds the latter
800Sstevel@tonic-gate  * part of the address is a byte string (of the same length as a pointer)
810Sstevel@tonic-gate  * that is assigned by the loopback transport.
820Sstevel@tonic-gate  *
830Sstevel@tonic-gate  * The uniqueness assumes that the loopback transport has a separate namespace
840Sstevel@tonic-gate  * for sockets in order to avoid name conflicts with e.g. TLI use of the
850Sstevel@tonic-gate  * same transport.
860Sstevel@tonic-gate  */
870Sstevel@tonic-gate struct so_ux_addr {
880Sstevel@tonic-gate 	void	*soua_vp;	/* vnode pointer or assigned by tl */
890Sstevel@tonic-gate 	uint_t	soua_magic;	/* See below */
900Sstevel@tonic-gate };
910Sstevel@tonic-gate 
920Sstevel@tonic-gate #define	SOU_MAGIC_EXPLICIT	0x75787670	/* "uxvp" */
930Sstevel@tonic-gate #define	SOU_MAGIC_IMPLICIT	0x616e6f6e	/* "anon" */
940Sstevel@tonic-gate 
950Sstevel@tonic-gate struct sockaddr_ux {
960Sstevel@tonic-gate 	sa_family_t		sou_family;	/* AF_UNIX */
970Sstevel@tonic-gate 	struct so_ux_addr	sou_addr;
980Sstevel@tonic-gate };
990Sstevel@tonic-gate 
1000Sstevel@tonic-gate typedef struct sonodeops sonodeops_t;
101741Smasputra typedef struct sonode sonode_t;
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate /*
1040Sstevel@tonic-gate  * The sonode represents a socket. A sonode never exist in the file system
1050Sstevel@tonic-gate  * name space and can not be opened using open() - only the socket, socketpair
1060Sstevel@tonic-gate  * and accept calls create sonodes.
1070Sstevel@tonic-gate  *
1080Sstevel@tonic-gate  * When an AF_UNIX socket is bound to a pathname the sockfs
1090Sstevel@tonic-gate  * creates a VSOCK vnode in the underlying file system. However, the vnodeops
1100Sstevel@tonic-gate  * etc in this VNODE remain those of the underlying file system.
1110Sstevel@tonic-gate  * Sockfs uses the v_stream pointer in the underlying file system VSOCK node
1120Sstevel@tonic-gate  * to find the sonode bound to the pathname. The bound pathname vnode
1130Sstevel@tonic-gate  * is accessed through so_ux_vp.
1140Sstevel@tonic-gate  *
1150Sstevel@tonic-gate  * A socket always corresponds to a VCHR stream representing the transport
1160Sstevel@tonic-gate  * provider (e.g. /dev/tcp). This information is retrieved from the kernel
1170Sstevel@tonic-gate  * socket configuration table and entered into so_accessvp. sockfs uses
1180Sstevel@tonic-gate  * this to perform VOP_ACCESS checks before allowing an open of the transport
1190Sstevel@tonic-gate  * provider.
1200Sstevel@tonic-gate  *
1210Sstevel@tonic-gate  * The locking of sockfs uses the so_lock mutex plus the SOLOCKED
1220Sstevel@tonic-gate  * and SOREADLOCKED flags in so_flag. The mutex protects all the state
1230Sstevel@tonic-gate  * in the sonode. The SOLOCKED flag is used to single-thread operations from
1240Sstevel@tonic-gate  * sockfs users to prevent e.g. multiple bind() calls to operate on the
1250Sstevel@tonic-gate  * same sonode concurrently. The SOREADLOCKED flag is used to ensure that
1260Sstevel@tonic-gate  * only one thread sleeps in kstrgetmsg for a given sonode. This is needed
1270Sstevel@tonic-gate  * to ensure atomic operation for things like MSG_WAITALL.
1280Sstevel@tonic-gate  *
1290Sstevel@tonic-gate  * Note that so_lock is sometimes held across calls that might go to sleep
1300Sstevel@tonic-gate  * (kmem_alloc and soallocproto*). This implies that no other lock in
1310Sstevel@tonic-gate  * the system should be held when calling into sockfs; from the system call
1320Sstevel@tonic-gate  * side or from strrput. If locks are held while calling into sockfs
1330Sstevel@tonic-gate  * the system might hang when running low on memory.
1340Sstevel@tonic-gate  */
1350Sstevel@tonic-gate struct sonode {
1360Sstevel@tonic-gate 	struct	vnode	*so_vnode;	/* vnode associated with this sonode */
1370Sstevel@tonic-gate 
1380Sstevel@tonic-gate 	sonodeops_t	*so_ops;	/* operations vector for this sonode */
1390Sstevel@tonic-gate 
1400Sstevel@tonic-gate 	/*
1410Sstevel@tonic-gate 	 * These fields are initialized once.
1420Sstevel@tonic-gate 	 */
1430Sstevel@tonic-gate 	dev_t		so_dev;		/* device the sonode represents */
1440Sstevel@tonic-gate 	struct	vnode	*so_accessvp;	/* vnode for the /dev entry */
1450Sstevel@tonic-gate 
1460Sstevel@tonic-gate 	/* The locks themselves */
1470Sstevel@tonic-gate 	kmutex_t	so_lock;	/* protects sonode fields */
1480Sstevel@tonic-gate 	kmutex_t	so_plumb_lock;	/* serializes plumbs, and the related */
1490Sstevel@tonic-gate 					/* fields so_version and so_pushcnt */
1500Sstevel@tonic-gate 	kcondvar_t	so_state_cv;	/* synchronize state changes */
1510Sstevel@tonic-gate 	kcondvar_t	so_ack_cv;	/* wait for TPI acks */
1520Sstevel@tonic-gate 	kcondvar_t	so_connind_cv;	/* wait for T_CONN_IND */
1530Sstevel@tonic-gate 	kcondvar_t	so_want_cv;	/* wait due to SOLOCKED */
1540Sstevel@tonic-gate 
1550Sstevel@tonic-gate 	/* These fields are protected by so_lock */
1560Sstevel@tonic-gate 	uint_t	so_state;		/* internal state flags SS_*, below */
1570Sstevel@tonic-gate 	uint_t	so_mode;		/* characteristics on socket. SM_* */
1580Sstevel@tonic-gate 
1590Sstevel@tonic-gate 	mblk_t	*so_ack_mp;		/* TPI ack received from below */
1600Sstevel@tonic-gate 	mblk_t	*so_conn_ind_head;	/* b_next list of T_CONN_IND */
1610Sstevel@tonic-gate 	mblk_t	*so_conn_ind_tail;
1620Sstevel@tonic-gate 	mblk_t	*so_unbind_mp;		/* Preallocated T_UNBIND_REQ message */
1630Sstevel@tonic-gate 
1640Sstevel@tonic-gate 	ushort_t so_flag;		/* flags, see below */
1650Sstevel@tonic-gate 	dev_t	so_fsid;		/* file system identifier */
1660Sstevel@tonic-gate 	time_t  so_atime;		/* time of last access */
1670Sstevel@tonic-gate 	time_t  so_mtime;		/* time of last modification */
1680Sstevel@tonic-gate 	time_t  so_ctime;		/* time of last attributes change */
1690Sstevel@tonic-gate 	int	so_count;		/* count of opened references */
1700Sstevel@tonic-gate 
1710Sstevel@tonic-gate 	/* Needed to recreate the same socket for accept */
1720Sstevel@tonic-gate 	short	so_family;
1730Sstevel@tonic-gate 	short	so_type;
1740Sstevel@tonic-gate 	short	so_protocol;
1750Sstevel@tonic-gate 	short	so_version;		/* From so_socket call */
1760Sstevel@tonic-gate 	short	so_pushcnt;		/* Number of modules above "sockmod" */
1770Sstevel@tonic-gate 
1780Sstevel@tonic-gate 	/* Options */
1790Sstevel@tonic-gate 	short	so_options;		/* From socket call, see socket.h */
1800Sstevel@tonic-gate 	struct linger	so_linger;	/* SO_LINGER value */
1810Sstevel@tonic-gate 	int	so_sndbuf;		/* SO_SNDBUF value */
1820Sstevel@tonic-gate 	int	so_rcvbuf;		/* SO_RCVBUF value */
1830Sstevel@tonic-gate 	int	so_sndlowat;		/* send low water mark */
1840Sstevel@tonic-gate 	int	so_rcvlowat;		/* receive low water mark */
1850Sstevel@tonic-gate #ifdef notyet
1860Sstevel@tonic-gate 	int	so_sndtimeo;		/* Not yet implemented */
1870Sstevel@tonic-gate 	int	so_rcvtimeo;		/* Not yet implemented */
1880Sstevel@tonic-gate #endif /* notyet */
1890Sstevel@tonic-gate 	ushort_t so_error;		/* error affecting connection */
1900Sstevel@tonic-gate 	ushort_t so_delayed_error;	/* From T_uderror_ind */
1910Sstevel@tonic-gate 	int	so_backlog;		/* Listen backlog */
1920Sstevel@tonic-gate 
1930Sstevel@tonic-gate 	/*
1940Sstevel@tonic-gate 	 * The counts (so_oobcnt and so_oobsigcnt) track the number of
1950Sstevel@tonic-gate 	 * urgent indicates that are (logically) queued on the stream head
1960Sstevel@tonic-gate 	 * read queue. The urgent data is queued on the stream head
1970Sstevel@tonic-gate 	 * as follows.
1980Sstevel@tonic-gate 	 *
1990Sstevel@tonic-gate 	 * In the normal case the SIGURG is not generated until
2000Sstevel@tonic-gate 	 * the T_EXDATA_IND arrives at the stream head. However, transports
2010Sstevel@tonic-gate 	 * that have an early indication that urgent data is pending
2020Sstevel@tonic-gate 	 * (e.g. TCP receiving a "new" urgent pointer value) can send up
2030Sstevel@tonic-gate 	 * an M_PCPROTO/SIGURG message to generate the signal early.
2040Sstevel@tonic-gate 	 *
2050Sstevel@tonic-gate 	 * The mark is indicated by either:
2060Sstevel@tonic-gate 	 *  - a T_EXDATA_IND (with no M_DATA b_cont) with MSGMARK set.
2070Sstevel@tonic-gate 	 *    When this message is consumed by sorecvmsg the socket layer
2080Sstevel@tonic-gate 	 *    sets SS_RCVATMARK until data has been consumed past the mark.
2090Sstevel@tonic-gate 	 *  - a message with MSGMARKNEXT set (indicating that the
2100Sstevel@tonic-gate 	 *    first byte of the next message constitutes the mark). When
2110Sstevel@tonic-gate 	 *    the last byte of the MSGMARKNEXT message is consumed in
2120Sstevel@tonic-gate 	 *    the stream head the stream head sets STRATMARK. This flag
2130Sstevel@tonic-gate 	 *    is cleared when at least one byte is read. (Note that
2140Sstevel@tonic-gate 	 *    the MSGMARKNEXT messages can be of zero length when there
2150Sstevel@tonic-gate 	 *    is no previous data to which the marknext can be attached.)
2160Sstevel@tonic-gate 	 *
2170Sstevel@tonic-gate 	 * While the T_EXDATA_IND method is the common case which is used
2180Sstevel@tonic-gate 	 * with all TPI transports, the MSGMARKNEXT method is needed to
2190Sstevel@tonic-gate 	 * indicate the mark when e.g. the TCP urgent byte has not been
2200Sstevel@tonic-gate 	 * received yet but the TCP urgent pointer has made TCP generate
2210Sstevel@tonic-gate 	 * the M_PCSIG/SIGURG.
2220Sstevel@tonic-gate 	 *
2230Sstevel@tonic-gate 	 * The signal (the M_PCSIG carrying the SIGURG) and the mark
2240Sstevel@tonic-gate 	 * indication can not be delivered as a single message, since
2250Sstevel@tonic-gate 	 * the signal should be delivered as high priority and any mark
2260Sstevel@tonic-gate 	 * indication must flow with the data. This implies that immediately
2270Sstevel@tonic-gate 	 * when the SIGURG has been delivered if the stream head queue is
2280Sstevel@tonic-gate 	 * empty it is impossible to determine if this will be the position
2290Sstevel@tonic-gate 	 * of the mark. This race condition is resolved by using MSGNOTMARKNEXT
2300Sstevel@tonic-gate 	 * messages and the STRNOTATMARK flag in the stream head. The
2310Sstevel@tonic-gate 	 * SIOCATMARK code calls the stream head to wait for either a
2320Sstevel@tonic-gate 	 * non-empty queue or one of the STR*ATMARK flags being set.
2330Sstevel@tonic-gate 	 * This implies that any transport that is sending M_PCSIG(SIGURG)
2340Sstevel@tonic-gate 	 * should send the appropriate MSGNOTMARKNEXT message (which can be
2350Sstevel@tonic-gate 	 * zero length) after sending an M_PCSIG to prevent SIOCATMARK
2360Sstevel@tonic-gate 	 * from sleeping unnecessarily.
2370Sstevel@tonic-gate 	 */
2380Sstevel@tonic-gate 	mblk_t	*so_oobmsg;		/* outofline oob data */
2390Sstevel@tonic-gate 	uint_t	so_oobsigcnt;		/* Number of SIGURG generated */
2400Sstevel@tonic-gate 	uint_t	so_oobcnt;		/* Number of T_EXDATA_IND queued */
2410Sstevel@tonic-gate 	pid_t	so_pgrp;		/* pgrp for signals */
2420Sstevel@tonic-gate 
2430Sstevel@tonic-gate 	/* From T_info_ack */
2440Sstevel@tonic-gate 	t_uscalar_t	so_tsdu_size;
2450Sstevel@tonic-gate 	t_uscalar_t	so_etsdu_size;
2460Sstevel@tonic-gate 	t_scalar_t	so_addr_size;
2470Sstevel@tonic-gate 	t_uscalar_t	so_opt_size;
2480Sstevel@tonic-gate 	t_uscalar_t	so_tidu_size;
2490Sstevel@tonic-gate 	t_scalar_t	so_serv_type;
2500Sstevel@tonic-gate 
2510Sstevel@tonic-gate 	/* From T_capability_ack */
2520Sstevel@tonic-gate 	t_uscalar_t	so_acceptor_id;
2530Sstevel@tonic-gate 
2540Sstevel@tonic-gate 	/* Internal provider information */
2550Sstevel@tonic-gate 	struct tpi_provinfo	*so_provinfo;
2560Sstevel@tonic-gate 
2570Sstevel@tonic-gate 	/*
2580Sstevel@tonic-gate 	 * The local and remote addresses have multiple purposes
2590Sstevel@tonic-gate 	 * but one of the key reasons for their existence and careful
2600Sstevel@tonic-gate 	 * tracking in sockfs is to support getsockname and getpeername
2610Sstevel@tonic-gate 	 * when the transport does not handle the TI_GET*NAME ioctls
2625331Samw 	 * and caching when it does (signaled by valid bits in so_state).
2630Sstevel@tonic-gate 	 * When all transports support the new TPI (with T_ADDR_REQ)
2640Sstevel@tonic-gate 	 * we can revisit this code.
2650Sstevel@tonic-gate 	 * The other usage of so_faddr is to keep the "connected to"
2660Sstevel@tonic-gate 	 * address for datagram sockets.
2670Sstevel@tonic-gate 	 * Finally, for AF_UNIX both local and remote addresses are used
2680Sstevel@tonic-gate 	 * to record the sockaddr_un since we use a separate namespace
2690Sstevel@tonic-gate 	 * in the loopback transport.
2700Sstevel@tonic-gate 	 */
2710Sstevel@tonic-gate 	struct soaddr so_laddr;		/* Local address */
2720Sstevel@tonic-gate 	struct soaddr so_faddr;		/* Peer address */
2730Sstevel@tonic-gate #define	so_laddr_sa	so_laddr.soa_sa
2740Sstevel@tonic-gate #define	so_faddr_sa	so_faddr.soa_sa
2750Sstevel@tonic-gate #define	so_laddr_len	so_laddr.soa_len
2760Sstevel@tonic-gate #define	so_faddr_len	so_faddr.soa_len
2770Sstevel@tonic-gate #define	so_laddr_maxlen	so_laddr.soa_maxlen
2780Sstevel@tonic-gate #define	so_faddr_maxlen	so_faddr.soa_maxlen
2790Sstevel@tonic-gate 	mblk_t		*so_eaddr_mp;	/* for so_delayed_error */
2800Sstevel@tonic-gate 
2810Sstevel@tonic-gate 	/*
2820Sstevel@tonic-gate 	 * For AF_UNIX sockets:
2830Sstevel@tonic-gate 	 * so_ux_laddr/faddr records the internal addresses used with the
2840Sstevel@tonic-gate 	 * transport.
2850Sstevel@tonic-gate 	 * so_ux_vp and v_stream->sd_vnode form the cross-
2860Sstevel@tonic-gate 	 * linkage between the underlying fs vnode corresponding to
2870Sstevel@tonic-gate 	 * the bound sockaddr_un and the socket node.
2880Sstevel@tonic-gate 	 */
2890Sstevel@tonic-gate 	struct so_ux_addr so_ux_laddr;	/* laddr bound with the transport */
2900Sstevel@tonic-gate 	struct so_ux_addr so_ux_faddr;	/* temporary peer address */
2910Sstevel@tonic-gate 	struct vnode	*so_ux_bound_vp; /* bound AF_UNIX file system vnode */
2920Sstevel@tonic-gate 	struct sonode	*so_next;	/* next sonode on socklist	*/
2930Sstevel@tonic-gate 	struct sonode	*so_prev;	/* previous sonode on socklist	*/
2940Sstevel@tonic-gate 	mblk_t	*so_discon_ind_mp;	/* T_DISCON_IND received from below */
2950Sstevel@tonic-gate 
2960Sstevel@tonic-gate 					/* put here for delayed processing  */
2970Sstevel@tonic-gate 	void		*so_priv;	/* sonode private data */
2980Sstevel@tonic-gate 	cred_t		*so_peercred;	/* connected socket peer cred */
2990Sstevel@tonic-gate 	pid_t		so_cpid;	/* connected socket peer cached pid */
3000Sstevel@tonic-gate 	zoneid_t	so_zoneid;	/* opener's zoneid */
3010Sstevel@tonic-gate 
3020Sstevel@tonic-gate 	kmem_cache_t	*so_cache;	/* object cache of this "sonode". */
3030Sstevel@tonic-gate 	void		*so_obj;	/* object to free */
3040Sstevel@tonic-gate 
3050Sstevel@tonic-gate 	/*
3060Sstevel@tonic-gate 	 * For NL7C sockets:
3070Sstevel@tonic-gate 	 *
3080Sstevel@tonic-gate 	 * so_nl7c_flags	the NL7C state of URL processing.
3090Sstevel@tonic-gate 	 *
3100Sstevel@tonic-gate 	 * so_nl7c_rcv_mp	mblk_t chain of already received data to be
3110Sstevel@tonic-gate 	 *			passed up to the app after NL7C gives up on
3120Sstevel@tonic-gate 	 *			a socket.
3130Sstevel@tonic-gate 	 *
3140Sstevel@tonic-gate 	 * so_nl7c_rcv_rval	returned rval for last mblk_t from above.
3150Sstevel@tonic-gate 	 *
3160Sstevel@tonic-gate 	 * so_nl7c_uri		the URI currently being processed.
3170Sstevel@tonic-gate 	 *
3180Sstevel@tonic-gate 	 * so_nl7c_rtime	URI request gethrestime_sec().
3191974Sbrutus 	 *
3201974Sbrutus 	 * so_nl7c_addr		pointer returned by nl7c_addr_lookup().
3210Sstevel@tonic-gate 	 */
3220Sstevel@tonic-gate 	uint64_t	so_nl7c_flags;
3230Sstevel@tonic-gate 	mblk_t		*so_nl7c_rcv_mp;
3240Sstevel@tonic-gate 	int64_t		so_nl7c_rcv_rval;
3250Sstevel@tonic-gate 	void		*so_nl7c_uri;
3260Sstevel@tonic-gate 	time_t		so_nl7c_rtime;
3271974Sbrutus 	void		*so_nl7c_addr;
328898Skais 
329898Skais 	/* For sockets acting as an in-kernel SSL proxy */
330898Skais 	kssl_endpt_type_t	so_kssl_type;	/* is proxy/is proxied/none */
331898Skais 	kssl_ent_t		so_kssl_ent;	/* SSL config entry */
332898Skais 	kssl_ctx_t		so_kssl_ctx;	/* SSL session context */
3336707Sbrutus 
3346707Sbrutus 	/* != NULL for sodirect_t enabled socket */
3356707Sbrutus 	sodirect_t	*so_direct;
3360Sstevel@tonic-gate };
3370Sstevel@tonic-gate 
3380Sstevel@tonic-gate /* flags */
3390Sstevel@tonic-gate #define	SOMOD		0x0001		/* update socket modification time */
3400Sstevel@tonic-gate #define	SOACC		0x0002		/* update socket access time */
3410Sstevel@tonic-gate 
3420Sstevel@tonic-gate #define	SOLOCKED	0x0010		/* use to serialize open/closes */
3430Sstevel@tonic-gate #define	SOREADLOCKED	0x0020		/* serialize kstrgetmsg calls */
3440Sstevel@tonic-gate #define	SOWANT		0x0040		/* some process waiting on lock */
3450Sstevel@tonic-gate #define	SOCLONE		0x0080		/* child of clone driver */
3460Sstevel@tonic-gate #define	SOASYNC_UNBIND	0x0100		/* wait for ACK of async unbind */
3470Sstevel@tonic-gate 
3480Sstevel@tonic-gate /*
3490Sstevel@tonic-gate  * Socket state bits.
3500Sstevel@tonic-gate  */
3510Sstevel@tonic-gate #define	SS_ISCONNECTED		0x00000001 /* socket connected to a peer */
3520Sstevel@tonic-gate #define	SS_ISCONNECTING		0x00000002 /* in process, connecting to peer */
3530Sstevel@tonic-gate #define	SS_ISDISCONNECTING	0x00000004 /* in process of disconnecting */
3540Sstevel@tonic-gate #define	SS_CANTSENDMORE		0x00000008 /* can't send more data to peer */
3550Sstevel@tonic-gate 
3560Sstevel@tonic-gate #define	SS_CANTRCVMORE		0x00000010 /* can't receive more data */
3570Sstevel@tonic-gate #define	SS_ISBOUND		0x00000020 /* socket is bound */
3580Sstevel@tonic-gate #define	SS_NDELAY		0x00000040 /* FNDELAY non-blocking */
3590Sstevel@tonic-gate #define	SS_NONBLOCK		0x00000080 /* O_NONBLOCK non-blocking */
3600Sstevel@tonic-gate 
3610Sstevel@tonic-gate #define	SS_ASYNC		0x00000100 /* async i/o notify */
3620Sstevel@tonic-gate #define	SS_ACCEPTCONN		0x00000200 /* listen done */
3630Sstevel@tonic-gate #define	SS_HASCONNIND		0x00000400 /* T_CONN_IND for poll */
3640Sstevel@tonic-gate #define	SS_SAVEDEOR		0x00000800 /* Saved MSG_EOR rcv side state */
3650Sstevel@tonic-gate 
3660Sstevel@tonic-gate #define	SS_RCVATMARK		0x00001000 /* at mark on input */
3670Sstevel@tonic-gate #define	SS_OOBPEND		0x00002000 /* OOB pending or present - poll */
3680Sstevel@tonic-gate #define	SS_HAVEOOBDATA		0x00004000 /* OOB data present */
3690Sstevel@tonic-gate #define	SS_HADOOBDATA		0x00008000 /* OOB data consumed */
3700Sstevel@tonic-gate 
3710Sstevel@tonic-gate #define	SS_FADDR_NOXLATE	0x00020000 /* No xlation of faddr for AF_UNIX */
3720Sstevel@tonic-gate 
3730Sstevel@tonic-gate #define	SS_HASDATA		0x00040000 /* NCAfs: data available */
3740Sstevel@tonic-gate #define	SS_DONEREAD		0x00080000 /* NCAfs: all data read */
3750Sstevel@tonic-gate #define	SS_MOREDATA		0x00100000 /* NCAfs: NCA has more data */
3760Sstevel@tonic-gate 
377741Smasputra #define	SS_DIRECT		0x00200000 /* transport is directly below */
3786707Sbrutus #define	SS_SODIRECT		0x00400000 /* transport supports sodirect */
3790Sstevel@tonic-gate 
3800Sstevel@tonic-gate #define	SS_LADDR_VALID		0x01000000	/* so_laddr valid for user */
3810Sstevel@tonic-gate #define	SS_FADDR_VALID		0x02000000	/* so_faddr valid for user */
3820Sstevel@tonic-gate 
3830Sstevel@tonic-gate /* Set of states when the socket can't be rebound */
3840Sstevel@tonic-gate #define	SS_CANTREBIND	(SS_ISCONNECTED|SS_ISCONNECTING|SS_ISDISCONNECTING|\
3850Sstevel@tonic-gate 			    SS_CANTSENDMORE|SS_CANTRCVMORE|SS_ACCEPTCONN)
3860Sstevel@tonic-gate 
3870Sstevel@tonic-gate /*
3880Sstevel@tonic-gate  * Characteristics of sockets. Not changed after the socket is created.
3890Sstevel@tonic-gate  */
3900Sstevel@tonic-gate #define	SM_PRIV			0x001	/* privileged for broadcast, raw... */
3910Sstevel@tonic-gate #define	SM_ATOMIC		0x002	/* atomic data transmission */
3920Sstevel@tonic-gate #define	SM_ADDR			0x004	/* addresses given with messages */
3930Sstevel@tonic-gate #define	SM_CONNREQUIRED		0x008	/* connection required by protocol */
3940Sstevel@tonic-gate 
3950Sstevel@tonic-gate #define	SM_FDPASSING		0x010	/* passes file descriptors */
3960Sstevel@tonic-gate #define	SM_EXDATA		0x020	/* Can handle T_EXDATA_REQ */
3970Sstevel@tonic-gate #define	SM_OPTDATA		0x040	/* Can handle T_OPTDATA_REQ */
3980Sstevel@tonic-gate #define	SM_BYTESTREAM		0x080	/* Byte stream - can use M_DATA */
3990Sstevel@tonic-gate 
4000Sstevel@tonic-gate #define	SM_ACCEPTOR_ID		0x100	/* so_acceptor_id is valid */
4010Sstevel@tonic-gate 
4020Sstevel@tonic-gate /*
4030Sstevel@tonic-gate  * Socket versions. Used by the socket library when calling _so_socket().
4040Sstevel@tonic-gate  */
4050Sstevel@tonic-gate #define	SOV_STREAM	0	/* Not a socket - just a stream */
4060Sstevel@tonic-gate #define	SOV_DEFAULT	1	/* Select based on so_default_version */
4070Sstevel@tonic-gate #define	SOV_SOCKSTREAM	2	/* Socket plus streams operations */
4080Sstevel@tonic-gate #define	SOV_SOCKBSD	3	/* Socket with no streams operations */
4090Sstevel@tonic-gate #define	SOV_XPG4_2	4	/* Xnet socket */
4100Sstevel@tonic-gate 
4110Sstevel@tonic-gate #if defined(_KERNEL) || defined(_KMEMUSER)
4120Sstevel@tonic-gate /*
4130Sstevel@tonic-gate  * Used for mapping family/type/protocol to vnode.
4140Sstevel@tonic-gate  * Defined here so that crash can use it.
4150Sstevel@tonic-gate  */
4160Sstevel@tonic-gate struct sockparams {
4170Sstevel@tonic-gate 	int	sp_domain;
4180Sstevel@tonic-gate 	int	sp_type;
4190Sstevel@tonic-gate 	int	sp_protocol;
4200Sstevel@tonic-gate 	char	*sp_devpath;
4210Sstevel@tonic-gate 	int	sp_devpathlen;	/* Is 0 if sp_devpath is a static string */
4220Sstevel@tonic-gate 	vnode_t	*sp_vnode;
4230Sstevel@tonic-gate 	struct sockparams *sp_next;
4240Sstevel@tonic-gate };
4250Sstevel@tonic-gate 
4260Sstevel@tonic-gate extern struct sockparams *sphead;
4270Sstevel@tonic-gate 
4280Sstevel@tonic-gate /*
4290Sstevel@tonic-gate  * Used to traverse the list of AF_UNIX sockets to construct the kstat
4300Sstevel@tonic-gate  * for netstat(1m).
4310Sstevel@tonic-gate  */
4320Sstevel@tonic-gate struct socklist {
4330Sstevel@tonic-gate 	kmutex_t	sl_lock;
4340Sstevel@tonic-gate 	struct sonode	*sl_list;
4350Sstevel@tonic-gate };
4360Sstevel@tonic-gate 
4370Sstevel@tonic-gate extern struct socklist socklist;
4380Sstevel@tonic-gate /*
4390Sstevel@tonic-gate  * ss_full_waits is the number of times the reader thread
4400Sstevel@tonic-gate  * waits when the queue is full and ss_empty_waits is the number
4410Sstevel@tonic-gate  * of times the consumer thread waits when the queue is empty.
4420Sstevel@tonic-gate  * No locks for these as they are just indicators of whether
4430Sstevel@tonic-gate  * disk or network or both is slow or fast.
4440Sstevel@tonic-gate  */
4450Sstevel@tonic-gate struct sendfile_stats {
4460Sstevel@tonic-gate 	uint32_t ss_file_cached;
4470Sstevel@tonic-gate 	uint32_t ss_file_not_cached;
4480Sstevel@tonic-gate 	uint32_t ss_full_waits;
4490Sstevel@tonic-gate 	uint32_t ss_empty_waits;
4500Sstevel@tonic-gate 	uint32_t ss_file_segmap;
4510Sstevel@tonic-gate };
4520Sstevel@tonic-gate 
4530Sstevel@tonic-gate /*
4540Sstevel@tonic-gate  * A single sendfile request is represented by snf_req.
4550Sstevel@tonic-gate  */
4560Sstevel@tonic-gate typedef struct snf_req {
4570Sstevel@tonic-gate 	struct snf_req	*sr_next;
4580Sstevel@tonic-gate 	mblk_t		*sr_mp_head;
4590Sstevel@tonic-gate 	mblk_t		*sr_mp_tail;
4600Sstevel@tonic-gate 	kmutex_t	sr_lock;
4610Sstevel@tonic-gate 	kcondvar_t	sr_cv;
4620Sstevel@tonic-gate 	uint_t		sr_qlen;
4630Sstevel@tonic-gate 	int		sr_hiwat;
4640Sstevel@tonic-gate 	int		sr_lowat;
4650Sstevel@tonic-gate 	int		sr_operation;
4660Sstevel@tonic-gate 	struct vnode	*sr_vp;
4670Sstevel@tonic-gate 	file_t 		*sr_fp;
4680Sstevel@tonic-gate 	ssize_t		sr_maxpsz;
4690Sstevel@tonic-gate 	u_offset_t	sr_file_off;
4700Sstevel@tonic-gate 	u_offset_t	sr_file_size;
4710Sstevel@tonic-gate #define	SR_READ_DONE	0x80000000
4720Sstevel@tonic-gate 	int		sr_read_error;
4730Sstevel@tonic-gate 	int		sr_write_error;
4740Sstevel@tonic-gate } snf_req_t;
4750Sstevel@tonic-gate 
4760Sstevel@tonic-gate /* A queue of sendfile requests */
4770Sstevel@tonic-gate struct sendfile_queue {
4780Sstevel@tonic-gate 	snf_req_t	*snfq_req_head;
4790Sstevel@tonic-gate 	snf_req_t	*snfq_req_tail;
4800Sstevel@tonic-gate 	kmutex_t	snfq_lock;
4810Sstevel@tonic-gate 	kcondvar_t	snfq_cv;
4820Sstevel@tonic-gate 	int		snfq_svc_threads;	/* # of service threads */
4830Sstevel@tonic-gate 	int		snfq_idle_cnt;		/* # of idling threads */
4840Sstevel@tonic-gate 	int		snfq_max_threads;
4850Sstevel@tonic-gate 	int		snfq_req_cnt;		/* Number of requests */
4860Sstevel@tonic-gate };
4870Sstevel@tonic-gate 
4880Sstevel@tonic-gate #define	READ_OP			1
4890Sstevel@tonic-gate #define	SNFQ_TIMEOUT		(60 * 5 * hz)	/* 5 minutes */
4900Sstevel@tonic-gate 
4910Sstevel@tonic-gate /* Socket network operations switch */
4920Sstevel@tonic-gate struct sonodeops {
4930Sstevel@tonic-gate 	int	(*sop_accept)(struct sonode *, int, struct sonode **);
4940Sstevel@tonic-gate 	int	(*sop_bind)(struct sonode *, struct sockaddr *, socklen_t,
4950Sstevel@tonic-gate 		    int);
4960Sstevel@tonic-gate 	int	(*sop_listen)(struct sonode *, int);
4970Sstevel@tonic-gate 	int	(*sop_connect)(struct sonode *, const struct sockaddr *,
4980Sstevel@tonic-gate 		    socklen_t, int, int);
4990Sstevel@tonic-gate 	int	(*sop_recvmsg)(struct sonode *, struct msghdr *,
5000Sstevel@tonic-gate 		    struct uio *);
5010Sstevel@tonic-gate 	int	(*sop_sendmsg)(struct sonode *, struct msghdr *,
5020Sstevel@tonic-gate 		    struct uio *);
5030Sstevel@tonic-gate 	int	(*sop_getpeername)(struct sonode *);
5040Sstevel@tonic-gate 	int	(*sop_getsockname)(struct sonode *);
5050Sstevel@tonic-gate 	int	(*sop_shutdown)(struct sonode *, int);
5060Sstevel@tonic-gate 	int	(*sop_getsockopt)(struct sonode *, int, int, void *,
5070Sstevel@tonic-gate 		    socklen_t *, int);
5080Sstevel@tonic-gate 	int 	(*sop_setsockopt)(struct sonode *, int, int, const void *,
5090Sstevel@tonic-gate 		    socklen_t);
5100Sstevel@tonic-gate };
5110Sstevel@tonic-gate 
5120Sstevel@tonic-gate #define	SOP_ACCEPT(so, fflag, nsop)	\
5130Sstevel@tonic-gate 	((so)->so_ops->sop_accept((so), (fflag), (nsop)))
5140Sstevel@tonic-gate #define	SOP_BIND(so, name, namelen, flags)	\
5150Sstevel@tonic-gate 	((so)->so_ops->sop_bind((so), (name), (namelen), (flags)))
5160Sstevel@tonic-gate #define	SOP_LISTEN(so, backlog)	\
5170Sstevel@tonic-gate 	((so)->so_ops->sop_listen((so), (backlog)))
5180Sstevel@tonic-gate #define	SOP_CONNECT(so, name, namelen, fflag, flags)	\
5190Sstevel@tonic-gate 	((so)->so_ops->sop_connect((so), (name), (namelen), (fflag), (flags)))
5200Sstevel@tonic-gate #define	SOP_RECVMSG(so, msg, uiop)	\
5210Sstevel@tonic-gate 	((so)->so_ops->sop_recvmsg((so), (msg), (uiop)))
5220Sstevel@tonic-gate #define	SOP_SENDMSG(so, msg, uiop)	\
5230Sstevel@tonic-gate 	((so)->so_ops->sop_sendmsg((so), (msg), (uiop)))
5240Sstevel@tonic-gate #define	SOP_GETPEERNAME(so)	\
5250Sstevel@tonic-gate 	((so)->so_ops->sop_getpeername((so)))
5260Sstevel@tonic-gate #define	SOP_GETSOCKNAME(so)	\
5270Sstevel@tonic-gate 	((so)->so_ops->sop_getsockname((so)))
5280Sstevel@tonic-gate #define	SOP_SHUTDOWN(so, how)	\
5290Sstevel@tonic-gate 	((so)->so_ops->sop_shutdown((so), (how)))
5300Sstevel@tonic-gate #define	SOP_GETSOCKOPT(so, level, optionname, optval, optlenp, flags)	\
5310Sstevel@tonic-gate 	((so)->so_ops->sop_getsockopt((so), (level), (optionname),	\
5320Sstevel@tonic-gate 	    (optval), (optlenp), (flags)))
5330Sstevel@tonic-gate #define	SOP_SETSOCKOPT(so, level, optionname, optval, optlen)		\
5340Sstevel@tonic-gate 	((so)->so_ops->sop_setsockopt((so), (level), (optionname),	\
5350Sstevel@tonic-gate 	    (optval), (optlen)))
5360Sstevel@tonic-gate 
5370Sstevel@tonic-gate #endif /* defined(_KERNEL) || defined(_KMEMUSER) */
5380Sstevel@tonic-gate 
5390Sstevel@tonic-gate #ifdef _KERNEL
5400Sstevel@tonic-gate 
5410Sstevel@tonic-gate #define	ISALIGNED_cmsghdr(addr) \
5420Sstevel@tonic-gate 		(((uintptr_t)(addr) & (_CMSG_HDR_ALIGNMENT - 1)) == 0)
5430Sstevel@tonic-gate 
5440Sstevel@tonic-gate #define	ROUNDUP_cmsglen(len) \
5450Sstevel@tonic-gate 	(((len) + _CMSG_HDR_ALIGNMENT - 1) & ~(_CMSG_HDR_ALIGNMENT - 1))
5460Sstevel@tonic-gate 
5470Sstevel@tonic-gate /*
5482712Snn35248  * Macros that operate on struct cmsghdr.
5492712Snn35248  * Used in parsing msg_control.
5502712Snn35248  * The CMSG_VALID macro does not assume that the last option buffer is padded.
5510Sstevel@tonic-gate  */
5520Sstevel@tonic-gate #define	CMSG_NEXT(cmsg)						\
5530Sstevel@tonic-gate 	(struct cmsghdr *)((uintptr_t)(cmsg) +			\
5540Sstevel@tonic-gate 	    ROUNDUP_cmsglen((cmsg)->cmsg_len))
5552712Snn35248 #define	CMSG_CONTENT(cmsg)	(&((cmsg)[1]))
5562712Snn35248 #define	CMSG_CONTENTLEN(cmsg)	((cmsg)->cmsg_len - sizeof (struct cmsghdr))
5572712Snn35248 #define	CMSG_VALID(cmsg, start, end)					\
5582712Snn35248 	(ISALIGNED_cmsghdr(cmsg) &&					\
5592712Snn35248 	((uintptr_t)(cmsg) >= (uintptr_t)(start)) &&			\
5602712Snn35248 	((uintptr_t)(cmsg) < (uintptr_t)(end)) &&			\
5612712Snn35248 	((ssize_t)(cmsg)->cmsg_len >= sizeof (struct cmsghdr)) &&	\
5622712Snn35248 	((uintptr_t)(cmsg) + (cmsg)->cmsg_len <= (uintptr_t)(end)))
5630Sstevel@tonic-gate 
5640Sstevel@tonic-gate /*
5650Sstevel@tonic-gate  * Maximum size of any argument that is copied in (addresses, options,
5660Sstevel@tonic-gate  * access rights). MUST be at least MAXPATHLEN + 3.
5670Sstevel@tonic-gate  * BSD and SunOS 4.X limited this to MLEN or MCLBYTES.
5680Sstevel@tonic-gate  */
5690Sstevel@tonic-gate #define	SO_MAXARGSIZE	8192
5700Sstevel@tonic-gate 
5710Sstevel@tonic-gate /*
5720Sstevel@tonic-gate  * Convert between vnode and sonode
5730Sstevel@tonic-gate  */
5740Sstevel@tonic-gate #define	VTOSO(vp)	((struct sonode *)((vp)->v_data))
5750Sstevel@tonic-gate #define	SOTOV(sp)	((sp)->so_vnode)
5760Sstevel@tonic-gate 
5770Sstevel@tonic-gate /*
5780Sstevel@tonic-gate  * Internal flags for sobind()
5790Sstevel@tonic-gate  */
5800Sstevel@tonic-gate #define	_SOBIND_REBIND		0x01	/* Bind to existing local address */
5810Sstevel@tonic-gate #define	_SOBIND_UNSPEC		0x02	/* Bind to unspecified address */
5820Sstevel@tonic-gate #define	_SOBIND_LOCK_HELD	0x04	/* so_excl_lock held by caller */
5830Sstevel@tonic-gate #define	_SOBIND_NOXLATE		0x08	/* No addr translation for AF_UNIX */
5840Sstevel@tonic-gate #define	_SOBIND_XPG4_2		0x10	/* xpg4.2 semantics */
5850Sstevel@tonic-gate #define	_SOBIND_SOCKBSD		0x20	/* BSD semantics */
5860Sstevel@tonic-gate #define	_SOBIND_LISTEN		0x40	/* Make into SS_ACCEPTCONN */
5870Sstevel@tonic-gate #define	_SOBIND_SOCKETPAIR	0x80	/* Internal flag for so_socketpair() */
5880Sstevel@tonic-gate 					/* to enable listen with backlog = 1 */
5890Sstevel@tonic-gate 
5900Sstevel@tonic-gate /*
5910Sstevel@tonic-gate  * Internal flags for sounbind()
5920Sstevel@tonic-gate  */
5930Sstevel@tonic-gate #define	_SOUNBIND_REBIND	0x01	/* Don't clear fields - will rebind */
5940Sstevel@tonic-gate 
5950Sstevel@tonic-gate /*
5960Sstevel@tonic-gate  * Internal flags for soconnect()
5970Sstevel@tonic-gate  */
5980Sstevel@tonic-gate #define	_SOCONNECT_NOXLATE	0x01	/* No addr translation for AF_UNIX */
5990Sstevel@tonic-gate #define	_SOCONNECT_DID_BIND	0x02	/* Unbind when connect fails */
6000Sstevel@tonic-gate #define	_SOCONNECT_XPG4_2	0x04	/* xpg4.2 semantics */
6010Sstevel@tonic-gate 
6020Sstevel@tonic-gate /*
6030Sstevel@tonic-gate  * Internal flags for sodisconnect()
6040Sstevel@tonic-gate  */
6050Sstevel@tonic-gate #define	_SODISCONNECT_LOCK_HELD	0x01	/* so_excl_lock held by caller */
6060Sstevel@tonic-gate 
6070Sstevel@tonic-gate /*
6080Sstevel@tonic-gate  * Internal flags for sotpi_getsockopt().
6090Sstevel@tonic-gate  */
6100Sstevel@tonic-gate #define	_SOGETSOCKOPT_XPG4_2	0x01	/* xpg4.2 semantics */
6110Sstevel@tonic-gate 
6120Sstevel@tonic-gate /*
6130Sstevel@tonic-gate  * Internal flags for soallocproto*()
6140Sstevel@tonic-gate  */
6150Sstevel@tonic-gate #define	_ALLOC_NOSLEEP		0	/* Don't sleep for memory */
6160Sstevel@tonic-gate #define	_ALLOC_INTR		1	/* Sleep until interrupt */
6170Sstevel@tonic-gate #define	_ALLOC_SLEEP		2	/* Sleep forever */
6180Sstevel@tonic-gate 
6190Sstevel@tonic-gate /*
6200Sstevel@tonic-gate  * Internal structure for handling AF_UNIX file descriptor passing
6210Sstevel@tonic-gate  */
6220Sstevel@tonic-gate struct fdbuf {
6230Sstevel@tonic-gate 	int		fd_size;	/* In bytes, for kmem_free */
6240Sstevel@tonic-gate 	int		fd_numfd;	/* Number of elements below */
6250Sstevel@tonic-gate 	char		*fd_ebuf;	/* Extra buffer to free  */
6260Sstevel@tonic-gate 	int		fd_ebuflen;
6270Sstevel@tonic-gate 	frtn_t		fd_frtn;
6280Sstevel@tonic-gate 	struct file	*fd_fds[1];	/* One or more */
6290Sstevel@tonic-gate };
6300Sstevel@tonic-gate #define	FDBUF_HDRSIZE	(sizeof (struct fdbuf) - sizeof (struct file *))
6310Sstevel@tonic-gate 
6320Sstevel@tonic-gate /*
6330Sstevel@tonic-gate  * Variable that can be patched to set what version of socket socket()
6340Sstevel@tonic-gate  * will create.
6350Sstevel@tonic-gate  */
6360Sstevel@tonic-gate extern int so_default_version;
6370Sstevel@tonic-gate 
6380Sstevel@tonic-gate #ifdef DEBUG
6390Sstevel@tonic-gate /* Turn on extra testing capabilities */
6400Sstevel@tonic-gate #define	SOCK_TEST
6410Sstevel@tonic-gate #endif /* DEBUG */
6420Sstevel@tonic-gate 
6430Sstevel@tonic-gate #ifdef DEBUG
6440Sstevel@tonic-gate char	*pr_state(uint_t, uint_t);
6450Sstevel@tonic-gate char	*pr_addr(int, struct sockaddr *, t_uscalar_t);
6460Sstevel@tonic-gate int	so_verify_oobstate(struct sonode *);
6470Sstevel@tonic-gate #endif /* DEBUG */
6480Sstevel@tonic-gate 
6490Sstevel@tonic-gate /*
6500Sstevel@tonic-gate  * DEBUG macros
6510Sstevel@tonic-gate  */
652*7632SNick.Todd@Sun.COM #if defined(DEBUG)
6530Sstevel@tonic-gate #define	SOCK_DEBUG
6540Sstevel@tonic-gate 
6550Sstevel@tonic-gate extern int sockdebug;
6560Sstevel@tonic-gate extern int sockprinterr;
6570Sstevel@tonic-gate 
6580Sstevel@tonic-gate #define	eprint(args)	printf args
6590Sstevel@tonic-gate #define	eprintso(so, args) \
6600Sstevel@tonic-gate { if (sockprinterr && ((so)->so_options & SO_DEBUG)) printf args; }
6610Sstevel@tonic-gate #define	eprintline(error)					\
6620Sstevel@tonic-gate {								\
6630Sstevel@tonic-gate 	if (error != EINTR && (sockprinterr || sockdebug > 0))	\
6640Sstevel@tonic-gate 		printf("socket error %d: line %d file %s\n",	\
6650Sstevel@tonic-gate 			(error), __LINE__, __FILE__);		\
6660Sstevel@tonic-gate }
6670Sstevel@tonic-gate 
6680Sstevel@tonic-gate #define	eprintsoline(so, error)					\
6690Sstevel@tonic-gate { if (sockprinterr && ((so)->so_options & SO_DEBUG))		\
6700Sstevel@tonic-gate 	printf("socket(%p) error %d: line %d file %s\n",	\
671*7632SNick.Todd@Sun.COM 		(void *)(so), (error), __LINE__, __FILE__);	\
6720Sstevel@tonic-gate }
6730Sstevel@tonic-gate #define	dprint(level, args)	{ if (sockdebug > (level)) printf args; }
6740Sstevel@tonic-gate #define	dprintso(so, level, args) \
6750Sstevel@tonic-gate { if (sockdebug > (level) && ((so)->so_options & SO_DEBUG)) printf args; }
6760Sstevel@tonic-gate 
677*7632SNick.Todd@Sun.COM #else /* define(DEBUG) */
6780Sstevel@tonic-gate 
6790Sstevel@tonic-gate #define	eprint(args)		{}
6800Sstevel@tonic-gate #define	eprintso(so, args)	{}
6810Sstevel@tonic-gate #define	eprintline(error)	{}
6820Sstevel@tonic-gate #define	eprintsoline(so, error)	{}
6830Sstevel@tonic-gate #define	dprint(level, args)	{}
6840Sstevel@tonic-gate #define	dprintso(so, level, args) {}
6850Sstevel@tonic-gate 
686*7632SNick.Todd@Sun.COM #endif /* defined(DEBUG) */
6870Sstevel@tonic-gate 
6880Sstevel@tonic-gate extern struct vfsops			sock_vfsops;
6890Sstevel@tonic-gate extern struct vnodeops			*socktpi_vnodeops;
6900Sstevel@tonic-gate extern const struct fs_operation_def	socktpi_vnodeops_template[];
6910Sstevel@tonic-gate 
6920Sstevel@tonic-gate extern sonodeops_t			sotpi_sonodeops;
6930Sstevel@tonic-gate 
6940Sstevel@tonic-gate extern dev_t				sockdev;
6950Sstevel@tonic-gate 
6960Sstevel@tonic-gate /*
6970Sstevel@tonic-gate  * sockfs functions
6980Sstevel@tonic-gate  */
6990Sstevel@tonic-gate extern int	sock_getmsg(vnode_t *, struct strbuf *, struct strbuf *,
7000Sstevel@tonic-gate 			uchar_t *, int *, int, rval_t *);
7010Sstevel@tonic-gate extern int	sock_putmsg(vnode_t *, struct strbuf *, struct strbuf *,
7020Sstevel@tonic-gate 			uchar_t, int, int);
7030Sstevel@tonic-gate struct sonode	*sotpi_create(vnode_t *, int, int, int, int, struct sonode *,
7040Sstevel@tonic-gate 			int *);
7055331Samw extern int	socktpi_open(struct vnode **, int, struct cred *,
7065331Samw 			caller_context_t *);
7070Sstevel@tonic-gate extern int	so_sock2stream(struct sonode *);
7080Sstevel@tonic-gate extern void	so_stream2sock(struct sonode *);
7090Sstevel@tonic-gate extern int	sockinit(int, char *);
7100Sstevel@tonic-gate extern struct vnode
7110Sstevel@tonic-gate 		*makesockvp(struct vnode *, int, int, int);
7120Sstevel@tonic-gate extern void	sockfree(struct sonode *);
7130Sstevel@tonic-gate extern void	so_update_attrs(struct sonode *, int);
7140Sstevel@tonic-gate extern int	soconfig(int, int, int,	char *, int);
7150Sstevel@tonic-gate extern struct vnode
7160Sstevel@tonic-gate 		*solookup(int, int, int, char *, int *);
7170Sstevel@tonic-gate extern void	so_lock_single(struct sonode *);
7180Sstevel@tonic-gate extern void	so_unlock_single(struct sonode *, int);
7190Sstevel@tonic-gate extern int	so_lock_read(struct sonode *, int);
7200Sstevel@tonic-gate extern int	so_lock_read_intr(struct sonode *, int);
7210Sstevel@tonic-gate extern void	so_unlock_read(struct sonode *);
7220Sstevel@tonic-gate extern void	*sogetoff(mblk_t *, t_uscalar_t, t_uscalar_t, uint_t);
7230Sstevel@tonic-gate extern void	so_getopt_srcaddr(void *, t_uscalar_t,
7240Sstevel@tonic-gate 			void **, t_uscalar_t *);
7250Sstevel@tonic-gate extern int	so_getopt_unix_close(void *, t_uscalar_t);
7260Sstevel@tonic-gate extern int	so_addr_verify(struct sonode *, const struct sockaddr *,
7270Sstevel@tonic-gate 			socklen_t);
7280Sstevel@tonic-gate extern int	so_ux_addr_xlate(struct sonode *, struct sockaddr *,
7290Sstevel@tonic-gate 			socklen_t, int, void **, socklen_t *);
7300Sstevel@tonic-gate extern void	fdbuf_free(struct fdbuf *);
7310Sstevel@tonic-gate extern mblk_t	*fdbuf_allocmsg(int, struct fdbuf *);
7320Sstevel@tonic-gate extern int	fdbuf_create(void *, int, struct fdbuf **);
7330Sstevel@tonic-gate extern void	so_closefds(void *, t_uscalar_t, int, int);
7340Sstevel@tonic-gate extern int	so_getfdopt(void *, t_uscalar_t, int, void **, int *);
7350Sstevel@tonic-gate t_uscalar_t	so_optlen(void *, t_uscalar_t, int);
7360Sstevel@tonic-gate extern void	so_cmsg2opt(void *, t_uscalar_t, int, mblk_t *);
7370Sstevel@tonic-gate extern t_uscalar_t
7380Sstevel@tonic-gate 		so_cmsglen(mblk_t *, void *, t_uscalar_t, int);
7390Sstevel@tonic-gate extern int	so_opt2cmsg(mblk_t *, void *, t_uscalar_t, int,
7400Sstevel@tonic-gate 			void *, t_uscalar_t);
7410Sstevel@tonic-gate extern void	soisconnecting(struct sonode *);
7420Sstevel@tonic-gate extern void	soisconnected(struct sonode *);
7430Sstevel@tonic-gate extern void	soisdisconnected(struct sonode *, int);
7440Sstevel@tonic-gate extern void	socantsendmore(struct sonode *);
7450Sstevel@tonic-gate extern void	socantrcvmore(struct sonode *);
7460Sstevel@tonic-gate extern void	soseterror(struct sonode *, int);
7470Sstevel@tonic-gate extern int	sogeterr(struct sonode *);
7480Sstevel@tonic-gate extern int	sogetrderr(vnode_t *, int, int *);
7490Sstevel@tonic-gate extern int	sogetwrerr(vnode_t *, int, int *);
7500Sstevel@tonic-gate extern void	so_unix_close(struct sonode *);
7510Sstevel@tonic-gate extern mblk_t	*soallocproto(size_t, int);
7520Sstevel@tonic-gate extern mblk_t	*soallocproto1(const void *, ssize_t, ssize_t, int);
7530Sstevel@tonic-gate extern void	soappendmsg(mblk_t *, const void *, ssize_t);
7540Sstevel@tonic-gate extern mblk_t	*soallocproto2(const void *, ssize_t, const void *, ssize_t,
7550Sstevel@tonic-gate 			ssize_t, int);
7560Sstevel@tonic-gate extern mblk_t	*soallocproto3(const void *, ssize_t, const void *, ssize_t,
7570Sstevel@tonic-gate 			const void *, ssize_t, ssize_t, int);
7580Sstevel@tonic-gate extern int	sowaitprim(struct sonode *, t_scalar_t, t_scalar_t,
7590Sstevel@tonic-gate 			t_uscalar_t, mblk_t **, clock_t);
7600Sstevel@tonic-gate extern int	sowaitokack(struct sonode *, t_scalar_t);
7610Sstevel@tonic-gate extern int	sowaitack(struct sonode *, mblk_t **, clock_t);
7620Sstevel@tonic-gate extern void	soqueueack(struct sonode *, mblk_t *);
7630Sstevel@tonic-gate extern int	sowaitconnind(struct sonode *, int, mblk_t **);
7640Sstevel@tonic-gate extern void	soqueueconnind(struct sonode *, mblk_t *);
7650Sstevel@tonic-gate extern int	soflushconnind(struct sonode *, t_scalar_t);
7660Sstevel@tonic-gate extern void	so_drain_discon_ind(struct sonode *);
7670Sstevel@tonic-gate extern void	so_flush_discon_ind(struct sonode *);
7680Sstevel@tonic-gate extern int	sowaitconnected(struct sonode *, int, int);
7690Sstevel@tonic-gate 
770741Smasputra extern int	sostream_direct(struct sonode *, struct uio *,
771741Smasputra 		    mblk_t *, cred_t *);
7720Sstevel@tonic-gate extern int	sosend_dgram(struct sonode *, struct sockaddr *,
773741Smasputra 		    socklen_t, struct uio *, int);
7740Sstevel@tonic-gate extern int	sosend_svc(struct sonode *, struct uio *, t_scalar_t, int, int);
7750Sstevel@tonic-gate extern void	so_installhooks(struct sonode *);
7760Sstevel@tonic-gate extern int	so_strinit(struct sonode *, struct sonode *);
7770Sstevel@tonic-gate extern int	sotpi_recvmsg(struct sonode *, struct nmsghdr *,
7780Sstevel@tonic-gate 		    struct uio *);
7790Sstevel@tonic-gate extern int	sotpi_getpeername(struct sonode *);
7800Sstevel@tonic-gate extern int	sotpi_getsockopt(struct sonode *, int, int, void *,
7810Sstevel@tonic-gate 		    socklen_t *, int);
7820Sstevel@tonic-gate extern int	sotpi_setsockopt(struct sonode *, int, int, const void *,
7830Sstevel@tonic-gate 		    socklen_t);
7840Sstevel@tonic-gate extern int	socktpi_ioctl(struct vnode *, int, intptr_t, int,
7855331Samw 		    struct cred *, int *, caller_context_t *);
7860Sstevel@tonic-gate extern int	sodisconnect(struct sonode *, t_scalar_t, int);
7870Sstevel@tonic-gate extern ssize_t	soreadfile(file_t *, uchar_t *, u_offset_t, int *, size_t);
7880Sstevel@tonic-gate extern int	so_set_asyncsigs(vnode_t *, pid_t, int, int, cred_t *);
7890Sstevel@tonic-gate extern int	so_set_events(struct sonode *, vnode_t *, cred_t *);
7900Sstevel@tonic-gate extern int	so_flip_async(struct sonode *, vnode_t *, int, cred_t *);
7910Sstevel@tonic-gate extern int	so_set_siggrp(struct sonode *, vnode_t *, pid_t, int, cred_t *);
7920Sstevel@tonic-gate extern void	*sock_kstat_init(zoneid_t);
7930Sstevel@tonic-gate extern void	sock_kstat_fini(zoneid_t, void *);
7945227Stz204579 extern struct sonode *getsonode(int, int *, file_t **);
7950Sstevel@tonic-gate 
7960Sstevel@tonic-gate /*
7975331Samw  * Function wrappers (mostly around the sonode switch) for
7980Sstevel@tonic-gate  * backward compatibility.
7990Sstevel@tonic-gate  */
8000Sstevel@tonic-gate extern int	soaccept(struct sonode *, int, struct sonode **);
8010Sstevel@tonic-gate extern int	sobind(struct sonode *, struct sockaddr *, socklen_t,
8020Sstevel@tonic-gate 		    int, int);
8030Sstevel@tonic-gate extern int	solisten(struct sonode *, int);
8040Sstevel@tonic-gate extern int	soconnect(struct sonode *, const struct sockaddr *, socklen_t,
8050Sstevel@tonic-gate 		    int, int);
8060Sstevel@tonic-gate extern int	sorecvmsg(struct sonode *, struct nmsghdr *, struct uio *);
8070Sstevel@tonic-gate extern int	sosendmsg(struct sonode *, struct nmsghdr *, struct uio *);
8080Sstevel@tonic-gate extern int	sogetpeername(struct sonode *);
8090Sstevel@tonic-gate extern int	sogetsockname(struct sonode *);
8100Sstevel@tonic-gate extern int	soshutdown(struct sonode *, int);
8110Sstevel@tonic-gate extern int	sogetsockopt(struct sonode *, int, int, void *, socklen_t *,
8120Sstevel@tonic-gate 		    int);
8130Sstevel@tonic-gate extern int	sosetsockopt(struct sonode *, int, int, const void *,
8140Sstevel@tonic-gate 		    t_uscalar_t);
8150Sstevel@tonic-gate 
8160Sstevel@tonic-gate extern struct sonode	*socreate(vnode_t *, int, int, int, int,
8170Sstevel@tonic-gate 			    struct sonode *, int *);
8180Sstevel@tonic-gate 
8190Sstevel@tonic-gate extern int	so_copyin(const void *, void *, size_t, int);
8200Sstevel@tonic-gate extern int	so_copyout(const void *, void *, size_t, int);
8210Sstevel@tonic-gate 
8225331Samw extern int	socktpi_access(struct vnode *, int, int, struct cred *,
8235331Samw 		    caller_context_t *);
8245331Samw extern int	socktpi_fid(struct vnode *, struct fid *, caller_context_t *);
8255331Samw extern int	socktpi_fsync(struct vnode *, int, struct cred *,
8265331Samw 		    caller_context_t *);
8270Sstevel@tonic-gate extern int	socktpi_getattr(struct vnode *, struct vattr *, int,
8285331Samw 		    struct cred *, caller_context_t *);
8295331Samw extern int	socktpi_seek(struct vnode *, offset_t, offset_t *,
8305331Samw 		    caller_context_t *);
8310Sstevel@tonic-gate extern int	socktpi_setattr(struct vnode *, struct vattr *, int,
8320Sstevel@tonic-gate 		    struct cred *, caller_context_t *);
8335331Samw extern int	socktpi_setfl(vnode_t *, int, int, cred_t *,
8345331Samw 		    caller_context_t *);
8350Sstevel@tonic-gate 
8360Sstevel@tonic-gate /* SCTP sockfs */
8370Sstevel@tonic-gate extern struct sonode	*sosctp_create(vnode_t *, int, int, int, int,
8380Sstevel@tonic-gate 			    struct sonode *, int *);
8390Sstevel@tonic-gate extern int sosctp_init(void);
8400Sstevel@tonic-gate 
8413422Snh145002 /* SDP sockfs */
8423422Snh145002 extern struct sonode    *sosdp_create(vnode_t *, int, int, int, int,
8433422Snh145002 			    struct sonode *, int *);
8443422Snh145002 extern int sosdp_init(void);
8453422Snh145002 
8460Sstevel@tonic-gate #endif
8470Sstevel@tonic-gate 
8480Sstevel@tonic-gate /*
8490Sstevel@tonic-gate  * Internal structure for obtaining sonode information from the socklist.
8500Sstevel@tonic-gate  * These types match those corresponding in the sonode structure.
8510Sstevel@tonic-gate  * This is not a published interface, and may change at any time.
8520Sstevel@tonic-gate  */
8530Sstevel@tonic-gate struct sockinfo {
8540Sstevel@tonic-gate 	uint_t		si_size;		/* real length of this struct */
8550Sstevel@tonic-gate 	short		si_family;
8560Sstevel@tonic-gate 	short		si_type;
8570Sstevel@tonic-gate 	ushort_t	si_flag;
8580Sstevel@tonic-gate 	uint_t		si_state;
8590Sstevel@tonic-gate 	uint_t		si_ux_laddr_sou_magic;
8600Sstevel@tonic-gate 	uint_t		si_ux_faddr_sou_magic;
8610Sstevel@tonic-gate 	t_scalar_t	si_serv_type;
8620Sstevel@tonic-gate 	t_uscalar_t	si_laddr_soa_len;
8630Sstevel@tonic-gate 	t_uscalar_t	si_faddr_soa_len;
8640Sstevel@tonic-gate 	uint16_t	si_laddr_family;
8650Sstevel@tonic-gate 	uint16_t	si_faddr_family;
8660Sstevel@tonic-gate 	char		si_laddr_sun_path[MAXPATHLEN + 1]; /* NULL terminated */
8670Sstevel@tonic-gate 	char		si_faddr_sun_path[MAXPATHLEN + 1];
8680Sstevel@tonic-gate 	zoneid_t	si_szoneid;
8690Sstevel@tonic-gate };
8700Sstevel@tonic-gate 
8710Sstevel@tonic-gate 
8720Sstevel@tonic-gate #ifdef	__cplusplus
8730Sstevel@tonic-gate }
8740Sstevel@tonic-gate #endif
8750Sstevel@tonic-gate 
8760Sstevel@tonic-gate #endif	/* _SYS_SOCKETVAR_H */
877