FreeBSD/Linux Kernel Cross Reference
sys/netinet/in_pcb.h
1 /*-
2 * Copyright (c) 1982, 1986, 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 4. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * @(#)in_pcb.h 8.1 (Berkeley) 6/10/93
30 * $FreeBSD: src/sys/netinet/in_pcb.h,v 1.76.2.3 2005/01/31 23:26:35 imp Exp $
31 */
32
33 #ifndef _NETINET_IN_PCB_H_
34 #define _NETINET_IN_PCB_H_
35
36 #include <sys/queue.h>
37 #include <sys/_lock.h>
38 #include <sys/_mutex.h>
39
40 #include <net/route.h>
41
42 #define in6pcb inpcb /* for KAME src sync over BSD*'s */
43 #define in6p_sp inp_sp /* for KAME src sync over BSD*'s */
44 struct inpcbpolicy;
45
46 /*
47 * Common structure pcb for internet protocol implementation.
48 * Here are stored pointers to local and foreign host table
49 * entries, local and foreign socket numbers, and pointers
50 * up (to a socket structure) and down (to a protocol-specific)
51 * control block.
52 */
53 LIST_HEAD(inpcbhead, inpcb);
54 LIST_HEAD(inpcbporthead, inpcbport);
55 typedef u_quad_t inp_gen_t;
56
57 /*
58 * PCB with AF_INET6 null bind'ed laddr can receive AF_INET input packet.
59 * So, AF_INET6 null laddr is also used as AF_INET null laddr,
60 * by utilize following structure. (At last, same as INRIA)
61 */
62 struct in_addr_4in6 {
63 u_int32_t ia46_pad32[3];
64 struct in_addr ia46_addr4;
65 };
66
67 /*
68 * NOTE: ipv6 addrs should be 64-bit aligned, per RFC 2553.
69 * in_conninfo has some extra padding to accomplish this.
70 */
71 struct in_endpoints {
72 u_int16_t ie_fport; /* foreign port */
73 u_int16_t ie_lport; /* local port */
74 /* protocol dependent part, local and foreign addr */
75 union {
76 /* foreign host table entry */
77 struct in_addr_4in6 ie46_foreign;
78 struct in6_addr ie6_foreign;
79 } ie_dependfaddr;
80 union {
81 /* local host table entry */
82 struct in_addr_4in6 ie46_local;
83 struct in6_addr ie6_local;
84 } ie_dependladdr;
85 #define ie_faddr ie_dependfaddr.ie46_foreign.ia46_addr4
86 #define ie_laddr ie_dependladdr.ie46_local.ia46_addr4
87 #define ie6_faddr ie_dependfaddr.ie6_foreign
88 #define ie6_laddr ie_dependladdr.ie6_local
89 };
90
91 /*
92 * XXX
93 * the defines for inc_* are hacks and should be changed to direct references
94 */
95 struct in_conninfo {
96 u_int8_t inc_flags;
97 u_int8_t inc_len;
98 u_int16_t inc_pad; /* XXX alignment for in_endpoints */
99 /* protocol dependent part */
100 struct in_endpoints inc_ie;
101 };
102 #define inc_isipv6 inc_flags /* temp compatability */
103 #define inc_fport inc_ie.ie_fport
104 #define inc_lport inc_ie.ie_lport
105 #define inc_faddr inc_ie.ie_faddr
106 #define inc_laddr inc_ie.ie_laddr
107 #define inc6_faddr inc_ie.ie6_faddr
108 #define inc6_laddr inc_ie.ie6_laddr
109
110 struct icmp6_filter;
111
112 struct inpcb {
113 LIST_ENTRY(inpcb) inp_hash; /* hash list */
114 LIST_ENTRY(inpcb) inp_list; /* list for all PCBs of this proto */
115 u_int32_t inp_flow;
116
117 /* local and foreign ports, local and foreign addr */
118 struct in_conninfo inp_inc;
119
120 caddr_t inp_ppcb; /* pointer to per-protocol pcb */
121 struct inpcbinfo *inp_pcbinfo; /* PCB list info */
122 struct socket *inp_socket; /* back pointer to socket */
123 /* list for this PCB's local port */
124 struct label *inp_label; /* MAC label */
125 int inp_flags; /* generic IP/datagram flags */
126
127 struct inpcbpolicy *inp_sp; /* for IPSEC */
128 u_char inp_vflag; /* IP version flag (v4/v6) */
129 #define INP_IPV4 0x1
130 #define INP_IPV6 0x2
131 #define INP_IPV6PROTO 0x4 /* opened under IPv6 protocol */
132 #define INP_TIMEWAIT 0x8 /* .. probably doesn't go here */
133 #define INP_ONESBCAST 0x10 /* send all-ones broadcast */
134 u_char inp_ip_ttl; /* time to live proto */
135 u_char inp_ip_p; /* protocol proto */
136
137 /* protocol dependent part; options */
138 struct {
139 u_char inp4_ip_tos; /* type of service proto */
140 struct mbuf *inp4_options; /* IP options */
141 struct ip_moptions *inp4_moptions; /* IP multicast options */
142 } inp_depend4;
143 #define inp_fport inp_inc.inc_fport
144 #define inp_lport inp_inc.inc_lport
145 #define inp_faddr inp_inc.inc_faddr
146 #define inp_laddr inp_inc.inc_laddr
147 #define inp_ip_tos inp_depend4.inp4_ip_tos
148 #define inp_options inp_depend4.inp4_options
149 #define inp_moptions inp_depend4.inp4_moptions
150 struct {
151 /* IP options */
152 struct mbuf *inp6_options;
153 /* IP6 options for outgoing packets */
154 struct ip6_pktopts *inp6_outputopts;
155 /* IP multicast options */
156 struct ip6_moptions *inp6_moptions;
157 /* ICMPv6 code type filter */
158 struct icmp6_filter *inp6_icmp6filt;
159 /* IPV6_CHECKSUM setsockopt */
160 int inp6_cksum;
161 u_short inp6_ifindex;
162 short inp6_hops;
163 } inp_depend6;
164 LIST_ENTRY(inpcb) inp_portlist;
165 struct inpcbport *inp_phd; /* head of this list */
166 inp_gen_t inp_gencnt; /* generation count of this instance */
167 struct mtx inp_mtx;
168
169 #define in6p_faddr inp_inc.inc6_faddr
170 #define in6p_laddr inp_inc.inc6_laddr
171 #define in6p_ip6_hlim inp_depend6.inp6_hlim
172 #define in6p_hops inp_depend6.inp6_hops /* default hop limit */
173 #define in6p_ip6_nxt inp_ip_p
174 #define in6p_flowinfo inp_flow
175 #define in6p_vflag inp_vflag
176 #define in6p_options inp_depend6.inp6_options
177 #define in6p_outputopts inp_depend6.inp6_outputopts
178 #define in6p_moptions inp_depend6.inp6_moptions
179 #define in6p_icmp6filt inp_depend6.inp6_icmp6filt
180 #define in6p_cksum inp_depend6.inp6_cksum
181 #define inp6_ifindex inp_depend6.inp6_ifindex
182 #define in6p_flags inp_flags /* for KAME src sync over BSD*'s */
183 #define in6p_socket inp_socket /* for KAME src sync over BSD*'s */
184 #define in6p_lport inp_lport /* for KAME src sync over BSD*'s */
185 #define in6p_fport inp_fport /* for KAME src sync over BSD*'s */
186 #define in6p_ppcb inp_ppcb /* for KAME src sync over BSD*'s */
187 };
188 /*
189 * The range of the generation count, as used in this implementation,
190 * is 9e19. We would have to create 300 billion connections per
191 * second for this number to roll over in a year. This seems sufficiently
192 * unlikely that we simply don't concern ourselves with that possibility.
193 */
194
195 /*
196 * Interface exported to userland by various protocols which use
197 * inpcbs. Hack alert -- only define if struct xsocket is in scope.
198 */
199 #ifdef _SYS_SOCKETVAR_H_
200 struct xinpcb {
201 size_t xi_len; /* length of this structure */
202 struct inpcb xi_inp;
203 struct xsocket xi_socket;
204 u_quad_t xi_alignment_hack;
205 };
206
207 struct xinpgen {
208 size_t xig_len; /* length of this structure */
209 u_int xig_count; /* number of PCBs at this time */
210 inp_gen_t xig_gen; /* generation count at this time */
211 so_gen_t xig_sogen; /* socket generation count at this time */
212 };
213 #endif /* _SYS_SOCKETVAR_H_ */
214
215 struct inpcbport {
216 LIST_ENTRY(inpcbport) phd_hash;
217 struct inpcbhead phd_pcblist;
218 u_short phd_port;
219 };
220
221 struct inpcbinfo { /* XXX documentation, prefixes */
222 struct inpcbhead *hashbase;
223 u_long hashmask;
224 struct inpcbporthead *porthashbase;
225 u_long porthashmask;
226 struct inpcbhead *listhead;
227 u_short lastport;
228 u_short lastlow;
229 u_short lasthi;
230 struct uma_zone *ipi_zone; /* zone to allocate pcbs from */
231 u_int ipi_count; /* number of pcbs in this list */
232 u_quad_t ipi_gencnt; /* current generation count */
233 struct mtx ipi_mtx;
234 };
235
236 /*
237 * NB: We cannot enable assertions when IPv6 is configured as
238 * this code is shared by both IPv4 and IPv6 and IPv6 is
239 * not properly locked.
240 */
241 #define INP_LOCK_INIT(inp, d, t) \
242 mtx_init(&(inp)->inp_mtx, (d), (t), MTX_DEF | MTX_RECURSE | MTX_DUPOK)
243 #define INP_LOCK_DESTROY(inp) mtx_destroy(&(inp)->inp_mtx)
244 #define INP_LOCK(inp) mtx_lock(&(inp)->inp_mtx)
245 #define INP_UNLOCK(inp) mtx_unlock(&(inp)->inp_mtx)
246 #define INP_LOCK_ASSERT(inp) do { \
247 mtx_assert(&(inp)->inp_mtx, MA_OWNED); \
248 NET_ASSERT_GIANT(); \
249 } while (0)
250 #define INP_UNLOCK_ASSERT(inp) mtx_assert(&(inp)->inp_mtx, MA_NOTOWNED)
251
252 #define INP_INFO_LOCK_INIT(ipi, d) \
253 mtx_init(&(ipi)->ipi_mtx, (d), NULL, MTX_DEF | MTX_RECURSE)
254 #define INP_INFO_RLOCK(ipi) mtx_lock(&(ipi)->ipi_mtx)
255 #define INP_INFO_WLOCK(ipi) mtx_lock(&(ipi)->ipi_mtx)
256 #define INP_INFO_RUNLOCK(ipi) mtx_unlock(&(ipi)->ipi_mtx)
257 #define INP_INFO_WUNLOCK(ipi) mtx_unlock(&(ipi)->ipi_mtx)
258 #define INP_INFO_RLOCK_ASSERT(ipi) do { \
259 mtx_assert(&(ipi)->ipi_mtx, MA_OWNED); \
260 NET_ASSERT_GIANT(); \
261 } while (0)
262 #define INP_INFO_WLOCK_ASSERT(ipi) do { \
263 mtx_assert(&(ipi)->ipi_mtx, MA_OWNED); \
264 NET_ASSERT_GIANT(); \
265 } while (0)
266
267 #define INP_PCBHASH(faddr, lport, fport, mask) \
268 (((faddr) ^ ((faddr) >> 16) ^ ntohs((lport) ^ (fport))) & (mask))
269 #define INP_PCBPORTHASH(lport, mask) \
270 (ntohs((lport)) & (mask))
271
272 /* flags in inp_flags: */
273 #define INP_RECVOPTS 0x01 /* receive incoming IP options */
274 #define INP_RECVRETOPTS 0x02 /* receive IP options for reply */
275 #define INP_RECVDSTADDR 0x04 /* receive IP dst address */
276 #define INP_HDRINCL 0x08 /* user supplies entire IP header */
277 #define INP_HIGHPORT 0x10 /* user wants "high" port binding */
278 #define INP_LOWPORT 0x20 /* user wants "low" port binding */
279 #define INP_ANONPORT 0x40 /* port chosen for user */
280 #define INP_RECVIF 0x80 /* receive incoming interface */
281 #define INP_MTUDISC 0x100 /* user can do MTU discovery */
282 #define INP_FAITH 0x200 /* accept FAITH'ed connections */
283 #define INP_RECVTTL 0x400 /* receive incoming IP TTL */
284
285 #define IN6P_IPV6_V6ONLY 0x008000 /* restrict AF_INET6 socket for v6 */
286
287 #define IN6P_PKTINFO 0x010000 /* receive IP6 dst and I/F */
288 #define IN6P_HOPLIMIT 0x020000 /* receive hoplimit */
289 #define IN6P_HOPOPTS 0x040000 /* receive hop-by-hop options */
290 #define IN6P_DSTOPTS 0x080000 /* receive dst options after rthdr */
291 #define IN6P_RTHDR 0x100000 /* receive routing header */
292 #define IN6P_RTHDRDSTOPTS 0x200000 /* receive dstoptions before rthdr */
293 #define IN6P_TCLASS 0x400000 /* receive traffic class value */
294 #define IN6P_AUTOFLOWLABEL 0x800000 /* attach flowlabel automatically */
295 #define IN6P_RFC2292 0x40000000 /* used RFC2292 API on the socket */
296 #define IN6P_MTU 0x80000000 /* receive path MTU */
297
298 #define INP_CONTROLOPTS (INP_RECVOPTS|INP_RECVRETOPTS|INP_RECVDSTADDR|\
299 INP_RECVIF|INP_RECVTTL|\
300 IN6P_PKTINFO|IN6P_HOPLIMIT|IN6P_HOPOPTS|\
301 IN6P_DSTOPTS|IN6P_RTHDR|IN6P_RTHDRDSTOPTS|\
302 IN6P_TCLASS|IN6P_AUTOFLOWLABEL|IN6P_RFC2292|\
303 IN6P_MTU)
304 #define INP_UNMAPPABLEOPTS (IN6P_HOPOPTS|IN6P_DSTOPTS|IN6P_RTHDR|\
305 IN6P_TCLASS|IN6P_AUTOFLOWLABEL)
306
307 /* for KAME src sync over BSD*'s */
308 #define IN6P_HIGHPORT INP_HIGHPORT
309 #define IN6P_LOWPORT INP_LOWPORT
310 #define IN6P_ANONPORT INP_ANONPORT
311 #define IN6P_RECVIF INP_RECVIF
312 #define IN6P_MTUDISC INP_MTUDISC
313 #define IN6P_FAITH INP_FAITH
314 #define IN6P_CONTROLOPTS INP_CONTROLOPTS
315 /*
316 * socket AF version is {newer than,or include}
317 * actual datagram AF version
318 */
319
320 #define INPLOOKUP_WILDCARD 1
321 #define sotoinpcb(so) ((struct inpcb *)(so)->so_pcb)
322 #define sotoin6pcb(so) sotoinpcb(so) /* for KAME src sync over BSD*'s */
323
324 #define INP_SOCKAF(so) so->so_proto->pr_domain->dom_family
325
326 #define INP_CHECK_SOCKAF(so, af) (INP_SOCKAF(so) == af)
327
328 #ifdef _KERNEL
329 extern int ipport_lowfirstauto;
330 extern int ipport_lowlastauto;
331 extern int ipport_firstauto;
332 extern int ipport_lastauto;
333 extern int ipport_hifirstauto;
334 extern int ipport_hilastauto;
335 extern struct callout ipport_tick_callout;
336
337 void in_pcbpurgeif0(struct inpcbinfo *, struct ifnet *);
338 int in_pcballoc(struct socket *, struct inpcbinfo *, const char *);
339 int in_pcbbind(struct inpcb *, struct sockaddr *, struct ucred *);
340 int in_pcbbind_setup(struct inpcb *, struct sockaddr *, in_addr_t *,
341 u_short *, struct ucred *);
342 int in_pcbconnect(struct inpcb *, struct sockaddr *, struct ucred *);
343 int in_pcbconnect_setup(struct inpcb *, struct sockaddr *, in_addr_t *,
344 u_short *, in_addr_t *, u_short *, struct inpcb **,
345 struct ucred *);
346 void in_pcbdetach(struct inpcb *);
347 void in_pcbdisconnect(struct inpcb *);
348 int in_pcbinshash(struct inpcb *);
349 struct inpcb *
350 in_pcblookup_local(struct inpcbinfo *,
351 struct in_addr, u_int, int);
352 struct inpcb *
353 in_pcblookup_hash(struct inpcbinfo *, struct in_addr, u_int,
354 struct in_addr, u_int, int, struct ifnet *);
355 void in_pcbnotifyall(struct inpcbinfo *pcbinfo, struct in_addr,
356 int, struct inpcb *(*)(struct inpcb *, int));
357 void in_pcbrehash(struct inpcb *);
358 void in_pcbsetsolabel(struct socket *so);
359 int in_setpeeraddr(struct socket *so, struct sockaddr **nam, struct inpcbinfo *pcbinfo);
360 int in_setsockaddr(struct socket *so, struct sockaddr **nam, struct inpcbinfo *pcbinfo);
361 struct sockaddr *
362 in_sockaddr(in_port_t port, struct in_addr *addr);
363 void in_pcbsosetlabel(struct socket *so);
364 void in_pcbremlists(struct inpcb *inp);
365 void ipport_tick(void *xtp);
366 #endif /* _KERNEL */
367
368 #endif /* !_NETINET_IN_PCB_H_ */
Cache object: 1d16ebc667d53aa2bed8bd71a6f88340
|