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