socketvar.h revision 130831
191094Sdes/*-
2115619Sdes * Copyright (c) 1982, 1986, 1990, 1993
3228690Sdes *	The Regents of the University of California.  All rights reserved.
491094Sdes *
591094Sdes * Redistribution and use in source and binary forms, with or without
691094Sdes * modification, are permitted provided that the following conditions
799158Sdes * are met:
899158Sdes * 1. Redistributions of source code must retain the above copyright
999158Sdes *    notice, this list of conditions and the following disclaimer.
1091094Sdes * 2. Redistributions in binary form must reproduce the above copyright
1191094Sdes *    notice, this list of conditions and the following disclaimer in the
1291094Sdes *    documentation and/or other materials provided with the distribution.
1391094Sdes * 4. Neither the name of the University nor the names of its contributors
1491094Sdes *    may be used to endorse or promote products derived from this software
1591094Sdes *    without specific prior written permission.
1691094Sdes *
1791094Sdes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1891094Sdes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1991094Sdes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2091094Sdes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2191094Sdes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2291094Sdes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2391094Sdes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2491094Sdes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2591094Sdes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2691094Sdes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2791094Sdes * SUCH DAMAGE.
2891094Sdes *
2991094Sdes *	@(#)socketvar.h	8.3 (Berkeley) 2/19/95
3091094Sdes * $FreeBSD: head/sys/sys/socketvar.h 130831 2004-06-21 00:20:43Z rwatson $
3191094Sdes */
3291094Sdes
3391094Sdes#ifndef _SYS_SOCKETVAR_H_
3491094Sdes#define _SYS_SOCKETVAR_H_
35255376Sdes
3691094Sdes#include <sys/queue.h>			/* for TAILQ macros */
3791094Sdes#include <sys/selinfo.h>		/* for struct selinfo */
38228690Sdes#include <sys/_lock.h>
39228690Sdes#include <sys/_mutex.h>
40228690Sdes
41228690Sdes/*
4291094Sdes * Kernel structure per socket.
4391094Sdes * Contains send and receive buffer queues,
4491094Sdes * handle on protocol and pointer to protocol
4591094Sdes * private data and error information.
4691094Sdes */
4791094Sdestypedef	u_quad_t so_gen_t;
4891094Sdes
4991094Sdes/*-
5091094Sdes * Locking key to struct socket:
51174832Sdes * (a) constant after allocation, no locking required.
5291094Sdes * (b) locked by SOCK_LOCK(so).
5391094Sdes * (c) locked by SOCKBUF_LOCK(&so->so_rcv).
54115619Sdes * (d) locked by SOCKBUF_LOCK(&so->so_snd).
55255376Sdes * (e) locked by ACCEPT_LOCK().
5691094Sdes * (f) not locked since integer reads/writes are atomic.
5791094Sdes * (g) used only as a sleep/wakeup address, no value.
5891094Sdes */
59255376Sdesstruct socket {
6091094Sdes	int	so_count;		/* (b) reference count */
61255376Sdes	short	so_type;		/* (a) generic type, see socket.h */
6291094Sdes	short	so_options;		/* from socket call, see socket.h */
6391094Sdes	short	so_linger;		/* time to linger while closing */
6491094Sdes	short	so_state;		/* (b) internal state flags SS_* */
65255376Sdes	int	so_qstate;		/* (e) internal state flags SQ_* */
66255376Sdes	void	*so_pcb;		/* protocol control block */
6791094Sdes	struct	protosw *so_proto;	/* (a) protocol handle */
68255376Sdes/*
6991094Sdes * Variables for connection queuing.
7091094Sdes * Socket where accepts occur is so_head in all subsidiary sockets.
7191830Sdes * If so_head is 0, socket is not related to an accept.
72255376Sdes * For head socket so_incomp queues partially completed connections,
7391094Sdes * while so_comp is a queue of connections ready to be accepted.
7491830Sdes * If a connection is aborted and it has so_head set, then
7591094Sdes * it has to be pulled out of either so_incomp or so_comp.
7691094Sdes * We allow connections to queue up based on current queue lengths
7791094Sdes * and limit on number of queued connections for this socket.
7891094Sdes */
7991094Sdes	struct	socket *so_head;	/* (e) back pointer to accept socket */
8091094Sdes	TAILQ_HEAD(, socket) so_incomp;	/* (e) queue of partial unaccepted connections */
8191094Sdes	TAILQ_HEAD(, socket) so_comp;	/* (e) queue of complete unaccepted connections */
8291094Sdes	TAILQ_ENTRY(socket) so_list;	/* (e) list of unaccepted connections */
8391094Sdes	short	so_qlen;		/* (e) number of unaccepted connections */
8491094Sdes	short	so_incqlen;		/* (e) number of unaccepted incomplete
8591094Sdes					   connections */
8691094Sdes	short	so_qlimit;		/* (e) max number queued connections */
8791094Sdes	short	so_timeo;		/* (g) connection timeout */
8891094Sdes	u_short	so_error;		/* error affecting connection */
8991094Sdes	struct	sigio *so_sigio;	/* [sg] information for async I/O or
9091094Sdes					   out of band data (SIGURG) */
9191094Sdes	u_long	so_oobmark;		/* chars to oob mark */
9291094Sdes	TAILQ_HEAD(, aiocblist) so_aiojobq; /* AIO ops waiting on socket */
9391830Sdes/*
94115619Sdes * Variables for socket buffering.
95115619Sdes */
9691094Sdes	struct sockbuf {
9791094Sdes		struct	selinfo sb_sel;	/* process selecting read/write */
9891094Sdes		struct	mtx sb_mtx;	/* sockbuf lock */
9991094Sdes#define	sb_startzero	sb_mb
10091094Sdes		struct	mbuf *sb_mb;	/* (c/d) the mbuf chain */
10191094Sdes		struct	mbuf *sb_mbtail; /* (c/d) the last mbuf in the chain */
10291094Sdes		struct	mbuf *sb_lastrecord;	/* (c/d) first mbuf of last
10391094Sdes						 * record in socket buffer */
10491094Sdes		u_int	sb_cc;		/* (c/d) actual chars in buffer */
10591094Sdes		u_int	sb_hiwat;	/* (c/d) max actual char count */
10691094Sdes		u_int	sb_mbcnt;	/* (c/d) chars of mbufs used */
10791094Sdes		u_int	sb_mbmax;	/* (c/d) max chars of mbufs to use */
10891094Sdes		u_int	sb_ctl;		/* (c/d) non-data chars in buffer */
10991094Sdes		int	sb_lowat;	/* (c/d) low water mark */
11091094Sdes		int	sb_timeo;	/* (c/d) timeout for read/write */
111236099Sdes		short	sb_flags;	/* (c/d) flags, see below */
11291094Sdes		short	sb_state;	/* (c/d) socket state on sockbuf */
113116520Sdes	} so_rcv, so_snd;
114115619Sdes/*
11591094Sdes * Constants for sb_flags field of struct sockbuf.
11691094Sdes */
11791094Sdes#define	SB_MAX		(256*1024)	/* default for max chars in sockbuf */
11891094Sdes#define	SB_LOCK		0x01		/* lock on data queue */
11991094Sdes#define	SB_WANT		0x02		/* someone is waiting to lock */
12091094Sdes#define	SB_WAIT		0x04		/* someone is waiting for data/space */
12191094Sdes#define	SB_SEL		0x08		/* someone is selecting */
12291094Sdes#define	SB_ASYNC	0x10		/* ASYNC I/O, need signals */
12395908Sdes#define	SB_UPCALL	0x20		/* someone wants an upcall */
12491094Sdes#define	SB_NOINTR	0x40		/* operations not interruptible */
12591094Sdes#define SB_AIO		0x80		/* AIO operations queued */
12691094Sdes#define SB_KNOTE	0x100		/* kernel note attached */
127147455Sdes
12895908Sdes	void	(*so_upcall)(struct socket *, void *, int);
129147455Sdes	void	*so_upcallarg;
130147455Sdes	struct	ucred *so_cred;		/* (a) user credentials */
13191094Sdes	struct	label *so_label;	/* (b) MAC label for socket */
13291100Sdes	struct	label *so_peerlabel;	/* (b) cached MAC label for peer */
13391100Sdes	/* NB: generation count must not be first; easiest to make it last. */
13491100Sdes	so_gen_t so_gencnt;		/* generation count */
13591100Sdes	void	*so_emuldata;		/* private data for emulators */
136 	struct so_accf {
137		struct	accept_filter *so_accept_filter;
138		void	*so_accept_filter_arg;	/* saved filter args */
139		char	*so_accept_filter_str;	/* saved user args */
140	} *so_accf;
141};
142
143#define SB_EMPTY_FIXUP(sb) do {						\
144	if ((sb)->sb_mb == NULL) {					\
145		(sb)->sb_mbtail = NULL;					\
146		(sb)->sb_lastrecord = NULL;				\
147	}								\
148} while (/*CONSTCOND*/0)
149
150/*
151 * Global accept mutex to serialize access to accept queues and
152 * fields associated with multiple sockets.  This allows us to
153 * avoid defining a lock order between listen and accept sockets
154 * until such time as it proves to be a good idea.
155 */
156extern struct mtx accept_mtx;
157#define	ACCEPT_LOCK()			mtx_lock(&accept_mtx)
158#define	ACCEPT_UNLOCK()			mtx_unlock(&accept_mtx)
159
160/*
161 * Per-socket buffer mutex used to protect most fields in the socket
162 * buffer.
163 */
164#define	SOCKBUF_MTX(_sb)		(&(_sb)->sb_mtx)
165#define	SOCKBUF_LOCK_INIT(_sb, _name) \
166	mtx_init(SOCKBUF_MTX(_sb), _name, NULL, MTX_DEF)
167#define	SOCKBUF_LOCK_DESTROY(_sb)	mtx_destroy(SOCKBUF_MTX(_sb))
168#define	SOCKBUF_LOCK(_sb)		mtx_lock(SOCKBUF_MTX(_sb))
169#define	SOCKBUF_OWNED(_sb)		mtx_owned(SOCKBUF_MTX(_sb))
170#define	SOCKBUF_UNLOCK(_sb)		mtx_unlock(SOCKBUF_MTX(_sb))
171#define	SOCKBUF_LOCK_ASSERT(_sb)	mtx_assert(SOCKBUF_MTX(_sb), MA_OWNED)
172
173/*
174 * Per-socket mutex: we reuse the receive socket buffer mutex for space
175 * efficiency.  This decision should probably be revisited as we optimize
176 * locking for the socket code.
177 */
178#define	SOCK_MTX(_so)			SOCKBUF_MTX(&(_so)->so_rcv)
179#define	SOCK_LOCK(_so)			SOCKBUF_LOCK(&(_so)->so_rcv)
180#define	SOCK_OWNED(_so)			SOCKBUF_OWNED(&(_so)->so_rcv)
181#define	SOCK_UNLOCK(_so)		SOCKBUF_UNLOCK(&(_so)->so_rcv)
182#define	SOCK_LOCK_ASSERT(_so)		SOCKBUF_LOCK_ASSERT(&(_so)->so_rcv)
183
184/*
185 * Socket state bits.
186 *
187 * Historically, this bits were all kept in the so_state field.  For
188 * locking reasons, they are now in multiple fields, as they are
189 * locked differently.  so_state maintains basic socket state protected
190 * by the socket lock.  so_qstate holds information about the socket
191 * accept queues.  Each socket buffer also has a state field holding
192 * information relevant to that socket buffer (can't send, rcv).  Many
193 * fields will be read without locks to improve performance and avoid
194 * lock order issues.  However, this approach must be used with caution.
195 */
196#define	SS_NOFDREF		0x0001	/* no file table ref any more */
197#define	SS_ISCONNECTED		0x0002	/* socket connected to a peer */
198#define	SS_ISCONNECTING		0x0004	/* in process of connecting to peer */
199#define	SS_ISDISCONNECTING	0x0008	/* in process of disconnecting */
200#define	SS_NBIO			0x0100	/* non-blocking ops */
201#define	SS_ASYNC		0x0200	/* async i/o notify */
202#define	SS_ISCONFIRMING		0x0400	/* deciding to accept connection req */
203#define	SS_ISDISCONNECTED	0x2000	/* socket disconnected from peer */
204
205/*
206 * Socket state bits now stored in the socket buffer state field.
207 */
208#define	SBS_CANTSENDMORE	0x0010	/* can't send more data to peer */
209#define	SBS_CANTRCVMORE		0x0020	/* can't receive more data from peer */
210#define	SBS_RCVATMARK		0x0040	/* at mark on input */
211
212/*
213 * Socket state bits stored in so_qstate.
214 */
215#define	SQ_INCOMP		0x0800	/* unaccepted, incomplete connection */
216#define	SQ_COMP			0x1000	/* unaccepted, complete connection */
217
218/*
219 * Externalized form of struct socket used by the sysctl(3) interface.
220 */
221struct xsocket {
222	size_t	xso_len;	/* length of this structure */
223	struct	socket *xso_so;	/* makes a convenient handle sometimes */
224	short	so_type;
225	short	so_options;
226	short	so_linger;
227	short	so_state;
228	caddr_t	so_pcb;		/* another convenient handle */
229	int	xso_protocol;
230	int	xso_family;
231	short	so_qlen;
232	short	so_incqlen;
233	short	so_qlimit;
234	short	so_timeo;
235	u_short	so_error;
236	pid_t	so_pgid;
237	u_long	so_oobmark;
238	struct xsockbuf {
239		u_int	sb_cc;
240		u_int	sb_hiwat;
241		u_int	sb_mbcnt;
242		u_int	sb_mbmax;
243		int	sb_lowat;
244		int	sb_timeo;
245		short	sb_flags;
246	} so_rcv, so_snd;
247	uid_t	so_uid;		/* XXX */
248};
249
250#ifdef _KERNEL
251
252/*
253 * Macros for sockets and socket buffering.
254 */
255
256/*
257 * Do we need to notify the other side when I/O is possible?
258 */
259#define	sb_notify(sb)	(((sb)->sb_flags & (SB_WAIT | SB_SEL | SB_ASYNC | \
260    SB_UPCALL | SB_AIO | SB_KNOTE)) != 0)
261
262/*
263 * How much space is there in a socket buffer (so->so_snd or so->so_rcv)?
264 * This is problematical if the fields are unsigned, as the space might
265 * still be negative (cc > hiwat or mbcnt > mbmax).  Should detect
266 * overflow and return 0.  Should use "lmin" but it doesn't exist now.
267 */
268#define	sbspace(sb) \
269    ((long) imin((int)((sb)->sb_hiwat - (sb)->sb_cc), \
270	 (int)((sb)->sb_mbmax - (sb)->sb_mbcnt)))
271
272/* do we have to send all at once on a socket? */
273#define	sosendallatonce(so) \
274    ((so)->so_proto->pr_flags & PR_ATOMIC)
275
276/* can we read something from so? */
277#define	soreadable(so) \
278    ((so)->so_rcv.sb_cc >= (so)->so_rcv.sb_lowat || \
279	((so)->so_rcv.sb_state & SBS_CANTRCVMORE) || \
280	!TAILQ_EMPTY(&(so)->so_comp) || (so)->so_error)
281
282/* can we write something to so? */
283#define	sowriteable(so) \
284    ((sbspace(&(so)->so_snd) >= (so)->so_snd.sb_lowat && \
285	(((so)->so_state&SS_ISCONNECTED) || \
286	  ((so)->so_proto->pr_flags&PR_CONNREQUIRED)==0)) || \
287     ((so)->so_snd.sb_state & SBS_CANTSENDMORE) || \
288     (so)->so_error)
289
290/* adjust counters in sb reflecting allocation of m */
291#define	sballoc(sb, m) { \
292	(sb)->sb_cc += (m)->m_len; \
293	if ((m)->m_type != MT_DATA && (m)->m_type != MT_HEADER && \
294	    (m)->m_type != MT_OOBDATA) \
295		(sb)->sb_ctl += (m)->m_len; \
296	(sb)->sb_mbcnt += MSIZE; \
297	if ((m)->m_flags & M_EXT) \
298		(sb)->sb_mbcnt += (m)->m_ext.ext_size; \
299}
300
301/* adjust counters in sb reflecting freeing of m */
302#define	sbfree(sb, m) { \
303	(sb)->sb_cc -= (m)->m_len; \
304	if ((m)->m_type != MT_DATA && (m)->m_type != MT_HEADER && \
305	    (m)->m_type != MT_OOBDATA) \
306		(sb)->sb_ctl -= (m)->m_len; \
307	(sb)->sb_mbcnt -= MSIZE; \
308	if ((m)->m_flags & M_EXT) \
309		(sb)->sb_mbcnt -= (m)->m_ext.ext_size; \
310}
311
312/*
313 * Set lock on sockbuf sb; sleep if lock is already held.
314 * Unless SB_NOINTR is set on sockbuf, sleep is interruptible.
315 * Returns error without lock if sleep is interrupted.
316 */
317#define sblock(sb, wf) ((sb)->sb_flags & SB_LOCK ? \
318		(((wf) == M_WAITOK) ? sb_lock(sb) : EWOULDBLOCK) : \
319		((sb)->sb_flags |= SB_LOCK), 0)
320
321/* release lock on sockbuf sb */
322#define	sbunlock(sb) do { \
323	SOCKBUF_LOCK_ASSERT(sb); \
324	(sb)->sb_flags &= ~SB_LOCK; \
325	if ((sb)->sb_flags & SB_WANT) { \
326		(sb)->sb_flags &= ~SB_WANT; \
327		wakeup(&(sb)->sb_flags); \
328	} \
329} while (0)
330
331/*
332 * soref()/sorele() ref-count the socket structure.  Note that you must
333 * still explicitly close the socket, but the last ref count will free
334 * the structure.
335 */
336#define	soref(so) do {							\
337	SOCK_LOCK_ASSERT(so);						\
338	++(so)->so_count;						\
339} while (0)
340
341#define	sorele(so) do {							\
342	SOCK_LOCK_ASSERT(so);						\
343	if ((so)->so_count <= 0)					\
344		panic("sorele");					\
345	if (--(so)->so_count == 0)					\
346		sofree(so);						\
347	else								\
348		SOCK_UNLOCK(so);					\
349} while (0)
350
351#define	sotryfree(so) do {						\
352	SOCK_LOCK_ASSERT(so);						\
353	if ((so)->so_count == 0)					\
354		sofree(so);						\
355	else								\
356		SOCK_UNLOCK(so);					\
357} while(0)
358
359/*
360 * In sorwakeup() and sowwakeup(), acquire the socket buffer lock to
361 * avoid a non-atomic test-and-wakeup.  However, sowakeup is
362 * responsible for releasing the lock if it is called.  We unlock only
363 * if we don't call into sowakeup.  If any code is introduced that
364 * directly invokes the underlying sowakeup() primitives, it must
365 * maintain the same semantics.
366 */
367#define	sorwakeup_locked(so) do {					\
368	SOCKBUF_LOCK_ASSERT(&(so)->so_rcv);				\
369	if (sb_notify(&(so)->so_rcv))					\
370		sowakeup((so), &(so)->so_rcv);	 			\
371	else								\
372		SOCKBUF_UNLOCK(&(so)->so_rcv);				\
373} while (0)
374
375#define	sorwakeup(so) do {						\
376	SOCKBUF_LOCK(&(so)->so_rcv);					\
377	sorwakeup_locked(so);						\
378} while (0)
379
380#define	sowwakeup_locked(so) do {					\
381	if (sb_notify(&(so)->so_snd))					\
382		sowakeup((so), &(so)->so_snd); 				\
383	else								\
384		SOCKBUF_UNLOCK(&(so)->so_snd);				\
385} while (0)
386
387#define	sowwakeup(so) do {						\
388	SOCKBUF_LOCK(&(so)->so_snd);					\
389	sowwakeup_locked(so);						\
390} while (0)
391
392/*
393 * Argument structure for sosetopt et seq.  This is in the KERNEL
394 * section because it will never be visible to user code.
395 */
396enum sopt_dir { SOPT_GET, SOPT_SET };
397struct sockopt {
398	enum	sopt_dir sopt_dir; /* is this a get or a set? */
399	int	sopt_level;	/* second arg of [gs]etsockopt */
400	int	sopt_name;	/* third arg of [gs]etsockopt */
401	void   *sopt_val;	/* fourth arg of [gs]etsockopt */
402	size_t	sopt_valsize;	/* (almost) fifth arg of [gs]etsockopt */
403	struct	thread *sopt_td; /* calling thread or null if kernel */
404};
405
406struct accept_filter {
407	char	accf_name[16];
408	void	(*accf_callback)
409		(struct socket *so, void *arg, int waitflag);
410	void *	(*accf_create)
411		(struct socket *so, char *arg);
412	void	(*accf_destroy)
413		(struct socket *so);
414	SLIST_ENTRY(accept_filter) accf_next;
415};
416
417#ifdef MALLOC_DECLARE
418MALLOC_DECLARE(M_ACCF);
419MALLOC_DECLARE(M_PCB);
420MALLOC_DECLARE(M_SONAME);
421#endif
422
423extern int	maxsockets;
424extern u_long	sb_max;
425extern struct uma_zone *socket_zone;
426extern so_gen_t so_gencnt;
427
428struct mbuf;
429struct sockaddr;
430struct ucred;
431struct uio;
432
433/*
434 * From uipc_socket and friends
435 */
436int	sockargs(struct mbuf **mp, caddr_t buf, int buflen, int type);
437int	getsockaddr(struct sockaddr **namp, caddr_t uaddr, size_t len);
438void	sbappend(struct sockbuf *sb, struct mbuf *m);
439void	sbappend_locked(struct sockbuf *sb, struct mbuf *m);
440void	sbappendstream(struct sockbuf *sb, struct mbuf *m);
441void	sbappendstream_locked(struct sockbuf *sb, struct mbuf *m);
442int	sbappendaddr(struct sockbuf *sb, const struct sockaddr *asa,
443	    struct mbuf *m0, struct mbuf *control);
444int	sbappendaddr_locked(struct sockbuf *sb, const struct sockaddr *asa,
445	    struct mbuf *m0, struct mbuf *control);
446int	sbappendcontrol(struct sockbuf *sb, struct mbuf *m0,
447	    struct mbuf *control);
448int	sbappendcontrol_locked(struct sockbuf *sb, struct mbuf *m0,
449	    struct mbuf *control);
450void	sbappendrecord(struct sockbuf *sb, struct mbuf *m0);
451void	sbappendrecord_locked(struct sockbuf *sb, struct mbuf *m0);
452void	sbcheck(struct sockbuf *sb);
453void	sbcompress(struct sockbuf *sb, struct mbuf *m, struct mbuf *n);
454struct mbuf *
455	sbcreatecontrol(caddr_t p, int size, int type, int level);
456void	sbdrop(struct sockbuf *sb, int len);
457void	sbdrop_locked(struct sockbuf *sb, int len);
458void	sbdroprecord(struct sockbuf *sb);
459void	sbdroprecord_locked(struct sockbuf *sb);
460void	sbflush(struct sockbuf *sb);
461void	sbflush_locked(struct sockbuf *sb);
462void	sbinsertoob(struct sockbuf *sb, struct mbuf *m0);
463void	sbinsertoob_locked(struct sockbuf *sb, struct mbuf *m0);
464void	sbrelease(struct sockbuf *sb, struct socket *so);
465void	sbrelease_locked(struct sockbuf *sb, struct socket *so);
466int	sbreserve(struct sockbuf *sb, u_long cc, struct socket *so,
467	    struct thread *td);
468void	sbtoxsockbuf(struct sockbuf *sb, struct xsockbuf *xsb);
469int	sbwait(struct sockbuf *sb);
470int	sb_lock(struct sockbuf *sb);
471int	soabort(struct socket *so);
472int	soaccept(struct socket *so, struct sockaddr **nam);
473struct	socket *soalloc(int mflags);
474int	socheckuid(struct socket *so, uid_t uid);
475int	sobind(struct socket *so, struct sockaddr *nam, struct thread *td);
476void	socantrcvmore(struct socket *so);
477void	socantrcvmore_locked(struct socket *so);
478void	socantsendmore(struct socket *so);
479void	socantsendmore_locked(struct socket *so);
480int	soclose(struct socket *so);
481int	soconnect(struct socket *so, struct sockaddr *nam, struct thread *td);
482int	soconnect2(struct socket *so1, struct socket *so2);
483int	socow_setup(struct mbuf *m0, struct uio *uio);
484int	socreate(int dom, struct socket **aso, int type, int proto,
485	    struct ucred *cred, struct thread *td);
486void	sodealloc(struct socket *so);
487int	sodisconnect(struct socket *so);
488struct	sockaddr *sodupsockaddr(const struct sockaddr *sa, int mflags);
489void	sofree(struct socket *so);
490int	sogetopt(struct socket *so, struct sockopt *sopt);
491void	sohasoutofband(struct socket *so);
492void	soisconnected(struct socket *so);
493void	soisconnecting(struct socket *so);
494void	soisdisconnected(struct socket *so);
495void	soisdisconnecting(struct socket *so);
496int	solisten(struct socket *so, int backlog, struct thread *td);
497struct socket *
498	sonewconn(struct socket *head, int connstatus);
499int	sooptcopyin(struct sockopt *sopt, void *buf, size_t len, size_t minlen);
500int	sooptcopyout(struct sockopt *sopt, const void *buf, size_t len);
501
502/* XXX; prepare mbuf for (__FreeBSD__ < 3) routines. */
503int	soopt_getm(struct sockopt *sopt, struct mbuf **mp);
504int	soopt_mcopyin(struct sockopt *sopt, struct mbuf *m);
505int	soopt_mcopyout(struct sockopt *sopt, struct mbuf *m);
506
507int	sopoll(struct socket *so, int events, struct ucred *active_cred,
508	    struct thread *td);
509int	soreceive(struct socket *so, struct sockaddr **paddr, struct uio *uio,
510	    struct mbuf **mp0, struct mbuf **controlp, int *flagsp);
511int	soreserve(struct socket *so, u_long sndcc, u_long rcvcc);
512void	sorflush(struct socket *so);
513int	sosend(struct socket *so, struct sockaddr *addr, struct uio *uio,
514	    struct mbuf *top, struct mbuf *control, int flags,
515	    struct thread *td);
516int	sosetopt(struct socket *so, struct sockopt *sopt);
517int	soshutdown(struct socket *so, int how);
518void	sotoxsocket(struct socket *so, struct xsocket *xso);
519void	sowakeup(struct socket *so, struct sockbuf *sb);
520
521#ifdef SOCKBUF_DEBUG
522void	sblastrecordchk(struct sockbuf *, const char *, int);
523#define	SBLASTRECORDCHK(sb)	sblastrecordchk((sb), __FILE__, __LINE__)
524
525void	sblastmbufchk(struct sockbuf *, const char *, int);
526#define	SBLASTMBUFCHK(sb)	sblastmbufchk((sb), __FILE__, __LINE__)
527#else
528#define	SBLASTRECORDCHK(sb)      /* nothing */
529#define	SBLASTMBUFCHK(sb)        /* nothing */
530#endif /* SOCKBUF_DEBUG */
531
532/*
533 * Accept filter functions (duh).
534 */
535int	accept_filt_add(struct accept_filter *filt);
536int	accept_filt_del(char *name);
537struct	accept_filter *accept_filt_get(char *name);
538#ifdef ACCEPT_FILTER_MOD
539#ifdef SYSCTL_DECL
540SYSCTL_DECL(_net_inet_accf);
541#endif
542int	accept_filt_generic_mod_event(module_t mod, int event, void *data);
543#endif
544
545#endif /* _KERNEL */
546
547#endif /* !_SYS_SOCKETVAR_H_ */
548