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