]> git.saurik.com Git - apple/xnu.git/blame - bsd/netinet/in_pcb.h
xnu-517.3.15.tar.gz
[apple/xnu.git] / bsd / netinet / in_pcb.h
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
43866e37 6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
1c79356b 7 *
43866e37
A
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
1c79356b
A
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
43866e37
A
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
1c79356b
A
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25/*
26 * Copyright (c) 1982, 1986, 1990, 1993
27 * The Regents of the University of California. All rights reserved.
28 *
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
31 * are met:
32 * 1. Redistributions of source code must retain the above copyright
33 * notice, this list of conditions and the following disclaimer.
34 * 2. Redistributions in binary form must reproduce the above copyright
35 * notice, this list of conditions and the following disclaimer in the
36 * documentation and/or other materials provided with the distribution.
37 * 3. All advertising materials mentioning features or use of this software
38 * must display the following acknowledgement:
39 * This product includes software developed by the University of
40 * California, Berkeley and its contributors.
41 * 4. Neither the name of the University nor the names of its contributors
42 * may be used to endorse or promote products derived from this software
43 * without specific prior written permission.
44 *
45 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
46 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
49 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
51 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
53 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
54 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
55 * SUCH DAMAGE.
56 *
57 * @(#)in_pcb.h 8.1 (Berkeley) 6/10/93
9bccf70c 58 * $FreeBSD: src/sys/netinet/in_pcb.h,v 1.32.2.4 2001/08/13 16:26:17 ume Exp $
1c79356b
A
59 */
60
61#ifndef _NETINET_IN_PCB_H_
62#define _NETINET_IN_PCB_H_
9bccf70c 63#include <sys/appleapiopts.h>
1c79356b
A
64
65#include <sys/queue.h>
1c79356b 66
9bccf70c
A
67
68#include <netinet6/ipsec.h> /* for IPSEC */
69
70#ifdef __APPLE_API_PRIVATE
71
72#define in6pcb inpcb /* for KAME src sync over BSD*'s */
73#define in6p_sp inp_sp /* for KAME src sync over BSD*'s */
1c79356b
A
74
75/*
76 * Common structure pcb for internet protocol implementation.
77 * Here are stored pointers to local and foreign host table
78 * entries, local and foreign socket numbers, and pointers
79 * up (to a socket structure) and down (to a protocol-specific)
80 * control block.
81 */
82LIST_HEAD(inpcbhead, inpcb);
83LIST_HEAD(inpcbporthead, inpcbport);
84typedef u_quad_t inp_gen_t;
85
86/*
87 * PCB with AF_INET6 null bind'ed laddr can receive AF_INET input packet.
88 * So, AF_INET6 null laddr is also used as AF_INET null laddr,
89 * by utilize following structure. (At last, same as INRIA)
90 */
91struct in_addr_4in6 {
9bccf70c
A
92 u_int32_t ia46_pad32[3];
93 struct in_addr ia46_addr4;
1c79356b
A
94};
95
96/*
97 * NB: the zone allocator is type-stable EXCEPT FOR THE FIRST TWO LONGS
98 * of the structure. Therefore, it is important that the members in
99 * that position not contain any information which is required to be
100 * stable.
101 */
9bccf70c 102struct icmp6_filter;
1c79356b
A
103
104struct inpcb {
105 LIST_ENTRY(inpcb) inp_hash; /* hash list */
55e303ae
A
106 struct in_addr reserved1; /* APPLE reserved: inp_faddr defined in protcol indep. part */
107 struct in_addr reserved2; /* APPLE reserved */
1c79356b
A
108 u_short inp_fport; /* foreign port */
109 u_short inp_lport; /* local port */
110 LIST_ENTRY(inpcb) inp_list; /* list for all PCBs of this proto */
111 caddr_t inp_ppcb; /* pointer to per-protocol pcb */
112 struct inpcbinfo *inp_pcbinfo; /* PCB list info */
113 struct socket *inp_socket; /* back pointer to socket */
114 u_char nat_owner; /* Used to NAT TCP/UDP traffic */
115 u_long nat_cookie; /* Cookie stored and returned to NAT */
116 LIST_ENTRY(inpcb) inp_portlist; /* list for this PCB's local port */
117 struct inpcbport *inp_phd; /* head of this list */
118 inp_gen_t inp_gencnt; /* generation count of this instance */
119 int inp_flags; /* generic IP/datagram flags */
120 u_int32_t inp_flow;
121
122 u_char inp_vflag;
123#define INP_IPV4 0x1
124#define INP_IPV6 0x2
125
126 u_char inp_ip_ttl; /* time to live proto */
127 u_char inp_ip_p; /* protocol proto */
128 /* protocol dependent part */
129 union {
130 /* foreign host table entry */
9bccf70c
A
131 struct in_addr_4in6 inp46_foreign;
132 struct in6_addr inp6_foreign;
1c79356b
A
133 } inp_dependfaddr;
134 union {
135 /* local host table entry */
9bccf70c
A
136 struct in_addr_4in6 inp46_local;
137 struct in6_addr inp6_local;
1c79356b
A
138 } inp_dependladdr;
139 union {
140 /* placeholder for routing entry */
9bccf70c
A
141 struct route inp4_route;
142 struct route_in6 inp6_route;
1c79356b
A
143 } inp_dependroute;
144 struct {
145 /* type of service proto */
146 u_char inp4_ip_tos;
147 /* IP options */
148 struct mbuf *inp4_options;
149 /* IP multicast options */
150 struct ip_moptions *inp4_moptions;
151 } inp_depend4;
9bccf70c
A
152#define inp_faddr inp_dependfaddr.inp46_foreign.ia46_addr4
153#define inp_laddr inp_dependladdr.inp46_local.ia46_addr4
154#define inp_route inp_dependroute.inp4_route
155#define inp_ip_tos inp_depend4.inp4_ip_tos
156#define inp_options inp_depend4.inp4_options
157#define inp_moptions inp_depend4.inp4_moptions
1c79356b
A
158 struct {
159 /* IP options */
160 struct mbuf *inp6_options;
9bccf70c
A
161 u_int8_t inp6_hlim;
162 u_int8_t unused_uint8_1;
163 ushort unused_uint16_1;
1c79356b 164 /* IP6 options for outgoing packets */
9bccf70c 165 struct ip6_pktopts *inp6_outputopts;
1c79356b 166 /* IP multicast options */
9bccf70c 167 struct ip6_moptions *inp6_moptions;
1c79356b 168 /* ICMPv6 code type filter */
9bccf70c 169 struct icmp6_filter *inp6_icmp6filt;
1c79356b 170 /* IPV6_CHECKSUM setsockopt */
9bccf70c 171 int inp6_cksum;
1c79356b
A
172 u_short inp6_ifindex;
173 short inp6_hops;
174 } inp_depend6;
9bccf70c
A
175#define in6p_faddr inp_dependfaddr.inp6_foreign
176#define in6p_laddr inp_dependladdr.inp6_local
177#define in6p_route inp_dependroute.inp6_route
178#define in6p_ip6_hlim inp_depend6.inp6_hlim
179#define in6p_hops inp_depend6.inp6_hops /* default hop limit */
180#define in6p_ip6_nxt inp_ip_p
181#define in6p_flowinfo inp_flow
182#define in6p_vflag inp_vflag
183#define in6p_options inp_depend6.inp6_options
184#define in6p_outputopts inp_depend6.inp6_outputopts
185#define in6p_moptions inp_depend6.inp6_moptions
186#define in6p_icmp6filt inp_depend6.inp6_icmp6filt
187#define in6p_cksum inp_depend6.inp6_cksum
188#define inp6_ifindex inp_depend6.inp6_ifindex
189#define in6p_flags inp_flags /* for KAME src sync over BSD*'s */
190#define in6p_socket inp_socket /* for KAME src sync over BSD*'s */
191#define in6p_lport inp_lport /* for KAME src sync over BSD*'s */
192#define in6p_fport inp_fport /* for KAME src sync over BSD*'s */
193#define in6p_ppcb inp_ppcb /* for KAME src sync over BSD*'s */
194
1c79356b
A
195 int hash_element; /* Array index of pcb's hash list */
196 caddr_t inp_saved_ppcb; /* place to save pointer while cached */
9bccf70c
A
197 struct inpcbpolicy *inp_sp;
198 u_long reserved[3]; /* For future use */
1c79356b 199};
9bccf70c 200#endif /* __APPLE_API_PRIVATE */
1c79356b
A
201/*
202 * The range of the generation count, as used in this implementation,
203 * is 9e19. We would have to create 300 billion connections per
204 * second for this number to roll over in a year. This seems sufficiently
205 * unlikely that we simply don't concern ourselves with that possibility.
206 */
207
208/*
209 * Interface exported to userland by various protocols which use
210 * inpcbs. Hack alert -- only define if struct xsocket is in scope.
211 */
212#ifdef _SYS_SOCKETVAR_H_
213struct xinpcb {
214 size_t xi_len; /* length of this structure */
215 struct inpcb xi_inp;
216 struct xsocket xi_socket;
217 u_quad_t xi_alignment_hack;
218};
219
220struct xinpgen {
221 size_t xig_len; /* length of this structure */
222 u_int xig_count; /* number of PCBs at this time */
223 inp_gen_t xig_gen; /* generation count at this time */
224 so_gen_t xig_sogen; /* socket generation count at this time */
225};
226#endif /* _SYS_SOCKETVAR_H_ */
227
9bccf70c 228#ifdef __APPLE_API_PRIVATE
1c79356b
A
229struct inpcbport {
230 LIST_ENTRY(inpcbport) phd_hash;
231 struct inpcbhead phd_pcblist;
232 u_short phd_port;
233};
234
235struct inpcbinfo { /* XXX documentation, prefixes */
236 struct inpcbhead *hashbase;
9bccf70c 237#ifdef __APPLE__
1c79356b 238 u_long hashsize; /* in elements */
9bccf70c 239#endif
1c79356b
A
240 u_long hashmask;
241 struct inpcbporthead *porthashbase;
242 u_long porthashmask;
243 struct inpcbhead *listhead;
244 u_short lastport;
245 u_short lastlow;
246 u_short lasthi;
247 void *ipi_zone; /* zone to allocate pcbs from */
248 u_int ipi_count; /* number of pcbs in this list */
249 u_quad_t ipi_gencnt; /* current generation count */
9bccf70c
A
250#ifdef __APPLE__
251 u_char all_owners;
252 struct socket nat_dummy_socket;
1c79356b 253 struct inpcb *last_pcb;
9bccf70c
A
254 caddr_t dummy_cb;
255#endif
1c79356b
A
256};
257
258#define INP_PCBHASH(faddr, lport, fport, mask) \
259 (((faddr) ^ ((faddr) >> 16) ^ ntohs((lport) ^ (fport))) & (mask))
260#define INP_PCBPORTHASH(lport, mask) \
261 (ntohs((lport)) & (mask))
262
263/* flags in inp_flags: */
264#define INP_RECVOPTS 0x01 /* receive incoming IP options */
265#define INP_RECVRETOPTS 0x02 /* receive IP options for reply */
266#define INP_RECVDSTADDR 0x04 /* receive IP dst address */
267#define INP_HDRINCL 0x08 /* user supplies entire IP header */
268#define INP_HIGHPORT 0x10 /* user wants "high" port binding */
269#define INP_LOWPORT 0x20 /* user wants "low" port binding */
270#define INP_ANONPORT 0x40 /* port chosen for user */
271#define INP_RECVIF 0x80 /* receive incoming interface */
272#define INP_MTUDISC 0x100 /* user can do MTU discovery */
9bccf70c
A
273#ifdef __APPLE__
274#define INP_STRIPHDR 0x200 /* Strip headers in raw_ip, for OT support */
275#endif
55e303ae
A
276#define INP_FAITH 0x400 /* accept FAITH'ed connections */
277#define INP_INADDR_ANY 0x800 /* local address wasn't specified */
278
279#define INP_RECVTTL 0x1000
9bccf70c
A
280
281#define IN6P_IPV6_V6ONLY 0x008000 /* restrict AF_INET6 socket for v6 */
282
283#define IN6P_PKTINFO 0x010000 /* receive IP6 dst and I/F */
284#define IN6P_HOPLIMIT 0x020000 /* receive hoplimit */
285#define IN6P_HOPOPTS 0x040000 /* receive hop-by-hop options */
286#define IN6P_DSTOPTS 0x080000 /* receive dst options after rthdr */
287#define IN6P_RTHDR 0x100000 /* receive routing header */
288#define IN6P_RTHDRDSTOPTS 0x200000 /* receive dstoptions before rthdr */
289#define IN6P_AUTOFLOWLABEL 0x800000 /* attach flowlabel automatically */
290#define IN6P_BINDV6ONLY 0x10000000 /* do not grab IPv4 traffic */
1c79356b
A
291
292#define INP_CONTROLOPTS (INP_RECVOPTS|INP_RECVRETOPTS|INP_RECVDSTADDR|\
293 INP_RECVIF|\
294 IN6P_PKTINFO|IN6P_HOPLIMIT|IN6P_HOPOPTS|\
9bccf70c 295 IN6P_DSTOPTS|IN6P_RTHDR|IN6P_RTHDRDSTOPTS|\
55e303ae 296 IN6P_AUTOFLOWLABEL|INP_RECVTTL)
9bccf70c
A
297#define INP_UNMAPPABLEOPTS (IN6P_HOPOPTS|IN6P_DSTOPTS|IN6P_RTHDR|\
298 IN6P_AUTOFLOWLABEL)
1c79356b
A
299
300 /* for KAME src sync over BSD*'s */
301#define IN6P_HIGHPORT INP_HIGHPORT
302#define IN6P_LOWPORT INP_LOWPORT
303#define IN6P_ANONPORT INP_ANONPORT
304#define IN6P_RECVIF INP_RECVIF
305#define IN6P_MTUDISC INP_MTUDISC
306#define IN6P_FAITH INP_FAITH
9bccf70c 307#define IN6P_CONTROLOPTS INP_CONTROLOPTS
1c79356b 308 /*
9bccf70c 309 * socket AF version is {newer than,or include}
1c79356b
A
310 * actual datagram AF version
311 */
312
313#define INPLOOKUP_WILDCARD 1
9bccf70c 314#ifdef __APPLE__
1c79356b
A
315#define INPCB_ALL_OWNERS 0xff
316#define INPCB_NO_OWNER 0x0
317#define INPCB_OWNED_BY_X 0x80
318#define INPCB_MAX_IDS 7
9bccf70c 319#endif
1c79356b
A
320
321#define sotoinpcb(so) ((struct inpcb *)(so)->so_pcb)
322#define sotoin6pcb(so) sotoinpcb(so) /* for KAME src sync over BSD*'s */
323
9bccf70c 324#define INP_SOCKAF(so) so->so_proto->pr_domain->dom_family
1c79356b 325
9bccf70c 326#define INP_CHECK_SOCKAF(so, af) (INP_SOCKAF(so) == af)
1c79356b
A
327
328#ifdef KERNEL
9bccf70c
A
329extern int ipport_lowfirstauto;
330extern int ipport_lowlastauto;
331extern int ipport_firstauto;
332extern int ipport_lastauto;
333extern int ipport_hifirstauto;
334extern int ipport_hilastauto;
335
336void in_pcbpurgeif0 __P((struct inpcb *, struct ifnet *));
1c79356b 337void in_losing __P((struct inpcb *));
9bccf70c 338void in_rtchange __P((struct inpcb *, int));
1c79356b
A
339int in_pcballoc __P((struct socket *, struct inpcbinfo *, struct proc *));
340int in_pcbbind __P((struct inpcb *, struct sockaddr *, struct proc *));
341int in_pcbconnect __P((struct inpcb *, struct sockaddr *, struct proc *));
342void in_pcbdetach __P((struct inpcb *));
343void in_pcbdisconnect __P((struct inpcb *));
344int in_pcbinshash __P((struct inpcb *));
345int in_pcbladdr __P((struct inpcb *, struct sockaddr *,
346 struct sockaddr_in **));
347struct inpcb *
348 in_pcblookup_local __P((struct inpcbinfo *,
349 struct in_addr, u_int, int));
350struct inpcb *
351 in_pcblookup_hash __P((struct inpcbinfo *,
9bccf70c
A
352 struct in_addr, u_int, struct in_addr, u_int,
353 int, struct ifnet *));
354void in_pcbnotifyall __P((struct inpcbhead *, struct in_addr,
355 int, void (*)(struct inpcb *, int)));
1c79356b
A
356void in_pcbrehash __P((struct inpcb *));
357int in_setpeeraddr __P((struct socket *so, struct sockaddr **nam));
358int in_setsockaddr __P((struct socket *so, struct sockaddr **nam));
359
9bccf70c 360#ifdef __APPLE__
1c79356b
A
361int
362in_pcb_grab_port __P((struct inpcbinfo *pcbinfo,
363 u_short options,
364 struct in_addr laddr,
365 u_short *lport,
366 struct in_addr faddr,
367 u_short fport,
368 u_int cookie,
369 u_char owner_id));
370
371int
372in_pcb_letgo_port __P((struct inpcbinfo *pcbinfo,
373 struct in_addr laddr,
374 u_short lport,
375 struct in_addr faddr,
376 u_short fport, u_char owner_id));
377
378u_char
379in_pcb_get_owner __P((struct inpcbinfo *pcbinfo,
380 struct in_addr laddr,
381 u_short lport,
382 struct in_addr faddr,
383 u_short fport,
384 u_int *cookie));
385
386void in_pcb_nat_init(struct inpcbinfo *pcbinfo, int afamily, int pfamily,
387 int protocol);
388
389int
390in_pcb_new_share_client(struct inpcbinfo *pcbinfo, u_char *owner_id);
391
392int
393in_pcb_rem_share_client(struct inpcbinfo *pcbinfo, u_char owner_id);
9bccf70c 394#endif /* __APPLE__ */
1c79356b
A
395
396void in_pcbremlists __P((struct inpcb *inp));
9bccf70c
A
397#ifndef __APPLE__
398int prison_xinpcb __P((struct proc *p, struct inpcb *inp));
1c79356b 399#endif
9bccf70c
A
400#endif /* _KERNEL */
401#endif /* __APPLE_API_PRIVATE */
1c79356b
A
402
403#endif /* !_NETINET_IN_PCB_H_ */