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