xref: /netbsd/sys/netinet/icmp6.h (revision bf9ec67e)
1 /*	$NetBSD: icmp6.h,v 1.21 2001/12/21 02:52:18 itojun Exp $	*/
2 /*	$KAME: icmp6.h,v 1.39 2001/02/06 03:48:06 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  * 3. All advertising materials mentioning features or use of this software
46  *    must display the following acknowledgement:
47  *	This product includes software developed by the University of
48  *	California, Berkeley and its contributors.
49  * 4. Neither the name of the University nor the names of its contributors
50  *    may be used to endorse or promote products derived from this software
51  *    without specific prior written permission.
52  *
53  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
54  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
55  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
56  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
57  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
58  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
59  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63  * SUCH DAMAGE.
64  *
65  *	@(#)ip_icmp.h	8.1 (Berkeley) 6/10/93
66  */
67 
68 #ifndef _NETINET_ICMP6_H_
69 #define _NETINET_ICMP6_H_
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 } __attribute__((__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 ICMP6_MEMBERSHIP_QUERY		130	/* group membership query */
102 #define MLD6_LISTENER_QUERY		130 	/* multicast listener query */
103 #define ICMP6_MEMBERSHIP_REPORT		131	/* group membership report */
104 #define MLD6_LISTENER_REPORT		131	/* multicast listener report */
105 #define ICMP6_MEMBERSHIP_REDUCTION	132	/* group membership termination */
106 #define MLD6_LISTENER_DONE		132	/* multicast listener done */
107 
108 #define ND_ROUTER_SOLICIT		133	/* router solicitation */
109 #define ND_ROUTER_ADVERT		134	/* router advertisment */
110 #define ND_NEIGHBOR_SOLICIT		135	/* neighbor solicitation */
111 #define ND_NEIGHBOR_ADVERT		136	/* neighbor advertisment */
112 #define ND_REDIRECT			137	/* redirect */
113 
114 #define ICMP6_ROUTER_RENUMBERING	138	/* router renumbering */
115 
116 #define ICMP6_WRUREQUEST		139	/* who are you request */
117 #define ICMP6_WRUREPLY			140	/* who are you reply */
118 #define ICMP6_FQDN_QUERY		139	/* FQDN query */
119 #define ICMP6_FQDN_REPLY		140	/* FQDN reply */
120 #define ICMP6_NI_QUERY			139	/* node information request */
121 #define ICMP6_NI_REPLY			140	/* node information reply */
122 
123 /* The definitions below are experimental. TBA */
124 #define MLD6_MTRACE_RESP		200	/* mtrace response(to sender) */
125 #define MLD6_MTRACE			201	/* mtrace messages */
126 
127 #define ICMP6_MAXTYPE			201
128 
129 #define ICMP6_DST_UNREACH_NOROUTE	0	/* no route to destination */
130 #define ICMP6_DST_UNREACH_ADMIN	 	1	/* administratively prohibited */
131 #define ICMP6_DST_UNREACH_NOTNEIGHBOR	2	/* not a neighbor(obsolete) */
132 #define ICMP6_DST_UNREACH_BEYONDSCOPE	2	/* beyond scope of source address */
133 #define ICMP6_DST_UNREACH_ADDR		3	/* address unreachable */
134 #define ICMP6_DST_UNREACH_NOPORT	4	/* port unreachable */
135 
136 #define ICMP6_TIME_EXCEED_TRANSIT 	0	/* ttl==0 in transit */
137 #define ICMP6_TIME_EXCEED_REASSEMBLY	1	/* ttl==0 in reass */
138 
139 #define ICMP6_PARAMPROB_HEADER 	 	0	/* erroneous header field */
140 #define ICMP6_PARAMPROB_NEXTHEADER	1	/* unrecognized next header */
141 #define ICMP6_PARAMPROB_OPTION		2	/* unrecognized option */
142 
143 #define ICMP6_INFOMSG_MASK		0x80	/* all informational messages */
144 
145 #define ICMP6_NI_SUBJ_IPV6	0	/* Query Subject is an IPv6 address */
146 #define ICMP6_NI_SUBJ_FQDN	1	/* Query Subject is a Domain name */
147 #define ICMP6_NI_SUBJ_IPV4	2	/* Query Subject is an IPv4 address */
148 
149 #define ICMP6_NI_SUCCESS	0	/* node information successful reply */
150 #define ICMP6_NI_REFUSED	1	/* node information request is refused */
151 #define ICMP6_NI_UNKNOWN	2	/* unknown Qtype */
152 
153 #define ICMP6_ROUTER_RENUMBERING_COMMAND  0	/* rr command */
154 #define ICMP6_ROUTER_RENUMBERING_RESULT   1	/* rr result */
155 #define ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET   255	/* rr seq num reset */
156 
157 /* Used in kernel only */
158 #define ND_REDIRECT_ONLINK	0	/* redirect to an on-link node */
159 #define ND_REDIRECT_ROUTER	1	/* redirect to a better router */
160 
161 /*
162  * Multicast Listener Discovery
163  */
164 struct mld6_hdr {
165 	struct icmp6_hdr	mld6_hdr;
166 	struct in6_addr		mld6_addr; /* multicast address */
167 } __attribute__((__packed__));
168 
169 #define mld6_type	mld6_hdr.icmp6_type
170 #define mld6_code	mld6_hdr.icmp6_code
171 #define mld6_cksum	mld6_hdr.icmp6_cksum
172 #define mld6_maxdelay	mld6_hdr.icmp6_data16[0]
173 #define mld6_reserved	mld6_hdr.icmp6_data16[1]
174 
175 /*
176  * Neighbor Discovery
177  */
178 
179 struct nd_router_solicit {	/* router solicitation */
180 	struct icmp6_hdr 	nd_rs_hdr;
181 	/* could be followed by options */
182 } __attribute__((__packed__));
183 
184 #define nd_rs_type	nd_rs_hdr.icmp6_type
185 #define nd_rs_code	nd_rs_hdr.icmp6_code
186 #define nd_rs_cksum	nd_rs_hdr.icmp6_cksum
187 #define nd_rs_reserved	nd_rs_hdr.icmp6_data32[0]
188 
189 struct nd_router_advert {	/* router advertisement */
190 	struct icmp6_hdr	nd_ra_hdr;
191 	u_int32_t		nd_ra_reachable;	/* reachable time */
192 	u_int32_t		nd_ra_retransmit;	/* retransmit timer */
193 	/* could be followed by options */
194 } __attribute__((__packed__));
195 
196 #define nd_ra_type		nd_ra_hdr.icmp6_type
197 #define nd_ra_code		nd_ra_hdr.icmp6_code
198 #define nd_ra_cksum		nd_ra_hdr.icmp6_cksum
199 #define nd_ra_curhoplimit	nd_ra_hdr.icmp6_data8[0]
200 #define nd_ra_flags_reserved	nd_ra_hdr.icmp6_data8[1]
201 #define ND_RA_FLAG_MANAGED	0x80
202 #define ND_RA_FLAG_OTHER	0x40
203 #define nd_ra_router_lifetime	nd_ra_hdr.icmp6_data16[1]
204 
205 struct nd_neighbor_solicit {	/* neighbor solicitation */
206 	struct icmp6_hdr	nd_ns_hdr;
207 	struct in6_addr		nd_ns_target;	/*target address */
208 	/* could be followed by options */
209 } __attribute__((__packed__));
210 
211 #define nd_ns_type		nd_ns_hdr.icmp6_type
212 #define nd_ns_code		nd_ns_hdr.icmp6_code
213 #define nd_ns_cksum		nd_ns_hdr.icmp6_cksum
214 #define nd_ns_reserved		nd_ns_hdr.icmp6_data32[0]
215 
216 struct nd_neighbor_advert {	/* neighbor advertisement */
217 	struct icmp6_hdr	nd_na_hdr;
218 	struct in6_addr		nd_na_target;	/* target address */
219 	/* could be followed by options */
220 } __attribute__((__packed__));
221 
222 #define nd_na_type		nd_na_hdr.icmp6_type
223 #define nd_na_code		nd_na_hdr.icmp6_code
224 #define nd_na_cksum		nd_na_hdr.icmp6_cksum
225 #define nd_na_flags_reserved	nd_na_hdr.icmp6_data32[0]
226 #if BYTE_ORDER == BIG_ENDIAN
227 #define ND_NA_FLAG_ROUTER		0x80000000
228 #define ND_NA_FLAG_SOLICITED		0x40000000
229 #define ND_NA_FLAG_OVERRIDE		0x20000000
230 #else
231 #if BYTE_ORDER == LITTLE_ENDIAN
232 #define ND_NA_FLAG_ROUTER		0x80
233 #define ND_NA_FLAG_SOLICITED		0x40
234 #define ND_NA_FLAG_OVERRIDE		0x20
235 #endif
236 #endif
237 
238 struct nd_redirect {		/* redirect */
239 	struct icmp6_hdr	nd_rd_hdr;
240 	struct in6_addr		nd_rd_target;	/* target address */
241 	struct in6_addr		nd_rd_dst;	/* destination address */
242 	/* could be followed by options */
243 } __attribute__((__packed__));
244 
245 #define nd_rd_type		nd_rd_hdr.icmp6_type
246 #define nd_rd_code		nd_rd_hdr.icmp6_code
247 #define nd_rd_cksum		nd_rd_hdr.icmp6_cksum
248 #define nd_rd_reserved		nd_rd_hdr.icmp6_data32[0]
249 
250 struct nd_opt_hdr {		/* Neighbor discovery option header */
251 	u_int8_t	nd_opt_type;
252 	u_int8_t	nd_opt_len;
253 	/* followed by option specific data*/
254 } __attribute__((__packed__));
255 
256 #define ND_OPT_SOURCE_LINKADDR		1
257 #define ND_OPT_TARGET_LINKADDR		2
258 #define ND_OPT_PREFIX_INFORMATION	3
259 #define ND_OPT_REDIRECTED_HEADER	4
260 #define ND_OPT_MTU			5
261 
262 struct nd_opt_prefix_info {	/* prefix information */
263 	u_int8_t	nd_opt_pi_type;
264 	u_int8_t	nd_opt_pi_len;
265 	u_int8_t	nd_opt_pi_prefix_len;
266 	u_int8_t	nd_opt_pi_flags_reserved;
267 	u_int32_t	nd_opt_pi_valid_time;
268 	u_int32_t	nd_opt_pi_preferred_time;
269 	u_int32_t	nd_opt_pi_reserved2;
270 	struct in6_addr	nd_opt_pi_prefix;
271 } __attribute__((__packed__));
272 
273 #define ND_OPT_PI_FLAG_ONLINK		0x80
274 #define ND_OPT_PI_FLAG_AUTO		0x40
275 
276 struct nd_opt_rd_hdr {         /* redirected header */
277 	u_int8_t	nd_opt_rh_type;
278 	u_int8_t	nd_opt_rh_len;
279 	u_int16_t	nd_opt_rh_reserved1;
280 	u_int32_t	nd_opt_rh_reserved2;
281 	/* followed by IP header and data */
282 } __attribute__((__packed__));
283 
284 struct nd_opt_mtu {		/* MTU option */
285 	u_int8_t	nd_opt_mtu_type;
286 	u_int8_t	nd_opt_mtu_len;
287 	u_int16_t	nd_opt_mtu_reserved;
288 	u_int32_t	nd_opt_mtu_mtu;
289 } __attribute__((__packed__));
290 
291 /*
292  * icmp6 namelookup
293  */
294 
295 struct icmp6_namelookup {
296 	struct icmp6_hdr 	icmp6_nl_hdr;
297 	u_int8_t	icmp6_nl_nonce[8];
298 	int32_t		icmp6_nl_ttl;
299 #if 0
300 	u_int8_t	icmp6_nl_len;
301 	u_int8_t	icmp6_nl_name[3];
302 #endif
303 	/* could be followed by options */
304 } __attribute__((__packed__));
305 
306 /*
307  * icmp6 node information
308  */
309 struct icmp6_nodeinfo {
310 	struct icmp6_hdr icmp6_ni_hdr;
311 	u_int8_t icmp6_ni_nonce[8];
312 	/* could be followed by reply data */
313 } __attribute__((__packed__));
314 
315 #define ni_type		icmp6_ni_hdr.icmp6_type
316 #define ni_code		icmp6_ni_hdr.icmp6_code
317 #define ni_cksum	icmp6_ni_hdr.icmp6_cksum
318 #define ni_qtype	icmp6_ni_hdr.icmp6_data16[0]
319 #define ni_flags	icmp6_ni_hdr.icmp6_data16[1]
320 
321 #define NI_QTYPE_NOOP		0 /* NOOP  */
322 #define NI_QTYPE_SUPTYPES	1 /* Supported Qtypes */
323 #define NI_QTYPE_FQDN		2 /* FQDN (draft 04) */
324 #define NI_QTYPE_DNSNAME	2 /* DNS Name */
325 #define NI_QTYPE_NODEADDR	3 /* Node Addresses */
326 #define NI_QTYPE_IPV4ADDR	4 /* IPv4 Addresses */
327 
328 #if BYTE_ORDER == BIG_ENDIAN
329 #define NI_SUPTYPE_FLAG_COMPRESS	0x1
330 #define NI_FQDN_FLAG_VALIDTTL		0x1
331 #elif BYTE_ORDER == LITTLE_ENDIAN
332 #define NI_SUPTYPE_FLAG_COMPRESS	0x0100
333 #define NI_FQDN_FLAG_VALIDTTL		0x0100
334 #endif
335 
336 #ifdef NAME_LOOKUPS_04
337 #if BYTE_ORDER == BIG_ENDIAN
338 #define NI_NODEADDR_FLAG_LINKLOCAL	0x1
339 #define NI_NODEADDR_FLAG_SITELOCAL	0x2
340 #define NI_NODEADDR_FLAG_GLOBAL		0x4
341 #define NI_NODEADDR_FLAG_ALL		0x8
342 #define NI_NODEADDR_FLAG_TRUNCATE	0x10
343 #define NI_NODEADDR_FLAG_ANYCAST	0x20 /* just experimental. not in spec */
344 #elif BYTE_ORDER == LITTLE_ENDIAN
345 #define NI_NODEADDR_FLAG_LINKLOCAL	0x0100
346 #define NI_NODEADDR_FLAG_SITELOCAL	0x0200
347 #define NI_NODEADDR_FLAG_GLOBAL		0x0400
348 #define NI_NODEADDR_FLAG_ALL		0x0800
349 #define NI_NODEADDR_FLAG_TRUNCATE	0x1000
350 #define NI_NODEADDR_FLAG_ANYCAST	0x2000 /* just experimental. not in spec */
351 #endif
352 #else  /* draft-ietf-ipngwg-icmp-name-lookups-05 (and later?) */
353 #if BYTE_ORDER == BIG_ENDIAN
354 #define NI_NODEADDR_FLAG_TRUNCATE	0x1
355 #define NI_NODEADDR_FLAG_ALL		0x2
356 #define NI_NODEADDR_FLAG_COMPAT		0x4
357 #define NI_NODEADDR_FLAG_LINKLOCAL	0x8
358 #define NI_NODEADDR_FLAG_SITELOCAL	0x10
359 #define NI_NODEADDR_FLAG_GLOBAL		0x20
360 #define NI_NODEADDR_FLAG_ANYCAST	0x40 /* just experimental. not in spec */
361 #elif BYTE_ORDER == LITTLE_ENDIAN
362 #define NI_NODEADDR_FLAG_TRUNCATE	0x0100
363 #define NI_NODEADDR_FLAG_ALL		0x0200
364 #define NI_NODEADDR_FLAG_COMPAT		0x0400
365 #define NI_NODEADDR_FLAG_LINKLOCAL	0x0800
366 #define NI_NODEADDR_FLAG_SITELOCAL	0x1000
367 #define NI_NODEADDR_FLAG_GLOBAL		0x2000
368 #define NI_NODEADDR_FLAG_ANYCAST	0x4000 /* just experimental. not in spec */
369 #endif
370 #endif
371 
372 struct ni_reply_fqdn {
373 	u_int32_t ni_fqdn_ttl;	/* TTL */
374 	u_int8_t ni_fqdn_namelen; /* length in octets of the FQDN */
375 	u_int8_t ni_fqdn_name[3]; /* XXX: alignment */
376 } __attribute__((__packed__));
377 
378 /*
379  * Router Renumbering. as router-renum-08.txt
380  */
381 struct icmp6_router_renum {	/* router renumbering header */
382 	struct icmp6_hdr	rr_hdr;
383 	u_int8_t	rr_segnum;
384 	u_int8_t	rr_flags;
385 	u_int16_t	rr_maxdelay;
386 	u_int32_t	rr_reserved;
387 } __attribute__((__packed__));
388 
389 #define ICMP6_RR_FLAGS_TEST		0x80
390 #define ICMP6_RR_FLAGS_REQRESULT	0x40
391 #define ICMP6_RR_FLAGS_FORCEAPPLY	0x20
392 #define ICMP6_RR_FLAGS_SPECSITE		0x10
393 #define ICMP6_RR_FLAGS_PREVDONE		0x08
394 
395 #define rr_type		rr_hdr.icmp6_type
396 #define rr_code		rr_hdr.icmp6_code
397 #define rr_cksum	rr_hdr.icmp6_cksum
398 #define rr_seqnum 	rr_hdr.icmp6_data32[0]
399 
400 struct rr_pco_match {		/* match prefix part */
401 	u_int8_t	rpm_code;
402 	u_int8_t	rpm_len;
403 	u_int8_t	rpm_ordinal;
404 	u_int8_t	rpm_matchlen;
405 	u_int8_t	rpm_minlen;
406 	u_int8_t	rpm_maxlen;
407 	u_int16_t	rpm_reserved;
408 	struct	in6_addr	rpm_prefix;
409 } __attribute__((__packed__));
410 
411 #define RPM_PCO_ADD		1
412 #define RPM_PCO_CHANGE		2
413 #define RPM_PCO_SETGLOBAL	3
414 #define RPM_PCO_MAX		4
415 
416 struct rr_pco_use {		/* use prefix part */
417 	u_int8_t	rpu_uselen;
418 	u_int8_t	rpu_keeplen;
419 	u_int8_t	rpu_ramask;
420 	u_int8_t	rpu_raflags;
421 	u_int32_t	rpu_vltime;
422 	u_int32_t	rpu_pltime;
423 	u_int32_t	rpu_flags;
424 	struct	in6_addr rpu_prefix;
425 } __attribute__((__packed__));
426 #define ICMP6_RR_PCOUSE_RAFLAGS_ONLINK	0x80
427 #define ICMP6_RR_PCOUSE_RAFLAGS_AUTO	0x40
428 
429 #if BYTE_ORDER == BIG_ENDIAN
430 #define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME     0x80000000
431 #define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME     0x40000000
432 #elif BYTE_ORDER == LITTLE_ENDIAN
433 #define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME     0x80
434 #define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME     0x40
435 #endif
436 
437 struct rr_result {		/* router renumbering result message */
438 	u_int16_t	rrr_flags;
439 	u_int8_t	rrr_ordinal;
440 	u_int8_t	rrr_matchedlen;
441 	u_int32_t	rrr_ifid;
442 	struct	in6_addr rrr_prefix;
443 } __attribute__((__packed__));
444 #if BYTE_ORDER == BIG_ENDIAN
445 #define ICMP6_RR_RESULT_FLAGS_OOB		0x0002
446 #define ICMP6_RR_RESULT_FLAGS_FORBIDDEN		0x0001
447 #elif BYTE_ORDER == LITTLE_ENDIAN
448 #define ICMP6_RR_RESULT_FLAGS_OOB		0x0200
449 #define ICMP6_RR_RESULT_FLAGS_FORBIDDEN		0x0100
450 #endif
451 
452 /*
453  * icmp6 filter structures.
454  */
455 
456 struct icmp6_filter {
457 	u_int32_t icmp6_filt[8];
458 };
459 
460 #ifdef _KERNEL
461 #define	ICMP6_FILTER_SETPASSALL(filterp) \
462 do {								\
463 	int i; u_char *p;					\
464 	p = (u_char *)filterp;					\
465 	for (i = 0; i < sizeof(struct icmp6_filter); i++)	\
466 		p[i] = 0xff;					\
467 } while (0)
468 #define	ICMP6_FILTER_SETBLOCKALL(filterp) \
469 	bzero(filterp, sizeof(struct icmp6_filter))
470 #else /* _KERNEL */
471 #define	ICMP6_FILTER_SETPASSALL(filterp) \
472 	memset(filterp, 0xff, sizeof(struct icmp6_filter))
473 #define	ICMP6_FILTER_SETBLOCKALL(filterp) \
474 	memset(filterp, 0x00, sizeof(struct icmp6_filter))
475 #endif /* _KERNEL */
476 
477 #define	ICMP6_FILTER_SETPASS(type, filterp) \
478 	(((filterp)->icmp6_filt[(type) >> 5]) |= (1 << ((type) & 31)))
479 #define	ICMP6_FILTER_SETBLOCK(type, filterp) \
480 	(((filterp)->icmp6_filt[(type) >> 5]) &= ~(1 << ((type) & 31)))
481 #define	ICMP6_FILTER_WILLPASS(type, filterp) \
482 	((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) != 0)
483 #define	ICMP6_FILTER_WILLBLOCK(type, filterp) \
484 	((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) == 0)
485 
486 /*
487  * Variables related to this implementation
488  * of the internet control message protocol version 6.
489  */
490 struct icmp6errstat {
491 	u_quad_t icp6errs_dst_unreach_noroute;
492 	u_quad_t icp6errs_dst_unreach_admin;
493 	u_quad_t icp6errs_dst_unreach_beyondscope;
494 	u_quad_t icp6errs_dst_unreach_addr;
495 	u_quad_t icp6errs_dst_unreach_noport;
496 	u_quad_t icp6errs_packet_too_big;
497 	u_quad_t icp6errs_time_exceed_transit;
498 	u_quad_t icp6errs_time_exceed_reassembly;
499 	u_quad_t icp6errs_paramprob_header;
500 	u_quad_t icp6errs_paramprob_nextheader;
501 	u_quad_t icp6errs_paramprob_option;
502 	u_quad_t icp6errs_redirect; /* we regard redirect as an error here */
503 	u_quad_t icp6errs_unknown;
504 };
505 
506 struct icmp6stat {
507 /* statistics related to icmp6 packets generated */
508 	u_quad_t icp6s_error;		/* # of calls to icmp6_error */
509 	u_quad_t icp6s_canterror;	/* no error 'cuz old was icmp */
510 	u_quad_t icp6s_toofreq;		/* no error 'cuz rate limitation */
511 	u_quad_t icp6s_outhist[256];
512 /* statistics related to input message processed */
513 	u_quad_t icp6s_badcode;		/* icmp6_code out of range */
514 	u_quad_t icp6s_tooshort;	/* packet < sizeof(struct icmp6_hdr) */
515 	u_quad_t icp6s_checksum;	/* bad checksum */
516 	u_quad_t icp6s_badlen;		/* calculated bound mismatch */
517 	/*
518 	 * number of responses: this member is inherited from netinet code, but
519 	 * for netinet6 code, it is already available in icp6s_outhist[].
520 	 */
521 	u_quad_t icp6s_reflect;
522 	u_quad_t icp6s_inhist[256];
523 	u_quad_t icp6s_nd_toomanyopt;	/* too many ND options */
524 	struct icmp6errstat icp6s_outerrhist;
525 #define icp6s_odst_unreach_noroute \
526 	icp6s_outerrhist.icp6errs_dst_unreach_noroute
527 #define icp6s_odst_unreach_admin icp6s_outerrhist.icp6errs_dst_unreach_admin
528 #define icp6s_odst_unreach_beyondscope \
529 	icp6s_outerrhist.icp6errs_dst_unreach_beyondscope
530 #define icp6s_odst_unreach_addr icp6s_outerrhist.icp6errs_dst_unreach_addr
531 #define icp6s_odst_unreach_noport icp6s_outerrhist.icp6errs_dst_unreach_noport
532 #define icp6s_opacket_too_big icp6s_outerrhist.icp6errs_packet_too_big
533 #define icp6s_otime_exceed_transit \
534 	icp6s_outerrhist.icp6errs_time_exceed_transit
535 #define icp6s_otime_exceed_reassembly \
536 	icp6s_outerrhist.icp6errs_time_exceed_reassembly
537 #define icp6s_oparamprob_header icp6s_outerrhist.icp6errs_paramprob_header
538 #define icp6s_oparamprob_nextheader \
539 	icp6s_outerrhist.icp6errs_paramprob_nextheader
540 #define icp6s_oparamprob_option icp6s_outerrhist.icp6errs_paramprob_option
541 #define icp6s_oredirect icp6s_outerrhist.icp6errs_redirect
542 #define icp6s_ounknown icp6s_outerrhist.icp6errs_unknown
543 	u_quad_t icp6s_pmtuchg;		/* path MTU changes */
544 	u_quad_t icp6s_nd_badopt;	/* bad ND options */
545 	u_quad_t icp6s_badns;		/* bad neighbor solicitation */
546 	u_quad_t icp6s_badna;		/* bad neighbor advertisement */
547 	u_quad_t icp6s_badrs;		/* bad router advertisement */
548 	u_quad_t icp6s_badra;		/* bad router advertisement */
549 	u_quad_t icp6s_badredirect;	/* bad redirect message */
550 };
551 
552 /*
553  * Names for ICMP sysctl objects
554  */
555 #define ICMPV6CTL_STATS		1
556 #define ICMPV6CTL_REDIRACCEPT	2	/* accept/process redirects */
557 #define ICMPV6CTL_REDIRTIMEOUT	3	/* redirect cache time */
558 #if 0	/*obsoleted*/
559 #define ICMPV6CTL_ERRRATELIMIT	5	/* ICMPv6 error rate limitation */
560 #endif
561 #define ICMPV6CTL_ND6_PRUNE	6
562 #define ICMPV6CTL_ND6_DELAY	8
563 #define ICMPV6CTL_ND6_UMAXTRIES	9
564 #define ICMPV6CTL_ND6_MMAXTRIES		10
565 #define ICMPV6CTL_ND6_USELOOPBACK	11
566 /*#define ICMPV6CTL_ND6_PROXYALL	12	obsoleted, do not reuse here */
567 #define ICMPV6CTL_NODEINFO	13
568 #define ICMPV6CTL_ERRPPSLIMIT	14	/* ICMPv6 error pps limitation */
569 #define ICMPV6CTL_ND6_MAXNUDHINT	15
570 #define ICMPV6CTL_MTUDISC_HIWAT	16
571 #define ICMPV6CTL_MTUDISC_LOWAT	17
572 #define ICMPV6CTL_ND6_DEBUG	18
573 #define ICMPV6CTL_MAXID		19
574 
575 #define ICMPV6CTL_NAMES { \
576 	{ 0, 0 }, \
577 	{ 0, 0 }, \
578 	{ "rediraccept", CTLTYPE_INT }, \
579 	{ "redirtimeout", CTLTYPE_INT }, \
580 	{ 0, 0 }, \
581 	{ 0, 0 }, \
582 	{ "nd6_prune", CTLTYPE_INT }, \
583 	{ 0, 0 }, \
584 	{ "nd6_delay", CTLTYPE_INT }, \
585 	{ "nd6_umaxtries", CTLTYPE_INT }, \
586 	{ "nd6_mmaxtries", CTLTYPE_INT }, \
587 	{ "nd6_useloopback", CTLTYPE_INT }, \
588 	{ 0, 0 }, \
589 	{ "nodeinfo", CTLTYPE_INT }, \
590 	{ "errppslimit", CTLTYPE_INT }, \
591 	{ "nd6_maxnudhint", CTLTYPE_INT }, \
592 	{ "mtudisc_hiwat", CTLTYPE_INT }, \
593 	{ "mtudisc_lowat", CTLTYPE_INT }, \
594 	{ "nd6_debug", CTLTYPE_INT }, \
595 }
596 
597 #define RTF_PROBEMTU	RTF_PROTO1
598 
599 #ifdef _KERNEL
600 # ifdef __STDC__
601 struct	rtentry;
602 struct	rttimer;
603 struct	in6_multi;
604 # endif
605 void	icmp6_init __P((void));
606 void	icmp6_paramerror __P((struct mbuf *, int));
607 void	icmp6_error __P((struct mbuf *, int, int, int));
608 int	icmp6_input __P((struct mbuf **, int *, int));
609 void	icmp6_fasttimo __P((void));
610 void	icmp6_reflect __P((struct mbuf *, size_t));
611 void	icmp6_prepare __P((struct mbuf *));
612 void	icmp6_redirect_input __P((struct mbuf *, int));
613 void	icmp6_redirect_output __P((struct mbuf *, struct rtentry *));
614 int	icmp6_sysctl __P((int *, u_int, void *, size_t *, void *, size_t));
615 
616 struct	ip6ctlparam;
617 void	icmp6_mtudisc_update __P((struct ip6ctlparam *, int));
618 void	icmp6_mtudisc_callback_register __P((void (*)(struct in6_addr *)));
619 
620 /* XXX: is this the right place for these macros? */
621 #define icmp6_ifstat_inc(ifp, tag) \
622 do {								\
623 	if ((ifp) && (ifp)->if_index <= if_index			\
624 	 && (ifp)->if_index < icmp6_ifstatmax			\
625 	 && icmp6_ifstat && icmp6_ifstat[(ifp)->if_index]) {	\
626 		icmp6_ifstat[(ifp)->if_index]->tag++;		\
627 	}							\
628 } while (0)
629 
630 #define icmp6_ifoutstat_inc(ifp, type, code) \
631 do { \
632 		icmp6_ifstat_inc(ifp, ifs6_out_msg); \
633 		switch(type) { \
634 		 case ICMP6_DST_UNREACH: \
635 			 icmp6_ifstat_inc(ifp, ifs6_out_dstunreach); \
636 			 if (code == ICMP6_DST_UNREACH_ADMIN) \
637 				 icmp6_ifstat_inc(ifp, ifs6_out_adminprohib); \
638 			 break; \
639 		 case ICMP6_PACKET_TOO_BIG: \
640 			 icmp6_ifstat_inc(ifp, ifs6_out_pkttoobig); \
641 			 break; \
642 		 case ICMP6_TIME_EXCEEDED: \
643 			 icmp6_ifstat_inc(ifp, ifs6_out_timeexceed); \
644 			 break; \
645 		 case ICMP6_PARAM_PROB: \
646 			 icmp6_ifstat_inc(ifp, ifs6_out_paramprob); \
647 			 break; \
648 		 case ICMP6_ECHO_REQUEST: \
649 			 icmp6_ifstat_inc(ifp, ifs6_out_echo); \
650 			 break; \
651 		 case ICMP6_ECHO_REPLY: \
652 			 icmp6_ifstat_inc(ifp, ifs6_out_echoreply); \
653 			 break; \
654 		 case MLD6_LISTENER_QUERY: \
655 			 icmp6_ifstat_inc(ifp, ifs6_out_mldquery); \
656 			 break; \
657 		 case MLD6_LISTENER_REPORT: \
658 			 icmp6_ifstat_inc(ifp, ifs6_out_mldreport); \
659 			 break; \
660 		 case MLD6_LISTENER_DONE: \
661 			 icmp6_ifstat_inc(ifp, ifs6_out_mlddone); \
662 			 break; \
663 		 case ND_ROUTER_SOLICIT: \
664 			 icmp6_ifstat_inc(ifp, ifs6_out_routersolicit); \
665 			 break; \
666 		 case ND_ROUTER_ADVERT: \
667 			 icmp6_ifstat_inc(ifp, ifs6_out_routeradvert); \
668 			 break; \
669 		 case ND_NEIGHBOR_SOLICIT: \
670 			 icmp6_ifstat_inc(ifp, ifs6_out_neighborsolicit); \
671 			 break; \
672 		 case ND_NEIGHBOR_ADVERT: \
673 			 icmp6_ifstat_inc(ifp, ifs6_out_neighboradvert); \
674 			 break; \
675 		 case ND_REDIRECT: \
676 			 icmp6_ifstat_inc(ifp, ifs6_out_redirect); \
677 			 break; \
678 		} \
679 } while (0)
680 
681 extern int	icmp6_rediraccept;	/* accept/process redirects */
682 extern int	icmp6_redirtimeout;	/* cache time for redirect routes */
683 #endif /* _KERNEL */
684 
685 #endif /* not _NETINET_ICMP6_H_ */
686