]> git.saurik.com Git - apple/xnu.git/blame - bsd/sys/socketvar.h
xnu-517.12.7.tar.gz
[apple/xnu.git] / bsd / sys / socketvar.h
CommitLineData
1c79356b 1/*
55e303ae 2 * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved.
1c79356b
A
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
e5568f75
A
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
1c79356b 11 *
e5568f75
A
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
1c79356b
A
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
e5568f75
A
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
1c79356b
A
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22/* Copyright (c) 1998, 1999 Apple Computer, Inc. All Rights Reserved */
23/* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
24/*-
25 * Copyright (c) 1982, 1986, 1990, 1993
26 * The Regents of the University of California. All rights reserved.
27 *
28 * Redistribution and use in source and binary forms, with or without
29 * modification, are permitted provided that the following conditions
30 * are met:
31 * 1. Redistributions of source code must retain the above copyright
32 * notice, this list of conditions and the following disclaimer.
33 * 2. Redistributions in binary form must reproduce the above copyright
34 * notice, this list of conditions and the following disclaimer in the
35 * documentation and/or other materials provided with the distribution.
36 * 3. All advertising materials mentioning features or use of this software
37 * must display the following acknowledgement:
38 * This product includes software developed by the University of
39 * California, Berkeley and its contributors.
40 * 4. Neither the name of the University nor the names of its contributors
41 * may be used to endorse or promote products derived from this software
42 * without specific prior written permission.
43 *
44 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
45 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
47 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
48 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
49 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
50 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
51 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
52 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
53 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
54 * SUCH DAMAGE.
55 *
9bccf70c
A
56 * @(#)socketvar.h 8.3 (Berkeley) 2/19/95
57 * $FreeBSD: src/sys/sys/socketvar.h,v 1.46.2.6 2001/08/31 13:45:49 jlemon Exp $
1c79356b
A
58 */
59
9bccf70c 60#ifndef _SYS_SOCKETVAR_H_
1c79356b
A
61#define _SYS_SOCKETVAR_H_
62
9bccf70c
A
63#include <sys/appleapiopts.h>
64#include <sys/queue.h> /* for TAILQ macros */
1c79356b 65#include <sys/select.h> /* for struct selinfo */
1c79356b
A
66#include <net/kext_net.h>
67#include <sys/ev.h>
68/*
69 * Hacks to get around compiler complaints
70 */
71struct mbuf;
1c79356b
A
72struct kextcb;
73struct protosw;
74struct sockif;
75struct sockutil;
76
77/* strings for sleep message: */
9bccf70c 78#ifdef __APPLE_API_UNSTABLE
1c79356b
A
79extern char netio[], netcon[], netcls[];
80#define SOCKET_CACHE_ON
81#define SO_CACHE_FLUSH_INTERVAL 1 /* Seconds */
82#define SO_CACHE_TIME_LIMIT (120/SO_CACHE_FLUSH_INTERVAL) /* Seconds */
83#define SO_CACHE_MAX_FREE_BATCH 50
84#define MAX_CACHED_SOCKETS 60000
85#define TEMPDEBUG 0
86
87/*
88 * Kernel structure per socket.
89 * Contains send and receive buffer queues,
90 * handle on protocol and pointer to protocol
91 * private data and error information.
92 */
93typedef u_quad_t so_gen_t;
94
9bccf70c
A
95#ifndef __APPLE__
96/* We don't support BSD style socket filters */
97struct accept_filter;
98#endif
99
1c79356b 100struct socket {
9bccf70c
A
101 int so_zone; /* zone we were allocated from */
102 short so_type; /* generic type, see socket.h */
1c79356b
A
103 short so_options; /* from socket call, see socket.h */
104 short so_linger; /* time to linger while closing */
9bccf70c 105 short so_state; /* internal state flags SS_*, below */
1c79356b
A
106 caddr_t so_pcb; /* protocol control block */
107 struct protosw *so_proto; /* protocol handle */
108/*
9bccf70c 109 * Variables for connection queuing.
1c79356b
A
110 * Socket where accepts occur is so_head in all subsidiary sockets.
111 * If so_head is 0, socket is not related to an accept.
9bccf70c
A
112 * For head socket so_incomp queues partially completed connections,
113 * while so_comp is a queue of connections ready to be accepted.
1c79356b 114 * If a connection is aborted and it has so_head set, then
9bccf70c 115 * it has to be pulled out of either so_incomp or so_comp.
1c79356b
A
116 * We allow connections to queue up based on current queue lengths
117 * and limit on number of queued connections for this socket.
118 */
119 struct socket *so_head; /* back pointer to accept socket */
120 TAILQ_HEAD(, socket) so_incomp; /* queue of partial unaccepted connections */
121 TAILQ_HEAD(, socket) so_comp; /* queue of complete unaccepted connections */
122 TAILQ_ENTRY(socket) so_list; /* list of unaccepted connections */
123 short so_qlen; /* number of unaccepted connections */
124 short so_incqlen; /* number of unaccepted incomplete
125 connections */
126 short so_qlimit; /* max number queued connections */
127 short so_timeo; /* connection timeout */
128 u_short so_error; /* error affecting connection */
129 pid_t so_pgid; /* pgid for signals */
130 u_long so_oobmark; /* chars to oob mark */
9bccf70c
A
131#ifndef __APPLE__
132 /* We don't support AIO ops */
133 TAILQ_HEAD(, aiocblist) so_aiojobq; /* AIO ops waiting on socket */
134#endif
1c79356b
A
135/*
136 * Variables for socket buffering.
137 */
138 struct sockbuf {
139 u_long sb_cc; /* actual chars in buffer */
140 u_long sb_hiwat; /* max actual char count */
141 u_long sb_mbcnt; /* chars of mbufs used */
142 u_long sb_mbmax; /* max chars of mbufs to use */
143 long sb_lowat; /* low water mark */
144 struct mbuf *sb_mb; /* the mbuf chain */
9bccf70c
A
145#if __APPLE__
146 struct socket *sb_so; /* socket back ptr for kexts */
147#endif
1c79356b
A
148 struct selinfo sb_sel; /* process selecting read/write */
149 short sb_flags; /* flags, see below */
150 short sb_timeo; /* timeout for read/write */
0b4e3aa0
A
151 void *reserved1; /* for future use if needed */
152 void *reserved2;
1c79356b
A
153 } so_rcv, so_snd;
154#define SB_MAX (256*1024) /* default for max chars in sockbuf */
155#define SB_LOCK 0x01 /* lock on data queue */
156#define SB_WANT 0x02 /* someone is waiting to lock */
157#define SB_WAIT 0x04 /* someone is waiting for data/space */
0b4e3aa0 158#define SB_SEL 0x08 /* someone is selecting */
9bccf70c
A
159#define SB_ASYNC 0x10 /* ASYNC I/O, need signals */
160#define SB_UPCALL 0x20 /* someone wants an upcall */
161#define SB_NOINTR 0x40 /* operations not interruptible */
55e303ae 162#define SB_KNOTE 0x100 /* kernel note attached */
9bccf70c
A
163#ifndef __APPLE__
164#define SB_AIO 0x80 /* AIO operations queued */
9bccf70c 165#else
0b4e3aa0 166#define SB_NOTIFY (SB_WAIT|SB_SEL|SB_ASYNC)
1c79356b
A
167#define SB_RECV 0x8000 /* this is rcv sb */
168
9bccf70c
A
169 caddr_t so_tpcb; /* Wisc. protocol control block - XXX unused? */
170#endif
171
1c79356b
A
172 void (*so_upcall) __P((struct socket *so, caddr_t arg, int waitf));
173 caddr_t so_upcallarg; /* Arg for above */
174 uid_t so_uid; /* who opened the socket */
175 /* NB: generation count must not be first; easiest to make it last. */
176 so_gen_t so_gencnt; /* generation count */
9bccf70c
A
177#ifndef __APPLE__
178 void *so_emuldata; /* private data for emulators */
179 struct so_accf {
180 struct accept_filter *so_accept_filter;
181 void *so_accept_filter_arg; /* saved filter args */
182 char *so_accept_filter_str; /* saved user args */
183 } *so_accf;
184#else
1c79356b
A
185 TAILQ_HEAD(,eventqelt) so_evlist;
186 int cached_in_sock_layer; /* Is socket bundled with pcb/pcb.inp_ppcb? */
187 struct socket *cache_next;
188 struct socket *cache_prev;
189 u_long cache_timestamp;
190 caddr_t so_saved_pcb; /* Saved pcb when cacheing */
191 struct mbuf *so_temp; /* Holding area for outbound frags */
192 /* Plug-in support - make the socket interface overridable */
193 struct mbuf *so_tail;
194 struct kextcb *so_ext; /* NKE hook */
9bccf70c
A
195 u_long so_flags; /* Flags */
196#define SOF_NOSIGPIPE 0x00000001
55e303ae 197#define SOF_NOADDRAVAIL 0x00000002 /* returns EADDRNOTAVAIL if src address is gone */
0b4e3aa0
A
198 void *reserved2;
199 void *reserved3;
200 void *reserved4;
9bccf70c 201#endif
1c79356b 202};
9bccf70c 203#endif /* __APPLE_API_UNSTABLE */
1c79356b
A
204
205/*
206 * Socket state bits.
207 */
208#define SS_NOFDREF 0x001 /* no file table ref any more */
209#define SS_ISCONNECTED 0x002 /* socket connected to a peer */
210#define SS_ISCONNECTING 0x004 /* in process of connecting to peer */
211#define SS_ISDISCONNECTING 0x008 /* in process of disconnecting */
212#define SS_CANTSENDMORE 0x010 /* can't send more data to peer */
213#define SS_CANTRCVMORE 0x020 /* can't receive more data from peer */
214#define SS_RCVATMARK 0x040 /* at mark on input */
215
216#define SS_PRIV 0x080 /* privileged for broadcast, raw... */
217#define SS_NBIO 0x100 /* non-blocking ops */
218#define SS_ASYNC 0x200 /* async i/o notify */
219#define SS_ISCONFIRMING 0x400 /* deciding to accept connection req */
220#define SS_INCOMP 0x800 /* Unaccepted, incomplete connection */
221#define SS_COMP 0x1000 /* unaccepted, complete connection */
9bccf70c 222#define SS_ISDISCONNECTED 0x2000 /* socket disconnected from peer */
1c79356b
A
223
224/*
225 * Externalized form of struct socket used by the sysctl(3) interface.
226 */
227struct xsocket {
228 size_t xso_len; /* length of this structure */
229 struct socket *xso_so; /* makes a convenient handle sometimes */
230 short so_type;
231 short so_options;
232 short so_linger;
233 short so_state;
234 caddr_t so_pcb; /* another convenient handle */
235 int xso_protocol;
236 int xso_family;
237 short so_qlen;
238 short so_incqlen;
239 short so_qlimit;
240 short so_timeo;
241 u_short so_error;
242 pid_t so_pgid;
243 u_long so_oobmark;
244 struct xsockbuf {
245 u_long sb_cc;
246 u_long sb_hiwat;
247 u_long sb_mbcnt;
248 u_long sb_mbmax;
249 long sb_lowat;
250 short sb_flags;
251 short sb_timeo;
252 } so_rcv, so_snd;
253 uid_t so_uid; /* XXX */
254};
255
256/*
257 * Macros for sockets and socket buffering.
258 */
9bccf70c
A
259#ifdef __APPLE__
260#ifdef __APPLE_API_UNSTABLE
1c79356b
A
261#define sbtoso(sb) (sb->sb_so)
262
9bccf70c
A
263/*
264 * Functions for sockets and socket buffering.
265 * These are macros on FreeBSD. On Darwin the
266 * implementation is in bsd/kern/uipc_socket2.c
267 */
268int sb_notify __P((struct sockbuf *sb));
269long sbspace __P((struct sockbuf *sb));
270int sosendallatonce __P((struct socket *so));
271int soreadable __P((struct socket *so));
272int sowriteable __P((struct socket *so));
273void sballoc __P((struct sockbuf *sb, struct mbuf *m));
274void sbfree __P((struct sockbuf *sb, struct mbuf *m));
275int sblock __P((struct sockbuf *sb, int wf));
276void sbunlock __P((struct sockbuf *sb));
277void sorwakeup __P((struct socket * so));
278void sowwakeup __P((struct socket * so));
1c79356b
A
279
280/*
281 * Socket extension mechanism: control block hooks:
282 * This is the "head" of any control block for an extenstion
283 * Note: we separate intercept function dispatch vectors from
284 * the NFDescriptor to permit selective replacement during
285 * operation, e.g., to disable some functions.
286 */
287struct kextcb
288{ struct kextcb *e_next; /* Next kext control block */
289 void *e_fcb; /* Real filter control block */
290 struct NFDescriptor *e_nfd; /* NKE Descriptor */
291 /* Plug-in support - intercept functions */
292 struct sockif *e_soif; /* Socket functions */
293 struct sockutil *e_sout; /* Sockbuf utility functions */
294};
295#define EXT_NULL 0x0 /* STATE: Not in use */
296#define sotokextcb(so) (so ? so->so_ext : 0)
9bccf70c 297#endif /* __APPLE___ */
1c79356b
A
298
299#ifdef KERNEL
9bccf70c 300
1c79356b
A
301/*
302 * Argument structure for sosetopt et seq. This is in the KERNEL
303 * section because it will never be visible to user code.
304 */
305enum sopt_dir { SOPT_GET, SOPT_SET };
306struct sockopt {
307 enum sopt_dir sopt_dir; /* is this a get or a set? */
308 int sopt_level; /* second arg of [gs]etsockopt */
309 int sopt_name; /* third arg of [gs]etsockopt */
310 void *sopt_val; /* fourth arg of [gs]etsockopt */
311 size_t sopt_valsize; /* (almost) fifth arg of [gs]etsockopt */
312 struct proc *sopt_p; /* calling process or null if kernel */
313};
314
315#if SENDFILE
1c79356b
A
316struct sf_buf {
317 SLIST_ENTRY(sf_buf) free_list; /* list of free buffer slots */
318 int refcnt; /* reference count */
319 struct vm_page *m; /* currently mapped page */
320 vm_offset_t kva; /* va of mapping */
321};
1c79356b
A
322#endif
323
324#ifdef MALLOC_DECLARE
325MALLOC_DECLARE(M_PCB);
326MALLOC_DECLARE(M_SONAME);
327#endif
328
329extern int maxsockets;
330extern u_long sb_max;
331extern int socket_zone;
332extern so_gen_t so_gencnt;
333
334struct file;
335struct filedesc;
336struct mbuf;
337struct sockaddr;
338struct stat;
339struct ucred;
340struct uio;
9bccf70c 341struct knote;
1c79356b
A
342
343/*
344 * File operations on sockets.
345 */
9bccf70c
A
346int soo_read __P((struct file *fp, struct uio *uio, struct ucred *cred,
347 int flags, struct proc *p));
348int soo_write __P((struct file *fp, struct uio *uio, struct ucred *cred,
349 int flags, struct proc *p));
350int soo_close __P((struct file *fp, struct proc *p));
1c79356b
A
351int soo_ioctl __P((struct file *fp, u_long cmd, caddr_t data,
352 struct proc *p));
1c79356b 353int soo_stat __P((struct socket *so, struct stat *ub));
9bccf70c 354int soo_select __P((struct file *fp, int which, void * wql, struct proc *p));
55e303ae
A
355int soo_kqfilter __P((struct file *fp, struct knote *kn, struct proc *p));
356
1c79356b
A
357
358/*
359 * From uipc_socket and friends
360 */
361struct sockaddr *dup_sockaddr __P((struct sockaddr *sa, int canwait));
362int getsock __P((struct filedesc *fdp, int fd, struct file **fpp));
363int sockargs __P((struct mbuf **mp, caddr_t buf, int buflen, int type));
364int getsockaddr __P((struct sockaddr **namp, caddr_t uaddr, size_t len));
365void sbappend __P((struct sockbuf *sb, struct mbuf *m));
366int sbappendaddr __P((struct sockbuf *sb, struct sockaddr *asa,
367 struct mbuf *m0, struct mbuf *control));
368int sbappendcontrol __P((struct sockbuf *sb, struct mbuf *m0,
369 struct mbuf *control));
370void sbappendrecord __P((struct sockbuf *sb, struct mbuf *m0));
371void sbcheck __P((struct sockbuf *sb));
372void sbcompress __P((struct sockbuf *sb, struct mbuf *m, struct mbuf *n));
373struct mbuf *
374 sbcreatecontrol __P((caddr_t p, int size, int type, int level));
375void sbdrop __P((struct sockbuf *sb, int len));
376void sbdroprecord __P((struct sockbuf *sb));
377void sbflush __P((struct sockbuf *sb));
378void sbinsertoob __P((struct sockbuf *sb, struct mbuf *m0));
379void sbrelease __P((struct sockbuf *sb));
380int sbreserve __P((struct sockbuf *sb, u_long cc));
381void sbtoxsockbuf __P((struct sockbuf *sb, struct xsockbuf *xsb));
382int sbwait __P((struct sockbuf *sb));
383int sb_lock __P((struct sockbuf *sb));
384int soabort __P((struct socket *so));
385int soaccept __P((struct socket *so, struct sockaddr **nam));
386struct socket *soalloc __P((int waitok, int dom, int type));
387int sobind __P((struct socket *so, struct sockaddr *nam));
388void socantrcvmore __P((struct socket *so));
389void socantsendmore __P((struct socket *so));
390int soclose __P((struct socket *so));
391int soconnect __P((struct socket *so, struct sockaddr *nam));
392int soconnect2 __P((struct socket *so1, struct socket *so2));
393int socreate __P((int dom, struct socket **aso, int type, int proto));
394void sodealloc __P((struct socket *so));
395int sodisconnect __P((struct socket *so));
396void sofree __P((struct socket *so));
397int sogetopt __P((struct socket *so, struct sockopt *sopt));
398void sohasoutofband __P((struct socket *so));
399void soisconnected __P((struct socket *so));
400void soisconnecting __P((struct socket *so));
401void soisdisconnected __P((struct socket *so));
402void soisdisconnecting __P((struct socket *so));
403int solisten __P((struct socket *so, int backlog));
404struct socket *
405 sodropablereq __P((struct socket *head));
406struct socket *
407 sonewconn __P((struct socket *head, int connstatus));
408int sooptcopyin __P((struct sockopt *sopt, void *buf, size_t len,
409 size_t minlen));
410int sooptcopyout __P((struct sockopt *sopt, void *buf, size_t len));
9bccf70c
A
411
412/*
413 * XXX; prepare mbuf for (__FreeBSD__ < 3) routines.
414 * Used primarily in IPSec and IPv6 code.
415 */
416int soopt_getm __P((struct sockopt *sopt, struct mbuf **mp));
417int soopt_mcopyin __P((struct sockopt *sopt, struct mbuf *m));
418int soopt_mcopyout __P((struct sockopt *sopt, struct mbuf *m));
419
0b4e3aa0 420int sopoll __P((struct socket *so, int events, struct ucred *cred, void *wql));
1c79356b
A
421int soreceive __P((struct socket *so, struct sockaddr **paddr,
422 struct uio *uio, struct mbuf **mp0,
423 struct mbuf **controlp, int *flagsp));
424int soreserve __P((struct socket *so, u_long sndcc, u_long rcvcc));
425void sorflush __P((struct socket *so));
426int sosend __P((struct socket *so, struct sockaddr *addr, struct uio *uio,
427 struct mbuf *top, struct mbuf *control, int flags));
428
429int sosetopt __P((struct socket *so, struct sockopt *sopt));
1c79356b
A
430int soshutdown __P((struct socket *so, int how));
431void sotoxsocket __P((struct socket *so, struct xsocket *xso));
432void sowakeup __P((struct socket *so, struct sockbuf *sb));
433
9bccf70c
A
434#ifndef __APPLE__
435/* accept filter functions */
436int accept_filt_add __P((struct accept_filter *filt));
437int accept_filt_del __P((char *name));
438struct accept_filter * accept_filt_get __P((char *name));
439#ifdef ACCEPT_FILTER_MOD
440int accept_filt_generic_mod_event __P((module_t mod, int event, void *data));
441SYSCTL_DECL(_net_inet_accf);
442#endif /* ACCEPT_FILTER_MOD */
443#endif /* !defined(__APPLE__) */
1c79356b
A
444
445#endif /* KERNEL */
9bccf70c
A
446#endif /* __APPLE_API_UNSTABLE */
447
1c79356b 448#endif /* !_SYS_SOCKETVAR_H_ */