]> git.saurik.com Git - apple/xnu.git/blob - bsd/sys/socketvar.h
xnu-1699.22.81.tar.gz
[apple/xnu.git] / bsd / sys / socketvar.h
1 /*
2 * Copyright (c) 2000-2011 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28 /* Copyright (c) 1998, 1999 Apple Computer, Inc. All Rights Reserved */
29 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
30 /*-
31 * Copyright (c) 1982, 1986, 1990, 1993
32 * The Regents of the University of California. All rights reserved.
33 *
34 * Redistribution and use in source and binary forms, with or without
35 * modification, are permitted provided that the following conditions
36 * are met:
37 * 1. Redistributions of source code must retain the above copyright
38 * notice, this list of conditions and the following disclaimer.
39 * 2. Redistributions in binary form must reproduce the above copyright
40 * notice, this list of conditions and the following disclaimer in the
41 * documentation and/or other materials provided with the distribution.
42 * 3. All advertising materials mentioning features or use of this software
43 * must display the following acknowledgement:
44 * This product includes software developed by the University of
45 * California, Berkeley and its contributors.
46 * 4. Neither the name of the University nor the names of its contributors
47 * may be used to endorse or promote products derived from this software
48 * without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * SUCH DAMAGE.
61 *
62 * @(#)socketvar.h 8.3 (Berkeley) 2/19/95
63 * $FreeBSD: src/sys/sys/socketvar.h,v 1.46.2.6 2001/08/31 13:45:49 jlemon Exp $
64 */
65 /*
66 * NOTICE: This file was modified by SPARTA, Inc. in 2005 to introduce
67 * support for mandatory and extensible security protections. This notice
68 * is included in support of clause 2.2 (b) of the Apple Public License,
69 * Version 2.0.
70 */
71
72 #ifndef _SYS_SOCKETVAR_H_
73 #define _SYS_SOCKETVAR_H_
74
75 #include <sys/appleapiopts.h>
76 #include <sys/queue.h> /* for TAILQ macros */
77 #include <sys/select.h> /* for struct selinfo */
78 #include <net/kext_net.h>
79 #include <sys/ev.h>
80 #include <sys/cdefs.h>
81
82 /*
83 * Hacks to get around compiler complaints
84 */
85 struct mbuf;
86 struct socket_filter_entry;
87 struct protosw;
88 struct sockif;
89 struct sockutil;
90
91 #ifdef KERNEL_PRIVATE
92 /* strings for sleep message: */
93 extern char netio[], netcon[], netcls[];
94 #define SOCKET_CACHE_ON
95 #define SO_CACHE_FLUSH_INTERVAL 1 /* Seconds */
96 #define SO_CACHE_TIME_LIMIT (120/SO_CACHE_FLUSH_INTERVAL) /* Seconds */
97 #define SO_CACHE_MAX_FREE_BATCH 50
98 #define MAX_CACHED_SOCKETS 60000
99 #define TEMPDEBUG 0
100
101 /*
102 * Kernel structure per socket.
103 * Contains send and receive buffer queues,
104 * handle on protocol and pointer to protocol
105 * private data and error information.
106 */
107 #endif /* KERNEL_PRIVATE */
108
109 typedef u_quad_t so_gen_t;
110
111 #ifdef PRIVATE
112 #define SO_TC_STATS_MAX 4
113
114 struct data_stats {
115 u_int64_t rxpackets;
116 u_int64_t rxbytes;
117 u_int64_t txpackets;
118 u_int64_t txbytes;
119 };
120 #endif /* PRIVATE */
121
122 #ifdef KERNEL_PRIVATE
123 #ifndef __APPLE__
124 /* We don't support BSD style socket filters */
125 struct accept_filter;
126 #endif
127
128 struct socket {
129 int so_zone; /* zone we were allocated from */
130 short so_type; /* generic type, see socket.h */
131 short so_options; /* from socket call, see socket.h */
132 short so_linger; /* time to linger while closing */
133 short so_state; /* internal state flags SS_*, below */
134 void *so_pcb; /* protocol control block */
135 struct protosw *so_proto; /* protocol handle */
136 /*
137 * Variables for connection queueing.
138 * Socket where accepts occur is so_head in all subsidiary sockets.
139 * If so_head is 0, socket is not related to an accept.
140 * For head socket so_incomp queues partially completed connections,
141 * while so_comp is a queue of connections ready to be accepted.
142 * If a connection is aborted and it has so_head set, then
143 * it has to be pulled out of either so_incomp or so_comp.
144 * We allow connections to queue up based on current queue lengths
145 * and limit on number of queued connections for this socket.
146 */
147 struct socket *so_head; /* back pointer to accept socket */
148 TAILQ_HEAD(, socket) so_incomp; /* q of partially unaccepted conns */
149 TAILQ_HEAD(, socket) so_comp; /* q of complete unaccepted conns */
150 TAILQ_ENTRY(socket) so_list; /* list of unaccepted connections */
151 short so_qlen; /* number of unaccepted connections */
152 short so_incqlen; /* number of unaccepted incomplete
153 connections */
154 short so_qlimit; /* max number queued connections */
155 short so_timeo; /* connection timeout */
156 u_short so_error; /* error affecting connection */
157 pid_t so_pgid; /* pgid for signals */
158 u_int32_t so_oobmark; /* chars to oob mark */
159 #ifndef __APPLE__
160 /* We don't support AIO ops */
161 TAILQ_HEAD(, aiocblist) so_aiojobq; /* AIO ops waiting on socket */
162 #endif
163 /*
164 * Variables for socket buffering.
165 */
166 struct sockbuf {
167 u_int32_t sb_cc; /* actual chars in buffer */
168 u_int32_t sb_hiwat; /* max actual char count */
169 u_int32_t sb_mbcnt; /* chars of mbufs used */
170 u_int32_t sb_mbmax; /* max chars of mbufs to use */
171 u_int32_t sb_ctl; /* non-data chars in buffer */
172 u_int32_t sb_lowat; /* low water mark */
173 struct mbuf *sb_mb; /* the mbuf chain */
174 struct mbuf *sb_mbtail; /* the last mbuf in the chain */
175 struct mbuf *sb_lastrecord; /* first mbuf of last record */
176 #if __APPLE__
177 struct socket *sb_so; /* socket back ptr for kexts */
178 #endif
179 struct selinfo sb_sel; /* process selecting read/write */
180 short sb_flags; /* flags, see below */
181 struct timeval sb_timeo; /* timeout for read/write */
182 u_int sb_maxused; /* max char count ever used in sockbuf */
183 void *reserved1[4]; /* for future use */
184 } so_rcv, so_snd;
185 #define SB_MAX (8192*1024) /* default for max chars in sockbuf */
186 #define LOW_SB_MAX (2*9*1024) /* lower limit on max socket buffer size, 2 max datagrams */
187 #define SB_LOCK 0x01 /* lock on data queue */
188 #define SB_WANT 0x02 /* someone is waiting to lock */
189 #define SB_WAIT 0x04 /* someone is waiting for data/space */
190 #define SB_SEL 0x08 /* someone is selecting */
191 #define SB_ASYNC 0x10 /* ASYNC I/O, need signals */
192 #define SB_UPCALL 0x20 /* someone wants an upcall */
193 #define SB_NOINTR 0x40 /* operations not interruptible */
194 #define SB_KNOTE 0x100 /* kernel note attached */
195 #define SB_USRSIZE 0x200 /* user specified sbreserve */
196 #ifndef __APPLE__
197 #define SB_AIO 0x80 /* AIO operations queued */
198 #else
199 #define SB_NOTIFY (SB_WAIT|SB_SEL|SB_ASYNC)
200 #define SB_DROP 0x400 /* does not accept any more data */
201 #define SB_UNIX 0x800 /* UNIX domain socket buffer */
202 #define SB_RECV 0x8000 /* this is rcv sb */
203
204 caddr_t so_tpcb; /* Wisc. protocol control block - XXX unused? */
205 #endif
206
207 void (*so_upcall)(struct socket *so, caddr_t arg, int waitf);
208 caddr_t so_upcallarg; /* Arg for above */
209 uid_t so_uid; /* who opened the socket */
210 gid_t so_gid; /* gid of whoever opened the socket */
211 /* NB: generation count must not be first; easiest to make it last. */
212 so_gen_t so_gencnt; /* generation count */
213 #ifndef __APPLE__
214 void *so_emuldata; /* private data for emulators */
215 struct so_accf {
216 struct accept_filter *so_accept_filter;
217 void *so_accept_filter_arg; /* saved filter args */
218 char *so_accept_filter_str; /* saved user args */
219 } *so_accf;
220 #else
221 TAILQ_HEAD(, eventqelt) so_evlist;
222 int cached_in_sock_layer; /* bundled with pcb/pcb.inp_ppcb? */
223 struct socket *cache_next;
224 struct socket *cache_prev;
225 u_int32_t cache_timestamp;
226 caddr_t so_saved_pcb; /* Saved pcb when cacheing */
227 struct mbuf *so_temp; /* Holding area for outbound frags */
228 /* Plug-in support - make the socket interface overridable */
229 struct mbuf *so_tail;
230 struct socket_filter_entry *so_filt; /* NKE hook */
231 u_int32_t so_flags; /* Flags */
232 #define SOF_NOSIGPIPE 0x1
233 #define SOF_NOADDRAVAIL 0x2 /* EADDRNOTAVAIL if src addr is gone */
234 #define SOF_PCBCLEARING 0x4 /* pru_disconnect done; don't call pru_detach */
235 #define SOF_DEFUNCT 0x8 /* socket marked as inactive */
236 #define SOF_CLOSEWAIT 0x10 /* blocked in close awaiting some events */
237 #define SOF_UPCALLINUSE 0x20 /* socket upcall is currently in progress */
238 #define SOF_REUSESHAREUID 0x40 /* Allows SO_REUSEADDR/SO_REUSEPORT for multiple so_uid */
239 #define SOF_MULTIPAGES 0x80 /* jumbo clusters may be used for sosend */
240 #define SOF_ABORTED 0x100 /* soabort was already called once on the socket */
241 #define SOF_OVERFLOW 0x200 /* socket was dropped as overflow of listen queue */
242 #ifdef __APPLE_API_PRIVATE
243 #define SOF_NOTIFYCONFLICT 0x400 /* notify that a bind was done on a port already in use */
244 #endif
245 #define SOF_UPCALLCLOSEWAIT 0x800 /* block on close until an upcall returns */
246 #define SOF_BINDRANDOMPORT 0x1000 /* Request a randomized port number for the bind */
247 #define SOF_NPX_SETOPTSHUT 0x2000 /* Non POSIX extension to allow setsockopt(2) after shut down */
248 #define SOF_RECV_TRAFFIC_CLASS 0x4000 /* Receive traffic class as ancillary data */
249 #define SOF_NODEFUNCT 0x8000 /* socket cannot be defunct'd */
250 #define SOF_INCOMP_INPROGRESS 0x10000 /* incomp socket still being processed */
251 int so_usecount; /* refcounting of socket use */;
252 int so_retaincnt;
253 u_int32_t so_filteruse; /* usecount for the socket filters */
254 u_int32_t so_traffic_mgt_flags; /* traffic_mgt socket config */
255 thread_t so_send_filt_thread;
256 u_int32_t so_restrictions;
257
258 /* for debug pruposes */
259 #define SO_LCKDBG_MAX 4 /* number of debug locking Link Registers recorded */
260 void *lock_lr[SO_LCKDBG_MAX]; /* locking calling history */
261 int next_lock_lr;
262 void *unlock_lr[SO_LCKDBG_MAX]; /* unlocking caller history */
263 int next_unlock_lr;
264 void *reserved; /* reserved for future use */
265 #endif /* __APPLE__ */
266
267 struct label *so_label; /* MAC label for socket */
268 struct label *so_peerlabel; /* cached MAC label for socket peer */
269 thread_t so_background_thread; /* thread that marked this socket background */
270 int so_traffic_class;
271
272 // last process to interact with this socket
273 u_int64_t last_upid;
274 pid_t last_pid;
275
276 struct data_stats so_tc_stats[SO_TC_STATS_MAX];
277 };
278
279 /* Control message accessor in mbufs */
280
281 #define _MIN_NXT_CMSGHDR_PTR(cmsg) \
282 ((char *)(cmsg) + \
283 __DARWIN_ALIGN32((__uint32_t)(cmsg)->cmsg_len) + \
284 __DARWIN_ALIGN32(sizeof(struct cmsghdr)))
285
286 #define M_FIRST_CMSGHDR(m) \
287 ((char *)(m) != (char *)0L && (size_t)(m)->m_len >= sizeof(struct cmsghdr) && \
288 (socklen_t)(m)->m_len >= __DARWIN_ALIGN32(((struct cmsghdr *)(m)->m_data)->cmsg_len) ?\
289 (struct cmsghdr *)(m)->m_data : \
290 (struct cmsghdr *)0L)
291
292 #define M_NXT_CMSGHDR(m, cmsg) \
293 ((char *)(cmsg) == (char *)0L ? M_FIRST_CMSGHDR(m) : \
294 _MIN_NXT_CMSGHDR_PTR(cmsg) > ((char *)(m)->m_data) + (m)->m_len || \
295 _MIN_NXT_CMSGHDR_PTR(cmsg) < (char *)(m)->m_data ? \
296 (struct cmsghdr *)0L /* NULL */ : \
297 (struct cmsghdr *)((unsigned char *)(cmsg) + \
298 __DARWIN_ALIGN32((__uint32_t)(cmsg)->cmsg_len)))
299
300 #endif /* KERNEL_PRIVATE */
301
302 /*
303 * Socket state bits.
304 */
305 #define SS_NOFDREF 0x0001 /* no file table ref any more */
306 #define SS_ISCONNECTED 0x0002 /* socket connected to a peer */
307 #define SS_ISCONNECTING 0x0004 /* in process of connecting to peer */
308 #define SS_ISDISCONNECTING 0x0008 /* in process of disconnecting */
309 #define SS_CANTSENDMORE 0x0010 /* can't send more data to peer */
310 #define SS_CANTRCVMORE 0x0020 /* can't receive more data from peer */
311 #define SS_RCVATMARK 0x0040 /* at mark on input */
312
313 #define SS_PRIV 0x0080 /* privileged for broadcast, raw... */
314 #define SS_NBIO 0x0100 /* non-blocking ops */
315 #define SS_ASYNC 0x0200 /* async i/o notify */
316 #define SS_ISCONFIRMING 0x0400 /* deciding to accept connection req */
317 #define SS_INCOMP 0x0800 /* Unaccepted, incomplete connection */
318 #define SS_COMP 0x1000 /* unaccepted, complete connection */
319 #define SS_ISDISCONNECTED 0x2000 /* socket disconnected from peer */
320 #define SS_DRAINING 0x4000 /* close waiting for blocked system
321 calls to drain */
322 #define SS_DEFUNCT 0x8000 /* has been fully defunct'd */
323
324 #if defined(__LP64__)
325 #define _XSOCKET_PTR(x) u_int32_t
326 #else
327 #define _XSOCKET_PTR(x) x
328 #endif
329
330 #pragma pack(4)
331
332 struct xsockbuf {
333 u_int32_t sb_cc;
334 u_int32_t sb_hiwat;
335 u_int32_t sb_mbcnt;
336 u_int32_t sb_mbmax;
337 int32_t sb_lowat;
338 short sb_flags;
339 short sb_timeo;
340 };
341
342 /*
343 * Externalized form of struct socket used by the sysctl(3) interface.
344 */
345 struct xsocket {
346 u_int32_t xso_len; /* length of this structure */
347 _XSOCKET_PTR(struct socket *) xso_so; /* makes a convenient handle */
348 short so_type;
349 short so_options;
350 short so_linger;
351 short so_state;
352 _XSOCKET_PTR(caddr_t) so_pcb; /* another convenient handle */
353 int xso_protocol;
354 int xso_family;
355 short so_qlen;
356 short so_incqlen;
357 short so_qlimit;
358 short so_timeo;
359 u_short so_error;
360 pid_t so_pgid;
361 u_int32_t so_oobmark;
362 struct xsockbuf so_rcv;
363 struct xsockbuf so_snd;
364 uid_t so_uid; /* XXX */
365 };
366
367 #if !CONFIG_EMBEDDED
368
369 struct xsocket64 {
370 u_int32_t xso_len; /* length of this structure */
371 u_int64_t xso_so; /* makes a convenient handle */
372 short so_type;
373 short so_options;
374 short so_linger;
375 short so_state;
376 u_int64_t so_pcb; /* another convenient handle */
377 int xso_protocol;
378 int xso_family;
379 short so_qlen;
380 short so_incqlen;
381 short so_qlimit;
382 short so_timeo;
383 u_short so_error;
384 pid_t so_pgid;
385 u_int32_t so_oobmark;
386 struct xsockbuf so_rcv;
387 struct xsockbuf so_snd;
388 uid_t so_uid; /* XXX */
389 };
390
391 #endif /* !CONFIG_EMBEDDED */
392
393 #ifdef PRIVATE
394
395 #define XSO_SOCKET 0x001
396 #define XSO_RCVBUF 0x002
397 #define XSO_SNDBUF 0x004
398 #define XSO_STATS 0x008
399 #define XSO_INPCB 0x010
400 #define XSO_TCPCB 0x020
401
402 struct xsocket_n {
403 u_int32_t xso_len; /* length of this structure */
404 u_int32_t xso_kind; /* XSO_SOCKET */
405 u_int64_t xso_so; /* makes a convenient handle */
406 short so_type;
407 short so_options;
408 short so_linger;
409 short so_state;
410 u_int64_t so_pcb; /* another convenient handle */
411 int xso_protocol;
412 int xso_family;
413 short so_qlen;
414 short so_incqlen;
415 short so_qlimit;
416 short so_timeo;
417 u_short so_error;
418 pid_t so_pgid;
419 u_int32_t so_oobmark;
420 uid_t so_uid; /* XXX */
421 };
422
423 struct xsockbuf_n {
424 u_int32_t xsb_len; /* length of this structure */
425 u_int32_t xsb_kind; /* XSO_RCVBUF or XSO_SNDBUF */
426 u_int32_t sb_cc;
427 u_int32_t sb_hiwat;
428 u_int32_t sb_mbcnt;
429 u_int32_t sb_mbmax;
430 int32_t sb_lowat;
431 short sb_flags;
432 short sb_timeo;
433 };
434
435 struct xsockstat_n {
436 u_int32_t xst_len; /* length of this structure */
437 u_int32_t xst_kind; /* XSO_STATS */
438 struct data_stats xst_tc_stats[SO_TC_STATS_MAX];
439 };
440
441 #endif /* PRIVATE */
442
443 #pragma pack()
444
445 #ifdef KERNEL_PRIVATE
446 /*
447 * Macros for sockets and socket buffering.
448 */
449
450 #define sbtoso(sb) (sb->sb_so)
451
452 /*
453 * Functions for sockets and socket buffering.
454 * These are macros on FreeBSD. On Darwin the
455 * implementation is in bsd/kern/uipc_socket2.c
456 */
457
458 __BEGIN_DECLS
459 int sb_notify(struct sockbuf *sb);
460 int sbspace(struct sockbuf *sb);
461 int sosendallatonce(struct socket *so);
462 int soreadable(struct socket *so);
463 int sowriteable(struct socket *so);
464 void sballoc(struct sockbuf *sb, struct mbuf *m);
465 void sbfree(struct sockbuf *sb, struct mbuf *m);
466 int sblock(struct sockbuf *sb, int wf);
467 void sbunlock(struct sockbuf *sb, int locked);
468 void sorwakeup(struct socket *so);
469 void sowwakeup(struct socket *so);
470 __END_DECLS
471
472 /*
473 * Socket extension mechanism: control block hooks:
474 * This is the "head" of any control block for an extenstion
475 * Note: we separate intercept function dispatch vectors from
476 * the NFDescriptor to permit selective replacement during
477 * operation, e.g., to disable some functions.
478 */
479 struct kextcb {
480 struct kextcb *e_next; /* Next kext control block */
481 void *e_fcb; /* Real filter control block */
482 struct NFDescriptor *e_nfd; /* NKE Descriptor */
483 /* Plug-in support - intercept functions */
484 struct sockif *e_soif; /* Socket functions */
485 struct sockutil *e_sout; /* Sockbuf utility functions */
486 };
487 #define EXT_NULL 0x0 /* STATE: Not in use */
488 #define sotokextcb(so) (so ? so->so_ext : 0)
489
490 #ifdef KERNEL
491
492 #define SO_FILT_HINT_LOCKED 0x1
493
494 /*
495 * Argument structure for sosetopt et seq. This is in the KERNEL
496 * section because it will never be visible to user code.
497 */
498 enum sopt_dir { SOPT_GET, SOPT_SET };
499 struct sockopt {
500 enum sopt_dir sopt_dir; /* is this a get or a set? */
501 int sopt_level; /* second arg of [gs]etsockopt */
502 int sopt_name; /* third arg of [gs]etsockopt */
503 user_addr_t sopt_val; /* fourth arg of [gs]etsockopt */
504 size_t sopt_valsize; /* (almost) fifth arg of [gs]etsockopt */
505 struct proc *sopt_p; /* calling process or null if kernel */
506 };
507
508 #if SENDFILE
509 struct sf_buf {
510 SLIST_ENTRY(sf_buf) free_list; /* list of free buffer slots */
511 int refcnt; /* reference count */
512 struct vm_page *m; /* currently mapped page */
513 vm_offset_t kva; /* va of mapping */
514 };
515 #endif
516
517 #ifdef MALLOC_DECLARE
518 MALLOC_DECLARE(M_PCB);
519 MALLOC_DECLARE(M_SONAME);
520 #endif
521
522 extern int maxsockets;
523 extern u_int32_t sb_max;
524 extern int socket_zone;
525 extern so_gen_t so_gencnt;
526 extern int socket_debug;
527 extern int sosendjcl;
528 extern int sosendjcl_ignore_capab;
529 extern int sodefunctlog;
530 extern int somaxconn;
531
532 struct file;
533 struct filedesc;
534 struct mbuf;
535 struct sockaddr;
536 struct stat;
537 struct ucred;
538 struct uio;
539 struct knote;
540 struct so_tcdbg;
541
542 #define SBLASTRECORDCHK(sb, s) \
543 if (socket_debug) sblastrecordchk(sb, s);
544
545 #define SBLASTMBUFCHK(sb, s) \
546 if (socket_debug) sblastmbufchk(sb, s);
547
548 #define SB_EMPTY_FIXUP(sb) { \
549 if ((sb)->sb_mb == NULL) { \
550 (sb)->sb_mbtail = NULL; \
551 (sb)->sb_lastrecord = NULL; \
552 } \
553 }
554
555 #define SODEFUNCTLOG(x) do { if (sodefunctlog) printf x; } while (0)
556
557 /*
558 * For debugging traffic class behaviors
559 */
560 #define SOTCDB_NO_DSCP 0x01 /* Do not set DSCP code in IP header */
561 #define SOTCDB_NO_MTC 0x02 /* Do not set the mbuf traffic class */
562 #define SOTCDB_NO_SENDTCPBG 0x04 /* Do not use background TCP CC algorithm for sender */
563 #define SOTCDB_NO_LCLTST 0x08 /* Do not test for local destination for setting DSCP */
564 #define SOTCDB_NO_DSCPTST 0x10 /* Overwritte any existing DSCP code */
565 #define SOTCDB_NO_RECVTCPBG 0x20 /* Do not use throttling on receiver-side of TCP */
566
567 extern u_int32_t sotcdb;
568
569 /*
570 * From uipc_socket and friends
571 */
572 __BEGIN_DECLS
573 /* Not exported */
574 extern void socketinit(void) __attribute__((section("__TEXT, initcode")));
575
576 /* Exported */
577 extern struct sockaddr *dup_sockaddr(struct sockaddr *sa, int canwait);
578 extern int getsock(struct filedesc *fdp, int fd, struct file **fpp);
579 extern int sockargs(struct mbuf **mp, user_addr_t data, int buflen, int type);
580
581 extern int sbappend(struct sockbuf *sb, struct mbuf *m);
582 extern int sbappendstream(struct sockbuf *sb, struct mbuf *m);
583 extern int sbappendaddr(struct sockbuf *sb, struct sockaddr *asa,
584 struct mbuf *m0, struct mbuf *control, int *error_out);
585 extern int sbappendcontrol(struct sockbuf *sb, struct mbuf *m0,
586 struct mbuf *control, int *error_out);
587 extern int sbappendrecord(struct sockbuf *sb, struct mbuf *m0);
588 extern void sbcheck(struct sockbuf *sb);
589 extern void sblastmbufchk(struct sockbuf *, const char *);
590 extern void sblastrecordchk(struct sockbuf *, const char *);
591 extern struct mbuf *sbcreatecontrol(caddr_t p, int size, int type, int level);
592 extern struct mbuf **sbcreatecontrol_mbuf(caddr_t p, int size, int type, int level, struct mbuf** m);
593 extern void sbdrop(struct sockbuf *sb, int len);
594 extern void sbdroprecord(struct sockbuf *sb);
595 extern void sbflush(struct sockbuf *sb);
596 extern int sbinsertoob(struct sockbuf *sb, struct mbuf *m0);
597 extern void sbrelease(struct sockbuf *sb);
598 extern int sbreserve(struct sockbuf *sb, u_int32_t cc);
599 extern void sbtoxsockbuf(struct sockbuf *sb, struct xsockbuf *xsb);
600 extern int sbwait(struct sockbuf *sb);
601 extern int sb_lock(struct sockbuf *sb);
602 extern void sb_empty_assert(struct sockbuf *, const char *);
603
604 extern int soabort(struct socket *so);
605 extern int soaccept(struct socket *so, struct sockaddr **nam);
606 extern int soacceptlock(struct socket *so, struct sockaddr **nam, int dolock);
607 extern int soacceptfilter(struct socket *so);
608 extern struct socket *soalloc(int waitok, int dom, int type);
609 extern int sobind(struct socket *so, struct sockaddr *nam);
610 extern void socantrcvmore(struct socket *so);
611 extern void socantsendmore(struct socket *so);
612 extern int soclose(struct socket *so);
613 extern int soconnect(struct socket *so, struct sockaddr *nam);
614 extern int soconnectlock(struct socket *so, struct sockaddr *nam, int dolock);
615 extern int soconnect2(struct socket *so1, struct socket *so2);
616 extern int socreate(int dom, struct socket **aso, int type, int proto);
617 extern void sodealloc(struct socket *so);
618 extern int sodisconnect(struct socket *so);
619 extern int sodisconnectlocked(struct socket *so);
620 extern void sofree(struct socket *so);
621 extern void soreference(struct socket *so);
622 extern void sodereference(struct socket *so);
623 extern void somultipages(struct socket *, boolean_t);
624 extern int sosetdefunct(struct proc *, struct socket *, int level, boolean_t);
625 extern int sodefunct(struct proc *, struct socket *, int level);
626 extern int sogetopt(struct socket *so, struct sockopt *sopt);
627 extern void sohasoutofband(struct socket *so);
628 extern void soisconnected(struct socket *so);
629 extern void soisconnecting(struct socket *so);
630 extern void soisdisconnected(struct socket *so);
631 extern void sodisconnectwakeup(struct socket *so);
632 extern void soisdisconnecting(struct socket *so);
633 extern int soisbackground(struct socket *so);
634 extern int solisten(struct socket *so, int backlog);
635 extern struct socket *sodropablereq(struct socket *head);
636 extern struct socket *sonewconn(struct socket *head, int connstatus,
637 const struct sockaddr *from);
638 extern int sooptcopyin(struct sockopt *sopt, void *data, size_t len,
639 size_t minlen);
640 extern int sooptcopyout(struct sockopt *sopt, void *data, size_t len);
641 extern int socket_lock(struct socket *so, int refcount);
642 extern int socket_unlock(struct socket *so, int refcount);
643 extern void sofreelastref(struct socket *, int);
644 extern int sogetaddr_locked(struct socket *, struct sockaddr **, int);
645 extern const char *solockhistory_nr(struct socket *);
646 extern void set_packet_tclass(struct mbuf *, struct socket *, int, int);
647 extern int mbuf_traffic_class_from_control(struct mbuf *);
648 extern void set_tcp_stream_priority(struct socket *so);
649 extern int so_set_traffic_class(struct socket *, int);
650 extern void so_set_default_traffic_class(struct socket *);
651 extern void socket_tclass_init(void);
652 extern int so_set_tcdbg(struct socket *, struct so_tcdbg *);
653 extern int sogetopt_tcdbg(struct socket *, struct sockopt *);
654 extern void so_recv_data_stat(struct socket *, struct mbuf *, size_t);
655
656 /*
657 * XXX; prepare mbuf for (__FreeBSD__ < 3) routines.
658 * Used primarily in IPSec and IPv6 code.
659 */
660 extern int soopt_getm(struct sockopt *sopt, struct mbuf **mp);
661 extern int soopt_mcopyin(struct sockopt *sopt, struct mbuf *m);
662 extern int soopt_mcopyout(struct sockopt *sopt, struct mbuf *m);
663
664 extern int sopoll(struct socket *so, int events, struct ucred *cred, void *wql);
665 extern int soreceive(struct socket *so, struct sockaddr **paddr,
666 struct uio *uio, struct mbuf **mp0, struct mbuf **controlp, int *flagsp);
667 extern int soreserve(struct socket *so, u_int32_t sndcc, u_int32_t rcvcc);
668 extern void sorflush(struct socket *so);
669 extern int sosend(struct socket *so, struct sockaddr *addr, struct uio *uio,
670 struct mbuf *top, struct mbuf *control, int flags);
671
672 extern int sosetopt(struct socket *so, struct sockopt *sopt);
673 extern int soshutdown(struct socket *so, int how);
674 extern int soshutdownlock(struct socket *so, int how);
675 extern void sotoxsocket(struct socket *so, struct xsocket *xso);
676 #if !CONFIG_EMBEDDED
677 extern void sotoxsocket64(struct socket *so, struct xsocket64 *xso);
678 #endif
679 extern void sbwakeup(struct sockbuf *sb);
680 extern void sowakeup(struct socket *so, struct sockbuf *sb);
681 extern int soioctl(struct socket *so, u_long cmd, caddr_t data, struct proc *p);
682
683 #ifndef __APPLE__
684 /* accept filter functions */
685 extern int accept_filt_add(struct accept_filter *filt);
686 extern int accept_filt_del(char *name);
687 extern struct accept_filter *accept_filt_get(char *name);
688 #ifdef ACCEPT_FILTER_MOD
689 extern int accept_filt_generic_mod_event(module_t mod, int event, void *data);
690 SYSCTL_DECL(_net_inet_accf);
691 #endif /* ACCEPT_FILTER_MOD */
692 #endif /* !defined(__APPLE__) */
693
694 __END_DECLS
695
696 #endif /* KERNEL */
697 #endif /* KERNEL_PRIVATE */
698
699 #endif /* !_SYS_SOCKETVAR_H_ */