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