master
  1/*	$NetBSD: socketvar.h,v 1.165.4.1 2024/02/04 11:20:15 martin 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)
 73struct uio;
 74struct lwp;
 75struct uidinfo;
 76#else
 77#include <sys/atomic.h>
 78#include <sys/uidinfo.h>
 79#endif
 80
 81TAILQ_HEAD(soqhead, socket);
 82
 83/*
 84 * Variables for socket buffering.
 85 */
 86struct 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 */
125struct 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
131struct sockaddr;
132
133struct 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
212struct 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
224struct 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)						\
234do {									\
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
242extern u_long		sb_max;
243extern int		somaxkva;
244extern int		sock_loan_thresh;
245extern kmutex_t		*softnet_lock;
246
247struct mbuf;
248struct lwp;
249struct msghdr;
250struct stat;
251struct knote;
252struct sockaddr_big;
253enum 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 */
261int	soo_read(file_t *, off_t *, struct uio *, kauth_cred_t, int);
262int	soo_write(file_t *, off_t *, struct uio *, kauth_cred_t, int);
263int	soo_fcntl(file_t *, u_int cmd, void *);
264int	soo_ioctl(file_t *, u_long cmd, void *);
265int	soo_poll(file_t *, int);
266int	soo_kqfilter(file_t *, struct knote *);
267int 	soo_close(file_t *);
268int	soo_stat(file_t *, struct stat *);
269void	soo_restart(file_t *);
270void	sbappend(struct sockbuf *, struct mbuf *);
271void	sbappendstream(struct sockbuf *, struct mbuf *);
272int	sbappendaddr(struct sockbuf *, const struct sockaddr *, struct mbuf *,
273	    struct mbuf *);
274int	sbappendaddrchain(struct sockbuf *, const struct sockaddr *,
275	     struct mbuf *, int);
276int	sbappendcontrol(struct sockbuf *, struct mbuf *, struct mbuf *);
277void	sbappendrecord(struct sockbuf *, struct mbuf *);
278void	sbcheck(struct sockbuf *);
279void	sbcompress(struct sockbuf *, struct mbuf *, struct mbuf *);
280struct mbuf *
281	sbcreatecontrol(void *, int, int, int);
282struct mbuf *
283	sbcreatecontrol1(void **, int, int, int, int);
284struct mbuf **
285	sbsavetimestamp(int, struct mbuf **);
286void	sbdrop(struct sockbuf *, int);
287void	sbdroprecord(struct sockbuf *);
288void	sbflush(struct sockbuf *);
289void	sbinsertoob(struct sockbuf *, struct mbuf *);
290void	sbrelease(struct sockbuf *, struct socket *);
291int	sbreserve(struct sockbuf *, u_long, struct socket *);
292int	sbwait(struct sockbuf *);
293int	sb_max_set(u_long);
294void	soinit(void);
295void	soinit1(void);
296void	soinit2(void);
297int	soabort(struct socket *);
298int	soaccept(struct socket *, struct sockaddr *);
299int	sofamily(const struct socket *);
300int	sobind(struct socket *, struct sockaddr *, struct lwp *);
301void	socantrcvmore(struct socket *);
302void	socantsendmore(struct socket *);
303void	soroverflow(struct socket *);
304int	soclose(struct socket *);
305int	soconnect(struct socket *, struct sockaddr *, struct lwp *);
306int	soconnect2(struct socket *, struct socket *);
307int	socreate(int, struct socket **, int, int, struct lwp *,
308		 struct socket *);
309int	fsocreate(int, struct socket **, int, int, int *, file_t **,
310		struct socket *);
311int	sodisconnect(struct socket *);
312void	sofree(struct socket *);
313int	sogetopt(struct socket *, struct sockopt *);
314void	sohasoutofband(struct socket *);
315void	soisconnected(struct socket *);
316void	soisconnecting(struct socket *);
317void	soisdisconnected(struct socket *);
318void	soisdisconnecting(struct socket *);
319int	solisten(struct socket *, int, struct lwp *);
320struct socket *
321	sonewconn(struct socket *, bool);
322void	soqinsque(struct socket *, struct socket *, int);
323bool	soqremque(struct socket *, int);
324int	soreceive(struct socket *, struct mbuf **, struct uio *,
325	    struct mbuf **, struct mbuf **, int *);
326int	soreserve(struct socket *, u_long, u_long);
327void	sorflush(struct socket *);
328int	sosend(struct socket *, struct sockaddr *, struct uio *,
329	    struct mbuf *, struct mbuf *, int, struct lwp *);
330int	sosetopt(struct socket *, struct sockopt *);
331int	so_setsockopt(struct lwp *, struct socket *, int, int, const void *, size_t);
332int	soshutdown(struct socket *, int);
333void	sorestart(struct socket *);
334void	sowakeup(struct socket *, struct sockbuf *, int);
335int	sockargs(struct mbuf **, const void *, size_t, enum uio_seg, int);
336int	sopoll(struct socket *, int);
337struct	socket *soget(bool);
338void	soput(struct socket *);
339bool	solocked(const struct socket *);
340bool	solocked2(const struct socket *, const struct socket *);
341int	sblock(struct sockbuf *, int);
342void	sbunlock(struct sockbuf *);
343int	sowait(struct socket *, bool, int);
344void	solockretry(struct socket *, kmutex_t *);
345void	sosetlock(struct socket *);
346void	solockreset(struct socket *, kmutex_t *);
347
348void	sockopt_init(struct sockopt *, int, int, size_t);
349void	sockopt_destroy(struct sockopt *);
350int	sockopt_set(struct sockopt *, const void *, size_t);
351int	sockopt_setint(struct sockopt *, int);
352int	sockopt_get(const struct sockopt *, void *, size_t);
353int	sockopt_getint(const struct sockopt *, int *);
354int	sockopt_setmbuf(struct sockopt *, struct mbuf *);
355struct mbuf *sockopt_getmbuf(const struct sockopt *);
356
357int	copyout_sockname(struct sockaddr *, unsigned int *, int, struct mbuf *);
358int	copyout_sockname_sb(struct sockaddr *, unsigned int *,
359    int , struct sockaddr_big *);
360int	copyout_msg_control(struct lwp *, struct msghdr *, struct mbuf *);
361void	free_control_mbuf(struct lwp *, struct mbuf *, struct mbuf *);
362
363int	do_sys_getpeername(int, struct sockaddr *);
364int	do_sys_getsockname(int, struct sockaddr *);
365
366int	do_sys_sendmsg(struct lwp *, int, struct msghdr *, int, register_t *);
367int	do_sys_sendmsg_so(struct lwp *, int, struct socket *, file_t *,
368	    struct msghdr *, int, register_t *);
369
370int	do_sys_recvmsg(struct lwp *, int, struct msghdr *,
371	    struct mbuf **, struct mbuf **, register_t *);
372int	do_sys_recvmsg_so(struct lwp *, int, struct socket *,
373	    struct msghdr *mp, struct mbuf **, struct mbuf **, register_t *);
374
375int	do_sys_bind(struct lwp *, int, struct sockaddr *);
376int	do_sys_connect(struct lwp *, int, struct sockaddr *);
377int	do_sys_accept(struct lwp *, int, struct sockaddr *, register_t *,
378	    const sigset_t *, int, int);
379
380int	do_sys_peeloff(struct socket *, void *);
381/*
382 * Inline functions for sockets and socket buffering.
383 */
384
385#include <sys/protosw.h>
386#include <sys/mbuf.h>
387
388/*
389 * Do we need to notify the other side when I/O is possible?
390 */
391static __inline int
392sb_notify(struct sockbuf *sb)
393{
394
395	KASSERT(solocked(sb->sb_so));
396
397	return sb->sb_flags & (SB_NOTIFY | SB_ASYNC | SB_UPCALL | SB_KNOTE);
398}
399
400/*
401 * How much space is there in a socket buffer (so->so_snd or so->so_rcv)?
402 * Since the fields are unsigned, detect overflow and return 0.
403 */
404static __inline u_long
405sbspace(const struct sockbuf *sb)
406{
407
408	KASSERT(solocked(sb->sb_so));
409	if (sb->sb_hiwat <= sb->sb_cc || sb->sb_mbmax <= sb->sb_mbcnt)
410		return 0;
411	return lmin(sb->sb_hiwat - sb->sb_cc, sb->sb_mbmax - sb->sb_mbcnt);
412}
413
414static __inline u_long
415sbspace_oob(const struct sockbuf *sb)
416{
417	u_long hiwat = sb->sb_hiwat;
418
419	if (hiwat < ULONG_MAX - 1024)
420		hiwat += 1024;
421
422	KASSERT(solocked(sb->sb_so));
423
424	if (hiwat <= sb->sb_cc || sb->sb_mbmax <= sb->sb_mbcnt)
425		return 0;
426	return lmin(hiwat - sb->sb_cc, sb->sb_mbmax - sb->sb_mbcnt);
427}
428
429/*
430 * How much socket buffer space has been used?
431 */
432static __inline u_long
433sbused(const struct sockbuf *sb)
434{
435
436	KASSERT(solocked(sb->sb_so));
437	return sb->sb_cc;
438}
439
440/* do we have to send all at once on a socket? */
441static __inline int
442sosendallatonce(const struct socket *so)
443{
444
445	return so->so_proto->pr_flags & PR_ATOMIC;
446}
447
448/* can we read something from so? */
449static __inline int
450soreadable(const struct socket *so)
451{
452
453	KASSERT(solocked(so));
454
455	return so->so_rcv.sb_cc >= so->so_rcv.sb_lowat ||
456	    (so->so_state & SS_CANTRCVMORE) != 0 ||
457	    so->so_qlen != 0 || so->so_error != 0 || so->so_rerror != 0;
458}
459
460/* can we write something to so? */
461static __inline int
462sowritable(const struct socket *so)
463{
464
465	KASSERT(solocked(so));
466
467	return (sbspace(&so->so_snd) >= so->so_snd.sb_lowat &&
468	    ((so->so_state & SS_ISCONNECTED) != 0 ||
469	    (so->so_proto->pr_flags & PR_CONNREQUIRED) == 0)) ||
470	    (so->so_state & SS_CANTSENDMORE) != 0 ||
471	    so->so_error != 0;
472}
473
474/* adjust counters in sb reflecting allocation of m */
475static __inline void
476sballoc(struct sockbuf *sb, struct mbuf *m)
477{
478
479	KASSERT(solocked(sb->sb_so));
480
481	sb->sb_cc += m->m_len;
482	sb->sb_mbcnt += MSIZE;
483	if (m->m_flags & M_EXT)
484		sb->sb_mbcnt += m->m_ext.ext_size;
485}
486
487/* adjust counters in sb reflecting freeing of m */
488static __inline void
489sbfree(struct sockbuf *sb, struct mbuf *m)
490{
491
492	KASSERT(solocked(sb->sb_so));
493
494	sb->sb_cc -= m->m_len;
495	sb->sb_mbcnt -= MSIZE;
496	if (m->m_flags & M_EXT)
497		sb->sb_mbcnt -= m->m_ext.ext_size;
498}
499
500static __inline void
501sorwakeup(struct socket *so)
502{
503
504	KASSERT(solocked(so));
505
506	if (sb_notify(&so->so_rcv))
507		sowakeup(so, &so->so_rcv, POLL_IN);
508}
509
510static __inline void
511sowwakeup(struct socket *so)
512{
513
514	KASSERT(solocked(so));
515
516	if (sb_notify(&so->so_snd))
517		sowakeup(so, &so->so_snd, POLL_OUT);
518}
519
520static __inline void
521solock(struct socket *so)
522{
523	kmutex_t *lock;
524
525	lock = atomic_load_consume(&so->so_lock);
526	mutex_enter(lock);
527	if (__predict_false(lock != atomic_load_relaxed(&so->so_lock)))
528		solockretry(so, lock);
529}
530
531static __inline void
532sounlock(struct socket *so)
533{
534
535	mutex_exit(so->so_lock);
536}
537
538#ifdef SOCKBUF_DEBUG
539/*
540 * SBLASTRECORDCHK: check sb->sb_lastrecord is maintained correctly.
541 * SBLASTMBUFCHK: check sb->sb_mbtail is maintained correctly.
542 *
543 * => panic if the socket buffer is inconsistent.
544 * => 'where' is used for a panic message.
545 */
546void	sblastrecordchk(struct sockbuf *, const char *);
547#define	SBLASTRECORDCHK(sb, where)	sblastrecordchk((sb), (where))
548
549void	sblastmbufchk(struct sockbuf *, const char *);
550#define	SBLASTMBUFCHK(sb, where)	sblastmbufchk((sb), (where))
551#define	SBCHECK(sb)			sbcheck(sb)
552#else
553#define	SBLASTRECORDCHK(sb, where)	/* nothing */
554#define	SBLASTMBUFCHK(sb, where)	/* nothing */
555#define	SBCHECK(sb)			/* nothing */
556#endif /* SOCKBUF_DEBUG */
557
558/* sosend loan */
559vaddr_t	sokvaalloc(vaddr_t, vsize_t, struct socket *);
560void	sokvafree(vaddr_t, vsize_t);
561void	soloanfree(struct mbuf *, void *, size_t, void *);
562
563/*
564 * Values for socket-buffer-append priority argument to sbappendaddrchain().
565 * The following flags are reserved for future implementation:
566 *
567 *  SB_PRIO_NONE:  honour normal socket-buffer limits.
568 *
569 *  SB_PRIO_ONESHOT_OVERFLOW:  if the socket has any space,
570 *	deliver the entire chain. Intended for large requests
571 *      that should be delivered in their entirety, or not at all.
572 *
573 * SB_PRIO_OVERDRAFT:  allow a small (2*MLEN) overflow, over and
574 *	aboce normal socket limits. Intended messages indicating
575 *      buffer overflow in earlier normal/lower-priority messages .
576 *
577 * SB_PRIO_BESTEFFORT: Ignore  limits entirely.  Intended only for
578 * 	kernel-generated messages to specially-marked scokets which
579 *	require "reliable" delivery, nd where the source socket/protocol
580 *	message generator enforce some hard limit (but possibly well
581 *	above kern.sbmax). It is entirely up to the in-kernel source to
582 *	avoid complete mbuf exhaustion or DoS scenarios.
583 */
584#define SB_PRIO_NONE 	 	0
585#define SB_PRIO_ONESHOT_OVERFLOW 1
586#define SB_PRIO_OVERDRAFT	2
587#define SB_PRIO_BESTEFFORT	3
588
589/*
590 * Accept filter functions (duh).
591 */
592int	accept_filt_getopt(struct socket *, struct sockopt *);
593int	accept_filt_setopt(struct socket *, const struct sockopt *);
594int	accept_filt_clear(struct socket *);
595int	accept_filt_add(struct accept_filter *);
596int	accept_filt_del(struct accept_filter *);
597struct	accept_filter *accept_filt_get(char *);
598#ifdef ACCEPT_FILTER_MOD
599#ifdef SYSCTL_DECL
600SYSCTL_DECL(_net_inet_accf);
601#endif
602void	accept_filter_init(void);
603#endif
604#ifdef DDB
605int sofindproc(struct socket *so, int all, void (*pr)(const char *, ...));
606void socket_print(const char *modif, void (*pr)(const char *, ...));
607#endif
608
609#endif /* _KERNEL */
610
611#endif /* !_SYS_SOCKETVAR_H_ */