xref: /f-stack/tools/compat/include/netinet/icmp6.h (revision d4a07e70)
1 /*	$FreeBSD$	*/
2 /*	$KAME: icmp6.h,v 1.46 2001/04/27 15:09:48 itojun Exp $	*/
3 
4 /*-
5  * SPDX-License-Identifier: BSD-3-Clause
6  *
7  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. Neither the name of the project nor the names of its contributors
19  *    may be used to endorse or promote products derived from this software
20  *    without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  */
34 
35 /*-
36  * Copyright (c) 1982, 1986, 1993
37  *	The Regents of the University of California.  All rights reserved.
38  *
39  * Redistribution and use in source and binary forms, with or without
40  * modification, are permitted provided that the following conditions
41  * are met:
42  * 1. Redistributions of source code must retain the above copyright
43  *    notice, this list of conditions and the following disclaimer.
44  * 2. Redistributions in binary form must reproduce the above copyright
45  *    notice, this list of conditions and the following disclaimer in the
46  *    documentation and/or other materials provided with the distribution.
47  * 3. Neither the name of the University nor the names of its contributors
48  *    may be used to endorse or promote products derived from this software
49  *    without specific prior written permission.
50  *
51  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
52  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
54  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
55  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
57  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61  * SUCH DAMAGE.
62  *
63  *	@(#)ip_icmp.h	8.1 (Berkeley) 6/10/93
64  */
65 
66 #ifndef _NETINET_ICMP6_H_
67 #define _NETINET_ICMP6_H_
68 
69 #ifdef FSTACK
70 #define __packed __attribute__((__packed__))
71 #endif
72 
73 #define ICMPV6_PLD_MAXLEN	1232	/* IPV6_MMTU - sizeof(struct ip6_hdr)
74 					   - sizeof(struct icmp6_hdr) */
75 
76 struct icmp6_hdr {
77 	u_int8_t	icmp6_type;	/* type field */
78 	u_int8_t	icmp6_code;	/* code field */
79 	u_int16_t	icmp6_cksum;	/* checksum field */
80 	union {
81 		u_int32_t	icmp6_un_data32[1]; /* type-specific field */
82 		u_int16_t	icmp6_un_data16[2]; /* type-specific field */
83 		u_int8_t	icmp6_un_data8[4];  /* type-specific field */
84 	} icmp6_dataun;
85 } __packed;
86 
87 #define icmp6_data32	icmp6_dataun.icmp6_un_data32
88 #define icmp6_data16	icmp6_dataun.icmp6_un_data16
89 #define icmp6_data8	icmp6_dataun.icmp6_un_data8
90 #define icmp6_pptr	icmp6_data32[0]		/* parameter prob */
91 #define icmp6_mtu	icmp6_data32[0]		/* packet too big */
92 #define icmp6_id	icmp6_data16[0]		/* echo request/reply */
93 #define icmp6_seq	icmp6_data16[1]		/* echo request/reply */
94 #define icmp6_maxdelay	icmp6_data16[0]		/* mcast group membership */
95 
96 #define ICMP6_DST_UNREACH		1	/* dest unreachable, codes: */
97 #define ICMP6_PACKET_TOO_BIG		2	/* packet too big */
98 #define ICMP6_TIME_EXCEEDED		3	/* time exceeded, code: */
99 #define ICMP6_PARAM_PROB		4	/* ip6 header bad */
100 
101 #define ICMP6_ECHO_REQUEST		128	/* echo service */
102 #define ICMP6_ECHO_REPLY		129	/* echo reply */
103 #define MLD_LISTENER_QUERY		130 	/* multicast listener query */
104 #define MLD_LISTENER_REPORT		131	/* multicast listener report */
105 #define MLD_LISTENER_DONE		132	/* multicast listener done */
106 #define MLD_LISTENER_REDUCTION MLD_LISTENER_DONE /* RFC3542 definition */
107 
108 /* RFC2292 decls */
109 #define ICMP6_MEMBERSHIP_QUERY		130	/* group membership query */
110 #define ICMP6_MEMBERSHIP_REPORT		131	/* group membership report */
111 #define ICMP6_MEMBERSHIP_REDUCTION	132	/* group membership termination */
112 
113 #ifndef _KERNEL
114 /* the followings are for backward compatibility to old KAME apps. */
115 #define MLD6_LISTENER_QUERY	MLD_LISTENER_QUERY
116 #define MLD6_LISTENER_REPORT	MLD_LISTENER_REPORT
117 #define MLD6_LISTENER_DONE	MLD_LISTENER_DONE
118 #endif
119 
120 #define ND_ROUTER_SOLICIT		133	/* router solicitation */
121 #define ND_ROUTER_ADVERT		134	/* router advertisement */
122 #define ND_NEIGHBOR_SOLICIT		135	/* neighbor solicitation */
123 #define ND_NEIGHBOR_ADVERT		136	/* neighbor advertisement */
124 #define ND_REDIRECT			137	/* redirect */
125 
126 #define ICMP6_ROUTER_RENUMBERING	138	/* router renumbering */
127 
128 #define ICMP6_WRUREQUEST		139	/* who are you request */
129 #define ICMP6_WRUREPLY			140	/* who are you reply */
130 #define ICMP6_FQDN_QUERY		139	/* FQDN query */
131 #define ICMP6_FQDN_REPLY		140	/* FQDN reply */
132 #define ICMP6_NI_QUERY			139	/* node information request */
133 #define ICMP6_NI_REPLY			140	/* node information reply */
134 #define MLDV2_LISTENER_REPORT		143	/* RFC3810 listener report */
135 
136 /* The definitions below are experimental. TBA */
137 #define MLD_MTRACE_RESP			200	/* mtrace resp (to sender) */
138 #define MLD_MTRACE			201	/* mtrace messages */
139 
140 #ifndef _KERNEL
141 #define MLD6_MTRACE_RESP	MLD_MTRACE_RESP
142 #define MLD6_MTRACE		MLD_MTRACE
143 #endif
144 
145 #define ICMP6_MAXTYPE			201
146 
147 #define ICMP6_DST_UNREACH_NOROUTE	0	/* no route to destination */
148 #define ICMP6_DST_UNREACH_ADMIN	 	1	/* administratively prohibited */
149 #define ICMP6_DST_UNREACH_NOTNEIGHBOR	2	/* not a neighbor(obsolete) */
150 #define ICMP6_DST_UNREACH_BEYONDSCOPE	2	/* beyond scope of source address */
151 #define ICMP6_DST_UNREACH_ADDR		3	/* address unreachable */
152 #define ICMP6_DST_UNREACH_NOPORT	4	/* port unreachable */
153 #define ICMP6_DST_UNREACH_POLICY	5	/* failed ingress/egress policy */
154 #define ICMP6_DST_UNREACH_REJECT	6	/* Reject route to destination */
155 #define ICMP6_DST_UNREACH_SRCROUTE	7	/* Error in source routing header */
156 
157 #define ICMP6_TIME_EXCEED_TRANSIT 	0	/* ttl==0 in transit */
158 #define ICMP6_TIME_EXCEED_REASSEMBLY	1	/* ttl==0 in reass */
159 
160 #define ICMP6_PARAMPROB_HEADER 	 	0	/* erroneous header field */
161 #define ICMP6_PARAMPROB_NEXTHEADER	1	/* unrecognized next header */
162 #define ICMP6_PARAMPROB_OPTION		2	/* unrecognized option */
163 
164 #define ICMP6_INFOMSG_MASK		0x80	/* all informational messages */
165 
166 #define ICMP6_NI_SUBJ_IPV6	0	/* Query Subject is an IPv6 address */
167 #define ICMP6_NI_SUBJ_FQDN	1	/* Query Subject is a Domain name */
168 #define ICMP6_NI_SUBJ_IPV4	2	/* Query Subject is an IPv4 address */
169 
170 #define ICMP6_NI_SUCCESS	0	/* node information successful reply */
171 #define ICMP6_NI_REFUSED	1	/* node information request is refused */
172 #define ICMP6_NI_UNKNOWN	2	/* unknown Qtype */
173 
174 #define ICMP6_ROUTER_RENUMBERING_COMMAND  0	/* rr command */
175 #define ICMP6_ROUTER_RENUMBERING_RESULT   1	/* rr result */
176 #define ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET   255	/* rr seq num reset */
177 
178 /* Used in kernel only */
179 #define ND_REDIRECT_ONLINK	0	/* redirect to an on-link node */
180 #define ND_REDIRECT_ROUTER	1	/* redirect to a better router */
181 
182 /*
183  * Multicast Listener Discovery
184  */
185 struct mld_hdr {
186 	struct icmp6_hdr	mld_icmp6_hdr;
187 	struct in6_addr		mld_addr; /* multicast address */
188 } __packed;
189 
190 /* definitions to provide backward compatibility to old KAME applications */
191 #ifndef _KERNEL
192 #define mld6_hdr	mld_hdr
193 #define mld6_type	mld_type
194 #define mld6_code	mld_code
195 #define mld6_cksum	mld_cksum
196 #define mld6_maxdelay	mld_maxdelay
197 #define mld6_reserved	mld_reserved
198 #define mld6_addr	mld_addr
199 #endif
200 
201 /* shortcut macro definitions */
202 #define mld_type	mld_icmp6_hdr.icmp6_type
203 #define mld_code	mld_icmp6_hdr.icmp6_code
204 #define mld_cksum	mld_icmp6_hdr.icmp6_cksum
205 #define mld_maxdelay	mld_icmp6_hdr.icmp6_data16[0]
206 #define mld_reserved	mld_icmp6_hdr.icmp6_data16[1]
207 #define mld_v2_reserved	mld_icmp6_hdr.icmp6_data16[0]
208 #define mld_v2_numrecs	mld_icmp6_hdr.icmp6_data16[1]
209 
210 /*
211  * Neighbor Discovery
212  */
213 
214 struct nd_router_solicit {	/* router solicitation */
215 	struct icmp6_hdr 	nd_rs_hdr;
216 	/* could be followed by options */
217 } __packed;
218 
219 #define nd_rs_type	nd_rs_hdr.icmp6_type
220 #define nd_rs_code	nd_rs_hdr.icmp6_code
221 #define nd_rs_cksum	nd_rs_hdr.icmp6_cksum
222 #define nd_rs_reserved	nd_rs_hdr.icmp6_data32[0]
223 
224 struct nd_router_advert {	/* router advertisement */
225 	struct icmp6_hdr	nd_ra_hdr;
226 	u_int32_t		nd_ra_reachable;	/* reachable time */
227 	u_int32_t		nd_ra_retransmit;	/* retransmit timer */
228 	/* could be followed by options */
229 } __packed;
230 
231 #define nd_ra_type		nd_ra_hdr.icmp6_type
232 #define nd_ra_code		nd_ra_hdr.icmp6_code
233 #define nd_ra_cksum		nd_ra_hdr.icmp6_cksum
234 #define nd_ra_curhoplimit	nd_ra_hdr.icmp6_data8[0]
235 #define nd_ra_flags_reserved	nd_ra_hdr.icmp6_data8[1]
236 #define ND_RA_FLAG_MANAGED	0x80
237 #define ND_RA_FLAG_OTHER	0x40
238 #define ND_RA_FLAG_HA		0x20
239 
240 /*
241  * Router preference values based on draft-draves-ipngwg-router-selection-01.
242  * These are non-standard definitions.
243  */
244 #define ND_RA_FLAG_RTPREF_MASK	0x18 /* 00011000 */
245 
246 #define ND_RA_FLAG_RTPREF_HIGH	0x08 /* 00001000 */
247 #define ND_RA_FLAG_RTPREF_MEDIUM	0x00 /* 00000000 */
248 #define ND_RA_FLAG_RTPREF_LOW	0x18 /* 00011000 */
249 #define ND_RA_FLAG_RTPREF_RSV	0x10 /* 00010000 */
250 
251 #ifdef EXPERIMENTAL
252 #define	ND_RA_FLAG_IPV6_ONLY	0x02 /* draft-ietf-6man-ipv6only-flag */
253 #endif
254 
255 #define nd_ra_router_lifetime	nd_ra_hdr.icmp6_data16[1]
256 
257 struct nd_neighbor_solicit {	/* neighbor solicitation */
258 	struct icmp6_hdr	nd_ns_hdr;
259 	struct in6_addr		nd_ns_target;	/*target address */
260 	/* could be followed by options */
261 } __packed;
262 
263 #define nd_ns_type		nd_ns_hdr.icmp6_type
264 #define nd_ns_code		nd_ns_hdr.icmp6_code
265 #define nd_ns_cksum		nd_ns_hdr.icmp6_cksum
266 #define nd_ns_reserved		nd_ns_hdr.icmp6_data32[0]
267 
268 struct nd_neighbor_advert {	/* neighbor advertisement */
269 	struct icmp6_hdr	nd_na_hdr;
270 	struct in6_addr		nd_na_target;	/* target address */
271 	/* could be followed by options */
272 } __packed;
273 
274 #define nd_na_type		nd_na_hdr.icmp6_type
275 #define nd_na_code		nd_na_hdr.icmp6_code
276 #define nd_na_cksum		nd_na_hdr.icmp6_cksum
277 #define nd_na_flags_reserved	nd_na_hdr.icmp6_data32[0]
278 #if BYTE_ORDER == BIG_ENDIAN
279 #define ND_NA_FLAG_ROUTER		0x80000000
280 #define ND_NA_FLAG_SOLICITED		0x40000000
281 #define ND_NA_FLAG_OVERRIDE		0x20000000
282 #else
283 #if BYTE_ORDER == LITTLE_ENDIAN
284 #define ND_NA_FLAG_ROUTER		0x80
285 #define ND_NA_FLAG_SOLICITED		0x40
286 #define ND_NA_FLAG_OVERRIDE		0x20
287 #endif
288 #endif
289 
290 struct nd_redirect {		/* redirect */
291 	struct icmp6_hdr	nd_rd_hdr;
292 	struct in6_addr		nd_rd_target;	/* target address */
293 	struct in6_addr		nd_rd_dst;	/* destination address */
294 	/* could be followed by options */
295 } __packed;
296 
297 #define nd_rd_type		nd_rd_hdr.icmp6_type
298 #define nd_rd_code		nd_rd_hdr.icmp6_code
299 #define nd_rd_cksum		nd_rd_hdr.icmp6_cksum
300 #define nd_rd_reserved		nd_rd_hdr.icmp6_data32[0]
301 
302 struct nd_opt_hdr {		/* Neighbor discovery option header */
303 	u_int8_t	nd_opt_type;
304 	u_int8_t	nd_opt_len;
305 	/* followed by option specific data*/
306 } __packed;
307 
308 #define ND_OPT_SOURCE_LINKADDR		1
309 #define ND_OPT_TARGET_LINKADDR		2
310 #define ND_OPT_PREFIX_INFORMATION	3
311 #define ND_OPT_REDIRECTED_HEADER	4
312 #define ND_OPT_MTU			5
313 #define ND_OPT_NONCE			14	/* RFC 3971 */
314 #define ND_OPT_ROUTE_INFO		24	/* RFC 4191 */
315 #define ND_OPT_RDNSS			25	/* RFC 6106 */
316 #define ND_OPT_DNSSL			31	/* RFC 6106 */
317 #define ND_OPT_MAX			31
318 
319 struct nd_opt_prefix_info {	/* prefix information */
320 	u_int8_t	nd_opt_pi_type;
321 	u_int8_t	nd_opt_pi_len;
322 	u_int8_t	nd_opt_pi_prefix_len;
323 	u_int8_t	nd_opt_pi_flags_reserved;
324 	u_int32_t	nd_opt_pi_valid_time;
325 	u_int32_t	nd_opt_pi_preferred_time;
326 	u_int32_t	nd_opt_pi_reserved2;
327 	struct in6_addr	nd_opt_pi_prefix;
328 } __packed;
329 
330 #define ND_OPT_PI_FLAG_ONLINK		0x80
331 #define ND_OPT_PI_FLAG_AUTO		0x40
332 
333 struct nd_opt_rd_hdr {		/* redirected header */
334 	u_int8_t	nd_opt_rh_type;
335 	u_int8_t	nd_opt_rh_len;
336 	u_int16_t	nd_opt_rh_reserved1;
337 	u_int32_t	nd_opt_rh_reserved2;
338 	/* followed by IP header and data */
339 } __packed;
340 
341 struct nd_opt_mtu {		/* MTU option */
342 	u_int8_t	nd_opt_mtu_type;
343 	u_int8_t	nd_opt_mtu_len;
344 	u_int16_t	nd_opt_mtu_reserved;
345 	u_int32_t	nd_opt_mtu_mtu;
346 } __packed;
347 
348 #define	ND_OPT_NONCE_LEN	((1 * 8) - 2)
349 #if ((ND_OPT_NONCE_LEN + 2) % 8) != 0
350 #error "(ND_OPT_NONCE_LEN + 2) must be a multiple of 8."
351 #endif
352 struct nd_opt_nonce {		/* nonce option */
353 	u_int8_t	nd_opt_nonce_type;
354 	u_int8_t	nd_opt_nonce_len;
355 	u_int8_t	nd_opt_nonce[ND_OPT_NONCE_LEN];
356 } __packed;
357 
358 struct nd_opt_route_info {	/* route info */
359 	u_int8_t	nd_opt_rti_type;
360 	u_int8_t	nd_opt_rti_len;
361 	u_int8_t	nd_opt_rti_prefixlen;
362 	u_int8_t	nd_opt_rti_flags;
363 	u_int32_t	nd_opt_rti_lifetime;
364 	/* prefix follows */
365 } __packed;
366 
367 struct nd_opt_rdnss {		/* RDNSS option (RFC 6106) */
368 	u_int8_t	nd_opt_rdnss_type;
369 	u_int8_t	nd_opt_rdnss_len;
370 	u_int16_t	nd_opt_rdnss_reserved;
371 	u_int32_t	nd_opt_rdnss_lifetime;
372 	/* followed by list of recursive DNS servers */
373 } __packed;
374 
375 struct nd_opt_dnssl {		/* DNSSL option (RFC 6106) */
376 	u_int8_t	nd_opt_dnssl_type;
377 	u_int8_t	nd_opt_dnssl_len;
378 	u_int16_t	nd_opt_dnssl_reserved;
379 	u_int32_t	nd_opt_dnssl_lifetime;
380 	/* followed by list of DNS search domains */
381 } __packed;
382 
383 /*
384  * icmp6 namelookup
385  */
386 
387 struct icmp6_namelookup {
388 	struct icmp6_hdr 	icmp6_nl_hdr;
389 	u_int8_t	icmp6_nl_nonce[8];
390 	int32_t		icmp6_nl_ttl;
391 #if 0
392 	u_int8_t	icmp6_nl_len;
393 	u_int8_t	icmp6_nl_name[3];
394 #endif
395 	/* could be followed by options */
396 } __packed;
397 
398 /*
399  * icmp6 node information
400  */
401 struct icmp6_nodeinfo {
402 	struct icmp6_hdr icmp6_ni_hdr;
403 	u_int8_t icmp6_ni_nonce[8];
404 	/* could be followed by reply data */
405 } __packed;
406 
407 #define ni_type		icmp6_ni_hdr.icmp6_type
408 #define ni_code		icmp6_ni_hdr.icmp6_code
409 #define ni_cksum	icmp6_ni_hdr.icmp6_cksum
410 #define ni_qtype	icmp6_ni_hdr.icmp6_data16[0]
411 #define ni_flags	icmp6_ni_hdr.icmp6_data16[1]
412 
413 #define NI_QTYPE_NOOP		0 /* NOOP  */
414 #define NI_QTYPE_SUPTYPES	1 /* Supported Qtypes */
415 #define NI_QTYPE_FQDN		2 /* FQDN (draft 04) */
416 #define NI_QTYPE_DNSNAME	2 /* DNS Name */
417 #define NI_QTYPE_NODEADDR	3 /* Node Addresses */
418 #define NI_QTYPE_IPV4ADDR	4 /* IPv4 Addresses */
419 
420 #if BYTE_ORDER == BIG_ENDIAN
421 #define NI_SUPTYPE_FLAG_COMPRESS	0x1
422 #define NI_FQDN_FLAG_VALIDTTL		0x1
423 #elif BYTE_ORDER == LITTLE_ENDIAN
424 #define NI_SUPTYPE_FLAG_COMPRESS	0x0100
425 #define NI_FQDN_FLAG_VALIDTTL		0x0100
426 #endif
427 
428 #ifdef NAME_LOOKUPS_04
429 #if BYTE_ORDER == BIG_ENDIAN
430 #define NI_NODEADDR_FLAG_LINKLOCAL	0x1
431 #define NI_NODEADDR_FLAG_SITELOCAL	0x2
432 #define NI_NODEADDR_FLAG_GLOBAL		0x4
433 #define NI_NODEADDR_FLAG_ALL		0x8
434 #define NI_NODEADDR_FLAG_TRUNCATE	0x10
435 #define NI_NODEADDR_FLAG_ANYCAST	0x20 /* just experimental. not in spec */
436 #elif BYTE_ORDER == LITTLE_ENDIAN
437 #define NI_NODEADDR_FLAG_LINKLOCAL	0x0100
438 #define NI_NODEADDR_FLAG_SITELOCAL	0x0200
439 #define NI_NODEADDR_FLAG_GLOBAL		0x0400
440 #define NI_NODEADDR_FLAG_ALL		0x0800
441 #define NI_NODEADDR_FLAG_TRUNCATE	0x1000
442 #define NI_NODEADDR_FLAG_ANYCAST	0x2000 /* just experimental. not in spec */
443 #endif
444 #else  /* draft-ietf-ipngwg-icmp-name-lookups-05 (and later?) */
445 #if BYTE_ORDER == BIG_ENDIAN
446 #define NI_NODEADDR_FLAG_TRUNCATE	0x1
447 #define NI_NODEADDR_FLAG_ALL		0x2
448 #define NI_NODEADDR_FLAG_COMPAT		0x4
449 #define NI_NODEADDR_FLAG_LINKLOCAL	0x8
450 #define NI_NODEADDR_FLAG_SITELOCAL	0x10
451 #define NI_NODEADDR_FLAG_GLOBAL		0x20
452 #define NI_NODEADDR_FLAG_ANYCAST	0x40 /* just experimental. not in spec */
453 #elif BYTE_ORDER == LITTLE_ENDIAN
454 #define NI_NODEADDR_FLAG_TRUNCATE	0x0100
455 #define NI_NODEADDR_FLAG_ALL		0x0200
456 #define NI_NODEADDR_FLAG_COMPAT		0x0400
457 #define NI_NODEADDR_FLAG_LINKLOCAL	0x0800
458 #define NI_NODEADDR_FLAG_SITELOCAL	0x1000
459 #define NI_NODEADDR_FLAG_GLOBAL		0x2000
460 #define NI_NODEADDR_FLAG_ANYCAST	0x4000 /* just experimental. not in spec */
461 #endif
462 #endif
463 
464 struct ni_reply_fqdn {
465 	u_int32_t ni_fqdn_ttl;	/* TTL */
466 	u_int8_t ni_fqdn_namelen; /* length in octets of the FQDN */
467 	u_int8_t ni_fqdn_name[3]; /* XXX: alignment */
468 } __packed;
469 
470 /*
471  * Router Renumbering. as router-renum-08.txt
472  */
473 struct icmp6_router_renum {	/* router renumbering header */
474 	struct icmp6_hdr	rr_hdr;
475 	u_int8_t	rr_segnum;
476 	u_int8_t	rr_flags;
477 	u_int16_t	rr_maxdelay;
478 	u_int32_t	rr_reserved;
479 } __packed;
480 
481 #define ICMP6_RR_FLAGS_TEST		0x80
482 #define ICMP6_RR_FLAGS_REQRESULT	0x40
483 #define ICMP6_RR_FLAGS_FORCEAPPLY	0x20
484 #define ICMP6_RR_FLAGS_SPECSITE		0x10
485 #define ICMP6_RR_FLAGS_PREVDONE		0x08
486 
487 #define rr_type		rr_hdr.icmp6_type
488 #define rr_code		rr_hdr.icmp6_code
489 #define rr_cksum	rr_hdr.icmp6_cksum
490 #define rr_seqnum 	rr_hdr.icmp6_data32[0]
491 
492 struct rr_pco_match {		/* match prefix part */
493 	u_int8_t	rpm_code;
494 	u_int8_t	rpm_len;
495 	u_int8_t	rpm_ordinal;
496 	u_int8_t	rpm_matchlen;
497 	u_int8_t	rpm_minlen;
498 	u_int8_t	rpm_maxlen;
499 	u_int16_t	rpm_reserved;
500 	struct	in6_addr	rpm_prefix;
501 } __packed;
502 
503 #define RPM_PCO_ADD		1
504 #define RPM_PCO_CHANGE		2
505 #define RPM_PCO_SETGLOBAL	3
506 #define RPM_PCO_MAX		4
507 
508 struct rr_pco_use {		/* use prefix part */
509 	u_int8_t	rpu_uselen;
510 	u_int8_t	rpu_keeplen;
511 	u_int8_t	rpu_ramask;
512 	u_int8_t	rpu_raflags;
513 	u_int32_t	rpu_vltime;
514 	u_int32_t	rpu_pltime;
515 	u_int32_t	rpu_flags;
516 	struct	in6_addr rpu_prefix;
517 } __packed;
518 #define ICMP6_RR_PCOUSE_RAFLAGS_ONLINK	0x80
519 #define ICMP6_RR_PCOUSE_RAFLAGS_AUTO	0x40
520 
521 #if BYTE_ORDER == BIG_ENDIAN
522 #define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME     0x80000000
523 #define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME     0x40000000
524 #elif BYTE_ORDER == LITTLE_ENDIAN
525 #define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME     0x80
526 #define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME     0x40
527 #endif
528 
529 struct rr_result {		/* router renumbering result message */
530 	u_int16_t	rrr_flags;
531 	u_int8_t	rrr_ordinal;
532 	u_int8_t	rrr_matchedlen;
533 	u_int32_t	rrr_ifid;
534 	struct	in6_addr rrr_prefix;
535 } __packed;
536 #if BYTE_ORDER == BIG_ENDIAN
537 #define ICMP6_RR_RESULT_FLAGS_OOB		0x0002
538 #define ICMP6_RR_RESULT_FLAGS_FORBIDDEN		0x0001
539 #elif BYTE_ORDER == LITTLE_ENDIAN
540 #define ICMP6_RR_RESULT_FLAGS_OOB		0x0200
541 #define ICMP6_RR_RESULT_FLAGS_FORBIDDEN		0x0100
542 #endif
543 
544 /*
545  * icmp6 filter structures.
546  */
547 
548 struct icmp6_filter {
549 	u_int32_t icmp6_filt[8];
550 };
551 
552 #ifdef _KERNEL
553 #define	ICMP6_FILTER_SETPASSALL(filterp) \
554 do {								\
555 	int i; u_char *p;					\
556 	p = (u_char *)filterp;					\
557 	for (i = 0; i < sizeof(struct icmp6_filter); i++)	\
558 		p[i] = 0xff;					\
559 } while (/*CONSTCOND*/ 0)
560 #define	ICMP6_FILTER_SETBLOCKALL(filterp) \
561 	bzero(filterp, sizeof(struct icmp6_filter))
562 #else /* _KERNEL */
563 #define	ICMP6_FILTER_SETPASSALL(filterp) \
564 	memset(filterp, 0xff, sizeof(struct icmp6_filter))
565 #define	ICMP6_FILTER_SETBLOCKALL(filterp) \
566 	memset(filterp, 0x00, sizeof(struct icmp6_filter))
567 #endif /* _KERNEL */
568 
569 #define	ICMP6_FILTER_SETPASS(type, filterp) \
570 	(((filterp)->icmp6_filt[(type) >> 5]) |= (1 << ((type) & 31)))
571 #define	ICMP6_FILTER_SETBLOCK(type, filterp) \
572 	(((filterp)->icmp6_filt[(type) >> 5]) &= ~(1 << ((type) & 31)))
573 #define	ICMP6_FILTER_WILLPASS(type, filterp) \
574 	((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) != 0)
575 #define	ICMP6_FILTER_WILLBLOCK(type, filterp) \
576 	((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) == 0)
577 
578 /*
579  * Variables related to this implementation
580  * of the internet control message protocol version 6.
581  */
582 struct icmp6errstat {
583 	uint64_t icp6errs_dst_unreach_noroute;
584 	uint64_t icp6errs_dst_unreach_admin;
585 	uint64_t icp6errs_dst_unreach_beyondscope;
586 	uint64_t icp6errs_dst_unreach_addr;
587 	uint64_t icp6errs_dst_unreach_noport;
588 	uint64_t icp6errs_packet_too_big;
589 	uint64_t icp6errs_time_exceed_transit;
590 	uint64_t icp6errs_time_exceed_reassembly;
591 	uint64_t icp6errs_paramprob_header;
592 	uint64_t icp6errs_paramprob_nextheader;
593 	uint64_t icp6errs_paramprob_option;
594 	uint64_t icp6errs_redirect; /* we regard redirect as an error here */
595 	uint64_t icp6errs_unknown;
596 };
597 
598 struct icmp6stat {
599 /* statistics related to icmp6 packets generated */
600 	uint64_t icp6s_error;		/* # of calls to icmp6_error */
601 	uint64_t icp6s_canterror;	/* no error 'cuz old was icmp */
602 	uint64_t icp6s_toofreq;		/* no error 'cuz rate limitation */
603 	uint64_t icp6s_outhist[256];
604 /* statistics related to input message processed */
605 	uint64_t icp6s_badcode;		/* icmp6_code out of range */
606 	uint64_t icp6s_tooshort;	/* packet < sizeof(struct icmp6_hdr) */
607 	uint64_t icp6s_checksum;	/* bad checksum */
608 	uint64_t icp6s_badlen;		/* calculated bound mismatch */
609 	/*
610 	 * number of responses: this member is inherited from netinet code, but
611 	 * for netinet6 code, it is already available in icp6s_outhist[].
612 	 */
613 	uint64_t icp6s_reflect;
614 	uint64_t icp6s_inhist[256];
615 	uint64_t icp6s_nd_toomanyopt;	/* too many ND options */
616 	struct icmp6errstat icp6s_outerrhist;
617 #define icp6s_odst_unreach_noroute \
618 	icp6s_outerrhist.icp6errs_dst_unreach_noroute
619 #define icp6s_odst_unreach_admin icp6s_outerrhist.icp6errs_dst_unreach_admin
620 #define icp6s_odst_unreach_beyondscope \
621 	icp6s_outerrhist.icp6errs_dst_unreach_beyondscope
622 #define icp6s_odst_unreach_addr icp6s_outerrhist.icp6errs_dst_unreach_addr
623 #define icp6s_odst_unreach_noport icp6s_outerrhist.icp6errs_dst_unreach_noport
624 #define icp6s_opacket_too_big icp6s_outerrhist.icp6errs_packet_too_big
625 #define icp6s_otime_exceed_transit \
626 	icp6s_outerrhist.icp6errs_time_exceed_transit
627 #define icp6s_otime_exceed_reassembly \
628 	icp6s_outerrhist.icp6errs_time_exceed_reassembly
629 #define icp6s_oparamprob_header icp6s_outerrhist.icp6errs_paramprob_header
630 #define icp6s_oparamprob_nextheader \
631 	icp6s_outerrhist.icp6errs_paramprob_nextheader
632 #define icp6s_oparamprob_option icp6s_outerrhist.icp6errs_paramprob_option
633 #define icp6s_oredirect icp6s_outerrhist.icp6errs_redirect
634 #define icp6s_ounknown icp6s_outerrhist.icp6errs_unknown
635 	uint64_t icp6s_pmtuchg;		/* path MTU changes */
636 	uint64_t icp6s_nd_badopt;	/* bad ND options */
637 	uint64_t icp6s_badns;		/* bad neighbor solicitation */
638 	uint64_t icp6s_badna;		/* bad neighbor advertisement */
639 	uint64_t icp6s_badrs;		/* bad router solicitation */
640 	uint64_t icp6s_badra;		/* bad router advertisement */
641 	uint64_t icp6s_badredirect;	/* bad redirect message */
642 	uint64_t icp6s_overflowdefrtr;	/* Too many default routers. */
643 	uint64_t icp6s_overflowprfx;	/* Too many prefixes. */
644 	uint64_t icp6s_overflownndp;	/* Too many neighbour entries. */
645 	uint64_t icp6s_overflowredirect;/* Too many redirects. */
646 	uint64_t icp6s_invlhlim;	/* Invalid hop limit. */
647 	uint64_t icp6s_spare[32];
648 };
649 
650 #ifdef _KERNEL
651 #include <sys/counter.h>
652 
653 VNET_PCPUSTAT_DECLARE(struct icmp6stat, icmp6stat);
654 /*
655  * In-kernel consumers can use these accessor macros directly to update
656  * stats.
657  */
658 #define	ICMP6STAT_ADD(name, val)	\
659     VNET_PCPUSTAT_ADD(struct icmp6stat, icmp6stat, name, (val))
660 #define	ICMP6STAT_INC(name)		ICMP6STAT_ADD(name, 1)
661 
662 /*
663  * Kernel module consumers must use this accessor macro.
664  */
665 void	kmod_icmp6stat_inc(int statnum);
666 #define	KMOD_ICMP6STAT_INC(name)	\
667     kmod_icmp6stat_inc(offsetof(struct icmp6stat, name) / sizeof(uint64_t))
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 void	icmp6_error(struct mbuf *, int, int, int);
708 void	icmp6_error2(struct mbuf *, int, int, int, struct ifnet *);
709 int	icmp6_input(struct mbuf **, int *, int);
710 void	icmp6_fasttimo(void);
711 void	icmp6_slowtimo(void);
712 void	icmp6_prepare(struct mbuf *);
713 void	icmp6_redirect_input(struct mbuf *, int);
714 void	icmp6_redirect_output(struct mbuf *, struct nhop_object *);
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 VNET_DECLARE(int, icmp6_rediraccept);	/* accept/process redirects */
782 VNET_DECLARE(int, icmp6_redirtimeout);	/* cache time for redirect routes */
783 
784 #define	V_icmp6_rediraccept	VNET(icmp6_rediraccept)
785 #define	V_icmp6_redirtimeout	VNET(icmp6_redirtimeout)
786 
787 #define ICMP6_NODEINFO_FQDNOK		0x1
788 #define ICMP6_NODEINFO_NODEADDROK	0x2
789 #define ICMP6_NODEINFO_TMPADDROK	0x4
790 #define ICMP6_NODEINFO_GLOBALOK		0x8
791 #endif /* _KERNEL */
792 
793 #endif /* not _NETINET_ICMP6_H_ */
794