280  */
 281 #define SS_ISCONNECTED          0x00000001 /* socket connected to a peer */
 282 #define SS_ISCONNECTING         0x00000002 /* in process, connecting to peer */
 283 #define SS_ISDISCONNECTING      0x00000004 /* in process of disconnecting */
 284 #define SS_CANTSENDMORE         0x00000008 /* can't send more data to peer */
 285 
 286 #define SS_CANTRCVMORE          0x00000010 /* can't receive more data */
 287 #define SS_ISBOUND              0x00000020 /* socket is bound */
 288 #define SS_NDELAY               0x00000040 /* FNDELAY non-blocking */
 289 #define SS_NONBLOCK             0x00000080 /* O_NONBLOCK non-blocking */
 290 
 291 #define SS_ASYNC                0x00000100 /* async i/o notify */
 292 #define SS_ACCEPTCONN           0x00000200 /* listen done */
 293 /*      unused                  0x00000400 */   /* was SS_HASCONNIND */
 294 #define SS_SAVEDEOR             0x00000800 /* Saved MSG_EOR rcv side state */
 295 
 296 #define SS_RCVATMARK            0x00001000 /* at mark on input */
 297 #define SS_OOBPEND              0x00002000 /* OOB pending or present - poll */
 298 #define SS_HAVEOOBDATA          0x00004000 /* OOB data present */
 299 #define SS_HADOOBDATA           0x00008000 /* OOB data consumed */
 300 #define SS_CLOSING              0x00010000 /* in process of closing */
 301 
 302 #define SS_FIL_DEFER            0x00020000 /* filter deferred notification */
 303 #define SS_FILOP_OK             0x00040000 /* socket can attach filters */
 304 #define SS_FIL_RCV_FLOWCTRL     0x00080000 /* filter asserted rcv flow ctrl */
 305 #define SS_FIL_SND_FLOWCTRL     0x00100000 /* filter asserted snd flow ctrl */
 306 #define SS_FIL_STOP             0x00200000 /* no more filter actions */
 307 
 308 #define SS_SODIRECT             0x00400000 /* transport supports sodirect */
 309 
 310 #define SS_SENTLASTREADSIG      0x01000000 /* last rx signal has been sent */
 311 #define SS_SENTLASTWRITESIG     0x02000000 /* last tx signal has been sent */
 312 
 313 #define SS_FALLBACK_DRAIN       0x20000000 /* data was/is being drained */
 314 #define SS_FALLBACK_PENDING     0x40000000 /* fallback is pending */
 315 #define SS_FALLBACK_COMP        0x80000000 /* fallback has completed */
 316 
 317 
 318 /* Set of states when the socket can't be rebound */
 319 #define SS_CANTREBIND   (SS_ISCONNECTED|SS_ISCONNECTING|SS_ISDISCONNECTING|\
 320                             SS_CANTSENDMORE|SS_CANTRCVMORE|SS_ACCEPTCONN)
 321 
 322 /*
 323  * Sockets that can fall back to TPI must ensure that fall back is not
 324  * initiated while a thread is using a socket.
 325  */
 326 #define SO_BLOCK_FALLBACK(so, fn)                               \
 327         ASSERT(MUTEX_NOT_HELD(&(so)->so_lock));                  \
 328         rw_enter(&(so)->so_fallback_rwlock, RW_READER);          \
 329         if ((so)->so_state & (SS_FALLBACK_COMP|SS_FILOP_OK)) {   \
 330                 if ((so)->so_state & SS_FALLBACK_COMP) { \
 331                         rw_exit(&(so)->so_fallback_rwlock);      \
 332                         return (fn);                            \
 333                 } else {                                        \
 334                         mutex_enter(&(so)->so_lock);             \
 335                         (so)->so_state &= ~SS_FILOP_OK;          \
 336                         mutex_exit(&(so)->so_lock);              \
 337                 }                                               \
 338         }
 339 
 340 #define SO_UNBLOCK_FALLBACK(so) {                       \
 341         rw_exit(&(so)->so_fallback_rwlock);              \
 342 }
 343 
 344 #define SO_SND_FLOWCTRLD(so)    \
 345         ((so)->so_snd_qfull || (so)->so_state & SS_FIL_SND_FLOWCTRL)
 346 
 347 /* Poll events */
 348 #define SO_POLLEV_IN            0x1     /* POLLIN wakeup needed */
 349 #define SO_POLLEV_ALWAYS        0x2     /* wakeups */
 350 
 351 /*
 352  * Characteristics of sockets. Not changed after the socket is created.
 353  */
 354 #define SM_PRIV                 0x001   /* privileged for broadcast, raw... */
 355 #define SM_ATOMIC               0x002   /* atomic data transmission */
 356 #define SM_ADDR                 0x004   /* addresses given with messages */
 357 #define SM_CONNREQUIRED         0x008   /* connection required by protocol */
 358 
 359 #define SM_FDPASSING            0x010   /* passes file descriptors */
 360 #define SM_EXDATA               0x020   /* Can handle T_EXDATA_REQ */
 361 #define SM_OPTDATA              0x040   /* Can handle T_OPTDATA_REQ */
 362 #define SM_BYTESTREAM           0x080   /* Byte stream - can use M_DATA */
 363 
 364 #define SM_ACCEPTOR_ID          0x100   /* so_acceptor_id is valid */
 365 
 366 #define SM_KERNEL               0x200   /* kernel socket */
 367 
 368 /* The modes below are only for non-streams sockets */
 369 #define SM_ACCEPTSUPP           0x400   /* can handle accept() */
 370 #define SM_SENDFILESUPP         0x800   /* Private: proto supp sendfile  */
 371 
 372 /*
 373  * Socket versions. Used by the socket library when calling _so_socket().
 374  */
 375 #define SOV_STREAM      0       /* Not a socket - just a stream */
 376 #define SOV_DEFAULT     1       /* Select based on so_default_version */
 377 #define SOV_SOCKSTREAM  2       /* Socket plus streams operations */
 378 #define SOV_SOCKBSD     3       /* Socket with no streams operations */
 379 #define SOV_XPG4_2      4       /* Xnet socket */
 380 
 381 #if defined(_KERNEL) || defined(_KMEMUSER)
 382 
 383 /*
 384  * sonode create and destroy functions.
 385  */
 386 typedef struct sonode *(*so_create_func_t)(struct sockparams *,
 387     int, int, int, int, int, int *, cred_t *);
 388 typedef void (*so_destroy_func_t)(struct sonode *);
 389 
 390 /* STREAM device information */
 
 | 
 
 
 280  */
 281 #define SS_ISCONNECTED          0x00000001 /* socket connected to a peer */
 282 #define SS_ISCONNECTING         0x00000002 /* in process, connecting to peer */
 283 #define SS_ISDISCONNECTING      0x00000004 /* in process of disconnecting */
 284 #define SS_CANTSENDMORE         0x00000008 /* can't send more data to peer */
 285 
 286 #define SS_CANTRCVMORE          0x00000010 /* can't receive more data */
 287 #define SS_ISBOUND              0x00000020 /* socket is bound */
 288 #define SS_NDELAY               0x00000040 /* FNDELAY non-blocking */
 289 #define SS_NONBLOCK             0x00000080 /* O_NONBLOCK non-blocking */
 290 
 291 #define SS_ASYNC                0x00000100 /* async i/o notify */
 292 #define SS_ACCEPTCONN           0x00000200 /* listen done */
 293 /*      unused                  0x00000400 */   /* was SS_HASCONNIND */
 294 #define SS_SAVEDEOR             0x00000800 /* Saved MSG_EOR rcv side state */
 295 
 296 #define SS_RCVATMARK            0x00001000 /* at mark on input */
 297 #define SS_OOBPEND              0x00002000 /* OOB pending or present - poll */
 298 #define SS_HAVEOOBDATA          0x00004000 /* OOB data present */
 299 #define SS_HADOOBDATA           0x00008000 /* OOB data consumed */
 300 
 301 #define SS_CLOSING              0x00010000 /* in process of closing */
 302 #define SS_FIL_DEFER            0x00020000 /* filter deferred notification */
 303 #define SS_FILOP_OK             0x00040000 /* socket can attach filters */
 304 #define SS_FIL_RCV_FLOWCTRL     0x00080000 /* filter asserted rcv flow ctrl */
 305 
 306 #define SS_FIL_SND_FLOWCTRL     0x00100000 /* filter asserted snd flow ctrl */
 307 #define SS_FIL_STOP             0x00200000 /* no more filter actions */
 308 #define SS_SODIRECT             0x00400000 /* transport supports sodirect */
 309 #define SS_FILOP_UNSF           0x00800000 /* block attaching unsafe filters */
 310 
 311 #define SS_SENTLASTREADSIG      0x01000000 /* last rx signal has been sent */
 312 #define SS_SENTLASTWRITESIG     0x02000000 /* last tx signal has been sent */
 313 
 314 #define SS_FALLBACK_DRAIN       0x20000000 /* data was/is being drained */
 315 #define SS_FALLBACK_PENDING     0x40000000 /* fallback is pending */
 316 #define SS_FALLBACK_COMP        0x80000000 /* fallback has completed */
 317 
 318 
 319 /* Set of states when the socket can't be rebound */
 320 #define SS_CANTREBIND   (SS_ISCONNECTED|SS_ISCONNECTING|SS_ISDISCONNECTING|\
 321                             SS_CANTSENDMORE|SS_CANTRCVMORE|SS_ACCEPTCONN)
 322 
 323 /*
 324  * Sockets that can fall back to TPI must ensure that fall back is not
 325  * initiated while a thread is using a socket. Otherwise this disables all
 326  * future filter attachment.
 327  */
 328 #define SO_BLOCK_FALLBACK(so, fn)                               \
 329         ASSERT(MUTEX_NOT_HELD(&(so)->so_lock));                  \
 330         rw_enter(&(so)->so_fallback_rwlock, RW_READER);          \
 331         if ((so)->so_state & (SS_FALLBACK_COMP|SS_FILOP_OK)) {   \
 332                 if ((so)->so_state & SS_FALLBACK_COMP) { \
 333                         rw_exit(&(so)->so_fallback_rwlock);      \
 334                         return (fn);                            \
 335                 } else {                                        \
 336                         mutex_enter(&(so)->so_lock);             \
 337                         (so)->so_state &= ~SS_FILOP_OK;          \
 338                         mutex_exit(&(so)->so_lock);              \
 339                 }                                               \
 340         }
 341 
 342 /*
 343  * Sockets that can fall back to TPI must ensure that fall back is not
 344  * initiated while a thread is using a socket. Otherwise this disables all
 345  * future unsafe filter attachment. Safe filters can still attach after
 346  * we execute the function in which this macro is used.
 347  */
 348 #define SO_BLOCK_FALLBACK_SAFE(so, fn)                          \
 349         ASSERT(MUTEX_NOT_HELD(&(so)->so_lock));                  \
 350         rw_enter(&(so)->so_fallback_rwlock, RW_READER);          \
 351         if ((so)->so_state & SS_FALLBACK_COMP) {         \
 352                 rw_exit(&(so)->so_fallback_rwlock);              \
 353                 return (fn);                                    \
 354         } else if (((so)->so_state & SS_FILOP_UNSF) == 0) {      \
 355                 mutex_enter(&(so)->so_lock);                     \
 356                 (so)->so_state |= SS_FILOP_UNSF;             \
 357                 mutex_exit(&(so)->so_lock);                      \
 358         }
 359 
 360 #define SO_UNBLOCK_FALLBACK(so) {                       \
 361         rw_exit(&(so)->so_fallback_rwlock);              \
 362 }
 363 
 364 #define SO_SND_FLOWCTRLD(so)    \
 365         ((so)->so_snd_qfull || (so)->so_state & SS_FIL_SND_FLOWCTRL)
 366 
 367 /* Poll events */
 368 #define SO_POLLEV_IN            0x1     /* POLLIN wakeup needed */
 369 #define SO_POLLEV_ALWAYS        0x2     /* wakeups */
 370 
 371 /*
 372  * Characteristics of sockets. Not changed after the socket is created.
 373  */
 374 #define SM_PRIV                 0x001   /* privileged for broadcast, raw... */
 375 #define SM_ATOMIC               0x002   /* atomic data transmission */
 376 #define SM_ADDR                 0x004   /* addresses given with messages */
 377 #define SM_CONNREQUIRED         0x008   /* connection required by protocol */
 378 
 379 #define SM_FDPASSING            0x010   /* passes file descriptors */
 380 #define SM_EXDATA               0x020   /* Can handle T_EXDATA_REQ */
 381 #define SM_OPTDATA              0x040   /* Can handle T_OPTDATA_REQ */
 382 #define SM_BYTESTREAM           0x080   /* Byte stream - can use M_DATA */
 383 
 384 #define SM_ACCEPTOR_ID          0x100   /* so_acceptor_id is valid */
 385 
 386 #define SM_KERNEL               0x200   /* kernel socket */
 387 
 388 /* The modes below are only for non-streams sockets */
 389 #define SM_ACCEPTSUPP           0x400   /* can handle accept() */
 390 #define SM_SENDFILESUPP         0x800   /* Private: proto supp sendfile  */
 391 #define SM_DEFERERR             0x1000  /* Private: defer so_error delivery */
 392 
 393 /*
 394  * Socket versions. Used by the socket library when calling _so_socket().
 395  */
 396 #define SOV_STREAM      0       /* Not a socket - just a stream */
 397 #define SOV_DEFAULT     1       /* Select based on so_default_version */
 398 #define SOV_SOCKSTREAM  2       /* Socket plus streams operations */
 399 #define SOV_SOCKBSD     3       /* Socket with no streams operations */
 400 #define SOV_XPG4_2      4       /* Xnet socket */
 401 
 402 #if defined(_KERNEL) || defined(_KMEMUSER)
 403 
 404 /*
 405  * sonode create and destroy functions.
 406  */
 407 typedef struct sonode *(*so_create_func_t)(struct sockparams *,
 408     int, int, int, int, int, int *, cred_t *);
 409 typedef void (*so_destroy_func_t)(struct sonode *);
 410 
 411 /* STREAM device information */
 
 |