1 0 stevel /* 2 0 stevel * CDDL HEADER START 3 0 stevel * 4 0 stevel * The contents of this file are subject to the terms of the 5 1548 rshoaib * Common Development and Distribution License (the "License"). 6 1548 rshoaib * You may not use this file except in compliance with the License. 7 0 stevel * 8 0 stevel * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 0 stevel * or http://www.opensolaris.org/os/licensing. 10 0 stevel * See the License for the specific language governing permissions 11 0 stevel * and limitations under the License. 12 0 stevel * 13 0 stevel * When distributing Covered Code, include this CDDL HEADER in each 14 0 stevel * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 0 stevel * If applicable, add the following below this CDDL HEADER, with the 16 0 stevel * fields enclosed by brackets "[]" replaced with your own identifying 17 0 stevel * information: Portions Copyright [yyyy] [name of copyright owner] 18 0 stevel * 19 0 stevel * CDDL HEADER END 20 0 stevel */ 21 1548 rshoaib 22 0 stevel /* 23 8941 Anders * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 24 0 stevel * Use is subject to license terms. 25 0 stevel */ 26 0 stevel 27 0 stevel /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 28 0 stevel /* All Rights Reserved */ 29 0 stevel 30 0 stevel /* 31 0 stevel * University Copyright- Copyright (c) 1982, 1986, 1988 32 0 stevel * The Regents of the University of California 33 0 stevel * All Rights Reserved 34 0 stevel * 35 0 stevel * University Acknowledgment- Portions of this document are derived from 36 0 stevel * software developed by the University of California, Berkeley, and its 37 0 stevel * contributors. 38 0 stevel */ 39 0 stevel 40 0 stevel #ifndef _SYS_SOCKETVAR_H 41 0 stevel #define _SYS_SOCKETVAR_H 42 0 stevel 43 0 stevel #include <sys/types.h> 44 0 stevel #include <sys/stream.h> 45 0 stevel #include <sys/t_lock.h> 46 0 stevel #include <sys/cred.h> 47 0 stevel #include <sys/vnode.h> 48 0 stevel #include <sys/file.h> 49 0 stevel #include <sys/param.h> 50 0 stevel #include <sys/zone.h> 51 8348 Eric #include <sys/sdt.h> 52 8348 Eric #include <sys/modctl.h> 53 8348 Eric #include <sys/atomic.h> 54 8348 Eric #include <sys/socket.h> 55 8348 Eric #include <sys/ksocket.h> 56 8964 Anders #include <sys/kstat.h> 57 9694 Scott 58 9694 Scott #ifdef _KERNEL 59 9694 Scott #include <sys/vfs_opreg.h> 60 9694 Scott #endif 61 0 stevel 62 0 stevel #ifdef __cplusplus 63 0 stevel extern "C" { 64 0 stevel #endif 65 0 stevel 66 0 stevel /* 67 0 stevel * Internal representation of the address used to represent addresses 68 0 stevel * in the loopback transport for AF_UNIX. While the sockaddr_un is used 69 0 stevel * as the sockfs layer address for AF_UNIX the pathnames contained in 70 0 stevel * these addresses are not unique (due to relative pathnames) thus can not 71 0 stevel * be used in the transport. 72 0 stevel * 73 0 stevel * The transport level address consists of a magic number (used to separate the 74 0 stevel * name space for specific and implicit binds). For a specific bind 75 0 stevel * this is followed by a "vnode *" which ensures that all specific binds 76 0 stevel * have a unique transport level address. For implicit binds the latter 77 0 stevel * part of the address is a byte string (of the same length as a pointer) 78 0 stevel * that is assigned by the loopback transport. 79 0 stevel * 80 0 stevel * The uniqueness assumes that the loopback transport has a separate namespace 81 0 stevel * for sockets in order to avoid name conflicts with e.g. TLI use of the 82 0 stevel * same transport. 83 0 stevel */ 84 0 stevel struct so_ux_addr { 85 0 stevel void *soua_vp; /* vnode pointer or assigned by tl */ 86 0 stevel uint_t soua_magic; /* See below */ 87 0 stevel }; 88 0 stevel 89 0 stevel #define SOU_MAGIC_EXPLICIT 0x75787670 /* "uxvp" */ 90 0 stevel #define SOU_MAGIC_IMPLICIT 0x616e6f6e /* "anon" */ 91 0 stevel 92 0 stevel struct sockaddr_ux { 93 0 stevel sa_family_t sou_family; /* AF_UNIX */ 94 0 stevel struct so_ux_addr sou_addr; 95 0 stevel }; 96 0 stevel 97 8348 Eric #if defined(_KERNEL) || defined(_KMEMUSER) 98 8348 Eric 99 8348 Eric #include <sys/socket_proto.h> 100 8348 Eric 101 0 stevel typedef struct sonodeops sonodeops_t; 102 741 masputra typedef struct sonode sonode_t; 103 9491 Anders 104 9491 Anders struct sodirect_s; 105 0 stevel 106 0 stevel /* 107 0 stevel * The sonode represents a socket. A sonode never exist in the file system 108 0 stevel * name space and can not be opened using open() - only the socket, socketpair 109 0 stevel * and accept calls create sonodes. 110 0 stevel * 111 8348 Eric * The locking of sockfs uses the so_lock mutex plus the SOLOCKED and 112 8348 Eric * SOREADLOCKED flags in so_flag. The mutex protects all the state in the 113 8348 Eric * sonode. It is expected that the underlying transport protocol serializes 114 8348 Eric * socket operations, so sockfs will not normally not single-thread 115 8348 Eric * operations. However, certain sockets, including TPI based ones, can only 116 8348 Eric * handle one control operation at a time. The SOLOCKED flag is used to 117 8348 Eric * single-thread operations from sockfs users to prevent e.g. multiple bind() 118 8348 Eric * calls to operate on the same sonode concurrently. The SOREADLOCKED flag is 119 8348 Eric * used to ensure that only one thread sleeps in kstrgetmsg for a given 120 8348 Eric * sonode. This is needed to ensure atomic operation for things like 121 8348 Eric * MSG_WAITALL. 122 0 stevel * 123 8348 Eric * The so_fallback_rwlock is used to ensure that for sockets that can 124 8348 Eric * fall back to TPI, the fallback is not initiated until all pending 125 8348 Eric * operations have completed. 126 0 stevel * 127 0 stevel * Note that so_lock is sometimes held across calls that might go to sleep 128 0 stevel * (kmem_alloc and soallocproto*). This implies that no other lock in 129 0 stevel * the system should be held when calling into sockfs; from the system call 130 8348 Eric * side or from strrput (in case of TPI based sockets). If locks are held 131 8348 Eric * while calling into sockfs the system might hang when running low on memory. 132 0 stevel */ 133 0 stevel struct sonode { 134 0 stevel struct vnode *so_vnode; /* vnode associated with this sonode */ 135 0 stevel 136 8348 Eric sonodeops_t *so_ops; /* operations vector for this sonode */ 137 8348 Eric void *so_priv; /* sonode private data */ 138 0 stevel 139 8348 Eric krwlock_t so_fallback_rwlock; 140 8348 Eric kmutex_t so_lock; /* protects sonode fields */ 141 0 stevel 142 0 stevel kcondvar_t so_state_cv; /* synchronize state changes */ 143 0 stevel kcondvar_t so_want_cv; /* wait due to SOLOCKED */ 144 0 stevel 145 0 stevel /* These fields are protected by so_lock */ 146 0 stevel 147 8348 Eric uint_t so_state; /* internal state flags SS_*, below */ 148 8348 Eric uint_t so_mode; /* characteristics on socket. SM_* */ 149 8348 Eric ushort_t so_flag; /* flags, see below */ 150 8348 Eric int so_count; /* count of opened references */ 151 0 stevel 152 8348 Eric sock_connid_t so_proto_connid; /* protocol generation number */ 153 0 stevel 154 8348 Eric ushort_t so_error; /* error affecting connection */ 155 8348 Eric 156 8348 Eric struct sockparams *so_sockparams; /* vnode or socket module */ 157 0 stevel /* Needed to recreate the same socket for accept */ 158 0 stevel short so_family; 159 0 stevel short so_type; 160 0 stevel short so_protocol; 161 0 stevel short so_version; /* From so_socket call */ 162 8348 Eric 163 8348 Eric /* Accept queue */ 164 8348 Eric kmutex_t so_acceptq_lock; /* protects accept queue */ 165 8348 Eric struct sonode *so_acceptq_next; /* acceptq list node */ 166 8348 Eric struct sonode *so_acceptq_head; 167 8348 Eric struct sonode **so_acceptq_tail; 168 8348 Eric unsigned int so_acceptq_len; 169 8348 Eric unsigned int so_backlog; /* Listen backlog */ 170 8348 Eric kcondvar_t so_acceptq_cv; /* wait for new conn. */ 171 0 stevel 172 0 stevel /* Options */ 173 0 stevel short so_options; /* From socket call, see socket.h */ 174 0 stevel struct linger so_linger; /* SO_LINGER value */ 175 8348 Eric #define so_sndbuf so_proto_props.sopp_txhiwat /* SO_SNDBUF value */ 176 8348 Eric #define so_sndlowat so_proto_props.sopp_txlowat /* tx low water mark */ 177 8348 Eric #define so_rcvbuf so_proto_props.sopp_rxhiwat /* SO_RCVBUF value */ 178 8348 Eric #define so_rcvlowat so_proto_props.sopp_rxlowat /* rx low water mark */ 179 8348 Eric #define so_max_addr_len so_proto_props.sopp_maxaddrlen 180 8348 Eric #define so_minpsz so_proto_props.sopp_minpsz 181 8348 Eric #define so_maxpsz so_proto_props.sopp_maxpsz 182 0 stevel 183 8465 Eric int so_xpg_rcvbuf; /* SO_RCVBUF value for XPG4 socket */ 184 8348 Eric clock_t so_sndtimeo; /* send timeout */ 185 8348 Eric clock_t so_rcvtimeo; /* recv timeout */ 186 8348 Eric 187 0 stevel mblk_t *so_oobmsg; /* outofline oob data */ 188 8348 Eric ssize_t so_oobmark; /* offset of the oob data */ 189 8348 Eric 190 0 stevel pid_t so_pgrp; /* pgrp for signals */ 191 0 stevel 192 0 stevel cred_t *so_peercred; /* connected socket peer cred */ 193 0 stevel pid_t so_cpid; /* connected socket peer cached pid */ 194 0 stevel zoneid_t so_zoneid; /* opener's zoneid */ 195 0 stevel 196 8348 Eric struct pollhead so_poll_list; /* common pollhead */ 197 8348 Eric short so_pollev; /* events that should be generated */ 198 0 stevel 199 8348 Eric /* Receive */ 200 8941 Anders unsigned int so_rcv_queued; /* # bytes on both rcv lists */ 201 8941 Anders mblk_t *so_rcv_q_head; /* processing/copyout rcv queue */ 202 8348 Eric mblk_t *so_rcv_q_last_head; 203 8941 Anders mblk_t *so_rcv_head; /* protocol prequeue */ 204 8348 Eric mblk_t *so_rcv_last_head; /* last mblk in b_next chain */ 205 8941 Anders kcondvar_t so_rcv_cv; /* wait for data */ 206 8348 Eric uint_t so_rcv_wanted; /* # of bytes wanted by app */ 207 8348 Eric timeout_id_t so_rcv_timer_tid; 208 898 kais 209 8348 Eric #define so_rcv_thresh so_proto_props.sopp_rcvthresh 210 8348 Eric #define so_rcv_timer_interval so_proto_props.sopp_rcvtimer 211 8348 Eric 212 8941 Anders kcondvar_t so_snd_cv; /* wait for snd buffers */ 213 8399 Rao uint32_t 214 8399 Rao so_snd_qfull: 1, /* Transmit full */ 215 8399 Rao so_rcv_wakeup: 1, 216 8399 Rao so_snd_wakeup: 1, 217 8399 Rao so_not_str: 1, /* B_TRUE if not streams based socket */ 218 8399 Rao so_pad_to_bit_31: 28; 219 8348 Eric 220 8348 Eric /* Communication channel with protocol */ 221 8348 Eric sock_lower_handle_t so_proto_handle; 222 8348 Eric sock_downcalls_t *so_downcalls; 223 8348 Eric 224 8348 Eric struct sock_proto_props so_proto_props; /* protocol settings */ 225 8348 Eric boolean_t so_flowctrld; /* Flow controlled */ 226 8348 Eric uint_t so_copyflag; /* Copy related flag */ 227 8348 Eric kcondvar_t so_copy_cv; /* Copy cond variable */ 228 8348 Eric 229 8348 Eric /* kernel sockets */ 230 8348 Eric ksocket_callbacks_t so_ksock_callbacks; 231 8348 Eric void *so_ksock_cb_arg; /* callback argument */ 232 8348 Eric kcondvar_t so_closing_cv; 233 6707 brutus 234 9491 Anders /* != NULL for sodirect enabled socket */ 235 9491 Anders struct sodirect_s *so_direct; 236 0 stevel }; 237 8348 Eric 238 8348 Eric #define SO_HAVE_DATA(so) \ 239 8427 Anders /* \ 240 8427 Anders * For the (tid == 0) case we must check so_rcv_{q_,}head \ 241 8427 Anders * rather than (so_rcv_queued > 0), since the latter does not \ 242 8427 Anders * take into account mblks with only control/name information. \ 243 8427 Anders */ \ 244 8427 Anders ((so)->so_rcv_timer_tid == 0 && ((so)->so_rcv_head != NULL || \ 245 8427 Anders (so)->so_rcv_q_head != NULL)) || \ 246 8348 Eric ((so)->so_state & SS_CANTRCVMORE) 247 8348 Eric 248 8348 Eric /* 249 8348 Eric * Events handled by the protocol (in case sd_poll is set) 250 8348 Eric */ 251 8348 Eric #define SO_PROTO_POLLEV (POLLIN|POLLRDNORM|POLLRDBAND) 252 8348 Eric 253 8348 Eric 254 8348 Eric #endif /* _KERNEL || _KMEMUSER */ 255 0 stevel 256 0 stevel /* flags */ 257 0 stevel #define SOMOD 0x0001 /* update socket modification time */ 258 0 stevel #define SOACC 0x0002 /* update socket access time */ 259 0 stevel 260 0 stevel #define SOLOCKED 0x0010 /* use to serialize open/closes */ 261 0 stevel #define SOREADLOCKED 0x0020 /* serialize kstrgetmsg calls */ 262 0 stevel #define SOWANT 0x0040 /* some process waiting on lock */ 263 0 stevel #define SOCLONE 0x0080 /* child of clone driver */ 264 0 stevel #define SOASYNC_UNBIND 0x0100 /* wait for ACK of async unbind */ 265 8348 Eric 266 8399 Rao #define SOCK_IS_NONSTR(so) ((so)->so_not_str) 267 0 stevel 268 0 stevel /* 269 0 stevel * Socket state bits. 270 0 stevel */ 271 0 stevel #define SS_ISCONNECTED 0x00000001 /* socket connected to a peer */ 272 0 stevel #define SS_ISCONNECTING 0x00000002 /* in process, connecting to peer */ 273 0 stevel #define SS_ISDISCONNECTING 0x00000004 /* in process of disconnecting */ 274 0 stevel #define SS_CANTSENDMORE 0x00000008 /* can't send more data to peer */ 275 0 stevel 276 0 stevel #define SS_CANTRCVMORE 0x00000010 /* can't receive more data */ 277 0 stevel #define SS_ISBOUND 0x00000020 /* socket is bound */ 278 0 stevel #define SS_NDELAY 0x00000040 /* FNDELAY non-blocking */ 279 0 stevel #define SS_NONBLOCK 0x00000080 /* O_NONBLOCK non-blocking */ 280 0 stevel 281 0 stevel #define SS_ASYNC 0x00000100 /* async i/o notify */ 282 0 stevel #define SS_ACCEPTCONN 0x00000200 /* listen done */ 283 8348 Eric /* unused 0x00000400 */ /* was SS_HASCONNIND */ 284 0 stevel #define SS_SAVEDEOR 0x00000800 /* Saved MSG_EOR rcv side state */ 285 0 stevel 286 0 stevel #define SS_RCVATMARK 0x00001000 /* at mark on input */ 287 0 stevel #define SS_OOBPEND 0x00002000 /* OOB pending or present - poll */ 288 0 stevel #define SS_HAVEOOBDATA 0x00004000 /* OOB data present */ 289 0 stevel #define SS_HADOOBDATA 0x00008000 /* OOB data consumed */ 290 8348 Eric #define SS_CLOSING 0x00010000 /* in process of closing */ 291 0 stevel 292 8348 Eric /* unused 0x00020000 */ /* was SS_FADDR_NOXLATE */ 293 8348 Eric /* unused 0x00040000 */ /* was SS_HASDATA */ 294 8348 Eric /* unused 0x00080000 */ /* was SS_DONEREAD */ 295 8348 Eric /* unused 0x00100000 */ /* was SS_MOREDATA */ 296 8348 Eric /* unused 0x00200000 */ /* was SS_DIRECT */ 297 0 stevel 298 6707 brutus #define SS_SODIRECT 0x00400000 /* transport supports sodirect */ 299 0 stevel 300 8963 Anders #define SS_SENTLASTREADSIG 0x01000000 /* last rx signal has been sent */ 301 8963 Anders #define SS_SENTLASTWRITESIG 0x02000000 /* last tx signal has been sent */ 302 8348 Eric 303 8963 Anders #define SS_FALLBACK_DRAIN 0x20000000 /* data was/is being drained */ 304 8963 Anders #define SS_FALLBACK_PENDING 0x40000000 /* fallback is pending */ 305 8963 Anders #define SS_FALLBACK_COMP 0x80000000 /* fallback has completed */ 306 8348 Eric 307 0 stevel 308 0 stevel /* Set of states when the socket can't be rebound */ 309 0 stevel #define SS_CANTREBIND (SS_ISCONNECTED|SS_ISCONNECTING|SS_ISDISCONNECTING|\ 310 0 stevel SS_CANTSENDMORE|SS_CANTRCVMORE|SS_ACCEPTCONN) 311 8348 Eric 312 8348 Eric /* 313 8348 Eric * Sockets that can fall back to TPI must ensure that fall back is not 314 8348 Eric * initiated while a thread is using a socket. 315 8348 Eric */ 316 8348 Eric #define SO_BLOCK_FALLBACK(so, fn) { \ 317 8348 Eric ASSERT(MUTEX_NOT_HELD(&(so)->so_lock)); \ 318 8348 Eric rw_enter(&(so)->so_fallback_rwlock, RW_READER); \ 319 8348 Eric if ((so)->so_state & SS_FALLBACK_COMP) { \ 320 8348 Eric rw_exit(&(so)->so_fallback_rwlock); \ 321 8348 Eric return (fn); \ 322 8348 Eric } \ 323 8348 Eric } 324 8348 Eric 325 8348 Eric #define SO_UNBLOCK_FALLBACK(so) { \ 326 8348 Eric rw_exit(&(so)->so_fallback_rwlock); \ 327 8348 Eric } 328 8348 Eric 329 8348 Eric /* Poll events */ 330 8348 Eric #define SO_POLLEV_IN 0x1 /* POLLIN wakeup needed */ 331 8348 Eric #define SO_POLLEV_ALWAYS 0x2 /* wakeups */ 332 0 stevel 333 0 stevel /* 334 0 stevel * Characteristics of sockets. Not changed after the socket is created. 335 0 stevel */ 336 0 stevel #define SM_PRIV 0x001 /* privileged for broadcast, raw... */ 337 0 stevel #define SM_ATOMIC 0x002 /* atomic data transmission */ 338 0 stevel #define SM_ADDR 0x004 /* addresses given with messages */ 339 0 stevel #define SM_CONNREQUIRED 0x008 /* connection required by protocol */ 340 0 stevel 341 0 stevel #define SM_FDPASSING 0x010 /* passes file descriptors */ 342 0 stevel #define SM_EXDATA 0x020 /* Can handle T_EXDATA_REQ */ 343 0 stevel #define SM_OPTDATA 0x040 /* Can handle T_OPTDATA_REQ */ 344 0 stevel #define SM_BYTESTREAM 0x080 /* Byte stream - can use M_DATA */ 345 0 stevel 346 0 stevel #define SM_ACCEPTOR_ID 0x100 /* so_acceptor_id is valid */ 347 0 stevel 348 8348 Eric #define SM_KERNEL 0x200 /* kernel socket */ 349 8348 Eric 350 8401 Anders /* The modes below are only for non-streams sockets */ 351 8348 Eric #define SM_ACCEPTSUPP 0x400 /* can handle accept() */ 352 8401 Anders #define SM_SENDFILESUPP 0x800 /* Private: proto supp sendfile */ 353 8348 Eric 354 0 stevel /* 355 0 stevel * Socket versions. Used by the socket library when calling _so_socket(). 356 0 stevel */ 357 0 stevel #define SOV_STREAM 0 /* Not a socket - just a stream */ 358 0 stevel #define SOV_DEFAULT 1 /* Select based on so_default_version */ 359 0 stevel #define SOV_SOCKSTREAM 2 /* Socket plus streams operations */ 360 0 stevel #define SOV_SOCKBSD 3 /* Socket with no streams operations */ 361 0 stevel #define SOV_XPG4_2 4 /* Xnet socket */ 362 0 stevel 363 0 stevel #if defined(_KERNEL) || defined(_KMEMUSER) 364 8348 Eric 365 0 stevel /* 366 8348 Eric * sonode create and destroy functions. 367 8348 Eric */ 368 8348 Eric typedef struct sonode *(*so_create_func_t)(struct sockparams *, 369 8348 Eric int, int, int, int, int, int *, cred_t *); 370 8348 Eric typedef void (*so_destroy_func_t)(struct sonode *); 371 8348 Eric 372 8348 Eric /* STREAM device information */ 373 8348 Eric typedef struct sdev_info { 374 8348 Eric char *sd_devpath; 375 8348 Eric int sd_devpathlen; /* Is 0 if sp_devpath is a static string */ 376 8348 Eric vnode_t *sd_vnode; 377 8348 Eric } sdev_info_t; 378 8348 Eric 379 8348 Eric #define SOCKMOD_VERSION 1 380 8348 Eric /* name of the TPI pseudo socket module */ 381 8348 Eric #define SOTPI_SMOD_NAME "socktpi" 382 8348 Eric 383 8348 Eric typedef struct __smod_priv_s { 384 8348 Eric so_create_func_t smodp_sock_create_func; 385 8348 Eric so_destroy_func_t smodp_sock_destroy_func; 386 8348 Eric so_proto_fallback_func_t smodp_proto_fallback_func; 387 8348 Eric } __smod_priv_t; 388 8348 Eric 389 8348 Eric /* 390 8348 Eric * Socket module register information 391 8348 Eric */ 392 8348 Eric typedef struct smod_reg_s { 393 8348 Eric int smod_version; 394 8348 Eric char *smod_name; 395 8348 Eric size_t smod_uc_version; 396 8348 Eric size_t smod_dc_version; 397 8348 Eric so_proto_create_func_t smod_proto_create_func; 398 8348 Eric 399 8348 Eric /* __smod_priv_data must be NULL */ 400 8348 Eric __smod_priv_t *__smod_priv; 401 8348 Eric } smod_reg_t; 402 8348 Eric 403 8348 Eric /* 404 8348 Eric * Socket module information 405 8348 Eric */ 406 8348 Eric typedef struct smod_info { 407 8348 Eric int smod_version; 408 8348 Eric char *smod_name; 409 8348 Eric uint_t smod_refcnt; /* # of entries */ 410 8348 Eric size_t smod_uc_version; /* upcall version */ 411 8348 Eric size_t smod_dc_version; /* down call version */ 412 8348 Eric so_proto_create_func_t smod_proto_create_func; 413 8348 Eric so_proto_fallback_func_t smod_proto_fallback_func; 414 8348 Eric so_create_func_t smod_sock_create_func; 415 8348 Eric so_destroy_func_t smod_sock_destroy_func; 416 8348 Eric list_node_t smod_node; 417 8348 Eric } smod_info_t; 418 8348 Eric 419 8964 Anders typedef struct sockparams_stats { 420 8964 Anders kstat_named_t sps_nfallback; /* # of fallbacks to TPI */ 421 8964 Anders kstat_named_t sps_nactive; /* # of active sockets */ 422 8964 Anders kstat_named_t sps_ncreate; /* total # of created sockets */ 423 8964 Anders } sockparams_stats_t; 424 8964 Anders 425 8348 Eric /* 426 8348 Eric * sockparams 427 8348 Eric * 428 8348 Eric * Used for mapping family/type/protocol to module 429 0 stevel */ 430 0 stevel struct sockparams { 431 8348 Eric /* 432 8348 Eric * The family, type, protocol, sdev_info and smod_info are 433 8348 Eric * set when the entry is created, and they will never change 434 8348 Eric * thereafter. 435 8348 Eric */ 436 8348 Eric int sp_family; 437 8348 Eric int sp_type; 438 8348 Eric int sp_protocol; 439 8348 Eric 440 8348 Eric sdev_info_t sp_sdev_info; /* STREAM device */ 441 8348 Eric char *sp_smod_name; /* socket module name */ 442 8348 Eric smod_info_t *sp_smod_info; /* socket module */ 443 8348 Eric 444 8348 Eric kmutex_t sp_lock; /* lock for refcnt */ 445 8348 Eric uint64_t sp_refcnt; /* entry reference count */ 446 8964 Anders sockparams_stats_t sp_stats; 447 8964 Anders kstat_t *sp_kstat; 448 8348 Eric 449 8348 Eric /* 450 8348 Eric * The entries below are only modified while holding 451 8348 Eric * splist_lock as a writer. 452 8348 Eric */ 453 8348 Eric int sp_flags; /* see below */ 454 8348 Eric list_node_t sp_node; 455 0 stevel }; 456 0 stevel 457 8348 Eric 458 8348 Eric /* 459 8348 Eric * sockparams flags 460 8348 Eric */ 461 8348 Eric #define SOCKPARAMS_EPHEMERAL 0x1 /* temp. entry, not on global list */ 462 8348 Eric 463 8348 Eric extern void sockparams_init(void); 464 8348 Eric extern struct sockparams *sockparams_hold_ephemeral_bydev(int, int, int, 465 8348 Eric const char *, int, int *); 466 8348 Eric extern struct sockparams *sockparams_hold_ephemeral_bymod(int, int, int, 467 8348 Eric const char *, int, int *); 468 8348 Eric extern void sockparams_ephemeral_drop_last_ref(struct sockparams *); 469 8348 Eric 470 8348 Eric extern void smod_init(void); 471 8348 Eric extern void smod_add(smod_info_t *); 472 8348 Eric extern int smod_register(const smod_reg_t *); 473 8348 Eric extern int smod_unregister(const char *); 474 8348 Eric extern smod_info_t *smod_lookup_byname(const char *); 475 8348 Eric 476 8348 Eric #define SOCKPARAMS_HAS_DEVICE(sp) \ 477 8348 Eric ((sp)->sp_sdev_info.sd_devpath != NULL) 478 8348 Eric 479 8348 Eric /* Increase the smod_info_t reference count */ 480 8348 Eric #define SMOD_INC_REF(smodp) { \ 481 8348 Eric ASSERT((smodp) != NULL); \ 482 8348 Eric DTRACE_PROBE1(smodinfo__inc__ref, struct smod_info *, (smodp)); \ 483 8348 Eric atomic_inc_uint(&(smodp)->smod_refcnt); \ 484 8348 Eric } 485 8348 Eric 486 8348 Eric /* 487 8348 Eric * Decreace the socket module entry reference count. 488 8348 Eric * When no one mapping to the entry, we try to unload the module from the 489 8348 Eric * kernel. If the module can't unload, just leave the module entry with 490 8348 Eric * a zero refcnt. 491 8348 Eric */ 492 8348 Eric #define SMOD_DEC_REF(sp, smodp) { \ 493 8348 Eric ASSERT((smodp) != NULL); \ 494 8348 Eric ASSERT((smodp)->smod_refcnt != 0); \ 495 8348 Eric atomic_dec_uint(&(smodp)->smod_refcnt); \ 496 8348 Eric /* \ 497 8348 Eric * No need to atomically check the return value because the \ 498 8348 Eric * socket module framework will verify that no one is using \ 499 8348 Eric * the module before unloading. Worst thing that can happen \ 500 8348 Eric * here is multiple calls to mod_remove_by_name(), which is OK. \ 501 8348 Eric */ \ 502 8348 Eric if ((smodp)->smod_refcnt == 0) \ 503 8348 Eric (void) mod_remove_by_name((sp)->sp_smod_name); \ 504 8348 Eric } 505 8348 Eric 506 8348 Eric /* Increase the reference count */ 507 8348 Eric #define SOCKPARAMS_INC_REF(sp) { \ 508 8348 Eric ASSERT((sp) != NULL); \ 509 8348 Eric DTRACE_PROBE1(sockparams__inc__ref, struct sockparams *, (sp)); \ 510 8348 Eric mutex_enter(&(sp)->sp_lock); \ 511 8348 Eric (sp)->sp_refcnt++; \ 512 8348 Eric ASSERT((sp)->sp_refcnt != 0); \ 513 8348 Eric mutex_exit(&(sp)->sp_lock); \ 514 8348 Eric } 515 8348 Eric 516 8348 Eric /* 517 8348 Eric * Decrease the reference count. 518 8348 Eric * 519 8348 Eric * If the sockparams is ephemeral, then the thread dropping the last ref 520 8348 Eric * count will destroy the entry. 521 8348 Eric */ 522 8348 Eric #define SOCKPARAMS_DEC_REF(sp) { \ 523 8348 Eric ASSERT((sp) != NULL); \ 524 8348 Eric DTRACE_PROBE1(sockparams__dec__ref, struct sockparams *, (sp)); \ 525 8348 Eric mutex_enter(&(sp)->sp_lock); \ 526 8348 Eric ASSERT((sp)->sp_refcnt > 0); \ 527 8348 Eric if ((sp)->sp_refcnt == 1) { \ 528 8348 Eric if ((sp)->sp_flags & SOCKPARAMS_EPHEMERAL) { \ 529 8348 Eric mutex_exit(&(sp)->sp_lock); \ 530 8348 Eric sockparams_ephemeral_drop_last_ref((sp)); \ 531 8348 Eric } else { \ 532 8348 Eric (sp)->sp_refcnt--; \ 533 8348 Eric if ((sp)->sp_smod_info != NULL) \ 534 8348 Eric SMOD_DEC_REF(sp, (sp)->sp_smod_info); \ 535 8348 Eric (sp)->sp_smod_info = NULL; \ 536 8348 Eric mutex_exit(&(sp)->sp_lock); \ 537 8348 Eric } \ 538 8348 Eric } else { \ 539 8348 Eric (sp)->sp_refcnt--; \ 540 8348 Eric mutex_exit(&(sp)->sp_lock); \ 541 8348 Eric } \ 542 8348 Eric } 543 0 stevel 544 0 stevel /* 545 0 stevel * Used to traverse the list of AF_UNIX sockets to construct the kstat 546 0 stevel * for netstat(1m). 547 0 stevel */ 548 0 stevel struct socklist { 549 0 stevel kmutex_t sl_lock; 550 0 stevel struct sonode *sl_list; 551 0 stevel }; 552 0 stevel 553 0 stevel extern struct socklist socklist; 554 0 stevel /* 555 0 stevel * ss_full_waits is the number of times the reader thread 556 0 stevel * waits when the queue is full and ss_empty_waits is the number 557 0 stevel * of times the consumer thread waits when the queue is empty. 558 0 stevel * No locks for these as they are just indicators of whether 559 0 stevel * disk or network or both is slow or fast. 560 0 stevel */ 561 0 stevel struct sendfile_stats { 562 0 stevel uint32_t ss_file_cached; 563 0 stevel uint32_t ss_file_not_cached; 564 0 stevel uint32_t ss_full_waits; 565 0 stevel uint32_t ss_empty_waits; 566 0 stevel uint32_t ss_file_segmap; 567 0 stevel }; 568 0 stevel 569 0 stevel /* 570 0 stevel * A single sendfile request is represented by snf_req. 571 0 stevel */ 572 0 stevel typedef struct snf_req { 573 0 stevel struct snf_req *sr_next; 574 0 stevel mblk_t *sr_mp_head; 575 0 stevel mblk_t *sr_mp_tail; 576 0 stevel kmutex_t sr_lock; 577 0 stevel kcondvar_t sr_cv; 578 0 stevel uint_t sr_qlen; 579 0 stevel int sr_hiwat; 580 0 stevel int sr_lowat; 581 0 stevel int sr_operation; 582 0 stevel struct vnode *sr_vp; 583 0 stevel file_t *sr_fp; 584 0 stevel ssize_t sr_maxpsz; 585 0 stevel u_offset_t sr_file_off; 586 0 stevel u_offset_t sr_file_size; 587 0 stevel #define SR_READ_DONE 0x80000000 588 0 stevel int sr_read_error; 589 0 stevel int sr_write_error; 590 0 stevel } snf_req_t; 591 0 stevel 592 0 stevel /* A queue of sendfile requests */ 593 0 stevel struct sendfile_queue { 594 0 stevel snf_req_t *snfq_req_head; 595 0 stevel snf_req_t *snfq_req_tail; 596 0 stevel kmutex_t snfq_lock; 597 0 stevel kcondvar_t snfq_cv; 598 0 stevel int snfq_svc_threads; /* # of service threads */ 599 0 stevel int snfq_idle_cnt; /* # of idling threads */ 600 0 stevel int snfq_max_threads; 601 0 stevel int snfq_req_cnt; /* Number of requests */ 602 0 stevel }; 603 0 stevel 604 0 stevel #define READ_OP 1 605 0 stevel #define SNFQ_TIMEOUT (60 * 5 * hz) /* 5 minutes */ 606 0 stevel 607 0 stevel /* Socket network operations switch */ 608 0 stevel struct sonodeops { 609 8348 Eric int (*sop_init)(struct sonode *, struct sonode *, cred_t *, 610 8348 Eric int); 611 8348 Eric int (*sop_accept)(struct sonode *, int, cred_t *, struct sonode **); 612 0 stevel int (*sop_bind)(struct sonode *, struct sockaddr *, socklen_t, 613 8348 Eric int, cred_t *); 614 8348 Eric int (*sop_listen)(struct sonode *, int, cred_t *); 615 0 stevel int (*sop_connect)(struct sonode *, const struct sockaddr *, 616 8348 Eric socklen_t, int, int, cred_t *); 617 0 stevel int (*sop_recvmsg)(struct sonode *, struct msghdr *, 618 8348 Eric struct uio *, cred_t *); 619 0 stevel int (*sop_sendmsg)(struct sonode *, struct msghdr *, 620 8348 Eric struct uio *, cred_t *); 621 8348 Eric int (*sop_sendmblk)(struct sonode *, struct msghdr *, int, 622 8348 Eric cred_t *, mblk_t **); 623 8348 Eric int (*sop_getpeername)(struct sonode *, struct sockaddr *, 624 8348 Eric socklen_t *, boolean_t, cred_t *); 625 8348 Eric int (*sop_getsockname)(struct sonode *, struct sockaddr *, 626 8348 Eric socklen_t *, cred_t *); 627 8348 Eric int (*sop_shutdown)(struct sonode *, int, cred_t *); 628 0 stevel int (*sop_getsockopt)(struct sonode *, int, int, void *, 629 8348 Eric socklen_t *, int, cred_t *); 630 0 stevel int (*sop_setsockopt)(struct sonode *, int, int, const void *, 631 8348 Eric socklen_t, cred_t *); 632 8348 Eric int (*sop_ioctl)(struct sonode *, int, intptr_t, int, 633 8348 Eric cred_t *, int32_t *); 634 8348 Eric int (*sop_poll)(struct sonode *, short, int, short *, 635 8348 Eric struct pollhead **); 636 8348 Eric int (*sop_close)(struct sonode *, int, cred_t *); 637 0 stevel }; 638 0 stevel 639 8348 Eric #define SOP_INIT(so, flag, cr, flags) \ 640 8348 Eric ((so)->so_ops->sop_init((so), (flag), (cr), (flags))) 641 8348 Eric #define SOP_ACCEPT(so, fflag, cr, nsop) \ 642 8348 Eric ((so)->so_ops->sop_accept((so), (fflag), (cr), (nsop))) 643 8348 Eric #define SOP_BIND(so, name, namelen, flags, cr) \ 644 8348 Eric ((so)->so_ops->sop_bind((so), (name), (namelen), (flags), (cr))) 645 8348 Eric #define SOP_LISTEN(so, backlog, cr) \ 646 8348 Eric ((so)->so_ops->sop_listen((so), (backlog), (cr))) 647 8348 Eric #define SOP_CONNECT(so, name, namelen, fflag, flags, cr) \ 648 8348 Eric ((so)->so_ops->sop_connect((so), (name), (namelen), (fflag), (flags), \ 649 8348 Eric (cr))) 650 8348 Eric #define SOP_RECVMSG(so, msg, uiop, cr) \ 651 8348 Eric ((so)->so_ops->sop_recvmsg((so), (msg), (uiop), (cr))) 652 8348 Eric #define SOP_SENDMSG(so, msg, uiop, cr) \ 653 8348 Eric ((so)->so_ops->sop_sendmsg((so), (msg), (uiop), (cr))) 654 8348 Eric #define SOP_SENDMBLK(so, msg, size, cr, mpp) \ 655 8348 Eric ((so)->so_ops->sop_sendmblk((so), (msg), (size), (cr), (mpp))) 656 8348 Eric #define SOP_GETPEERNAME(so, addr, addrlen, accept, cr) \ 657 8348 Eric ((so)->so_ops->sop_getpeername((so), (addr), (addrlen), (accept), (cr))) 658 8348 Eric #define SOP_GETSOCKNAME(so, addr, addrlen, cr) \ 659 8348 Eric ((so)->so_ops->sop_getsockname((so), (addr), (addrlen), (cr))) 660 8348 Eric #define SOP_SHUTDOWN(so, how, cr) \ 661 8348 Eric ((so)->so_ops->sop_shutdown((so), (how), (cr))) 662 8348 Eric #define SOP_GETSOCKOPT(so, level, optionname, optval, optlenp, flags, cr) \ 663 0 stevel ((so)->so_ops->sop_getsockopt((so), (level), (optionname), \ 664 8348 Eric (optval), (optlenp), (flags), (cr))) 665 8348 Eric #define SOP_SETSOCKOPT(so, level, optionname, optval, optlen, cr) \ 666 0 stevel ((so)->so_ops->sop_setsockopt((so), (level), (optionname), \ 667 8348 Eric (optval), (optlen), (cr))) 668 8348 Eric #define SOP_IOCTL(so, cmd, arg, mode, cr, rvalp) \ 669 8348 Eric ((so)->so_ops->sop_ioctl((so), (cmd), (arg), (mode), (cr), (rvalp))) 670 8348 Eric #define SOP_POLL(so, events, anyyet, reventsp, phpp) \ 671 8348 Eric ((so)->so_ops->sop_poll((so), (events), (anyyet), (reventsp), (phpp))) 672 8348 Eric #define SOP_CLOSE(so, flag, cr) \ 673 8348 Eric ((so)->so_ops->sop_close((so), (flag), (cr))) 674 0 stevel 675 0 stevel #endif /* defined(_KERNEL) || defined(_KMEMUSER) */ 676 0 stevel 677 0 stevel #ifdef _KERNEL 678 0 stevel 679 0 stevel #define ISALIGNED_cmsghdr(addr) \ 680 0 stevel (((uintptr_t)(addr) & (_CMSG_HDR_ALIGNMENT - 1)) == 0) 681 0 stevel 682 0 stevel #define ROUNDUP_cmsglen(len) \ 683 0 stevel (((len) + _CMSG_HDR_ALIGNMENT - 1) & ~(_CMSG_HDR_ALIGNMENT - 1)) 684 0 stevel 685 8348 Eric #define IS_NON_STREAM_SOCK(vp) \ 686 8348 Eric ((vp)->v_type == VSOCK && (vp)->v_stream == NULL) 687 0 stevel /* 688 2712 nn35248 * Macros that operate on struct cmsghdr. 689 2712 nn35248 * Used in parsing msg_control. 690 2712 nn35248 * The CMSG_VALID macro does not assume that the last option buffer is padded. 691 0 stevel */ 692 0 stevel #define CMSG_NEXT(cmsg) \ 693 0 stevel (struct cmsghdr *)((uintptr_t)(cmsg) + \ 694 0 stevel ROUNDUP_cmsglen((cmsg)->cmsg_len)) 695 2712 nn35248 #define CMSG_CONTENT(cmsg) (&((cmsg)[1])) 696 2712 nn35248 #define CMSG_CONTENTLEN(cmsg) ((cmsg)->cmsg_len - sizeof (struct cmsghdr)) 697 2712 nn35248 #define CMSG_VALID(cmsg, start, end) \ 698 2712 nn35248 (ISALIGNED_cmsghdr(cmsg) && \ 699 2712 nn35248 ((uintptr_t)(cmsg) >= (uintptr_t)(start)) && \ 700 2712 nn35248 ((uintptr_t)(cmsg) < (uintptr_t)(end)) && \ 701 2712 nn35248 ((ssize_t)(cmsg)->cmsg_len >= sizeof (struct cmsghdr)) && \ 702 2712 nn35248 ((uintptr_t)(cmsg) + (cmsg)->cmsg_len <= (uintptr_t)(end))) 703 0 stevel 704 0 stevel /* 705 0 stevel * Maximum size of any argument that is copied in (addresses, options, 706 0 stevel * access rights). MUST be at least MAXPATHLEN + 3. 707 0 stevel * BSD and SunOS 4.X limited this to MLEN or MCLBYTES. 708 0 stevel */ 709 0 stevel #define SO_MAXARGSIZE 8192 710 0 stevel 711 0 stevel /* 712 0 stevel * Convert between vnode and sonode 713 0 stevel */ 714 0 stevel #define VTOSO(vp) ((struct sonode *)((vp)->v_data)) 715 0 stevel #define SOTOV(sp) ((sp)->so_vnode) 716 0 stevel 717 0 stevel /* 718 0 stevel * Internal flags for sobind() 719 0 stevel */ 720 0 stevel #define _SOBIND_REBIND 0x01 /* Bind to existing local address */ 721 0 stevel #define _SOBIND_UNSPEC 0x02 /* Bind to unspecified address */ 722 0 stevel #define _SOBIND_LOCK_HELD 0x04 /* so_excl_lock held by caller */ 723 0 stevel #define _SOBIND_NOXLATE 0x08 /* No addr translation for AF_UNIX */ 724 0 stevel #define _SOBIND_XPG4_2 0x10 /* xpg4.2 semantics */ 725 0 stevel #define _SOBIND_SOCKBSD 0x20 /* BSD semantics */ 726 0 stevel #define _SOBIND_LISTEN 0x40 /* Make into SS_ACCEPTCONN */ 727 0 stevel #define _SOBIND_SOCKETPAIR 0x80 /* Internal flag for so_socketpair() */ 728 0 stevel /* to enable listen with backlog = 1 */ 729 0 stevel 730 0 stevel /* 731 0 stevel * Internal flags for sounbind() 732 0 stevel */ 733 0 stevel #define _SOUNBIND_REBIND 0x01 /* Don't clear fields - will rebind */ 734 0 stevel 735 0 stevel /* 736 0 stevel * Internal flags for soconnect() 737 0 stevel */ 738 0 stevel #define _SOCONNECT_NOXLATE 0x01 /* No addr translation for AF_UNIX */ 739 0 stevel #define _SOCONNECT_DID_BIND 0x02 /* Unbind when connect fails */ 740 0 stevel #define _SOCONNECT_XPG4_2 0x04 /* xpg4.2 semantics */ 741 0 stevel 742 0 stevel /* 743 0 stevel * Internal flags for sodisconnect() 744 0 stevel */ 745 0 stevel #define _SODISCONNECT_LOCK_HELD 0x01 /* so_excl_lock held by caller */ 746 0 stevel 747 0 stevel /* 748 0 stevel * Internal flags for sotpi_getsockopt(). 749 0 stevel */ 750 0 stevel #define _SOGETSOCKOPT_XPG4_2 0x01 /* xpg4.2 semantics */ 751 0 stevel 752 0 stevel /* 753 0 stevel * Internal flags for soallocproto*() 754 0 stevel */ 755 0 stevel #define _ALLOC_NOSLEEP 0 /* Don't sleep for memory */ 756 0 stevel #define _ALLOC_INTR 1 /* Sleep until interrupt */ 757 0 stevel #define _ALLOC_SLEEP 2 /* Sleep forever */ 758 0 stevel 759 0 stevel /* 760 0 stevel * Internal structure for handling AF_UNIX file descriptor passing 761 0 stevel */ 762 0 stevel struct fdbuf { 763 0 stevel int fd_size; /* In bytes, for kmem_free */ 764 0 stevel int fd_numfd; /* Number of elements below */ 765 0 stevel char *fd_ebuf; /* Extra buffer to free */ 766 0 stevel int fd_ebuflen; 767 0 stevel frtn_t fd_frtn; 768 0 stevel struct file *fd_fds[1]; /* One or more */ 769 0 stevel }; 770 0 stevel #define FDBUF_HDRSIZE (sizeof (struct fdbuf) - sizeof (struct file *)) 771 0 stevel 772 0 stevel /* 773 0 stevel * Variable that can be patched to set what version of socket socket() 774 0 stevel * will create. 775 0 stevel */ 776 0 stevel extern int so_default_version; 777 0 stevel 778 0 stevel #ifdef DEBUG 779 0 stevel /* Turn on extra testing capabilities */ 780 0 stevel #define SOCK_TEST 781 0 stevel #endif /* DEBUG */ 782 0 stevel 783 0 stevel #ifdef DEBUG 784 0 stevel char *pr_state(uint_t, uint_t); 785 0 stevel char *pr_addr(int, struct sockaddr *, t_uscalar_t); 786 0 stevel int so_verify_oobstate(struct sonode *); 787 0 stevel #endif /* DEBUG */ 788 0 stevel 789 0 stevel /* 790 0 stevel * DEBUG macros 791 0 stevel */ 792 7632 Nick #if defined(DEBUG) 793 0 stevel #define SOCK_DEBUG 794 0 stevel 795 0 stevel extern int sockdebug; 796 0 stevel extern int sockprinterr; 797 0 stevel 798 0 stevel #define eprint(args) printf args 799 0 stevel #define eprintso(so, args) \ 800 0 stevel { if (sockprinterr && ((so)->so_options & SO_DEBUG)) printf args; } 801 0 stevel #define eprintline(error) \ 802 0 stevel { \ 803 0 stevel if (error != EINTR && (sockprinterr || sockdebug > 0)) \ 804 0 stevel printf("socket error %d: line %d file %s\n", \ 805 0 stevel (error), __LINE__, __FILE__); \ 806 0 stevel } 807 0 stevel 808 0 stevel #define eprintsoline(so, error) \ 809 0 stevel { if (sockprinterr && ((so)->so_options & SO_DEBUG)) \ 810 0 stevel printf("socket(%p) error %d: line %d file %s\n", \ 811 7632 Nick (void *)(so), (error), __LINE__, __FILE__); \ 812 0 stevel } 813 0 stevel #define dprint(level, args) { if (sockdebug > (level)) printf args; } 814 0 stevel #define dprintso(so, level, args) \ 815 0 stevel { if (sockdebug > (level) && ((so)->so_options & SO_DEBUG)) printf args; } 816 0 stevel 817 7632 Nick #else /* define(DEBUG) */ 818 0 stevel 819 0 stevel #define eprint(args) {} 820 0 stevel #define eprintso(so, args) {} 821 0 stevel #define eprintline(error) {} 822 0 stevel #define eprintsoline(so, error) {} 823 0 stevel #define dprint(level, args) {} 824 0 stevel #define dprintso(so, level, args) {} 825 0 stevel 826 7632 Nick #endif /* defined(DEBUG) */ 827 0 stevel 828 0 stevel extern struct vfsops sock_vfsops; 829 8348 Eric extern struct vnodeops *socket_vnodeops; 830 8348 Eric extern const struct fs_operation_def socket_vnodeops_template[]; 831 0 stevel 832 0 stevel extern dev_t sockdev; 833 0 stevel 834 0 stevel /* 835 0 stevel * sockfs functions 836 0 stevel */ 837 0 stevel extern int sock_getmsg(vnode_t *, struct strbuf *, struct strbuf *, 838 0 stevel uchar_t *, int *, int, rval_t *); 839 0 stevel extern int sock_putmsg(vnode_t *, struct strbuf *, struct strbuf *, 840 0 stevel uchar_t, int, int); 841 8348 Eric extern int sogetvp(char *, vnode_t **, int); 842 0 stevel extern int sockinit(int, char *); 843 8348 Eric extern int soconfig(int, int, int, char *, int, char *); 844 8348 Eric extern int solookup(int, int, int, struct sockparams **); 845 0 stevel extern void so_lock_single(struct sonode *); 846 0 stevel extern void so_unlock_single(struct sonode *, int); 847 0 stevel extern int so_lock_read(struct sonode *, int); 848 0 stevel extern int so_lock_read_intr(struct sonode *, int); 849 0 stevel extern void so_unlock_read(struct sonode *); 850 0 stevel extern void *sogetoff(mblk_t *, t_uscalar_t, t_uscalar_t, uint_t); 851 0 stevel extern void so_getopt_srcaddr(void *, t_uscalar_t, 852 0 stevel void **, t_uscalar_t *); 853 0 stevel extern int so_getopt_unix_close(void *, t_uscalar_t); 854 0 stevel extern void fdbuf_free(struct fdbuf *); 855 0 stevel extern mblk_t *fdbuf_allocmsg(int, struct fdbuf *); 856 0 stevel extern int fdbuf_create(void *, int, struct fdbuf **); 857 0 stevel extern void so_closefds(void *, t_uscalar_t, int, int); 858 0 stevel extern int so_getfdopt(void *, t_uscalar_t, int, void **, int *); 859 0 stevel t_uscalar_t so_optlen(void *, t_uscalar_t, int); 860 0 stevel extern void so_cmsg2opt(void *, t_uscalar_t, int, mblk_t *); 861 0 stevel extern t_uscalar_t 862 0 stevel so_cmsglen(mblk_t *, void *, t_uscalar_t, int); 863 0 stevel extern int so_opt2cmsg(mblk_t *, void *, t_uscalar_t, int, 864 0 stevel void *, t_uscalar_t); 865 0 stevel extern void soisconnecting(struct sonode *); 866 0 stevel extern void soisconnected(struct sonode *); 867 0 stevel extern void soisdisconnected(struct sonode *, int); 868 0 stevel extern void socantsendmore(struct sonode *); 869 0 stevel extern void socantrcvmore(struct sonode *); 870 0 stevel extern void soseterror(struct sonode *, int); 871 8348 Eric extern int sogeterr(struct sonode *, boolean_t); 872 0 stevel extern int sowaitconnected(struct sonode *, int, int); 873 0 stevel 874 0 stevel extern ssize_t soreadfile(file_t *, uchar_t *, u_offset_t, int *, size_t); 875 0 stevel extern void *sock_kstat_init(zoneid_t); 876 0 stevel extern void sock_kstat_fini(zoneid_t, void *); 877 5227 tz204579 extern struct sonode *getsonode(int, int *, file_t **); 878 0 stevel /* 879 5331 amw * Function wrappers (mostly around the sonode switch) for 880 0 stevel * backward compatibility. 881 0 stevel */ 882 0 stevel extern int soaccept(struct sonode *, int, struct sonode **); 883 0 stevel extern int sobind(struct sonode *, struct sockaddr *, socklen_t, 884 0 stevel int, int); 885 0 stevel extern int solisten(struct sonode *, int); 886 0 stevel extern int soconnect(struct sonode *, const struct sockaddr *, socklen_t, 887 0 stevel int, int); 888 0 stevel extern int sorecvmsg(struct sonode *, struct nmsghdr *, struct uio *); 889 0 stevel extern int sosendmsg(struct sonode *, struct nmsghdr *, struct uio *); 890 0 stevel extern int soshutdown(struct sonode *, int); 891 0 stevel extern int sogetsockopt(struct sonode *, int, int, void *, socklen_t *, 892 0 stevel int); 893 0 stevel extern int sosetsockopt(struct sonode *, int, int, const void *, 894 0 stevel t_uscalar_t); 895 0 stevel 896 8348 Eric extern struct sonode *socreate(struct sockparams *, int, int, int, int, 897 8348 Eric int *); 898 0 stevel 899 0 stevel extern int so_copyin(const void *, void *, size_t, int); 900 0 stevel extern int so_copyout(const void *, void *, size_t, int); 901 3422 nh145002 902 0 stevel #endif 903 0 stevel 904 0 stevel /* 905 0 stevel * Internal structure for obtaining sonode information from the socklist. 906 0 stevel * These types match those corresponding in the sonode structure. 907 0 stevel * This is not a published interface, and may change at any time. 908 0 stevel */ 909 0 stevel struct sockinfo { 910 0 stevel uint_t si_size; /* real length of this struct */ 911 0 stevel short si_family; 912 0 stevel short si_type; 913 0 stevel ushort_t si_flag; 914 0 stevel uint_t si_state; 915 0 stevel uint_t si_ux_laddr_sou_magic; 916 0 stevel uint_t si_ux_faddr_sou_magic; 917 0 stevel t_scalar_t si_serv_type; 918 0 stevel t_uscalar_t si_laddr_soa_len; 919 0 stevel t_uscalar_t si_faddr_soa_len; 920 0 stevel uint16_t si_laddr_family; 921 0 stevel uint16_t si_faddr_family; 922 0 stevel char si_laddr_sun_path[MAXPATHLEN + 1]; /* NULL terminated */ 923 0 stevel char si_faddr_sun_path[MAXPATHLEN + 1]; 924 8348 Eric boolean_t si_faddr_noxlate; 925 0 stevel zoneid_t si_szoneid; 926 0 stevel }; 927 0 stevel 928 8348 Eric #define SOCKMOD_PATH "socketmod" /* dir where sockmods are stored */ 929 0 stevel 930 0 stevel #ifdef __cplusplus 931 0 stevel } 932 0 stevel #endif 933 0 stevel 934 0 stevel #endif /* _SYS_SOCKETVAR_H */ 935