xref: /netbsd-src/sys/netinet6/ip6_var.h (revision bdc22b2e01993381dcefeff2bc9b56ca75a4235c)
1 /*	$NetBSD: ip6_var.h,v 1.80 2018/02/14 05:29:39 maxv Exp $	*/
2 /*	$KAME: ip6_var.h,v 1.33 2000/06/11 14:59:20 jinmei 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, 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. Neither the name of the University nor the names of its contributors
46  *    may be used to endorse or promote products derived from this software
47  *    without specific prior written permission.
48  *
49  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
50  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
53  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59  * SUCH DAMAGE.
60  *
61  *	@(#)ip_var.h	8.1 (Berkeley) 6/10/93
62  */
63 
64 #ifndef _NETINET6_IP6_VAR_H_
65 #define _NETINET6_IP6_VAR_H_
66 
67 #include <sys/socketvar.h>
68 #include <net/route.h>
69 
70 struct	ip6_moptions {
71 	if_index_t im6o_multicast_if_index; /* I/F for outgoing multicasts */
72 	u_char	im6o_multicast_hlim;	/* hoplimit for outgoing multicasts */
73 	u_char	im6o_multicast_loop;	/* 1 >= hear sends if a member */
74 	LIST_HEAD(, in6_multi_mship) im6o_memberships;
75 };
76 
77 /*
78  * Control options for outgoing packets
79  */
80 
81 /* Routing header related info */
82 struct	ip6po_rhinfo {
83 	struct	ip6_rthdr *ip6po_rhi_rthdr; /* Routing header */
84 	struct	route ip6po_rhi_route; /* Route to the 1st hop */
85 };
86 #define ip6po_rthdr	ip6po_rhinfo.ip6po_rhi_rthdr
87 #define ip6po_route	ip6po_rhinfo.ip6po_rhi_route
88 
89 /* Nexthop related info */
90 struct	ip6po_nhinfo {
91 	struct	sockaddr *ip6po_nhi_nexthop;
92 	struct	route ip6po_nhi_route; /* Route to the nexthop */
93 };
94 #define ip6po_nexthop	ip6po_nhinfo.ip6po_nhi_nexthop
95 #define ip6po_nextroute	ip6po_nhinfo.ip6po_nhi_route
96 
97 struct	ip6_pktopts {
98 	int	ip6po_hlim;		/* Hoplimit for outgoing packets */
99 	struct	in6_pktinfo *ip6po_pktinfo; /* Outgoing IF/address information */
100 	struct	ip6po_nhinfo ip6po_nhinfo; /* Next-hop address information */
101 	struct	ip6_hbh *ip6po_hbh; /* Hop-by-Hop options header */
102 	struct	ip6_dest *ip6po_dest1; /* Destination options header(1st part) */
103 	struct	ip6po_rhinfo ip6po_rhinfo; /* Routing header related info. */
104 	struct	ip6_dest *ip6po_dest2; /* Destination options header(2nd part) */
105 	int	ip6po_tclass;	/* traffic class */
106 	int	ip6po_minmtu;  /* fragment vs PMTU discovery policy */
107 #define IP6PO_MINMTU_MCASTONLY	-1 /* default; send at min MTU for multicast*/
108 #define IP6PO_MINMTU_DISABLE	 0 /* always perform pmtu disc */
109 #define IP6PO_MINMTU_ALL	 1 /* always send at min MTU */
110 	int	ip6po_prefer_tempaddr;	/* whether temporary addresses are
111 					 * preferred as source address */
112 #define IP6PO_TEMPADDR_SYSTEM	-1 /* follow the system default */
113 #define IP6PO_TEMPADDR_NOTPREFER 0 /* not prefer temporary address */
114 #define IP6PO_TEMPADDR_PREFER	 1 /* prefer temporary address */
115 	int ip6po_flags;
116 #if 0	/* parameters in this block is obsolete. do not reuse the values. */
117 #define IP6PO_REACHCONF	0x01	/* upper-layer reachability confirmation. */
118 #define IP6PO_MINMTU	0x02	/* use minimum MTU (IPV6_USE_MIN_MTU) */
119 #endif
120 #define IP6PO_DONTFRAG	0x04	/* disable fragmentation (IPV6_DONTFRAG) */
121 };
122 
123 /*
124  * IPv6 statistics.
125  * Each counter is an unsigned 64-bit value.
126  */
127 #define	IP6_STAT_TOTAL		0	/* total packets received */
128 #define	IP6_STAT_TOOSHORT	1	/* packet too short */
129 #define	IP6_STAT_TOOSMALL	2	/* not enough data */
130 #define	IP6_STAT_FRAGMENTS	3	/* fragments received */
131 #define	IP6_STAT_FRAGDROPPED	4	/* frags dropped (dups, out of space) */
132 #define	IP6_STAT_FRAGTIMEOUT	5	/* fragments timed out */
133 #define	IP6_STAT_FRAGOVERFLOW	6	/* fragments that exceed limit */
134 #define IP6_STAT_FORWARD	7	/* packets forwarded */
135 #define	IP6_STAT_CANTFORWARD	8	/* packets rcvd for uncreachable dst */
136 #define	IP6_STAT_REDIRECTSENT	9	/* packets forwarded on same net */
137 #define	IP6_STAT_DELIVERED	10	/* datagrams delivered to upper level */
138 #define	IP6_STAT_LOCALOUT	11	/* total IP packets generated here */
139 #define	IP6_STAT_ODROPPED	12	/* lost packets due to nobufs, etc. */
140 #define	IP6_STAT_REASSEMBLED	13	/* total packets reassembled ok */
141 #define	IP6_STAT_FRAGMENTED	14	/* datagrams successfully fragmented */
142 #define	IP6_STAT_OFRAGMENTS	15	/* output fragments created */
143 #define	IP6_STAT_CANTFRAG	16	/* don't fragment flag was set, etc. */
144 #define	IP6_STAT_BADOPTIONS	17	/* error in option processing */
145 #define	IP6_STAT_NOROUTE	18	/* packets discarded due to no route */
146 #define	IP6_STAT_BADVERS	19	/* ip6 version != 6 */
147 #define	IP6_STAT_RAWOUT		20	/* total raw ip packets generated */
148 #define	IP6_STAT_BADSCOPE	21	/* scope error */
149 #define	IP6_STAT_NOTMEMBER	22	/* don't join this multicast group */
150 #define	IP6_STAT_NXTHIST	23	/* next header histogram */
151 		/* space for 256 counters */
152 #define	IP6_STAT_M1		279	/* one mbuf */
153 #define	IP6_STAT_M2M		280	/* two or more mbuf */
154 		/* space for 32 counters */
155 #define	IP6_STAT_MEXT1		312	/* one ext mbuf */
156 #define	IP6_STAT_MEXT2M		313	/* two or more ext mbuf */
157 #define	IP6_STAT_EXTHDRTOOLONG	314	/* ext hdr are not contiguous */
158 #define	IP6_STAT_NOGIF		315	/* no match gif found */
159 #define	IP6_STAT_TOOMANYHDR	316	/* discarded due to too many headers */
160 	/*
161 	 * statistics for improvement of the source address selection
162 	 * algorithm:
163 	 * XXX: hardcoded 16 = # of ip6 multicast scope types + 1
164 	 */
165 #define	IP6_STAT_SOURCES_NONE	317	/* number of times that address
166 					   selection fails */
167 #define	IP6_STAT_SOURCES_SAMEIF	318	/* number of times that an address
168 					   on the outgoing I/F is chosen */
169 		/* space for 16 counters */
170 #define	IP6_STAT_SOURCES_OTHERIF 334	/* number of times that an address on
171 					   a non-outgoing I/F is chosen */
172 		/* space for 16 counters */
173 #define	IP6_STAT_SOURCES_SAMESCOPE 350	/* number of times that an address that
174 					   has the same scope from the dest.
175 					   is chosen */
176 		/* space for 16 counters */
177 #define	IP6_STAT_SOURCES_OTHERSCOPE 366	/* number of times that an address that
178 					   has a different scope from the dest.
179 					   is chosen */
180 		/* space for 16 counters */
181 #define	IP6_STAT_SOURCES_DEPRECATED 382	/* number of times that a deprecated
182 					   address is chosen */
183 		/* space for 16 counters */
184 #define	IP6_STAT_FORWARD_CACHEHIT 398
185 #define	IP6_STAT_FORWARD_CACHEMISS 399
186 #define	IP6_STAT_FASTFORWARD	400	/* packets fast forwarded */
187 #define	IP6_STAT_FASTFORWARDFLOWS 401	/* number of fast forward flows */
188 #define	IP6_STAT_NOIPSEC	402	/* no match ipsec(4) found */
189 
190 #define	IP6_NSTATS		403
191 
192 #define IP6FLOW_HASHBITS         6 /* should not be a multiple of 8 */
193 
194 /*
195  * Structure for an IPv6 flow (ip6_fastforward).
196  */
197 struct ip6flow {
198 	TAILQ_ENTRY(ip6flow) ip6f_list;  /* next in active list */
199 	TAILQ_ENTRY(ip6flow) ip6f_hash;  /* next ip6flow in bucket */
200 	size_t ip6f_hashidx;             /* own hash index of ipflowtable[] */
201 	struct in6_addr ip6f_dst;       /* destination address */
202 	struct in6_addr ip6f_src;       /* source address */
203 	struct route ip6f_ro;       /* associated route entry */
204 	u_int32_t ip6f_flow;		/* flow (tos) */
205 	u_quad_t ip6f_uses;               /* number of uses in this period */
206 	u_quad_t ip6f_last_uses;          /* number of uses in last period */
207 	u_quad_t ip6f_dropped;            /* ENOBUFS returned by if_output */
208 	u_quad_t ip6f_forwarded;          /* packets forwarded */
209 	u_int ip6f_timer;               /* lifetime timer */
210 };
211 
212 #ifdef _KERNEL
213 /*
214  * Auxiliary attributes of incoming IPv6 packets, which is initialized when we
215  * come into ip6_input().
216  * XXX do not make it a kitchen sink!
217  */
218 struct ip6aux {
219 	/* ip6.ip6_dst */
220 	struct in6_addr	ip6a_src;
221 	uint32_t	ip6a_scope_id;
222 	int		ip6a_flags;
223 };
224 
225 /* flags passed to ip6_output as last parameter */
226 #define	IPV6_UNSPECSRC		0x01	/* allow :: as the source address */
227 #define	IPV6_FORWARDING		0x02	/* most of IPv6 header exists */
228 #define	IPV6_MINMTU		0x04	/* use minimum MTU (IPV6_USE_MIN_MTU) */
229 
230 extern u_int32_t ip6_id;		/* fragment identifier */
231 extern int	ip6_defhlim;		/* default hop limit */
232 extern int	ip6_defmcasthlim;	/* default multicast hop limit */
233 extern int	ip6_forwarding;		/* act as router? */
234 extern int	ip6_sendredirect;	/* send ICMPv6 redirect? */
235 extern int	ip6_use_deprecated;	/* allow deprecated addr as source */
236 extern int	ip6_rr_prune;		/* router renumbering prefix
237 					 * walk list every 5 sec.    */
238 extern int	ip6_mcast_pmtu;		/* enable pMTU discovery for multicast? */
239 extern int	ip6_v6only;
240 extern int	ip6_neighborgcthresh;	/* Threshold # of NDP entries for GC */
241 extern int	ip6_maxifprefixes; /* Max acceptable prefixes via RA per IF */
242 extern int	ip6_maxifdefrouters;	/* Max acceptable def routers via RA */
243 extern int	ip6_maxdynroutes; /* Max # of routes created via redirect */
244 
245 
246 extern struct socket *ip6_mrouter; 	/* multicast routing daemon */
247 extern int	ip6_sendredirects;	/* send IP redirects when forwarding? */
248 extern int	ip6_maxfragpackets; /* Maximum packets in reassembly queue */
249 extern int	ip6_maxfrags;	/* Maximum fragments in reassembly queue */
250 extern int	ip6_accept_rtadv;	/* Acts as a host not a router */
251 extern int	ip6_rtadv_maxroutes;	/* maximum number of routes via rtadv */
252 extern int	ip6_keepfaith;		/* Firewall Aided Internet Translator */
253 extern int	ip6_log_interval;
254 extern time_t	ip6_log_time;
255 extern int	ip6_hdrnestlimit; /* upper limit of # of extension headers */
256 extern int	ip6_dad_count;		/* DupAddrDetectionTransmits */
257 
258 extern int ip6_auto_flowlabel;
259 extern int ip6_auto_linklocal;
260 
261 extern int   ip6_anonportmin;		/* minimum ephemeral port */
262 extern int   ip6_anonportmax;		/* maximum ephemeral port */
263 extern int   ip6_lowportmin;		/* minimum reserved port */
264 extern int   ip6_lowportmax;		/* maximum reserved port */
265 
266 extern int	ip6_use_tempaddr; /* whether to use temporary addresses. */
267 extern int	ip6_prefer_tempaddr; /* whether to prefer temporary addresses
268 					in the source address selection */
269 extern int	ip6_use_defzone; /* whether to use the default scope zone
270 				    when unspecified */
271 
272 #ifdef GATEWAY
273 extern int      ip6_maxflows;           /* maximum amount of flows for ip6ff */
274 extern int	ip6_hashsize;		/* size of hash table */
275 #endif
276 
277 struct in6pcb;
278 extern const struct pr_usrreqs rip6_usrreqs;
279 
280 int	icmp6_ctloutput(int, struct socket *, struct sockopt *);
281 
282 struct mbuf;
283 void	ip6_init(void);
284 void	ip6_input(struct mbuf *, struct ifnet *);
285 const struct ip6aux *ip6_getdstifaddr(struct mbuf *);
286 void	ip6_freepcbopts(struct ip6_pktopts *);
287 void	ip6_freemoptions(struct ip6_moptions *);
288 int	ip6_unknown_opt(u_int8_t *, struct mbuf *, int);
289 int	ip6_get_prevhdr(struct mbuf *, int);
290 int	ip6_nexthdr(struct mbuf *, int, int, int *);
291 int	ip6_lasthdr(struct mbuf *, int, int, int *);
292 
293 struct m_tag *ip6_addaux(struct mbuf *);
294 struct m_tag *ip6_findaux(struct mbuf *);
295 void	ip6_delaux(struct mbuf *);
296 struct ip6_hdr;
297 int	ip6_mforward(struct ip6_hdr *, struct ifnet *, struct mbuf *);
298 int	ip6_hopopts_input(u_int32_t *, u_int32_t *, struct mbuf **, int *);
299 void	ip6_savecontrol(struct in6pcb *, struct mbuf **, struct ip6_hdr *,
300 		struct mbuf *);
301 void	ip6_notify_pmtu(struct in6pcb *, const struct sockaddr_in6 *,
302 		u_int32_t *);
303 int	ip6_sysctl(int *, u_int, void *, size_t *, void *, size_t);
304 
305 void	ip6_forward(struct mbuf *, int);
306 
307 void	ip6_mloopback(struct ifnet *, struct mbuf *,
308 	              const struct sockaddr_in6 *);
309 int	ip6_output(struct mbuf *, struct ip6_pktopts *, struct route *, int,
310 	    struct ip6_moptions *, struct in6pcb *, struct ifnet **);
311 int	ip6_if_output(struct ifnet * const, struct ifnet * const,
312 	    struct mbuf * const,
313 	    const struct sockaddr_in6 * const, const struct rtentry *);
314 int	ip6_ctloutput(int, struct socket *, struct sockopt *);
315 int	ip6_raw_ctloutput(int, struct socket *, struct sockopt *);
316 void	ip6_initpktopts(struct ip6_pktopts *);
317 int	ip6_setpktopts(struct mbuf *, struct ip6_pktopts *,
318 			    struct ip6_pktopts *, kauth_cred_t, int);
319 void	ip6_clearpktopts(struct ip6_pktopts *, int);
320 struct ip6_pktopts *ip6_copypktopts(struct ip6_pktopts *, int);
321 int	ip6_optlen(struct in6pcb *);
322 
323 void	ip6_statinc(u_int);
324 
325 int	route6_input(struct mbuf **, int *, int);
326 
327 void	frag6_init(void);
328 int	frag6_input(struct mbuf **, int *, int);
329 int	ip6_reass_packet(struct mbuf **, int);
330 void	frag6_slowtimo(void);
331 void	frag6_fasttimo(void);
332 void	frag6_drain(void);
333 void	frag6_drainstub(void);
334 
335 int	ip6flow_init(int);
336 void	ip6flow_poolinit(void);
337 struct  ip6flow *ip6flow_reap(int);
338 void    ip6flow_create(struct route *, struct mbuf *);
339 void    ip6flow_slowtimo(void);
340 int	ip6flow_invalidate_all(int);
341 
342 void	rip6_init(void);
343 int	rip6_input(struct mbuf **, int *, int);
344 void	*rip6_ctlinput(int, const struct sockaddr *, void *);
345 int	rip6_ctloutput(int, struct socket *, struct sockopt *);
346 int	rip6_output(struct mbuf *, struct socket *, struct sockaddr_in6 *,
347 			 struct mbuf *);
348 int	rip6_attach(struct socket *, int);
349 int	rip6_usrreq(struct socket *,
350 	    int, struct mbuf *, struct mbuf *, struct mbuf *, struct lwp *);
351 
352 int	dest6_input(struct mbuf **, int *, int);
353 int	none_input(struct mbuf **, int *, int);
354 
355 struct route;
356 
357 int	in6_selectsrc(struct sockaddr_in6 *, struct ip6_pktopts *,
358 	   struct ip6_moptions *, struct route *, struct in6_addr *,
359 	   struct ifnet **, struct psref *, struct in6_addr *);
360 int in6_selectroute(struct sockaddr_in6 *, struct ip6_pktopts *,
361 	struct route **, struct rtentry **, bool);
362 int	ip6_get_membership(const struct sockopt *, struct ifnet **,
363 	    struct psref *, void *, size_t);
364 
365 u_int32_t ip6_randomid(void);
366 u_int32_t ip6_randomflowlabel(void);
367 #endif /* _KERNEL */
368 
369 #endif /* !_NETINET6_IP6_VAR_H_ */
370