Annotation of src/sys/sys/socketvar.h, Revision 1.153
1.153 ! maxv 1: /* $NetBSD: socketvar.h,v 1.152 2018/04/19 21:19:07 christos Exp $ */
1.105 ad 2:
3: /*-
1.119 ad 4: * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
1.105 ad 5: * All rights reserved.
6: *
1.119 ad 7: * This code is derived from software contributed to The NetBSD Foundation
8: * by Andrew Doran.
9: *
1.105 ad 10: * Redistribution and use in source and binary forms, with or without
11: * modification, are permitted provided that the following conditions
12: * are met:
13: * 1. Redistributions of source code must retain the above copyright
14: * notice, this list of conditions and the following disclaimer.
15: * 2. Redistributions in binary form must reproduce the above copyright
16: * notice, this list of conditions and the following disclaimer in the
17: * documentation and/or other materials provided with the distribution.
18: *
19: * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21: * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23: * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29: * POSSIBILITY OF SUCH DAMAGE.
30: */
1.11 cgd 31:
1.1 cgd 32: /*-
1.8 mycroft 33: * Copyright (c) 1982, 1986, 1990, 1993
34: * The Regents of the University of California. All rights reserved.
1.1 cgd 35: *
36: * Redistribution and use in source and binary forms, with or without
37: * modification, are permitted provided that the following conditions
38: * are met:
39: * 1. Redistributions of source code must retain the above copyright
40: * notice, this list of conditions and the following disclaimer.
41: * 2. Redistributions in binary form must reproduce the above copyright
42: * notice, this list of conditions and the following disclaimer in the
43: * documentation and/or other materials provided with the distribution.
1.65 agc 44: * 3. Neither the name of the University nor the names of its contributors
1.1 cgd 45: * may be used to endorse or promote products derived from this software
46: * without specific prior written permission.
47: *
48: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58: * SUCH DAMAGE.
59: *
1.28 fvdl 60: * @(#)socketvar.h 8.3 (Berkeley) 2/19/95
1.1 cgd 61: */
62:
1.24 mikel 63: #ifndef _SYS_SOCKETVAR_H_
1.42 lukem 64: #define _SYS_SOCKETVAR_H_
1.24 mikel 65:
1.81 kleink 66: #include <sys/select.h>
67: #include <sys/selinfo.h> /* for struct selinfo */
1.27 thorpej 68: #include <sys/queue.h>
1.105 ad 69: #include <sys/mutex.h>
70: #include <sys/condvar.h>
1.27 thorpej 71:
1.114 pooka 72: #if !defined(_KERNEL)
1.29 matt 73: struct uio;
1.85 christos 74: struct lwp;
1.82 christos 75: struct uidinfo;
1.115 pooka 76: #else
77: #include <sys/uidinfo.h>
1.29 matt 78: #endif
79:
1.27 thorpej 80: TAILQ_HEAD(soqhead, socket);
1.3 mycroft 81:
1.1 cgd 82: /*
1.58 matt 83: * Variables for socket buffering.
84: */
85: struct sockbuf {
1.66 wrstuden 86: struct selinfo sb_sel; /* process selecting read/write */
87: struct mowner *sb_mowner; /* who owns data for this sockbuf */
1.105 ad 88: struct socket *sb_so; /* back pointer to socket */
89: kcondvar_t sb_cv; /* notifier */
1.66 wrstuden 90: /* When re-zeroing this struct, we zero from sb_startzero to the end */
91: #define sb_startzero sb_cc
1.58 matt 92: u_long sb_cc; /* actual chars in buffer */
93: u_long sb_hiwat; /* max actual char count */
94: u_long sb_mbcnt; /* chars of mbufs used */
95: u_long sb_mbmax; /* max chars of mbufs to use */
1.149 christos 96: u_long sb_lowat; /* low water mark */
1.58 matt 97: struct mbuf *sb_mb; /* the mbuf chain */
98: struct mbuf *sb_mbtail; /* the last mbuf in the chain */
99: struct mbuf *sb_lastrecord; /* first mbuf of last record in
100: socket buffer */
1.79 yamt 101: int sb_flags; /* flags, see below */
102: int sb_timeo; /* timeout for read/write */
1.80 darrenr 103: u_long sb_overflowed; /* # of drops due to full buffer */
1.58 matt 104: };
105:
106: #ifndef SB_MAX
107: #define SB_MAX (256*1024) /* default for max chars in sockbuf */
108: #endif
109:
110: #define SB_LOCK 0x01 /* lock on data queue */
1.105 ad 111: #define SB_NOTIFY 0x04 /* someone is waiting for data/space */
1.58 matt 112: #define SB_ASYNC 0x10 /* ASYNC I/O, need signals */
113: #define SB_UPCALL 0x20 /* someone wants an upcall */
114: #define SB_NOINTR 0x40 /* operations not interruptible */
115: #define SB_KNOTE 0x100 /* kernel note attached */
1.98 rmind 116: #define SB_AUTOSIZE 0x800 /* automatically size socket buffer */
1.58 matt 117:
118: /*
1.1 cgd 119: * Kernel structure per socket.
120: * Contains send and receive buffer queues,
121: * handle on protocol and pointer to protocol
122: * private data and error information.
123: */
1.135 matt 124: struct so_accf {
125: struct accept_filter *so_accept_filter;
126: void *so_accept_filter_arg; /* saved filter args */
127: char *so_accept_filter_str; /* saved user args */
128: };
129:
1.139 rtr 130: struct sockaddr;
131:
1.1 cgd 132: struct socket {
1.105 ad 133: kmutex_t * volatile so_lock; /* pointer to lock on structure */
134: kcondvar_t so_cv; /* notifier */
1.42 lukem 135: short so_type; /* generic type, see socket.h */
136: short so_options; /* from socket call, see socket.h */
1.92 christos 137: u_short so_linger; /* time to linger while closing */
1.42 lukem 138: short so_state; /* internal state flags SS_*, below */
1.128 christos 139: int so_unused; /* used to be so_nbio */
1.42 lukem 140: void *so_pcb; /* protocol control block */
1.74 matt 141: const struct protosw *so_proto; /* protocol handle */
1.1 cgd 142: /*
143: * Variables for connection queueing.
144: * Socket where accepts occur is so_head in all subsidiary sockets.
145: * If so_head is 0, socket is not related to an accept.
146: * For head socket so_q0 queues partially completed connections,
147: * while so_q is a queue of connections ready to be accepted.
148: * If a connection is aborted and it has so_head set, then
149: * it has to be pulled out of either so_q0 or so_q.
150: * We allow connections to queue up based on current queue lengths
151: * and limit on number of queued connections for this socket.
152: */
1.42 lukem 153: struct socket *so_head; /* back pointer to accept socket */
154: struct soqhead *so_onq; /* queue (q or q0) that we're on */
155: struct soqhead so_q0; /* queue of partial connections */
156: struct soqhead so_q; /* queue of incoming connections */
1.27 thorpej 157: TAILQ_ENTRY(socket) so_qe; /* our queue entry (q or q0) */
1.42 lukem 158: short so_q0len; /* partials on so_q0 */
159: short so_qlen; /* number of connections on so_q */
160: short so_qlimit; /* max number queued connections */
161: short so_timeo; /* connection timeout */
162: u_short so_error; /* error affecting connection */
1.106 ad 163: u_short so_aborting; /* references from soabort() */
1.42 lukem 164: pid_t so_pgid; /* pgid for signals */
165: u_long so_oobmark; /* chars to oob mark */
1.58 matt 166: struct sockbuf so_snd; /* send buffer */
167: struct sockbuf so_rcv; /* receive buffer */
1.1 cgd 168:
1.42 lukem 169: void *so_internal; /* Space for svr4 stream data */
1.120 tls 170: void (*so_upcall) (struct socket *, void *, int, int);
1.93 christos 171: void * so_upcallarg; /* Arg for above */
1.139 rtr 172: int (*so_send) (struct socket *, struct sockaddr *,
1.64 itojun 173: struct uio *, struct mbuf *,
1.83 christos 174: struct mbuf *, int, struct lwp *);
1.71 matt 175: int (*so_receive) (struct socket *,
1.64 itojun 176: struct mbuf **,
177: struct uio *, struct mbuf **,
1.71 matt 178: struct mbuf **, int *);
1.58 matt 179: struct mowner *so_mowner; /* who owns mbufs for this socket */
1.82 christos 180: struct uidinfo *so_uidinfo; /* who opened the socket */
1.111 yamt 181: gid_t so_egid; /* creator effective gid */
182: pid_t so_cpid; /* creator pid */
1.135 matt 183: struct so_accf *so_accf;
1.124 elad 184: kauth_cred_t so_cred; /* socket credentials */
1.1 cgd 185: };
186:
187: /*
188: * Socket state bits.
189: */
190: #define SS_NOFDREF 0x001 /* no file table ref any more */
191: #define SS_ISCONNECTED 0x002 /* socket connected to a peer */
192: #define SS_ISCONNECTING 0x004 /* in process of connecting to peer */
193: #define SS_ISDISCONNECTING 0x008 /* in process of disconnecting */
194: #define SS_CANTSENDMORE 0x010 /* can't send more data to peer */
195: #define SS_CANTRCVMORE 0x020 /* can't receive more data from peer */
196: #define SS_RCVATMARK 0x040 /* at mark on input */
1.122 dsl 197: #define SS_ISABORTING 0x080 /* aborting fd references - close() */
1.123 dsl 198: #define SS_RESTARTSYS 0x100 /* restart blocked system calls */
1.33 mycroft 199: #define SS_ISDISCONNECTED 0x800 /* socket disconnected from peer */
1.1 cgd 200:
1.19 mycroft 201: #define SS_ASYNC 0x100 /* async i/o notify */
1.42 lukem 202: #define SS_MORETOCOME 0x400 /*
203: * hint from sosend to lower layer;
204: * more data coming
205: */
1.94 yamt 206: #define SS_ISAPIPE 0x1000 /* socket is implementing a pipe */
1.127 christos 207: #define SS_NBIO 0x2000 /* socket is in non blocking I/O */
1.1 cgd 208:
1.105 ad 209: #ifdef _KERNEL
1.1 cgd 210:
1.112 tls 211: struct accept_filter {
212: char accf_name[16];
213: void (*accf_callback)
1.120 tls 214: (struct socket *, void *, int, int);
1.112 tls 215: void * (*accf_create)
1.120 tls 216: (struct socket *, char *);
1.112 tls 217: void (*accf_destroy)
1.120 tls 218: (struct socket *);
1.116 ad 219: LIST_ENTRY(accept_filter) accf_next;
220: u_int accf_refcnt;
1.112 tls 221: };
222:
1.113 plunky 223: struct sockopt {
224: int sopt_level; /* option level */
225: int sopt_name; /* option name */
226: size_t sopt_size; /* data length */
1.146 christos 227: size_t sopt_retsize; /* returned data length */
1.113 plunky 228: void * sopt_data; /* data pointer */
229: uint8_t sopt_buf[sizeof(int)]; /* internal storage */
230: };
231:
1.140 pgoyette 232: #define SB_EMPTY_FIXUP(sb) \
233: do { \
234: KASSERT(solocked((sb)->sb_so)); \
235: if ((sb)->sb_mb == NULL) { \
236: (sb)->sb_mbtail = NULL; \
237: (sb)->sb_lastrecord = NULL; \
238: } \
239: } while (/*CONSTCOND*/0)
240:
1.42 lukem 241: extern u_long sb_max;
1.63 ragge 242: extern int somaxkva;
1.88 yamt 243: extern int sock_loan_thresh;
1.105 ad 244: extern kmutex_t *softnet_lock;
1.31 thorpej 245:
1.17 christos 246: struct mbuf;
1.84 christos 247: struct lwp;
1.17 christos 248: struct msghdr;
249: struct stat;
1.55 jdolecek 250: struct knote;
1.143 christos 251: struct sockaddr_big;
1.147 christos 252: enum uio_seg;
1.17 christos 253:
1.100 dyoung 254: struct mbuf *getsombuf(struct socket *, int);
1.99 dyoung 255:
1.148 christos 256: /* 0x400 is SO_OTIMESTAMP */
257: #define SOOPT_TIMESTAMP(o) ((o) & (SO_TIMESTAMP | 0x400))
1.145 christos 258:
1.1 cgd 259: /*
260: * File operations on sockets.
261: */
1.104 ad 262: int soo_read(file_t *, off_t *, struct uio *, kauth_cred_t, int);
263: int soo_write(file_t *, off_t *, struct uio *, kauth_cred_t, int);
264: int soo_fcntl(file_t *, u_int cmd, void *);
265: int soo_ioctl(file_t *, u_long cmd, void *);
266: int soo_poll(file_t *, int);
267: int soo_kqfilter(file_t *, struct knote *);
268: int soo_close(file_t *);
269: int soo_stat(file_t *, struct stat *);
1.123 dsl 270: void soo_restart(file_t *);
1.64 itojun 271: void sbappend(struct sockbuf *, struct mbuf *);
272: void sbappendstream(struct sockbuf *, struct mbuf *);
1.73 matt 273: int sbappendaddr(struct sockbuf *, const struct sockaddr *, struct mbuf *,
1.64 itojun 274: struct mbuf *);
1.76 jonathan 275: int sbappendaddrchain(struct sockbuf *, const struct sockaddr *,
276: struct mbuf *, int);
1.64 itojun 277: int sbappendcontrol(struct sockbuf *, struct mbuf *, struct mbuf *);
278: void sbappendrecord(struct sockbuf *, struct mbuf *);
279: void sbcheck(struct sockbuf *);
280: void sbcompress(struct sockbuf *, struct mbuf *, struct mbuf *);
1.23 thorpej 281: struct mbuf *
1.93 christos 282: sbcreatecontrol(void *, int, int, int);
1.130 christos 283: struct mbuf *
284: sbcreatecontrol1(void **, int, int, int, int);
1.145 christos 285: struct mbuf **
1.153 ! maxv 286: sbsavetimestamp(int, struct mbuf **);
1.64 itojun 287: void sbdrop(struct sockbuf *, int);
288: void sbdroprecord(struct sockbuf *);
289: void sbflush(struct sockbuf *);
290: void sbinsertoob(struct sockbuf *, struct mbuf *);
1.70 christos 291: void sbrelease(struct sockbuf *, struct socket *);
292: int sbreserve(struct sockbuf *, u_long, struct socket *);
1.64 itojun 293: int sbwait(struct sockbuf *);
1.68 thorpej 294: int sb_max_set(u_long);
1.42 lukem 295: void soinit(void);
1.126 bouyer 296: void soinit1(void);
1.109 ad 297: void soinit2(void);
1.64 itojun 298: int soabort(struct socket *);
1.137 rtr 299: int soaccept(struct socket *, struct sockaddr *);
1.121 dyoung 300: int sofamily(const struct socket *);
1.136 rtr 301: int sobind(struct socket *, struct sockaddr *, struct lwp *);
1.64 itojun 302: void socantrcvmore(struct socket *);
303: void socantsendmore(struct socket *);
1.151 roy 304: void soroverflow(struct socket *);
1.64 itojun 305: int soclose(struct socket *);
1.138 rtr 306: int soconnect(struct socket *, struct sockaddr *, struct lwp *);
1.64 itojun 307: int soconnect2(struct socket *, struct socket *);
1.105 ad 308: int socreate(int, struct socket **, int, int, struct lwp *,
309: struct socket *);
1.133 rmind 310: int fsocreate(int, struct socket **, int, int, int *);
1.64 itojun 311: int sodisconnect(struct socket *);
312: void sofree(struct socket *);
1.113 plunky 313: int sogetopt(struct socket *, struct sockopt *);
1.64 itojun 314: void sohasoutofband(struct socket *);
315: void soisconnected(struct socket *);
316: void soisconnecting(struct socket *);
317: void soisdisconnected(struct socket *);
318: void soisdisconnecting(struct socket *);
1.101 elad 319: int solisten(struct socket *, int, struct lwp *);
1.7 mycroft 320: struct socket *
1.131 rmind 321: sonewconn(struct socket *, bool);
1.64 itojun 322: void soqinsque(struct socket *, struct socket *, int);
1.132 rmind 323: bool soqremque(struct socket *, int);
1.64 itojun 324: int soreceive(struct socket *, struct mbuf **, struct uio *,
325: struct mbuf **, struct mbuf **, int *);
326: int soreserve(struct socket *, u_long, u_long);
327: void sorflush(struct socket *);
1.139 rtr 328: int sosend(struct socket *, struct sockaddr *, struct uio *,
1.83 christos 329: struct mbuf *, struct mbuf *, int, struct lwp *);
1.113 plunky 330: int sosetopt(struct socket *, struct sockopt *);
331: int so_setsockopt(struct lwp *, struct socket *, int, int, const void *, size_t);
1.64 itojun 332: int soshutdown(struct socket *, int);
1.123 dsl 333: void sorestart(struct socket *);
1.67 christos 334: void sowakeup(struct socket *, struct sockbuf *, int);
1.147 christos 335: int sockargs(struct mbuf **, const void *, size_t, enum uio_seg, int);
1.103 ad 336: int sopoll(struct socket *, int);
1.105 ad 337: struct socket *soget(bool);
338: void soput(struct socket *);
1.149 christos 339: bool solocked(const struct socket *);
340: bool solocked2(const struct socket *, const struct socket *);
1.105 ad 341: int sblock(struct sockbuf *, int);
342: void sbunlock(struct sockbuf *);
1.118 yamt 343: int sowait(struct socket *, bool, int);
1.105 ad 344: void solockretry(struct socket *, kmutex_t *);
345: void sosetlock(struct socket *);
1.110 ad 346: void solockreset(struct socket *, kmutex_t *);
1.42 lukem 347:
1.113 plunky 348: void sockopt_init(struct sockopt *, int, int, size_t);
349: void sockopt_destroy(struct sockopt *);
350: int sockopt_set(struct sockopt *, const void *, size_t);
351: int sockopt_setint(struct sockopt *, int);
352: int sockopt_get(const struct sockopt *, void *, size_t);
353: int sockopt_getint(const struct sockopt *, int *);
354: int sockopt_setmbuf(struct sockopt *, struct mbuf *);
355: struct mbuf *sockopt_getmbuf(const struct sockopt *);
356:
1.96 dsl 357: int copyout_sockname(struct sockaddr *, unsigned int *, int, struct mbuf *);
1.142 christos 358: int copyout_sockname_sb(struct sockaddr *, unsigned int *,
359: int , struct sockaddr_big *);
1.96 dsl 360: int copyout_msg_control(struct lwp *, struct msghdr *, struct mbuf *);
361: void free_control_mbuf(struct lwp *, struct mbuf *, struct mbuf *);
362:
1.137 rtr 363: int do_sys_getpeername(int, struct sockaddr *);
364: int do_sys_getsockname(int, struct sockaddr *);
1.144 christos 365:
1.141 martin 366: int do_sys_sendmsg(struct lwp *, int, struct msghdr *, int,
367: const void *, size_t, register_t *);
1.144 christos 368: int do_sys_sendmsg_so(struct lwp *, int, struct socket *, file_t *,
369: struct msghdr *, int, const void *, size_t, register_t *);
370:
1.141 martin 371: int do_sys_recvmsg(struct lwp *, int, struct msghdr *,
1.144 christos 372: const void *, size_t, struct mbuf **, struct mbuf **, register_t *);
373: int do_sys_recvmsg_so(struct lwp *, int, struct socket *,
374: struct msghdr *mp, const void *, size_t, struct mbuf **,
375: struct mbuf **, register_t *);
1.52 thorpej 376:
1.136 rtr 377: int do_sys_bind(struct lwp *, int, struct sockaddr *);
1.138 rtr 378: int do_sys_connect(struct lwp *, int, struct sockaddr *);
1.137 rtr 379: int do_sys_accept(struct lwp *, int, struct sockaddr *, register_t *,
1.125 christos 380: const sigset_t *, int, int);
1.95 dsl 381:
1.105 ad 382: /*
383: * Inline functions for sockets and socket buffering.
384: */
385:
386: #include <sys/protosw.h>
387: #include <sys/mbuf.h>
388:
389: /*
390: * Do we need to notify the other side when I/O is possible?
391: */
1.152 christos 392: static __inline int
1.105 ad 393: sb_notify(struct sockbuf *sb)
394: {
395:
396: KASSERT(solocked(sb->sb_so));
397:
398: return sb->sb_flags & (SB_NOTIFY | SB_ASYNC | SB_UPCALL | SB_KNOTE);
399: }
400:
401: /*
402: * How much space is there in a socket buffer (so->so_snd or so->so_rcv)?
1.149 christos 403: * Since the fields are unsigned, detect overflow and return 0.
1.105 ad 404: */
1.152 christos 405: static __inline u_long
1.149 christos 406: sbspace(const struct sockbuf *sb)
1.105 ad 407: {
408:
409: KASSERT(solocked(sb->sb_so));
1.149 christos 410: if (sb->sb_hiwat <= sb->sb_cc || sb->sb_mbmax <= sb->sb_mbcnt)
411: return 0;
1.105 ad 412: return lmin(sb->sb_hiwat - sb->sb_cc, sb->sb_mbmax - sb->sb_mbcnt);
413: }
414:
415: /* do we have to send all at once on a socket? */
1.152 christos 416: static __inline int
1.149 christos 417: sosendallatonce(const struct socket *so)
1.105 ad 418: {
419:
420: return so->so_proto->pr_flags & PR_ATOMIC;
421: }
422:
423: /* can we read something from so? */
1.152 christos 424: static __inline int
1.149 christos 425: soreadable(const struct socket *so)
1.105 ad 426: {
427:
428: KASSERT(solocked(so));
429:
430: return so->so_rcv.sb_cc >= so->so_rcv.sb_lowat ||
431: (so->so_state & SS_CANTRCVMORE) != 0 ||
432: so->so_qlen != 0 || so->so_error != 0;
433: }
434:
435: /* can we write something to so? */
1.152 christos 436: static __inline int
1.149 christos 437: sowritable(const struct socket *so)
1.105 ad 438: {
439:
440: KASSERT(solocked(so));
441:
442: return (sbspace(&so->so_snd) >= so->so_snd.sb_lowat &&
443: ((so->so_state & SS_ISCONNECTED) != 0 ||
444: (so->so_proto->pr_flags & PR_CONNREQUIRED) == 0)) ||
445: (so->so_state & SS_CANTSENDMORE) != 0 ||
446: so->so_error != 0;
447: }
448:
449: /* adjust counters in sb reflecting allocation of m */
1.152 christos 450: static __inline void
1.105 ad 451: sballoc(struct sockbuf *sb, struct mbuf *m)
452: {
453:
454: KASSERT(solocked(sb->sb_so));
455:
456: sb->sb_cc += m->m_len;
457: sb->sb_mbcnt += MSIZE;
458: if (m->m_flags & M_EXT)
459: sb->sb_mbcnt += m->m_ext.ext_size;
460: }
461:
462: /* adjust counters in sb reflecting freeing of m */
1.152 christos 463: static __inline void
1.105 ad 464: sbfree(struct sockbuf *sb, struct mbuf *m)
465: {
466:
467: KASSERT(solocked(sb->sb_so));
468:
469: sb->sb_cc -= m->m_len;
470: sb->sb_mbcnt -= MSIZE;
471: if (m->m_flags & M_EXT)
472: sb->sb_mbcnt -= m->m_ext.ext_size;
473: }
474:
1.152 christos 475: static __inline void
1.105 ad 476: sorwakeup(struct socket *so)
477: {
478:
479: KASSERT(solocked(so));
480:
481: if (sb_notify(&so->so_rcv))
482: sowakeup(so, &so->so_rcv, POLL_IN);
483: }
484:
1.152 christos 485: static __inline void
1.105 ad 486: sowwakeup(struct socket *so)
487: {
488:
489: KASSERT(solocked(so));
490:
491: if (sb_notify(&so->so_snd))
492: sowakeup(so, &so->so_snd, POLL_OUT);
493: }
494:
1.152 christos 495: static __inline void
1.105 ad 496: solock(struct socket *so)
497: {
498: kmutex_t *lock;
499:
500: lock = so->so_lock;
501: mutex_enter(lock);
502: if (__predict_false(lock != so->so_lock))
503: solockretry(so, lock);
504: }
505:
1.152 christos 506: static __inline void
1.105 ad 507: sounlock(struct socket *so)
508: {
509:
510: mutex_exit(so->so_lock);
511: }
1.95 dsl 512:
1.52 thorpej 513: #ifdef SOCKBUF_DEBUG
1.78 yamt 514: /*
515: * SBLASTRECORDCHK: check sb->sb_lastrecord is maintained correctly.
516: * SBLASTMBUFCHK: check sb->sb_mbtail is maintained correctly.
517: *
518: * => panic if the socket buffer is inconsistent.
519: * => 'where' is used for a panic message.
520: */
1.52 thorpej 521: void sblastrecordchk(struct sockbuf *, const char *);
522: #define SBLASTRECORDCHK(sb, where) sblastrecordchk((sb), (where))
523:
524: void sblastmbufchk(struct sockbuf *, const char *);
525: #define SBLASTMBUFCHK(sb, where) sblastmbufchk((sb), (where))
1.105 ad 526: #define SBCHECK(sb) sbcheck(sb)
1.52 thorpej 527: #else
528: #define SBLASTRECORDCHK(sb, where) /* nothing */
529: #define SBLASTMBUFCHK(sb, where) /* nothing */
1.105 ad 530: #define SBCHECK(sb) /* nothing */
1.52 thorpej 531: #endif /* SOCKBUF_DEBUG */
1.60 yamt 532:
533: /* sosend loan */
1.129 matt 534: vaddr_t sokvaalloc(vaddr_t, vsize_t, struct socket *);
1.60 yamt 535: void sokvafree(vaddr_t, vsize_t);
1.93 christos 536: void soloanfree(struct mbuf *, void *, size_t, void *);
1.17 christos 537:
1.76 jonathan 538: /*
539: * Values for socket-buffer-append priority argument to sbappendaddrchain().
540: * The following flags are reserved for future implementation:
541: *
542: * SB_PRIO_NONE: honour normal socket-buffer limits.
543: *
544: * SB_PRIO_ONESHOT_OVERFLOW: if the socket has any space,
545: * deliver the entire chain. Intended for large requests
546: * that should be delivered in their entirety, or not at all.
547: *
548: * SB_PRIO_OVERDRAFT: allow a small (2*MLEN) overflow, over and
549: * aboce normal socket limits. Intended messages indicating
550: * buffer overflow in earlier normal/lower-priority messages .
551: *
552: * SB_PRIO_BESTEFFORT: Ignore limits entirely. Intended only for
553: * kernel-generated messages to specially-marked scokets which
554: * require "reliable" delivery, nd where the source socket/protocol
555: * message generator enforce some hard limit (but possibly well
556: * above kern.sbmax). It is entirely up to the in-kernel source to
557: * avoid complete mbuf exhaustion or DoS scenarios.
558: */
559: #define SB_PRIO_NONE 0
560: #define SB_PRIO_ONESHOT_OVERFLOW 1
561: #define SB_PRIO_OVERDRAFT 2
562: #define SB_PRIO_BESTEFFORT 3
563:
1.112 tls 564: /*
565: * Accept filter functions (duh).
566: */
1.116 ad 567: int accept_filt_getopt(struct socket *, struct sockopt *);
568: int accept_filt_setopt(struct socket *, const struct sockopt *);
569: int accept_filt_clear(struct socket *);
1.112 tls 570: int accept_filt_add(struct accept_filter *);
1.116 ad 571: int accept_filt_del(struct accept_filter *);
1.112 tls 572: struct accept_filter *accept_filt_get(char *);
573: #ifdef ACCEPT_FILTER_MOD
574: #ifdef SYSCTL_DECL
575: SYSCTL_DECL(_net_inet_accf);
576: #endif
577: void accept_filter_init(void);
578: #endif
579:
1.14 jtc 580: #endif /* _KERNEL */
1.24 mikel 581:
582: #endif /* !_SYS_SOCKETVAR_H_ */
CVSweb <webmaster@jp.NetBSD.org>