icmp6.h revision 331722
1130812Smarcel/*	$FreeBSD: stable/11/sys/netinet/icmp6.h 331722 2018-03-29 02:50:57Z eadler $	*/
2130812Smarcel/*	$KAME: icmp6.h,v 1.46 2001/04/27 15:09:48 itojun Exp $	*/
3130812Smarcel
4130812Smarcel/*-
5130812Smarcel * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
6130812Smarcel * All rights reserved.
7130812Smarcel *
8130812Smarcel * Redistribution and use in source and binary forms, with or without
9130812Smarcel * modification, are permitted provided that the following conditions
10130812Smarcel * are met:
11130812Smarcel * 1. Redistributions of source code must retain the above copyright
12130812Smarcel *    notice, this list of conditions and the following disclaimer.
13130812Smarcel * 2. Redistributions in binary form must reproduce the above copyright
14130812Smarcel *    notice, this list of conditions and the following disclaimer in the
15130812Smarcel *    documentation and/or other materials provided with the distribution.
16130812Smarcel * 3. Neither the name of the project nor the names of its contributors
17130812Smarcel *    may be used to endorse or promote products derived from this software
18130812Smarcel *    without specific prior written permission.
19130812Smarcel *
20130812Smarcel * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
21130812Smarcel * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22130812Smarcel * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23130812Smarcel * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
24130812Smarcel * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25130812Smarcel * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26130812Smarcel * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27130812Smarcel * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28130812Smarcel * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29130812Smarcel * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30130812Smarcel * SUCH DAMAGE.
31130812Smarcel */
32130812Smarcel
33130812Smarcel/*-
34130812Smarcel * Copyright (c) 1982, 1986, 1993
35130812Smarcel *	The Regents of the University of California.  All rights reserved.
36130812Smarcel *
37130812Smarcel * Redistribution and use in source and binary forms, with or without
38130812Smarcel * modification, are permitted provided that the following conditions
39130812Smarcel * are met:
40130812Smarcel * 1. Redistributions of source code must retain the above copyright
41130812Smarcel *    notice, this list of conditions and the following disclaimer.
42130812Smarcel * 2. Redistributions in binary form must reproduce the above copyright
43130812Smarcel *    notice, this list of conditions and the following disclaimer in the
44130812Smarcel *    documentation and/or other materials provided with the distribution.
45130812Smarcel * 4. Neither the name of the University nor the names of its contributors
46130812Smarcel *    may be used to endorse or promote products derived from this software
47130812Smarcel *    without specific prior written permission.
48130812Smarcel *
49130812Smarcel * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
50130812Smarcel * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51130812Smarcel * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52130812Smarcel * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
53130812Smarcel * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54130812Smarcel * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55130812Smarcel * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56130812Smarcel * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57130812Smarcel * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58130812Smarcel * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59130812Smarcel * SUCH DAMAGE.
60130812Smarcel *
61130812Smarcel *	@(#)ip_icmp.h	8.1 (Berkeley) 6/10/93
62130812Smarcel */
63130812Smarcel
64130812Smarcel#ifndef _NETINET_ICMP6_H_
65130812Smarcel#define _NETINET_ICMP6_H_
66130812Smarcel
67130812Smarcel#define ICMPV6_PLD_MAXLEN	1232	/* IPV6_MMTU - sizeof(struct ip6_hdr)
68130812Smarcel					   - sizeof(struct icmp6_hdr) */
69130812Smarcel
70130812Smarcelstruct icmp6_hdr {
71130812Smarcel	u_int8_t	icmp6_type;	/* type field */
72130812Smarcel	u_int8_t	icmp6_code;	/* code field */
73130812Smarcel	u_int16_t	icmp6_cksum;	/* checksum field */
74130812Smarcel	union {
75130812Smarcel		u_int32_t	icmp6_un_data32[1]; /* type-specific field */
76130812Smarcel		u_int16_t	icmp6_un_data16[2]; /* type-specific field */
77130812Smarcel		u_int8_t	icmp6_un_data8[4];  /* type-specific field */
78130812Smarcel	} icmp6_dataun;
79130812Smarcel} __packed;
80130812Smarcel
81130812Smarcel#define icmp6_data32	icmp6_dataun.icmp6_un_data32
82130812Smarcel#define icmp6_data16	icmp6_dataun.icmp6_un_data16
83130812Smarcel#define icmp6_data8	icmp6_dataun.icmp6_un_data8
84130812Smarcel#define icmp6_pptr	icmp6_data32[0]		/* parameter prob */
85130812Smarcel#define icmp6_mtu	icmp6_data32[0]		/* packet too big */
86130812Smarcel#define icmp6_id	icmp6_data16[0]		/* echo request/reply */
87130812Smarcel#define icmp6_seq	icmp6_data16[1]		/* echo request/reply */
88130812Smarcel#define icmp6_maxdelay	icmp6_data16[0]		/* mcast group membership */
89130812Smarcel
90130812Smarcel#define ICMP6_DST_UNREACH		1	/* dest unreachable, codes: */
91130812Smarcel#define ICMP6_PACKET_TOO_BIG		2	/* packet too big */
92130812Smarcel#define ICMP6_TIME_EXCEEDED		3	/* time exceeded, code: */
93130812Smarcel#define ICMP6_PARAM_PROB		4	/* ip6 header bad */
94130812Smarcel
95130812Smarcel#define ICMP6_ECHO_REQUEST		128	/* echo service */
96130812Smarcel#define ICMP6_ECHO_REPLY		129	/* echo reply */
97130812Smarcel#define MLD_LISTENER_QUERY		130 	/* multicast listener query */
98130812Smarcel#define MLD_LISTENER_REPORT		131	/* multicast listener report */
99130812Smarcel#define MLD_LISTENER_DONE		132	/* multicast listener done */
100130812Smarcel#define MLD_LISTENER_REDUCTION MLD_LISTENER_DONE /* RFC3542 definition */
101130812Smarcel
102130812Smarcel/* RFC2292 decls */
103130812Smarcel#define ICMP6_MEMBERSHIP_QUERY		130	/* group membership query */
104130812Smarcel#define ICMP6_MEMBERSHIP_REPORT		131	/* group membership report */
105130812Smarcel#define ICMP6_MEMBERSHIP_REDUCTION	132	/* group membership termination */
106130812Smarcel
107130812Smarcel#ifndef _KERNEL
108130812Smarcel/* the followings are for backward compatibility to old KAME apps. */
109130812Smarcel#define MLD6_LISTENER_QUERY	MLD_LISTENER_QUERY
110130812Smarcel#define MLD6_LISTENER_REPORT	MLD_LISTENER_REPORT
111130812Smarcel#define MLD6_LISTENER_DONE	MLD_LISTENER_DONE
112130812Smarcel#endif
113130812Smarcel
114130812Smarcel#define ND_ROUTER_SOLICIT		133	/* router solicitation */
115130812Smarcel#define ND_ROUTER_ADVERT		134	/* router advertisement */
116130812Smarcel#define ND_NEIGHBOR_SOLICIT		135	/* neighbor solicitation */
117130812Smarcel#define ND_NEIGHBOR_ADVERT		136	/* neighbor advertisement */
118130812Smarcel#define ND_REDIRECT			137	/* redirect */
119130812Smarcel
120130812Smarcel#define ICMP6_ROUTER_RENUMBERING	138	/* router renumbering */
121130812Smarcel
122130812Smarcel#define ICMP6_WRUREQUEST		139	/* who are you request */
123130812Smarcel#define ICMP6_WRUREPLY			140	/* who are you reply */
124130812Smarcel#define ICMP6_FQDN_QUERY		139	/* FQDN query */
125130812Smarcel#define ICMP6_FQDN_REPLY		140	/* FQDN reply */
126130812Smarcel#define ICMP6_NI_QUERY			139	/* node information request */
127130812Smarcel#define ICMP6_NI_REPLY			140	/* node information reply */
128130812Smarcel#define MLDV2_LISTENER_REPORT		143	/* RFC3810 listener report */
129130812Smarcel
130130812Smarcel/* The definitions below are experimental. TBA */
131130812Smarcel#define MLD_MTRACE_RESP			200	/* mtrace resp (to sender) */
132130812Smarcel#define MLD_MTRACE			201	/* mtrace messages */
133130812Smarcel
134130812Smarcel#ifndef _KERNEL
135130812Smarcel#define MLD6_MTRACE_RESP	MLD_MTRACE_RESP
136130812Smarcel#define MLD6_MTRACE		MLD_MTRACE
137130812Smarcel#endif
138130812Smarcel
139130812Smarcel#define ICMP6_MAXTYPE			201
140130812Smarcel
141130812Smarcel#define ICMP6_DST_UNREACH_NOROUTE	0	/* no route to destination */
142130812Smarcel#define ICMP6_DST_UNREACH_ADMIN	 	1	/* administratively prohibited */
143130812Smarcel#define ICMP6_DST_UNREACH_NOTNEIGHBOR	2	/* not a neighbor(obsolete) */
144130812Smarcel#define ICMP6_DST_UNREACH_BEYONDSCOPE	2	/* beyond scope of source address */
145130812Smarcel#define ICMP6_DST_UNREACH_ADDR		3	/* address unreachable */
146130812Smarcel#define ICMP6_DST_UNREACH_NOPORT	4	/* port unreachable */
147130812Smarcel#define ICMP6_DST_UNREACH_POLICY	5	/* failed ingress/egress policy */
148130812Smarcel#define ICMP6_DST_UNREACH_REJECT	6	/* Reject route to destination */
149130812Smarcel#define ICMP6_DST_UNREACH_SRCROUTE	7	/* Error in source routing header */
150130812Smarcel
151130812Smarcel#define ICMP6_TIME_EXCEED_TRANSIT 	0	/* ttl==0 in transit */
152130812Smarcel#define ICMP6_TIME_EXCEED_REASSEMBLY	1	/* ttl==0 in reass */
153130812Smarcel
154130812Smarcel#define ICMP6_PARAMPROB_HEADER 	 	0	/* erroneous header field */
155130812Smarcel#define ICMP6_PARAMPROB_NEXTHEADER	1	/* unrecognized next header */
156130812Smarcel#define ICMP6_PARAMPROB_OPTION		2	/* unrecognized option */
157130812Smarcel
158130812Smarcel#define ICMP6_INFOMSG_MASK		0x80	/* all informational messages */
159130812Smarcel
160130812Smarcel#define ICMP6_NI_SUBJ_IPV6	0	/* Query Subject is an IPv6 address */
161130812Smarcel#define ICMP6_NI_SUBJ_FQDN	1	/* Query Subject is a Domain name */
162130812Smarcel#define ICMP6_NI_SUBJ_IPV4	2	/* Query Subject is an IPv4 address */
163130812Smarcel
164130812Smarcel#define ICMP6_NI_SUCCESS	0	/* node information successful reply */
165130812Smarcel#define ICMP6_NI_REFUSED	1	/* node information request is refused */
166130812Smarcel#define ICMP6_NI_UNKNOWN	2	/* unknown Qtype */
167130812Smarcel
168130812Smarcel#define ICMP6_ROUTER_RENUMBERING_COMMAND  0	/* rr command */
169130812Smarcel#define ICMP6_ROUTER_RENUMBERING_RESULT   1	/* rr result */
170130812Smarcel#define ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET   255	/* rr seq num reset */
171130812Smarcel
172130812Smarcel/* Used in kernel only */
173130812Smarcel#define ND_REDIRECT_ONLINK	0	/* redirect to an on-link node */
174130812Smarcel#define ND_REDIRECT_ROUTER	1	/* redirect to a better router */
175130812Smarcel
176130812Smarcel/*
177130812Smarcel * Multicast Listener Discovery
178130812Smarcel */
179130812Smarcelstruct mld_hdr {
180130812Smarcel	struct icmp6_hdr	mld_icmp6_hdr;
181	struct in6_addr		mld_addr; /* multicast address */
182} __packed;
183
184/* definitions to provide backward compatibility to old KAME applications */
185#ifndef _KERNEL
186#define mld6_hdr	mld_hdr
187#define mld6_type	mld_type
188#define mld6_code	mld_code
189#define mld6_cksum	mld_cksum
190#define mld6_maxdelay	mld_maxdelay
191#define mld6_reserved	mld_reserved
192#define mld6_addr	mld_addr
193#endif
194
195/* shortcut macro definitions */
196#define mld_type	mld_icmp6_hdr.icmp6_type
197#define mld_code	mld_icmp6_hdr.icmp6_code
198#define mld_cksum	mld_icmp6_hdr.icmp6_cksum
199#define mld_maxdelay	mld_icmp6_hdr.icmp6_data16[0]
200#define mld_reserved	mld_icmp6_hdr.icmp6_data16[1]
201#define mld_v2_reserved	mld_icmp6_hdr.icmp6_data16[0]
202#define mld_v2_numrecs	mld_icmp6_hdr.icmp6_data16[1]
203
204/*
205 * Neighbor Discovery
206 */
207
208struct nd_router_solicit {	/* router solicitation */
209	struct icmp6_hdr 	nd_rs_hdr;
210	/* could be followed by options */
211} __packed;
212
213#define nd_rs_type	nd_rs_hdr.icmp6_type
214#define nd_rs_code	nd_rs_hdr.icmp6_code
215#define nd_rs_cksum	nd_rs_hdr.icmp6_cksum
216#define nd_rs_reserved	nd_rs_hdr.icmp6_data32[0]
217
218struct nd_router_advert {	/* router advertisement */
219	struct icmp6_hdr	nd_ra_hdr;
220	u_int32_t		nd_ra_reachable;	/* reachable time */
221	u_int32_t		nd_ra_retransmit;	/* retransmit timer */
222	/* could be followed by options */
223} __packed;
224
225#define nd_ra_type		nd_ra_hdr.icmp6_type
226#define nd_ra_code		nd_ra_hdr.icmp6_code
227#define nd_ra_cksum		nd_ra_hdr.icmp6_cksum
228#define nd_ra_curhoplimit	nd_ra_hdr.icmp6_data8[0]
229#define nd_ra_flags_reserved	nd_ra_hdr.icmp6_data8[1]
230#define ND_RA_FLAG_MANAGED	0x80
231#define ND_RA_FLAG_OTHER	0x40
232#define ND_RA_FLAG_HA		0x20
233
234/*
235 * Router preference values based on draft-draves-ipngwg-router-selection-01.
236 * These are non-standard definitions.
237 */
238#define ND_RA_FLAG_RTPREF_MASK	0x18 /* 00011000 */
239
240#define ND_RA_FLAG_RTPREF_HIGH	0x08 /* 00001000 */
241#define ND_RA_FLAG_RTPREF_MEDIUM	0x00 /* 00000000 */
242#define ND_RA_FLAG_RTPREF_LOW	0x18 /* 00011000 */
243#define ND_RA_FLAG_RTPREF_RSV	0x10 /* 00010000 */
244
245#define nd_ra_router_lifetime	nd_ra_hdr.icmp6_data16[1]
246
247struct nd_neighbor_solicit {	/* neighbor solicitation */
248	struct icmp6_hdr	nd_ns_hdr;
249	struct in6_addr		nd_ns_target;	/*target address */
250	/* could be followed by options */
251} __packed;
252
253#define nd_ns_type		nd_ns_hdr.icmp6_type
254#define nd_ns_code		nd_ns_hdr.icmp6_code
255#define nd_ns_cksum		nd_ns_hdr.icmp6_cksum
256#define nd_ns_reserved		nd_ns_hdr.icmp6_data32[0]
257
258struct nd_neighbor_advert {	/* neighbor advertisement */
259	struct icmp6_hdr	nd_na_hdr;
260	struct in6_addr		nd_na_target;	/* target address */
261	/* could be followed by options */
262} __packed;
263
264#define nd_na_type		nd_na_hdr.icmp6_type
265#define nd_na_code		nd_na_hdr.icmp6_code
266#define nd_na_cksum		nd_na_hdr.icmp6_cksum
267#define nd_na_flags_reserved	nd_na_hdr.icmp6_data32[0]
268#if BYTE_ORDER == BIG_ENDIAN
269#define ND_NA_FLAG_ROUTER		0x80000000
270#define ND_NA_FLAG_SOLICITED		0x40000000
271#define ND_NA_FLAG_OVERRIDE		0x20000000
272#else
273#if BYTE_ORDER == LITTLE_ENDIAN
274#define ND_NA_FLAG_ROUTER		0x80
275#define ND_NA_FLAG_SOLICITED		0x40
276#define ND_NA_FLAG_OVERRIDE		0x20
277#endif
278#endif
279
280struct nd_redirect {		/* redirect */
281	struct icmp6_hdr	nd_rd_hdr;
282	struct in6_addr		nd_rd_target;	/* target address */
283	struct in6_addr		nd_rd_dst;	/* destination address */
284	/* could be followed by options */
285} __packed;
286
287#define nd_rd_type		nd_rd_hdr.icmp6_type
288#define nd_rd_code		nd_rd_hdr.icmp6_code
289#define nd_rd_cksum		nd_rd_hdr.icmp6_cksum
290#define nd_rd_reserved		nd_rd_hdr.icmp6_data32[0]
291
292struct nd_opt_hdr {		/* Neighbor discovery option header */
293	u_int8_t	nd_opt_type;
294	u_int8_t	nd_opt_len;
295	/* followed by option specific data*/
296} __packed;
297
298#define ND_OPT_SOURCE_LINKADDR		1
299#define ND_OPT_TARGET_LINKADDR		2
300#define ND_OPT_PREFIX_INFORMATION	3
301#define ND_OPT_REDIRECTED_HEADER	4
302#define ND_OPT_MTU			5
303#define ND_OPT_NONCE			14	/* RFC 3971 */
304#define ND_OPT_ROUTE_INFO		24	/* RFC 4191 */
305#define ND_OPT_RDNSS			25	/* RFC 6106 */
306#define ND_OPT_DNSSL			31	/* RFC 6106 */
307#define ND_OPT_MAX			31
308
309struct nd_opt_prefix_info {	/* prefix information */
310	u_int8_t	nd_opt_pi_type;
311	u_int8_t	nd_opt_pi_len;
312	u_int8_t	nd_opt_pi_prefix_len;
313	u_int8_t	nd_opt_pi_flags_reserved;
314	u_int32_t	nd_opt_pi_valid_time;
315	u_int32_t	nd_opt_pi_preferred_time;
316	u_int32_t	nd_opt_pi_reserved2;
317	struct in6_addr	nd_opt_pi_prefix;
318} __packed;
319
320#define ND_OPT_PI_FLAG_ONLINK		0x80
321#define ND_OPT_PI_FLAG_AUTO		0x40
322
323struct nd_opt_rd_hdr {		/* redirected header */
324	u_int8_t	nd_opt_rh_type;
325	u_int8_t	nd_opt_rh_len;
326	u_int16_t	nd_opt_rh_reserved1;
327	u_int32_t	nd_opt_rh_reserved2;
328	/* followed by IP header and data */
329} __packed;
330
331struct nd_opt_mtu {		/* MTU option */
332	u_int8_t	nd_opt_mtu_type;
333	u_int8_t	nd_opt_mtu_len;
334	u_int16_t	nd_opt_mtu_reserved;
335	u_int32_t	nd_opt_mtu_mtu;
336} __packed;
337
338#define	ND_OPT_NONCE_LEN	((1 * 8) - 2)
339#if ((ND_OPT_NONCE_LEN + 2) % 8) != 0
340#error "(ND_OPT_NONCE_LEN + 2) must be a multiple of 8."
341#endif
342struct nd_opt_nonce {		/* nonce option */
343	u_int8_t	nd_opt_nonce_type;
344	u_int8_t	nd_opt_nonce_len;
345	u_int8_t	nd_opt_nonce[ND_OPT_NONCE_LEN];
346} __packed;
347
348struct nd_opt_route_info {	/* route info */
349	u_int8_t	nd_opt_rti_type;
350	u_int8_t	nd_opt_rti_len;
351	u_int8_t	nd_opt_rti_prefixlen;
352	u_int8_t	nd_opt_rti_flags;
353	u_int32_t	nd_opt_rti_lifetime;
354	/* prefix follows */
355} __packed;
356
357struct nd_opt_rdnss {		/* RDNSS option (RFC 6106) */
358	u_int8_t	nd_opt_rdnss_type;
359	u_int8_t	nd_opt_rdnss_len;
360	u_int16_t	nd_opt_rdnss_reserved;
361	u_int32_t	nd_opt_rdnss_lifetime;
362	/* followed by list of recursive DNS servers */
363} __packed;
364
365struct nd_opt_dnssl {		/* DNSSL option (RFC 6106) */
366	u_int8_t	nd_opt_dnssl_type;
367	u_int8_t	nd_opt_dnssl_len;
368	u_int16_t	nd_opt_dnssl_reserved;
369	u_int32_t	nd_opt_dnssl_lifetime;
370	/* followed by list of DNS search domains */
371} __packed;
372
373/*
374 * icmp6 namelookup
375 */
376
377struct icmp6_namelookup {
378	struct icmp6_hdr 	icmp6_nl_hdr;
379	u_int8_t	icmp6_nl_nonce[8];
380	int32_t		icmp6_nl_ttl;
381#if 0
382	u_int8_t	icmp6_nl_len;
383	u_int8_t	icmp6_nl_name[3];
384#endif
385	/* could be followed by options */
386} __packed;
387
388/*
389 * icmp6 node information
390 */
391struct icmp6_nodeinfo {
392	struct icmp6_hdr icmp6_ni_hdr;
393	u_int8_t icmp6_ni_nonce[8];
394	/* could be followed by reply data */
395} __packed;
396
397#define ni_type		icmp6_ni_hdr.icmp6_type
398#define ni_code		icmp6_ni_hdr.icmp6_code
399#define ni_cksum	icmp6_ni_hdr.icmp6_cksum
400#define ni_qtype	icmp6_ni_hdr.icmp6_data16[0]
401#define ni_flags	icmp6_ni_hdr.icmp6_data16[1]
402
403#define NI_QTYPE_NOOP		0 /* NOOP  */
404#define NI_QTYPE_SUPTYPES	1 /* Supported Qtypes */
405#define NI_QTYPE_FQDN		2 /* FQDN (draft 04) */
406#define NI_QTYPE_DNSNAME	2 /* DNS Name */
407#define NI_QTYPE_NODEADDR	3 /* Node Addresses */
408#define NI_QTYPE_IPV4ADDR	4 /* IPv4 Addresses */
409
410#if BYTE_ORDER == BIG_ENDIAN
411#define NI_SUPTYPE_FLAG_COMPRESS	0x1
412#define NI_FQDN_FLAG_VALIDTTL		0x1
413#elif BYTE_ORDER == LITTLE_ENDIAN
414#define NI_SUPTYPE_FLAG_COMPRESS	0x0100
415#define NI_FQDN_FLAG_VALIDTTL		0x0100
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#endif
434#else  /* draft-ietf-ipngwg-icmp-name-lookups-05 (and later?) */
435#if BYTE_ORDER == BIG_ENDIAN
436#define NI_NODEADDR_FLAG_TRUNCATE	0x1
437#define NI_NODEADDR_FLAG_ALL		0x2
438#define NI_NODEADDR_FLAG_COMPAT		0x4
439#define NI_NODEADDR_FLAG_LINKLOCAL	0x8
440#define NI_NODEADDR_FLAG_SITELOCAL	0x10
441#define NI_NODEADDR_FLAG_GLOBAL		0x20
442#define NI_NODEADDR_FLAG_ANYCAST	0x40 /* just experimental. not in spec */
443#elif BYTE_ORDER == LITTLE_ENDIAN
444#define NI_NODEADDR_FLAG_TRUNCATE	0x0100
445#define NI_NODEADDR_FLAG_ALL		0x0200
446#define NI_NODEADDR_FLAG_COMPAT		0x0400
447#define NI_NODEADDR_FLAG_LINKLOCAL	0x0800
448#define NI_NODEADDR_FLAG_SITELOCAL	0x1000
449#define NI_NODEADDR_FLAG_GLOBAL		0x2000
450#define NI_NODEADDR_FLAG_ANYCAST	0x4000 /* just experimental. not in spec */
451#endif
452#endif
453
454struct ni_reply_fqdn {
455	u_int32_t ni_fqdn_ttl;	/* TTL */
456	u_int8_t ni_fqdn_namelen; /* length in octets of the FQDN */
457	u_int8_t ni_fqdn_name[3]; /* XXX: alignment */
458} __packed;
459
460/*
461 * Router Renumbering. as router-renum-08.txt
462 */
463struct icmp6_router_renum {	/* router renumbering header */
464	struct icmp6_hdr	rr_hdr;
465	u_int8_t	rr_segnum;
466	u_int8_t	rr_flags;
467	u_int16_t	rr_maxdelay;
468	u_int32_t	rr_reserved;
469} __packed;
470
471#define ICMP6_RR_FLAGS_TEST		0x80
472#define ICMP6_RR_FLAGS_REQRESULT	0x40
473#define ICMP6_RR_FLAGS_FORCEAPPLY	0x20
474#define ICMP6_RR_FLAGS_SPECSITE		0x10
475#define ICMP6_RR_FLAGS_PREVDONE		0x08
476
477#define rr_type		rr_hdr.icmp6_type
478#define rr_code		rr_hdr.icmp6_code
479#define rr_cksum	rr_hdr.icmp6_cksum
480#define rr_seqnum 	rr_hdr.icmp6_data32[0]
481
482struct rr_pco_match {		/* match prefix part */
483	u_int8_t	rpm_code;
484	u_int8_t	rpm_len;
485	u_int8_t	rpm_ordinal;
486	u_int8_t	rpm_matchlen;
487	u_int8_t	rpm_minlen;
488	u_int8_t	rpm_maxlen;
489	u_int16_t	rpm_reserved;
490	struct	in6_addr	rpm_prefix;
491} __packed;
492
493#define RPM_PCO_ADD		1
494#define RPM_PCO_CHANGE		2
495#define RPM_PCO_SETGLOBAL	3
496#define RPM_PCO_MAX		4
497
498struct rr_pco_use {		/* use prefix part */
499	u_int8_t	rpu_uselen;
500	u_int8_t	rpu_keeplen;
501	u_int8_t	rpu_ramask;
502	u_int8_t	rpu_raflags;
503	u_int32_t	rpu_vltime;
504	u_int32_t	rpu_pltime;
505	u_int32_t	rpu_flags;
506	struct	in6_addr rpu_prefix;
507} __packed;
508#define ICMP6_RR_PCOUSE_RAFLAGS_ONLINK	0x80
509#define ICMP6_RR_PCOUSE_RAFLAGS_AUTO	0x40
510
511#if BYTE_ORDER == BIG_ENDIAN
512#define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME     0x80000000
513#define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME     0x40000000
514#elif BYTE_ORDER == LITTLE_ENDIAN
515#define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME     0x80
516#define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME     0x40
517#endif
518
519struct rr_result {		/* router renumbering result message */
520	u_int16_t	rrr_flags;
521	u_int8_t	rrr_ordinal;
522	u_int8_t	rrr_matchedlen;
523	u_int32_t	rrr_ifid;
524	struct	in6_addr rrr_prefix;
525} __packed;
526#if BYTE_ORDER == BIG_ENDIAN
527#define ICMP6_RR_RESULT_FLAGS_OOB		0x0002
528#define ICMP6_RR_RESULT_FLAGS_FORBIDDEN		0x0001
529#elif BYTE_ORDER == LITTLE_ENDIAN
530#define ICMP6_RR_RESULT_FLAGS_OOB		0x0200
531#define ICMP6_RR_RESULT_FLAGS_FORBIDDEN		0x0100
532#endif
533
534/*
535 * icmp6 filter structures.
536 */
537
538struct icmp6_filter {
539	u_int32_t icmp6_filt[8];
540};
541
542#ifdef _KERNEL
543#define	ICMP6_FILTER_SETPASSALL(filterp) \
544do {								\
545	int i; u_char *p;					\
546	p = (u_char *)filterp;					\
547	for (i = 0; i < sizeof(struct icmp6_filter); i++)	\
548		p[i] = 0xff;					\
549} while (/*CONSTCOND*/ 0)
550#define	ICMP6_FILTER_SETBLOCKALL(filterp) \
551	bzero(filterp, sizeof(struct icmp6_filter))
552#else /* _KERNEL */
553#define	ICMP6_FILTER_SETPASSALL(filterp) \
554	memset(filterp, 0xff, sizeof(struct icmp6_filter))
555#define	ICMP6_FILTER_SETBLOCKALL(filterp) \
556	memset(filterp, 0x00, sizeof(struct icmp6_filter))
557#endif /* _KERNEL */
558
559#define	ICMP6_FILTER_SETPASS(type, filterp) \
560	(((filterp)->icmp6_filt[(type) >> 5]) |= (1 << ((type) & 31)))
561#define	ICMP6_FILTER_SETBLOCK(type, filterp) \
562	(((filterp)->icmp6_filt[(type) >> 5]) &= ~(1 << ((type) & 31)))
563#define	ICMP6_FILTER_WILLPASS(type, filterp) \
564	((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) != 0)
565#define	ICMP6_FILTER_WILLBLOCK(type, filterp) \
566	((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) == 0)
567
568/*
569 * Variables related to this implementation
570 * of the internet control message protocol version 6.
571 */
572struct icmp6errstat {
573	uint64_t icp6errs_dst_unreach_noroute;
574	uint64_t icp6errs_dst_unreach_admin;
575	uint64_t icp6errs_dst_unreach_beyondscope;
576	uint64_t icp6errs_dst_unreach_addr;
577	uint64_t icp6errs_dst_unreach_noport;
578	uint64_t icp6errs_packet_too_big;
579	uint64_t icp6errs_time_exceed_transit;
580	uint64_t icp6errs_time_exceed_reassembly;
581	uint64_t icp6errs_paramprob_header;
582	uint64_t icp6errs_paramprob_nextheader;
583	uint64_t icp6errs_paramprob_option;
584	uint64_t icp6errs_redirect; /* we regard redirect as an error here */
585	uint64_t icp6errs_unknown;
586};
587
588struct icmp6stat {
589/* statistics related to icmp6 packets generated */
590	uint64_t icp6s_error;		/* # of calls to icmp6_error */
591	uint64_t icp6s_canterror;	/* no error 'cuz old was icmp */
592	uint64_t icp6s_toofreq;		/* no error 'cuz rate limitation */
593	uint64_t icp6s_outhist[256];
594/* statistics related to input message processed */
595	uint64_t icp6s_badcode;		/* icmp6_code out of range */
596	uint64_t icp6s_tooshort;	/* packet < sizeof(struct icmp6_hdr) */
597	uint64_t icp6s_checksum;	/* bad checksum */
598	uint64_t icp6s_badlen;		/* calculated bound mismatch */
599	/*
600	 * number of responses: this member is inherited from netinet code, but
601	 * for netinet6 code, it is already available in icp6s_outhist[].
602	 */
603	uint64_t icp6s_reflect;
604	uint64_t icp6s_inhist[256];
605	uint64_t icp6s_nd_toomanyopt;	/* too many ND options */
606	struct icmp6errstat icp6s_outerrhist;
607#define icp6s_odst_unreach_noroute \
608	icp6s_outerrhist.icp6errs_dst_unreach_noroute
609#define icp6s_odst_unreach_admin icp6s_outerrhist.icp6errs_dst_unreach_admin
610#define icp6s_odst_unreach_beyondscope \
611	icp6s_outerrhist.icp6errs_dst_unreach_beyondscope
612#define icp6s_odst_unreach_addr icp6s_outerrhist.icp6errs_dst_unreach_addr
613#define icp6s_odst_unreach_noport icp6s_outerrhist.icp6errs_dst_unreach_noport
614#define icp6s_opacket_too_big icp6s_outerrhist.icp6errs_packet_too_big
615#define icp6s_otime_exceed_transit \
616	icp6s_outerrhist.icp6errs_time_exceed_transit
617#define icp6s_otime_exceed_reassembly \
618	icp6s_outerrhist.icp6errs_time_exceed_reassembly
619#define icp6s_oparamprob_header icp6s_outerrhist.icp6errs_paramprob_header
620#define icp6s_oparamprob_nextheader \
621	icp6s_outerrhist.icp6errs_paramprob_nextheader
622#define icp6s_oparamprob_option icp6s_outerrhist.icp6errs_paramprob_option
623#define icp6s_oredirect icp6s_outerrhist.icp6errs_redirect
624#define icp6s_ounknown icp6s_outerrhist.icp6errs_unknown
625	uint64_t icp6s_pmtuchg;		/* path MTU changes */
626	uint64_t icp6s_nd_badopt;	/* bad ND options */
627	uint64_t icp6s_badns;		/* bad neighbor solicitation */
628	uint64_t icp6s_badna;		/* bad neighbor advertisement */
629	uint64_t icp6s_badrs;		/* bad router solicitation */
630	uint64_t icp6s_badra;		/* bad router advertisement */
631	uint64_t icp6s_badredirect;	/* bad redirect message */
632};
633
634#ifdef _KERNEL
635#include <sys/counter.h>
636
637VNET_PCPUSTAT_DECLARE(struct icmp6stat, icmp6stat);
638/*
639 * In-kernel consumers can use these accessor macros directly to update
640 * stats.
641 */
642#define	ICMP6STAT_ADD(name, val)	\
643    VNET_PCPUSTAT_ADD(struct icmp6stat, icmp6stat, name, (val))
644#define	ICMP6STAT_INC(name)		ICMP6STAT_ADD(name, 1)
645
646/*
647 * Kernel module consumers must use this accessor macro.
648 */
649void	kmod_icmp6stat_inc(int statnum);
650#define	KMOD_ICMP6STAT_INC(name)	\
651    kmod_icmp6stat_inc(offsetof(struct icmp6stat, name) / sizeof(uint64_t))
652#endif
653
654/*
655 * Names for ICMP sysctl objects
656 */
657#define ICMPV6CTL_STATS		1
658#define ICMPV6CTL_REDIRACCEPT	2	/* accept/process redirects */
659#define ICMPV6CTL_REDIRTIMEOUT	3	/* redirect cache time */
660#if 0	/*obsoleted*/
661#define ICMPV6CTL_ERRRATELIMIT	5	/* ICMPv6 error rate limitation */
662#endif
663#define ICMPV6CTL_ND6_PRUNE	6
664#define ICMPV6CTL_ND6_DELAY	8
665#define ICMPV6CTL_ND6_UMAXTRIES	9
666#define ICMPV6CTL_ND6_MMAXTRIES		10
667#define ICMPV6CTL_ND6_USELOOPBACK	11
668/*#define ICMPV6CTL_ND6_PROXYALL	12	obsoleted, do not reuse here */
669#define ICMPV6CTL_NODEINFO	13
670#define ICMPV6CTL_ERRPPSLIMIT	14	/* ICMPv6 error pps limitation */
671#define ICMPV6CTL_ND6_MAXNUDHINT	15
672#define ICMPV6CTL_MTUDISC_HIWAT	16
673#define ICMPV6CTL_MTUDISC_LOWAT	17
674#define ICMPV6CTL_ND6_DEBUG	18
675#define ICMPV6CTL_ND6_DRLIST	19
676#define ICMPV6CTL_ND6_PRLIST	20
677#define ICMPV6CTL_MLD_MAXSRCFILTER	21
678#define ICMPV6CTL_MLD_SOMAXSRC	22
679#define ICMPV6CTL_MLD_VERSION	23
680#define ICMPV6CTL_ND6_MAXQLEN	24
681#define ICMPV6CTL_NODEINFO_OLDMCPREFIX	25
682#define ICMPV6CTL_MAXID		26
683
684#define RTF_PROBEMTU	RTF_PROTO1
685
686#ifdef _KERNEL
687# ifdef __STDC__
688struct	rtentry;
689struct	rttimer;
690struct	in6_multi;
691# endif
692void	icmp6_paramerror(struct mbuf *, int);
693void	icmp6_error(struct mbuf *, int, int, int);
694void	icmp6_error2(struct mbuf *, int, int, int, struct ifnet *);
695int	icmp6_input(struct mbuf **, int *, int);
696void	icmp6_fasttimo(void);
697void	icmp6_slowtimo(void);
698void	icmp6_reflect(struct mbuf *, size_t);
699void	icmp6_prepare(struct mbuf *);
700void	icmp6_redirect_input(struct mbuf *, int);
701void	icmp6_redirect_output(struct mbuf *, struct rtentry *);
702
703struct	ip6ctlparam;
704void	icmp6_mtudisc_update(struct ip6ctlparam *, int);
705
706/* XXX: is this the right place for these macros? */
707#define icmp6_ifstat_inc(ifp, tag) \
708do {								\
709	if (ifp)						\
710		counter_u64_add(((struct in6_ifextra *)		\
711		    ((ifp)->if_afdata[AF_INET6]))->icmp6_ifstat[\
712		    offsetof(struct icmp6_ifstat, tag) / sizeof(uint64_t)], 1);\
713} while (/*CONSTCOND*/ 0)
714
715#define icmp6_ifoutstat_inc(ifp, type, code) \
716do { \
717		icmp6_ifstat_inc(ifp, ifs6_out_msg); \
718 		if (type < ICMP6_INFOMSG_MASK) \
719 			icmp6_ifstat_inc(ifp, ifs6_out_error); \
720		switch (type) { \
721		 case ICMP6_DST_UNREACH: \
722			 icmp6_ifstat_inc(ifp, ifs6_out_dstunreach); \
723			 if (code == ICMP6_DST_UNREACH_ADMIN) \
724				 icmp6_ifstat_inc(ifp, ifs6_out_adminprohib); \
725			 break; \
726		 case ICMP6_PACKET_TOO_BIG: \
727			 icmp6_ifstat_inc(ifp, ifs6_out_pkttoobig); \
728			 break; \
729		 case ICMP6_TIME_EXCEEDED: \
730			 icmp6_ifstat_inc(ifp, ifs6_out_timeexceed); \
731			 break; \
732		 case ICMP6_PARAM_PROB: \
733			 icmp6_ifstat_inc(ifp, ifs6_out_paramprob); \
734			 break; \
735		 case ICMP6_ECHO_REQUEST: \
736			 icmp6_ifstat_inc(ifp, ifs6_out_echo); \
737			 break; \
738		 case ICMP6_ECHO_REPLY: \
739			 icmp6_ifstat_inc(ifp, ifs6_out_echoreply); \
740			 break; \
741		 case MLD_LISTENER_QUERY: \
742			 icmp6_ifstat_inc(ifp, ifs6_out_mldquery); \
743			 break; \
744		 case MLD_LISTENER_REPORT: \
745			 icmp6_ifstat_inc(ifp, ifs6_out_mldreport); \
746			 break; \
747		 case MLD_LISTENER_DONE: \
748			 icmp6_ifstat_inc(ifp, ifs6_out_mlddone); \
749			 break; \
750		 case ND_ROUTER_SOLICIT: \
751			 icmp6_ifstat_inc(ifp, ifs6_out_routersolicit); \
752			 break; \
753		 case ND_ROUTER_ADVERT: \
754			 icmp6_ifstat_inc(ifp, ifs6_out_routeradvert); \
755			 break; \
756		 case ND_NEIGHBOR_SOLICIT: \
757			 icmp6_ifstat_inc(ifp, ifs6_out_neighborsolicit); \
758			 break; \
759		 case ND_NEIGHBOR_ADVERT: \
760			 icmp6_ifstat_inc(ifp, ifs6_out_neighboradvert); \
761			 break; \
762		 case ND_REDIRECT: \
763			 icmp6_ifstat_inc(ifp, ifs6_out_redirect); \
764			 break; \
765		} \
766} while (/*CONSTCOND*/ 0)
767
768VNET_DECLARE(int, icmp6_rediraccept);	/* accept/process redirects */
769VNET_DECLARE(int, icmp6_redirtimeout);	/* cache time for redirect routes */
770
771#define	V_icmp6_rediraccept	VNET(icmp6_rediraccept)
772#define	V_icmp6_redirtimeout	VNET(icmp6_redirtimeout)
773
774#define ICMP6_NODEINFO_FQDNOK		0x1
775#define ICMP6_NODEINFO_NODEADDROK	0x2
776#define ICMP6_NODEINFO_TMPADDROK	0x4
777#define ICMP6_NODEINFO_GLOBALOK		0x8
778#endif /* _KERNEL */
779
780#endif /* not _NETINET_ICMP6_H_ */
781