socketvar.h revision 07d13e573541b3558ff2c74bdbb227165aa597a7
2N/A * The contents of this file are subject to the terms of the 2N/A * Common Development and Distribution License (the "License"). 2N/A * You may not use this file except in compliance with the License. 2N/A * See the License for the specific language governing permissions 2N/A * and limitations under the License. 2N/A * When distributing Covered Code, include this CDDL HEADER in each 2N/A * If applicable, add the following below this CDDL HEADER, with the 2N/A * fields enclosed by brackets "[]" replaced with your own identifying 2N/A * information: Portions Copyright [yyyy] [name of copyright owner] 2N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 2N/A * Use is subject to license terms. 2N/A/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 2N/A/* All Rights Reserved */ 2N/A * University Copyright- Copyright (c) 1982, 1986, 1988 2N/A * The Regents of the University of California 2N/A * All Rights Reserved 2N/A * University Acknowledgment- Portions of this document are derived from 2N/A * software developed by the University of California, Berkeley, and its 2N/A * Internal representation of the address used to represent addresses * in the loopback transport for AF_UNIX. While the sockaddr_un is used * as the sockfs layer address for AF_UNIX the pathnames contained in * these addresses are not unique (due to relative pathnames) thus can not * be used in the transport. * The transport level address consists of a magic number (used to separate the * name space for specific and implicit binds). For a specific bind * this is followed by a "vnode *" which ensures that all specific binds * have a unique transport level address. For implicit binds the latter * part of the address is a byte string (of the same length as a pointer) * that is assigned by the loopback transport. * The uniqueness assumes that the loopback transport has a separate namespace * for sockets in order to avoid name conflicts with e.g. TLI use of the void *
soua_vp;
/* vnode pointer or assigned by tl */ * The sonode represents a socket. A sonode never exist in the file system * name space and can not be opened using open() - only the socket, socketpair * and accept calls create sonodes. * The locking of sockfs uses the so_lock mutex plus the SOLOCKED and * SOREADLOCKED flags in so_flag. The mutex protects all the state in the * sonode. It is expected that the underlying transport protocol serializes * socket operations, so sockfs will not normally not single-thread * operations. However, certain sockets, including TPI based ones, can only * handle one control operation at a time. The SOLOCKED flag is used to * single-thread operations from sockfs users to prevent e.g. multiple bind() * calls to operate on the same sonode concurrently. The SOREADLOCKED flag is * used to ensure that only one thread sleeps in kstrgetmsg for a given * sonode. This is needed to ensure atomic operation for things like * The so_fallback_rwlock is used to ensure that for sockets that can * fall back to TPI, the fallback is not initiated until all pending * operations have completed. * Note that so_lock is sometimes held across calls that might go to sleep * (kmem_alloc and soallocproto*). This implies that no other lock in * the system should be held when calling into sockfs; from the system call * side or from strrput (in case of TPI based sockets). If locks are held * while calling into sockfs the system might hang when running low on memory. void *
so_priv;
/* sonode private data */ /* These fields are protected by so_lock */ int so_count;
/* count of opened references */ /* Needed to recreate the same socket for accept */ short so_pollev;
/* events that should be generated */ so_not_str:
1,
/* B_TRUE if not streams based socket */ /* Communication channel with protocol */ /* != NULL for sodirect_t enabled socket */ * We do an initial check for events without holding locks. However, * if there are no event available, then we redo the check for POLLIN * Events handled by the protocol (in case sd_poll is set) #
endif /* _KERNEL || _KMEMUSER */#
define SOMOD 0x0001 /* update socket modification time */#
define SOACC 0x0002 /* update socket access time */#
define SOREADLOCKED 0x0020 /* serialize kstrgetmsg calls */#
define SOWANT 0x0040 /* some process waiting on lock */#
define SOCLONE 0x0080 /* child of clone driver */#
define SS_ISBOUND 0x00000020 /* socket is bound */#
define SS_NDELAY 0x00000040 /* FNDELAY non-blocking */#
define SS_NONBLOCK 0x00000080 /* O_NONBLOCK non-blocking */#
define SS_ASYNC 0x00000100 /* async i/o notify *//* unused 0x00000400 */ /* was SS_HASCONNIND */ #
define SS_SAVEDEOR 0x00000800 /* Saved MSG_EOR rcv side state */#
define SS_OOBPEND 0x00002000 /* OOB pending or present - poll */#
define SS_CLOSING 0x00010000 /* in process of closing *//* unused 0x00020000 */ /* was SS_FADDR_NOXLATE */ /* unused 0x00040000 */ /* was SS_HASDATA */ /* unused 0x00080000 */ /* was SS_DONEREAD */ /* unused 0x00100000 */ /* was SS_MOREDATA */ /* unused 0x00200000 */ /* was SS_DIRECT */ #
define SS_SODIRECT 0x00400000 /* transport supports sodirect *//* unused 0x01000000 */ /* was SS_LADDR_VALID */ /* unused 0x02000000 */ /* was SS_FADDR_VALID */ /* Set of states when the socket can't be rebound */ * Sockets that can fall back to TPI must ensure that fall back is not * initiated while a thread is using a socket. * Characteristics of sockets. Not changed after the socket is created. #
define SM_PRIV 0x001 /* privileged for broadcast, raw... */#
define SM_ATOMIC 0x002 /* atomic data transmission */#
define SM_ADDR 0x004 /* addresses given with messages */#
define SM_EXDATA 0x020 /* Can handle T_EXDATA_REQ */#
define SM_OPTDATA 0x040 /* Can handle T_OPTDATA_REQ *//* The modes below are only for non-streams sockets */ * Socket versions. Used by the socket library when calling _so_socket(). #
define SOV_STREAM 0
/* Not a socket - just a stream */#
define SOV_DEFAULT 1 /* Select based on so_default_version */#
define SOV_SOCKBSD 3 /* Socket with no streams operations */ * sonode create and destroy functions. int,
int,
int,
int,
int,
int *,
cred_t *);
/* STREAM device information */ /* name of the TPI pseudo socket module */ * Socket module register information /* __smod_priv_data must be NULL */ * Socket module information * The family, type, protocol, sdev_info and smod_info are * set when the entry is created, and they will never change * The entries below are only modified while holding * splist_lock as a writer. const char *,
int,
int *);
const char *,
int,
int *);
/* Increase the smod_info_t reference count */ * Decreace the socket module entry reference count. * When no one mapping to the entry, we try to unload the module from the * kernel. If the module can't unload, just leave the module entry with * No need to atomically check the return value because the \ * socket module framework will verify that no one is using \ * the module before unloading. Worst thing that can happen \ * here is multiple calls to mod_remove_by_name(), which is OK. \ /* Increase the reference count */ * Decrease the reference count. * If the sockparams is ephemeral, then the thread dropping the last ref * count will destroy the entry. * Used to traverse the list of AF_UNIX sockets to construct the kstat * ss_full_waits is the number of times the reader thread * waits when the queue is full and ss_empty_waits is the number * of times the consumer thread waits when the queue is empty. * No locks for these as they are just indicators of whether * disk or network or both is slow or fast. * A single sendfile request is represented by snf_req. /* A queue of sendfile requests */ /* Socket network operations switch */ #
endif /* defined(_KERNEL) || defined(_KMEMUSER) */ * Macros that operate on struct cmsghdr. * Used in parsing msg_control. * The CMSG_VALID macro does not assume that the last option buffer is padded. * Maximum size of any argument that is copied in (addresses, options, * access rights). MUST be at least MAXPATHLEN + 3. * BSD and SunOS 4.X limited this to MLEN or MCLBYTES. * Convert between vnode and sonode * Internal flags for sobind() /* to enable listen with backlog = 1 */ * Internal flags for sounbind() * Internal flags for soconnect() * Internal flags for sodisconnect() * Internal flags for sotpi_getsockopt(). * Internal flags for soallocproto*() * Internal structure for handling AF_UNIX file descriptor passing int fd_size;
/* In bytes, for kmem_free */ int fd_numfd;
/* Number of elements below */ char *
fd_ebuf;
/* Extra buffer to free */ * Variable that can be patched to set what version of socket socket() /* Turn on extra testing capabilities */ printf(
"socket error %d: line %d file %s\n", \
printf(
"socket(%p) error %d: line %d file %s\n", \
#
else /* define(DEBUG) */#
endif /* defined(DEBUG) */extern int soconfig(
int,
int,
int,
char *,
int,
char *);
* Function wrappers (mostly around the sonode switch) for * backward compatibility. * Internal structure for obtaining sonode information from the socklist. * These types match those corresponding in the sonode structure. * This is not a published interface, and may change at any time. #
define SOCKMOD_PATH "socketmod" /* dir where sockmods are stored */#
endif /* _SYS_SOCKETVAR_H */