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