Second major scheduler patch. This corrects interactive issues that were
[dragonfly.git] / sys / netinet / in_pcb.h
CommitLineData
984263bc 1/*
a00f5de5 2 * Copyright (c) 2004 Jeffrey Hsu. All rights reserved.
984263bc
MD
3 * Copyright (c) 1982, 1986, 1990, 1993
4 * The Regents of the University of California. 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 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by the University of
17 * California, Berkeley and its contributors.
18 * 4. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * @(#)in_pcb.h 8.1 (Berkeley) 6/10/93
35 * $FreeBSD: src/sys/netinet/in_pcb.h,v 1.32.2.7 2003/01/24 05:11:34 sam Exp $
a00f5de5 36 * $DragonFly: src/sys/netinet/in_pcb.h,v 1.8 2004/03/06 05:00:41 hsu Exp $
984263bc
MD
37 */
38
39#ifndef _NETINET_IN_PCB_H_
40#define _NETINET_IN_PCB_H_
41
42#include <sys/queue.h>
43
44#include <net/route.h>
45
46#define in6pcb inpcb /* for KAME src sync over BSD*'s */
47#define in6p_sp inp_sp /* for KAME src sync over BSD*'s */
48struct inpcbpolicy;
49
50/*
51 * Common structure pcb for internet protocol implementation.
52 * Here are stored pointers to local and foreign host table
53 * entries, local and foreign socket numbers, and pointers
54 * up (to a socket structure) and down (to a protocol-specific)
55 * control block.
56 */
57LIST_HEAD(inpcbhead, inpcb);
58LIST_HEAD(inpcbporthead, inpcbport);
59typedef u_quad_t inp_gen_t;
60
61/*
62 * PCB with AF_INET6 null bind'ed laddr can receive AF_INET input packet.
63 * So, AF_INET6 null laddr is also used as AF_INET null laddr,
64 * by utilize following structure. (At last, same as INRIA)
65 */
66struct in_addr_4in6 {
67 u_int32_t ia46_pad32[3];
68 struct in_addr ia46_addr4;
69};
70
71/*
72 * NOTE: ipv6 addrs should be 64-bit aligned, per RFC 2553.
73 * in_conninfo has some extra padding to accomplish this.
74 */
75struct in_endpoints {
76 u_int16_t ie_fport; /* foreign port */
77 u_int16_t ie_lport; /* local port */
78 /* protocol dependent part, local and foreign addr */
79 union {
80 /* foreign host table entry */
81 struct in_addr_4in6 ie46_foreign;
82 struct in6_addr ie6_foreign;
83 } ie_dependfaddr;
84 union {
85 /* local host table entry */
86 struct in_addr_4in6 ie46_local;
87 struct in6_addr ie6_local;
88 } ie_dependladdr;
89#define ie_faddr ie_dependfaddr.ie46_foreign.ia46_addr4
90#define ie_laddr ie_dependladdr.ie46_local.ia46_addr4
91#define ie6_faddr ie_dependfaddr.ie6_foreign
92#define ie6_laddr ie_dependladdr.ie6_local
93};
94
95/*
96 * XXX
97 * At some point struct route should possibly change to:
98 * struct rtentry *rt
99 * struct in_endpoints *ie;
100 */
101struct in_conninfo {
102 u_int8_t inc_flags;
103 u_int8_t inc_len;
104 u_int16_t inc_pad; /* XXX alignment for in_endpoints */
105 /* protocol dependent part; cached route */
106 struct in_endpoints inc_ie;
107 union {
108 /* placeholder for routing entry */
109 struct route inc4_route;
110 struct route_in6 inc6_route;
111 } inc_dependroute;
112};
9a7c6212 113#define inc_isipv6 inc_flags /* temp compatibility */
984263bc
MD
114#define inc_fport inc_ie.ie_fport
115#define inc_lport inc_ie.ie_lport
116#define inc_faddr inc_ie.ie_faddr
117#define inc_laddr inc_ie.ie_laddr
118#define inc_route inc_dependroute.inc4_route
119#define inc6_faddr inc_ie.ie6_faddr
120#define inc6_laddr inc_ie.ie6_laddr
121#define inc6_route inc_dependroute.inc6_route
122
123/*
124 * NB: the zone allocator is type-stable EXCEPT FOR THE FIRST TWO LONGS
125 * of the structure. Therefore, it is important that the members in
126 * that position not contain any information which is required to be
127 * stable.
128 */
129struct icmp6_filter;
130
131struct inpcb {
132 LIST_ENTRY(inpcb) inp_hash; /* hash list */
133 LIST_ENTRY(inpcb) inp_list; /* list for all PCBs of this proto */
134 u_int32_t inp_flow;
135
136 /* local and foreign ports, local and foreign addr */
137 struct in_conninfo inp_inc;
138
139 caddr_t inp_ppcb; /* pointer to per-protocol pcb */
140 struct inpcbinfo *inp_pcbinfo; /* PCB list info */
141 struct socket *inp_socket; /* back pointer to socket */
142 /* list for this PCB's local port */
143 int inp_flags; /* generic IP/datagram flags */
144
145 struct inpcbpolicy *inp_sp; /* for IPSEC */
146 u_char inp_vflag;
147#define INP_IPV4 0x1
148#define INP_IPV6 0x2
149 u_char inp_ip_ttl; /* time to live proto */
150 u_char inp_ip_p; /* protocol proto */
151
152 /* protocol dependent part; options */
153 struct {
154 u_char inp4_ip_tos; /* type of service proto */
155 struct mbuf *inp4_options; /* IP options */
156 struct ip_moptions *inp4_moptions; /* IP multicast options */
157 } inp_depend4;
158#define inp_fport inp_inc.inc_fport
159#define inp_lport inp_inc.inc_lport
160#define inp_faddr inp_inc.inc_faddr
161#define inp_laddr inp_inc.inc_laddr
162#define inp_route inp_inc.inc_route
163#define inp_ip_tos inp_depend4.inp4_ip_tos
164#define inp_options inp_depend4.inp4_options
165#define inp_moptions inp_depend4.inp4_moptions
166 struct {
167 /* IP options */
168 struct mbuf *inp6_options;
169 /* IP6 options for outgoing packets */
170 struct ip6_pktopts *inp6_outputopts;
171 /* IP multicast options */
172 struct ip6_moptions *inp6_moptions;
173 /* ICMPv6 code type filter */
174 struct icmp6_filter *inp6_icmp6filt;
175 /* IPV6_CHECKSUM setsockopt */
176 int inp6_cksum;
177 u_short inp6_ifindex;
178 short inp6_hops;
179 u_int8_t inp6_hlim;
180 } inp_depend6;
181 LIST_ENTRY(inpcb) inp_portlist;
182 struct inpcbport *inp_phd; /* head of this list */
183 inp_gen_t inp_gencnt; /* generation count of this instance */
184#define in6p_faddr inp_inc.inc6_faddr
185#define in6p_laddr inp_inc.inc6_laddr
186#define in6p_route inp_inc.inc6_route
187#define in6p_ip6_hlim inp_depend6.inp6_hlim
188#define in6p_hops inp_depend6.inp6_hops /* default hop limit */
189#define in6p_ip6_nxt inp_ip_p
190#define in6p_flowinfo inp_flow
191#define in6p_vflag inp_vflag
192#define in6p_options inp_depend6.inp6_options
193#define in6p_outputopts inp_depend6.inp6_outputopts
194#define in6p_moptions inp_depend6.inp6_moptions
195#define in6p_icmp6filt inp_depend6.inp6_icmp6filt
196#define in6p_cksum inp_depend6.inp6_cksum
197#define inp6_ifindex inp_depend6.inp6_ifindex
198#define in6p_flags inp_flags /* for KAME src sync over BSD*'s */
199#define in6p_socket inp_socket /* for KAME src sync over BSD*'s */
200#define in6p_lport inp_lport /* for KAME src sync over BSD*'s */
201#define in6p_fport inp_fport /* for KAME src sync over BSD*'s */
202#define in6p_ppcb inp_ppcb /* for KAME src sync over BSD*'s */
203};
204/*
205 * The range of the generation count, as used in this implementation,
206 * is 9e19. We would have to create 300 billion connections per
207 * second for this number to roll over in a year. This seems sufficiently
208 * unlikely that we simply don't concern ourselves with that possibility.
209 */
210
211/*
212 * Interface exported to userland by various protocols which use
213 * inpcbs. Hack alert -- only define if struct xsocket is in scope.
214 */
215#ifdef _SYS_SOCKETVAR_H_
216struct xinpcb {
217 size_t xi_len; /* length of this structure */
218 struct inpcb xi_inp;
219 struct xsocket xi_socket;
220 u_quad_t xi_alignment_hack;
221};
222
223struct xinpgen {
224 size_t xig_len; /* length of this structure */
225 u_int xig_count; /* number of PCBs at this time */
226 inp_gen_t xig_gen; /* generation count at this time */
227 so_gen_t xig_sogen; /* socket generation count at this time */
228};
229#endif /* _SYS_SOCKETVAR_H_ */
230
231struct inpcbport {
232 LIST_ENTRY(inpcbport) phd_hash;
233 struct inpcbhead phd_pcblist;
234 u_short phd_port;
235};
236
237struct inpcbinfo { /* XXX documentation, prefixes */
238 struct inpcbhead *hashbase;
239 u_long hashmask;
240 struct inpcbporthead *porthashbase;
241 u_long porthashmask;
13d8907a
JH
242 struct inpcbhead *bindhashbase;
243 u_long bindhashmask;
a00f5de5 244 struct inpcbhead listhead; /* head of queue of active pcb's */
984263bc
MD
245 u_short lastport;
246 u_short lastlow;
247 u_short lasthi;
248 struct vm_zone *ipi_zone; /* zone to allocate pcbs from */
249 u_int ipi_count; /* number of pcbs in this list */
250 u_quad_t ipi_gencnt; /* current generation count */
251};
252
13d8907a
JH
253
254#define INP_PCBCONNHASH(faddr, fport, laddr, lport, mask) \
255 (((faddr) ^ ((faddr) >> 16) ^ (laddr) ^ ntohs((lport) ^ (fport))) & (mask))
256
257#define INP_PCBPORTHASH(lport, mask) (ntohs(lport) & (mask))
258
259#define INP_PCBBINDHASH(lport, mask) (ntohs(lport) & (mask))
984263bc
MD
260
261/* flags in inp_flags: */
262#define INP_RECVOPTS 0x01 /* receive incoming IP options */
263#define INP_RECVRETOPTS 0x02 /* receive IP options for reply */
264#define INP_RECVDSTADDR 0x04 /* receive IP dst address */
265#define INP_HDRINCL 0x08 /* user supplies entire IP header */
266#define INP_HIGHPORT 0x10 /* user wants "high" port binding */
267#define INP_LOWPORT 0x20 /* user wants "low" port binding */
268#define INP_ANONPORT 0x40 /* port chosen for user */
269#define INP_RECVIF 0x80 /* receive incoming interface */
270#define INP_MTUDISC 0x100 /* user can do MTU discovery */
271#define INP_FAITH 0x200 /* accept FAITH'ed connections */
13d8907a
JH
272#define INP_BOUND 0x400
273#define INP_CONNECTED 0x800
984263bc
MD
274
275#define IN6P_IPV6_V6ONLY 0x008000 /* restrict AF_INET6 socket for v6 */
276
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
285#define INP_CONTROLOPTS (INP_RECVOPTS|INP_RECVRETOPTS|INP_RECVDSTADDR|\
286 INP_RECVIF|\
287 IN6P_PKTINFO|IN6P_HOPLIMIT|IN6P_HOPOPTS|\
288 IN6P_DSTOPTS|IN6P_RTHDR|IN6P_RTHDRDSTOPTS|\
289 IN6P_AUTOFLOWLABEL)
290#define INP_UNMAPPABLEOPTS (IN6P_HOPOPTS|IN6P_DSTOPTS|IN6P_RTHDR|\
291 IN6P_AUTOFLOWLABEL)
292
293 /* for KAME src sync over BSD*'s */
294#define IN6P_HIGHPORT INP_HIGHPORT
295#define IN6P_LOWPORT INP_LOWPORT
296#define IN6P_ANONPORT INP_ANONPORT
297#define IN6P_RECVIF INP_RECVIF
298#define IN6P_MTUDISC INP_MTUDISC
299#define IN6P_FAITH INP_FAITH
300#define IN6P_CONTROLOPTS INP_CONTROLOPTS
301 /*
302 * socket AF version is {newer than,or include}
303 * actual datagram AF version
304 */
305
306#define INPLOOKUP_WILDCARD 1
307#define sotoinpcb(so) ((struct inpcb *)(so)->so_pcb)
308#define sotoin6pcb(so) sotoinpcb(so) /* for KAME src sync over BSD*'s */
309
310#define INP_SOCKAF(so) so->so_proto->pr_domain->dom_family
311
312#define INP_CHECK_SOCKAF(so, af) (INP_SOCKAF(so) == af)
313
314#ifdef _KERNEL
315extern int ipport_lowfirstauto;
316extern int ipport_lowlastauto;
317extern int ipport_firstauto;
318extern int ipport_lastauto;
319extern int ipport_hifirstauto;
320extern int ipport_hilastauto;
321
42a7fc75
RG
322void in_pcbpurgeif0 (struct inpcb *, struct ifnet *);
323void in_losing (struct inpcb *);
324void in_rtchange (struct inpcb *, int);
e4700d00 325int in_pcballoc (struct socket *, struct inpcbinfo *);
42a7fc75
RG
326int in_pcbbind (struct inpcb *, struct sockaddr *, struct thread *);
327int in_pcbconnect (struct inpcb *, struct sockaddr *, struct thread *);
328void in_pcbdetach (struct inpcb *);
329void in_pcbdisconnect (struct inpcb *);
13d8907a
JH
330void in_pcbinsbindhash(struct inpcb *inp);
331void in_pcbinsconnhash(struct inpcb *inp);
332int in_pcbinsporthash (struct inpcb *);
42a7fc75
RG
333int in_pcbladdr (struct inpcb *, struct sockaddr *,
334 struct sockaddr_in **);
984263bc 335struct inpcb *
42a7fc75
RG
336 in_pcblookup_local (struct inpcbinfo *,
337 struct in_addr, u_int, int);
984263bc 338struct inpcb *
42a7fc75 339 in_pcblookup_hash (struct inpcbinfo *,
984263bc 340 struct in_addr, u_int, struct in_addr, u_int,
42a7fc75
RG
341 int, struct ifnet *);
342void in_pcbnotifyall (struct inpcbhead *, struct in_addr,
343 int, void (*)(struct inpcb *, int));
13d8907a 344void in_pcbrehash(struct inpcb *, int);
42a7fc75
RG
345int in_setpeeraddr (struct socket *so, struct sockaddr **nam);
346int in_setsockaddr (struct socket *so, struct sockaddr **nam);
13d8907a
JH
347void in_pcbrembindhash(struct inpcb *inp);
348void in_pcbremconnhash(struct inpcb *inp);
42a7fc75
RG
349void in_pcbremlists (struct inpcb *inp);
350int prison_xinpcb (struct thread *p, struct inpcb *inp);
984263bc
MD
351#endif /* _KERNEL */
352
353#endif /* !_NETINET_IN_PCB_H_ */