xref: /netbsd/sys/netinet6/in6_pcb.h (revision bf9ec67e)
1 /*	$NetBSD: in6_pcb.h,v 1.19 2001/10/24 06:36:38 itojun Exp $	*/
2 /*	$KAME: in6_pcb.h,v 1.45 2001/02/09 05:59:46 itojun Exp $	*/
3 
4 /*
5  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. Neither the name of the project nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  */
32 
33 /*
34  * Copyright (c) 1982, 1986, 1990, 1993
35  *	The Regents of the University of California.  All rights reserved.
36  *
37  * Redistribution and use in source and binary forms, with or without
38  * modification, are permitted provided that the following conditions
39  * are met:
40  * 1. Redistributions of source code must retain the above copyright
41  *    notice, this list of conditions and the following disclaimer.
42  * 2. Redistributions in binary form must reproduce the above copyright
43  *    notice, this list of conditions and the following disclaimer in the
44  *    documentation and/or other materials provided with the distribution.
45  * 3. All advertising materials mentioning features or use of this software
46  *    must display the following acknowledgement:
47  *	This product includes software developed by the University of
48  *	California, Berkeley and its contributors.
49  * 4. Neither the name of the University nor the names of its contributors
50  *    may be used to endorse or promote products derived from this software
51  *    without specific prior written permission.
52  *
53  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
54  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
55  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
56  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
57  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
58  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
59  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63  * SUCH DAMAGE.
64  *
65  *	@(#)in_pcb.h	8.1 (Berkeley) 6/10/93
66  */
67 
68 #ifndef _NETINET6_IN6_PCB_H_
69 #define _NETINET6_IN6_PCB_H_
70 
71 #include <sys/queue.h>
72 
73 /*
74  * Common structure pcb for internet protocol implementation.
75  * Here are stored pointers to local and foreign host table
76  * entries, local and foreign socket numbers, and pointers
77  * up (to a socket structure) and down (to a protocol-specific)
78  * control block.
79  */
80 struct icmp6_filter;
81 struct inpcbpolicy;
82 
83 struct	in6pcb {
84 	struct	in6pcb *in6p_next, *in6p_prev;
85 					/* pointers to other pcb's */
86 	struct	in6pcb *in6p_head;	/* pointer back to chain of
87 					   in6pcb's for this protocol */
88 	struct	in6_addr in6p_faddr;	/* foreign host table entry */
89 	u_int16_t in6p_fport;		/* foreign port */
90 	struct	in6_addr in6p_laddr;	/* local host table entry */
91 	u_int16_t in6p_lport;		/* local port */
92 	u_int32_t in6p_flowinfo;	/* priority and flowlabel */
93 	struct	socket *in6p_socket;	/* back pointer to socket */
94 	caddr_t	in6p_ppcb;		/* pointer to per-protocol pcb */
95 	struct	route_in6 in6p_route;	/* placeholder for routing entry */
96 	int	in6p_flags;		/* generic IP6/datagram flags */
97 	int	in6p_hops;		/* default hop limit */
98 	struct	ip6_hdr in6p_ip6;	/* header prototype */
99 	struct	mbuf *in6p_options;   /* IP6 options */
100 	struct	ip6_pktopts *in6p_outputopts; /* IP6 options for outgoing packets */
101 	struct	ip6_moptions *in6p_moptions; /* IP6 multicast options */
102 	u_short	in6p_ifindex;
103 	/* should move the following just after next/prev */
104 	LIST_ENTRY(in6pcb) in6p_hlist;	/* hash chain */
105 	u_long	in6p_hash;		/* hash value */
106 #if 1 /* IPSEC */
107 	struct inpcbpolicy *in6p_sp;	/* security policy. */
108 #endif
109 	struct icmp6_filter *in6p_icmp6filt;
110 	int	in6p_cksum;		/* IPV6_CHECKSUM setsockopt */
111 };
112 
113 #ifdef _KERNEL
114 #define in6p_ip6_nxt in6p_ip6.ip6_nxt  /* for KAME src sync over BSD*'s */
115 #endif
116 
117 /*
118  * Flags in in6p_flags
119  * We define KAME's original flags in higher 16 bits as much as possible
120  * for compatibility with *bsd*s.
121  */
122 #define IN6P_RECVOPTS		0x001000 /* receive incoming IP6 options */
123 #define IN6P_RECVRETOPTS	0x002000 /* receive IP6 options for reply */
124 #define IN6P_RECVDSTADDR	0x004000 /* receive IP6 dst address */
125 #define IN6P_IPV6_V6ONLY	0x008000 /* restrict AF_INET6 socket for v6 */
126 #define IN6P_PKTINFO		0x010000 /* receive IP6 dst and I/F */
127 #define IN6P_HOPLIMIT		0x020000 /* receive hoplimit */
128 #define IN6P_HOPOPTS		0x040000 /* receive hop-by-hop options */
129 #define IN6P_DSTOPTS		0x080000 /* receive dst options after rthdr */
130 #define IN6P_RTHDR		0x100000 /* receive routing header */
131 #define IN6P_RTHDRDSTOPTS	0x200000 /* receive dstoptions before rthdr */
132 
133 #define IN6P_HIGHPORT		0x1000000 /* user wants "high" port binding */
134 #define IN6P_LOWPORT		0x2000000 /* user wants "low" port binding */
135 #define IN6P_ANONPORT		0x4000000 /* port chosen for user */
136 #define IN6P_FAITH		0x8000000 /* accept FAITH'ed connections */
137 #if 0 /* obsoleted */
138 #define IN6P_BINDV6ONLY		0x10000000 /* do not grab IPv4 traffic */
139 #endif
140 
141 #define IN6P_CONTROLOPTS	(IN6P_PKTINFO|IN6P_HOPLIMIT|IN6P_HOPOPTS|\
142 				 IN6P_DSTOPTS|IN6P_RTHDR|IN6P_RTHDRDSTOPTS)
143 
144 
145 #define IN6PLOOKUP_WILDCARD	1
146 #define IN6PLOOKUP_SETLOCAL	2
147 
148 /* compute hash value for foreign and local in6_addr and port */
149 #define IN6_HASH(faddr, fport, laddr, lport) 			\
150 	(((faddr)->s6_addr32[0] ^ (faddr)->s6_addr32[1] ^	\
151 	  (faddr)->s6_addr32[2] ^ (faddr)->s6_addr32[3] ^	\
152 	  (laddr)->s6_addr32[0] ^ (laddr)->s6_addr32[1] ^	\
153 	  (laddr)->s6_addr32[2] ^ (laddr)->s6_addr32[3])	\
154 	 + (fport) + (lport))
155 
156 #define sotoin6pcb(so)	((struct in6pcb *)(so)->so_pcb)
157 
158 #ifdef _KERNEL
159 void	in6_losing __P((struct in6pcb *));
160 int	in6_pcballoc __P((struct socket *, struct in6pcb *));
161 int	in6_pcbbind __P((struct in6pcb *, struct mbuf *, struct proc *));
162 int	in6_pcbconnect __P((struct in6pcb *, struct mbuf *));
163 void	in6_pcbdetach __P((struct in6pcb *));
164 void	in6_pcbdisconnect __P((struct in6pcb *));
165 struct	in6pcb *
166 	in6_pcblookup __P((struct in6pcb *,
167 			   struct in6_addr *, u_int, struct in6_addr *,
168 			   u_int, int));
169 int	in6_pcbnotify __P((struct in6pcb *, struct sockaddr *,
170 			   u_int, struct sockaddr *, u_int, int, void *,
171 			   void (*)(struct in6pcb *, int)));
172 void	in6_pcbpurgeif0 __P((struct in6pcb *, struct ifnet *));
173 void	in6_pcbpurgeif __P((struct in6pcb *, struct ifnet *));
174 void	in6_rtchange __P((struct in6pcb *, int));
175 void	in6_setpeeraddr __P((struct in6pcb *, struct mbuf *));
176 void	in6_setsockaddr __P((struct in6pcb *, struct mbuf *));
177 
178 /* in in6_src.c */
179 struct 	in6_addr *in6_selectsrc __P((struct sockaddr_in6 *,
180 				     struct ip6_pktopts *,
181 				     struct ip6_moptions *,
182 				     struct route_in6 *,
183 				     struct in6_addr *, int *));
184 int	in6_selecthlim __P((struct in6pcb *, struct ifnet *));
185 int	in6_pcbsetport __P((struct in6_addr *, struct in6pcb *));
186 
187 extern struct rtentry *
188 	in6_pcbrtentry __P((struct in6pcb *));
189 extern struct in6pcb *in6_pcblookup_connect __P((struct in6pcb *,
190 	struct in6_addr *, u_int, struct in6_addr *, u_int, int));
191 extern struct in6pcb *in6_pcblookup_bind __P((struct in6pcb *,
192 	struct in6_addr *, u_int, int));
193 #endif /* _KERNEL */
194 
195 #endif /* !_NETINET6_IN6_PCB_H_ */
196