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