xref: /freebsd/sys/netinet/icmp6.h (revision 734e82fe33aa764367791a7d603b383996c6b40b)
1 /*	$KAME: icmp6.h,v 1.46 2001/04/27 15:09:48 itojun Exp $	*/
2 
3 /*-
4  * SPDX-License-Identifier: BSD-3-Clause
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 } __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 #define MLD_LISTENER_REDUCTION MLD_LISTENER_DONE /* RFC3542 definition */
102 
103 /* RFC2292 decls */
104 #define ICMP6_MEMBERSHIP_QUERY		130	/* group membership query */
105 #define ICMP6_MEMBERSHIP_REPORT		131	/* group membership report */
106 #define ICMP6_MEMBERSHIP_REDUCTION	132	/* group membership termination */
107 
108 #ifndef _KERNEL
109 /* the followings are for backward compatibility to old KAME apps. */
110 #define MLD6_LISTENER_QUERY	MLD_LISTENER_QUERY
111 #define MLD6_LISTENER_REPORT	MLD_LISTENER_REPORT
112 #define MLD6_LISTENER_DONE	MLD_LISTENER_DONE
113 #endif
114 
115 #define ND_ROUTER_SOLICIT		133	/* router solicitation */
116 #define ND_ROUTER_ADVERT		134	/* router advertisement */
117 #define ND_NEIGHBOR_SOLICIT		135	/* neighbor solicitation */
118 #define ND_NEIGHBOR_ADVERT		136	/* neighbor advertisement */
119 #define ND_REDIRECT			137	/* redirect */
120 
121 #define ICMP6_ROUTER_RENUMBERING	138	/* router renumbering */
122 
123 #define ICMP6_WRUREQUEST		139	/* who are you request */
124 #define ICMP6_WRUREPLY			140	/* who are you reply */
125 #define ICMP6_FQDN_QUERY		139	/* FQDN query */
126 #define ICMP6_FQDN_REPLY		140	/* FQDN reply */
127 #define ICMP6_NI_QUERY			139	/* node information request */
128 #define ICMP6_NI_REPLY			140	/* node information reply */
129 #define MLDV2_LISTENER_REPORT		143	/* RFC3810 listener report */
130 
131 /* The definitions below are experimental. TBA */
132 #define MLD_MTRACE_RESP			200	/* mtrace resp (to sender) */
133 #define MLD_MTRACE			201	/* mtrace messages */
134 
135 #ifndef _KERNEL
136 #define MLD6_MTRACE_RESP	MLD_MTRACE_RESP
137 #define MLD6_MTRACE		MLD_MTRACE
138 #endif
139 
140 #define ICMP6_MAXTYPE			201
141 
142 #define ICMP6_DST_UNREACH_NOROUTE	0	/* no route to destination */
143 #define ICMP6_DST_UNREACH_ADMIN	 	1	/* administratively prohibited */
144 #define ICMP6_DST_UNREACH_NOTNEIGHBOR	2	/* not a neighbor(obsolete) */
145 #define ICMP6_DST_UNREACH_BEYONDSCOPE	2	/* beyond scope of source address */
146 #define ICMP6_DST_UNREACH_ADDR		3	/* address unreachable */
147 #define ICMP6_DST_UNREACH_NOPORT	4	/* port unreachable */
148 #define ICMP6_DST_UNREACH_POLICY	5	/* failed ingress/egress policy */
149 #define ICMP6_DST_UNREACH_REJECT	6	/* Reject route to destination */
150 #define ICMP6_DST_UNREACH_SRCROUTE	7	/* Error in source routing header */
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 } __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 #define mld_v2_reserved	mld_icmp6_hdr.icmp6_data16[0]
203 #define mld_v2_numrecs	mld_icmp6_hdr.icmp6_data16[1]
204 
205 /*
206  * Neighbor Discovery
207  */
208 
209 struct nd_router_solicit {	/* router solicitation */
210 	struct icmp6_hdr 	nd_rs_hdr;
211 	/* could be followed by options */
212 } __packed;
213 
214 #define nd_rs_type	nd_rs_hdr.icmp6_type
215 #define nd_rs_code	nd_rs_hdr.icmp6_code
216 #define nd_rs_cksum	nd_rs_hdr.icmp6_cksum
217 #define nd_rs_reserved	nd_rs_hdr.icmp6_data32[0]
218 
219 struct nd_router_advert {	/* router advertisement */
220 	struct icmp6_hdr	nd_ra_hdr;
221 	u_int32_t		nd_ra_reachable;	/* reachable time */
222 	u_int32_t		nd_ra_retransmit;	/* retransmit timer */
223 	/* could be followed by options */
224 } __packed;
225 
226 #define nd_ra_type		nd_ra_hdr.icmp6_type
227 #define nd_ra_code		nd_ra_hdr.icmp6_code
228 #define nd_ra_cksum		nd_ra_hdr.icmp6_cksum
229 #define nd_ra_curhoplimit	nd_ra_hdr.icmp6_data8[0]
230 #define nd_ra_flags_reserved	nd_ra_hdr.icmp6_data8[1]
231 #define ND_RA_FLAG_MANAGED	0x80
232 #define ND_RA_FLAG_OTHER	0x40
233 #define ND_RA_FLAG_HA		0x20
234 
235 /*
236  * Router preference values based on draft-draves-ipngwg-router-selection-01.
237  * These are non-standard definitions.
238  */
239 #define ND_RA_FLAG_RTPREF_MASK	0x18 /* 00011000 */
240 
241 #define ND_RA_FLAG_RTPREF_HIGH	0x08 /* 00001000 */
242 #define ND_RA_FLAG_RTPREF_MEDIUM	0x00 /* 00000000 */
243 #define ND_RA_FLAG_RTPREF_LOW	0x18 /* 00011000 */
244 #define ND_RA_FLAG_RTPREF_RSV	0x10 /* 00010000 */
245 
246 #ifdef EXPERIMENTAL
247 #define	ND_RA_FLAG_IPV6_ONLY	0x02 /* draft-ietf-6man-ipv6only-flag */
248 #endif
249 
250 #define nd_ra_router_lifetime	nd_ra_hdr.icmp6_data16[1]
251 
252 struct nd_neighbor_solicit {	/* neighbor solicitation */
253 	struct icmp6_hdr	nd_ns_hdr;
254 	struct in6_addr		nd_ns_target;	/*target address */
255 	/* could be followed by options */
256 } __packed;
257 
258 #define nd_ns_type		nd_ns_hdr.icmp6_type
259 #define nd_ns_code		nd_ns_hdr.icmp6_code
260 #define nd_ns_cksum		nd_ns_hdr.icmp6_cksum
261 #define nd_ns_reserved		nd_ns_hdr.icmp6_data32[0]
262 
263 struct nd_neighbor_advert {	/* neighbor advertisement */
264 	struct icmp6_hdr	nd_na_hdr;
265 	struct in6_addr		nd_na_target;	/* target address */
266 	/* could be followed by options */
267 } __packed;
268 
269 #define nd_na_type		nd_na_hdr.icmp6_type
270 #define nd_na_code		nd_na_hdr.icmp6_code
271 #define nd_na_cksum		nd_na_hdr.icmp6_cksum
272 #define nd_na_flags_reserved	nd_na_hdr.icmp6_data32[0]
273 #if BYTE_ORDER == BIG_ENDIAN
274 #define ND_NA_FLAG_ROUTER		0x80000000
275 #define ND_NA_FLAG_SOLICITED		0x40000000
276 #define ND_NA_FLAG_OVERRIDE		0x20000000
277 #else
278 #if BYTE_ORDER == LITTLE_ENDIAN
279 #define ND_NA_FLAG_ROUTER		0x80
280 #define ND_NA_FLAG_SOLICITED		0x40
281 #define ND_NA_FLAG_OVERRIDE		0x20
282 #endif
283 #endif
284 
285 struct nd_redirect {		/* redirect */
286 	struct icmp6_hdr	nd_rd_hdr;
287 	struct in6_addr		nd_rd_target;	/* target address */
288 	struct in6_addr		nd_rd_dst;	/* destination address */
289 	/* could be followed by options */
290 } __packed;
291 
292 #define nd_rd_type		nd_rd_hdr.icmp6_type
293 #define nd_rd_code		nd_rd_hdr.icmp6_code
294 #define nd_rd_cksum		nd_rd_hdr.icmp6_cksum
295 #define nd_rd_reserved		nd_rd_hdr.icmp6_data32[0]
296 
297 struct nd_opt_hdr {		/* Neighbor discovery option header */
298 	u_int8_t	nd_opt_type;
299 	u_int8_t	nd_opt_len;
300 	/* followed by option specific data*/
301 } __packed;
302 
303 #define ND_OPT_SOURCE_LINKADDR		1
304 #define ND_OPT_TARGET_LINKADDR		2
305 #define ND_OPT_PREFIX_INFORMATION	3
306 #define ND_OPT_REDIRECTED_HEADER	4
307 #define ND_OPT_MTU			5
308 #define ND_OPT_NONCE			14	/* RFC 3971 */
309 #define ND_OPT_ROUTE_INFO		24	/* RFC 4191 */
310 #define ND_OPT_RDNSS			25	/* RFC 6106 */
311 #define ND_OPT_DNSSL			31	/* RFC 6106 */
312 #define ND_OPT_MAX			31
313 
314 struct nd_opt_prefix_info {	/* prefix information */
315 	u_int8_t	nd_opt_pi_type;
316 	u_int8_t	nd_opt_pi_len;
317 	u_int8_t	nd_opt_pi_prefix_len;
318 	u_int8_t	nd_opt_pi_flags_reserved;
319 	u_int32_t	nd_opt_pi_valid_time;
320 	u_int32_t	nd_opt_pi_preferred_time;
321 	u_int32_t	nd_opt_pi_reserved2;
322 	struct in6_addr	nd_opt_pi_prefix;
323 } __packed;
324 
325 #define ND_OPT_PI_FLAG_ONLINK		0x80
326 #define ND_OPT_PI_FLAG_AUTO		0x40
327 
328 struct nd_opt_rd_hdr {		/* redirected header */
329 	u_int8_t	nd_opt_rh_type;
330 	u_int8_t	nd_opt_rh_len;
331 	u_int16_t	nd_opt_rh_reserved1;
332 	u_int32_t	nd_opt_rh_reserved2;
333 	/* followed by IP header and data */
334 } __packed;
335 
336 struct nd_opt_mtu {		/* MTU option */
337 	u_int8_t	nd_opt_mtu_type;
338 	u_int8_t	nd_opt_mtu_len;
339 	u_int16_t	nd_opt_mtu_reserved;
340 	u_int32_t	nd_opt_mtu_mtu;
341 } __packed;
342 
343 #define	ND_OPT_NONCE_LEN	((1 * 8) - 2)
344 #if ((ND_OPT_NONCE_LEN + 2) % 8) != 0
345 #error "(ND_OPT_NONCE_LEN + 2) must be a multiple of 8."
346 #endif
347 struct nd_opt_nonce {		/* nonce option */
348 	u_int8_t	nd_opt_nonce_type;
349 	u_int8_t	nd_opt_nonce_len;
350 	u_int8_t	nd_opt_nonce[ND_OPT_NONCE_LEN];
351 } __packed;
352 
353 struct nd_opt_route_info {	/* route info */
354 	u_int8_t	nd_opt_rti_type;
355 	u_int8_t	nd_opt_rti_len;
356 	u_int8_t	nd_opt_rti_prefixlen;
357 	u_int8_t	nd_opt_rti_flags;
358 	u_int32_t	nd_opt_rti_lifetime;
359 	/* prefix follows */
360 } __packed;
361 
362 struct nd_opt_rdnss {		/* RDNSS option (RFC 6106) */
363 	u_int8_t	nd_opt_rdnss_type;
364 	u_int8_t	nd_opt_rdnss_len;
365 	u_int16_t	nd_opt_rdnss_reserved;
366 	u_int32_t	nd_opt_rdnss_lifetime;
367 	/* followed by list of recursive DNS servers */
368 } __packed;
369 
370 struct nd_opt_dnssl {		/* DNSSL option (RFC 6106) */
371 	u_int8_t	nd_opt_dnssl_type;
372 	u_int8_t	nd_opt_dnssl_len;
373 	u_int16_t	nd_opt_dnssl_reserved;
374 	u_int32_t	nd_opt_dnssl_lifetime;
375 	/* followed by list of DNS search domains */
376 } __packed;
377 
378 /*
379  * icmp6 namelookup
380  */
381 
382 struct icmp6_namelookup {
383 	struct icmp6_hdr 	icmp6_nl_hdr;
384 	u_int8_t	icmp6_nl_nonce[8];
385 	int32_t		icmp6_nl_ttl;
386 #if 0
387 	u_int8_t	icmp6_nl_len;
388 	u_int8_t	icmp6_nl_name[3];
389 #endif
390 	/* could be followed by options */
391 } __packed;
392 
393 /*
394  * icmp6 node information
395  */
396 struct icmp6_nodeinfo {
397 	struct icmp6_hdr icmp6_ni_hdr;
398 	u_int8_t icmp6_ni_nonce[8];
399 	/* could be followed by reply data */
400 } __packed;
401 
402 #define ni_type		icmp6_ni_hdr.icmp6_type
403 #define ni_code		icmp6_ni_hdr.icmp6_code
404 #define ni_cksum	icmp6_ni_hdr.icmp6_cksum
405 #define ni_qtype	icmp6_ni_hdr.icmp6_data16[0]
406 #define ni_flags	icmp6_ni_hdr.icmp6_data16[1]
407 
408 #define NI_QTYPE_NOOP		0 /* NOOP  */
409 #define NI_QTYPE_SUPTYPES	1 /* Supported Qtypes */
410 #define NI_QTYPE_FQDN		2 /* FQDN (draft 04) */
411 #define NI_QTYPE_DNSNAME	2 /* DNS Name */
412 #define NI_QTYPE_NODEADDR	3 /* Node Addresses */
413 #define NI_QTYPE_IPV4ADDR	4 /* IPv4 Addresses */
414 
415 #if BYTE_ORDER == BIG_ENDIAN
416 #define NI_SUPTYPE_FLAG_COMPRESS	0x1
417 #define NI_FQDN_FLAG_VALIDTTL		0x1
418 #elif BYTE_ORDER == LITTLE_ENDIAN
419 #define NI_SUPTYPE_FLAG_COMPRESS	0x0100
420 #define NI_FQDN_FLAG_VALIDTTL		0x0100
421 #endif
422 
423 #ifdef NAME_LOOKUPS_04
424 #if BYTE_ORDER == BIG_ENDIAN
425 #define NI_NODEADDR_FLAG_LINKLOCAL	0x1
426 #define NI_NODEADDR_FLAG_SITELOCAL	0x2
427 #define NI_NODEADDR_FLAG_GLOBAL		0x4
428 #define NI_NODEADDR_FLAG_ALL		0x8
429 #define NI_NODEADDR_FLAG_TRUNCATE	0x10
430 #define NI_NODEADDR_FLAG_ANYCAST	0x20 /* just experimental. not in spec */
431 #elif BYTE_ORDER == LITTLE_ENDIAN
432 #define NI_NODEADDR_FLAG_LINKLOCAL	0x0100
433 #define NI_NODEADDR_FLAG_SITELOCAL	0x0200
434 #define NI_NODEADDR_FLAG_GLOBAL		0x0400
435 #define NI_NODEADDR_FLAG_ALL		0x0800
436 #define NI_NODEADDR_FLAG_TRUNCATE	0x1000
437 #define NI_NODEADDR_FLAG_ANYCAST	0x2000 /* just experimental. not in spec */
438 #endif
439 #else  /* draft-ietf-ipngwg-icmp-name-lookups-05 (and later?) */
440 #if BYTE_ORDER == BIG_ENDIAN
441 #define NI_NODEADDR_FLAG_TRUNCATE	0x1
442 #define NI_NODEADDR_FLAG_ALL		0x2
443 #define NI_NODEADDR_FLAG_COMPAT		0x4
444 #define NI_NODEADDR_FLAG_LINKLOCAL	0x8
445 #define NI_NODEADDR_FLAG_SITELOCAL	0x10
446 #define NI_NODEADDR_FLAG_GLOBAL		0x20
447 #define NI_NODEADDR_FLAG_ANYCAST	0x40 /* just experimental. not in spec */
448 #elif BYTE_ORDER == LITTLE_ENDIAN
449 #define NI_NODEADDR_FLAG_TRUNCATE	0x0100
450 #define NI_NODEADDR_FLAG_ALL		0x0200
451 #define NI_NODEADDR_FLAG_COMPAT		0x0400
452 #define NI_NODEADDR_FLAG_LINKLOCAL	0x0800
453 #define NI_NODEADDR_FLAG_SITELOCAL	0x1000
454 #define NI_NODEADDR_FLAG_GLOBAL		0x2000
455 #define NI_NODEADDR_FLAG_ANYCAST	0x4000 /* just experimental. not in spec */
456 #endif
457 #endif
458 
459 struct ni_reply_fqdn {
460 	u_int32_t ni_fqdn_ttl;	/* TTL */
461 	u_int8_t ni_fqdn_namelen; /* length in octets of the FQDN */
462 	u_int8_t ni_fqdn_name[3]; /* XXX: alignment */
463 } __packed;
464 
465 /*
466  * Router Renumbering. as router-renum-08.txt
467  */
468 struct icmp6_router_renum {	/* router renumbering header */
469 	struct icmp6_hdr	rr_hdr;
470 	u_int8_t	rr_segnum;
471 	u_int8_t	rr_flags;
472 	u_int16_t	rr_maxdelay;
473 	u_int32_t	rr_reserved;
474 } __packed;
475 
476 #define ICMP6_RR_FLAGS_TEST		0x80
477 #define ICMP6_RR_FLAGS_REQRESULT	0x40
478 #define ICMP6_RR_FLAGS_FORCEAPPLY	0x20
479 #define ICMP6_RR_FLAGS_SPECSITE		0x10
480 #define ICMP6_RR_FLAGS_PREVDONE		0x08
481 
482 #define rr_type		rr_hdr.icmp6_type
483 #define rr_code		rr_hdr.icmp6_code
484 #define rr_cksum	rr_hdr.icmp6_cksum
485 #define rr_seqnum 	rr_hdr.icmp6_data32[0]
486 
487 struct rr_pco_match {		/* match prefix part */
488 	u_int8_t	rpm_code;
489 	u_int8_t	rpm_len;
490 	u_int8_t	rpm_ordinal;
491 	u_int8_t	rpm_matchlen;
492 	u_int8_t	rpm_minlen;
493 	u_int8_t	rpm_maxlen;
494 	u_int16_t	rpm_reserved;
495 	struct	in6_addr	rpm_prefix;
496 } __packed;
497 
498 #define RPM_PCO_ADD		1
499 #define RPM_PCO_CHANGE		2
500 #define RPM_PCO_SETGLOBAL	3
501 #define RPM_PCO_MAX		4
502 
503 struct rr_pco_use {		/* use prefix part */
504 	u_int8_t	rpu_uselen;
505 	u_int8_t	rpu_keeplen;
506 	u_int8_t	rpu_ramask;
507 	u_int8_t	rpu_raflags;
508 	u_int32_t	rpu_vltime;
509 	u_int32_t	rpu_pltime;
510 	u_int32_t	rpu_flags;
511 	struct	in6_addr rpu_prefix;
512 } __packed;
513 #define ICMP6_RR_PCOUSE_RAFLAGS_ONLINK	0x80
514 #define ICMP6_RR_PCOUSE_RAFLAGS_AUTO	0x40
515 
516 #if BYTE_ORDER == BIG_ENDIAN
517 #define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME     0x80000000
518 #define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME     0x40000000
519 #elif BYTE_ORDER == LITTLE_ENDIAN
520 #define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME     0x80
521 #define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME     0x40
522 #endif
523 
524 struct rr_result {		/* router renumbering result message */
525 	u_int16_t	rrr_flags;
526 	u_int8_t	rrr_ordinal;
527 	u_int8_t	rrr_matchedlen;
528 	u_int32_t	rrr_ifid;
529 	struct	in6_addr rrr_prefix;
530 } __packed;
531 #if BYTE_ORDER == BIG_ENDIAN
532 #define ICMP6_RR_RESULT_FLAGS_OOB		0x0002
533 #define ICMP6_RR_RESULT_FLAGS_FORBIDDEN		0x0001
534 #elif BYTE_ORDER == LITTLE_ENDIAN
535 #define ICMP6_RR_RESULT_FLAGS_OOB		0x0200
536 #define ICMP6_RR_RESULT_FLAGS_FORBIDDEN		0x0100
537 #endif
538 
539 /*
540  * icmp6 filter structures.
541  */
542 
543 struct icmp6_filter {
544 	u_int32_t icmp6_filt[8];
545 };
546 
547 #ifdef _KERNEL
548 #define	ICMP6_FILTER_SETPASSALL(filterp) \
549 do {								\
550 	int i; u_char *p;					\
551 	p = (u_char *)filterp;					\
552 	for (i = 0; i < sizeof(struct icmp6_filter); i++)	\
553 		p[i] = 0xff;					\
554 } while (/*CONSTCOND*/ 0)
555 #define	ICMP6_FILTER_SETBLOCKALL(filterp) \
556 	bzero(filterp, sizeof(struct icmp6_filter))
557 #else /* _KERNEL */
558 #define	ICMP6_FILTER_SETPASSALL(filterp) \
559 	memset(filterp, 0xff, sizeof(struct icmp6_filter))
560 #define	ICMP6_FILTER_SETBLOCKALL(filterp) \
561 	memset(filterp, 0x00, sizeof(struct icmp6_filter))
562 #endif /* _KERNEL */
563 
564 #define	ICMP6_FILTER_SETPASS(type, filterp) \
565 	(((filterp)->icmp6_filt[(type) >> 5]) |= (1 << ((type) & 31)))
566 #define	ICMP6_FILTER_SETBLOCK(type, filterp) \
567 	(((filterp)->icmp6_filt[(type) >> 5]) &= ~(1 << ((type) & 31)))
568 #define	ICMP6_FILTER_WILLPASS(type, filterp) \
569 	((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) != 0)
570 #define	ICMP6_FILTER_WILLBLOCK(type, filterp) \
571 	((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) == 0)
572 
573 /*
574  * Variables related to this implementation
575  * of the internet control message protocol version 6.
576  */
577 struct icmp6errstat {
578 	uint64_t icp6errs_dst_unreach_noroute;
579 	uint64_t icp6errs_dst_unreach_admin;
580 	uint64_t icp6errs_dst_unreach_beyondscope;
581 	uint64_t icp6errs_dst_unreach_addr;
582 	uint64_t icp6errs_dst_unreach_noport;
583 	uint64_t icp6errs_packet_too_big;
584 	uint64_t icp6errs_time_exceed_transit;
585 	uint64_t icp6errs_time_exceed_reassembly;
586 	uint64_t icp6errs_paramprob_header;
587 	uint64_t icp6errs_paramprob_nextheader;
588 	uint64_t icp6errs_paramprob_option;
589 	uint64_t icp6errs_redirect; /* we regard redirect as an error here */
590 	uint64_t icp6errs_unknown;
591 };
592 
593 struct icmp6stat {
594 /* statistics related to icmp6 packets generated */
595 	uint64_t icp6s_error;		/* # of calls to icmp6_error */
596 	uint64_t icp6s_canterror;	/* no error 'cuz old was icmp */
597 	uint64_t icp6s_toofreq;		/* no error 'cuz rate limitation */
598 	uint64_t icp6s_outhist[256];
599 /* statistics related to input message processed */
600 	uint64_t icp6s_badcode;		/* icmp6_code out of range */
601 	uint64_t icp6s_tooshort;	/* packet < sizeof(struct icmp6_hdr) */
602 	uint64_t icp6s_checksum;	/* bad checksum */
603 	uint64_t icp6s_badlen;		/* calculated bound mismatch */
604 	uint64_t icp6s_dropped;		/* # of packets dropped waiting for a resolution */
605 	/*
606 	 * number of responses: this member is inherited from netinet code, but
607 	 * for netinet6 code, it is already available in icp6s_outhist[].
608 	 */
609 	uint64_t icp6s_reflect;
610 	uint64_t icp6s_inhist[256];
611 	uint64_t icp6s_nd_toomanyopt;	/* too many ND options */
612 	struct icmp6errstat icp6s_outerrhist;
613 #define icp6s_odst_unreach_noroute \
614 	icp6s_outerrhist.icp6errs_dst_unreach_noroute
615 #define icp6s_odst_unreach_admin icp6s_outerrhist.icp6errs_dst_unreach_admin
616 #define icp6s_odst_unreach_beyondscope \
617 	icp6s_outerrhist.icp6errs_dst_unreach_beyondscope
618 #define icp6s_odst_unreach_addr icp6s_outerrhist.icp6errs_dst_unreach_addr
619 #define icp6s_odst_unreach_noport icp6s_outerrhist.icp6errs_dst_unreach_noport
620 #define icp6s_opacket_too_big icp6s_outerrhist.icp6errs_packet_too_big
621 #define icp6s_otime_exceed_transit \
622 	icp6s_outerrhist.icp6errs_time_exceed_transit
623 #define icp6s_otime_exceed_reassembly \
624 	icp6s_outerrhist.icp6errs_time_exceed_reassembly
625 #define icp6s_oparamprob_header icp6s_outerrhist.icp6errs_paramprob_header
626 #define icp6s_oparamprob_nextheader \
627 	icp6s_outerrhist.icp6errs_paramprob_nextheader
628 #define icp6s_oparamprob_option icp6s_outerrhist.icp6errs_paramprob_option
629 #define icp6s_oredirect icp6s_outerrhist.icp6errs_redirect
630 #define icp6s_ounknown icp6s_outerrhist.icp6errs_unknown
631 	uint64_t icp6s_pmtuchg;		/* path MTU changes */
632 	uint64_t icp6s_nd_badopt;	/* bad ND options */
633 	uint64_t icp6s_badns;		/* bad neighbor solicitation */
634 	uint64_t icp6s_badna;		/* bad neighbor advertisement */
635 	uint64_t icp6s_badrs;		/* bad router solicitation */
636 	uint64_t icp6s_badra;		/* bad router advertisement */
637 	uint64_t icp6s_badredirect;	/* bad redirect message */
638 	uint64_t icp6s_overflowdefrtr;	/* Too many default routers. */
639 	uint64_t icp6s_overflowprfx;	/* Too many prefixes. */
640 	uint64_t icp6s_overflownndp;	/* Too many neighbour entries. */
641 	uint64_t icp6s_overflowredirect;/* Too many redirects. */
642 	uint64_t icp6s_invlhlim;	/* Invalid hop limit. */
643 	uint64_t icp6s_spare[32];
644 };
645 
646 #ifdef _KERNEL
647 #include <sys/counter.h>
648 
649 VNET_PCPUSTAT_DECLARE(struct icmp6stat, icmp6stat);
650 /*
651  * In-kernel consumers can use these accessor macros directly to update
652  * stats.
653  */
654 #define	ICMP6STAT_ADD(name, val)	\
655     VNET_PCPUSTAT_ADD(struct icmp6stat, icmp6stat, name, (val))
656 #define	ICMP6STAT_INC(name)		ICMP6STAT_ADD(name, 1)
657 
658 /*
659  * Kernel module consumers must use this accessor macro.
660  */
661 void	kmod_icmp6stat_inc(int statnum);
662 #define	KMOD_ICMP6STAT_INC(name)	\
663     kmod_icmp6stat_inc(offsetof(struct icmp6stat, name) / sizeof(uint64_t))
664 #endif
665 
666 /*
667  * Names for ICMP sysctl objects
668  */
669 #define ICMPV6CTL_STATS		1
670 #define ICMPV6CTL_REDIRACCEPT	2	/* accept/process redirects */
671 #define ICMPV6CTL_REDIRTIMEOUT	3	/* redirect cache time */
672 #if 0	/*obsoleted*/
673 #define ICMPV6CTL_ERRRATELIMIT	5	/* ICMPv6 error rate limitation */
674 #endif
675 #define ICMPV6CTL_ND6_PRUNE	6
676 #define ICMPV6CTL_ND6_DELAY	8
677 #define ICMPV6CTL_ND6_UMAXTRIES	9
678 #define ICMPV6CTL_ND6_MMAXTRIES		10
679 #define ICMPV6CTL_ND6_USELOOPBACK	11
680 /*#define ICMPV6CTL_ND6_PROXYALL	12	obsoleted, do not reuse here */
681 #define ICMPV6CTL_NODEINFO	13
682 #define ICMPV6CTL_ERRPPSLIMIT	14	/* ICMPv6 error pps limitation */
683 #define ICMPV6CTL_ND6_MAXNUDHINT	15
684 #define ICMPV6CTL_MTUDISC_HIWAT	16
685 #define ICMPV6CTL_MTUDISC_LOWAT	17
686 #define ICMPV6CTL_ND6_DEBUG	18
687 #define ICMPV6CTL_ND6_DRLIST	19
688 #define ICMPV6CTL_ND6_PRLIST	20
689 #define ICMPV6CTL_MLD_MAXSRCFILTER	21
690 #define ICMPV6CTL_MLD_SOMAXSRC	22
691 #define ICMPV6CTL_MLD_VERSION	23
692 #define ICMPV6CTL_ND6_MAXQLEN	24
693 #define ICMPV6CTL_NODEINFO_OLDMCPREFIX	25
694 #define ICMPV6CTL_MAXID		26
695 
696 #ifdef _KERNEL
697 # ifdef __STDC__
698 struct	nhop_object;
699 struct	rttimer;
700 struct	in6_multi;
701 # endif
702 void	icmp6_paramerror(struct mbuf *, int);
703 int	icmp6_errmap(const struct icmp6_hdr *);
704 void	icmp6_error(struct mbuf *, int, int, int);
705 void	icmp6_error2(struct mbuf *, int, int, int, struct ifnet *);
706 int	icmp6_input(struct mbuf **, int *, int);
707 void	icmp6_prepare(struct mbuf *);
708 void	icmp6_redirect_input(struct mbuf *, int);
709 void	icmp6_redirect_output(struct mbuf *, struct nhop_object *);
710 int	icmp6_ratelimit(const struct in6_addr *, const int, const int);
711 
712 struct	ip6ctlparam;
713 void	icmp6_mtudisc_update(struct ip6ctlparam *, int);
714 
715 /* XXX: is this the right place for these macros? */
716 #define icmp6_ifstat_inc(ifp, tag) \
717 do {								\
718 	if (ifp)						\
719 		counter_u64_add(((struct in6_ifextra *)		\
720 		    ((ifp)->if_afdata[AF_INET6]))->icmp6_ifstat[\
721 		    offsetof(struct icmp6_ifstat, tag) / sizeof(uint64_t)], 1);\
722 } while (/*CONSTCOND*/ 0)
723 
724 #define icmp6_ifoutstat_inc(ifp, type, code) \
725 do { \
726 		icmp6_ifstat_inc(ifp, ifs6_out_msg); \
727  		if (type < ICMP6_INFOMSG_MASK) \
728  			icmp6_ifstat_inc(ifp, ifs6_out_error); \
729 		switch (type) { \
730 		 case ICMP6_DST_UNREACH: \
731 			 icmp6_ifstat_inc(ifp, ifs6_out_dstunreach); \
732 			 if (code == ICMP6_DST_UNREACH_ADMIN) \
733 				 icmp6_ifstat_inc(ifp, ifs6_out_adminprohib); \
734 			 break; \
735 		 case ICMP6_PACKET_TOO_BIG: \
736 			 icmp6_ifstat_inc(ifp, ifs6_out_pkttoobig); \
737 			 break; \
738 		 case ICMP6_TIME_EXCEEDED: \
739 			 icmp6_ifstat_inc(ifp, ifs6_out_timeexceed); \
740 			 break; \
741 		 case ICMP6_PARAM_PROB: \
742 			 icmp6_ifstat_inc(ifp, ifs6_out_paramprob); \
743 			 break; \
744 		 case ICMP6_ECHO_REQUEST: \
745 			 icmp6_ifstat_inc(ifp, ifs6_out_echo); \
746 			 break; \
747 		 case ICMP6_ECHO_REPLY: \
748 			 icmp6_ifstat_inc(ifp, ifs6_out_echoreply); \
749 			 break; \
750 		 case MLD_LISTENER_QUERY: \
751 			 icmp6_ifstat_inc(ifp, ifs6_out_mldquery); \
752 			 break; \
753 		 case MLD_LISTENER_REPORT: \
754 			 icmp6_ifstat_inc(ifp, ifs6_out_mldreport); \
755 			 break; \
756 		 case MLD_LISTENER_DONE: \
757 			 icmp6_ifstat_inc(ifp, ifs6_out_mlddone); \
758 			 break; \
759 		 case ND_ROUTER_SOLICIT: \
760 			 icmp6_ifstat_inc(ifp, ifs6_out_routersolicit); \
761 			 break; \
762 		 case ND_ROUTER_ADVERT: \
763 			 icmp6_ifstat_inc(ifp, ifs6_out_routeradvert); \
764 			 break; \
765 		 case ND_NEIGHBOR_SOLICIT: \
766 			 icmp6_ifstat_inc(ifp, ifs6_out_neighborsolicit); \
767 			 break; \
768 		 case ND_NEIGHBOR_ADVERT: \
769 			 icmp6_ifstat_inc(ifp, ifs6_out_neighboradvert); \
770 			 break; \
771 		 case ND_REDIRECT: \
772 			 icmp6_ifstat_inc(ifp, ifs6_out_redirect); \
773 			 break; \
774 		} \
775 } while (/*CONSTCOND*/ 0)
776 
777 VNET_DECLARE(int, icmp6_rediraccept);	/* accept/process redirects */
778 VNET_DECLARE(int, icmp6_redirtimeout);	/* cache time for redirect routes */
779 
780 #define	V_icmp6_rediraccept	VNET(icmp6_rediraccept)
781 #define	V_icmp6_redirtimeout	VNET(icmp6_redirtimeout)
782 
783 #define ICMP6_NODEINFO_FQDNOK		0x1
784 #define ICMP6_NODEINFO_NODEADDROK	0x2
785 #define ICMP6_NODEINFO_TMPADDROK	0x4
786 #define ICMP6_NODEINFO_GLOBALOK		0x8
787 #endif /* _KERNEL */
788 
789 #endif /* not _NETINET_ICMP6_H_ */
790