Print this page
OS-4865 lxbrand async socket errors catch programs off guard
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
OS-4213 lxbrand should be able to set TCP_DEFER_ACCEPT after other socket operations

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/sys/socketvar.h
          +++ new/usr/src/uts/common/sys/socketvar.h
↓ open down ↓ 289 lines elided ↑ open up ↑
 290  290  
 291  291  #define SS_ASYNC                0x00000100 /* async i/o notify */
 292  292  #define SS_ACCEPTCONN           0x00000200 /* listen done */
 293  293  /*      unused                  0x00000400 */   /* was SS_HASCONNIND */
 294  294  #define SS_SAVEDEOR             0x00000800 /* Saved MSG_EOR rcv side state */
 295  295  
 296  296  #define SS_RCVATMARK            0x00001000 /* at mark on input */
 297  297  #define SS_OOBPEND              0x00002000 /* OOB pending or present - poll */
 298  298  #define SS_HAVEOOBDATA          0x00004000 /* OOB data present */
 299  299  #define SS_HADOOBDATA           0x00008000 /* OOB data consumed */
 300      -#define SS_CLOSING              0x00010000 /* in process of closing */
 301  300  
      301 +#define SS_CLOSING              0x00010000 /* in process of closing */
 302  302  #define SS_FIL_DEFER            0x00020000 /* filter deferred notification */
 303  303  #define SS_FILOP_OK             0x00040000 /* socket can attach filters */
 304  304  #define SS_FIL_RCV_FLOWCTRL     0x00080000 /* filter asserted rcv flow ctrl */
      305 +
 305  306  #define SS_FIL_SND_FLOWCTRL     0x00100000 /* filter asserted snd flow ctrl */
 306  307  #define SS_FIL_STOP             0x00200000 /* no more filter actions */
 307      -
 308  308  #define SS_SODIRECT             0x00400000 /* transport supports sodirect */
      309 +#define SS_FILOP_UNSF           0x00800000 /* block attaching unsafe filters */
 309  310  
 310  311  #define SS_SENTLASTREADSIG      0x01000000 /* last rx signal has been sent */
 311  312  #define SS_SENTLASTWRITESIG     0x02000000 /* last tx signal has been sent */
 312  313  
 313  314  #define SS_FALLBACK_DRAIN       0x20000000 /* data was/is being drained */
 314  315  #define SS_FALLBACK_PENDING     0x40000000 /* fallback is pending */
 315  316  #define SS_FALLBACK_COMP        0x80000000 /* fallback has completed */
 316  317  
 317  318  
 318  319  /* Set of states when the socket can't be rebound */
 319  320  #define SS_CANTREBIND   (SS_ISCONNECTED|SS_ISCONNECTING|SS_ISDISCONNECTING|\
 320  321                              SS_CANTSENDMORE|SS_CANTRCVMORE|SS_ACCEPTCONN)
 321  322  
 322  323  /*
 323  324   * Sockets that can fall back to TPI must ensure that fall back is not
 324      - * initiated while a thread is using a socket.
      325 + * initiated while a thread is using a socket. Otherwise this disables all
      326 + * future filter attachment.
 325  327   */
 326  328  #define SO_BLOCK_FALLBACK(so, fn)                               \
 327  329          ASSERT(MUTEX_NOT_HELD(&(so)->so_lock));                 \
 328  330          rw_enter(&(so)->so_fallback_rwlock, RW_READER);         \
 329  331          if ((so)->so_state & (SS_FALLBACK_COMP|SS_FILOP_OK)) {  \
 330  332                  if ((so)->so_state & SS_FALLBACK_COMP) {        \
 331  333                          rw_exit(&(so)->so_fallback_rwlock);     \
 332  334                          return (fn);                            \
 333  335                  } else {                                        \
 334  336                          mutex_enter(&(so)->so_lock);            \
 335  337                          (so)->so_state &= ~SS_FILOP_OK;         \
 336  338                          mutex_exit(&(so)->so_lock);             \
 337  339                  }                                               \
 338  340          }
 339  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 +
 340  360  #define SO_UNBLOCK_FALLBACK(so) {                       \
 341  361          rw_exit(&(so)->so_fallback_rwlock);             \
 342  362  }
 343  363  
 344  364  #define SO_SND_FLOWCTRLD(so)    \
 345  365          ((so)->so_snd_qfull || (so)->so_state & SS_FIL_SND_FLOWCTRL)
 346  366  
 347  367  /* Poll events */
 348  368  #define SO_POLLEV_IN            0x1     /* POLLIN wakeup needed */
 349  369  #define SO_POLLEV_ALWAYS        0x2     /* wakeups */
↓ open down ↓ 11 lines elided ↑ open up ↑
 361  381  #define SM_OPTDATA              0x040   /* Can handle T_OPTDATA_REQ */
 362  382  #define SM_BYTESTREAM           0x080   /* Byte stream - can use M_DATA */
 363  383  
 364  384  #define SM_ACCEPTOR_ID          0x100   /* so_acceptor_id is valid */
 365  385  
 366  386  #define SM_KERNEL               0x200   /* kernel socket */
 367  387  
 368  388  /* The modes below are only for non-streams sockets */
 369  389  #define SM_ACCEPTSUPP           0x400   /* can handle accept() */
 370  390  #define SM_SENDFILESUPP         0x800   /* Private: proto supp sendfile  */
      391 +#define SM_DEFERERR             0x1000  /* Private: defer so_error delivery */
 371  392  
 372  393  /*
 373  394   * Socket versions. Used by the socket library when calling _so_socket().
 374  395   */
 375  396  #define SOV_STREAM      0       /* Not a socket - just a stream */
 376  397  #define SOV_DEFAULT     1       /* Select based on so_default_version */
 377  398  #define SOV_SOCKSTREAM  2       /* Socket plus streams operations */
 378  399  #define SOV_SOCKBSD     3       /* Socket with no streams operations */
 379  400  #define SOV_XPG4_2      4       /* Xnet socket */
 380  401  
↓ open down ↓ 689 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX