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 /* 2312257SAnders.Persson@Sun.COM * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 270Sstevel@tonic-gate /* All Rights Reserved */ 280Sstevel@tonic-gate 290Sstevel@tonic-gate /* 300Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 310Sstevel@tonic-gate * The Regents of the University of California 320Sstevel@tonic-gate * All Rights Reserved 330Sstevel@tonic-gate * 340Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 350Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 360Sstevel@tonic-gate * contributors. 370Sstevel@tonic-gate */ 380Sstevel@tonic-gate 390Sstevel@tonic-gate #ifndef _SYS_SOCKETVAR_H 400Sstevel@tonic-gate #define _SYS_SOCKETVAR_H 410Sstevel@tonic-gate 420Sstevel@tonic-gate #include <sys/types.h> 430Sstevel@tonic-gate #include <sys/stream.h> 440Sstevel@tonic-gate #include <sys/t_lock.h> 450Sstevel@tonic-gate #include <sys/cred.h> 460Sstevel@tonic-gate #include <sys/vnode.h> 470Sstevel@tonic-gate #include <sys/file.h> 480Sstevel@tonic-gate #include <sys/param.h> 490Sstevel@tonic-gate #include <sys/zone.h> 508348SEric.Yu@Sun.COM #include <sys/sdt.h> 518348SEric.Yu@Sun.COM #include <sys/modctl.h> 528348SEric.Yu@Sun.COM #include <sys/atomic.h> 538348SEric.Yu@Sun.COM #include <sys/socket.h> 548348SEric.Yu@Sun.COM #include <sys/ksocket.h> 558964SAnders.Persson@Sun.COM #include <sys/kstat.h> 560Sstevel@tonic-gate 579694SScott.Rotondo@Sun.COM #ifdef _KERNEL 589694SScott.Rotondo@Sun.COM #include <sys/vfs_opreg.h> 599694SScott.Rotondo@Sun.COM #endif 609694SScott.Rotondo@Sun.COM 610Sstevel@tonic-gate #ifdef __cplusplus 620Sstevel@tonic-gate extern "C" { 630Sstevel@tonic-gate #endif 640Sstevel@tonic-gate 650Sstevel@tonic-gate /* 660Sstevel@tonic-gate * Internal representation of the address used to represent addresses 670Sstevel@tonic-gate * in the loopback transport for AF_UNIX. While the sockaddr_un is used 680Sstevel@tonic-gate * as the sockfs layer address for AF_UNIX the pathnames contained in 690Sstevel@tonic-gate * these addresses are not unique (due to relative pathnames) thus can not 700Sstevel@tonic-gate * be used in the transport. 710Sstevel@tonic-gate * 720Sstevel@tonic-gate * The transport level address consists of a magic number (used to separate the 730Sstevel@tonic-gate * name space for specific and implicit binds). For a specific bind 740Sstevel@tonic-gate * this is followed by a "vnode *" which ensures that all specific binds 750Sstevel@tonic-gate * have a unique transport level address. For implicit binds the latter 760Sstevel@tonic-gate * part of the address is a byte string (of the same length as a pointer) 770Sstevel@tonic-gate * that is assigned by the loopback transport. 780Sstevel@tonic-gate * 790Sstevel@tonic-gate * The uniqueness assumes that the loopback transport has a separate namespace 800Sstevel@tonic-gate * for sockets in order to avoid name conflicts with e.g. TLI use of the 810Sstevel@tonic-gate * same transport. 820Sstevel@tonic-gate */ 830Sstevel@tonic-gate struct so_ux_addr { 840Sstevel@tonic-gate void *soua_vp; /* vnode pointer or assigned by tl */ 850Sstevel@tonic-gate uint_t soua_magic; /* See below */ 860Sstevel@tonic-gate }; 870Sstevel@tonic-gate 880Sstevel@tonic-gate #define SOU_MAGIC_EXPLICIT 0x75787670 /* "uxvp" */ 890Sstevel@tonic-gate #define SOU_MAGIC_IMPLICIT 0x616e6f6e /* "anon" */ 900Sstevel@tonic-gate 910Sstevel@tonic-gate struct sockaddr_ux { 920Sstevel@tonic-gate sa_family_t sou_family; /* AF_UNIX */ 930Sstevel@tonic-gate struct so_ux_addr sou_addr; 940Sstevel@tonic-gate }; 950Sstevel@tonic-gate 968348SEric.Yu@Sun.COM #if defined(_KERNEL) || defined(_KMEMUSER) 978348SEric.Yu@Sun.COM 988348SEric.Yu@Sun.COM #include <sys/socket_proto.h> 998348SEric.Yu@Sun.COM 1000Sstevel@tonic-gate typedef struct sonodeops sonodeops_t; 101741Smasputra typedef struct sonode sonode_t; 1020Sstevel@tonic-gate 1039491SAnders.Persson@Sun.COM struct sodirect_s; 1049491SAnders.Persson@Sun.COM 1050Sstevel@tonic-gate /* 1060Sstevel@tonic-gate * The sonode represents a socket. A sonode never exist in the file system 1070Sstevel@tonic-gate * name space and can not be opened using open() - only the socket, socketpair 1080Sstevel@tonic-gate * and accept calls create sonodes. 1090Sstevel@tonic-gate * 1108348SEric.Yu@Sun.COM * The locking of sockfs uses the so_lock mutex plus the SOLOCKED and 1118348SEric.Yu@Sun.COM * SOREADLOCKED flags in so_flag. The mutex protects all the state in the 1128348SEric.Yu@Sun.COM * sonode. It is expected that the underlying transport protocol serializes 1138348SEric.Yu@Sun.COM * socket operations, so sockfs will not normally not single-thread 1148348SEric.Yu@Sun.COM * operations. However, certain sockets, including TPI based ones, can only 1158348SEric.Yu@Sun.COM * handle one control operation at a time. The SOLOCKED flag is used to 1168348SEric.Yu@Sun.COM * single-thread operations from sockfs users to prevent e.g. multiple bind() 1178348SEric.Yu@Sun.COM * calls to operate on the same sonode concurrently. The SOREADLOCKED flag is 1188348SEric.Yu@Sun.COM * used to ensure that only one thread sleeps in kstrgetmsg for a given 1198348SEric.Yu@Sun.COM * sonode. This is needed to ensure atomic operation for things like 1208348SEric.Yu@Sun.COM * MSG_WAITALL. 1210Sstevel@tonic-gate * 1228348SEric.Yu@Sun.COM * The so_fallback_rwlock is used to ensure that for sockets that can 1238348SEric.Yu@Sun.COM * fall back to TPI, the fallback is not initiated until all pending 1248348SEric.Yu@Sun.COM * operations have completed. 1250Sstevel@tonic-gate * 1260Sstevel@tonic-gate * Note that so_lock is sometimes held across calls that might go to sleep 1270Sstevel@tonic-gate * (kmem_alloc and soallocproto*). This implies that no other lock in 1280Sstevel@tonic-gate * the system should be held when calling into sockfs; from the system call 1298348SEric.Yu@Sun.COM * side or from strrput (in case of TPI based sockets). If locks are held 1308348SEric.Yu@Sun.COM * while calling into sockfs the system might hang when running low on memory. 1310Sstevel@tonic-gate */ 1320Sstevel@tonic-gate struct sonode { 1330Sstevel@tonic-gate struct vnode *so_vnode; /* vnode associated with this sonode */ 1340Sstevel@tonic-gate 1358348SEric.Yu@Sun.COM sonodeops_t *so_ops; /* operations vector for this sonode */ 1368348SEric.Yu@Sun.COM void *so_priv; /* sonode private data */ 1370Sstevel@tonic-gate 1388348SEric.Yu@Sun.COM krwlock_t so_fallback_rwlock; 1390Sstevel@tonic-gate kmutex_t so_lock; /* protects sonode fields */ 1408348SEric.Yu@Sun.COM 1410Sstevel@tonic-gate kcondvar_t so_state_cv; /* synchronize state changes */ 14211521SAnders.Persson@Sun.COM kcondvar_t so_single_cv; /* wait due to SOLOCKED */ 14311521SAnders.Persson@Sun.COM kcondvar_t so_read_cv; /* wait due to SOREADLOCKED */ 1440Sstevel@tonic-gate 1450Sstevel@tonic-gate /* These fields are protected by so_lock */ 1460Sstevel@tonic-gate 1478348SEric.Yu@Sun.COM uint_t so_state; /* internal state flags SS_*, below */ 1488348SEric.Yu@Sun.COM uint_t so_mode; /* characteristics on socket. SM_* */ 1498348SEric.Yu@Sun.COM ushort_t so_flag; /* flags, see below */ 1508348SEric.Yu@Sun.COM int so_count; /* count of opened references */ 1510Sstevel@tonic-gate 1528348SEric.Yu@Sun.COM sock_connid_t so_proto_connid; /* protocol generation number */ 1530Sstevel@tonic-gate 1548348SEric.Yu@Sun.COM ushort_t so_error; /* error affecting connection */ 1558348SEric.Yu@Sun.COM 1568348SEric.Yu@Sun.COM struct sockparams *so_sockparams; /* vnode or socket module */ 1570Sstevel@tonic-gate /* Needed to recreate the same socket for accept */ 1580Sstevel@tonic-gate short so_family; 1590Sstevel@tonic-gate short so_type; 1600Sstevel@tonic-gate short so_protocol; 1610Sstevel@tonic-gate short so_version; /* From so_socket call */ 1628348SEric.Yu@Sun.COM 1638348SEric.Yu@Sun.COM /* Accept queue */ 1648348SEric.Yu@Sun.COM kmutex_t so_acceptq_lock; /* protects accept queue */ 16512643SAnders.Persson@Sun.COM list_t so_acceptq_list; /* pending conns */ 16612643SAnders.Persson@Sun.COM list_t so_acceptq_defer; /* deferred conns */ 16712643SAnders.Persson@Sun.COM list_node_t so_acceptq_node; /* acceptq list node */ 16812643SAnders.Persson@Sun.COM unsigned int so_acceptq_len; /* # of conns (both lists) */ 1698348SEric.Yu@Sun.COM unsigned int so_backlog; /* Listen backlog */ 1708348SEric.Yu@Sun.COM kcondvar_t so_acceptq_cv; /* wait for new conn. */ 17112643SAnders.Persson@Sun.COM struct sonode *so_listener; /* parent socket */ 1720Sstevel@tonic-gate 1730Sstevel@tonic-gate /* Options */ 1740Sstevel@tonic-gate short so_options; /* From socket call, see socket.h */ 1750Sstevel@tonic-gate struct linger so_linger; /* SO_LINGER value */ 1768348SEric.Yu@Sun.COM #define so_sndbuf so_proto_props.sopp_txhiwat /* SO_SNDBUF value */ 1778348SEric.Yu@Sun.COM #define so_sndlowat so_proto_props.sopp_txlowat /* tx low water mark */ 1788348SEric.Yu@Sun.COM #define so_rcvbuf so_proto_props.sopp_rxhiwat /* SO_RCVBUF value */ 1798348SEric.Yu@Sun.COM #define so_rcvlowat so_proto_props.sopp_rxlowat /* rx low water mark */ 1808348SEric.Yu@Sun.COM #define so_max_addr_len so_proto_props.sopp_maxaddrlen 1818348SEric.Yu@Sun.COM #define so_minpsz so_proto_props.sopp_minpsz 1828348SEric.Yu@Sun.COM #define so_maxpsz so_proto_props.sopp_maxpsz 1830Sstevel@tonic-gate 1848465SEric.Yu@Sun.COM int so_xpg_rcvbuf; /* SO_RCVBUF value for XPG4 socket */ 1858348SEric.Yu@Sun.COM clock_t so_sndtimeo; /* send timeout */ 1868348SEric.Yu@Sun.COM clock_t so_rcvtimeo; /* recv timeout */ 1878348SEric.Yu@Sun.COM 1880Sstevel@tonic-gate mblk_t *so_oobmsg; /* outofline oob data */ 1898348SEric.Yu@Sun.COM ssize_t so_oobmark; /* offset of the oob data */ 1908348SEric.Yu@Sun.COM 1910Sstevel@tonic-gate pid_t so_pgrp; /* pgrp for signals */ 1920Sstevel@tonic-gate 1930Sstevel@tonic-gate cred_t *so_peercred; /* connected socket peer cred */ 1940Sstevel@tonic-gate pid_t so_cpid; /* connected socket peer cached pid */ 1950Sstevel@tonic-gate zoneid_t so_zoneid; /* opener's zoneid */ 1960Sstevel@tonic-gate 1978348SEric.Yu@Sun.COM struct pollhead so_poll_list; /* common pollhead */ 1988348SEric.Yu@Sun.COM short so_pollev; /* events that should be generated */ 1998348SEric.Yu@Sun.COM 2008348SEric.Yu@Sun.COM /* Receive */ 2018941SAnders.Persson@Sun.COM unsigned int so_rcv_queued; /* # bytes on both rcv lists */ 2028941SAnders.Persson@Sun.COM mblk_t *so_rcv_q_head; /* processing/copyout rcv queue */ 2038348SEric.Yu@Sun.COM mblk_t *so_rcv_q_last_head; 2048941SAnders.Persson@Sun.COM mblk_t *so_rcv_head; /* protocol prequeue */ 2058348SEric.Yu@Sun.COM mblk_t *so_rcv_last_head; /* last mblk in b_next chain */ 2068941SAnders.Persson@Sun.COM kcondvar_t so_rcv_cv; /* wait for data */ 2078348SEric.Yu@Sun.COM uint_t so_rcv_wanted; /* # of bytes wanted by app */ 2088348SEric.Yu@Sun.COM timeout_id_t so_rcv_timer_tid; 2098348SEric.Yu@Sun.COM 2108348SEric.Yu@Sun.COM #define so_rcv_thresh so_proto_props.sopp_rcvthresh 2118348SEric.Yu@Sun.COM #define so_rcv_timer_interval so_proto_props.sopp_rcvtimer 2120Sstevel@tonic-gate 2138941SAnders.Persson@Sun.COM kcondvar_t so_snd_cv; /* wait for snd buffers */ 2148399SRao.Shoaib@Sun.COM uint32_t 2158399SRao.Shoaib@Sun.COM so_snd_qfull: 1, /* Transmit full */ 2168399SRao.Shoaib@Sun.COM so_rcv_wakeup: 1, 2178399SRao.Shoaib@Sun.COM so_snd_wakeup: 1, 2188399SRao.Shoaib@Sun.COM so_not_str: 1, /* B_TRUE if not streams based socket */ 2198399SRao.Shoaib@Sun.COM so_pad_to_bit_31: 28; 220898Skais 2218348SEric.Yu@Sun.COM /* Communication channel with protocol */ 2228348SEric.Yu@Sun.COM sock_lower_handle_t so_proto_handle; 2238348SEric.Yu@Sun.COM sock_downcalls_t *so_downcalls; 2248348SEric.Yu@Sun.COM 2258348SEric.Yu@Sun.COM struct sock_proto_props so_proto_props; /* protocol settings */ 2268348SEric.Yu@Sun.COM boolean_t so_flowctrld; /* Flow controlled */ 2278348SEric.Yu@Sun.COM uint_t so_copyflag; /* Copy related flag */ 2288348SEric.Yu@Sun.COM kcondvar_t so_copy_cv; /* Copy cond variable */ 2298348SEric.Yu@Sun.COM 2308348SEric.Yu@Sun.COM /* kernel sockets */ 2318348SEric.Yu@Sun.COM ksocket_callbacks_t so_ksock_callbacks; 2328348SEric.Yu@Sun.COM void *so_ksock_cb_arg; /* callback argument */ 2338348SEric.Yu@Sun.COM kcondvar_t so_closing_cv; 2346707Sbrutus 2359491SAnders.Persson@Sun.COM /* != NULL for sodirect enabled socket */ 2369491SAnders.Persson@Sun.COM struct sodirect_s *so_direct; 23712643SAnders.Persson@Sun.COM 23812643SAnders.Persson@Sun.COM /* socket filters */ 23912643SAnders.Persson@Sun.COM uint_t so_filter_active; /* # of active fil */ 24012643SAnders.Persson@Sun.COM uint_t so_filter_tx; /* pending tx ops */ 24112643SAnders.Persson@Sun.COM struct sof_instance *so_filter_top; /* top of stack */ 24212643SAnders.Persson@Sun.COM struct sof_instance *so_filter_bottom; /* bottom of stack */ 24312643SAnders.Persson@Sun.COM clock_t so_filter_defertime; /* time when deferred */ 2440Sstevel@tonic-gate }; 2450Sstevel@tonic-gate 2468348SEric.Yu@Sun.COM #define SO_HAVE_DATA(so) \ 2478427SAnders.Persson@Sun.COM /* \ 2488427SAnders.Persson@Sun.COM * For the (tid == 0) case we must check so_rcv_{q_,}head \ 2498427SAnders.Persson@Sun.COM * rather than (so_rcv_queued > 0), since the latter does not \ 2508427SAnders.Persson@Sun.COM * take into account mblks with only control/name information. \ 2518427SAnders.Persson@Sun.COM */ \ 2528427SAnders.Persson@Sun.COM ((so)->so_rcv_timer_tid == 0 && ((so)->so_rcv_head != NULL || \ 2538427SAnders.Persson@Sun.COM (so)->so_rcv_q_head != NULL)) || \ 2548348SEric.Yu@Sun.COM ((so)->so_state & SS_CANTRCVMORE) 2558348SEric.Yu@Sun.COM 2568348SEric.Yu@Sun.COM /* 2578348SEric.Yu@Sun.COM * Events handled by the protocol (in case sd_poll is set) 2588348SEric.Yu@Sun.COM */ 2598348SEric.Yu@Sun.COM #define SO_PROTO_POLLEV (POLLIN|POLLRDNORM|POLLRDBAND) 2608348SEric.Yu@Sun.COM 2618348SEric.Yu@Sun.COM 2628348SEric.Yu@Sun.COM #endif /* _KERNEL || _KMEMUSER */ 2638348SEric.Yu@Sun.COM 2640Sstevel@tonic-gate /* flags */ 2650Sstevel@tonic-gate #define SOMOD 0x0001 /* update socket modification time */ 2660Sstevel@tonic-gate #define SOACC 0x0002 /* update socket access time */ 2670Sstevel@tonic-gate 2680Sstevel@tonic-gate #define SOLOCKED 0x0010 /* use to serialize open/closes */ 2690Sstevel@tonic-gate #define SOREADLOCKED 0x0020 /* serialize kstrgetmsg calls */ 27011521SAnders.Persson@Sun.COM #define SOCLONE 0x0040 /* child of clone driver */ 27111521SAnders.Persson@Sun.COM #define SOASYNC_UNBIND 0x0080 /* wait for ACK of async unbind */ 2720Sstevel@tonic-gate 2738399SRao.Shoaib@Sun.COM #define SOCK_IS_NONSTR(so) ((so)->so_not_str) 2748348SEric.Yu@Sun.COM 2750Sstevel@tonic-gate /* 2760Sstevel@tonic-gate * Socket state bits. 2770Sstevel@tonic-gate */ 2780Sstevel@tonic-gate #define SS_ISCONNECTED 0x00000001 /* socket connected to a peer */ 2790Sstevel@tonic-gate #define SS_ISCONNECTING 0x00000002 /* in process, connecting to peer */ 2800Sstevel@tonic-gate #define SS_ISDISCONNECTING 0x00000004 /* in process of disconnecting */ 2810Sstevel@tonic-gate #define SS_CANTSENDMORE 0x00000008 /* can't send more data to peer */ 2820Sstevel@tonic-gate 2830Sstevel@tonic-gate #define SS_CANTRCVMORE 0x00000010 /* can't receive more data */ 2840Sstevel@tonic-gate #define SS_ISBOUND 0x00000020 /* socket is bound */ 2850Sstevel@tonic-gate #define SS_NDELAY 0x00000040 /* FNDELAY non-blocking */ 2860Sstevel@tonic-gate #define SS_NONBLOCK 0x00000080 /* O_NONBLOCK non-blocking */ 2870Sstevel@tonic-gate 2880Sstevel@tonic-gate #define SS_ASYNC 0x00000100 /* async i/o notify */ 2890Sstevel@tonic-gate #define SS_ACCEPTCONN 0x00000200 /* listen done */ 2908348SEric.Yu@Sun.COM /* unused 0x00000400 */ /* was SS_HASCONNIND */ 2910Sstevel@tonic-gate #define SS_SAVEDEOR 0x00000800 /* Saved MSG_EOR rcv side state */ 2920Sstevel@tonic-gate 2930Sstevel@tonic-gate #define SS_RCVATMARK 0x00001000 /* at mark on input */ 2940Sstevel@tonic-gate #define SS_OOBPEND 0x00002000 /* OOB pending or present - poll */ 2950Sstevel@tonic-gate #define SS_HAVEOOBDATA 0x00004000 /* OOB data present */ 2960Sstevel@tonic-gate #define SS_HADOOBDATA 0x00008000 /* OOB data consumed */ 2978348SEric.Yu@Sun.COM #define SS_CLOSING 0x00010000 /* in process of closing */ 2980Sstevel@tonic-gate 29912643SAnders.Persson@Sun.COM #define SS_FIL_DEFER 0x00020000 /* filter deferred notification */ 30012643SAnders.Persson@Sun.COM #define SS_FILOP_OK 0x00040000 /* socket can attach filters */ 30112643SAnders.Persson@Sun.COM #define SS_FIL_RCV_FLOWCTRL 0x00080000 /* filter asserted rcv flow ctrl */ 30212643SAnders.Persson@Sun.COM #define SS_FIL_SND_FLOWCTRL 0x00100000 /* filter asserted snd flow ctrl */ 303*13062SAnders.Persson@Sun.COM #define SS_FIL_STOP 0x00200000 /* no more filter actions */ 3040Sstevel@tonic-gate 3056707Sbrutus #define SS_SODIRECT 0x00400000 /* transport supports sodirect */ 3060Sstevel@tonic-gate 3078963SAnders.Persson@Sun.COM #define SS_SENTLASTREADSIG 0x01000000 /* last rx signal has been sent */ 3088963SAnders.Persson@Sun.COM #define SS_SENTLASTWRITESIG 0x02000000 /* last tx signal has been sent */ 3098348SEric.Yu@Sun.COM 3108963SAnders.Persson@Sun.COM #define SS_FALLBACK_DRAIN 0x20000000 /* data was/is being drained */ 3118963SAnders.Persson@Sun.COM #define SS_FALLBACK_PENDING 0x40000000 /* fallback is pending */ 3128963SAnders.Persson@Sun.COM #define SS_FALLBACK_COMP 0x80000000 /* fallback has completed */ 3138348SEric.Yu@Sun.COM 3140Sstevel@tonic-gate 3150Sstevel@tonic-gate /* Set of states when the socket can't be rebound */ 3160Sstevel@tonic-gate #define SS_CANTREBIND (SS_ISCONNECTED|SS_ISCONNECTING|SS_ISDISCONNECTING|\ 3170Sstevel@tonic-gate SS_CANTSENDMORE|SS_CANTRCVMORE|SS_ACCEPTCONN) 3180Sstevel@tonic-gate 3190Sstevel@tonic-gate /* 3208348SEric.Yu@Sun.COM * Sockets that can fall back to TPI must ensure that fall back is not 3218348SEric.Yu@Sun.COM * initiated while a thread is using a socket. 3228348SEric.Yu@Sun.COM */ 32312643SAnders.Persson@Sun.COM #define SO_BLOCK_FALLBACK(so, fn) \ 32412643SAnders.Persson@Sun.COM ASSERT(MUTEX_NOT_HELD(&(so)->so_lock)); \ 32512643SAnders.Persson@Sun.COM rw_enter(&(so)->so_fallback_rwlock, RW_READER); \ 32612643SAnders.Persson@Sun.COM if ((so)->so_state & (SS_FALLBACK_COMP|SS_FILOP_OK)) { \ 32712643SAnders.Persson@Sun.COM if ((so)->so_state & SS_FALLBACK_COMP) { \ 32812643SAnders.Persson@Sun.COM rw_exit(&(so)->so_fallback_rwlock); \ 32912643SAnders.Persson@Sun.COM return (fn); \ 33012643SAnders.Persson@Sun.COM } else { \ 33112643SAnders.Persson@Sun.COM mutex_enter(&(so)->so_lock); \ 33212643SAnders.Persson@Sun.COM (so)->so_state &= ~SS_FILOP_OK; \ 33312643SAnders.Persson@Sun.COM mutex_exit(&(so)->so_lock); \ 33412643SAnders.Persson@Sun.COM } \ 33512643SAnders.Persson@Sun.COM } 3368348SEric.Yu@Sun.COM 3378348SEric.Yu@Sun.COM #define SO_UNBLOCK_FALLBACK(so) { \ 3388348SEric.Yu@Sun.COM rw_exit(&(so)->so_fallback_rwlock); \ 3398348SEric.Yu@Sun.COM } 3408348SEric.Yu@Sun.COM 34112643SAnders.Persson@Sun.COM #define SO_SND_FLOWCTRLD(so) \ 34212643SAnders.Persson@Sun.COM ((so)->so_snd_qfull || (so)->so_state & SS_FIL_SND_FLOWCTRL) 34312643SAnders.Persson@Sun.COM 3448348SEric.Yu@Sun.COM /* Poll events */ 3458348SEric.Yu@Sun.COM #define SO_POLLEV_IN 0x1 /* POLLIN wakeup needed */ 3468348SEric.Yu@Sun.COM #define SO_POLLEV_ALWAYS 0x2 /* wakeups */ 3478348SEric.Yu@Sun.COM 3488348SEric.Yu@Sun.COM /* 3490Sstevel@tonic-gate * Characteristics of sockets. Not changed after the socket is created. 3500Sstevel@tonic-gate */ 3510Sstevel@tonic-gate #define SM_PRIV 0x001 /* privileged for broadcast, raw... */ 3520Sstevel@tonic-gate #define SM_ATOMIC 0x002 /* atomic data transmission */ 3530Sstevel@tonic-gate #define SM_ADDR 0x004 /* addresses given with messages */ 3540Sstevel@tonic-gate #define SM_CONNREQUIRED 0x008 /* connection required by protocol */ 3550Sstevel@tonic-gate 3560Sstevel@tonic-gate #define SM_FDPASSING 0x010 /* passes file descriptors */ 3570Sstevel@tonic-gate #define SM_EXDATA 0x020 /* Can handle T_EXDATA_REQ */ 3580Sstevel@tonic-gate #define SM_OPTDATA 0x040 /* Can handle T_OPTDATA_REQ */ 3590Sstevel@tonic-gate #define SM_BYTESTREAM 0x080 /* Byte stream - can use M_DATA */ 3600Sstevel@tonic-gate 3610Sstevel@tonic-gate #define SM_ACCEPTOR_ID 0x100 /* so_acceptor_id is valid */ 3620Sstevel@tonic-gate 3638348SEric.Yu@Sun.COM #define SM_KERNEL 0x200 /* kernel socket */ 3648348SEric.Yu@Sun.COM 3658401SAnders.Persson@Sun.COM /* The modes below are only for non-streams sockets */ 3668348SEric.Yu@Sun.COM #define SM_ACCEPTSUPP 0x400 /* can handle accept() */ 3678401SAnders.Persson@Sun.COM #define SM_SENDFILESUPP 0x800 /* Private: proto supp sendfile */ 3688348SEric.Yu@Sun.COM 3690Sstevel@tonic-gate /* 3700Sstevel@tonic-gate * Socket versions. Used by the socket library when calling _so_socket(). 3710Sstevel@tonic-gate */ 3720Sstevel@tonic-gate #define SOV_STREAM 0 /* Not a socket - just a stream */ 3730Sstevel@tonic-gate #define SOV_DEFAULT 1 /* Select based on so_default_version */ 3740Sstevel@tonic-gate #define SOV_SOCKSTREAM 2 /* Socket plus streams operations */ 3750Sstevel@tonic-gate #define SOV_SOCKBSD 3 /* Socket with no streams operations */ 3760Sstevel@tonic-gate #define SOV_XPG4_2 4 /* Xnet socket */ 3770Sstevel@tonic-gate 3780Sstevel@tonic-gate #if defined(_KERNEL) || defined(_KMEMUSER) 3798348SEric.Yu@Sun.COM 3800Sstevel@tonic-gate /* 3818348SEric.Yu@Sun.COM * sonode create and destroy functions. 3828348SEric.Yu@Sun.COM */ 3838348SEric.Yu@Sun.COM typedef struct sonode *(*so_create_func_t)(struct sockparams *, 3848348SEric.Yu@Sun.COM int, int, int, int, int, int *, cred_t *); 3858348SEric.Yu@Sun.COM typedef void (*so_destroy_func_t)(struct sonode *); 3868348SEric.Yu@Sun.COM 3878348SEric.Yu@Sun.COM /* STREAM device information */ 3888348SEric.Yu@Sun.COM typedef struct sdev_info { 3898348SEric.Yu@Sun.COM char *sd_devpath; 3908348SEric.Yu@Sun.COM int sd_devpathlen; /* Is 0 if sp_devpath is a static string */ 3918348SEric.Yu@Sun.COM vnode_t *sd_vnode; 3928348SEric.Yu@Sun.COM } sdev_info_t; 3938348SEric.Yu@Sun.COM 39412643SAnders.Persson@Sun.COM #define SOCKMOD_VERSION_1 1 39512643SAnders.Persson@Sun.COM #define SOCKMOD_VERSION 2 39612643SAnders.Persson@Sun.COM 3978348SEric.Yu@Sun.COM /* name of the TPI pseudo socket module */ 3988348SEric.Yu@Sun.COM #define SOTPI_SMOD_NAME "socktpi" 3998348SEric.Yu@Sun.COM 4008348SEric.Yu@Sun.COM typedef struct __smod_priv_s { 4018348SEric.Yu@Sun.COM so_create_func_t smodp_sock_create_func; 4028348SEric.Yu@Sun.COM so_destroy_func_t smodp_sock_destroy_func; 4038348SEric.Yu@Sun.COM so_proto_fallback_func_t smodp_proto_fallback_func; 40412643SAnders.Persson@Sun.COM const char *smodp_fallback_devpath_v4; 40512643SAnders.Persson@Sun.COM const char *smodp_fallback_devpath_v6; 4068348SEric.Yu@Sun.COM } __smod_priv_t; 4078348SEric.Yu@Sun.COM 4088348SEric.Yu@Sun.COM /* 4098348SEric.Yu@Sun.COM * Socket module register information 4108348SEric.Yu@Sun.COM */ 4118348SEric.Yu@Sun.COM typedef struct smod_reg_s { 4128348SEric.Yu@Sun.COM int smod_version; 4138348SEric.Yu@Sun.COM char *smod_name; 4148348SEric.Yu@Sun.COM size_t smod_uc_version; 4158348SEric.Yu@Sun.COM size_t smod_dc_version; 4168348SEric.Yu@Sun.COM so_proto_create_func_t smod_proto_create_func; 4178348SEric.Yu@Sun.COM 4188348SEric.Yu@Sun.COM /* __smod_priv_data must be NULL */ 4198348SEric.Yu@Sun.COM __smod_priv_t *__smod_priv; 4208348SEric.Yu@Sun.COM } smod_reg_t; 4218348SEric.Yu@Sun.COM 4228348SEric.Yu@Sun.COM /* 4238348SEric.Yu@Sun.COM * Socket module information 4248348SEric.Yu@Sun.COM */ 4258348SEric.Yu@Sun.COM typedef struct smod_info { 4268348SEric.Yu@Sun.COM int smod_version; 4278348SEric.Yu@Sun.COM char *smod_name; 4288348SEric.Yu@Sun.COM uint_t smod_refcnt; /* # of entries */ 4298348SEric.Yu@Sun.COM size_t smod_uc_version; /* upcall version */ 4308348SEric.Yu@Sun.COM size_t smod_dc_version; /* down call version */ 4318348SEric.Yu@Sun.COM so_proto_create_func_t smod_proto_create_func; 4328348SEric.Yu@Sun.COM so_proto_fallback_func_t smod_proto_fallback_func; 43312643SAnders.Persson@Sun.COM const char *smod_fallback_devpath_v4; 43412643SAnders.Persson@Sun.COM const char *smod_fallback_devpath_v6; 4358348SEric.Yu@Sun.COM so_create_func_t smod_sock_create_func; 4368348SEric.Yu@Sun.COM so_destroy_func_t smod_sock_destroy_func; 4378348SEric.Yu@Sun.COM list_node_t smod_node; 4388348SEric.Yu@Sun.COM } smod_info_t; 4398348SEric.Yu@Sun.COM 4408964SAnders.Persson@Sun.COM typedef struct sockparams_stats { 4418964SAnders.Persson@Sun.COM kstat_named_t sps_nfallback; /* # of fallbacks to TPI */ 4428964SAnders.Persson@Sun.COM kstat_named_t sps_nactive; /* # of active sockets */ 4438964SAnders.Persson@Sun.COM kstat_named_t sps_ncreate; /* total # of created sockets */ 4448964SAnders.Persson@Sun.COM } sockparams_stats_t; 4458964SAnders.Persson@Sun.COM 4468348SEric.Yu@Sun.COM /* 4478348SEric.Yu@Sun.COM * sockparams 4488348SEric.Yu@Sun.COM * 44912257SAnders.Persson@Sun.COM * Used for mapping family/type/protocol to a socket module or STREAMS device 4500Sstevel@tonic-gate */ 4510Sstevel@tonic-gate struct sockparams { 4528348SEric.Yu@Sun.COM /* 45312257SAnders.Persson@Sun.COM * The family, type, protocol, sdev_info and smod_name are 4548348SEric.Yu@Sun.COM * set when the entry is created, and they will never change 4558348SEric.Yu@Sun.COM * thereafter. 4568348SEric.Yu@Sun.COM */ 4578348SEric.Yu@Sun.COM int sp_family; 4588348SEric.Yu@Sun.COM int sp_type; 4598348SEric.Yu@Sun.COM int sp_protocol; 4608348SEric.Yu@Sun.COM 4618348SEric.Yu@Sun.COM sdev_info_t sp_sdev_info; /* STREAM device */ 4628348SEric.Yu@Sun.COM char *sp_smod_name; /* socket module name */ 46312257SAnders.Persson@Sun.COM 46412257SAnders.Persson@Sun.COM kmutex_t sp_lock; /* lock for refcnt and smod_info */ 46512257SAnders.Persson@Sun.COM uint64_t sp_refcnt; /* entry reference count */ 4668348SEric.Yu@Sun.COM smod_info_t *sp_smod_info; /* socket module */ 4678348SEric.Yu@Sun.COM 4688964SAnders.Persson@Sun.COM sockparams_stats_t sp_stats; 4698964SAnders.Persson@Sun.COM kstat_t *sp_kstat; 4708348SEric.Yu@Sun.COM 4718348SEric.Yu@Sun.COM /* 4728348SEric.Yu@Sun.COM * The entries below are only modified while holding 47312643SAnders.Persson@Sun.COM * sockconf_lock as a writer. 4748348SEric.Yu@Sun.COM */ 4758348SEric.Yu@Sun.COM int sp_flags; /* see below */ 4768348SEric.Yu@Sun.COM list_node_t sp_node; 47712643SAnders.Persson@Sun.COM 47812643SAnders.Persson@Sun.COM list_t sp_auto_filters; /* list of automatic filters */ 47912643SAnders.Persson@Sun.COM list_t sp_prog_filters; /* list of programmatic filters */ 4800Sstevel@tonic-gate }; 4810Sstevel@tonic-gate 48212643SAnders.Persson@Sun.COM struct sof_entry; 48312643SAnders.Persson@Sun.COM 48412643SAnders.Persson@Sun.COM typedef struct sp_filter { 48512643SAnders.Persson@Sun.COM struct sof_entry *spf_filter; 48612643SAnders.Persson@Sun.COM list_node_t spf_node; 48712643SAnders.Persson@Sun.COM } sp_filter_t; 48812643SAnders.Persson@Sun.COM 4898348SEric.Yu@Sun.COM 4908348SEric.Yu@Sun.COM /* 4918348SEric.Yu@Sun.COM * sockparams flags 4928348SEric.Yu@Sun.COM */ 4938348SEric.Yu@Sun.COM #define SOCKPARAMS_EPHEMERAL 0x1 /* temp. entry, not on global list */ 4948348SEric.Yu@Sun.COM 4958348SEric.Yu@Sun.COM extern void sockparams_init(void); 4968348SEric.Yu@Sun.COM extern struct sockparams *sockparams_hold_ephemeral_bydev(int, int, int, 4978348SEric.Yu@Sun.COM const char *, int, int *); 4988348SEric.Yu@Sun.COM extern struct sockparams *sockparams_hold_ephemeral_bymod(int, int, int, 4998348SEric.Yu@Sun.COM const char *, int, int *); 5008348SEric.Yu@Sun.COM extern void sockparams_ephemeral_drop_last_ref(struct sockparams *); 5018348SEric.Yu@Sun.COM 50212643SAnders.Persson@Sun.COM extern struct sockparams *sockparams_create(int, int, int, char *, char *, int, 50312643SAnders.Persson@Sun.COM int, int, int *); 50412643SAnders.Persson@Sun.COM extern void sockparams_destroy(struct sockparams *); 50512643SAnders.Persson@Sun.COM extern int sockparams_add(struct sockparams *); 50612643SAnders.Persson@Sun.COM extern int sockparams_delete(int, int, int); 50712643SAnders.Persson@Sun.COM extern int sockparams_new_filter(struct sof_entry *); 50812643SAnders.Persson@Sun.COM extern void sockparams_filter_cleanup(struct sof_entry *); 50912643SAnders.Persson@Sun.COM 5108348SEric.Yu@Sun.COM extern void smod_init(void); 5118348SEric.Yu@Sun.COM extern void smod_add(smod_info_t *); 5128348SEric.Yu@Sun.COM extern int smod_register(const smod_reg_t *); 5138348SEric.Yu@Sun.COM extern int smod_unregister(const char *); 5148348SEric.Yu@Sun.COM extern smod_info_t *smod_lookup_byname(const char *); 5158348SEric.Yu@Sun.COM 5168348SEric.Yu@Sun.COM #define SOCKPARAMS_HAS_DEVICE(sp) \ 5178348SEric.Yu@Sun.COM ((sp)->sp_sdev_info.sd_devpath != NULL) 5188348SEric.Yu@Sun.COM 5198348SEric.Yu@Sun.COM /* Increase the smod_info_t reference count */ 5208348SEric.Yu@Sun.COM #define SMOD_INC_REF(smodp) { \ 5218348SEric.Yu@Sun.COM ASSERT((smodp) != NULL); \ 5228348SEric.Yu@Sun.COM DTRACE_PROBE1(smodinfo__inc__ref, struct smod_info *, (smodp)); \ 5238348SEric.Yu@Sun.COM atomic_inc_uint(&(smodp)->smod_refcnt); \ 5248348SEric.Yu@Sun.COM } 5258348SEric.Yu@Sun.COM 5268348SEric.Yu@Sun.COM /* 5278348SEric.Yu@Sun.COM * Decreace the socket module entry reference count. 5288348SEric.Yu@Sun.COM * When no one mapping to the entry, we try to unload the module from the 5298348SEric.Yu@Sun.COM * kernel. If the module can't unload, just leave the module entry with 5308348SEric.Yu@Sun.COM * a zero refcnt. 5318348SEric.Yu@Sun.COM */ 53212257SAnders.Persson@Sun.COM #define SMOD_DEC_REF(smodp, modname) { \ 5338348SEric.Yu@Sun.COM ASSERT((smodp) != NULL); \ 5348348SEric.Yu@Sun.COM ASSERT((smodp)->smod_refcnt != 0); \ 5358348SEric.Yu@Sun.COM atomic_dec_uint(&(smodp)->smod_refcnt); \ 5368348SEric.Yu@Sun.COM /* \ 5378348SEric.Yu@Sun.COM * No need to atomically check the return value because the \ 5388348SEric.Yu@Sun.COM * socket module framework will verify that no one is using \ 5398348SEric.Yu@Sun.COM * the module before unloading. Worst thing that can happen \ 5408348SEric.Yu@Sun.COM * here is multiple calls to mod_remove_by_name(), which is OK. \ 5418348SEric.Yu@Sun.COM */ \ 5428348SEric.Yu@Sun.COM if ((smodp)->smod_refcnt == 0) \ 54312257SAnders.Persson@Sun.COM (void) mod_remove_by_name(modname); \ 5448348SEric.Yu@Sun.COM } 5458348SEric.Yu@Sun.COM 5468348SEric.Yu@Sun.COM /* Increase the reference count */ 5478348SEric.Yu@Sun.COM #define SOCKPARAMS_INC_REF(sp) { \ 5488348SEric.Yu@Sun.COM ASSERT((sp) != NULL); \ 5498348SEric.Yu@Sun.COM DTRACE_PROBE1(sockparams__inc__ref, struct sockparams *, (sp)); \ 5508348SEric.Yu@Sun.COM mutex_enter(&(sp)->sp_lock); \ 5518348SEric.Yu@Sun.COM (sp)->sp_refcnt++; \ 5528348SEric.Yu@Sun.COM ASSERT((sp)->sp_refcnt != 0); \ 5538348SEric.Yu@Sun.COM mutex_exit(&(sp)->sp_lock); \ 5548348SEric.Yu@Sun.COM } 5558348SEric.Yu@Sun.COM 5568348SEric.Yu@Sun.COM /* 5578348SEric.Yu@Sun.COM * Decrease the reference count. 5588348SEric.Yu@Sun.COM * 5598348SEric.Yu@Sun.COM * If the sockparams is ephemeral, then the thread dropping the last ref 5608348SEric.Yu@Sun.COM * count will destroy the entry. 5618348SEric.Yu@Sun.COM */ 5628348SEric.Yu@Sun.COM #define SOCKPARAMS_DEC_REF(sp) { \ 5638348SEric.Yu@Sun.COM ASSERT((sp) != NULL); \ 5648348SEric.Yu@Sun.COM DTRACE_PROBE1(sockparams__dec__ref, struct sockparams *, (sp)); \ 5658348SEric.Yu@Sun.COM mutex_enter(&(sp)->sp_lock); \ 5668348SEric.Yu@Sun.COM ASSERT((sp)->sp_refcnt > 0); \ 5678348SEric.Yu@Sun.COM if ((sp)->sp_refcnt == 1) { \ 5688348SEric.Yu@Sun.COM if ((sp)->sp_flags & SOCKPARAMS_EPHEMERAL) { \ 5698348SEric.Yu@Sun.COM mutex_exit(&(sp)->sp_lock); \ 5708348SEric.Yu@Sun.COM sockparams_ephemeral_drop_last_ref((sp)); \ 5718348SEric.Yu@Sun.COM } else { \ 5728348SEric.Yu@Sun.COM (sp)->sp_refcnt--; \ 57312257SAnders.Persson@Sun.COM if ((sp)->sp_smod_info != NULL) { \ 57412257SAnders.Persson@Sun.COM SMOD_DEC_REF((sp)->sp_smod_info, \ 57512257SAnders.Persson@Sun.COM (sp)->sp_smod_name); \ 57612257SAnders.Persson@Sun.COM } \ 5778348SEric.Yu@Sun.COM (sp)->sp_smod_info = NULL; \ 5788348SEric.Yu@Sun.COM mutex_exit(&(sp)->sp_lock); \ 5798348SEric.Yu@Sun.COM } \ 5808348SEric.Yu@Sun.COM } else { \ 5818348SEric.Yu@Sun.COM (sp)->sp_refcnt--; \ 5828348SEric.Yu@Sun.COM mutex_exit(&(sp)->sp_lock); \ 5838348SEric.Yu@Sun.COM } \ 5848348SEric.Yu@Sun.COM } 5850Sstevel@tonic-gate 5860Sstevel@tonic-gate /* 5870Sstevel@tonic-gate * Used to traverse the list of AF_UNIX sockets to construct the kstat 5880Sstevel@tonic-gate * for netstat(1m). 5890Sstevel@tonic-gate */ 5900Sstevel@tonic-gate struct socklist { 5910Sstevel@tonic-gate kmutex_t sl_lock; 5920Sstevel@tonic-gate struct sonode *sl_list; 5930Sstevel@tonic-gate }; 5940Sstevel@tonic-gate 5950Sstevel@tonic-gate extern struct socklist socklist; 5960Sstevel@tonic-gate /* 5970Sstevel@tonic-gate * ss_full_waits is the number of times the reader thread 5980Sstevel@tonic-gate * waits when the queue is full and ss_empty_waits is the number 5990Sstevel@tonic-gate * of times the consumer thread waits when the queue is empty. 6000Sstevel@tonic-gate * No locks for these as they are just indicators of whether 6010Sstevel@tonic-gate * disk or network or both is slow or fast. 6020Sstevel@tonic-gate */ 6030Sstevel@tonic-gate struct sendfile_stats { 6040Sstevel@tonic-gate uint32_t ss_file_cached; 6050Sstevel@tonic-gate uint32_t ss_file_not_cached; 6060Sstevel@tonic-gate uint32_t ss_full_waits; 6070Sstevel@tonic-gate uint32_t ss_empty_waits; 6080Sstevel@tonic-gate uint32_t ss_file_segmap; 6090Sstevel@tonic-gate }; 6100Sstevel@tonic-gate 6110Sstevel@tonic-gate /* 6120Sstevel@tonic-gate * A single sendfile request is represented by snf_req. 6130Sstevel@tonic-gate */ 6140Sstevel@tonic-gate typedef struct snf_req { 6150Sstevel@tonic-gate struct snf_req *sr_next; 6160Sstevel@tonic-gate mblk_t *sr_mp_head; 6170Sstevel@tonic-gate mblk_t *sr_mp_tail; 6180Sstevel@tonic-gate kmutex_t sr_lock; 6190Sstevel@tonic-gate kcondvar_t sr_cv; 6200Sstevel@tonic-gate uint_t sr_qlen; 6210Sstevel@tonic-gate int sr_hiwat; 6220Sstevel@tonic-gate int sr_lowat; 6230Sstevel@tonic-gate int sr_operation; 6240Sstevel@tonic-gate struct vnode *sr_vp; 6250Sstevel@tonic-gate file_t *sr_fp; 6260Sstevel@tonic-gate ssize_t sr_maxpsz; 6270Sstevel@tonic-gate u_offset_t sr_file_off; 6280Sstevel@tonic-gate u_offset_t sr_file_size; 6290Sstevel@tonic-gate #define SR_READ_DONE 0x80000000 6300Sstevel@tonic-gate int sr_read_error; 6310Sstevel@tonic-gate int sr_write_error; 6320Sstevel@tonic-gate } snf_req_t; 6330Sstevel@tonic-gate 6340Sstevel@tonic-gate /* A queue of sendfile requests */ 6350Sstevel@tonic-gate struct sendfile_queue { 6360Sstevel@tonic-gate snf_req_t *snfq_req_head; 6370Sstevel@tonic-gate snf_req_t *snfq_req_tail; 6380Sstevel@tonic-gate kmutex_t snfq_lock; 6390Sstevel@tonic-gate kcondvar_t snfq_cv; 6400Sstevel@tonic-gate int snfq_svc_threads; /* # of service threads */ 6410Sstevel@tonic-gate int snfq_idle_cnt; /* # of idling threads */ 6420Sstevel@tonic-gate int snfq_max_threads; 6430Sstevel@tonic-gate int snfq_req_cnt; /* Number of requests */ 6440Sstevel@tonic-gate }; 6450Sstevel@tonic-gate 6460Sstevel@tonic-gate #define READ_OP 1 6470Sstevel@tonic-gate #define SNFQ_TIMEOUT (60 * 5 * hz) /* 5 minutes */ 6480Sstevel@tonic-gate 6490Sstevel@tonic-gate /* Socket network operations switch */ 6500Sstevel@tonic-gate struct sonodeops { 6518348SEric.Yu@Sun.COM int (*sop_init)(struct sonode *, struct sonode *, cred_t *, 6520Sstevel@tonic-gate int); 6538348SEric.Yu@Sun.COM int (*sop_accept)(struct sonode *, int, cred_t *, struct sonode **); 6548348SEric.Yu@Sun.COM int (*sop_bind)(struct sonode *, struct sockaddr *, socklen_t, 6558348SEric.Yu@Sun.COM int, cred_t *); 6568348SEric.Yu@Sun.COM int (*sop_listen)(struct sonode *, int, cred_t *); 65712643SAnders.Persson@Sun.COM int (*sop_connect)(struct sonode *, struct sockaddr *, 6588348SEric.Yu@Sun.COM socklen_t, int, int, cred_t *); 6590Sstevel@tonic-gate int (*sop_recvmsg)(struct sonode *, struct msghdr *, 6608348SEric.Yu@Sun.COM struct uio *, cred_t *); 6610Sstevel@tonic-gate int (*sop_sendmsg)(struct sonode *, struct msghdr *, 6628348SEric.Yu@Sun.COM struct uio *, cred_t *); 6638348SEric.Yu@Sun.COM int (*sop_sendmblk)(struct sonode *, struct msghdr *, int, 6648348SEric.Yu@Sun.COM cred_t *, mblk_t **); 6658348SEric.Yu@Sun.COM int (*sop_getpeername)(struct sonode *, struct sockaddr *, 6668348SEric.Yu@Sun.COM socklen_t *, boolean_t, cred_t *); 6678348SEric.Yu@Sun.COM int (*sop_getsockname)(struct sonode *, struct sockaddr *, 6688348SEric.Yu@Sun.COM socklen_t *, cred_t *); 6698348SEric.Yu@Sun.COM int (*sop_shutdown)(struct sonode *, int, cred_t *); 6700Sstevel@tonic-gate int (*sop_getsockopt)(struct sonode *, int, int, void *, 6718348SEric.Yu@Sun.COM socklen_t *, int, cred_t *); 6720Sstevel@tonic-gate int (*sop_setsockopt)(struct sonode *, int, int, const void *, 6738348SEric.Yu@Sun.COM socklen_t, cred_t *); 6748348SEric.Yu@Sun.COM int (*sop_ioctl)(struct sonode *, int, intptr_t, int, 6758348SEric.Yu@Sun.COM cred_t *, int32_t *); 6768348SEric.Yu@Sun.COM int (*sop_poll)(struct sonode *, short, int, short *, 6778348SEric.Yu@Sun.COM struct pollhead **); 6788348SEric.Yu@Sun.COM int (*sop_close)(struct sonode *, int, cred_t *); 6790Sstevel@tonic-gate }; 6800Sstevel@tonic-gate 6818348SEric.Yu@Sun.COM #define SOP_INIT(so, flag, cr, flags) \ 6828348SEric.Yu@Sun.COM ((so)->so_ops->sop_init((so), (flag), (cr), (flags))) 6838348SEric.Yu@Sun.COM #define SOP_ACCEPT(so, fflag, cr, nsop) \ 6848348SEric.Yu@Sun.COM ((so)->so_ops->sop_accept((so), (fflag), (cr), (nsop))) 6858348SEric.Yu@Sun.COM #define SOP_BIND(so, name, namelen, flags, cr) \ 6868348SEric.Yu@Sun.COM ((so)->so_ops->sop_bind((so), (name), (namelen), (flags), (cr))) 6878348SEric.Yu@Sun.COM #define SOP_LISTEN(so, backlog, cr) \ 6888348SEric.Yu@Sun.COM ((so)->so_ops->sop_listen((so), (backlog), (cr))) 6898348SEric.Yu@Sun.COM #define SOP_CONNECT(so, name, namelen, fflag, flags, cr) \ 6908348SEric.Yu@Sun.COM ((so)->so_ops->sop_connect((so), (name), (namelen), (fflag), (flags), \ 6918348SEric.Yu@Sun.COM (cr))) 6928348SEric.Yu@Sun.COM #define SOP_RECVMSG(so, msg, uiop, cr) \ 6938348SEric.Yu@Sun.COM ((so)->so_ops->sop_recvmsg((so), (msg), (uiop), (cr))) 6948348SEric.Yu@Sun.COM #define SOP_SENDMSG(so, msg, uiop, cr) \ 6958348SEric.Yu@Sun.COM ((so)->so_ops->sop_sendmsg((so), (msg), (uiop), (cr))) 6968348SEric.Yu@Sun.COM #define SOP_SENDMBLK(so, msg, size, cr, mpp) \ 6978348SEric.Yu@Sun.COM ((so)->so_ops->sop_sendmblk((so), (msg), (size), (cr), (mpp))) 6988348SEric.Yu@Sun.COM #define SOP_GETPEERNAME(so, addr, addrlen, accept, cr) \ 6998348SEric.Yu@Sun.COM ((so)->so_ops->sop_getpeername((so), (addr), (addrlen), (accept), (cr))) 7008348SEric.Yu@Sun.COM #define SOP_GETSOCKNAME(so, addr, addrlen, cr) \ 7018348SEric.Yu@Sun.COM ((so)->so_ops->sop_getsockname((so), (addr), (addrlen), (cr))) 7028348SEric.Yu@Sun.COM #define SOP_SHUTDOWN(so, how, cr) \ 7038348SEric.Yu@Sun.COM ((so)->so_ops->sop_shutdown((so), (how), (cr))) 7048348SEric.Yu@Sun.COM #define SOP_GETSOCKOPT(so, level, optionname, optval, optlenp, flags, cr) \ 7050Sstevel@tonic-gate ((so)->so_ops->sop_getsockopt((so), (level), (optionname), \ 7068348SEric.Yu@Sun.COM (optval), (optlenp), (flags), (cr))) 7078348SEric.Yu@Sun.COM #define SOP_SETSOCKOPT(so, level, optionname, optval, optlen, cr) \ 7080Sstevel@tonic-gate ((so)->so_ops->sop_setsockopt((so), (level), (optionname), \ 7098348SEric.Yu@Sun.COM (optval), (optlen), (cr))) 7108348SEric.Yu@Sun.COM #define SOP_IOCTL(so, cmd, arg, mode, cr, rvalp) \ 7118348SEric.Yu@Sun.COM ((so)->so_ops->sop_ioctl((so), (cmd), (arg), (mode), (cr), (rvalp))) 7128348SEric.Yu@Sun.COM #define SOP_POLL(so, events, anyyet, reventsp, phpp) \ 7138348SEric.Yu@Sun.COM ((so)->so_ops->sop_poll((so), (events), (anyyet), (reventsp), (phpp))) 7148348SEric.Yu@Sun.COM #define SOP_CLOSE(so, flag, cr) \ 7158348SEric.Yu@Sun.COM ((so)->so_ops->sop_close((so), (flag), (cr))) 7160Sstevel@tonic-gate 7170Sstevel@tonic-gate #endif /* defined(_KERNEL) || defined(_KMEMUSER) */ 7180Sstevel@tonic-gate 7190Sstevel@tonic-gate #ifdef _KERNEL 7200Sstevel@tonic-gate 7210Sstevel@tonic-gate #define ISALIGNED_cmsghdr(addr) \ 7220Sstevel@tonic-gate (((uintptr_t)(addr) & (_CMSG_HDR_ALIGNMENT - 1)) == 0) 7230Sstevel@tonic-gate 7240Sstevel@tonic-gate #define ROUNDUP_cmsglen(len) \ 7250Sstevel@tonic-gate (((len) + _CMSG_HDR_ALIGNMENT - 1) & ~(_CMSG_HDR_ALIGNMENT - 1)) 7260Sstevel@tonic-gate 7278348SEric.Yu@Sun.COM #define IS_NON_STREAM_SOCK(vp) \ 7288348SEric.Yu@Sun.COM ((vp)->v_type == VSOCK && (vp)->v_stream == NULL) 7290Sstevel@tonic-gate /* 7302712Snn35248 * Macros that operate on struct cmsghdr. 7312712Snn35248 * Used in parsing msg_control. 7322712Snn35248 * The CMSG_VALID macro does not assume that the last option buffer is padded. 7330Sstevel@tonic-gate */ 7340Sstevel@tonic-gate #define CMSG_NEXT(cmsg) \ 7350Sstevel@tonic-gate (struct cmsghdr *)((uintptr_t)(cmsg) + \ 7360Sstevel@tonic-gate ROUNDUP_cmsglen((cmsg)->cmsg_len)) 7372712Snn35248 #define CMSG_CONTENT(cmsg) (&((cmsg)[1])) 7382712Snn35248 #define CMSG_CONTENTLEN(cmsg) ((cmsg)->cmsg_len - sizeof (struct cmsghdr)) 7392712Snn35248 #define CMSG_VALID(cmsg, start, end) \ 7402712Snn35248 (ISALIGNED_cmsghdr(cmsg) && \ 7412712Snn35248 ((uintptr_t)(cmsg) >= (uintptr_t)(start)) && \ 7422712Snn35248 ((uintptr_t)(cmsg) < (uintptr_t)(end)) && \ 7432712Snn35248 ((ssize_t)(cmsg)->cmsg_len >= sizeof (struct cmsghdr)) && \ 7442712Snn35248 ((uintptr_t)(cmsg) + (cmsg)->cmsg_len <= (uintptr_t)(end))) 7450Sstevel@tonic-gate 7460Sstevel@tonic-gate /* 7470Sstevel@tonic-gate * Maximum size of any argument that is copied in (addresses, options, 7480Sstevel@tonic-gate * access rights). MUST be at least MAXPATHLEN + 3. 7490Sstevel@tonic-gate * BSD and SunOS 4.X limited this to MLEN or MCLBYTES. 7500Sstevel@tonic-gate */ 7510Sstevel@tonic-gate #define SO_MAXARGSIZE 8192 7520Sstevel@tonic-gate 7530Sstevel@tonic-gate /* 7540Sstevel@tonic-gate * Convert between vnode and sonode 7550Sstevel@tonic-gate */ 7560Sstevel@tonic-gate #define VTOSO(vp) ((struct sonode *)((vp)->v_data)) 7570Sstevel@tonic-gate #define SOTOV(sp) ((sp)->so_vnode) 7580Sstevel@tonic-gate 7590Sstevel@tonic-gate /* 7600Sstevel@tonic-gate * Internal flags for sobind() 7610Sstevel@tonic-gate */ 7620Sstevel@tonic-gate #define _SOBIND_REBIND 0x01 /* Bind to existing local address */ 7630Sstevel@tonic-gate #define _SOBIND_UNSPEC 0x02 /* Bind to unspecified address */ 7640Sstevel@tonic-gate #define _SOBIND_LOCK_HELD 0x04 /* so_excl_lock held by caller */ 7650Sstevel@tonic-gate #define _SOBIND_NOXLATE 0x08 /* No addr translation for AF_UNIX */ 7660Sstevel@tonic-gate #define _SOBIND_XPG4_2 0x10 /* xpg4.2 semantics */ 7670Sstevel@tonic-gate #define _SOBIND_SOCKBSD 0x20 /* BSD semantics */ 7680Sstevel@tonic-gate #define _SOBIND_LISTEN 0x40 /* Make into SS_ACCEPTCONN */ 7690Sstevel@tonic-gate #define _SOBIND_SOCKETPAIR 0x80 /* Internal flag for so_socketpair() */ 7700Sstevel@tonic-gate /* to enable listen with backlog = 1 */ 7710Sstevel@tonic-gate 7720Sstevel@tonic-gate /* 7730Sstevel@tonic-gate * Internal flags for sounbind() 7740Sstevel@tonic-gate */ 7750Sstevel@tonic-gate #define _SOUNBIND_REBIND 0x01 /* Don't clear fields - will rebind */ 7760Sstevel@tonic-gate 7770Sstevel@tonic-gate /* 7780Sstevel@tonic-gate * Internal flags for soconnect() 7790Sstevel@tonic-gate */ 7800Sstevel@tonic-gate #define _SOCONNECT_NOXLATE 0x01 /* No addr translation for AF_UNIX */ 7810Sstevel@tonic-gate #define _SOCONNECT_DID_BIND 0x02 /* Unbind when connect fails */ 7820Sstevel@tonic-gate #define _SOCONNECT_XPG4_2 0x04 /* xpg4.2 semantics */ 7830Sstevel@tonic-gate 7840Sstevel@tonic-gate /* 7850Sstevel@tonic-gate * Internal flags for sodisconnect() 7860Sstevel@tonic-gate */ 7870Sstevel@tonic-gate #define _SODISCONNECT_LOCK_HELD 0x01 /* so_excl_lock held by caller */ 7880Sstevel@tonic-gate 7890Sstevel@tonic-gate /* 7900Sstevel@tonic-gate * Internal flags for sotpi_getsockopt(). 7910Sstevel@tonic-gate */ 7920Sstevel@tonic-gate #define _SOGETSOCKOPT_XPG4_2 0x01 /* xpg4.2 semantics */ 7930Sstevel@tonic-gate 7940Sstevel@tonic-gate /* 7950Sstevel@tonic-gate * Internal flags for soallocproto*() 7960Sstevel@tonic-gate */ 7970Sstevel@tonic-gate #define _ALLOC_NOSLEEP 0 /* Don't sleep for memory */ 7980Sstevel@tonic-gate #define _ALLOC_INTR 1 /* Sleep until interrupt */ 7990Sstevel@tonic-gate #define _ALLOC_SLEEP 2 /* Sleep forever */ 8000Sstevel@tonic-gate 8010Sstevel@tonic-gate /* 8020Sstevel@tonic-gate * Internal structure for handling AF_UNIX file descriptor passing 8030Sstevel@tonic-gate */ 8040Sstevel@tonic-gate struct fdbuf { 8050Sstevel@tonic-gate int fd_size; /* In bytes, for kmem_free */ 8060Sstevel@tonic-gate int fd_numfd; /* Number of elements below */ 8070Sstevel@tonic-gate char *fd_ebuf; /* Extra buffer to free */ 8080Sstevel@tonic-gate int fd_ebuflen; 8090Sstevel@tonic-gate frtn_t fd_frtn; 8100Sstevel@tonic-gate struct file *fd_fds[1]; /* One or more */ 8110Sstevel@tonic-gate }; 8120Sstevel@tonic-gate #define FDBUF_HDRSIZE (sizeof (struct fdbuf) - sizeof (struct file *)) 8130Sstevel@tonic-gate 8140Sstevel@tonic-gate /* 8150Sstevel@tonic-gate * Variable that can be patched to set what version of socket socket() 8160Sstevel@tonic-gate * will create. 8170Sstevel@tonic-gate */ 8180Sstevel@tonic-gate extern int so_default_version; 8190Sstevel@tonic-gate 8200Sstevel@tonic-gate #ifdef DEBUG 8210Sstevel@tonic-gate /* Turn on extra testing capabilities */ 8220Sstevel@tonic-gate #define SOCK_TEST 8230Sstevel@tonic-gate #endif /* DEBUG */ 8240Sstevel@tonic-gate 8250Sstevel@tonic-gate #ifdef DEBUG 8260Sstevel@tonic-gate char *pr_state(uint_t, uint_t); 8270Sstevel@tonic-gate char *pr_addr(int, struct sockaddr *, t_uscalar_t); 8280Sstevel@tonic-gate int so_verify_oobstate(struct sonode *); 8290Sstevel@tonic-gate #endif /* DEBUG */ 8300Sstevel@tonic-gate 8310Sstevel@tonic-gate /* 8320Sstevel@tonic-gate * DEBUG macros 8330Sstevel@tonic-gate */ 8347632SNick.Todd@Sun.COM #if defined(DEBUG) 8350Sstevel@tonic-gate #define SOCK_DEBUG 8360Sstevel@tonic-gate 8370Sstevel@tonic-gate extern int sockdebug; 8380Sstevel@tonic-gate extern int sockprinterr; 8390Sstevel@tonic-gate 8400Sstevel@tonic-gate #define eprint(args) printf args 8410Sstevel@tonic-gate #define eprintso(so, args) \ 8420Sstevel@tonic-gate { if (sockprinterr && ((so)->so_options & SO_DEBUG)) printf args; } 8430Sstevel@tonic-gate #define eprintline(error) \ 8440Sstevel@tonic-gate { \ 8450Sstevel@tonic-gate if (error != EINTR && (sockprinterr || sockdebug > 0)) \ 8460Sstevel@tonic-gate printf("socket error %d: line %d file %s\n", \ 8470Sstevel@tonic-gate (error), __LINE__, __FILE__); \ 8480Sstevel@tonic-gate } 8490Sstevel@tonic-gate 8500Sstevel@tonic-gate #define eprintsoline(so, error) \ 8510Sstevel@tonic-gate { if (sockprinterr && ((so)->so_options & SO_DEBUG)) \ 8520Sstevel@tonic-gate printf("socket(%p) error %d: line %d file %s\n", \ 8537632SNick.Todd@Sun.COM (void *)(so), (error), __LINE__, __FILE__); \ 8540Sstevel@tonic-gate } 8550Sstevel@tonic-gate #define dprint(level, args) { if (sockdebug > (level)) printf args; } 8560Sstevel@tonic-gate #define dprintso(so, level, args) \ 8570Sstevel@tonic-gate { if (sockdebug > (level) && ((so)->so_options & SO_DEBUG)) printf args; } 8580Sstevel@tonic-gate 8597632SNick.Todd@Sun.COM #else /* define(DEBUG) */ 8600Sstevel@tonic-gate 8610Sstevel@tonic-gate #define eprint(args) {} 8620Sstevel@tonic-gate #define eprintso(so, args) {} 8630Sstevel@tonic-gate #define eprintline(error) {} 8640Sstevel@tonic-gate #define eprintsoline(so, error) {} 8650Sstevel@tonic-gate #define dprint(level, args) {} 8660Sstevel@tonic-gate #define dprintso(so, level, args) {} 8670Sstevel@tonic-gate 8687632SNick.Todd@Sun.COM #endif /* defined(DEBUG) */ 8690Sstevel@tonic-gate 8700Sstevel@tonic-gate extern struct vfsops sock_vfsops; 8718348SEric.Yu@Sun.COM extern struct vnodeops *socket_vnodeops; 8728348SEric.Yu@Sun.COM extern const struct fs_operation_def socket_vnodeops_template[]; 8730Sstevel@tonic-gate 8740Sstevel@tonic-gate extern dev_t sockdev; 8750Sstevel@tonic-gate 87612643SAnders.Persson@Sun.COM extern krwlock_t sockconf_lock; 87712643SAnders.Persson@Sun.COM 8780Sstevel@tonic-gate /* 8790Sstevel@tonic-gate * sockfs functions 8800Sstevel@tonic-gate */ 8810Sstevel@tonic-gate extern int sock_getmsg(vnode_t *, struct strbuf *, struct strbuf *, 8820Sstevel@tonic-gate uchar_t *, int *, int, rval_t *); 8830Sstevel@tonic-gate extern int sock_putmsg(vnode_t *, struct strbuf *, struct strbuf *, 8840Sstevel@tonic-gate uchar_t, int, int); 8858348SEric.Yu@Sun.COM extern int sogetvp(char *, vnode_t **, int); 8860Sstevel@tonic-gate extern int sockinit(int, char *); 8878348SEric.Yu@Sun.COM extern int solookup(int, int, int, struct sockparams **); 8880Sstevel@tonic-gate extern void so_lock_single(struct sonode *); 8890Sstevel@tonic-gate extern void so_unlock_single(struct sonode *, int); 8900Sstevel@tonic-gate extern int so_lock_read(struct sonode *, int); 8910Sstevel@tonic-gate extern int so_lock_read_intr(struct sonode *, int); 8920Sstevel@tonic-gate extern void so_unlock_read(struct sonode *); 8930Sstevel@tonic-gate extern void *sogetoff(mblk_t *, t_uscalar_t, t_uscalar_t, uint_t); 8940Sstevel@tonic-gate extern void so_getopt_srcaddr(void *, t_uscalar_t, 8950Sstevel@tonic-gate void **, t_uscalar_t *); 8960Sstevel@tonic-gate extern int so_getopt_unix_close(void *, t_uscalar_t); 8970Sstevel@tonic-gate extern void fdbuf_free(struct fdbuf *); 8980Sstevel@tonic-gate extern mblk_t *fdbuf_allocmsg(int, struct fdbuf *); 8990Sstevel@tonic-gate extern int fdbuf_create(void *, int, struct fdbuf **); 9000Sstevel@tonic-gate extern void so_closefds(void *, t_uscalar_t, int, int); 9010Sstevel@tonic-gate extern int so_getfdopt(void *, t_uscalar_t, int, void **, int *); 9020Sstevel@tonic-gate t_uscalar_t so_optlen(void *, t_uscalar_t, int); 9030Sstevel@tonic-gate extern void so_cmsg2opt(void *, t_uscalar_t, int, mblk_t *); 9040Sstevel@tonic-gate extern t_uscalar_t 9050Sstevel@tonic-gate so_cmsglen(mblk_t *, void *, t_uscalar_t, int); 9060Sstevel@tonic-gate extern int so_opt2cmsg(mblk_t *, void *, t_uscalar_t, int, 9070Sstevel@tonic-gate void *, t_uscalar_t); 9080Sstevel@tonic-gate extern void soisconnecting(struct sonode *); 9090Sstevel@tonic-gate extern void soisconnected(struct sonode *); 9100Sstevel@tonic-gate extern void soisdisconnected(struct sonode *, int); 9110Sstevel@tonic-gate extern void socantsendmore(struct sonode *); 9120Sstevel@tonic-gate extern void socantrcvmore(struct sonode *); 9130Sstevel@tonic-gate extern void soseterror(struct sonode *, int); 9148348SEric.Yu@Sun.COM extern int sogeterr(struct sonode *, boolean_t); 9150Sstevel@tonic-gate extern int sowaitconnected(struct sonode *, int, int); 9160Sstevel@tonic-gate 9170Sstevel@tonic-gate extern ssize_t soreadfile(file_t *, uchar_t *, u_offset_t, int *, size_t); 9180Sstevel@tonic-gate extern void *sock_kstat_init(zoneid_t); 9190Sstevel@tonic-gate extern void sock_kstat_fini(zoneid_t, void *); 9205227Stz204579 extern struct sonode *getsonode(int, int *, file_t **); 9210Sstevel@tonic-gate /* 9225331Samw * Function wrappers (mostly around the sonode switch) for 9230Sstevel@tonic-gate * backward compatibility. 9240Sstevel@tonic-gate */ 9250Sstevel@tonic-gate extern int soaccept(struct sonode *, int, struct sonode **); 9260Sstevel@tonic-gate extern int sobind(struct sonode *, struct sockaddr *, socklen_t, 9270Sstevel@tonic-gate int, int); 9280Sstevel@tonic-gate extern int solisten(struct sonode *, int); 92912643SAnders.Persson@Sun.COM extern int soconnect(struct sonode *, struct sockaddr *, socklen_t, 9300Sstevel@tonic-gate int, int); 9310Sstevel@tonic-gate extern int sorecvmsg(struct sonode *, struct nmsghdr *, struct uio *); 9320Sstevel@tonic-gate extern int sosendmsg(struct sonode *, struct nmsghdr *, struct uio *); 9330Sstevel@tonic-gate extern int soshutdown(struct sonode *, int); 9340Sstevel@tonic-gate extern int sogetsockopt(struct sonode *, int, int, void *, socklen_t *, 9350Sstevel@tonic-gate int); 9360Sstevel@tonic-gate extern int sosetsockopt(struct sonode *, int, int, const void *, 9370Sstevel@tonic-gate t_uscalar_t); 9380Sstevel@tonic-gate 9398348SEric.Yu@Sun.COM extern struct sonode *socreate(struct sockparams *, int, int, int, int, 9408348SEric.Yu@Sun.COM int *); 9410Sstevel@tonic-gate 9420Sstevel@tonic-gate extern int so_copyin(const void *, void *, size_t, int); 9430Sstevel@tonic-gate extern int so_copyout(const void *, void *, size_t, int); 9440Sstevel@tonic-gate 9450Sstevel@tonic-gate #endif 9460Sstevel@tonic-gate 9470Sstevel@tonic-gate /* 9480Sstevel@tonic-gate * Internal structure for obtaining sonode information from the socklist. 9490Sstevel@tonic-gate * These types match those corresponding in the sonode structure. 9500Sstevel@tonic-gate * This is not a published interface, and may change at any time. 9510Sstevel@tonic-gate */ 9520Sstevel@tonic-gate struct sockinfo { 9530Sstevel@tonic-gate uint_t si_size; /* real length of this struct */ 9540Sstevel@tonic-gate short si_family; 9550Sstevel@tonic-gate short si_type; 9560Sstevel@tonic-gate ushort_t si_flag; 9570Sstevel@tonic-gate uint_t si_state; 9580Sstevel@tonic-gate uint_t si_ux_laddr_sou_magic; 9590Sstevel@tonic-gate uint_t si_ux_faddr_sou_magic; 9600Sstevel@tonic-gate t_scalar_t si_serv_type; 9610Sstevel@tonic-gate t_uscalar_t si_laddr_soa_len; 9620Sstevel@tonic-gate t_uscalar_t si_faddr_soa_len; 9630Sstevel@tonic-gate uint16_t si_laddr_family; 9640Sstevel@tonic-gate uint16_t si_faddr_family; 9650Sstevel@tonic-gate char si_laddr_sun_path[MAXPATHLEN + 1]; /* NULL terminated */ 9660Sstevel@tonic-gate char si_faddr_sun_path[MAXPATHLEN + 1]; 9678348SEric.Yu@Sun.COM boolean_t si_faddr_noxlate; 9680Sstevel@tonic-gate zoneid_t si_szoneid; 9690Sstevel@tonic-gate }; 9700Sstevel@tonic-gate 97112643SAnders.Persson@Sun.COM /* 97212643SAnders.Persson@Sun.COM * Subcodes for sockconf() system call 97312643SAnders.Persson@Sun.COM */ 97412643SAnders.Persson@Sun.COM #define SOCKCONFIG_ADD_SOCK 0 97512643SAnders.Persson@Sun.COM #define SOCKCONFIG_REMOVE_SOCK 1 97612643SAnders.Persson@Sun.COM #define SOCKCONFIG_ADD_FILTER 2 97712643SAnders.Persson@Sun.COM #define SOCKCONFIG_REMOVE_FILTER 3 97812643SAnders.Persson@Sun.COM 97912643SAnders.Persson@Sun.COM /* 98012643SAnders.Persson@Sun.COM * Data structures for configuring socket filters. 98112643SAnders.Persson@Sun.COM */ 98212643SAnders.Persson@Sun.COM 98312643SAnders.Persson@Sun.COM /* 98412643SAnders.Persson@Sun.COM * Placement hint for automatic filters 98512643SAnders.Persson@Sun.COM */ 98612643SAnders.Persson@Sun.COM typedef enum { 98712643SAnders.Persson@Sun.COM SOF_HINT_NONE, 98812643SAnders.Persson@Sun.COM SOF_HINT_TOP, 98912643SAnders.Persson@Sun.COM SOF_HINT_BOTTOM, 99012643SAnders.Persson@Sun.COM SOF_HINT_BEFORE, 99112643SAnders.Persson@Sun.COM SOF_HINT_AFTER 99212643SAnders.Persson@Sun.COM } sof_hint_t; 99312643SAnders.Persson@Sun.COM 99412643SAnders.Persson@Sun.COM /* 99512643SAnders.Persson@Sun.COM * Socket tuple. Used by sockconfig_filter_props to list socket 99612643SAnders.Persson@Sun.COM * types of interest. 99712643SAnders.Persson@Sun.COM */ 99812643SAnders.Persson@Sun.COM typedef struct sof_socktuple { 99912643SAnders.Persson@Sun.COM int sofst_family; 100012643SAnders.Persson@Sun.COM int sofst_type; 100112643SAnders.Persson@Sun.COM int sofst_protocol; 100212643SAnders.Persson@Sun.COM } sof_socktuple_t; 100312643SAnders.Persson@Sun.COM 100412643SAnders.Persson@Sun.COM /* 100512643SAnders.Persson@Sun.COM * Socket filter properties used by sockconfig() system call. 100612643SAnders.Persson@Sun.COM */ 100712643SAnders.Persson@Sun.COM struct sockconfig_filter_props { 100812643SAnders.Persson@Sun.COM char *sfp_modname; 100912643SAnders.Persson@Sun.COM boolean_t sfp_autoattach; 101012643SAnders.Persson@Sun.COM sof_hint_t sfp_hint; 101112643SAnders.Persson@Sun.COM char *sfp_hintarg; 101212643SAnders.Persson@Sun.COM uint_t sfp_socktuple_cnt; 101312643SAnders.Persson@Sun.COM sof_socktuple_t *sfp_socktuple; 101412643SAnders.Persson@Sun.COM }; 101512643SAnders.Persson@Sun.COM 101612643SAnders.Persson@Sun.COM #ifdef _SYSCALL32 101712643SAnders.Persson@Sun.COM 101812643SAnders.Persson@Sun.COM typedef struct sof_socktuple32 { 101912643SAnders.Persson@Sun.COM int32_t sofst_family; 102012643SAnders.Persson@Sun.COM int32_t sofst_type; 102112643SAnders.Persson@Sun.COM int32_t sofst_protocol; 102212643SAnders.Persson@Sun.COM } sof_socktuple32_t; 102312643SAnders.Persson@Sun.COM 102412643SAnders.Persson@Sun.COM struct sockconfig_filter_props32 { 102512643SAnders.Persson@Sun.COM caddr32_t sfp_modname; 102612643SAnders.Persson@Sun.COM boolean_t sfp_autoattach; 102712643SAnders.Persson@Sun.COM sof_hint_t sfp_hint; 102812643SAnders.Persson@Sun.COM caddr32_t sfp_hintarg; 102912643SAnders.Persson@Sun.COM uint32_t sfp_socktuple_cnt; 103012643SAnders.Persson@Sun.COM caddr32_t sfp_socktuple; 103112643SAnders.Persson@Sun.COM }; 103212643SAnders.Persson@Sun.COM 103312643SAnders.Persson@Sun.COM #endif /* _SYSCALL32 */ 103412643SAnders.Persson@Sun.COM 10358348SEric.Yu@Sun.COM #define SOCKMOD_PATH "socketmod" /* dir where sockmods are stored */ 10360Sstevel@tonic-gate 10370Sstevel@tonic-gate #ifdef __cplusplus 10380Sstevel@tonic-gate } 10390Sstevel@tonic-gate #endif 10400Sstevel@tonic-gate 10410Sstevel@tonic-gate #endif /* _SYS_SOCKETVAR_H */ 1042