user_socketvar.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. /*-
  2. * Copyright (c) 1982, 1986, 1990, 1993
  3. * The Regents of the University of California. All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. Neither the name of the University nor the names of its contributors
  14. * may be used to endorse or promote products derived from this software
  15. * without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  18. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  21. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27. * SUCH DAMAGE.
  28. *
  29. */
  30. /* __Userspace__ version of <sys/socketvar.h> goes here.*/
  31. #ifndef _USER_SOCKETVAR_H_
  32. #define _USER_SOCKETVAR_H_
  33. #if defined(__APPLE__)
  34. #include <sys/types.h>
  35. #include <unistd.h>
  36. #endif
  37. /* #include <sys/selinfo.h> */ /*__Userspace__ alternative?*/ /* for struct selinfo */
  38. /* #include <sys/_lock.h> was 0 byte file */
  39. /* #include <sys/_mutex.h> was 0 byte file */
  40. /* #include <sys/_sx.h> */ /*__Userspace__ alternative?*/
  41. #if !defined(__DragonFly__) && !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(_WIN32) && !defined(__native_client__)
  42. #include <sys/uio.h>
  43. #endif
  44. #define SOCK_MAXADDRLEN 255
  45. #if !defined(MSG_NOTIFICATION)
  46. #define MSG_NOTIFICATION 0x2000 /* SCTP notification */
  47. #endif
  48. #define SCTP_SO_LINGER 0x0001
  49. #define SCTP_SO_ACCEPTCONN 0x0002
  50. #define SS_CANTRCVMORE 0x020
  51. #define SS_CANTSENDMORE 0x010
  52. #if defined(__APPLE__) || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(_WIN32) || defined(__native_client__)
  53. #define UIO_MAXIOV 1024
  54. #define ERESTART (-1)
  55. #endif
  56. #if !defined(__APPLE__) && !defined(__NetBSD__) && !defined(__OpenBSD__)
  57. enum uio_rw { UIO_READ, UIO_WRITE };
  58. #endif
  59. #if !defined(__NetBSD__) && !defined(__OpenBSD__)
  60. /* Segment flag values. */
  61. enum uio_seg {
  62. UIO_USERSPACE, /* from user data space */
  63. UIO_SYSSPACE /* from system space */
  64. };
  65. #endif
  66. struct proc {
  67. int stub; /* struct proc is a dummy for __Userspace__ */
  68. };
  69. MALLOC_DECLARE(M_ACCF);
  70. MALLOC_DECLARE(M_PCB);
  71. MALLOC_DECLARE(M_SONAME);
  72. /* __Userspace__ Are these all the fields we need?
  73. * Removing struct thread *uio_td; owner field
  74. */
  75. struct uio {
  76. struct iovec *uio_iov; /* scatter/gather list */
  77. int uio_iovcnt; /* length of scatter/gather list */
  78. off_t uio_offset; /* offset in target object */
  79. ssize_t uio_resid; /* remaining bytes to process */
  80. enum uio_seg uio_segflg; /* address space */
  81. enum uio_rw uio_rw; /* operation */
  82. };
  83. /* __Userspace__ */
  84. /*
  85. * Kernel structure per socket.
  86. * Contains send and receive buffer queues,
  87. * handle on protocol and pointer to protocol
  88. * private data and error information.
  89. */
  90. #if defined(_WIN32)
  91. #define AF_ROUTE 17
  92. #if !defined(__MINGW32__)
  93. typedef __int32 pid_t;
  94. #endif
  95. typedef unsigned __int32 uid_t;
  96. enum sigType {
  97. SIGNAL = 0,
  98. BROADCAST = 1,
  99. MAX_EVENTS = 2
  100. };
  101. #endif
  102. /*-
  103. * Locking key to struct socket:
  104. * (a) constant after allocation, no locking required.
  105. * (b) locked by SOCK_LOCK(so).
  106. * (c) locked by SOCKBUF_LOCK(&so->so_rcv).
  107. * (d) locked by SOCKBUF_LOCK(&so->so_snd).
  108. * (e) locked by ACCEPT_LOCK().
  109. * (f) not locked since integer reads/writes are atomic.
  110. * (g) used only as a sleep/wakeup address, no value.
  111. * (h) locked by global mutex so_global_mtx.
  112. */
  113. struct socket {
  114. int so_count; /* (b) reference count */
  115. short so_type; /* (a) generic type, see socket.h */
  116. short so_options; /* from socket call, see socket.h */
  117. short so_linger; /* time to linger while closing */
  118. short so_state; /* (b) internal state flags SS_* */
  119. int so_qstate; /* (e) internal state flags SQ_* */
  120. void *so_pcb; /* protocol control block */
  121. int so_dom;
  122. /*
  123. * Variables for connection queuing.
  124. * Socket where accepts occur is so_head in all subsidiary sockets.
  125. * If so_head is 0, socket is not related to an accept.
  126. * For head socket so_incomp queues partially completed connections,
  127. * while so_comp is a queue of connections ready to be accepted.
  128. * If a connection is aborted and it has so_head set, then
  129. * it has to be pulled out of either so_incomp or so_comp.
  130. * We allow connections to queue up based on current queue lengths
  131. * and limit on number of queued connections for this socket.
  132. */
  133. struct socket *so_head; /* (e) back pointer to listen socket */
  134. TAILQ_HEAD(, socket) so_incomp; /* (e) queue of partial unaccepted connections */
  135. TAILQ_HEAD(, socket) so_comp; /* (e) queue of complete unaccepted connections */
  136. TAILQ_ENTRY(socket) so_list; /* (e) list of unaccepted connections */
  137. u_short so_qlen; /* (e) number of unaccepted connections */
  138. u_short so_incqlen; /* (e) number of unaccepted incomplete
  139. connections */
  140. u_short so_qlimit; /* (e) max number queued connections */
  141. short so_timeo; /* (g) connection timeout */
  142. userland_cond_t timeo_cond; /* timeo_cond condition variable being used in wakeup */
  143. u_short so_error; /* (f) error affecting connection */
  144. struct sigio *so_sigio; /* [sg] information for async I/O or
  145. out of band data (SIGURG) */
  146. u_long so_oobmark; /* (c) chars to oob mark */
  147. TAILQ_HEAD(, aiocblist) so_aiojobq; /* AIO ops waiting on socket */
  148. /*
  149. * Variables for socket buffering.
  150. */
  151. struct sockbuf {
  152. /* __Userspace__ Many of these fields may
  153. * not be required for the sctp stack.
  154. * Commenting out the following.
  155. * Including pthread mutex and condition variable to be
  156. * used by sbwait, sorwakeup and sowwakeup.
  157. */
  158. /* struct selinfo sb_sel;*/ /* process selecting read/write */
  159. /* struct mtx sb_mtx;*/ /* sockbuf lock */
  160. /* struct sx sb_sx;*/ /* prevent I/O interlacing */
  161. userland_cond_t sb_cond; /* sockbuf condition variable */
  162. userland_mutex_t sb_mtx; /* sockbuf lock associated with sb_cond */
  163. short sb_state; /* (c/d) socket state on sockbuf */
  164. #define sb_startzero sb_mb
  165. struct mbuf *sb_mb; /* (c/d) the mbuf chain */
  166. struct mbuf *sb_mbtail; /* (c/d) the last mbuf in the chain */
  167. struct mbuf *sb_lastrecord; /* (c/d) first mbuf of last
  168. * record in socket buffer */
  169. struct mbuf *sb_sndptr; /* (c/d) pointer into mbuf chain */
  170. u_int sb_sndptroff; /* (c/d) byte offset of ptr into chain */
  171. u_int sb_cc; /* (c/d) actual chars in buffer */
  172. u_int sb_hiwat; /* (c/d) max actual char count */
  173. u_int sb_mbcnt; /* (c/d) chars of mbufs used */
  174. u_int sb_mbmax; /* (c/d) max chars of mbufs to use */
  175. u_int sb_ctl; /* (c/d) non-data chars in buffer */
  176. int sb_lowat; /* (c/d) low water mark */
  177. int sb_timeo; /* (c/d) timeout for read/write */
  178. short sb_flags; /* (c/d) flags, see below */
  179. } so_rcv, so_snd;
  180. /*
  181. * Constants for sb_flags field of struct sockbuf.
  182. */
  183. #define SB_MAX (256*1024) /* default for max chars in sockbuf */
  184. #define SB_RAW (64*1024*2) /*Aligning so->so_rcv.sb_hiwat with the receive buffer size of raw socket*/
  185. /*
  186. * Constants for sb_flags field of struct sockbuf.
  187. */
  188. #define SB_WAIT 0x04 /* someone is waiting for data/space */
  189. #define SB_SEL 0x08 /* someone is selecting */
  190. #define SB_ASYNC 0x10 /* ASYNC I/O, need signals */
  191. #define SB_UPCALL 0x20 /* someone wants an upcall */
  192. #define SB_NOINTR 0x40 /* operations not interruptible */
  193. #define SB_AIO 0x80 /* AIO operations queued */
  194. #define SB_KNOTE 0x100 /* kernel note attached */
  195. #define SB_AUTOSIZE 0x800 /* automatically size socket buffer */
  196. void (*so_upcall)(struct socket *, void *, int);
  197. void *so_upcallarg;
  198. struct ucred *so_cred; /* (a) user credentials */
  199. struct label *so_label; /* (b) MAC label for socket */
  200. struct label *so_peerlabel; /* (b) cached MAC label for peer */
  201. /* NB: generation count must not be first. */
  202. uint32_t so_gencnt; /* (h) generation count */
  203. void *so_emuldata; /* (b) private data for emulators */
  204. struct so_accf {
  205. struct accept_filter *so_accept_filter;
  206. void *so_accept_filter_arg; /* saved filter args */
  207. char *so_accept_filter_str; /* saved user args */
  208. } *so_accf;
  209. };
  210. #define SB_EMPTY_FIXUP(sb) do { \
  211. if ((sb)->sb_mb == NULL) { \
  212. (sb)->sb_mbtail = NULL; \
  213. (sb)->sb_lastrecord = NULL; \
  214. } \
  215. } while (/*CONSTCOND*/0)
  216. /*
  217. * Global accept mutex to serialize access to accept queues and
  218. * fields associated with multiple sockets. This allows us to
  219. * avoid defining a lock order between listen and accept sockets
  220. * until such time as it proves to be a good idea.
  221. */
  222. #if defined(_WIN32)
  223. extern userland_mutex_t accept_mtx;
  224. extern userland_cond_t accept_cond;
  225. #define ACCEPT_LOCK_ASSERT()
  226. #define ACCEPT_LOCK() do { \
  227. EnterCriticalSection(&accept_mtx); \
  228. } while (0)
  229. #define ACCEPT_UNLOCK() do { \
  230. LeaveCriticalSection(&accept_mtx); \
  231. } while (0)
  232. #define ACCEPT_UNLOCK_ASSERT()
  233. #else
  234. extern userland_mutex_t accept_mtx;
  235. extern userland_cond_t accept_cond;
  236. #ifdef INVARIANTS
  237. #define ACCEPT_LOCK() KASSERT(pthread_mutex_lock(&accept_mtx) == 0, ("%s: accept_mtx already locked", __func__))
  238. #define ACCEPT_UNLOCK() KASSERT(pthread_mutex_unlock(&accept_mtx) == 0, ("%s: accept_mtx not locked", __func__))
  239. #else
  240. #define ACCEPT_LOCK() (void)pthread_mutex_lock(&accept_mtx)
  241. #define ACCEPT_UNLOCK() (void)pthread_mutex_unlock(&accept_mtx)
  242. #endif
  243. #define ACCEPT_LOCK_ASSERT() \
  244. KASSERT(pthread_mutex_trylock(&accept_mtx) == EBUSY, ("%s: accept_mtx not locked", __func__))
  245. #define ACCEPT_UNLOCK_ASSERT() do { \
  246. KASSERT(pthread_mutex_trylock(&accept_mtx) == 0, ("%s: accept_mtx locked", __func__)); \
  247. (void)pthread_mutex_unlock(&accept_mtx); \
  248. } while (0)
  249. #endif
  250. /*
  251. * Per-socket buffer mutex used to protect most fields in the socket
  252. * buffer.
  253. */
  254. #define SOCKBUF_MTX(_sb) (&(_sb)->sb_mtx)
  255. #if defined(_WIN32)
  256. #define SOCKBUF_LOCK_INIT(_sb, _name) \
  257. InitializeCriticalSection(SOCKBUF_MTX(_sb))
  258. #define SOCKBUF_LOCK_DESTROY(_sb) DeleteCriticalSection(SOCKBUF_MTX(_sb))
  259. #define SOCKBUF_COND_INIT(_sb) InitializeConditionVariable((&(_sb)->sb_cond))
  260. #define SOCKBUF_COND_DESTROY(_sb) DeleteConditionVariable((&(_sb)->sb_cond))
  261. #define SOCK_COND_INIT(_so) InitializeConditionVariable((&(_so)->timeo_cond))
  262. #define SOCK_COND_DESTROY(_so) DeleteConditionVariable((&(_so)->timeo_cond))
  263. #define SOCK_COND(_so) (&(_so)->timeo_cond)
  264. #else
  265. #ifdef INVARIANTS
  266. #define SOCKBUF_LOCK_INIT(_sb, _name) do { \
  267. pthread_mutexattr_t mutex_attr; \
  268. \
  269. pthread_mutexattr_init(&mutex_attr); \
  270. pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_ERRORCHECK); \
  271. pthread_mutex_init(SOCKBUF_MTX(_sb), &mutex_attr); \
  272. pthread_mutexattr_destroy(&mutex_attr); \
  273. } while (0)
  274. #else
  275. #define SOCKBUF_LOCK_INIT(_sb, _name) \
  276. pthread_mutex_init(SOCKBUF_MTX(_sb), NULL)
  277. #endif
  278. #define SOCKBUF_LOCK_DESTROY(_sb) pthread_mutex_destroy(SOCKBUF_MTX(_sb))
  279. #define SOCKBUF_COND_INIT(_sb) pthread_cond_init((&(_sb)->sb_cond), NULL)
  280. #define SOCKBUF_COND_DESTROY(_sb) pthread_cond_destroy((&(_sb)->sb_cond))
  281. #define SOCK_COND_INIT(_so) pthread_cond_init((&(_so)->timeo_cond), NULL)
  282. #define SOCK_COND_DESTROY(_so) pthread_cond_destroy((&(_so)->timeo_cond))
  283. #define SOCK_COND(_so) (&(_so)->timeo_cond)
  284. #endif
  285. /*__Userspace__ SOCKBUF_LOCK(_sb) is now defined in netinet/sctp_process_lock.h */
  286. /* #define SOCKBUF_OWNED(_sb) mtx_owned(SOCKBUF_MTX(_sb)) unused */
  287. /*__Userspace__ SOCKBUF_UNLOCK(_sb) is now defined in netinet/sctp_process_lock.h */
  288. /*__Userspace__ SOCKBUF_LOCK_ASSERT(_sb) is now defined in netinet/sctp_process_lock.h */
  289. /* #define SOCKBUF_UNLOCK_ASSERT(_sb) mtx_assert(SOCKBUF_MTX(_sb), MA_NOTOWNED) unused */
  290. /*
  291. * Per-socket mutex: we reuse the receive socket buffer mutex for space
  292. * efficiency. This decision should probably be revisited as we optimize
  293. * locking for the socket code.
  294. */
  295. #define SOCK_MTX(_so) SOCKBUF_MTX(&(_so)->so_rcv)
  296. /*__Userspace__ SOCK_LOCK(_so) is now defined in netinet/sctp_process_lock.h */
  297. /* #define SOCK_OWNED(_so) SOCKBUF_OWNED(&(_so)->so_rcv) unused */
  298. /*__Userspace__ SOCK_UNLOCK(_so) is now defined in netinet/sctp_process_lock.h */
  299. #define SOCK_LOCK_ASSERT(_so) SOCKBUF_LOCK_ASSERT(&(_so)->so_rcv)
  300. /*
  301. * Socket state bits.
  302. *
  303. * Historically, this bits were all kept in the so_state field. For
  304. * locking reasons, they are now in multiple fields, as they are
  305. * locked differently. so_state maintains basic socket state protected
  306. * by the socket lock. so_qstate holds information about the socket
  307. * accept queues. Each socket buffer also has a state field holding
  308. * information relevant to that socket buffer (can't send, rcv). Many
  309. * fields will be read without locks to improve performance and avoid
  310. * lock order issues. However, this approach must be used with caution.
  311. */
  312. #define SS_NOFDREF 0x0001 /* no file table ref any more */
  313. #define SS_ISCONNECTED 0x0002 /* socket connected to a peer */
  314. #define SS_ISCONNECTING 0x0004 /* in process of connecting to peer */
  315. #define SS_ISDISCONNECTING 0x0008 /* in process of disconnecting */
  316. #define SS_NBIO 0x0100 /* non-blocking ops */
  317. #define SS_ASYNC 0x0200 /* async i/o notify */
  318. #define SS_ISCONFIRMING 0x0400 /* deciding to accept connection req */
  319. #define SS_ISDISCONNECTED 0x2000 /* socket disconnected from peer */
  320. /*
  321. * Protocols can mark a socket as SS_PROTOREF to indicate that, following
  322. * pru_detach, they still want the socket to persist, and will free it
  323. * themselves when they are done. Protocols should only ever call sofree()
  324. * following setting this flag in pru_detach(), and never otherwise, as
  325. * sofree() bypasses socket reference counting.
  326. */
  327. #define SS_PROTOREF 0x4000 /* strong protocol reference */
  328. /*
  329. * Socket state bits now stored in the socket buffer state field.
  330. */
  331. #define SBS_CANTSENDMORE 0x0010 /* can't send more data to peer */
  332. #define SBS_CANTRCVMORE 0x0020 /* can't receive more data from peer */
  333. #define SBS_RCVATMARK 0x0040 /* at mark on input */
  334. /*
  335. * Socket state bits stored in so_qstate.
  336. */
  337. #define SQ_INCOMP 0x0800 /* unaccepted, incomplete connection */
  338. #define SQ_COMP 0x1000 /* unaccepted, complete connection */
  339. /*
  340. * Socket event flags
  341. */
  342. #define SCTP_EVENT_READ 0x0001 /* socket is readable */
  343. #define SCTP_EVENT_WRITE 0x0002 /* socket is writeable */
  344. #define SCTP_EVENT_ERROR 0x0004 /* socket has an error state */
  345. /*-------------------------------------------------------------*/
  346. /*-------------------------------------------------------------*/
  347. /* __Userspace__ */
  348. /*-------------------------------------------------------------*/
  349. /*-------------------------------------------------------------*/
  350. /* this new __Userspace__ section is to copy portions of the _KERNEL block
  351. * above into, avoiding having to port the entire thing at once...
  352. * For function prototypes, the full bodies are in user_socket.c .
  353. */
  354. /* ---------------------------------------------------------- */
  355. /* --- function prototypes (implemented in user_socket.c) --- */
  356. /* ---------------------------------------------------------- */
  357. void soisconnecting(struct socket *so);
  358. void soisdisconnecting(struct socket *so);
  359. void soisconnected(struct socket *so);
  360. struct socket * sonewconn(struct socket *head, int connstatus);
  361. void socantrcvmore(struct socket *so);
  362. void socantsendmore(struct socket *so);
  363. void sofree(struct socket *so);
  364. /* -------------- */
  365. /* --- macros --- */
  366. /* -------------- */
  367. #define soref(so) do { \
  368. SOCK_LOCK_ASSERT(so); \
  369. ++(so)->so_count; \
  370. } while (0)
  371. #define sorele(so) do { \
  372. ACCEPT_LOCK_ASSERT(); \
  373. SOCK_LOCK_ASSERT(so); \
  374. KASSERT((so)->so_count > 0, ("sorele")); \
  375. if (--(so)->so_count == 0) \
  376. sofree(so); \
  377. else { \
  378. SOCK_UNLOCK(so); \
  379. ACCEPT_UNLOCK(); \
  380. } \
  381. } while (0)
  382. /* replacing imin with min (user_environment.h) */
  383. #define sbspace(sb) \
  384. ((long) min((int)((sb)->sb_hiwat - (sb)->sb_cc), \
  385. (int)((sb)->sb_mbmax - (sb)->sb_mbcnt)))
  386. /* do we have to send all at once on a socket? */
  387. #define sosendallatonce(so) \
  388. ((so)->so_proto->pr_flags & PR_ATOMIC)
  389. /* can we read something from so? */
  390. #define soreadable(so) \
  391. ((int)((so)->so_rcv.sb_cc) >= (so)->so_rcv.sb_lowat || \
  392. ((so)->so_rcv.sb_state & SBS_CANTRCVMORE) || \
  393. !TAILQ_EMPTY(&(so)->so_comp) || (so)->so_error)
  394. #if 0 /* original */
  395. #define PR_CONNREQUIRED 0x04 /* from sys/protosw.h "needed" for sowriteable */
  396. #define sowriteable(so) \
  397. ((sbspace(&(so)->so_snd) >= (so)->so_snd.sb_lowat && \
  398. (((so)->so_state&SS_ISCONNECTED) || \
  399. ((so)->so_proto->pr_flags&PR_CONNREQUIRED)==0)) || \
  400. ((so)->so_snd.sb_state & SBS_CANTSENDMORE) || \
  401. (so)->so_error)
  402. #else /* line with PR_CONNREQUIRED removed */
  403. /* can we write something to so? */
  404. #define sowriteable(so) \
  405. ((sbspace(&(so)->so_snd) >= (so)->so_snd.sb_lowat && \
  406. (((so)->so_state&SS_ISCONNECTED))) || \
  407. ((so)->so_snd.sb_state & SBS_CANTSENDMORE) || \
  408. (so)->so_error)
  409. #endif
  410. extern void solisten_proto(struct socket *so, int backlog);
  411. extern int solisten_proto_check(struct socket *so);
  412. extern int sctp_listen(struct socket *so, int backlog, struct proc *p);
  413. extern void socantrcvmore_locked(struct socket *so);
  414. extern int sctp_bind(struct socket *so, struct sockaddr *addr);
  415. extern int sctp6_bind(struct socket *so, struct sockaddr *addr, void *proc);
  416. extern int sctpconn_bind(struct socket *so, struct sockaddr *addr);
  417. extern int sctp_accept(struct socket *so, struct sockaddr **addr);
  418. extern int sctp_attach(struct socket *so, int proto, uint32_t vrf_id);
  419. extern int sctp6_attach(struct socket *so, int proto, uint32_t vrf_id);
  420. extern int sctp_abort(struct socket *so);
  421. extern int sctp6_abort(struct socket *so);
  422. extern void sctp_close(struct socket *so);
  423. extern int soaccept(struct socket *so, struct sockaddr **nam);
  424. extern int solisten(struct socket *so, int backlog);
  425. extern int soreserve(struct socket *so, u_long sndcc, u_long rcvcc);
  426. extern void sowakeup(struct socket *so, struct sockbuf *sb);
  427. extern void wakeup(void *ident, struct socket *so); /*__Userspace__ */
  428. extern int uiomove(void *cp, int n, struct uio *uio);
  429. extern int sbwait(struct sockbuf *sb);
  430. extern int sodisconnect(struct socket *so);
  431. extern int soconnect(struct socket *so, struct sockaddr *nam);
  432. extern int sctp_disconnect(struct socket *so);
  433. extern int sctp_connect(struct socket *so, struct sockaddr *addr);
  434. extern int sctp6_connect(struct socket *so, struct sockaddr *addr);
  435. extern int sctpconn_connect(struct socket *so, struct sockaddr *addr);
  436. extern void sctp_finish(void);
  437. /* ------------------------------------------------ */
  438. /* ----- macros copied from above ---- */
  439. /* ------------------------------------------------ */
  440. /*
  441. * Do we need to notify the other side when I/O is possible?
  442. */
  443. #define sb_notify(sb) (((sb)->sb_flags & (SB_WAIT | SB_SEL | SB_ASYNC | \
  444. SB_UPCALL | SB_AIO | SB_KNOTE)) != 0)
  445. /*
  446. * In sorwakeup() and sowwakeup(), acquire the socket buffer lock to
  447. * avoid a non-atomic test-and-wakeup. However, sowakeup is
  448. * responsible for releasing the lock if it is called. We unlock only
  449. * if we don't call into sowakeup. If any code is introduced that
  450. * directly invokes the underlying sowakeup() primitives, it must
  451. * maintain the same semantics.
  452. */
  453. #define sorwakeup_locked(so) do { \
  454. SOCKBUF_LOCK_ASSERT(&(so)->so_rcv); \
  455. if (sb_notify(&(so)->so_rcv)) \
  456. sowakeup((so), &(so)->so_rcv); \
  457. else \
  458. SOCKBUF_UNLOCK(&(so)->so_rcv); \
  459. } while (0)
  460. #define sorwakeup(so) do { \
  461. SOCKBUF_LOCK(&(so)->so_rcv); \
  462. sorwakeup_locked(so); \
  463. } while (0)
  464. #define sowwakeup_locked(so) do { \
  465. SOCKBUF_LOCK_ASSERT(&(so)->so_snd); \
  466. if (sb_notify(&(so)->so_snd)) \
  467. sowakeup((so), &(so)->so_snd); \
  468. else \
  469. SOCKBUF_UNLOCK(&(so)->so_snd); \
  470. } while (0)
  471. #define sowwakeup(so) do { \
  472. SOCKBUF_LOCK(&(so)->so_snd); \
  473. sowwakeup_locked(so); \
  474. } while (0)
  475. #endif /* !_SYS_SOCKETVAR_H_ */