socketvar.h revision 132018
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 * 4. 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 *	@(#)socketvar.h	8.3 (Berkeley) 2/19/95
30 * $FreeBSD: head/sys/sys/socketvar.h 132018 2004-07-12 06:22:42Z alfred $
31 */
32
33#ifndef _SYS_SOCKETVAR_H_
34#define _SYS_SOCKETVAR_H_
35
36#include <sys/queue.h>			/* for TAILQ macros */
37#include <sys/selinfo.h>		/* for struct selinfo */
38#include <sys/_lock.h>
39#include <sys/_mutex.h>
40
41/*
42 * Kernel structure per socket.
43 * Contains send and receive buffer queues,
44 * handle on protocol and pointer to protocol
45 * private data and error information.
46 */
47typedef	u_quad_t so_gen_t;
48
49/*-
50 * Locking key to struct socket:
51 * (a) constant after allocation, no locking required.
52 * (b) locked by SOCK_LOCK(so).
53 * (c) locked by SOCKBUF_LOCK(&so->so_rcv).
54 * (d) locked by SOCKBUF_LOCK(&so->so_snd).
55 * (e) locked by ACCEPT_LOCK().
56 * (f) not locked since integer reads/writes are atomic.
57 * (g) used only as a sleep/wakeup address, no value.
58 * (h) locked by global mutex so_global_mtx.
59 */
60struct socket {
61	int	so_count;		/* (b) reference count */
62	short	so_type;		/* (a) generic type, see socket.h */
63	short	so_options;		/* from socket call, see socket.h */
64	short	so_linger;		/* time to linger while closing */
65	short	so_state;		/* (b) internal state flags SS_* */
66	int	so_qstate;		/* (e) internal state flags SQ_* */
67	void	*so_pcb;		/* protocol control block */
68	struct	protosw *so_proto;	/* (a) protocol handle */
69/*
70 * Variables for connection queuing.
71 * Socket where accepts occur is so_head in all subsidiary sockets.
72 * If so_head is 0, socket is not related to an accept.
73 * For head socket so_incomp queues partially completed connections,
74 * while so_comp is a queue of connections ready to be accepted.
75 * If a connection is aborted and it has so_head set, then
76 * it has to be pulled out of either so_incomp or so_comp.
77 * We allow connections to queue up based on current queue lengths
78 * and limit on number of queued connections for this socket.
79 */
80	struct	socket *so_head;	/* (e) back pointer to accept socket */
81	TAILQ_HEAD(, socket) so_incomp;	/* (e) queue of partial unaccepted connections */
82	TAILQ_HEAD(, socket) so_comp;	/* (e) queue of complete unaccepted connections */
83	TAILQ_ENTRY(socket) so_list;	/* (e) list of unaccepted connections */
84	short	so_qlen;		/* (e) number of unaccepted connections */
85	short	so_incqlen;		/* (e) number of unaccepted incomplete
86					   connections */
87	short	so_qlimit;		/* (e) max number queued connections */
88	short	so_timeo;		/* (g) connection timeout */
89	u_short	so_error;		/* (f) error affecting connection */
90	struct	sigio *so_sigio;	/* [sg] information for async I/O or
91					   out of band data (SIGURG) */
92	u_long	so_oobmark;		/* (c) chars to oob mark */
93	TAILQ_HEAD(, aiocblist) so_aiojobq; /* AIO ops waiting on socket */
94/*
95 * Variables for socket buffering.
96 */
97	struct sockbuf {
98		struct	selinfo sb_sel;	/* process selecting read/write */
99		struct	mtx sb_mtx;	/* sockbuf lock */
100#define	sb_startzero	sb_mb
101		struct	mbuf *sb_mb;	/* (c/d) the mbuf chain */
102		struct	mbuf *sb_mbtail; /* (c/d) the last mbuf in the chain */
103		struct	mbuf *sb_lastrecord;	/* (c/d) first mbuf of last
104						 * record in socket buffer */
105		u_int	sb_cc;		/* (c/d) actual chars in buffer */
106		u_int	sb_hiwat;	/* (c/d) max actual char count */
107		u_int	sb_mbcnt;	/* (c/d) chars of mbufs used */
108		u_int	sb_mbmax;	/* (c/d) max chars of mbufs to use */
109		u_int	sb_ctl;		/* (c/d) non-data chars in buffer */
110		int	sb_lowat;	/* (c/d) low water mark */
111		int	sb_timeo;	/* (c/d) timeout for read/write */
112		short	sb_flags;	/* (c/d) flags, see below */
113		short	sb_state;	/* (c/d) socket state on sockbuf */
114	} so_rcv, so_snd;
115/*
116 * Constants for sb_flags field of struct sockbuf.
117 */
118#define	SB_MAX		(256*1024)	/* default for max chars in sockbuf */
119/*
120 * Constants for sb_flags field of struct sockbuf.
121 */
122#define	SB_LOCK		0x01		/* lock on data queue */
123#define	SB_WANT		0x02		/* someone is waiting to lock */
124#define	SB_WAIT		0x04		/* someone is waiting for data/space */
125#define	SB_SEL		0x08		/* someone is selecting */
126#define	SB_ASYNC	0x10		/* ASYNC I/O, need signals */
127#define	SB_UPCALL	0x20		/* someone wants an upcall */
128#define	SB_NOINTR	0x40		/* operations not interruptible */
129#define SB_AIO		0x80		/* AIO operations queued */
130#define SB_KNOTE	0x100		/* kernel note attached */
131
132	void	(*so_upcall)(struct socket *, void *, int);
133	void	*so_upcallarg;
134	struct	ucred *so_cred;		/* (a) user credentials */
135	struct	label *so_label;	/* (b) MAC label for socket */
136	struct	label *so_peerlabel;	/* (b) cached MAC label for peer */
137	/* NB: generation count must not be first; easiest to make it last. */
138	so_gen_t so_gencnt;		/* (h) generation count */
139	void	*so_emuldata;		/* private data for emulators */
140 	struct so_accf {
141		struct	accept_filter *so_accept_filter;
142		void	*so_accept_filter_arg;	/* saved filter args */
143		char	*so_accept_filter_str;	/* saved user args */
144	} *so_accf;
145};
146
147#define SB_EMPTY_FIXUP(sb) do {						\
148	if ((sb)->sb_mb == NULL) {					\
149		(sb)->sb_mbtail = NULL;					\
150		(sb)->sb_lastrecord = NULL;				\
151	}								\
152} while (/*CONSTCOND*/0)
153
154/*
155 * Global accept mutex to serialize access to accept queues and
156 * fields associated with multiple sockets.  This allows us to
157 * avoid defining a lock order between listen and accept sockets
158 * until such time as it proves to be a good idea.
159 */
160extern struct mtx accept_mtx;
161#define	ACCEPT_LOCK()			mtx_lock(&accept_mtx)
162#define	ACCEPT_UNLOCK()			mtx_unlock(&accept_mtx)
163
164/*
165 * Per-socket buffer mutex used to protect most fields in the socket
166 * buffer.
167 */
168#define	SOCKBUF_MTX(_sb)		(&(_sb)->sb_mtx)
169#define	SOCKBUF_LOCK_INIT(_sb, _name) \
170	mtx_init(SOCKBUF_MTX(_sb), _name, NULL, MTX_DEF)
171#define	SOCKBUF_LOCK_DESTROY(_sb)	mtx_destroy(SOCKBUF_MTX(_sb))
172#define	SOCKBUF_LOCK(_sb)		mtx_lock(SOCKBUF_MTX(_sb))
173#define	SOCKBUF_OWNED(_sb)		mtx_owned(SOCKBUF_MTX(_sb))
174#define	SOCKBUF_UNLOCK(_sb)		mtx_unlock(SOCKBUF_MTX(_sb))
175#define	SOCKBUF_LOCK_ASSERT(_sb)	mtx_assert(SOCKBUF_MTX(_sb), MA_OWNED)
176
177/*
178 * Per-socket mutex: we reuse the receive socket buffer mutex for space
179 * efficiency.  This decision should probably be revisited as we optimize
180 * locking for the socket code.
181 */
182#define	SOCK_MTX(_so)			SOCKBUF_MTX(&(_so)->so_rcv)
183#define	SOCK_LOCK(_so)			SOCKBUF_LOCK(&(_so)->so_rcv)
184#define	SOCK_OWNED(_so)			SOCKBUF_OWNED(&(_so)->so_rcv)
185#define	SOCK_UNLOCK(_so)		SOCKBUF_UNLOCK(&(_so)->so_rcv)
186#define	SOCK_LOCK_ASSERT(_so)		SOCKBUF_LOCK_ASSERT(&(_so)->so_rcv)
187
188/*
189 * Socket state bits.
190 *
191 * Historically, this bits were all kept in the so_state field.  For
192 * locking reasons, they are now in multiple fields, as they are
193 * locked differently.  so_state maintains basic socket state protected
194 * by the socket lock.  so_qstate holds information about the socket
195 * accept queues.  Each socket buffer also has a state field holding
196 * information relevant to that socket buffer (can't send, rcv).  Many
197 * fields will be read without locks to improve performance and avoid
198 * lock order issues.  However, this approach must be used with caution.
199 */
200#define	SS_NOFDREF		0x0001	/* no file table ref any more */
201#define	SS_ISCONNECTED		0x0002	/* socket connected to a peer */
202#define	SS_ISCONNECTING		0x0004	/* in process of connecting to peer */
203#define	SS_ISDISCONNECTING	0x0008	/* in process of disconnecting */
204#define	SS_NBIO			0x0100	/* non-blocking ops */
205#define	SS_ASYNC		0x0200	/* async i/o notify */
206#define	SS_ISCONFIRMING		0x0400	/* deciding to accept connection req */
207#define	SS_ISDISCONNECTED	0x2000	/* socket disconnected from peer */
208
209/*
210 * Socket state bits now stored in the socket buffer state field.
211 */
212#define	SBS_CANTSENDMORE	0x0010	/* can't send more data to peer */
213#define	SBS_CANTRCVMORE		0x0020	/* can't receive more data from peer */
214#define	SBS_RCVATMARK		0x0040	/* at mark on input */
215
216/*
217 * Socket state bits stored in so_qstate.
218 */
219#define	SQ_INCOMP		0x0800	/* unaccepted, incomplete connection */
220#define	SQ_COMP			0x1000	/* unaccepted, complete connection */
221
222/*
223 * Externalized form of struct socket used by the sysctl(3) interface.
224 */
225struct xsocket {
226	size_t	xso_len;	/* length of this structure */
227	struct	socket *xso_so;	/* makes a convenient handle sometimes */
228	short	so_type;
229	short	so_options;
230	short	so_linger;
231	short	so_state;
232	caddr_t	so_pcb;		/* another convenient handle */
233	int	xso_protocol;
234	int	xso_family;
235	short	so_qlen;
236	short	so_incqlen;
237	short	so_qlimit;
238	short	so_timeo;
239	u_short	so_error;
240	pid_t	so_pgid;
241	u_long	so_oobmark;
242	struct xsockbuf {
243		u_int	sb_cc;
244		u_int	sb_hiwat;
245		u_int	sb_mbcnt;
246		u_int	sb_mbmax;
247		int	sb_lowat;
248		int	sb_timeo;
249		short	sb_flags;
250	} so_rcv, so_snd;
251	uid_t	so_uid;		/* XXX */
252};
253
254#ifdef _KERNEL
255
256/*
257 * Macros for sockets and socket buffering.
258 */
259
260/*
261 * Do we need to notify the other side when I/O is possible?
262 */
263#define	sb_notify(sb)	(((sb)->sb_flags & (SB_WAIT | SB_SEL | SB_ASYNC | \
264    SB_UPCALL | SB_AIO | SB_KNOTE)) != 0)
265
266/*
267 * How much space is there in a socket buffer (so->so_snd or so->so_rcv)?
268 * This is problematical if the fields are unsigned, as the space might
269 * still be negative (cc > hiwat or mbcnt > mbmax).  Should detect
270 * overflow and return 0.  Should use "lmin" but it doesn't exist now.
271 */
272#define	sbspace(sb) \
273    ((long) imin((int)((sb)->sb_hiwat - (sb)->sb_cc), \
274	 (int)((sb)->sb_mbmax - (sb)->sb_mbcnt)))
275
276/* do we have to send all at once on a socket? */
277#define	sosendallatonce(so) \
278    ((so)->so_proto->pr_flags & PR_ATOMIC)
279
280/* can we read something from so? */
281#define	soreadable(so) \
282    ((so)->so_rcv.sb_cc >= (so)->so_rcv.sb_lowat || \
283	((so)->so_rcv.sb_state & SBS_CANTRCVMORE) || \
284	!TAILQ_EMPTY(&(so)->so_comp) || (so)->so_error)
285
286/* can we write something to so? */
287#define	sowriteable(so) \
288    ((sbspace(&(so)->so_snd) >= (so)->so_snd.sb_lowat && \
289	(((so)->so_state&SS_ISCONNECTED) || \
290	  ((so)->so_proto->pr_flags&PR_CONNREQUIRED)==0)) || \
291     ((so)->so_snd.sb_state & SBS_CANTSENDMORE) || \
292     (so)->so_error)
293
294/* adjust counters in sb reflecting allocation of m */
295#define	sballoc(sb, m) { \
296	(sb)->sb_cc += (m)->m_len; \
297	if ((m)->m_type != MT_DATA && (m)->m_type != MT_HEADER && \
298	    (m)->m_type != MT_OOBDATA) \
299		(sb)->sb_ctl += (m)->m_len; \
300	(sb)->sb_mbcnt += MSIZE; \
301	if ((m)->m_flags & M_EXT) \
302		(sb)->sb_mbcnt += (m)->m_ext.ext_size; \
303}
304
305/* adjust counters in sb reflecting freeing of m */
306#define	sbfree(sb, m) { \
307	(sb)->sb_cc -= (m)->m_len; \
308	if ((m)->m_type != MT_DATA && (m)->m_type != MT_HEADER && \
309	    (m)->m_type != MT_OOBDATA) \
310		(sb)->sb_ctl -= (m)->m_len; \
311	(sb)->sb_mbcnt -= MSIZE; \
312	if ((m)->m_flags & M_EXT) \
313		(sb)->sb_mbcnt -= (m)->m_ext.ext_size; \
314}
315
316/*
317 * Set lock on sockbuf sb; sleep if lock is already held.
318 * Unless SB_NOINTR is set on sockbuf, sleep is interruptible.
319 * Returns error without lock if sleep is interrupted.
320 */
321#define sblock(sb, wf) ((sb)->sb_flags & SB_LOCK ? \
322		(((wf) == M_WAITOK) ? sb_lock(sb) : EWOULDBLOCK) : \
323		((sb)->sb_flags |= SB_LOCK), 0)
324
325/* release lock on sockbuf sb */
326#define	sbunlock(sb) do { \
327	SOCKBUF_LOCK_ASSERT(sb); \
328	(sb)->sb_flags &= ~SB_LOCK; \
329	if ((sb)->sb_flags & SB_WANT) { \
330		(sb)->sb_flags &= ~SB_WANT; \
331		wakeup(&(sb)->sb_flags); \
332	} \
333} while (0)
334
335/*
336 * soref()/sorele() ref-count the socket structure.  Note that you must
337 * still explicitly close the socket, but the last ref count will free
338 * the structure.
339 */
340#define	soref(so) do {							\
341	SOCK_LOCK_ASSERT(so);						\
342	++(so)->so_count;						\
343} while (0)
344
345#define	sorele(so) do {							\
346	SOCK_LOCK_ASSERT(so);						\
347	if ((so)->so_count <= 0)					\
348		panic("sorele");					\
349	if (--(so)->so_count == 0)					\
350		sofree(so);						\
351	else								\
352		SOCK_UNLOCK(so);					\
353} while (0)
354
355#define	sotryfree(so) do {						\
356	SOCK_LOCK_ASSERT(so);						\
357	if ((so)->so_count == 0)					\
358		sofree(so);						\
359	else								\
360		SOCK_UNLOCK(so);					\
361} while(0)
362
363/*
364 * In sorwakeup() and sowwakeup(), acquire the socket buffer lock to
365 * avoid a non-atomic test-and-wakeup.  However, sowakeup is
366 * responsible for releasing the lock if it is called.  We unlock only
367 * if we don't call into sowakeup.  If any code is introduced that
368 * directly invokes the underlying sowakeup() primitives, it must
369 * maintain the same semantics.
370 */
371#define	sorwakeup_locked(so) do {					\
372	SOCKBUF_LOCK_ASSERT(&(so)->so_rcv);				\
373	if (sb_notify(&(so)->so_rcv))					\
374		sowakeup((so), &(so)->so_rcv);	 			\
375	else								\
376		SOCKBUF_UNLOCK(&(so)->so_rcv);				\
377} while (0)
378
379#define	sorwakeup(so) do {						\
380	SOCKBUF_LOCK(&(so)->so_rcv);					\
381	sorwakeup_locked(so);						\
382} while (0)
383
384#define	sowwakeup_locked(so) do {					\
385	SOCKBUF_LOCK_ASSERT(&(so)->so_snd);				\
386	if (sb_notify(&(so)->so_snd))					\
387		sowakeup((so), &(so)->so_snd); 				\
388	else								\
389		SOCKBUF_UNLOCK(&(so)->so_snd);				\
390} while (0)
391
392#define	sowwakeup(so) do {						\
393	SOCKBUF_LOCK(&(so)->so_snd);					\
394	sowwakeup_locked(so);						\
395} while (0)
396
397/*
398 * Argument structure for sosetopt et seq.  This is in the KERNEL
399 * section because it will never be visible to user code.
400 */
401enum sopt_dir { SOPT_GET, SOPT_SET };
402struct sockopt {
403	enum	sopt_dir sopt_dir; /* is this a get or a set? */
404	int	sopt_level;	/* second arg of [gs]etsockopt */
405	int	sopt_name;	/* third arg of [gs]etsockopt */
406	void   *sopt_val;	/* fourth arg of [gs]etsockopt */
407	size_t	sopt_valsize;	/* (almost) fifth arg of [gs]etsockopt */
408	struct	thread *sopt_td; /* calling thread or null if kernel */
409};
410
411struct accept_filter {
412	char	accf_name[16];
413	void	(*accf_callback)
414		(struct socket *so, void *arg, int waitflag);
415	void *	(*accf_create)
416		(struct socket *so, char *arg);
417	void	(*accf_destroy)
418		(struct socket *so);
419	SLIST_ENTRY(accept_filter) accf_next;
420};
421
422#ifdef MALLOC_DECLARE
423MALLOC_DECLARE(M_ACCF);
424MALLOC_DECLARE(M_PCB);
425MALLOC_DECLARE(M_SONAME);
426#endif
427
428extern int	maxsockets;
429extern u_long	sb_max;
430extern struct uma_zone *socket_zone;
431extern so_gen_t so_gencnt;
432
433struct mbuf;
434struct sockaddr;
435struct ucred;
436struct uio;
437
438/*
439 * From uipc_socket and friends
440 */
441int	kern_setsockopt(struct socket *so, int level, int optname,
442    void *optval, size_t optlen);
443int	sockargs(struct mbuf **mp, caddr_t buf, int buflen, int type);
444int	getsockaddr(struct sockaddr **namp, caddr_t uaddr, size_t len);
445void	sbappend(struct sockbuf *sb, struct mbuf *m);
446void	sbappend_locked(struct sockbuf *sb, struct mbuf *m);
447void	sbappendstream(struct sockbuf *sb, struct mbuf *m);
448void	sbappendstream_locked(struct sockbuf *sb, struct mbuf *m);
449int	sbappendaddr(struct sockbuf *sb, const struct sockaddr *asa,
450	    struct mbuf *m0, struct mbuf *control);
451int	sbappendaddr_locked(struct sockbuf *sb, const struct sockaddr *asa,
452	    struct mbuf *m0, struct mbuf *control);
453int	sbappendcontrol(struct sockbuf *sb, struct mbuf *m0,
454	    struct mbuf *control);
455int	sbappendcontrol_locked(struct sockbuf *sb, struct mbuf *m0,
456	    struct mbuf *control);
457void	sbappendrecord(struct sockbuf *sb, struct mbuf *m0);
458void	sbappendrecord_locked(struct sockbuf *sb, struct mbuf *m0);
459void	sbcheck(struct sockbuf *sb);
460void	sbcompress(struct sockbuf *sb, struct mbuf *m, struct mbuf *n);
461struct mbuf *
462	sbcreatecontrol(caddr_t p, int size, int type, int level);
463void	sbdrop(struct sockbuf *sb, int len);
464void	sbdrop_locked(struct sockbuf *sb, int len);
465void	sbdroprecord(struct sockbuf *sb);
466void	sbdroprecord_locked(struct sockbuf *sb);
467void	sbflush(struct sockbuf *sb);
468void	sbflush_locked(struct sockbuf *sb);
469void	sbinsertoob(struct sockbuf *sb, struct mbuf *m0);
470void	sbinsertoob_locked(struct sockbuf *sb, struct mbuf *m0);
471void	sbrelease(struct sockbuf *sb, struct socket *so);
472void	sbrelease_locked(struct sockbuf *sb, struct socket *so);
473int	sbreserve(struct sockbuf *sb, u_long cc, struct socket *so,
474	    struct thread *td);
475int	sbreserve_locked(struct sockbuf *sb, u_long cc, struct socket *so,
476	    struct thread *td);
477void	sbtoxsockbuf(struct sockbuf *sb, struct xsockbuf *xsb);
478int	sbwait(struct sockbuf *sb);
479int	sb_lock(struct sockbuf *sb);
480int	soabort(struct socket *so);
481int	soaccept(struct socket *so, struct sockaddr **nam);
482struct	socket *soalloc(int mflags);
483int	socheckuid(struct socket *so, uid_t uid);
484int	sobind(struct socket *so, struct sockaddr *nam, struct thread *td);
485void	socantrcvmore(struct socket *so);
486void	socantrcvmore_locked(struct socket *so);
487void	socantsendmore(struct socket *so);
488void	socantsendmore_locked(struct socket *so);
489int	soclose(struct socket *so);
490int	soconnect(struct socket *so, struct sockaddr *nam, struct thread *td);
491int	soconnect2(struct socket *so1, struct socket *so2);
492int	socow_setup(struct mbuf *m0, struct uio *uio);
493int	socreate(int dom, struct socket **aso, int type, int proto,
494	    struct ucred *cred, struct thread *td);
495void	sodealloc(struct socket *so);
496int	sodisconnect(struct socket *so);
497struct	sockaddr *sodupsockaddr(const struct sockaddr *sa, int mflags);
498void	sofree(struct socket *so);
499int	sogetopt(struct socket *so, struct sockopt *sopt);
500void	sohasoutofband(struct socket *so);
501void	soisconnected(struct socket *so);
502void	soisconnecting(struct socket *so);
503void	soisdisconnected(struct socket *so);
504void	soisdisconnecting(struct socket *so);
505int	solisten(struct socket *so, int backlog, struct thread *td);
506struct socket *
507	sonewconn(struct socket *head, int connstatus);
508int	sooptcopyin(struct sockopt *sopt, void *buf, size_t len, size_t minlen);
509int	sooptcopyout(struct sockopt *sopt, const void *buf, size_t len);
510
511/* XXX; prepare mbuf for (__FreeBSD__ < 3) routines. */
512int	soopt_getm(struct sockopt *sopt, struct mbuf **mp);
513int	soopt_mcopyin(struct sockopt *sopt, struct mbuf *m);
514int	soopt_mcopyout(struct sockopt *sopt, struct mbuf *m);
515
516int	sopoll(struct socket *so, int events, struct ucred *active_cred,
517	    struct thread *td);
518int	soreceive(struct socket *so, struct sockaddr **paddr, struct uio *uio,
519	    struct mbuf **mp0, struct mbuf **controlp, int *flagsp);
520int	soreserve(struct socket *so, u_long sndcc, u_long rcvcc);
521void	sorflush(struct socket *so);
522int	sosend(struct socket *so, struct sockaddr *addr, struct uio *uio,
523	    struct mbuf *top, struct mbuf *control, int flags,
524	    struct thread *td);
525int	sosetopt(struct socket *so, struct sockopt *sopt);
526int	soshutdown(struct socket *so, int how);
527void	sotoxsocket(struct socket *so, struct xsocket *xso);
528void	sowakeup(struct socket *so, struct sockbuf *sb);
529
530#ifdef SOCKBUF_DEBUG
531void	sblastrecordchk(struct sockbuf *, const char *, int);
532#define	SBLASTRECORDCHK(sb)	sblastrecordchk((sb), __FILE__, __LINE__)
533
534void	sblastmbufchk(struct sockbuf *, const char *, int);
535#define	SBLASTMBUFCHK(sb)	sblastmbufchk((sb), __FILE__, __LINE__)
536#else
537#define	SBLASTRECORDCHK(sb)      /* nothing */
538#define	SBLASTMBUFCHK(sb)        /* nothing */
539#endif /* SOCKBUF_DEBUG */
540
541/*
542 * Accept filter functions (duh).
543 */
544int	accept_filt_add(struct accept_filter *filt);
545int	accept_filt_del(char *name);
546struct	accept_filter *accept_filt_get(char *name);
547#ifdef ACCEPT_FILTER_MOD
548#ifdef SYSCTL_DECL
549SYSCTL_DECL(_net_inet_accf);
550#endif
551int	accept_filt_generic_mod_event(module_t mod, int event, void *data);
552#endif
553
554#endif /* _KERNEL */
555
556#endif /* !_SYS_SOCKETVAR_H_ */
557