xref: /freebsd/sys/netinet/icmp6.h (revision 7fdf597e96a02165cfe22ff357b857d5fa15ed8a)
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 #include <sys/stdint.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_PREF64			38	/* RFC 8781 */
313 #define ND_OPT_MAX			38
314 
315 struct nd_opt_prefix_info {	/* prefix information */
316 	u_int8_t	nd_opt_pi_type;
317 	u_int8_t	nd_opt_pi_len;
318 	u_int8_t	nd_opt_pi_prefix_len;
319 	u_int8_t	nd_opt_pi_flags_reserved;
320 	u_int32_t	nd_opt_pi_valid_time;
321 	u_int32_t	nd_opt_pi_preferred_time;
322 	u_int32_t	nd_opt_pi_reserved2;
323 	struct in6_addr	nd_opt_pi_prefix;
324 } __packed;
325 
326 #define ND_OPT_PI_FLAG_ONLINK		0x80
327 #define ND_OPT_PI_FLAG_AUTO		0x40
328 
329 struct nd_opt_rd_hdr {		/* redirected header */
330 	u_int8_t	nd_opt_rh_type;
331 	u_int8_t	nd_opt_rh_len;
332 	u_int16_t	nd_opt_rh_reserved1;
333 	u_int32_t	nd_opt_rh_reserved2;
334 	/* followed by IP header and data */
335 } __packed;
336 
337 struct nd_opt_mtu {		/* MTU option */
338 	u_int8_t	nd_opt_mtu_type;
339 	u_int8_t	nd_opt_mtu_len;
340 	u_int16_t	nd_opt_mtu_reserved;
341 	u_int32_t	nd_opt_mtu_mtu;
342 } __packed;
343 
344 #define	ND_OPT_NONCE_LEN	((1 * 8) - 2)
345 #if ((ND_OPT_NONCE_LEN + 2) % 8) != 0
346 #error "(ND_OPT_NONCE_LEN + 2) must be a multiple of 8."
347 #endif
348 struct nd_opt_nonce {		/* nonce option */
349 	u_int8_t	nd_opt_nonce_type;
350 	u_int8_t	nd_opt_nonce_len;
351 	u_int8_t	nd_opt_nonce[ND_OPT_NONCE_LEN];
352 } __packed;
353 
354 struct nd_opt_route_info {	/* route info */
355 	u_int8_t	nd_opt_rti_type;
356 	u_int8_t	nd_opt_rti_len;
357 	u_int8_t	nd_opt_rti_prefixlen;
358 	u_int8_t	nd_opt_rti_flags;
359 	u_int32_t	nd_opt_rti_lifetime;
360 	/* prefix follows */
361 } __packed;
362 
363 struct nd_opt_rdnss {		/* RDNSS option (RFC 6106) */
364 	u_int8_t	nd_opt_rdnss_type;
365 	u_int8_t	nd_opt_rdnss_len;
366 	u_int16_t	nd_opt_rdnss_reserved;
367 	u_int32_t	nd_opt_rdnss_lifetime;
368 	/* followed by list of recursive DNS servers */
369 } __packed;
370 
371 struct nd_opt_dnssl {		/* DNSSL option (RFC 6106) */
372 	u_int8_t	nd_opt_dnssl_type;
373 	u_int8_t	nd_opt_dnssl_len;
374 	u_int16_t	nd_opt_dnssl_reserved;
375 	u_int32_t	nd_opt_dnssl_lifetime;
376 	/* followed by list of DNS search domains */
377 } __packed;
378 
379 struct nd_opt_pref64 {		/* PREF64 option (RFC 8781) */
380 	uint8_t		nd_opt_pref64_type;
381 	uint8_t		nd_opt_pref64_len;
382 	/* bits 0-12 are the SL, bits 13-15 are the PLC */
383 	uint16_t	nd_opt_pref64_sl_plc;
384 	char		nd_opt_prefix[12];
385 } __packed;
386 
387 /*
388  * icmp6 namelookup
389  */
390 
391 struct icmp6_namelookup {
392 	struct icmp6_hdr 	icmp6_nl_hdr;
393 	u_int8_t	icmp6_nl_nonce[8];
394 	int32_t		icmp6_nl_ttl;
395 #if 0
396 	u_int8_t	icmp6_nl_len;
397 	u_int8_t	icmp6_nl_name[3];
398 #endif
399 	/* could be followed by options */
400 } __packed;
401 
402 /*
403  * icmp6 node information
404  */
405 struct icmp6_nodeinfo {
406 	struct icmp6_hdr icmp6_ni_hdr;
407 	u_int8_t icmp6_ni_nonce[8];
408 	/* could be followed by reply data */
409 } __packed;
410 
411 #define ni_type		icmp6_ni_hdr.icmp6_type
412 #define ni_code		icmp6_ni_hdr.icmp6_code
413 #define ni_cksum	icmp6_ni_hdr.icmp6_cksum
414 #define ni_qtype	icmp6_ni_hdr.icmp6_data16[0]
415 #define ni_flags	icmp6_ni_hdr.icmp6_data16[1]
416 
417 #define NI_QTYPE_NOOP		0 /* NOOP  */
418 #define NI_QTYPE_SUPTYPES	1 /* Supported Qtypes */
419 #define NI_QTYPE_FQDN		2 /* FQDN (draft 04) */
420 #define NI_QTYPE_DNSNAME	2 /* DNS Name */
421 #define NI_QTYPE_NODEADDR	3 /* Node Addresses */
422 #define NI_QTYPE_IPV4ADDR	4 /* IPv4 Addresses */
423 
424 #if BYTE_ORDER == BIG_ENDIAN
425 #define NI_SUPTYPE_FLAG_COMPRESS	0x1
426 #define NI_FQDN_FLAG_VALIDTTL		0x1
427 #elif BYTE_ORDER == LITTLE_ENDIAN
428 #define NI_SUPTYPE_FLAG_COMPRESS	0x0100
429 #define NI_FQDN_FLAG_VALIDTTL		0x0100
430 #endif
431 
432 #ifdef NAME_LOOKUPS_04
433 #if BYTE_ORDER == BIG_ENDIAN
434 #define NI_NODEADDR_FLAG_LINKLOCAL	0x1
435 #define NI_NODEADDR_FLAG_SITELOCAL	0x2
436 #define NI_NODEADDR_FLAG_GLOBAL		0x4
437 #define NI_NODEADDR_FLAG_ALL		0x8
438 #define NI_NODEADDR_FLAG_TRUNCATE	0x10
439 #define NI_NODEADDR_FLAG_ANYCAST	0x20 /* just experimental. not in spec */
440 #elif BYTE_ORDER == LITTLE_ENDIAN
441 #define NI_NODEADDR_FLAG_LINKLOCAL	0x0100
442 #define NI_NODEADDR_FLAG_SITELOCAL	0x0200
443 #define NI_NODEADDR_FLAG_GLOBAL		0x0400
444 #define NI_NODEADDR_FLAG_ALL		0x0800
445 #define NI_NODEADDR_FLAG_TRUNCATE	0x1000
446 #define NI_NODEADDR_FLAG_ANYCAST	0x2000 /* just experimental. not in spec */
447 #endif
448 #else  /* draft-ietf-ipngwg-icmp-name-lookups-05 (and later?) */
449 #if BYTE_ORDER == BIG_ENDIAN
450 #define NI_NODEADDR_FLAG_TRUNCATE	0x1
451 #define NI_NODEADDR_FLAG_ALL		0x2
452 #define NI_NODEADDR_FLAG_COMPAT		0x4
453 #define NI_NODEADDR_FLAG_LINKLOCAL	0x8
454 #define NI_NODEADDR_FLAG_SITELOCAL	0x10
455 #define NI_NODEADDR_FLAG_GLOBAL		0x20
456 #define NI_NODEADDR_FLAG_ANYCAST	0x40 /* just experimental. not in spec */
457 #elif BYTE_ORDER == LITTLE_ENDIAN
458 #define NI_NODEADDR_FLAG_TRUNCATE	0x0100
459 #define NI_NODEADDR_FLAG_ALL		0x0200
460 #define NI_NODEADDR_FLAG_COMPAT		0x0400
461 #define NI_NODEADDR_FLAG_LINKLOCAL	0x0800
462 #define NI_NODEADDR_FLAG_SITELOCAL	0x1000
463 #define NI_NODEADDR_FLAG_GLOBAL		0x2000
464 #define NI_NODEADDR_FLAG_ANYCAST	0x4000 /* just experimental. not in spec */
465 #endif
466 #endif
467 
468 struct ni_reply_fqdn {
469 	u_int32_t ni_fqdn_ttl;	/* TTL */
470 	u_int8_t ni_fqdn_namelen; /* length in octets of the FQDN */
471 	u_int8_t ni_fqdn_name[3]; /* XXX: alignment */
472 } __packed;
473 
474 /*
475  * Router Renumbering. as router-renum-08.txt
476  */
477 struct icmp6_router_renum {	/* router renumbering header */
478 	struct icmp6_hdr	rr_hdr;
479 	u_int8_t	rr_segnum;
480 	u_int8_t	rr_flags;
481 	u_int16_t	rr_maxdelay;
482 	u_int32_t	rr_reserved;
483 } __packed;
484 
485 #define ICMP6_RR_FLAGS_TEST		0x80
486 #define ICMP6_RR_FLAGS_REQRESULT	0x40
487 #define ICMP6_RR_FLAGS_FORCEAPPLY	0x20
488 #define ICMP6_RR_FLAGS_SPECSITE		0x10
489 #define ICMP6_RR_FLAGS_PREVDONE		0x08
490 
491 #define rr_type		rr_hdr.icmp6_type
492 #define rr_code		rr_hdr.icmp6_code
493 #define rr_cksum	rr_hdr.icmp6_cksum
494 #define rr_seqnum 	rr_hdr.icmp6_data32[0]
495 
496 struct rr_pco_match {		/* match prefix part */
497 	u_int8_t	rpm_code;
498 	u_int8_t	rpm_len;
499 	u_int8_t	rpm_ordinal;
500 	u_int8_t	rpm_matchlen;
501 	u_int8_t	rpm_minlen;
502 	u_int8_t	rpm_maxlen;
503 	u_int16_t	rpm_reserved;
504 	struct	in6_addr	rpm_prefix;
505 } __packed;
506 
507 #define RPM_PCO_ADD		1
508 #define RPM_PCO_CHANGE		2
509 #define RPM_PCO_SETGLOBAL	3
510 #define RPM_PCO_MAX		4
511 
512 struct rr_pco_use {		/* use prefix part */
513 	u_int8_t	rpu_uselen;
514 	u_int8_t	rpu_keeplen;
515 	u_int8_t	rpu_ramask;
516 	u_int8_t	rpu_raflags;
517 	u_int32_t	rpu_vltime;
518 	u_int32_t	rpu_pltime;
519 	u_int32_t	rpu_flags;
520 	struct	in6_addr rpu_prefix;
521 } __packed;
522 #define ICMP6_RR_PCOUSE_RAFLAGS_ONLINK	0x80
523 #define ICMP6_RR_PCOUSE_RAFLAGS_AUTO	0x40
524 
525 #if BYTE_ORDER == BIG_ENDIAN
526 #define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME     0x80000000
527 #define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME     0x40000000
528 #elif BYTE_ORDER == LITTLE_ENDIAN
529 #define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME     0x80
530 #define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME     0x40
531 #endif
532 
533 struct rr_result {		/* router renumbering result message */
534 	u_int16_t	rrr_flags;
535 	u_int8_t	rrr_ordinal;
536 	u_int8_t	rrr_matchedlen;
537 	u_int32_t	rrr_ifid;
538 	struct	in6_addr rrr_prefix;
539 } __packed;
540 #if BYTE_ORDER == BIG_ENDIAN
541 #define ICMP6_RR_RESULT_FLAGS_OOB		0x0002
542 #define ICMP6_RR_RESULT_FLAGS_FORBIDDEN		0x0001
543 #elif BYTE_ORDER == LITTLE_ENDIAN
544 #define ICMP6_RR_RESULT_FLAGS_OOB		0x0200
545 #define ICMP6_RR_RESULT_FLAGS_FORBIDDEN		0x0100
546 #endif
547 
548 /*
549  * icmp6 filter structures.
550  */
551 
552 struct icmp6_filter {
553 	u_int32_t icmp6_filt[8];
554 };
555 
556 #ifdef _KERNEL
557 #define	ICMP6_FILTER_SETPASSALL(filterp) \
558 do {								\
559 	int i; u_char *p;					\
560 	p = (u_char *)filterp;					\
561 	for (i = 0; i < sizeof(struct icmp6_filter); i++)	\
562 		p[i] = 0xff;					\
563 } while (/*CONSTCOND*/ 0)
564 #define	ICMP6_FILTER_SETBLOCKALL(filterp) \
565 	bzero(filterp, sizeof(struct icmp6_filter))
566 #else /* _KERNEL */
567 #define	ICMP6_FILTER_SETPASSALL(filterp) \
568 	memset(filterp, 0xff, sizeof(struct icmp6_filter))
569 #define	ICMP6_FILTER_SETBLOCKALL(filterp) \
570 	memset(filterp, 0x00, sizeof(struct icmp6_filter))
571 #endif /* _KERNEL */
572 
573 #define	ICMP6_FILTER_SETPASS(type, filterp) \
574 	(((filterp)->icmp6_filt[(type) >> 5]) |= (1 << ((type) & 31)))
575 #define	ICMP6_FILTER_SETBLOCK(type, filterp) \
576 	(((filterp)->icmp6_filt[(type) >> 5]) &= ~(1 << ((type) & 31)))
577 #define	ICMP6_FILTER_WILLPASS(type, filterp) \
578 	((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) != 0)
579 #define	ICMP6_FILTER_WILLBLOCK(type, filterp) \
580 	((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) == 0)
581 
582 /*
583  * Variables related to this implementation
584  * of the internet control message protocol version 6.
585  */
586 struct icmp6stat {
587 /* statistics related to icmp6 packets generated */
588 	uint64_t icp6s_error;		/* # of calls to icmp6_error */
589 	uint64_t icp6s_canterror;	/* no error 'cuz old was icmp */
590 	uint64_t icp6s_toofreq;		/* no error 'cuz rate limitation */
591 	uint64_t icp6s_outhist[256];
592 /* statistics related to input message processed */
593 	uint64_t icp6s_badcode;		/* icmp6_code out of range */
594 	uint64_t icp6s_tooshort;	/* packet < sizeof(struct icmp6_hdr) */
595 	uint64_t icp6s_checksum;	/* bad checksum */
596 	uint64_t icp6s_badlen;		/* calculated bound mismatch */
597 	uint64_t icp6s_dropped;		/* # of packets dropped waiting for a resolution */
598 	/*
599 	 * number of responses: this member is inherited from netinet code, but
600 	 * for netinet6 code, it is already available in icp6s_outhist[].
601 	 */
602 	uint64_t icp6s_reflect;
603 	uint64_t icp6s_inhist[256];
604 	uint64_t icp6s_nd_toomanyopt;	/* too many ND options */
605 	uint64_t icp6s_odst_unreach_noroute;
606 	uint64_t icp6s_odst_unreach_admin;
607 	uint64_t icp6s_odst_unreach_beyondscope;
608 	uint64_t icp6s_odst_unreach_addr;
609 	uint64_t icp6s_odst_unreach_noport;
610 	uint64_t icp6s_opacket_too_big;
611 	uint64_t icp6s_otime_exceed_transit;
612 	uint64_t icp6s_otime_exceed_reassembly;
613 	uint64_t icp6s_oparamprob_header;
614 	uint64_t icp6s_oparamprob_nextheader;
615 	uint64_t icp6s_oparamprob_option;
616 	uint64_t icp6s_oredirect;
617 	uint64_t icp6s_ounknown;
618 	uint64_t icp6s_pmtuchg;		/* path MTU changes */
619 	uint64_t icp6s_nd_badopt;	/* bad ND options */
620 	uint64_t icp6s_badns;		/* bad neighbor solicitation */
621 	uint64_t icp6s_badna;		/* bad neighbor advertisement */
622 	uint64_t icp6s_badrs;		/* bad router solicitation */
623 	uint64_t icp6s_badra;		/* bad router advertisement */
624 	uint64_t icp6s_badredirect;	/* bad redirect message */
625 	uint64_t icp6s_overflowdefrtr;	/* Too many default routers. */
626 	uint64_t icp6s_overflowprfx;	/* Too many prefixes. */
627 	uint64_t icp6s_overflownndp;	/* Too many neighbour entries. */
628 	uint64_t icp6s_overflowredirect;/* Too many redirects. */
629 	uint64_t icp6s_invlhlim;	/* Invalid hop limit. */
630 	uint64_t icp6s_spare[32];
631 };
632 
633 #ifdef _KERNEL
634 #include <sys/counter.h>
635 #include <netinet/in_kdtrace.h>
636 
637 #ifdef SYSCTL_DECL
638 SYSCTL_DECL(_net_inet6_icmp6);
639 #endif
640 
641 VNET_PCPUSTAT_DECLARE(struct icmp6stat, icmp6stat);
642 /*
643  * In-kernel consumers can use these accessor macros directly to update
644  * stats.
645  */
646 #define ICMP6STAT_ADD(name, val)                                             \
647 	do {                                                                 \
648 		MIB_SDT_PROBE1(icmp6, count, name, (val));                   \
649 		VNET_PCPUSTAT_ADD(struct icmp6stat, icmp6stat, name, (val)); \
650 	} while (0)
651 #define ICMP6STAT_INC(name) ICMP6STAT_ADD(name, 1)
652 #define ICMP6STAT_INC2(name, type)                                       \
653 	do {                                                             \
654 		MIB_SDT_PROBE2(icmp6, count, name, 1, type);             \
655 		VNET_PCPUSTAT_ADD(struct icmp6stat, icmp6stat, name, 1); \
656 	} while (0)
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 	do {                                                              \
664 		MIB_SDT_PROBE1(icmp6, count, name, 1);                    \
665 		kmod_icmp6stat_inc(                                       \
666 		    offsetof(struct icmp6stat, name) / sizeof(uint64_t)); \
667 	} while (0)
668 #endif
669 
670 /*
671  * Names for ICMP sysctl objects
672  */
673 #define ICMPV6CTL_STATS		1
674 #define ICMPV6CTL_REDIRACCEPT	2	/* accept/process redirects */
675 #define ICMPV6CTL_REDIRTIMEOUT	3	/* redirect cache time */
676 #if 0	/*obsoleted*/
677 #define ICMPV6CTL_ERRRATELIMIT	5	/* ICMPv6 error rate limitation */
678 #endif
679 #define ICMPV6CTL_ND6_PRUNE	6
680 #define ICMPV6CTL_ND6_DELAY	8
681 #define ICMPV6CTL_ND6_UMAXTRIES	9
682 #define ICMPV6CTL_ND6_MMAXTRIES		10
683 #define ICMPV6CTL_ND6_USELOOPBACK	11
684 /*#define ICMPV6CTL_ND6_PROXYALL	12	obsoleted, do not reuse here */
685 #define ICMPV6CTL_NODEINFO	13
686 #define ICMPV6CTL_ERRPPSLIMIT	14	/* ICMPv6 error pps limitation */
687 #define ICMPV6CTL_ND6_MAXNUDHINT	15
688 #define ICMPV6CTL_MTUDISC_HIWAT	16
689 #define ICMPV6CTL_MTUDISC_LOWAT	17
690 #define ICMPV6CTL_ND6_DEBUG	18
691 #define ICMPV6CTL_ND6_DRLIST	19
692 #define ICMPV6CTL_ND6_PRLIST	20
693 #define ICMPV6CTL_MLD_MAXSRCFILTER	21
694 #define ICMPV6CTL_MLD_SOMAXSRC	22
695 #define ICMPV6CTL_MLD_VERSION	23
696 #define ICMPV6CTL_ND6_MAXQLEN	24
697 #define ICMPV6CTL_NODEINFO_OLDMCPREFIX	25
698 #define ICMPV6CTL_MAXID		26
699 
700 #ifdef _KERNEL
701 # ifdef __STDC__
702 struct	nhop_object;
703 struct	rttimer;
704 struct	in6_multi;
705 # endif
706 void	icmp6_paramerror(struct mbuf *, int);
707 int	icmp6_errmap(const struct icmp6_hdr *);
708 void	icmp6_error(struct mbuf *, int, int, int);
709 void	icmp6_error2(struct mbuf *, int, int, int, struct ifnet *);
710 int	icmp6_input(struct mbuf **, int *, int);
711 void	icmp6_prepare(struct mbuf *);
712 void	icmp6_redirect_input(struct mbuf *, int);
713 void	icmp6_redirect_output(struct mbuf *, struct nhop_object *);
714 int	icmp6_ratelimit(const struct in6_addr *, const int, const int);
715 
716 struct	ip6ctlparam;
717 void	icmp6_mtudisc_update(struct ip6ctlparam *, int);
718 
719 /* XXX: is this the right place for these macros? */
720 #define icmp6_ifstat_inc(ifp, tag) \
721 do {								\
722 	if (ifp)						\
723 		counter_u64_add(((struct in6_ifextra *)		\
724 		    ((ifp)->if_afdata[AF_INET6]))->icmp6_ifstat[\
725 		    offsetof(struct icmp6_ifstat, tag) / sizeof(uint64_t)], 1);\
726 } while (/*CONSTCOND*/ 0)
727 
728 #define icmp6_ifoutstat_inc(ifp, type, code) \
729 do { \
730 		icmp6_ifstat_inc(ifp, ifs6_out_msg); \
731  		if (type < ICMP6_INFOMSG_MASK) \
732  			icmp6_ifstat_inc(ifp, ifs6_out_error); \
733 		switch (type) { \
734 		 case ICMP6_DST_UNREACH: \
735 			 icmp6_ifstat_inc(ifp, ifs6_out_dstunreach); \
736 			 if (code == ICMP6_DST_UNREACH_ADMIN) \
737 				 icmp6_ifstat_inc(ifp, ifs6_out_adminprohib); \
738 			 break; \
739 		 case ICMP6_PACKET_TOO_BIG: \
740 			 icmp6_ifstat_inc(ifp, ifs6_out_pkttoobig); \
741 			 break; \
742 		 case ICMP6_TIME_EXCEEDED: \
743 			 icmp6_ifstat_inc(ifp, ifs6_out_timeexceed); \
744 			 break; \
745 		 case ICMP6_PARAM_PROB: \
746 			 icmp6_ifstat_inc(ifp, ifs6_out_paramprob); \
747 			 break; \
748 		 case ICMP6_ECHO_REQUEST: \
749 			 icmp6_ifstat_inc(ifp, ifs6_out_echo); \
750 			 break; \
751 		 case ICMP6_ECHO_REPLY: \
752 			 icmp6_ifstat_inc(ifp, ifs6_out_echoreply); \
753 			 break; \
754 		 case MLD_LISTENER_QUERY: \
755 			 icmp6_ifstat_inc(ifp, ifs6_out_mldquery); \
756 			 break; \
757 		 case MLD_LISTENER_REPORT: \
758 			 icmp6_ifstat_inc(ifp, ifs6_out_mldreport); \
759 			 break; \
760 		 case MLD_LISTENER_DONE: \
761 			 icmp6_ifstat_inc(ifp, ifs6_out_mlddone); \
762 			 break; \
763 		 case ND_ROUTER_SOLICIT: \
764 			 icmp6_ifstat_inc(ifp, ifs6_out_routersolicit); \
765 			 break; \
766 		 case ND_ROUTER_ADVERT: \
767 			 icmp6_ifstat_inc(ifp, ifs6_out_routeradvert); \
768 			 break; \
769 		 case ND_NEIGHBOR_SOLICIT: \
770 			 icmp6_ifstat_inc(ifp, ifs6_out_neighborsolicit); \
771 			 break; \
772 		 case ND_NEIGHBOR_ADVERT: \
773 			 icmp6_ifstat_inc(ifp, ifs6_out_neighboradvert); \
774 			 break; \
775 		 case ND_REDIRECT: \
776 			 icmp6_ifstat_inc(ifp, ifs6_out_redirect); \
777 			 break; \
778 		} \
779 } while (/*CONSTCOND*/ 0)
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