2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
23 * Copyright (c) 1982, 1986, 1990, 1993
24 * The Regents of the University of California. All rights reserved.
26 * Redistribution and use in source and binary forms, with or without
27 * modification, are permitted provided that the following conditions
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.
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
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 $
58 #ifndef _NETINET_IN_PCB_H_
59 #define _NETINET_IN_PCB_H_
60 #include <sys/appleapiopts.h>
62 #include <sys/queue.h>
65 #include <netinet6/ipsec.h> /* for IPSEC */
67 #ifdef __APPLE_API_PRIVATE
69 #define in6pcb inpcb /* for KAME src sync over BSD*'s */
70 #define in6p_sp inp_sp /* for KAME src sync over BSD*'s */
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)
79 LIST_HEAD(inpcbhead
, inpcb
);
80 LIST_HEAD(inpcbporthead
, inpcbport
);
81 typedef u_quad_t inp_gen_t
;
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)
89 u_int32_t ia46_pad32
[3];
90 struct in_addr ia46_addr4
;
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
102 LIST_ENTRY(inpcb
) inp_hash
; /* hash list */
103 struct in_addr inp_faddr
; /* foreign host table entry */
104 struct in_addr inp_laddr
; /* local host table entry */
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 */
123 u_char inp_ip_ttl
; /* time to live proto */
124 u_char inp_ip_p
; /* protocol proto */
125 /* protocol dependent part */
127 /* foreign host table entry */
128 struct in_addr_4in6 inp46_foreign
;
129 struct in6_addr inp6_foreign
;
132 /* local host table entry */
133 struct in_addr_4in6 inp46_local
;
134 struct in6_addr inp6_local
;
137 /* placeholder for routing entry */
138 struct route inp4_route
;
139 struct route_in6 inp6_route
;
142 /* type of service proto */
145 struct mbuf
*inp4_options
;
146 /* IP multicast options */
147 struct ip_moptions
*inp4_moptions
;
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
157 struct mbuf
*inp6_options
;
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 */
169 u_short inp6_ifindex
;
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 */
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 */
197 #endif /* __APPLE_API_PRIVATE */
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.
206 * Interface exported to userland by various protocols which use
207 * inpcbs. Hack alert -- only define if struct xsocket is in scope.
209 #ifdef _SYS_SOCKETVAR_H_
211 size_t xi_len
; /* length of this structure */
213 struct xsocket xi_socket
;
214 u_quad_t xi_alignment_hack
;
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 */
223 #endif /* _SYS_SOCKETVAR_H_ */
225 #ifdef __APPLE_API_PRIVATE
227 LIST_ENTRY(inpcbport
) phd_hash
;
228 struct inpcbhead phd_pcblist
;
232 struct inpcbinfo
{ /* XXX documentation, prefixes */
233 struct inpcbhead
*hashbase
;
235 u_long hashsize
; /* in elements */
238 struct inpcbporthead
*porthashbase
;
240 struct inpcbhead
*listhead
;
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 */
249 struct socket nat_dummy_socket
;
250 struct inpcb
*last_pcb
;
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))
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 */
271 #define INP_STRIPHDR 0x200 /* Strip headers in raw_ip, for OT support */
273 #define INP_FAITH 0x400 /* accept FAITH'ed connections */
275 #define IN6P_IPV6_V6ONLY 0x008000 /* restrict AF_INET6 socket for v6 */
277 #define IN6P_PKTINFO 0x010000 /* receive IP6 dst and I/F */
278 #define IN6P_HOPLIMIT 0x020000 /* receive hoplimit */
279 #define IN6P_HOPOPTS 0x040000 /* receive hop-by-hop options */
280 #define IN6P_DSTOPTS 0x080000 /* receive dst options after rthdr */
281 #define IN6P_RTHDR 0x100000 /* receive routing header */
282 #define IN6P_RTHDRDSTOPTS 0x200000 /* receive dstoptions before rthdr */
283 #define IN6P_AUTOFLOWLABEL 0x800000 /* attach flowlabel automatically */
284 #define IN6P_BINDV6ONLY 0x10000000 /* do not grab IPv4 traffic */
286 #define INP_CONTROLOPTS (INP_RECVOPTS|INP_RECVRETOPTS|INP_RECVDSTADDR|\
288 IN6P_PKTINFO|IN6P_HOPLIMIT|IN6P_HOPOPTS|\
289 IN6P_DSTOPTS|IN6P_RTHDR|IN6P_RTHDRDSTOPTS|\
291 #define INP_UNMAPPABLEOPTS (IN6P_HOPOPTS|IN6P_DSTOPTS|IN6P_RTHDR|\
294 /* for KAME src sync over BSD*'s */
295 #define IN6P_HIGHPORT INP_HIGHPORT
296 #define IN6P_LOWPORT INP_LOWPORT
297 #define IN6P_ANONPORT INP_ANONPORT
298 #define IN6P_RECVIF INP_RECVIF
299 #define IN6P_MTUDISC INP_MTUDISC
300 #define IN6P_FAITH INP_FAITH
301 #define IN6P_CONTROLOPTS INP_CONTROLOPTS
303 * socket AF version is {newer than,or include}
304 * actual datagram AF version
307 #define INPLOOKUP_WILDCARD 1
309 #define INPCB_ALL_OWNERS 0xff
310 #define INPCB_NO_OWNER 0x0
311 #define INPCB_OWNED_BY_X 0x80
312 #define INPCB_MAX_IDS 7
315 #define sotoinpcb(so) ((struct inpcb *)(so)->so_pcb)
316 #define sotoin6pcb(so) sotoinpcb(so) /* for KAME src sync over BSD*'s */
318 #define INP_SOCKAF(so) so->so_proto->pr_domain->dom_family
320 #define INP_CHECK_SOCKAF(so, af) (INP_SOCKAF(so) == af)
323 extern int ipport_lowfirstauto
;
324 extern int ipport_lowlastauto
;
325 extern int ipport_firstauto
;
326 extern int ipport_lastauto
;
327 extern int ipport_hifirstauto
;
328 extern int ipport_hilastauto
;
330 void in_pcbpurgeif0
__P((struct inpcb
*, struct ifnet
*));
331 void in_losing
__P((struct inpcb
*));
332 void in_rtchange
__P((struct inpcb
*, int));
333 int in_pcballoc
__P((struct socket
*, struct inpcbinfo
*, struct proc
*));
334 int in_pcbbind
__P((struct inpcb
*, struct sockaddr
*, struct proc
*));
335 int in_pcbconnect
__P((struct inpcb
*, struct sockaddr
*, struct proc
*));
336 void in_pcbdetach
__P((struct inpcb
*));
337 void in_pcbdisconnect
__P((struct inpcb
*));
338 int in_pcbinshash
__P((struct inpcb
*));
339 int in_pcbladdr
__P((struct inpcb
*, struct sockaddr
*,
340 struct sockaddr_in
**));
342 in_pcblookup_local
__P((struct inpcbinfo
*,
343 struct in_addr
, u_int
, int));
345 in_pcblookup_hash
__P((struct inpcbinfo
*,
346 struct in_addr
, u_int
, struct in_addr
, u_int
,
347 int, struct ifnet
*));
348 void in_pcbnotifyall
__P((struct inpcbhead
*, struct in_addr
,
349 int, void (*)(struct inpcb
*, int)));
350 void in_pcbrehash
__P((struct inpcb
*));
351 int in_setpeeraddr
__P((struct socket
*so
, struct sockaddr
**nam
));
352 int in_setsockaddr
__P((struct socket
*so
, struct sockaddr
**nam
));
356 in_pcb_grab_port
__P((struct inpcbinfo
*pcbinfo
,
358 struct in_addr laddr
,
360 struct in_addr faddr
,
366 in_pcb_letgo_port
__P((struct inpcbinfo
*pcbinfo
,
367 struct in_addr laddr
,
369 struct in_addr faddr
,
370 u_short fport
, u_char owner_id
));
373 in_pcb_get_owner
__P((struct inpcbinfo
*pcbinfo
,
374 struct in_addr laddr
,
376 struct in_addr faddr
,
380 void in_pcb_nat_init(struct inpcbinfo
*pcbinfo
, int afamily
, int pfamily
,
384 in_pcb_new_share_client(struct inpcbinfo
*pcbinfo
, u_char
*owner_id
);
387 in_pcb_rem_share_client(struct inpcbinfo
*pcbinfo
, u_char owner_id
);
388 #endif /* __APPLE__ */
390 void in_pcbremlists
__P((struct inpcb
*inp
));
392 int prison_xinpcb
__P((struct proc
*p
, struct inpcb
*inp
));
395 #endif /* __APPLE_API_PRIVATE */
397 #endif /* !_NETINET_IN_PCB_H_ */