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