1 /* $NetBSD: socketvar.h,v 1.165 2022/04/09 23:52:23 riastradh Exp $ */
2
3 /*-
4 * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Andrew Doran.
9 *
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 */
31
32 /*-
33 * Copyright (c) 1982, 1986, 1990, 1993
34 * The Regents of the University of California. All rights reserved.
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.
44 * 3. Neither the name of the University nor the names of its contributors
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 *
60 * @(#)socketvar.h 8.3 (Berkeley) 2/19/95
61 */
62
63 #ifndef _SYS_SOCKETVAR_H_
64 #define _SYS_SOCKETVAR_H_
65
66 #include <sys/select.h>
67 #include <sys/selinfo.h> /* for struct selinfo */
68 #include <sys/queue.h>
69 #include <sys/mutex.h>
70 #include <sys/condvar.h>
71
72 #if !defined(_KERNEL)
73 struct uio;
74 struct lwp;
75 struct uidinfo;
76 #else
77 #include <sys/atomic.h>
78 #include <sys/uidinfo.h>
79 #endif
80
81 TAILQ_HEAD(soqhead, socket);
82
83 /*
84 * Variables for socket buffering.
85 */
86 struct sockbuf {
87 struct selinfo sb_sel; /* process selecting read/write */
88 struct mowner *sb_mowner; /* who owns data for this sockbuf */
89 struct socket *sb_so; /* back pointer to socket */
90 kcondvar_t sb_cv; /* notifier */
91 /* When re-zeroing this struct, we zero from sb_startzero to the end */
92 #define sb_startzero sb_cc
93 u_long sb_cc; /* actual chars in buffer */
94 u_long sb_hiwat; /* max actual char count */
95 u_long sb_mbcnt; /* chars of mbufs used */
96 u_long sb_mbmax; /* max chars of mbufs to use */
97 u_long sb_lowat; /* low water mark */
98 struct mbuf *sb_mb; /* the mbuf chain */
99 struct mbuf *sb_mbtail; /* the last mbuf in the chain */
100 struct mbuf *sb_lastrecord; /* first mbuf of last record in
101 socket buffer */
102 int sb_flags; /* flags, see below */
103 int sb_timeo; /* timeout for read/write */
104 u_long sb_overflowed; /* # of drops due to full buffer */
105 };
106
107 #ifndef SB_MAX
108 #define SB_MAX (256*1024) /* default for max chars in sockbuf */
109 #endif
110
111 #define SB_LOCK 0x01 /* lock on data queue */
112 #define SB_NOTIFY 0x04 /* someone is waiting for data/space */
113 #define SB_ASYNC 0x10 /* ASYNC I/O, need signals */
114 #define SB_UPCALL 0x20 /* someone wants an upcall */
115 #define SB_NOINTR 0x40 /* operations not interruptible */
116 #define SB_KNOTE 0x100 /* kernel note attached */
117 #define SB_AUTOSIZE 0x800 /* automatically size socket buffer */
118
119 /*
120 * Kernel structure per socket.
121 * Contains send and receive buffer queues,
122 * handle on protocol and pointer to protocol
123 * private data and error information.
124 */
125 struct so_accf {
126 struct accept_filter *so_accept_filter;
127 void *so_accept_filter_arg; /* saved filter args */
128 char *so_accept_filter_str; /* saved user args */
129 };
130
131 struct sockaddr;
132
133 struct socket {
134 kmutex_t * volatile so_lock; /* pointer to lock on structure */
135 kcondvar_t so_cv; /* notifier */
136 short so_type; /* generic type, see socket.h */
137 short so_options; /* from socket call, see socket.h */
138 u_short so_linger; /* time to linger while closing */
139 short so_state; /* internal state flags SS_*, below */
140 int so_unused; /* used to be so_nbio */
141 void *so_pcb; /* protocol control block */
142 const struct protosw *so_proto; /* protocol handle */
143 /*
144 * Variables for connection queueing.
145 * Socket where accepts occur is so_head in all subsidiary sockets.
146 * If so_head is 0, socket is not related to an accept.
147 * For head socket so_q0 queues partially completed connections,
148 * while so_q is a queue of connections ready to be accepted.
149 * If a connection is aborted and it has so_head set, then
150 * it has to be pulled out of either so_q0 or so_q.
151 * We allow connections to queue up based on current queue lengths
152 * and limit on number of queued connections for this socket.
153 */
154 struct socket *so_head; /* back pointer to accept socket */
155 struct soqhead *so_onq; /* queue (q or q0) that we're on */
156 struct soqhead so_q0; /* queue of partial connections */
157 struct soqhead so_q; /* queue of incoming connections */
158 TAILQ_ENTRY(socket) so_qe; /* our queue entry (q or q0) */
159 short so_q0len; /* partials on so_q0 */
160 short so_qlen; /* number of connections on so_q */
161 short so_qlimit; /* max number queued connections */
162 short so_timeo; /* connection timeout */
163 u_short so_error; /* error affecting connection */
164 u_short so_rerror; /* error affecting receiving */
165 u_short so_aborting; /* references from soabort() */
166 pid_t so_pgid; /* pgid for signals */
167 u_long so_oobmark; /* chars to oob mark */
168 struct sockbuf so_snd; /* send buffer */
169 struct sockbuf so_rcv; /* receive buffer */
170
171 void *so_internal; /* Space for svr4 stream data */
172 void (*so_upcall) (struct socket *, void *, int, int);
173 void * so_upcallarg; /* Arg for above */
174 int (*so_send) (struct socket *, struct sockaddr *,
175 struct uio *, struct mbuf *,
176 struct mbuf *, int, struct lwp *);
177 int (*so_receive) (struct socket *,
178 struct mbuf **,
179 struct uio *, struct mbuf **,
180 struct mbuf **, int *);
181 struct mowner *so_mowner; /* who owns mbufs for this socket */
182 struct uidinfo *so_uidinfo; /* who opened the socket */
183 gid_t so_egid; /* creator effective gid */
184 pid_t so_cpid; /* creator pid */
185 struct so_accf *so_accf;
186 kauth_cred_t so_cred; /* socket credentials */
187 };
188
189 /*
190 * Socket state bits.
191 */
192 #define SS_NOFDREF 0x001 /* no file table ref any more */
193 #define SS_ISCONNECTED 0x002 /* socket connected to a peer */
194 #define SS_ISCONNECTING 0x004 /* in process of connecting to peer */
195 #define SS_ISDISCONNECTING 0x008 /* in process of disconnecting */
196 #define SS_CANTSENDMORE 0x010 /* can't send more data to peer */
197 #define SS_CANTRCVMORE 0x020 /* can't receive more data from peer */
198 #define SS_RCVATMARK 0x040 /* at mark on input */
199 #define SS_ISABORTING 0x080 /* aborting fd references - close() */
200 #define SS_RESTARTSYS 0x100 /* restart blocked system calls */
201 #define SS_POLLRDBAND 0x200 /* poll should return POLLRDBAND */
202 #define SS_MORETOCOME 0x400 /*
203 * hint from sosend to lower layer;
204 * more data coming
205 */
206 #define SS_ISDISCONNECTED 0x800 /* socket disconnected from peer */
207 #define SS_ISAPIPE 0x1000 /* socket is implementing a pipe */
208 #define SS_NBIO 0x2000 /* socket is in non blocking I/O */
209
210 #ifdef _KERNEL
211
212 struct accept_filter {
213 char accf_name[16];
214 void (*accf_callback)
215 (struct socket *, void *, int, int);
216 void * (*accf_create)
217 (struct socket *, char *);
218 void (*accf_destroy)
219 (struct socket *);
220 LIST_ENTRY(accept_filter) accf_next;
221 u_int accf_refcnt;
222 };
223
224 struct sockopt {
225 int sopt_level; /* option level */
226 int sopt_name; /* option name */
227 size_t sopt_size; /* data length */
228 size_t sopt_retsize; /* returned data length */
229 void * sopt_data; /* data pointer */
230 uint8_t sopt_buf[sizeof(int)]; /* internal storage */
231 };
232
233 #define SB_EMPTY_FIXUP(sb) \
234 do { \
235 KASSERT(solocked((sb)->sb_so)); \
236 if ((sb)->sb_mb == NULL) { \
237 (sb)->sb_mbtail = NULL; \
238 (sb)->sb_lastrecord = NULL; \
239 } \
240 } while (/*CONSTCOND*/0)
241
242 extern u_long sb_max;
243 extern int somaxkva;
244 extern int sock_loan_thresh;
245 extern kmutex_t *softnet_lock;
246
247 struct mbuf;
248 struct lwp;
249 struct msghdr;
250 struct stat;
251 struct knote;
252 struct sockaddr_big;
253 enum uio_seg;
254
255 /* 0x400 is SO_OTIMESTAMP */
256 #define SOOPT_TIMESTAMP(o) ((o) & (SO_TIMESTAMP | 0x400))
257
258 /*
259 * File operations on sockets.
260 */
261 int soo_read(file_t *, off_t *, struct uio *, kauth_cred_t, int);
262 int soo_write(file_t *, off_t *, struct uio *, kauth_cred_t, int);
263 int soo_fcntl(file_t *, u_int cmd, void *);
264 int soo_ioctl(file_t *, u_long cmd, void *);
265 int soo_poll(file_t *, int);
266 int soo_kqfilter(file_t *, struct knote *);
267 int soo_close(file_t *);
268 int soo_stat(file_t *, struct stat *);
269 void soo_restart(file_t *);
270 void sbappend(struct sockbuf *, struct mbuf *);
271 void sbappendstream(struct sockbuf *, struct mbuf *);
272 int sbappendaddr(struct sockbuf *, const struct sockaddr *, struct mbuf *,
273 struct mbuf *);
274 int sbappendaddrchain(struct sockbuf *, const struct sockaddr *,
275 struct mbuf *, int);
276 int sbappendcontrol(struct sockbuf *, struct mbuf *, struct mbuf *);
277 void sbappendrecord(struct sockbuf *, struct mbuf *);
278 void sbcheck(struct sockbuf *);
279 void sbcompress(struct sockbuf *, struct mbuf *, struct mbuf *);
280 struct mbuf *
281 sbcreatecontrol(void *, int, int, int);
282 struct mbuf *
283 sbcreatecontrol1(void **, int, int, int, int);
284 struct mbuf **
285 sbsavetimestamp(int, struct mbuf **);
286 void sbdrop(struct sockbuf *, int);
287 void sbdroprecord(struct sockbuf *);
288 void sbflush(struct sockbuf *);
289 void sbinsertoob(struct sockbuf *, struct mbuf *);
290 void sbrelease(struct sockbuf *, struct socket *);
291 int sbreserve(struct sockbuf *, u_long, struct socket *);
292 int sbwait(struct sockbuf *);
293 int sb_max_set(u_long);
294 void soinit(void);
295 void soinit1(void);
296 void soinit2(void);
297 int soabort(struct socket *);
298 int soaccept(struct socket *, struct sockaddr *);
299 int sofamily(const struct socket *);
300 int sobind(struct socket *, struct sockaddr *, struct lwp *);
301 void socantrcvmore(struct socket *);
302 void socantsendmore(struct socket *);
303 void soroverflow(struct socket *);
304 int soclose(struct socket *);
305 int soconnect(struct socket *, struct sockaddr *, struct lwp *);
306 int soconnect2(struct socket *, struct socket *);
307 int socreate(int, struct socket **, int, int, struct lwp *,
308 struct socket *);
309 int fsocreate(int, struct socket **, int, int, int *);
310 int sodisconnect(struct socket *);
311 void sofree(struct socket *);
312 int sogetopt(struct socket *, struct sockopt *);
313 void sohasoutofband(struct socket *);
314 void soisconnected(struct socket *);
315 void soisconnecting(struct socket *);
316 void soisdisconnected(struct socket *);
317 void soisdisconnecting(struct socket *);
318 int solisten(struct socket *, int, struct lwp *);
319 struct socket *
320 sonewconn(struct socket *, bool);
321 void soqinsque(struct socket *, struct socket *, int);
322 bool soqremque(struct socket *, int);
323 int soreceive(struct socket *, struct mbuf **, struct uio *,
324 struct mbuf **, struct mbuf **, int *);
325 int soreserve(struct socket *, u_long, u_long);
326 void sorflush(struct socket *);
327 int sosend(struct socket *, struct sockaddr *, struct uio *,
328 struct mbuf *, struct mbuf *, int, struct lwp *);
329 int sosetopt(struct socket *, struct sockopt *);
330 int so_setsockopt(struct lwp *, struct socket *, int, int, const void *, size_t);
331 int soshutdown(struct socket *, int);
332 void sorestart(struct socket *);
333 void sowakeup(struct socket *, struct sockbuf *, int);
334 int sockargs(struct mbuf **, const void *, size_t, enum uio_seg, int);
335 int sopoll(struct socket *, int);
336 struct socket *soget(bool);
337 void soput(struct socket *);
338 bool solocked(const struct socket *);
339 bool solocked2(const struct socket *, const struct socket *);
340 int sblock(struct sockbuf *, int);
341 void sbunlock(struct sockbuf *);
342 int sowait(struct socket *, bool, int);
343 void solockretry(struct socket *, kmutex_t *);
344 void sosetlock(struct socket *);
345 void solockreset(struct socket *, kmutex_t *);
346
347 void sockopt_init(struct sockopt *, int, int, size_t);
348 void sockopt_destroy(struct sockopt *);
349 int sockopt_set(struct sockopt *, const void *, size_t);
350 int sockopt_setint(struct sockopt *, int);
351 int sockopt_get(const struct sockopt *, void *, size_t);
352 int sockopt_getint(const struct sockopt *, int *);
353 int sockopt_setmbuf(struct sockopt *, struct mbuf *);
354 struct mbuf *sockopt_getmbuf(const struct sockopt *);
355
356 int copyout_sockname(struct sockaddr *, unsigned int *, int, struct mbuf *);
357 int copyout_sockname_sb(struct sockaddr *, unsigned int *,
358 int , struct sockaddr_big *);
359 int copyout_msg_control(struct lwp *, struct msghdr *, struct mbuf *);
360 void free_control_mbuf(struct lwp *, struct mbuf *, struct mbuf *);
361
362 int do_sys_getpeername(int, struct sockaddr *);
363 int do_sys_getsockname(int, struct sockaddr *);
364
365 int do_sys_sendmsg(struct lwp *, int, struct msghdr *, int, register_t *);
366 int do_sys_sendmsg_so(struct lwp *, int, struct socket *, file_t *,
367 struct msghdr *, int, register_t *);
368
369 int do_sys_recvmsg(struct lwp *, int, struct msghdr *,
370 struct mbuf **, struct mbuf **, register_t *);
371 int do_sys_recvmsg_so(struct lwp *, int, struct socket *,
372 struct msghdr *mp, struct mbuf **, struct mbuf **, register_t *);
373
374 int do_sys_bind(struct lwp *, int, struct sockaddr *);
375 int do_sys_connect(struct lwp *, int, struct sockaddr *);
376 int do_sys_accept(struct lwp *, int, struct sockaddr *, register_t *,
377 const sigset_t *, int, int);
378
379 int do_sys_peeloff(struct socket *, void *);
380 /*
381 * Inline functions for sockets and socket buffering.
382 */
383
384 #include <sys/protosw.h>
385 #include <sys/mbuf.h>
386
387 /*
388 * Do we need to notify the other side when I/O is possible?
389 */
390 static __inline int
sb_notify(struct sockbuf * sb)391 sb_notify(struct sockbuf *sb)
392 {
393
394 KASSERT(solocked(sb->sb_so));
395
396 return sb->sb_flags & (SB_NOTIFY | SB_ASYNC | SB_UPCALL | SB_KNOTE);
397 }
398
399 /*
400 * How much space is there in a socket buffer (so->so_snd or so->so_rcv)?
401 * Since the fields are unsigned, detect overflow and return 0.
402 */
403 static __inline u_long
sbspace(const struct sockbuf * sb)404 sbspace(const struct sockbuf *sb)
405 {
406
407 KASSERT(solocked(sb->sb_so));
408 if (sb->sb_hiwat <= sb->sb_cc || sb->sb_mbmax <= sb->sb_mbcnt)
409 return 0;
410 return lmin(sb->sb_hiwat - sb->sb_cc, sb->sb_mbmax - sb->sb_mbcnt);
411 }
412
413 static __inline u_long
sbspace_oob(const struct sockbuf * sb)414 sbspace_oob(const struct sockbuf *sb)
415 {
416 u_long hiwat = sb->sb_hiwat;
417
418 if (hiwat < ULONG_MAX - 1024)
419 hiwat += 1024;
420
421 KASSERT(solocked(sb->sb_so));
422
423 if (hiwat <= sb->sb_cc || sb->sb_mbmax <= sb->sb_mbcnt)
424 return 0;
425 return lmin(hiwat - sb->sb_cc, sb->sb_mbmax - sb->sb_mbcnt);
426 }
427
428 /*
429 * How much socket buffer space has been used?
430 */
431 static __inline u_long
sbused(const struct sockbuf * sb)432 sbused(const struct sockbuf *sb)
433 {
434
435 KASSERT(solocked(sb->sb_so));
436 return sb->sb_cc;
437 }
438
439 /* do we have to send all at once on a socket? */
440 static __inline int
sosendallatonce(const struct socket * so)441 sosendallatonce(const struct socket *so)
442 {
443
444 return so->so_proto->pr_flags & PR_ATOMIC;
445 }
446
447 /* can we read something from so? */
448 static __inline int
soreadable(const struct socket * so)449 soreadable(const struct socket *so)
450 {
451
452 KASSERT(solocked(so));
453
454 return so->so_rcv.sb_cc >= so->so_rcv.sb_lowat ||
455 (so->so_state & SS_CANTRCVMORE) != 0 ||
456 so->so_qlen != 0 || so->so_error != 0 || so->so_rerror != 0;
457 }
458
459 /* can we write something to so? */
460 static __inline int
sowritable(const struct socket * so)461 sowritable(const struct socket *so)
462 {
463
464 KASSERT(solocked(so));
465
466 return (sbspace(&so->so_snd) >= so->so_snd.sb_lowat &&
467 ((so->so_state & SS_ISCONNECTED) != 0 ||
468 (so->so_proto->pr_flags & PR_CONNREQUIRED) == 0)) ||
469 (so->so_state & SS_CANTSENDMORE) != 0 ||
470 so->so_error != 0;
471 }
472
473 /* adjust counters in sb reflecting allocation of m */
474 static __inline void
sballoc(struct sockbuf * sb,struct mbuf * m)475 sballoc(struct sockbuf *sb, struct mbuf *m)
476 {
477
478 KASSERT(solocked(sb->sb_so));
479
480 sb->sb_cc += m->m_len;
481 sb->sb_mbcnt += MSIZE;
482 if (m->m_flags & M_EXT)
483 sb->sb_mbcnt += m->m_ext.ext_size;
484 }
485
486 /* adjust counters in sb reflecting freeing of m */
487 static __inline void
sbfree(struct sockbuf * sb,struct mbuf * m)488 sbfree(struct sockbuf *sb, struct mbuf *m)
489 {
490
491 KASSERT(solocked(sb->sb_so));
492
493 sb->sb_cc -= m->m_len;
494 sb->sb_mbcnt -= MSIZE;
495 if (m->m_flags & M_EXT)
496 sb->sb_mbcnt -= m->m_ext.ext_size;
497 }
498
499 static __inline void
sorwakeup(struct socket * so)500 sorwakeup(struct socket *so)
501 {
502
503 KASSERT(solocked(so));
504
505 if (sb_notify(&so->so_rcv))
506 sowakeup(so, &so->so_rcv, POLL_IN);
507 }
508
509 static __inline void
sowwakeup(struct socket * so)510 sowwakeup(struct socket *so)
511 {
512
513 KASSERT(solocked(so));
514
515 if (sb_notify(&so->so_snd))
516 sowakeup(so, &so->so_snd, POLL_OUT);
517 }
518
519 static __inline void
solock(struct socket * so)520 solock(struct socket *so)
521 {
522 kmutex_t *lock;
523
524 lock = atomic_load_consume(&so->so_lock);
525 mutex_enter(lock);
526 if (__predict_false(lock != atomic_load_relaxed(&so->so_lock)))
527 solockretry(so, lock);
528 }
529
530 static __inline void
sounlock(struct socket * so)531 sounlock(struct socket *so)
532 {
533
534 mutex_exit(so->so_lock);
535 }
536
537 #ifdef SOCKBUF_DEBUG
538 /*
539 * SBLASTRECORDCHK: check sb->sb_lastrecord is maintained correctly.
540 * SBLASTMBUFCHK: check sb->sb_mbtail is maintained correctly.
541 *
542 * => panic if the socket buffer is inconsistent.
543 * => 'where' is used for a panic message.
544 */
545 void sblastrecordchk(struct sockbuf *, const char *);
546 #define SBLASTRECORDCHK(sb, where) sblastrecordchk((sb), (where))
547
548 void sblastmbufchk(struct sockbuf *, const char *);
549 #define SBLASTMBUFCHK(sb, where) sblastmbufchk((sb), (where))
550 #define SBCHECK(sb) sbcheck(sb)
551 #else
552 #define SBLASTRECORDCHK(sb, where) /* nothing */
553 #define SBLASTMBUFCHK(sb, where) /* nothing */
554 #define SBCHECK(sb) /* nothing */
555 #endif /* SOCKBUF_DEBUG */
556
557 /* sosend loan */
558 vaddr_t sokvaalloc(vaddr_t, vsize_t, struct socket *);
559 void sokvafree(vaddr_t, vsize_t);
560 void soloanfree(struct mbuf *, void *, size_t, void *);
561
562 /*
563 * Values for socket-buffer-append priority argument to sbappendaddrchain().
564 * The following flags are reserved for future implementation:
565 *
566 * SB_PRIO_NONE: honour normal socket-buffer limits.
567 *
568 * SB_PRIO_ONESHOT_OVERFLOW: if the socket has any space,
569 * deliver the entire chain. Intended for large requests
570 * that should be delivered in their entirety, or not at all.
571 *
572 * SB_PRIO_OVERDRAFT: allow a small (2*MLEN) overflow, over and
573 * aboce normal socket limits. Intended messages indicating
574 * buffer overflow in earlier normal/lower-priority messages .
575 *
576 * SB_PRIO_BESTEFFORT: Ignore limits entirely. Intended only for
577 * kernel-generated messages to specially-marked scokets which
578 * require "reliable" delivery, nd where the source socket/protocol
579 * message generator enforce some hard limit (but possibly well
580 * above kern.sbmax). It is entirely up to the in-kernel source to
581 * avoid complete mbuf exhaustion or DoS scenarios.
582 */
583 #define SB_PRIO_NONE 0
584 #define SB_PRIO_ONESHOT_OVERFLOW 1
585 #define SB_PRIO_OVERDRAFT 2
586 #define SB_PRIO_BESTEFFORT 3
587
588 /*
589 * Accept filter functions (duh).
590 */
591 int accept_filt_getopt(struct socket *, struct sockopt *);
592 int accept_filt_setopt(struct socket *, const struct sockopt *);
593 int accept_filt_clear(struct socket *);
594 int accept_filt_add(struct accept_filter *);
595 int accept_filt_del(struct accept_filter *);
596 struct accept_filter *accept_filt_get(char *);
597 #ifdef ACCEPT_FILTER_MOD
598 #ifdef SYSCTL_DECL
599 SYSCTL_DECL(_net_inet_accf);
600 #endif
601 void accept_filter_init(void);
602 #endif
603 #ifdef DDB
604 int sofindproc(struct socket *so, int all, void (*pr)(const char *, ...));
605 void socket_print(const char *modif, void (*pr)(const char *, ...));
606 #endif
607
608 #endif /* _KERNEL */
609
610 #endif /* !_SYS_SOCKETVAR_H_ */
611