1 | /*- |
---|
2 | * Copyright (c) 1982, 1986, 1990, 1993 |
---|
3 | * The Regents of the University of California. |
---|
4 | * All rights reserved. |
---|
5 | * |
---|
6 | * Redistribution and use in source and binary forms, with or without |
---|
7 | * modification, are permitted provided that the following conditions |
---|
8 | * are met: |
---|
9 | * 1. Redistributions of source code must retain the above copyright |
---|
10 | * notice, this list of conditions and the following disclaimer. |
---|
11 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
12 | * notice, this list of conditions and the following disclaimer in the |
---|
13 | * documentation and/or other materials provided with the distribution. |
---|
14 | * 4. Neither the name of the University nor the names of its contributors |
---|
15 | * may be used to endorse or promote products derived from this software |
---|
16 | * without specific prior written permission. |
---|
17 | * |
---|
18 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
---|
19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
---|
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
---|
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
---|
24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
---|
25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
---|
26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
---|
27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
---|
28 | * SUCH DAMAGE. |
---|
29 | * |
---|
30 | * @(#)in_pcb.h 8.1 (Berkeley) 6/10/93 |
---|
31 | * $FreeBSD$ |
---|
32 | */ |
---|
33 | |
---|
34 | #ifndef _NETINET_IN_PCB_H_ |
---|
35 | #define _NETINET_IN_PCB_H_ |
---|
36 | |
---|
37 | #include <sys/queue.h> |
---|
38 | #include <sys/_lock.h> |
---|
39 | #include <sys/_mutex.h> |
---|
40 | #include <sys/_rwlock.h> |
---|
41 | |
---|
42 | #ifdef _KERNEL |
---|
43 | #include <sys/rwlock.h> |
---|
44 | #include <net/vnet.h> |
---|
45 | #endif |
---|
46 | |
---|
47 | #define in6pcb inpcb /* for KAME src sync over BSD*'s */ |
---|
48 | #define in6p_sp inp_sp /* for KAME src sync over BSD*'s */ |
---|
49 | struct inpcbpolicy; |
---|
50 | |
---|
51 | /* |
---|
52 | * struct inpcb is the common protocol control block structure used in most |
---|
53 | * IP transport protocols. |
---|
54 | * |
---|
55 | * Pointers to local and foreign host table entries, local and foreign socket |
---|
56 | * numbers, and pointers up (to a socket structure) and down (to a |
---|
57 | * protocol-specific control block) are stored here. |
---|
58 | */ |
---|
59 | LIST_HEAD(inpcbhead, inpcb); |
---|
60 | LIST_HEAD(inpcbporthead, inpcbport); |
---|
61 | typedef u_quad_t inp_gen_t; |
---|
62 | |
---|
63 | /* |
---|
64 | * PCB with AF_INET6 null bind'ed laddr can receive AF_INET input packet. |
---|
65 | * So, AF_INET6 null laddr is also used as AF_INET null laddr, by utilizing |
---|
66 | * the following structure. |
---|
67 | */ |
---|
68 | struct in_addr_4in6 { |
---|
69 | u_int32_t ia46_pad32[3]; |
---|
70 | struct in_addr ia46_addr4; |
---|
71 | }; |
---|
72 | |
---|
73 | /* |
---|
74 | * NOTE: ipv6 addrs should be 64-bit aligned, per RFC 2553. in_conninfo has |
---|
75 | * some extra padding to accomplish this. |
---|
76 | */ |
---|
77 | struct in_endpoints { |
---|
78 | u_int16_t ie_fport; /* foreign port */ |
---|
79 | u_int16_t ie_lport; /* local port */ |
---|
80 | /* protocol dependent part, local and foreign addr */ |
---|
81 | union { |
---|
82 | /* foreign host table entry */ |
---|
83 | struct in_addr_4in6 ie46_foreign; |
---|
84 | struct in6_addr ie6_foreign; |
---|
85 | } ie_dependfaddr; |
---|
86 | union { |
---|
87 | /* local host table entry */ |
---|
88 | struct in_addr_4in6 ie46_local; |
---|
89 | struct in6_addr ie6_local; |
---|
90 | } ie_dependladdr; |
---|
91 | }; |
---|
92 | #define ie_faddr ie_dependfaddr.ie46_foreign.ia46_addr4 |
---|
93 | #define ie_laddr ie_dependladdr.ie46_local.ia46_addr4 |
---|
94 | #define ie6_faddr ie_dependfaddr.ie6_foreign |
---|
95 | #define ie6_laddr ie_dependladdr.ie6_local |
---|
96 | |
---|
97 | /* |
---|
98 | * XXX The defines for inc_* are hacks and should be changed to direct |
---|
99 | * references. |
---|
100 | */ |
---|
101 | struct in_conninfo { |
---|
102 | u_int8_t inc_flags; |
---|
103 | u_int8_t inc_len; |
---|
104 | u_int16_t inc_fibnum; /* XXX was pad, 16 bits is plenty */ |
---|
105 | /* protocol dependent part */ |
---|
106 | struct in_endpoints inc_ie; |
---|
107 | }; |
---|
108 | |
---|
109 | /* |
---|
110 | * Flags for inc_flags. |
---|
111 | */ |
---|
112 | #define INC_ISIPV6 0x01 |
---|
113 | |
---|
114 | #define inc_isipv6 inc_flags /* temp compatability */ |
---|
115 | #define inc_fport inc_ie.ie_fport |
---|
116 | #define inc_lport inc_ie.ie_lport |
---|
117 | #define inc_faddr inc_ie.ie_faddr |
---|
118 | #define inc_laddr inc_ie.ie_laddr |
---|
119 | #define inc6_faddr inc_ie.ie6_faddr |
---|
120 | #define inc6_laddr inc_ie.ie6_laddr |
---|
121 | |
---|
122 | struct icmp6_filter; |
---|
123 | |
---|
124 | /*- |
---|
125 | * struct inpcb captures the network layer state for TCP, UDP, and raw IPv4 |
---|
126 | * and IPv6 sockets. In the case of TCP, further per-connection state is |
---|
127 | * hung off of inp_ppcb most of the time. Almost all fields of struct inpcb |
---|
128 | * are static after creation or protected by a per-inpcb rwlock, inp_lock. A |
---|
129 | * few fields also require the global pcbinfo lock for the inpcb to be held, |
---|
130 | * when modified, such as the global connection lists and hashes, as well as |
---|
131 | * binding information (which affects which hash a connection is on). This |
---|
132 | * model means that connections can be looked up without holding the |
---|
133 | * per-connection lock, which is important for performance when attempting to |
---|
134 | * find the connection for a packet given its IP and port tuple. Writing to |
---|
135 | * these fields that write locks be held on both the inpcb and global locks. |
---|
136 | * |
---|
137 | * Key: |
---|
138 | * (c) - Constant after initialization |
---|
139 | * (i) - Protected by the inpcb lock |
---|
140 | * (p) - Protected by the pcbinfo lock for the inpcb |
---|
141 | * (s) - Protected by another subsystem's locks |
---|
142 | * (x) - Undefined locking |
---|
143 | * |
---|
144 | * A few other notes: |
---|
145 | * |
---|
146 | * When a read lock is held, stability of the field is guaranteed; to write |
---|
147 | * to a field, a write lock must generally be held. |
---|
148 | * |
---|
149 | * netinet/netinet6-layer code should not assume that the inp_socket pointer |
---|
150 | * is safe to dereference without inp_lock being held, even for protocols |
---|
151 | * other than TCP (where the inpcb persists during TIMEWAIT even after the |
---|
152 | * socket has been freed), or there may be close(2)-related races. |
---|
153 | * |
---|
154 | * The inp_vflag field is overloaded, and would otherwise ideally be (c). |
---|
155 | */ |
---|
156 | struct inpcb { |
---|
157 | LIST_ENTRY(inpcb) inp_hash; /* (i/p) hash list */ |
---|
158 | LIST_ENTRY(inpcb) inp_list; /* (i/p) list for all PCBs for proto */ |
---|
159 | void *inp_ppcb; /* (i) pointer to per-protocol pcb */ |
---|
160 | struct inpcbinfo *inp_pcbinfo; /* (c) PCB list info */ |
---|
161 | struct socket *inp_socket; /* (i) back pointer to socket */ |
---|
162 | struct ucred *inp_cred; /* (c) cache of socket cred */ |
---|
163 | u_int32_t inp_flow; /* (i) IPv6 flow information */ |
---|
164 | int inp_flags; /* (i) generic IP/datagram flags */ |
---|
165 | int inp_flags2; /* (i) generic IP/datagram flags #2*/ |
---|
166 | u_char inp_vflag; /* (i) IP version flag (v4/v6) */ |
---|
167 | u_char inp_ip_ttl; /* (i) time to live proto */ |
---|
168 | u_char inp_ip_p; /* (c) protocol proto */ |
---|
169 | u_char inp_ip_minttl; /* (i) minimum TTL or drop */ |
---|
170 | uint32_t inp_flowid; /* (x) flow id / queue id */ |
---|
171 | u_int inp_refcount; /* (i) refcount */ |
---|
172 | void *inp_pspare[4]; /* (x) rtentry / general use */ |
---|
173 | u_int inp_ispare[4]; /* general use */ |
---|
174 | |
---|
175 | /* Local and foreign ports, local and foreign addr. */ |
---|
176 | struct in_conninfo inp_inc; /* (i/p) list for PCB's local port */ |
---|
177 | |
---|
178 | /* MAC and IPSEC policy information. */ |
---|
179 | struct label *inp_label; /* (i) MAC label */ |
---|
180 | struct inpcbpolicy *inp_sp; /* (s) for IPSEC */ |
---|
181 | |
---|
182 | /* Protocol-dependent part; options. */ |
---|
183 | struct { |
---|
184 | u_char inp4_ip_tos; /* (i) type of service proto */ |
---|
185 | struct mbuf *inp4_options; /* (i) IP options */ |
---|
186 | struct ip_moptions *inp4_moptions; /* (i) IP mcast options */ |
---|
187 | } inp_depend4; |
---|
188 | struct { |
---|
189 | /* (i) IP options */ |
---|
190 | struct mbuf *inp6_options; |
---|
191 | /* (i) IP6 options for outgoing packets */ |
---|
192 | struct ip6_pktopts *inp6_outputopts; |
---|
193 | /* (i) IP multicast options */ |
---|
194 | struct ip6_moptions *inp6_moptions; |
---|
195 | /* (i) ICMPv6 code type filter */ |
---|
196 | struct icmp6_filter *inp6_icmp6filt; |
---|
197 | /* (i) IPV6_CHECKSUM setsockopt */ |
---|
198 | int inp6_cksum; |
---|
199 | short inp6_hops; |
---|
200 | } inp_depend6; |
---|
201 | LIST_ENTRY(inpcb) inp_portlist; /* (i/p) */ |
---|
202 | struct inpcbport *inp_phd; /* (i/p) head of this list */ |
---|
203 | #define inp_zero_size offsetof(struct inpcb, inp_gencnt) |
---|
204 | inp_gen_t inp_gencnt; /* (c) generation count */ |
---|
205 | struct llentry *inp_lle; /* cached L2 information */ |
---|
206 | struct rtentry *inp_rt; /* cached L3 information */ |
---|
207 | struct rwlock inp_lock; |
---|
208 | }; |
---|
209 | #define inp_fport inp_inc.inc_fport |
---|
210 | #define inp_lport inp_inc.inc_lport |
---|
211 | #define inp_faddr inp_inc.inc_faddr |
---|
212 | #define inp_laddr inp_inc.inc_laddr |
---|
213 | #define inp_ip_tos inp_depend4.inp4_ip_tos |
---|
214 | #define inp_options inp_depend4.inp4_options |
---|
215 | #define inp_moptions inp_depend4.inp4_moptions |
---|
216 | |
---|
217 | #define in6p_faddr inp_inc.inc6_faddr |
---|
218 | #define in6p_laddr inp_inc.inc6_laddr |
---|
219 | #define in6p_hops inp_depend6.inp6_hops /* default hop limit */ |
---|
220 | #define in6p_flowinfo inp_flow |
---|
221 | #define in6p_options inp_depend6.inp6_options |
---|
222 | #define in6p_outputopts inp_depend6.inp6_outputopts |
---|
223 | #define in6p_moptions inp_depend6.inp6_moptions |
---|
224 | #define in6p_icmp6filt inp_depend6.inp6_icmp6filt |
---|
225 | #define in6p_cksum inp_depend6.inp6_cksum |
---|
226 | |
---|
227 | #define inp_vnet inp_pcbinfo->ipi_vnet |
---|
228 | |
---|
229 | /* |
---|
230 | * The range of the generation count, as used in this implementation, is 9e19. |
---|
231 | * We would have to create 300 billion connections per second for this number |
---|
232 | * to roll over in a year. This seems sufficiently unlikely that we simply |
---|
233 | * don't concern ourselves with that possibility. |
---|
234 | */ |
---|
235 | |
---|
236 | /* |
---|
237 | * Interface exported to userland by various protocols which use inpcbs. Hack |
---|
238 | * alert -- only define if struct xsocket is in scope. |
---|
239 | */ |
---|
240 | #ifdef _SYS_SOCKETVAR_H_ |
---|
241 | struct xinpcb { |
---|
242 | size_t xi_len; /* length of this structure */ |
---|
243 | struct inpcb xi_inp; |
---|
244 | struct xsocket xi_socket; |
---|
245 | u_quad_t xi_alignment_hack; |
---|
246 | }; |
---|
247 | |
---|
248 | struct xinpgen { |
---|
249 | size_t xig_len; /* length of this structure */ |
---|
250 | u_int xig_count; /* number of PCBs at this time */ |
---|
251 | inp_gen_t xig_gen; /* generation count at this time */ |
---|
252 | so_gen_t xig_sogen; /* socket generation count at this time */ |
---|
253 | }; |
---|
254 | #endif /* _SYS_SOCKETVAR_H_ */ |
---|
255 | |
---|
256 | struct inpcbport { |
---|
257 | LIST_ENTRY(inpcbport) phd_hash; |
---|
258 | struct inpcbhead phd_pcblist; |
---|
259 | u_short phd_port; |
---|
260 | }; |
---|
261 | |
---|
262 | /* |
---|
263 | * Global data structure for each high-level protocol (UDP, TCP, ...) in both |
---|
264 | * IPv4 and IPv6. Holds inpcb lists and information for managing them. |
---|
265 | */ |
---|
266 | struct inpcbinfo { |
---|
267 | /* |
---|
268 | * Global list of inpcbs on the protocol. |
---|
269 | */ |
---|
270 | struct inpcbhead *ipi_listhead; |
---|
271 | u_int ipi_count; |
---|
272 | |
---|
273 | /* |
---|
274 | * Global hash of inpcbs, hashed by local and foreign addresses and |
---|
275 | * port numbers. |
---|
276 | */ |
---|
277 | struct inpcbhead *ipi_hashbase; |
---|
278 | u_long ipi_hashmask; |
---|
279 | |
---|
280 | /* |
---|
281 | * Global hash of inpcbs, hashed by only local port number. |
---|
282 | */ |
---|
283 | struct inpcbporthead *ipi_porthashbase; |
---|
284 | u_long ipi_porthashmask; |
---|
285 | |
---|
286 | /* |
---|
287 | * Fields associated with port lookup and allocation. |
---|
288 | */ |
---|
289 | u_short ipi_lastport; |
---|
290 | u_short ipi_lastlow; |
---|
291 | u_short ipi_lasthi; |
---|
292 | |
---|
293 | /* |
---|
294 | * UMA zone from which inpcbs are allocated for this protocol. |
---|
295 | */ |
---|
296 | struct uma_zone *ipi_zone; |
---|
297 | |
---|
298 | /* |
---|
299 | * Generation count--incremented each time a connection is allocated |
---|
300 | * or freed. |
---|
301 | */ |
---|
302 | u_quad_t ipi_gencnt; |
---|
303 | struct rwlock ipi_lock; |
---|
304 | |
---|
305 | /* |
---|
306 | * Pointer to network stack instance |
---|
307 | */ |
---|
308 | struct vnet *ipi_vnet; |
---|
309 | |
---|
310 | /* |
---|
311 | * general use 2 |
---|
312 | */ |
---|
313 | void *ipi_pspare[2]; |
---|
314 | }; |
---|
315 | |
---|
316 | #define INP_LOCK_INIT(inp, d, t) \ |
---|
317 | rw_init_flags(&(inp)->inp_lock, (t), RW_RECURSE | RW_DUPOK) |
---|
318 | #define INP_LOCK_DESTROY(inp) rw_destroy(&(inp)->inp_lock) |
---|
319 | #define INP_RLOCK(inp) rw_rlock(&(inp)->inp_lock) |
---|
320 | #define INP_WLOCK(inp) rw_wlock(&(inp)->inp_lock) |
---|
321 | #define INP_TRY_RLOCK(inp) rw_try_rlock(&(inp)->inp_lock) |
---|
322 | #define INP_TRY_WLOCK(inp) rw_try_wlock(&(inp)->inp_lock) |
---|
323 | #define INP_RUNLOCK(inp) rw_runlock(&(inp)->inp_lock) |
---|
324 | #define INP_WUNLOCK(inp) rw_wunlock(&(inp)->inp_lock) |
---|
325 | #define INP_TRY_UPGRADE(inp) rw_try_upgrade(&(inp)->inp_lock) |
---|
326 | #define INP_DOWNGRADE(inp) rw_downgrade(&(inp)->inp_lock) |
---|
327 | #define INP_WLOCKED(inp) rw_wowned(&(inp)->inp_lock) |
---|
328 | #define INP_LOCK_ASSERT(inp) rw_assert(&(inp)->inp_lock, RA_LOCKED) |
---|
329 | #define INP_RLOCK_ASSERT(inp) rw_assert(&(inp)->inp_lock, RA_RLOCKED) |
---|
330 | #define INP_WLOCK_ASSERT(inp) rw_assert(&(inp)->inp_lock, RA_WLOCKED) |
---|
331 | #define INP_UNLOCK_ASSERT(inp) rw_assert(&(inp)->inp_lock, RA_UNLOCKED) |
---|
332 | |
---|
333 | #ifdef _KERNEL |
---|
334 | /* |
---|
335 | * These locking functions are for inpcb consumers outside of sys/netinet, |
---|
336 | * more specifically, they were added for the benefit of TOE drivers. The |
---|
337 | * macros are reserved for use by the stack. |
---|
338 | */ |
---|
339 | void inp_wlock(struct inpcb *); |
---|
340 | void inp_wunlock(struct inpcb *); |
---|
341 | void inp_rlock(struct inpcb *); |
---|
342 | void inp_runlock(struct inpcb *); |
---|
343 | |
---|
344 | #ifdef INVARIANTS |
---|
345 | void inp_lock_assert(struct inpcb *); |
---|
346 | void inp_unlock_assert(struct inpcb *); |
---|
347 | #else |
---|
348 | static __inline void |
---|
349 | inp_lock_assert(struct inpcb *inp __unused) |
---|
350 | { |
---|
351 | } |
---|
352 | |
---|
353 | static __inline void |
---|
354 | inp_unlock_assert(struct inpcb *inp __unused) |
---|
355 | { |
---|
356 | } |
---|
357 | |
---|
358 | #endif |
---|
359 | |
---|
360 | void inp_apply_all(void (*func)(struct inpcb *, void *), void *arg); |
---|
361 | int inp_ip_tos_get(const struct inpcb *inp); |
---|
362 | void inp_ip_tos_set(struct inpcb *inp, int val); |
---|
363 | struct socket * |
---|
364 | inp_inpcbtosocket(struct inpcb *inp); |
---|
365 | struct tcpcb * |
---|
366 | inp_inpcbtotcpcb(struct inpcb *inp); |
---|
367 | void inp_4tuple_get(struct inpcb *inp, uint32_t *laddr, uint16_t *lp, |
---|
368 | uint32_t *faddr, uint16_t *fp); |
---|
369 | |
---|
370 | #endif /* _KERNEL */ |
---|
371 | |
---|
372 | #define INP_INFO_LOCK_INIT(ipi, d) \ |
---|
373 | rw_init_flags(&(ipi)->ipi_lock, (d), RW_RECURSE) |
---|
374 | #define INP_INFO_LOCK_DESTROY(ipi) rw_destroy(&(ipi)->ipi_lock) |
---|
375 | #define INP_INFO_RLOCK(ipi) rw_rlock(&(ipi)->ipi_lock) |
---|
376 | #define INP_INFO_WLOCK(ipi) rw_wlock(&(ipi)->ipi_lock) |
---|
377 | #define INP_INFO_TRY_RLOCK(ipi) rw_try_rlock(&(ipi)->ipi_lock) |
---|
378 | #define INP_INFO_TRY_WLOCK(ipi) rw_try_wlock(&(ipi)->ipi_lock) |
---|
379 | #define INP_INFO_TRY_UPGRADE(ipi) rw_try_upgrade(&(ipi)->ipi_lock) |
---|
380 | #define INP_INFO_RUNLOCK(ipi) rw_runlock(&(ipi)->ipi_lock) |
---|
381 | #define INP_INFO_WUNLOCK(ipi) rw_wunlock(&(ipi)->ipi_lock) |
---|
382 | #define INP_INFO_LOCK_ASSERT(ipi) rw_assert(&(ipi)->ipi_lock, RA_LOCKED) |
---|
383 | #define INP_INFO_RLOCK_ASSERT(ipi) rw_assert(&(ipi)->ipi_lock, RA_RLOCKED) |
---|
384 | #define INP_INFO_WLOCK_ASSERT(ipi) rw_assert(&(ipi)->ipi_lock, RA_WLOCKED) |
---|
385 | #define INP_INFO_UNLOCK_ASSERT(ipi) rw_assert(&(ipi)->ipi_lock, RA_UNLOCKED) |
---|
386 | |
---|
387 | #define INP_PCBHASH(faddr, lport, fport, mask) \ |
---|
388 | (((faddr) ^ ((faddr) >> 16) ^ ntohs((lport) ^ (fport))) & (mask)) |
---|
389 | #define INP_PCBPORTHASH(lport, mask) \ |
---|
390 | (ntohs((lport)) & (mask)) |
---|
391 | |
---|
392 | /* |
---|
393 | * Flags for inp_vflags -- historically version flags only |
---|
394 | */ |
---|
395 | #define INP_IPV4 0x1 |
---|
396 | #define INP_IPV6 0x2 |
---|
397 | #define INP_IPV6PROTO 0x4 /* opened under IPv6 protocol */ |
---|
398 | |
---|
399 | /* |
---|
400 | * Flags for inp_flags. |
---|
401 | */ |
---|
402 | #define INP_RECVOPTS 0x00000001 /* receive incoming IP options */ |
---|
403 | #define INP_RECVRETOPTS 0x00000002 /* receive IP options for reply */ |
---|
404 | #define INP_RECVDSTADDR 0x00000004 /* receive IP dst address */ |
---|
405 | #define INP_HDRINCL 0x00000008 /* user supplies entire IP header */ |
---|
406 | #define INP_HIGHPORT 0x00000010 /* user wants "high" port binding */ |
---|
407 | #define INP_LOWPORT 0x00000020 /* user wants "low" port binding */ |
---|
408 | #define INP_ANONPORT 0x00000040 /* port chosen for user */ |
---|
409 | #define INP_RECVIF 0x00000080 /* receive incoming interface */ |
---|
410 | #define INP_MTUDISC 0x00000100 /* user can do MTU discovery */ |
---|
411 | #define INP_FAITH 0x00000200 /* accept FAITH'ed connections */ |
---|
412 | #define INP_RECVTTL 0x00000400 /* receive incoming IP TTL */ |
---|
413 | #define INP_DONTFRAG 0x00000800 /* don't fragment packet */ |
---|
414 | #define INP_BINDANY 0x00001000 /* allow bind to any address */ |
---|
415 | #define INP_INHASHLIST 0x00002000 /* in_pcbinshash() has been called */ |
---|
416 | #define IN6P_IPV6_V6ONLY 0x00008000 /* restrict AF_INET6 socket for v6 */ |
---|
417 | #define IN6P_PKTINFO 0x00010000 /* receive IP6 dst and I/F */ |
---|
418 | #define IN6P_HOPLIMIT 0x00020000 /* receive hoplimit */ |
---|
419 | #define IN6P_HOPOPTS 0x00040000 /* receive hop-by-hop options */ |
---|
420 | #define IN6P_DSTOPTS 0x00080000 /* receive dst options after rthdr */ |
---|
421 | #define IN6P_RTHDR 0x00100000 /* receive routing header */ |
---|
422 | #define IN6P_RTHDRDSTOPTS 0x00200000 /* receive dstoptions before rthdr */ |
---|
423 | #define IN6P_TCLASS 0x00400000 /* receive traffic class value */ |
---|
424 | #define IN6P_AUTOFLOWLABEL 0x00800000 /* attach flowlabel automatically */ |
---|
425 | #define INP_TIMEWAIT 0x01000000 /* in TIMEWAIT, ppcb is tcptw */ |
---|
426 | #define INP_ONESBCAST 0x02000000 /* send all-ones broadcast */ |
---|
427 | #define INP_DROPPED 0x04000000 /* protocol drop flag */ |
---|
428 | #define INP_SOCKREF 0x08000000 /* strong socket reference */ |
---|
429 | #define INP_SW_FLOWID 0x10000000 /* software generated flow id */ |
---|
430 | #define INP_HW_FLOWID 0x20000000 /* hardware generated flow id */ |
---|
431 | #define IN6P_RFC2292 0x40000000 /* used RFC2292 API on the socket */ |
---|
432 | #define IN6P_MTU 0x80000000 /* receive path MTU */ |
---|
433 | |
---|
434 | #define INP_CONTROLOPTS (INP_RECVOPTS|INP_RECVRETOPTS|INP_RECVDSTADDR|\ |
---|
435 | INP_RECVIF|INP_RECVTTL|\ |
---|
436 | IN6P_PKTINFO|IN6P_HOPLIMIT|IN6P_HOPOPTS|\ |
---|
437 | IN6P_DSTOPTS|IN6P_RTHDR|IN6P_RTHDRDSTOPTS|\ |
---|
438 | IN6P_TCLASS|IN6P_AUTOFLOWLABEL|IN6P_RFC2292|\ |
---|
439 | IN6P_MTU) |
---|
440 | |
---|
441 | /* |
---|
442 | * Flags for inp_flags2. |
---|
443 | */ |
---|
444 | #define INP_LLE_VALID 0x00000001 /* cached lle is valid */ |
---|
445 | #define INP_RT_VALID 0x00000002 /* cached rtentry is valid */ |
---|
446 | |
---|
447 | #define INPLOOKUP_WILDCARD 1 |
---|
448 | #define sotoinpcb(so) ((struct inpcb *)(so)->so_pcb) |
---|
449 | #define sotoin6pcb(so) sotoinpcb(so) /* for KAME src sync over BSD*'s */ |
---|
450 | |
---|
451 | #define INP_SOCKAF(so) so->so_proto->pr_domain->dom_family |
---|
452 | |
---|
453 | #define INP_CHECK_SOCKAF(so, af) (INP_SOCKAF(so) == af) |
---|
454 | |
---|
455 | #ifdef _KERNEL |
---|
456 | VNET_DECLARE(int, ipport_reservedhigh); |
---|
457 | VNET_DECLARE(int, ipport_reservedlow); |
---|
458 | VNET_DECLARE(int, ipport_lowfirstauto); |
---|
459 | VNET_DECLARE(int, ipport_lowlastauto); |
---|
460 | VNET_DECLARE(int, ipport_firstauto); |
---|
461 | VNET_DECLARE(int, ipport_lastauto); |
---|
462 | VNET_DECLARE(int, ipport_hifirstauto); |
---|
463 | VNET_DECLARE(int, ipport_hilastauto); |
---|
464 | VNET_DECLARE(int, ipport_randomized); |
---|
465 | VNET_DECLARE(int, ipport_randomcps); |
---|
466 | VNET_DECLARE(int, ipport_randomtime); |
---|
467 | VNET_DECLARE(int, ipport_stoprandom); |
---|
468 | VNET_DECLARE(int, ipport_tcpallocs); |
---|
469 | |
---|
470 | #define V_ipport_reservedhigh VNET(ipport_reservedhigh) |
---|
471 | #define V_ipport_reservedlow VNET(ipport_reservedlow) |
---|
472 | #define V_ipport_lowfirstauto VNET(ipport_lowfirstauto) |
---|
473 | #define V_ipport_lowlastauto VNET(ipport_lowlastauto) |
---|
474 | #define V_ipport_firstauto VNET(ipport_firstauto) |
---|
475 | #define V_ipport_lastauto VNET(ipport_lastauto) |
---|
476 | #define V_ipport_hifirstauto VNET(ipport_hifirstauto) |
---|
477 | #define V_ipport_hilastauto VNET(ipport_hilastauto) |
---|
478 | #define V_ipport_randomized VNET(ipport_randomized) |
---|
479 | #define V_ipport_randomcps VNET(ipport_randomcps) |
---|
480 | #define V_ipport_randomtime VNET(ipport_randomtime) |
---|
481 | #define V_ipport_stoprandom VNET(ipport_stoprandom) |
---|
482 | #define V_ipport_tcpallocs VNET(ipport_tcpallocs) |
---|
483 | |
---|
484 | extern struct callout ipport_tick_callout; |
---|
485 | |
---|
486 | void in_pcbpurgeif0(struct inpcbinfo *, struct ifnet *); |
---|
487 | int in_pcballoc(struct socket *, struct inpcbinfo *); |
---|
488 | int in_pcbbind(struct inpcb *, struct sockaddr *, struct ucred *); |
---|
489 | int in_pcbbind_setup(struct inpcb *, struct sockaddr *, in_addr_t *, |
---|
490 | u_short *, struct ucred *); |
---|
491 | int in_pcbconnect(struct inpcb *, struct sockaddr *, struct ucred *); |
---|
492 | int in_pcbconnect_setup(struct inpcb *, struct sockaddr *, in_addr_t *, |
---|
493 | u_short *, in_addr_t *, u_short *, struct inpcb **, |
---|
494 | struct ucred *); |
---|
495 | void in_pcbdetach(struct inpcb *); |
---|
496 | void in_pcbdisconnect(struct inpcb *); |
---|
497 | void in_pcbdrop(struct inpcb *); |
---|
498 | void in_pcbfree(struct inpcb *); |
---|
499 | int in_pcbinshash(struct inpcb *); |
---|
500 | struct inpcb * |
---|
501 | in_pcblookup_local(struct inpcbinfo *, |
---|
502 | struct in_addr, u_short, int, struct ucred *); |
---|
503 | struct inpcb * |
---|
504 | in_pcblookup_hash(struct inpcbinfo *, struct in_addr, u_int, |
---|
505 | struct in_addr, u_int, int, struct ifnet *); |
---|
506 | void in_pcbnotifyall(struct inpcbinfo *pcbinfo, struct in_addr, |
---|
507 | int, struct inpcb *(*)(struct inpcb *, int)); |
---|
508 | void in_pcbref(struct inpcb *); |
---|
509 | void in_pcbrehash(struct inpcb *); |
---|
510 | int in_pcbrele(struct inpcb *); |
---|
511 | void in_pcbsetsolabel(struct socket *so); |
---|
512 | int in_getpeeraddr(struct socket *so, struct sockaddr **nam); |
---|
513 | int in_getsockaddr(struct socket *so, struct sockaddr **nam); |
---|
514 | struct sockaddr * |
---|
515 | in_sockaddr(in_port_t port, struct in_addr *addr); |
---|
516 | void in_pcbsosetlabel(struct socket *so); |
---|
517 | void ipport_tick(void *xtp); |
---|
518 | #endif /* _KERNEL */ |
---|
519 | |
---|
520 | #endif /* !_NETINET_IN_PCB_H_ */ |
---|