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