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