|
|
1.1 root 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: */
56:
57: #ifndef _NETINET_IN_PCB_H_
58: #define _NETINET_IN_PCB_H_
59:
60: #include <sys/queue.h>
61:
62: /*
63: * Common structure pcb for internet protocol implementation.
64: * Here are stored pointers to local and foreign host table
65: * entries, local and foreign socket numbers, and pointers
66: * up (to a socket structure) and down (to a protocol-specific)
67: * control block.
68: */
69: LIST_HEAD(inpcbhead, inpcb);
70: LIST_HEAD(inpcbporthead, inpcbport);
71: typedef u_quad_t inp_gen_t;
72:
73: /*
74: * NB: the zone allocator is type-stable EXCEPT FOR THE FIRST TWO LONGS
75: * of the structure. Therefore, it is important that the members in
76: * that position not contain any information which is required to be
77: * stable.
78: */
79: struct inpcb {
80: LIST_ENTRY(inpcb) inp_hash; /* hash list */
81: struct in_addr inp_faddr; /* foreign host table entry */
82: struct in_addr inp_laddr; /* local host table entry */
83: u_short inp_fport; /* foreign port */
84: u_short inp_lport; /* local port */
85: LIST_ENTRY(inpcb) inp_list; /* list for all PCBs of this proto */
86: caddr_t inp_ppcb; /* pointer to per-protocol pcb */
87: struct inpcbinfo *inp_pcbinfo; /* PCB list info */
88: struct socket *inp_socket; /* back pointer to socket */
89: struct mbuf *inp_options; /* IP options */
90: struct route inp_route; /* placeholder for routing entry */
91: int inp_flags; /* generic IP/datagram flags */
92: u_char inp_ip_tos; /* type of service proto */
93: u_char inp_ip_ttl; /* time to live proto */
94: u_char inp_ip_p; /* protocol proto */
95: u_char nat_owner; /* Used to NAT TCP/UDP traffic */
96: u_long nat_cookie; /* Cookie stored and returned to NAT */
97: struct ip_moptions *inp_moptions; /* IP multicast options */
98: LIST_ENTRY(inpcb) inp_portlist; /* list for this PCB's local port */
99: struct inpcbport *inp_phd; /* head of this list */
100: inp_gen_t inp_gencnt; /* generation count of this instance */
101: };
102: /*
103: * The range of the generation count, as used in this implementation,
104: * is 9e19. We would have to create 300 billion connections per
105: * second for this number to roll over in a year. This seems sufficiently
106: * unlikely that we simply don't concern ourselves with that possibility.
107: */
108:
109: /*
110: * Interface exported to userland by various protocols which use
111: * inpcbs. Hack alert -- only define if struct xsocket is in scope.
112: */
113: #ifdef _SYS_SOCKETVAR_H_
114: struct xinpcb {
115: size_t xi_len; /* length of this structure */
116: struct inpcb xi_inp;
117: struct xsocket xi_socket;
118: u_quad_t xi_alignment_hack;
119: };
120:
121: struct xinpgen {
122: size_t xig_len; /* length of this structure */
123: u_int xig_count; /* number of PCBs at this time */
124: inp_gen_t xig_gen; /* generation count at this time */
125: so_gen_t xig_sogen; /* socket generation count at this time */
126: };
127: #endif /* _SYS_SOCKETVAR_H_ */
128:
129: struct inpcbport {
130: LIST_ENTRY(inpcbport) phd_hash;
131: struct inpcbhead phd_pcblist;
132: u_short phd_port;
133: };
134:
135: struct inpcbinfo { /* XXX documentation, prefixes */
136: struct inpcbhead *hashbase;
137: u_long hashmask;
138: struct inpcbporthead *porthashbase;
139: u_long porthashmask;
140: struct inpcbhead *listhead;
141: u_short lastport;
142: u_short lastlow;
143: u_short lasthi;
144: void *ipi_zone; /* zone to allocate pcbs from */
145: u_int ipi_count; /* number of pcbs in this list */
146: u_quad_t ipi_gencnt; /* current generation count */
147: u_char all_owners;
148: struct socket nat_dummy_socket;
149: struct inpcb *last_pcb;
150: caddr_t dummy_cb;
151: };
152:
153: #define INP_PCBHASH(faddr, lport, fport, mask) \
154: (((faddr) ^ ((faddr) >> 16) ^ ntohs((lport) ^ (fport))) & (mask))
155: #define INP_PCBPORTHASH(lport, mask) \
156: (ntohs((lport)) & (mask))
157:
158: /* flags in inp_flags: */
159: #define INP_RECVOPTS 0x01 /* receive incoming IP options */
160: #define INP_RECVRETOPTS 0x02 /* receive IP options for reply */
161: #define INP_RECVDSTADDR 0x04 /* receive IP dst address */
162: #define INP_HDRINCL 0x08 /* user supplies entire IP header */
163: #define INP_HIGHPORT 0x10 /* user wants "high" port binding */
164: #define INP_LOWPORT 0x20 /* user wants "low" port binding */
165: #define INP_ANONPORT 0x40 /* port chosen for user */
166: #define INP_RECVIF 0x80 /* receive incoming interface */
167: #define INP_MTUDISC 0x100 /* user can do MTU discovery */
168: #define INP_CONTROLOPTS (INP_RECVOPTS|INP_RECVRETOPTS|INP_RECVDSTADDR|\
169: INP_RECVIF)
170: #define INP_STRIPHDR 0x200 /* drop receive of raw IP header */
171:
172: #define INPLOOKUP_WILDCARD 1
173: #define INPCB_ALL_OWNERS 0xff
174: #define INPCB_NO_OWNER 0x0
175: #define INPCB_OWNED_BY_X 0x80
176: #define INPCB_MAX_IDS 7
177:
178: #define sotoinpcb(so) ((struct inpcb *)(so)->so_pcb)
179:
180: #ifdef KERNEL
181: void in_losing __P((struct inpcb *));
182: int in_pcballoc __P((struct socket *, struct inpcbinfo *, struct proc *));
183: int in_pcbbind __P((struct inpcb *, struct sockaddr *, struct proc *));
184: int in_pcbconnect __P((struct inpcb *, struct sockaddr *, struct proc *));
185: void in_pcbdetach __P((struct inpcb *));
186: void in_pcbdisconnect __P((struct inpcb *));
187: int in_pcbinshash __P((struct inpcb *));
188: int in_pcbladdr __P((struct inpcb *, struct sockaddr *,
189: struct sockaddr_in **));
190: struct inpcb *
191: in_pcblookup_local __P((struct inpcbinfo *,
192: struct in_addr, u_int, int));
193: struct inpcb *
194: in_pcblookup_hash __P((struct inpcbinfo *,
195: struct in_addr, u_int, struct in_addr, u_int, int));
196: void in_pcbnotify __P((struct inpcbhead *, struct sockaddr *,
197: u_int, struct in_addr, u_int, int, void (*)(struct inpcb *, int)));
198: void in_pcbrehash __P((struct inpcb *));
199: int in_setpeeraddr __P((struct socket *so, struct sockaddr **nam));
200: int in_setsockaddr __P((struct socket *so, struct sockaddr **nam));
201:
202: int
203: in_pcb_grab_port __P((struct inpcbinfo *pcbinfo,
204: u_short options,
205: struct in_addr laddr,
206: u_short *lport,
207: struct in_addr faddr,
208: u_short fport,
209: u_int cookie,
210: u_char owner_id));
211:
212: int
213: in_pcb_letgo_port __P((struct inpcbinfo *pcbinfo,
214: struct in_addr laddr,
215: u_short lport,
216: struct in_addr faddr,
217: u_short fport, u_char owner_id));
218:
219: u_char
220: in_pcb_get_owner __P((struct inpcbinfo *pcbinfo,
221: struct in_addr laddr,
222: u_short lport,
223: struct in_addr faddr,
224: u_short fport,
225: u_int *cookie));
226:
227: void in_pcb_nat_init(struct inpcbinfo *pcbinfo, int afamily, int pfamily,
228: int protocol);
229:
230: int
231: in_pcb_new_share_client(struct inpcbinfo *pcbinfo, u_char *owner_id);
232:
233: int
234: in_pcb_rem_share_client(struct inpcbinfo *pcbinfo, u_char owner_id);
235:
236: #endif /* KERNEL */
237:
238: #endif /* !_NETINET_IN_PCB_H_ */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.