xref: /freebsd-13.1/sys/sys/socketvar.h (revision f9832988)
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 1982, 1986, 1990, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. Neither the name of the University nor the names of its contributors
16  *    may be used to endorse or promote products derived from this software
17  *    without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  *
31  *	@(#)socketvar.h	8.3 (Berkeley) 2/19/95
32  *
33  * $FreeBSD$
34  */
35 
36 #ifndef _SYS_SOCKETVAR_H_
37 #define _SYS_SOCKETVAR_H_
38 
39 /*
40  * Socket generation count type.  Also used in xinpcb, xtcpcb, xunpcb.
41  */
42 typedef uint64_t so_gen_t;
43 
44 #if defined(_KERNEL) || defined(_WANT_SOCKET)
45 #include <sys/queue.h>			/* for TAILQ macros */
46 #include <sys/selinfo.h>		/* for struct selinfo */
47 #include <sys/_lock.h>
48 #include <sys/_mutex.h>
49 #include <sys/osd.h>
50 #include <sys/_sx.h>
51 #include <sys/sockbuf.h>
52 #ifdef _KERNEL
53 #include <sys/caprights.h>
54 #include <sys/sockopt.h>
55 #endif
56 
57 struct vnet;
58 
59 /*
60  * Kernel structure per socket.
61  * Contains send and receive buffer queues,
62  * handle on protocol and pointer to protocol
63  * private data and error information.
64  */
65 typedef	int so_upcall_t(struct socket *, void *, int);
66 typedef	void so_dtor_t(struct socket *);
67 
68 struct socket;
69 
70 enum socket_qstate {
71 	SQ_NONE = 0,
72 	SQ_INCOMP = 0x0800,	/* on sol_incomp */
73 	SQ_COMP = 0x1000,	/* on sol_comp */
74 };
75 
76 /*-
77  * Locking key to struct socket:
78  * (a) constant after allocation, no locking required.
79  * (b) locked by SOCK_LOCK(so).
80  * (cr) locked by SOCKBUF_LOCK(&so->so_rcv).
81  * (cs) locked by SOCKBUF_LOCK(&so->so_snd).
82  * (e) locked by SOLISTEN_LOCK() of corresponding listening socket.
83  * (f) not locked since integer reads/writes are atomic.
84  * (g) used only as a sleep/wakeup address, no value.
85  * (h) locked by global mutex so_global_mtx.
86  * (k) locked by KTLS workqueue mutex
87  */
88 TAILQ_HEAD(accept_queue, socket);
89 struct socket {
90 	struct mtx	so_lock;
91 	volatile u_int	so_count;	/* (b / refcount) */
92 	struct selinfo	so_rdsel;	/* (b/cr) for so_rcv/so_comp */
93 	struct selinfo	so_wrsel;	/* (b/cs) for so_snd */
94 	short	so_type;		/* (a) generic type, see socket.h */
95 	int	so_options;		/* (b) from socket call, see socket.h */
96 	short	so_linger;		/* time to linger close(2) */
97 	short	so_state;		/* (b) internal state flags SS_* */
98 	void	*so_pcb;		/* protocol control block */
99 	struct	vnet *so_vnet;		/* (a) network stack instance */
100 	struct	protosw *so_proto;	/* (a) protocol handle */
101 	short	so_timeo;		/* (g) connection timeout */
102 	u_short	so_error;		/* (f) error affecting connection */
103 	u_short so_rerror;		/* (f) error affecting connection */
104 	struct	sigio *so_sigio;	/* [sg] information for async I/O or
105 					   out of band data (SIGURG) */
106 	struct	ucred *so_cred;		/* (a) user credentials */
107 	struct	label *so_label;	/* (b) MAC label for socket */
108 	/* NB: generation count must not be first. */
109 	so_gen_t so_gencnt;		/* (h) generation count */
110 	void	*so_emuldata;		/* (b) private data for emulators */
111 	so_dtor_t *so_dtor;		/* (b) optional destructor */
112 	struct	osd	osd;		/* Object Specific extensions */
113 	/*
114 	 * so_fibnum, so_user_cookie and friends can be used to attach
115 	 * some user-specified metadata to a socket, which then can be
116 	 * used by the kernel for various actions.
117 	 * so_user_cookie is used by ipfw/dummynet.
118 	 */
119 	int so_fibnum;		/* routing domain for this socket */
120 	uint32_t so_user_cookie;
121 
122 	int so_ts_clock;	/* type of the clock used for timestamps */
123 	uint32_t so_max_pacing_rate;	/* (f) TX rate limit in bytes/s */
124 	union {
125 		/* Regular (data flow) socket. */
126 		struct {
127 			/* (cr, cs) Receive and send buffers. */
128 			struct sockbuf		so_rcv, so_snd;
129 
130 			/* (e) Our place on accept queue. */
131 			TAILQ_ENTRY(socket)	so_list;
132 			struct socket		*so_listen;	/* (b) */
133 			enum socket_qstate so_qstate;		/* (b) */
134 			/* (b) cached MAC label for peer */
135 			struct	label		*so_peerlabel;
136 			u_long	so_oobmark;	/* chars to oob mark */
137 
138 			/* (k) Our place on KTLS RX work queue. */
139 			STAILQ_ENTRY(socket)	so_ktls_rx_list;
140 		};
141 		/*
142 		 * Listening socket, where accepts occur, is so_listen in all
143 		 * subsidiary sockets.  If so_listen is NULL, socket is not
144 		 * related to an accept.  For a listening socket itself
145 		 * sol_incomp queues partially completed connections, while
146 		 * sol_comp is a queue of connections ready to be accepted.
147 		 * If a connection is aborted and it has so_listen set, then
148 		 * it has to be pulled out of either sol_incomp or sol_comp.
149 		 * We allow connections to queue up based on current queue
150 		 * lengths and limit on number of queued connections for this
151 		 * socket.
152 		 */
153 		struct {
154 			/* (e) queue of partial unaccepted connections */
155 			struct accept_queue	sol_incomp;
156 			/* (e) queue of complete unaccepted connections */
157 			struct accept_queue	sol_comp;
158 			u_int	sol_qlen;    /* (e) sol_comp length */
159 			u_int	sol_incqlen; /* (e) sol_incomp length */
160 			u_int	sol_qlimit;  /* (e) queue limit */
161 
162 			/* accept_filter(9) optional data */
163 			struct	accept_filter	*sol_accept_filter;
164 			void	*sol_accept_filter_arg;	/* saved filter args */
165 			char	*sol_accept_filter_str;	/* saved user args */
166 
167 			/* Optional upcall, for kernel socket. */
168 			so_upcall_t	*sol_upcall;	/* (e) */
169 			void		*sol_upcallarg;	/* (e) */
170 
171 			/* Socket buffer parameters, to be copied to
172 			 * dataflow sockets, accepted from this one. */
173 			int		sol_sbrcv_lowat;
174 			int		sol_sbsnd_lowat;
175 			u_int		sol_sbrcv_hiwat;
176 			u_int		sol_sbsnd_hiwat;
177 			short		sol_sbrcv_flags;
178 			short		sol_sbsnd_flags;
179 			sbintime_t	sol_sbrcv_timeo;
180 			sbintime_t	sol_sbsnd_timeo;
181 
182 			/* Information tracking listen queue overflows. */
183 			struct timeval	sol_lastover;	/* (e) */
184 			int		sol_overcount;	/* (e) */
185 		};
186 	};
187 };
188 #endif	/* defined(_KERNEL) || defined(_WANT_SOCKET) */
189 
190 /*
191  * Socket state bits.
192  *
193  * Historically, these bits were all kept in the so_state field.
194  * They are now split into separate, lock-specific fields.
195  * so_state maintains basic socket state protected by the socket lock.
196  * so_qstate holds information about the socket accept queues.
197  * Each socket buffer also has a state field holding information
198  * relevant to that socket buffer (can't send, rcv).
199  * Many fields will be read without locks to improve performance and avoid
200  * lock order issues.  However, this approach must be used with caution.
201  */
202 #define	SS_NOFDREF		0x0001	/* no file table ref any more */
203 #define	SS_ISCONNECTED		0x0002	/* socket connected to a peer */
204 #define	SS_ISCONNECTING		0x0004	/* in process of connecting to peer */
205 #define	SS_ISDISCONNECTING	0x0008	/* in process of disconnecting */
206 #define	SS_NBIO			0x0100	/* non-blocking ops */
207 #define	SS_ASYNC		0x0200	/* async i/o notify */
208 #define	SS_ISCONFIRMING		0x0400	/* deciding to accept connection req */
209 #define	SS_ISDISCONNECTED	0x2000	/* socket disconnected from peer */
210 
211 /*
212  * Protocols can mark a socket as SS_PROTOREF to indicate that, following
213  * pru_detach, they still want the socket to persist, and will free it
214  * themselves when they are done.  Protocols should only ever call sofree()
215  * following setting this flag in pru_detach(), and never otherwise, as
216  * sofree() bypasses socket reference counting.
217  */
218 #define	SS_PROTOREF		0x4000	/* strong protocol reference */
219 
220 #ifdef _KERNEL
221 
222 #define	SOCK_MTX(so)		(&(so)->so_lock)
223 #define	SOCK_LOCK(so)		mtx_lock(&(so)->so_lock)
224 #define	SOCK_OWNED(so)		mtx_owned(&(so)->so_lock)
225 #define	SOCK_UNLOCK(so)		mtx_unlock(&(so)->so_lock)
226 #define	SOCK_LOCK_ASSERT(so)	mtx_assert(&(so)->so_lock, MA_OWNED)
227 #define	SOCK_UNLOCK_ASSERT(so)	mtx_assert(&(so)->so_lock, MA_NOTOWNED)
228 
229 #define	SOLISTENING(sol)	(((sol)->so_options & SO_ACCEPTCONN) != 0)
230 #define	SOLISTEN_LOCK(sol)	do {					\
231 	mtx_lock(&(sol)->so_lock);					\
232 	KASSERT(SOLISTENING(sol),					\
233 	    ("%s: %p not listening", __func__, (sol)));			\
234 } while (0)
235 #define	SOLISTEN_TRYLOCK(sol)	mtx_trylock(&(sol)->so_lock)
236 #define	SOLISTEN_UNLOCK(sol)	do {					\
237 	KASSERT(SOLISTENING(sol),					\
238 	    ("%s: %p not listening", __func__, (sol)));			\
239 	mtx_unlock(&(sol)->so_lock);					\
240 } while (0)
241 #define	SOLISTEN_LOCK_ASSERT(sol)	do {				\
242 	mtx_assert(&(sol)->so_lock, MA_OWNED);				\
243 	KASSERT(SOLISTENING(sol),					\
244 	    ("%s: %p not listening", __func__, (sol)));			\
245 } while (0)
246 
247 /*
248  * Macros for sockets and socket buffering.
249  */
250 
251 /*
252  * Flags to soiolock().
253  */
254 #define	SBL_WAIT	0x00000001	/* Wait if not immediately available. */
255 #define	SBL_NOINTR	0x00000002	/* Force non-interruptible sleep. */
256 #define	SBL_VALID	(SBL_WAIT | SBL_NOINTR)
257 
258 
259 #define	SBLOCKWAIT(f)	(((f) & MSG_DONTWAIT) ? 0 : SBL_WAIT)
260 
261 #define	SOCK_IO_SEND_LOCK(so, flags)					\
262 	soiolock((so), &(so)->so_snd.sb_sx, (flags))
263 #define	SOCK_IO_SEND_UNLOCK(so)						\
264 	soiounlock(&(so)->so_snd.sb_sx)
265 #define	SOCK_IO_RECV_LOCK(so, flags)					\
266 	soiolock((so), &(so)->so_rcv.sb_sx, (flags))
267 #define	SOCK_IO_RECV_UNLOCK(so)						\
268 	soiounlock(&(so)->so_rcv.sb_sx)
269 
270 /*
271  * Do we need to notify the other side when I/O is possible?
272  */
273 #define	sb_notify(sb)	(((sb)->sb_flags & (SB_WAIT | SB_SEL | SB_ASYNC | \
274     SB_UPCALL | SB_AIO | SB_KNOTE)) != 0)
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	soreadabledata(so) \
282 	(sbavail(&(so)->so_rcv) >= (so)->so_rcv.sb_lowat || \
283 	(so)->so_error || (so)->so_rerror)
284 #define	soreadable(so) \
285 	(soreadabledata(so) || ((so)->so_rcv.sb_state & SBS_CANTRCVMORE))
286 
287 /* can we write something to so? */
288 #define	sowriteable(so) \
289     ((sbspace(&(so)->so_snd) >= (so)->so_snd.sb_lowat && \
290 	(((so)->so_state&SS_ISCONNECTED) || \
291 	  ((so)->so_proto->pr_flags&PR_CONNREQUIRED)==0)) || \
292      ((so)->so_snd.sb_state & SBS_CANTSENDMORE) || \
293      (so)->so_error)
294 
295 /*
296  * soref()/sorele() ref-count the socket structure.
297  * soref() may be called without owning socket lock, but in that case a
298  * caller must own something that holds socket, and so_count must be not 0.
299  * Note that you must still explicitly close the socket, but the last ref
300  * count will free the structure.
301  */
302 #define	soref(so)	refcount_acquire(&(so)->so_count)
303 #define	sorele(so) do {							\
304 	SOCK_LOCK_ASSERT(so);						\
305 	if (refcount_release(&(so)->so_count))				\
306 		sofree(so);						\
307 	else								\
308 		SOCK_UNLOCK(so);					\
309 } while (0)
310 
311 /*
312  * In sorwakeup() and sowwakeup(), acquire the socket buffer lock to
313  * avoid a non-atomic test-and-wakeup.  However, sowakeup is
314  * responsible for releasing the lock if it is called.  We unlock only
315  * if we don't call into sowakeup.  If any code is introduced that
316  * directly invokes the underlying sowakeup() primitives, it must
317  * maintain the same semantics.
318  */
319 #define	sorwakeup_locked(so) do {					\
320 	SOCKBUF_LOCK_ASSERT(&(so)->so_rcv);				\
321 	if (sb_notify(&(so)->so_rcv))					\
322 		sowakeup((so), &(so)->so_rcv);	 			\
323 	else								\
324 		SOCKBUF_UNLOCK(&(so)->so_rcv);				\
325 } while (0)
326 
327 #define	sorwakeup(so) do {						\
328 	SOCKBUF_LOCK(&(so)->so_rcv);					\
329 	sorwakeup_locked(so);						\
330 } while (0)
331 
332 #define	sowwakeup_locked(so) do {					\
333 	SOCKBUF_LOCK_ASSERT(&(so)->so_snd);				\
334 	if (sb_notify(&(so)->so_snd))					\
335 		sowakeup((so), &(so)->so_snd); 				\
336 	else								\
337 		SOCKBUF_UNLOCK(&(so)->so_snd);				\
338 } while (0)
339 
340 #define	sowwakeup(so) do {						\
341 	SOCKBUF_LOCK(&(so)->so_snd);					\
342 	sowwakeup_locked(so);						\
343 } while (0)
344 
345 struct accept_filter {
346 	char	accf_name[16];
347 	int	(*accf_callback)
348 		(struct socket *so, void *arg, int waitflag);
349 	void *	(*accf_create)
350 		(struct socket *so, char *arg);
351 	void	(*accf_destroy)
352 		(struct socket *so);
353 	SLIST_ENTRY(accept_filter) accf_next;
354 };
355 
356 #define	ACCEPT_FILTER_DEFINE(modname, filtname, cb, create, destroy, ver) \
357 	static struct accept_filter modname##_filter = {		\
358 		.accf_name = filtname,					\
359 		.accf_callback = cb,					\
360 		.accf_create = create,					\
361 		.accf_destroy = destroy,				\
362 	};								\
363 	static moduledata_t modname##_mod = {				\
364 		.name = __XSTRING(modname),				\
365 		.evhand = accept_filt_generic_mod_event,		\
366 		.priv = &modname##_filter,				\
367 	};								\
368 	DECLARE_MODULE(modname, modname##_mod, SI_SUB_DRIVERS,		\
369 	    SI_ORDER_MIDDLE);						\
370 	MODULE_VERSION(modname, ver)
371 
372 #ifdef MALLOC_DECLARE
373 MALLOC_DECLARE(M_ACCF);
374 MALLOC_DECLARE(M_PCB);
375 MALLOC_DECLARE(M_SONAME);
376 #endif
377 
378 /*
379  * Socket specific helper hook point identifiers
380  * Do not leave holes in the sequence, hook registration is a loop.
381  */
382 #define HHOOK_SOCKET_OPT		0
383 #define HHOOK_SOCKET_CREATE		1
384 #define HHOOK_SOCKET_RCV 		2
385 #define HHOOK_SOCKET_SND		3
386 #define HHOOK_FILT_SOREAD		4
387 #define HHOOK_FILT_SOWRITE		5
388 #define HHOOK_SOCKET_CLOSE		6
389 #define HHOOK_SOCKET_LAST		HHOOK_SOCKET_CLOSE
390 
391 struct socket_hhook_data {
392 	struct socket	*so;
393 	struct mbuf	*m;
394 	void		*hctx;		/* hook point specific data*/
395 	int		status;
396 };
397 
398 extern int	maxsockets;
399 extern u_long	sb_max;
400 extern so_gen_t so_gencnt;
401 
402 struct file;
403 struct filecaps;
404 struct filedesc;
405 struct mbuf;
406 struct sockaddr;
407 struct ucred;
408 struct uio;
409 
410 /* 'which' values for socket upcalls. */
411 #define	SO_RCV		1
412 #define	SO_SND		2
413 
414 /* Return values for socket upcalls. */
415 #define	SU_OK		0
416 #define	SU_ISCONNECTED	1
417 
418 /*
419  * From uipc_socket and friends
420  */
421 int	getsockaddr(struct sockaddr **namp, const struct sockaddr *uaddr,
422 	    size_t len);
423 int	getsock_cap(struct thread *td, int fd, cap_rights_t *rightsp,
424 	    struct file **fpp, u_int *fflagp, struct filecaps *havecaps);
425 void	soabort(struct socket *so);
426 int	soaccept(struct socket *so, struct sockaddr **nam);
427 void	soaio_enqueue(struct task *task);
428 void	soaio_rcv(void *context, int pending);
429 void	soaio_snd(void *context, int pending);
430 int	socheckuid(struct socket *so, uid_t uid);
431 int	sobind(struct socket *so, struct sockaddr *nam, struct thread *td);
432 int	sobindat(int fd, struct socket *so, struct sockaddr *nam,
433 	    struct thread *td);
434 int	soclose(struct socket *so);
435 int	soconnect(struct socket *so, struct sockaddr *nam, struct thread *td);
436 int	soconnectat(int fd, struct socket *so, struct sockaddr *nam,
437 	    struct thread *td);
438 int	soconnect2(struct socket *so1, struct socket *so2);
439 int	socreate(int dom, struct socket **aso, int type, int proto,
440 	    struct ucred *cred, struct thread *td);
441 int	sodisconnect(struct socket *so);
442 void	sodtor_set(struct socket *, so_dtor_t *);
443 struct	sockaddr *sodupsockaddr(const struct sockaddr *sa, int mflags);
444 void	sofree(struct socket *so);
445 void	sohasoutofband(struct socket *so);
446 int	solisten(struct socket *so, int backlog, struct thread *td);
447 void	solisten_proto(struct socket *so, int backlog);
448 int	solisten_proto_check(struct socket *so);
449 int	solisten_dequeue(struct socket *, struct socket **, int);
450 struct socket *
451 	sonewconn(struct socket *head, int connstatus);
452 struct socket *
453 	sopeeloff(struct socket *);
454 int	sopoll(struct socket *so, int events, struct ucred *active_cred,
455 	    struct thread *td);
456 int	sopoll_generic(struct socket *so, int events,
457 	    struct ucred *active_cred, struct thread *td);
458 int	soreceive(struct socket *so, struct sockaddr **paddr, struct uio *uio,
459 	    struct mbuf **mp0, struct mbuf **controlp, int *flagsp);
460 int	soreceive_stream(struct socket *so, struct sockaddr **paddr,
461 	    struct uio *uio, struct mbuf **mp0, struct mbuf **controlp,
462 	    int *flagsp);
463 int	soreceive_dgram(struct socket *so, struct sockaddr **paddr,
464 	    struct uio *uio, struct mbuf **mp0, struct mbuf **controlp,
465 	    int *flagsp);
466 int	soreceive_generic(struct socket *so, struct sockaddr **paddr,
467 	    struct uio *uio, struct mbuf **mp0, struct mbuf **controlp,
468 	    int *flagsp);
469 int	soreserve(struct socket *so, u_long sndcc, u_long rcvcc);
470 void	sorflush(struct socket *so);
471 int	sosend(struct socket *so, struct sockaddr *addr, struct uio *uio,
472 	    struct mbuf *top, struct mbuf *control, int flags,
473 	    struct thread *td);
474 int	sosend_dgram(struct socket *so, struct sockaddr *addr,
475 	    struct uio *uio, struct mbuf *top, struct mbuf *control,
476 	    int flags, struct thread *td);
477 int	sosend_generic(struct socket *so, struct sockaddr *addr,
478 	    struct uio *uio, struct mbuf *top, struct mbuf *control,
479 	    int flags, struct thread *td);
480 int	soshutdown(struct socket *so, int how);
481 void	soupcall_clear(struct socket *, int);
482 void	soupcall_set(struct socket *, int, so_upcall_t, void *);
483 void	solisten_upcall_set(struct socket *, so_upcall_t, void *);
484 void	sowakeup(struct socket *so, struct sockbuf *sb);
485 void	sowakeup_aio(struct socket *so, struct sockbuf *sb);
486 void	solisten_wakeup(struct socket *);
487 int	selsocket(struct socket *so, int events, struct timeval *tv,
488 	    struct thread *td);
489 void	soisconnected(struct socket *so);
490 void	soisconnecting(struct socket *so);
491 void	soisdisconnected(struct socket *so);
492 void	soisdisconnecting(struct socket *so);
493 void	socantrcvmore(struct socket *so);
494 void	socantrcvmore_locked(struct socket *so);
495 void	socantsendmore(struct socket *so);
496 void	socantsendmore_locked(struct socket *so);
497 void	soroverflow(struct socket *so);
498 void	soroverflow_locked(struct socket *so);
499 int	soiolock(struct socket *so, struct sx *sx, int flags);
500 void	soiounlock(struct sx *sx);
501 
502 /*
503  * Accept filter functions (duh).
504  */
505 int	accept_filt_add(struct accept_filter *filt);
506 int	accept_filt_del(char *name);
507 struct	accept_filter *accept_filt_get(char *name);
508 #ifdef ACCEPT_FILTER_MOD
509 #ifdef SYSCTL_DECL
510 SYSCTL_DECL(_net_inet_accf);
511 #endif
512 int	accept_filt_generic_mod_event(module_t mod, int event, void *data);
513 #endif
514 
515 #endif /* _KERNEL */
516 
517 /*
518  * Structure to export socket from kernel to utilities, via sysctl(3).
519  */
520 struct xsocket {
521 	ksize_t		xso_len;	/* length of this structure */
522 	kvaddr_t	xso_so;		/* kernel address of struct socket */
523 	kvaddr_t	so_pcb;		/* kernel address of struct inpcb */
524 	uint64_t	so_oobmark;
525 	int64_t		so_spare64[8];
526 	int32_t		xso_protocol;
527 	int32_t		xso_family;
528 	uint32_t	so_qlen;
529 	uint32_t	so_incqlen;
530 	uint32_t	so_qlimit;
531 	pid_t		so_pgid;
532 	uid_t		so_uid;
533 	int32_t		so_spare32[8];
534 	int16_t		so_type;
535 	int16_t		so_options;
536 	int16_t		so_linger;
537 	int16_t		so_state;
538 	int16_t		so_timeo;
539 	uint16_t	so_error;
540 	struct xsockbuf {
541 		uint32_t	sb_cc;
542 		uint32_t	sb_hiwat;
543 		uint32_t	sb_mbcnt;
544 		uint32_t	sb_mcnt;
545 		uint32_t	sb_ccnt;
546 		uint32_t	sb_mbmax;
547 		int32_t		sb_lowat;
548 		int32_t		sb_timeo;
549 		int16_t		sb_flags;
550 	} so_rcv, so_snd;
551 };
552 
553 #ifdef _KERNEL
554 void	sotoxsocket(struct socket *so, struct xsocket *xso);
555 void	sbtoxsockbuf(struct sockbuf *sb, struct xsockbuf *xsb);
556 #endif
557 
558 /*
559  * Socket buffer state bits.  Exported via libprocstat(3).
560  */
561 #define	SBS_CANTSENDMORE	0x0010	/* can't send more data to peer */
562 #define	SBS_CANTRCVMORE		0x0020	/* can't receive more data from peer */
563 #define	SBS_RCVATMARK		0x0040	/* at mark on input */
564 
565 #endif /* !_SYS_SOCKETVAR_H_ */
566