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