xref: /netbsd-src/sys/netinet/icmp6.h (revision de1dfb1250df962f1ff3a011772cf58e605aed11)
1 /*	$NetBSD: icmp6.h,v 1.30 2004/04/21 17:49:46 itojun Exp $	*/
2 /*	$KAME: icmp6.h,v 1.84 2003/04/23 10:26:51 itojun Exp $	*/
3 
4 
5 /*
6  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. Neither the name of the project nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  */
33 
34 /*
35  * Copyright (c) 1982, 1986, 1993
36  *	The Regents of the University of California.  All rights reserved.
37  *
38  * Redistribution and use in source and binary forms, with or without
39  * modification, are permitted provided that the following conditions
40  * are met:
41  * 1. Redistributions of source code must retain the above copyright
42  *    notice, this list of conditions and the following disclaimer.
43  * 2. Redistributions in binary form must reproduce the above copyright
44  *    notice, this list of conditions and the following disclaimer in the
45  *    documentation and/or other materials provided with the distribution.
46  * 3. Neither the name of the University nor the names of its contributors
47  *    may be used to endorse or promote products derived from this software
48  *    without specific prior written permission.
49  *
50  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60  * SUCH DAMAGE.
61  *
62  *	@(#)ip_icmp.h	8.1 (Berkeley) 6/10/93
63  */
64 
65 #ifndef _NETINET_ICMP6_H_
66 #define _NETINET_ICMP6_H_
67 
68 #define ICMPV6_PLD_MAXLEN	1232	/* IPV6_MMTU - sizeof(struct ip6_hdr)
69 					   - sizeof(struct icmp6_hdr) */
70 
71 struct icmp6_hdr {
72 	u_int8_t	icmp6_type;	/* type field */
73 	u_int8_t	icmp6_code;	/* code field */
74 	u_int16_t	icmp6_cksum;	/* checksum field */
75 	union {
76 		u_int32_t	icmp6_un_data32[1]; /* type-specific field */
77 		u_int16_t	icmp6_un_data16[2]; /* type-specific field */
78 		u_int8_t	icmp6_un_data8[4];  /* type-specific field */
79 	} icmp6_dataun;
80 } __attribute__((__packed__));
81 
82 #define icmp6_data32	icmp6_dataun.icmp6_un_data32
83 #define icmp6_data16	icmp6_dataun.icmp6_un_data16
84 #define icmp6_data8	icmp6_dataun.icmp6_un_data8
85 #define icmp6_pptr	icmp6_data32[0]		/* parameter prob */
86 #define icmp6_mtu	icmp6_data32[0]		/* packet too big */
87 #define icmp6_id	icmp6_data16[0]		/* echo request/reply */
88 #define icmp6_seq	icmp6_data16[1]		/* echo request/reply */
89 #define icmp6_maxdelay	icmp6_data16[0]		/* mcast group membership */
90 
91 #define ICMP6_DST_UNREACH		1	/* dest unreachable, codes: */
92 #define ICMP6_PACKET_TOO_BIG		2	/* packet too big */
93 #define ICMP6_TIME_EXCEEDED		3	/* time exceeded, code: */
94 #define ICMP6_PARAM_PROB		4	/* ip6 header bad */
95 
96 #define ICMP6_ECHO_REQUEST		128	/* echo service */
97 #define ICMP6_ECHO_REPLY		129	/* echo reply */
98 #define MLD_LISTENER_QUERY		130 	/* multicast listener query */
99 #define MLD_LISTENER_REPORT		131	/* multicast listener report */
100 #define MLD_LISTENER_DONE		132	/* multicast listener done */
101 
102 /* RFC2292 decls */
103 #define ICMP6_MEMBERSHIP_QUERY		130	/* group membership query */
104 #define ICMP6_MEMBERSHIP_REPORT		131	/* group membership report */
105 #define ICMP6_MEMBERSHIP_REDUCTION	132	/* group membership termination */
106 
107 #ifndef _KERNEL
108 /* the followings are for backward compatibility to old KAME apps. */
109 #define MLD6_LISTENER_QUERY	MLD_LISTENER_QUERY
110 #define MLD6_LISTENER_REPORT	MLD_LISTENER_REPORT
111 #define MLD6_LISTENER_DONE	MLD_LISTENER_DONE
112 #endif
113 
114 #define ND_ROUTER_SOLICIT		133	/* router solicitation */
115 #define ND_ROUTER_ADVERT		134	/* router advertisment */
116 #define ND_NEIGHBOR_SOLICIT		135	/* neighbor solicitation */
117 #define ND_NEIGHBOR_ADVERT		136	/* neighbor advertisment */
118 #define ND_REDIRECT			137	/* redirect */
119 
120 #define ICMP6_ROUTER_RENUMBERING	138	/* router renumbering */
121 
122 #define ICMP6_WRUREQUEST		139	/* who are you request */
123 #define ICMP6_WRUREPLY			140	/* who are you reply */
124 #define ICMP6_FQDN_QUERY		139	/* FQDN query */
125 #define ICMP6_FQDN_REPLY		140	/* FQDN reply */
126 #define ICMP6_NI_QUERY			139	/* node information request */
127 #define ICMP6_NI_REPLY			140	/* node information reply */
128 
129 /* The definitions below are experimental. TBA */
130 #define MLD_MTRACE_RESP			200	/* mtrace response(to sender) */
131 #define MLD_MTRACE			201	/* mtrace messages */
132 
133 #ifndef _KERNEL
134 /* the followings are for backward compatibility to old KAME apps. */
135 #define MLD6_MTRACE_RESP	MLD_MTRACE_RESP
136 #define MLD6_MTRACE		MLD_MTRACE
137 #endif
138 
139 #define ICMP6_MAXTYPE			201
140 
141 #define ICMP6_DST_UNREACH_NOROUTE	0	/* no route to destination */
142 #define ICMP6_DST_UNREACH_ADMIN	 	1	/* administratively prohibited */
143 #define ICMP6_DST_UNREACH_NOTNEIGHBOR	2	/* not a neighbor(obsolete) */
144 #define ICMP6_DST_UNREACH_BEYONDSCOPE	2	/* beyond scope of source address */
145 #define ICMP6_DST_UNREACH_ADDR		3	/* address unreachable */
146 #define ICMP6_DST_UNREACH_NOPORT	4	/* port unreachable */
147 
148 #define ICMP6_TIME_EXCEED_TRANSIT 	0	/* ttl==0 in transit */
149 #define ICMP6_TIME_EXCEED_REASSEMBLY	1	/* ttl==0 in reass */
150 
151 #define ICMP6_PARAMPROB_HEADER 	 	0	/* erroneous header field */
152 #define ICMP6_PARAMPROB_NEXTHEADER	1	/* unrecognized next header */
153 #define ICMP6_PARAMPROB_OPTION		2	/* unrecognized option */
154 
155 #define ICMP6_INFOMSG_MASK		0x80	/* all informational messages */
156 
157 #define ICMP6_NI_SUBJ_IPV6	0	/* Query Subject is an IPv6 address */
158 #define ICMP6_NI_SUBJ_FQDN	1	/* Query Subject is a Domain name */
159 #define ICMP6_NI_SUBJ_IPV4	2	/* Query Subject is an IPv4 address */
160 
161 #define ICMP6_NI_SUCCESS	0	/* node information successful reply */
162 #define ICMP6_NI_REFUSED	1	/* node information request is refused */
163 #define ICMP6_NI_UNKNOWN	2	/* unknown Qtype */
164 
165 #define ICMP6_ROUTER_RENUMBERING_COMMAND  0	/* rr command */
166 #define ICMP6_ROUTER_RENUMBERING_RESULT   1	/* rr result */
167 #define ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET   255	/* rr seq num reset */
168 
169 /* Used in kernel only */
170 #define ND_REDIRECT_ONLINK	0	/* redirect to an on-link node */
171 #define ND_REDIRECT_ROUTER	1	/* redirect to a better router */
172 
173 /*
174  * Multicast Listener Discovery
175  */
176 struct mld_hdr {
177 	struct icmp6_hdr	mld_icmp6_hdr;
178 	struct in6_addr		mld_addr; /* multicast address */
179 } __attribute__((__packed__));
180 
181 /* definitions to provide backward compatibility to old KAME applications */
182 #ifndef _KERNEL
183 #define mld6_hdr	mld_hdr
184 #define mld6_type	mld_type
185 #define mld6_code	mld_code
186 #define mld6_cksum	mld_cksum
187 #define mld6_maxdelay	mld_maxdelay
188 #define mld6_reserved	mld_reserved
189 #define mld6_addr	mld_addr
190 #endif
191 
192 /* shortcut macro definitions */
193 #define mld_type	mld_icmp6_hdr.icmp6_type
194 #define mld_code	mld_icmp6_hdr.icmp6_code
195 #define mld_cksum	mld_icmp6_hdr.icmp6_cksum
196 #define mld_maxdelay	mld_icmp6_hdr.icmp6_data16[0]
197 #define mld_reserved	mld_icmp6_hdr.icmp6_data16[1]
198 
199 /*
200  * Neighbor Discovery
201  */
202 
203 struct nd_router_solicit {	/* router solicitation */
204 	struct icmp6_hdr 	nd_rs_hdr;
205 	/* could be followed by options */
206 } __attribute__((__packed__));
207 
208 #define nd_rs_type	nd_rs_hdr.icmp6_type
209 #define nd_rs_code	nd_rs_hdr.icmp6_code
210 #define nd_rs_cksum	nd_rs_hdr.icmp6_cksum
211 #define nd_rs_reserved	nd_rs_hdr.icmp6_data32[0]
212 
213 struct nd_router_advert {	/* router advertisement */
214 	struct icmp6_hdr	nd_ra_hdr;
215 	u_int32_t		nd_ra_reachable;	/* reachable time */
216 	u_int32_t		nd_ra_retransmit;	/* retransmit timer */
217 	/* could be followed by options */
218 } __attribute__((__packed__));
219 
220 #define nd_ra_type		nd_ra_hdr.icmp6_type
221 #define nd_ra_code		nd_ra_hdr.icmp6_code
222 #define nd_ra_cksum		nd_ra_hdr.icmp6_cksum
223 #define nd_ra_curhoplimit	nd_ra_hdr.icmp6_data8[0]
224 #define nd_ra_flags_reserved	nd_ra_hdr.icmp6_data8[1]
225 #define ND_RA_FLAG_MANAGED	0x80
226 #define ND_RA_FLAG_OTHER	0x40
227 #define nd_ra_router_lifetime	nd_ra_hdr.icmp6_data16[1]
228 
229 struct nd_neighbor_solicit {	/* neighbor solicitation */
230 	struct icmp6_hdr	nd_ns_hdr;
231 	struct in6_addr		nd_ns_target;	/*target address */
232 	/* could be followed by options */
233 } __attribute__((__packed__));
234 
235 #define nd_ns_type		nd_ns_hdr.icmp6_type
236 #define nd_ns_code		nd_ns_hdr.icmp6_code
237 #define nd_ns_cksum		nd_ns_hdr.icmp6_cksum
238 #define nd_ns_reserved		nd_ns_hdr.icmp6_data32[0]
239 
240 struct nd_neighbor_advert {	/* neighbor advertisement */
241 	struct icmp6_hdr	nd_na_hdr;
242 	struct in6_addr		nd_na_target;	/* target address */
243 	/* could be followed by options */
244 } __attribute__((__packed__));
245 
246 #define nd_na_type		nd_na_hdr.icmp6_type
247 #define nd_na_code		nd_na_hdr.icmp6_code
248 #define nd_na_cksum		nd_na_hdr.icmp6_cksum
249 #define nd_na_flags_reserved	nd_na_hdr.icmp6_data32[0]
250 #if BYTE_ORDER == BIG_ENDIAN
251 #define ND_NA_FLAG_ROUTER		0x80000000
252 #define ND_NA_FLAG_SOLICITED		0x40000000
253 #define ND_NA_FLAG_OVERRIDE		0x20000000
254 #else
255 #if BYTE_ORDER == LITTLE_ENDIAN
256 #define ND_NA_FLAG_ROUTER		0x80
257 #define ND_NA_FLAG_SOLICITED		0x40
258 #define ND_NA_FLAG_OVERRIDE		0x20
259 #endif
260 #endif
261 
262 struct nd_redirect {		/* redirect */
263 	struct icmp6_hdr	nd_rd_hdr;
264 	struct in6_addr		nd_rd_target;	/* target address */
265 	struct in6_addr		nd_rd_dst;	/* destination address */
266 	/* could be followed by options */
267 } __attribute__((__packed__));
268 
269 #define nd_rd_type		nd_rd_hdr.icmp6_type
270 #define nd_rd_code		nd_rd_hdr.icmp6_code
271 #define nd_rd_cksum		nd_rd_hdr.icmp6_cksum
272 #define nd_rd_reserved		nd_rd_hdr.icmp6_data32[0]
273 
274 struct nd_opt_hdr {		/* Neighbor discovery option header */
275 	u_int8_t	nd_opt_type;
276 	u_int8_t	nd_opt_len;
277 	/* followed by option specific data*/
278 } __attribute__((__packed__));
279 
280 #define ND_OPT_SOURCE_LINKADDR		1
281 #define ND_OPT_TARGET_LINKADDR		2
282 #define ND_OPT_PREFIX_INFORMATION	3
283 #define ND_OPT_REDIRECTED_HEADER	4
284 #define ND_OPT_MTU			5
285 
286 struct nd_opt_prefix_info {	/* prefix information */
287 	u_int8_t	nd_opt_pi_type;
288 	u_int8_t	nd_opt_pi_len;
289 	u_int8_t	nd_opt_pi_prefix_len;
290 	u_int8_t	nd_opt_pi_flags_reserved;
291 	u_int32_t	nd_opt_pi_valid_time;
292 	u_int32_t	nd_opt_pi_preferred_time;
293 	u_int32_t	nd_opt_pi_reserved2;
294 	struct in6_addr	nd_opt_pi_prefix;
295 } __attribute__((__packed__));
296 
297 #define ND_OPT_PI_FLAG_ONLINK		0x80
298 #define ND_OPT_PI_FLAG_AUTO		0x40
299 
300 struct nd_opt_rd_hdr {		/* redirected header */
301 	u_int8_t	nd_opt_rh_type;
302 	u_int8_t	nd_opt_rh_len;
303 	u_int16_t	nd_opt_rh_reserved1;
304 	u_int32_t	nd_opt_rh_reserved2;
305 	/* followed by IP header and data */
306 } __attribute__((__packed__));
307 
308 struct nd_opt_mtu {		/* MTU option */
309 	u_int8_t	nd_opt_mtu_type;
310 	u_int8_t	nd_opt_mtu_len;
311 	u_int16_t	nd_opt_mtu_reserved;
312 	u_int32_t	nd_opt_mtu_mtu;
313 } __attribute__((__packed__));
314 
315 /*
316  * icmp6 namelookup
317  */
318 
319 struct icmp6_namelookup {
320 	struct icmp6_hdr 	icmp6_nl_hdr;
321 	u_int8_t	icmp6_nl_nonce[8];
322 	int32_t		icmp6_nl_ttl;
323 #if 0
324 	u_int8_t	icmp6_nl_len;
325 	u_int8_t	icmp6_nl_name[3];
326 #endif
327 	/* could be followed by options */
328 } __attribute__((__packed__));
329 
330 /*
331  * icmp6 node information
332  */
333 struct icmp6_nodeinfo {
334 	struct icmp6_hdr icmp6_ni_hdr;
335 	u_int8_t icmp6_ni_nonce[8];
336 	/* could be followed by reply data */
337 } __attribute__((__packed__));
338 
339 #define ni_type		icmp6_ni_hdr.icmp6_type
340 #define ni_code		icmp6_ni_hdr.icmp6_code
341 #define ni_cksum	icmp6_ni_hdr.icmp6_cksum
342 #define ni_qtype	icmp6_ni_hdr.icmp6_data16[0]
343 #define ni_flags	icmp6_ni_hdr.icmp6_data16[1]
344 
345 #define NI_QTYPE_NOOP		0 /* NOOP  */
346 #define NI_QTYPE_SUPTYPES	1 /* Supported Qtypes */
347 #define NI_QTYPE_FQDN		2 /* FQDN (draft 04) */
348 #define NI_QTYPE_DNSNAME	2 /* DNS Name */
349 #define NI_QTYPE_NODEADDR	3 /* Node Addresses */
350 #define NI_QTYPE_IPV4ADDR	4 /* IPv4 Addresses */
351 
352 #if BYTE_ORDER == BIG_ENDIAN
353 #define NI_SUPTYPE_FLAG_COMPRESS	0x1
354 #define NI_FQDN_FLAG_VALIDTTL		0x1
355 #elif BYTE_ORDER == LITTLE_ENDIAN
356 #define NI_SUPTYPE_FLAG_COMPRESS	0x0100
357 #define NI_FQDN_FLAG_VALIDTTL		0x0100
358 #endif
359 
360 #ifdef NAME_LOOKUPS_04
361 #if BYTE_ORDER == BIG_ENDIAN
362 #define NI_NODEADDR_FLAG_LINKLOCAL	0x1
363 #define NI_NODEADDR_FLAG_SITELOCAL	0x2
364 #define NI_NODEADDR_FLAG_GLOBAL		0x4
365 #define NI_NODEADDR_FLAG_ALL		0x8
366 #define NI_NODEADDR_FLAG_TRUNCATE	0x10
367 #define NI_NODEADDR_FLAG_ANYCAST	0x20 /* just experimental. not in spec */
368 #elif BYTE_ORDER == LITTLE_ENDIAN
369 #define NI_NODEADDR_FLAG_LINKLOCAL	0x0100
370 #define NI_NODEADDR_FLAG_SITELOCAL	0x0200
371 #define NI_NODEADDR_FLAG_GLOBAL		0x0400
372 #define NI_NODEADDR_FLAG_ALL		0x0800
373 #define NI_NODEADDR_FLAG_TRUNCATE	0x1000
374 #define NI_NODEADDR_FLAG_ANYCAST	0x2000 /* just experimental. not in spec */
375 #endif
376 #else  /* draft-ietf-ipngwg-icmp-name-lookups-05 (and later?) */
377 #if BYTE_ORDER == BIG_ENDIAN
378 #define NI_NODEADDR_FLAG_TRUNCATE	0x1
379 #define NI_NODEADDR_FLAG_ALL		0x2
380 #define NI_NODEADDR_FLAG_COMPAT		0x4
381 #define NI_NODEADDR_FLAG_LINKLOCAL	0x8
382 #define NI_NODEADDR_FLAG_SITELOCAL	0x10
383 #define NI_NODEADDR_FLAG_GLOBAL		0x20
384 #define NI_NODEADDR_FLAG_ANYCAST	0x40 /* just experimental. not in spec */
385 #elif BYTE_ORDER == LITTLE_ENDIAN
386 #define NI_NODEADDR_FLAG_TRUNCATE	0x0100
387 #define NI_NODEADDR_FLAG_ALL		0x0200
388 #define NI_NODEADDR_FLAG_COMPAT		0x0400
389 #define NI_NODEADDR_FLAG_LINKLOCAL	0x0800
390 #define NI_NODEADDR_FLAG_SITELOCAL	0x1000
391 #define NI_NODEADDR_FLAG_GLOBAL		0x2000
392 #define NI_NODEADDR_FLAG_ANYCAST	0x4000 /* just experimental. not in spec */
393 #endif
394 #endif
395 
396 struct ni_reply_fqdn {
397 	u_int32_t ni_fqdn_ttl;	/* TTL */
398 	u_int8_t ni_fqdn_namelen; /* length in octets of the FQDN */
399 	u_int8_t ni_fqdn_name[3]; /* XXX: alignment */
400 } __attribute__((__packed__));
401 
402 /*
403  * Router Renumbering. as router-renum-08.txt
404  */
405 struct icmp6_router_renum {	/* router renumbering header */
406 	struct icmp6_hdr	rr_hdr;
407 	u_int8_t	rr_segnum;
408 	u_int8_t	rr_flags;
409 	u_int16_t	rr_maxdelay;
410 	u_int32_t	rr_reserved;
411 } __attribute__((__packed__));
412 
413 #define ICMP6_RR_FLAGS_TEST		0x80
414 #define ICMP6_RR_FLAGS_REQRESULT	0x40
415 #define ICMP6_RR_FLAGS_FORCEAPPLY	0x20
416 #define ICMP6_RR_FLAGS_SPECSITE		0x10
417 #define ICMP6_RR_FLAGS_PREVDONE		0x08
418 
419 #define rr_type		rr_hdr.icmp6_type
420 #define rr_code		rr_hdr.icmp6_code
421 #define rr_cksum	rr_hdr.icmp6_cksum
422 #define rr_seqnum 	rr_hdr.icmp6_data32[0]
423 
424 struct rr_pco_match {		/* match prefix part */
425 	u_int8_t	rpm_code;
426 	u_int8_t	rpm_len;
427 	u_int8_t	rpm_ordinal;
428 	u_int8_t	rpm_matchlen;
429 	u_int8_t	rpm_minlen;
430 	u_int8_t	rpm_maxlen;
431 	u_int16_t	rpm_reserved;
432 	struct	in6_addr	rpm_prefix;
433 } __attribute__((__packed__));
434 
435 #define RPM_PCO_ADD		1
436 #define RPM_PCO_CHANGE		2
437 #define RPM_PCO_SETGLOBAL	3
438 #define RPM_PCO_MAX		4
439 
440 struct rr_pco_use {		/* use prefix part */
441 	u_int8_t	rpu_uselen;
442 	u_int8_t	rpu_keeplen;
443 	u_int8_t	rpu_ramask;
444 	u_int8_t	rpu_raflags;
445 	u_int32_t	rpu_vltime;
446 	u_int32_t	rpu_pltime;
447 	u_int32_t	rpu_flags;
448 	struct	in6_addr rpu_prefix;
449 } __attribute__((__packed__));
450 #define ICMP6_RR_PCOUSE_RAFLAGS_ONLINK	0x80
451 #define ICMP6_RR_PCOUSE_RAFLAGS_AUTO	0x40
452 
453 #if BYTE_ORDER == BIG_ENDIAN
454 #define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME     0x80000000
455 #define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME     0x40000000
456 #elif BYTE_ORDER == LITTLE_ENDIAN
457 #define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME     0x80
458 #define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME     0x40
459 #endif
460 
461 struct rr_result {		/* router renumbering result message */
462 	u_int16_t	rrr_flags;
463 	u_int8_t	rrr_ordinal;
464 	u_int8_t	rrr_matchedlen;
465 	u_int32_t	rrr_ifid;
466 	struct	in6_addr rrr_prefix;
467 } __attribute__((__packed__));
468 #if BYTE_ORDER == BIG_ENDIAN
469 #define ICMP6_RR_RESULT_FLAGS_OOB		0x0002
470 #define ICMP6_RR_RESULT_FLAGS_FORBIDDEN		0x0001
471 #elif BYTE_ORDER == LITTLE_ENDIAN
472 #define ICMP6_RR_RESULT_FLAGS_OOB		0x0200
473 #define ICMP6_RR_RESULT_FLAGS_FORBIDDEN		0x0100
474 #endif
475 
476 /*
477  * icmp6 filter structures.
478  */
479 
480 struct icmp6_filter {
481 	u_int32_t icmp6_filt[8];
482 };
483 
484 #ifdef _KERNEL
485 #define	ICMP6_FILTER_SETPASSALL(filterp) \
486 do {								\
487 	int i; u_char *p;					\
488 	p = (u_char *)filterp;					\
489 	for (i = 0; i < sizeof(struct icmp6_filter); i++)	\
490 		p[i] = 0xff;					\
491 } while (/*CONSTCOND*/ 0)
492 #define	ICMP6_FILTER_SETBLOCKALL(filterp) \
493 	bzero(filterp, sizeof(struct icmp6_filter))
494 #else /* _KERNEL */
495 #define	ICMP6_FILTER_SETPASSALL(filterp) \
496 	memset(filterp, 0xff, sizeof(struct icmp6_filter))
497 #define	ICMP6_FILTER_SETBLOCKALL(filterp) \
498 	memset(filterp, 0x00, sizeof(struct icmp6_filter))
499 #endif /* _KERNEL */
500 
501 #define	ICMP6_FILTER_SETPASS(type, filterp) \
502 	(((filterp)->icmp6_filt[(type) >> 5]) |= (1 << ((type) & 31)))
503 #define	ICMP6_FILTER_SETBLOCK(type, filterp) \
504 	(((filterp)->icmp6_filt[(type) >> 5]) &= ~(1 << ((type) & 31)))
505 #define	ICMP6_FILTER_WILLPASS(type, filterp) \
506 	((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) != 0)
507 #define	ICMP6_FILTER_WILLBLOCK(type, filterp) \
508 	((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) == 0)
509 
510 /*
511  * Variables related to this implementation
512  * of the internet control message protocol version 6.
513  */
514 struct icmp6errstat {
515 	u_quad_t icp6errs_dst_unreach_noroute;
516 	u_quad_t icp6errs_dst_unreach_admin;
517 	u_quad_t icp6errs_dst_unreach_beyondscope;
518 	u_quad_t icp6errs_dst_unreach_addr;
519 	u_quad_t icp6errs_dst_unreach_noport;
520 	u_quad_t icp6errs_packet_too_big;
521 	u_quad_t icp6errs_time_exceed_transit;
522 	u_quad_t icp6errs_time_exceed_reassembly;
523 	u_quad_t icp6errs_paramprob_header;
524 	u_quad_t icp6errs_paramprob_nextheader;
525 	u_quad_t icp6errs_paramprob_option;
526 	u_quad_t icp6errs_redirect; /* we regard redirect as an error here */
527 	u_quad_t icp6errs_unknown;
528 };
529 
530 struct icmp6stat {
531 /* statistics related to icmp6 packets generated */
532 	u_quad_t icp6s_error;		/* # of calls to icmp6_error */
533 	u_quad_t icp6s_canterror;	/* no error 'cuz old was icmp */
534 	u_quad_t icp6s_toofreq;		/* no error 'cuz rate limitation */
535 	u_quad_t icp6s_outhist[256];
536 /* statistics related to input message processed */
537 	u_quad_t icp6s_badcode;		/* icmp6_code out of range */
538 	u_quad_t icp6s_tooshort;	/* packet < sizeof(struct icmp6_hdr) */
539 	u_quad_t icp6s_checksum;	/* bad checksum */
540 	u_quad_t icp6s_badlen;		/* calculated bound mismatch */
541 	/*
542 	 * number of responses: this member is inherited from netinet code, but
543 	 * for netinet6 code, it is already available in icp6s_outhist[].
544 	 */
545 	u_quad_t icp6s_reflect;
546 	u_quad_t icp6s_inhist[256];
547 	u_quad_t icp6s_nd_toomanyopt;	/* too many ND options */
548 	struct icmp6errstat icp6s_outerrhist;
549 #define icp6s_odst_unreach_noroute \
550 	icp6s_outerrhist.icp6errs_dst_unreach_noroute
551 #define icp6s_odst_unreach_admin icp6s_outerrhist.icp6errs_dst_unreach_admin
552 #define icp6s_odst_unreach_beyondscope \
553 	icp6s_outerrhist.icp6errs_dst_unreach_beyondscope
554 #define icp6s_odst_unreach_addr icp6s_outerrhist.icp6errs_dst_unreach_addr
555 #define icp6s_odst_unreach_noport icp6s_outerrhist.icp6errs_dst_unreach_noport
556 #define icp6s_opacket_too_big icp6s_outerrhist.icp6errs_packet_too_big
557 #define icp6s_otime_exceed_transit \
558 	icp6s_outerrhist.icp6errs_time_exceed_transit
559 #define icp6s_otime_exceed_reassembly \
560 	icp6s_outerrhist.icp6errs_time_exceed_reassembly
561 #define icp6s_oparamprob_header icp6s_outerrhist.icp6errs_paramprob_header
562 #define icp6s_oparamprob_nextheader \
563 	icp6s_outerrhist.icp6errs_paramprob_nextheader
564 #define icp6s_oparamprob_option icp6s_outerrhist.icp6errs_paramprob_option
565 #define icp6s_oredirect icp6s_outerrhist.icp6errs_redirect
566 #define icp6s_ounknown icp6s_outerrhist.icp6errs_unknown
567 	u_quad_t icp6s_pmtuchg;		/* path MTU changes */
568 	u_quad_t icp6s_nd_badopt;	/* bad ND options */
569 	u_quad_t icp6s_badns;		/* bad neighbor solicitation */
570 	u_quad_t icp6s_badna;		/* bad neighbor advertisement */
571 	u_quad_t icp6s_badrs;		/* bad router advertisement */
572 	u_quad_t icp6s_badra;		/* bad router advertisement */
573 	u_quad_t icp6s_badredirect;	/* bad redirect message */
574 };
575 
576 /*
577  * Names for ICMP sysctl objects
578  */
579 #define ICMPV6CTL_STATS		1
580 #define ICMPV6CTL_REDIRACCEPT	2	/* accept/process redirects */
581 #define ICMPV6CTL_REDIRTIMEOUT	3	/* redirect cache time */
582 #if 0	/*obsoleted*/
583 #define ICMPV6CTL_ERRRATELIMIT	5	/* ICMPv6 error rate limitation */
584 #endif
585 #define ICMPV6CTL_ND6_PRUNE	6
586 #define ICMPV6CTL_ND6_DELAY	8
587 #define ICMPV6CTL_ND6_UMAXTRIES	9
588 #define ICMPV6CTL_ND6_MMAXTRIES		10
589 #define ICMPV6CTL_ND6_USELOOPBACK	11
590 /*#define ICMPV6CTL_ND6_PROXYALL	12	obsoleted, do not reuse here */
591 #define ICMPV6CTL_NODEINFO	13
592 #define ICMPV6CTL_ERRPPSLIMIT	14	/* ICMPv6 error pps limitation */
593 #define ICMPV6CTL_ND6_MAXNUDHINT	15
594 #define ICMPV6CTL_MTUDISC_HIWAT	16
595 #define ICMPV6CTL_MTUDISC_LOWAT	17
596 #define ICMPV6CTL_ND6_DEBUG	18
597 #define ICMPV6CTL_ND6_DRLIST	19
598 #define ICMPV6CTL_ND6_PRLIST	20
599 #define ICMPV6CTL_MAXID		21
600 
601 #define ICMPV6CTL_NAMES { \
602 	{ 0, 0 }, \
603 	{ 0, 0 }, \
604 	{ "rediraccept", CTLTYPE_INT }, \
605 	{ "redirtimeout", CTLTYPE_INT }, \
606 	{ 0, 0 }, \
607 	{ 0, 0 }, \
608 	{ "nd6_prune", CTLTYPE_INT }, \
609 	{ 0, 0 }, \
610 	{ "nd6_delay", CTLTYPE_INT }, \
611 	{ "nd6_umaxtries", CTLTYPE_INT }, \
612 	{ "nd6_mmaxtries", CTLTYPE_INT }, \
613 	{ "nd6_useloopback", CTLTYPE_INT }, \
614 	{ 0, 0 }, \
615 	{ "nodeinfo", CTLTYPE_INT }, \
616 	{ "errppslimit", CTLTYPE_INT }, \
617 	{ "nd6_maxnudhint", CTLTYPE_INT }, \
618 	{ "mtudisc_hiwat", CTLTYPE_INT }, \
619 	{ "mtudisc_lowat", CTLTYPE_INT }, \
620 	{ "nd6_debug", CTLTYPE_INT }, \
621 	{ 0, 0 }, \
622 	{ 0, 0 }, \
623 }
624 
625 #define RTF_PROBEMTU	RTF_PROTO1
626 
627 #ifdef _KERNEL
628 struct	rtentry;
629 struct	rttimer;
630 struct	in6_multi;
631 
632 void	icmp6_init(void);
633 void	icmp6_paramerror(struct mbuf *, int);
634 void	icmp6_error(struct mbuf *, int, int, int);
635 int	icmp6_input(struct mbuf **, int *, int);
636 void	icmp6_fasttimo(void);
637 void	icmp6_reflect(struct mbuf *, size_t);
638 void	icmp6_prepare(struct mbuf *);
639 void	icmp6_redirect_input(struct mbuf *, int);
640 void	icmp6_redirect_output(struct mbuf *, struct rtentry *);
641 int	icmp6_sysctl(int *, u_int, void *, size_t *, void *, size_t);
642 
643 struct	ip6ctlparam;
644 void	icmp6_mtudisc_update(struct ip6ctlparam *, int);
645 void	icmp6_mtudisc_callback_register(void (*)(struct in6_addr *));
646 
647 /* XXX: is this the right place for these macros? */
648 #define icmp6_ifstat_inc(ifp, tag) \
649 do {								\
650 	if (ifp)						\
651 		((struct in6_ifextra *)((ifp)->if_afdata[AF_INET6]))->icmp6_ifstat->tag++; \
652 } while (/*CONSTCOND*/ 0)
653 
654 #define icmp6_ifoutstat_inc(ifp, type, code) \
655 do { \
656 		icmp6_ifstat_inc(ifp, ifs6_out_msg); \
657 		switch(type) { \
658 		 case ICMP6_DST_UNREACH: \
659 			 icmp6_ifstat_inc(ifp, ifs6_out_dstunreach); \
660 			 if (code == ICMP6_DST_UNREACH_ADMIN) \
661 				 icmp6_ifstat_inc(ifp, ifs6_out_adminprohib); \
662 			 break; \
663 		 case ICMP6_PACKET_TOO_BIG: \
664 			 icmp6_ifstat_inc(ifp, ifs6_out_pkttoobig); \
665 			 break; \
666 		 case ICMP6_TIME_EXCEEDED: \
667 			 icmp6_ifstat_inc(ifp, ifs6_out_timeexceed); \
668 			 break; \
669 		 case ICMP6_PARAM_PROB: \
670 			 icmp6_ifstat_inc(ifp, ifs6_out_paramprob); \
671 			 break; \
672 		 case ICMP6_ECHO_REQUEST: \
673 			 icmp6_ifstat_inc(ifp, ifs6_out_echo); \
674 			 break; \
675 		 case ICMP6_ECHO_REPLY: \
676 			 icmp6_ifstat_inc(ifp, ifs6_out_echoreply); \
677 			 break; \
678 		 case MLD_LISTENER_QUERY: \
679 			 icmp6_ifstat_inc(ifp, ifs6_out_mldquery); \
680 			 break; \
681 		 case MLD_LISTENER_REPORT: \
682 			 icmp6_ifstat_inc(ifp, ifs6_out_mldreport); \
683 			 break; \
684 		 case MLD_LISTENER_DONE: \
685 			 icmp6_ifstat_inc(ifp, ifs6_out_mlddone); \
686 			 break; \
687 		 case ND_ROUTER_SOLICIT: \
688 			 icmp6_ifstat_inc(ifp, ifs6_out_routersolicit); \
689 			 break; \
690 		 case ND_ROUTER_ADVERT: \
691 			 icmp6_ifstat_inc(ifp, ifs6_out_routeradvert); \
692 			 break; \
693 		 case ND_NEIGHBOR_SOLICIT: \
694 			 icmp6_ifstat_inc(ifp, ifs6_out_neighborsolicit); \
695 			 break; \
696 		 case ND_NEIGHBOR_ADVERT: \
697 			 icmp6_ifstat_inc(ifp, ifs6_out_neighboradvert); \
698 			 break; \
699 		 case ND_REDIRECT: \
700 			 icmp6_ifstat_inc(ifp, ifs6_out_redirect); \
701 			 break; \
702 		} \
703 } while (/*CONSTCOND*/ 0)
704 
705 extern int	icmp6_rediraccept;	/* accept/process redirects */
706 extern int	icmp6_redirtimeout;	/* cache time for redirect routes */
707 #endif /* _KERNEL */
708 
709 #endif /* not _NETINET_ICMP6_H_ */
710