socketvar.h revision 6a571a2dc9fd3dada6de18b4c74cc8dcfca99eda
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* University Copyright- Copyright (c) 1982, 1986, 1988
* The Regents of the University of California
* All Rights Reserved
*
* University Acknowledgment- Portions of this document are derived from
* software developed by the University of California, Berkeley, and its
* contributors.
*/
#ifndef _SYS_SOCKETVAR_H
#define _SYS_SOCKETVAR_H
#ifdef _KERNEL
#include <sys/vfs_opreg.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
/*
* 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
* same transport.
*/
struct so_ux_addr {
void *soua_vp; /* vnode pointer or assigned by tl */
};
struct sockaddr_ux {
struct so_ux_addr sou_addr;
};
#include <sys/socket_proto.h>
typedef struct sonodeops sonodeops_t;
struct sodirect_s;
/*
* 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
* MSG_WAITALL.
*
* 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.
*/
struct sonode {
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_family;
short so_type;
short so_protocol;
short so_version; /* From so_socket call */
/* Accept queue */
struct sonode *so_acceptq_head;
struct sonode **so_acceptq_tail;
unsigned int so_acceptq_len;
unsigned int so_backlog; /* Listen backlog */
/* Options */
short so_options; /* From socket call, see socket.h */
int so_xpg_rcvbuf; /* SO_RCVBUF value for XPG4 socket */
short so_pollev; /* events that should be generated */
/* Receive */
unsigned int so_rcv_queued; /* # bytes on both rcv lists */
so_rcv_wakeup: 1,
so_snd_wakeup: 1,
so_pad_to_bit_31: 28;
/* Communication channel with protocol */
/* kernel sockets */
void *so_ksock_cb_arg; /* callback argument */
/* != NULL for sodirect enabled socket */
struct sodirect_s *so_direct;
};
#define SO_HAVE_DATA(so) \
/* \
* For the (tid == 0) case we must check so_rcv_{q_,}head \
* rather than (so_rcv_queued > 0), since the latter does not \
*/ \
/*
* Events handled by the protocol (in case sd_poll is set)
*/
#endif /* _KERNEL || _KMEMUSER */
/* flags */
/*
* Socket state bits.
*/
/* unused 0x00000400 */ /* was SS_HASCONNIND */
/* 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 */
/* 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.
*/
return (fn); \
} \
}
#define SO_UNBLOCK_FALLBACK(so) { \
}
/* Poll events */
/*
* Characteristics of sockets. Not changed after the socket is created.
*/
/* 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 */
/*
* sonode create and destroy functions.
*/
int, int, int, int, int, int *, cred_t *);
typedef void (*so_destroy_func_t)(struct sonode *);
/* STREAM device information */
typedef struct sdev_info {
char *sd_devpath;
int sd_devpathlen; /* Is 0 if sp_devpath is a static string */
} sdev_info_t;
#define SOCKMOD_VERSION 1
/* name of the TPI pseudo socket module */
#define SOTPI_SMOD_NAME "socktpi"
typedef struct __smod_priv_s {
/*
* Socket module register information
*/
typedef struct smod_reg_s {
int smod_version;
char *smod_name;
/* __smod_priv_data must be NULL */
} smod_reg_t;
/*
* Socket module information
*/
typedef struct smod_info {
int smod_version;
char *smod_name;
} smod_info_t;
typedef struct sockparams_stats {
/*
* sockparams
*
*/
struct sockparams {
/*
* The family, type, protocol, sdev_info and smod_info are
* set when the entry is created, and they will never change
* thereafter.
*/
int sp_family;
int sp_type;
int sp_protocol;
char *sp_smod_name; /* socket module name */
/*
* The entries below are only modified while holding
* splist_lock as a writer.
*/
int sp_flags; /* see below */
};
/*
* sockparams flags
*/
extern void sockparams_init(void);
extern struct sockparams *sockparams_hold_ephemeral_bydev(int, int, int,
const char *, int, int *);
extern struct sockparams *sockparams_hold_ephemeral_bymod(int, int, int,
const char *, int, int *);
extern void sockparams_ephemeral_drop_last_ref(struct sockparams *);
extern void smod_init(void);
extern void smod_add(smod_info_t *);
extern int smod_register(const smod_reg_t *);
extern int smod_unregister(const char *);
extern smod_info_t *smod_lookup_byname(const char *);
#define SOCKPARAMS_HAS_DEVICE(sp) \
/* Increase the smod_info_t reference count */
#define SMOD_INC_REF(smodp) { \
}
/*
* 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
* a zero refcnt.
*/
/* \
* 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. \
*/ \
if ((smodp)->smod_refcnt == 0) \
}
/* Increase the reference count */
#define SOCKPARAMS_INC_REF(sp) { \
}
/*
* Decrease the reference count.
*
* If the sockparams is ephemeral, then the thread dropping the last ref
* count will destroy the entry.
*/
#define SOCKPARAMS_DEC_REF(sp) { \
} else { \
} \
} else { \
} \
}
/*
* Used to traverse the list of AF_UNIX sockets to construct the kstat
* for netstat(1m).
*/
struct socklist {
};
/*
* 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.
*/
struct sendfile_stats {
};
/*
* A single sendfile request is represented by snf_req.
*/
typedef struct snf_req {
int sr_hiwat;
int sr_lowat;
int sr_operation;
#define SR_READ_DONE 0x80000000
int sr_read_error;
int sr_write_error;
} snf_req_t;
/* A queue of sendfile requests */
struct sendfile_queue {
int snfq_svc_threads; /* # of service threads */
int snfq_idle_cnt; /* # of idling threads */
int snfq_max_threads;
int snfq_req_cnt; /* Number of requests */
};
#define READ_OP 1
/* Socket network operations switch */
struct sonodeops {
int);
int, cred_t *);
int (*sop_getsockopt)(struct sonode *, int, int, void *,
int (*sop_setsockopt)(struct sonode *, int, int, const void *,
struct pollhead **);
};
(cr)))
#endif /* defined(_KERNEL) || defined(_KMEMUSER) */
#ifdef _KERNEL
#define ISALIGNED_cmsghdr(addr) \
#define ROUNDUP_cmsglen(len) \
#define IS_NON_STREAM_SOCK(vp) \
/*
* 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.
*/
(ISALIGNED_cmsghdr(cmsg) && \
/*
* 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.
*/
#define SO_MAXARGSIZE 8192
/*
* 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*()
*/
#define _ALLOC_NOSLEEP 0 /* Don't sleep for memory */
/*
* Internal structure for handling AF_UNIX file descriptor passing
*/
struct fdbuf {
int fd_size; /* In bytes, for kmem_free */
int fd_numfd; /* Number of elements below */
char *fd_ebuf; /* Extra buffer to free */
int fd_ebuflen;
};
/*
* Variable that can be patched to set what version of socket socket()
* will create.
*/
extern int so_default_version;
#ifdef DEBUG
/* Turn on extra testing capabilities */
#define SOCK_TEST
#endif /* DEBUG */
#ifdef DEBUG
int so_verify_oobstate(struct sonode *);
#endif /* DEBUG */
/*
* DEBUG macros
*/
#if defined(DEBUG)
#define SOCK_DEBUG
extern int sockdebug;
extern int sockprinterr;
#define eprintline(error) \
{ \
printf("socket error %d: line %d file %s\n", \
}
printf("socket(%p) error %d: line %d file %s\n", \
}
#else /* define(DEBUG) */
#define eprintline(error) {}
#endif /* defined(DEBUG) */
extern struct vfsops sock_vfsops;
extern struct vnodeops *socket_vnodeops;
extern const struct fs_operation_def socket_vnodeops_template[];
/*
* sockfs functions
*/
uchar_t, int, int);
extern int sockinit(int, char *);
extern int soconfig(int, int, int, char *, int, char *);
extern int solookup(int, int, int, struct sockparams **);
extern void so_lock_single(struct sonode *);
extern void so_unlock_single(struct sonode *, int);
extern int so_lock_read(struct sonode *, int);
extern int so_lock_read_intr(struct sonode *, int);
extern void so_unlock_read(struct sonode *);
extern void so_getopt_srcaddr(void *, t_uscalar_t,
void **, t_uscalar_t *);
extern int so_getopt_unix_close(void *, t_uscalar_t);
extern void fdbuf_free(struct fdbuf *);
extern int fdbuf_create(void *, int, struct fdbuf **);
extern void so_closefds(void *, t_uscalar_t, int, int);
extern int so_getfdopt(void *, t_uscalar_t, int, void **, int *);
extern t_uscalar_t
void *, t_uscalar_t);
extern void soisconnecting(struct sonode *);
extern void soisconnected(struct sonode *);
extern void soisdisconnected(struct sonode *, int);
extern void socantsendmore(struct sonode *);
extern void socantrcvmore(struct sonode *);
extern void soseterror(struct sonode *, int);
extern int sowaitconnected(struct sonode *, int, int);
extern void *sock_kstat_init(zoneid_t);
extern void sock_kstat_fini(zoneid_t, void *);
/*
* Function wrappers (mostly around the sonode switch) for
* backward compatibility.
*/
int, int);
int, int);
extern int soshutdown(struct sonode *, int);
int);
extern int sosetsockopt(struct sonode *, int, int, const void *,
int *);
extern int so_copyout(const void *, void *, size_t, int);
#endif
/*
* 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.
*/
struct sockinfo {
short si_family;
short si_type;
};
#ifdef __cplusplus
}
#endif
#endif /* _SYS_SOCKETVAR_H */