blob: 0ecc2e59d9f20d1b74e4d7e6ff72d40260b98779 [file] [log] [blame]
Lorenzo Colittice7c4042013-07-01 17:07:03 +09001/* $NetBSD: icmp6.h,v 1.47 2013/07/01 12:43:15 christos Exp $ */
Steinar H. Gunderson6846a452011-01-20 01:31:36 +01002/* $KAME: icmp6.h,v 1.84 2003/04/23 10:26:51 itojun Exp $ */
3
4
5/*
6 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the project nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34/*
35 * Copyright (c) 1982, 1986, 1993
36 * The Regents of the University of California. All rights reserved.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
46 * 3. Neither the name of the University nor the names of its contributors
47 * may be used to endorse or promote products derived from this software
48 * without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * SUCH DAMAGE.
61 *
62 * @(#)ip_icmp.h 8.1 (Berkeley) 6/10/93
63 */
64
65#ifndef _NETINET_ICMP6_H_
66#define _NETINET_ICMP6_H_
67
Elliott Hughes3a040d82013-07-08 11:16:24 -070068#include <netinet/in.h> /* android-added: glibc source compatibility. */
69
Steinar H. Gunderson6846a452011-01-20 01:31:36 +010070#define ICMPV6_PLD_MAXLEN 1232 /* IPV6_MMTU - sizeof(struct ip6_hdr)
71 - sizeof(struct icmp6_hdr) */
72
73struct icmp6_hdr {
74 u_int8_t icmp6_type; /* type field */
75 u_int8_t icmp6_code; /* code field */
76 u_int16_t icmp6_cksum; /* checksum field */
77 union {
78 u_int32_t icmp6_un_data32[1]; /* type-specific field */
79 u_int16_t icmp6_un_data16[2]; /* type-specific field */
80 u_int8_t icmp6_un_data8[4]; /* type-specific field */
81 } icmp6_dataun;
82} __packed;
83
84#define icmp6_data32 icmp6_dataun.icmp6_un_data32
85#define icmp6_data16 icmp6_dataun.icmp6_un_data16
86#define icmp6_data8 icmp6_dataun.icmp6_un_data8
87#define icmp6_pptr icmp6_data32[0] /* parameter prob */
88#define icmp6_mtu icmp6_data32[0] /* packet too big */
89#define icmp6_id icmp6_data16[0] /* echo request/reply */
90#define icmp6_seq icmp6_data16[1] /* echo request/reply */
91#define icmp6_maxdelay icmp6_data16[0] /* mcast group membership */
92
93#define ICMP6_DST_UNREACH 1 /* dest unreachable, codes: */
94#define ICMP6_PACKET_TOO_BIG 2 /* packet too big */
95#define ICMP6_TIME_EXCEEDED 3 /* time exceeded, code: */
96#define ICMP6_PARAM_PROB 4 /* ip6 header bad */
97
98#define ICMP6_ECHO_REQUEST 128 /* echo service */
99#define ICMP6_ECHO_REPLY 129 /* echo reply */
100#define MLD_LISTENER_QUERY 130 /* multicast listener query */
101#define MLD_LISTENER_REPORT 131 /* multicast listener report */
102#define MLD_LISTENER_DONE 132 /* multicast listener done */
Lorenzo Colittice7c4042013-07-01 17:07:03 +0900103#define MLD_LISTENER_REDUCTION MLD_LISTENER_DONE /* RFC3542 definition */
Steinar H. Gunderson6846a452011-01-20 01:31:36 +0100104
105/* RFC2292 decls */
106#define ICMP6_MEMBERSHIP_QUERY 130 /* group membership query */
107#define ICMP6_MEMBERSHIP_REPORT 131 /* group membership report */
108#define ICMP6_MEMBERSHIP_REDUCTION 132 /* group membership termination */
109
110#ifndef _KERNEL
111/* the followings are for backward compatibility to old KAME apps. */
112#define MLD6_LISTENER_QUERY MLD_LISTENER_QUERY
113#define MLD6_LISTENER_REPORT MLD_LISTENER_REPORT
114#define MLD6_LISTENER_DONE MLD_LISTENER_DONE
115#endif
116
117#define ND_ROUTER_SOLICIT 133 /* router solicitation */
118#define ND_ROUTER_ADVERT 134 /* router advertisement */
119#define ND_NEIGHBOR_SOLICIT 135 /* neighbor solicitation */
120#define ND_NEIGHBOR_ADVERT 136 /* neighbor advertisement */
121#define ND_REDIRECT 137 /* redirect */
122
123#define ICMP6_ROUTER_RENUMBERING 138 /* router renumbering */
124
125#define ICMP6_WRUREQUEST 139 /* who are you request */
126#define ICMP6_WRUREPLY 140 /* who are you reply */
127#define ICMP6_FQDN_QUERY 139 /* FQDN query */
128#define ICMP6_FQDN_REPLY 140 /* FQDN reply */
129#define ICMP6_NI_QUERY 139 /* node information request */
130#define ICMP6_NI_REPLY 140 /* node information reply */
Lorenzo Colittice7c4042013-07-01 17:07:03 +0900131#define MLDV2_LISTENER_REPORT 143 /* RFC3810 listener report */
Steinar H. Gunderson6846a452011-01-20 01:31:36 +0100132
133/* The definitions below are experimental. TBA */
134#define MLD_MTRACE_RESP 200 /* mtrace response(to sender) */
135#define MLD_MTRACE 201 /* mtrace messages */
136
137#ifndef _KERNEL
138/* the followings are for backward compatibility to old KAME apps. */
139#define MLD6_MTRACE_RESP MLD_MTRACE_RESP
140#define MLD6_MTRACE MLD_MTRACE
141#endif
142
143#define ICMP6_MAXTYPE 201
144
145#define ICMP6_DST_UNREACH_NOROUTE 0 /* no route to destination */
146#define ICMP6_DST_UNREACH_ADMIN 1 /* administratively prohibited */
147#define ICMP6_DST_UNREACH_NOTNEIGHBOR 2 /* not a neighbor(obsolete) */
148#define ICMP6_DST_UNREACH_BEYONDSCOPE 2 /* beyond scope of source address */
149#define ICMP6_DST_UNREACH_ADDR 3 /* address unreachable */
150#define ICMP6_DST_UNREACH_NOPORT 4 /* port unreachable */
Lorenzo Colittice7c4042013-07-01 17:07:03 +0900151#define ICMP6_DST_UNREACH_POLICY 5 /* source address failed ingress/egress policy */
152#define ICMP6_DST_UNREACH_REJROUTE 6 /* reject route to destination */
153#define ICMP6_DST_UNREACH_SOURCERT 7 /* error in source routing header */
Steinar H. Gunderson6846a452011-01-20 01:31:36 +0100154
155#define ICMP6_TIME_EXCEED_TRANSIT 0 /* ttl==0 in transit */
156#define ICMP6_TIME_EXCEED_REASSEMBLY 1 /* ttl==0 in reass */
157
158#define ICMP6_PARAMPROB_HEADER 0 /* erroneous header field */
159#define ICMP6_PARAMPROB_NEXTHEADER 1 /* unrecognized next header */
160#define ICMP6_PARAMPROB_OPTION 2 /* unrecognized option */
161
162#define ICMP6_INFOMSG_MASK 0x80 /* all informational messages */
163
164#define ICMP6_NI_SUBJ_IPV6 0 /* Query Subject is an IPv6 address */
165#define ICMP6_NI_SUBJ_FQDN 1 /* Query Subject is a Domain name */
166#define ICMP6_NI_SUBJ_IPV4 2 /* Query Subject is an IPv4 address */
167
168#define ICMP6_NI_SUCCESS 0 /* node information successful reply */
169#define ICMP6_NI_REFUSED 1 /* node information request is refused */
170#define ICMP6_NI_UNKNOWN 2 /* unknown Qtype */
171
172#define ICMP6_ROUTER_RENUMBERING_COMMAND 0 /* rr command */
173#define ICMP6_ROUTER_RENUMBERING_RESULT 1 /* rr result */
174#define ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET 255 /* rr seq num reset */
175
176/* Used in kernel only */
177#define ND_REDIRECT_ONLINK 0 /* redirect to an on-link node */
178#define ND_REDIRECT_ROUTER 1 /* redirect to a better router */
179
180/*
181 * Multicast Listener Discovery
182 */
183struct mld_hdr {
184 struct icmp6_hdr mld_icmp6_hdr;
185 struct in6_addr mld_addr; /* multicast address */
186} __packed;
187
188/* definitions to provide backward compatibility to old KAME applications */
189#ifndef _KERNEL
190#define mld6_hdr mld_hdr
191#define mld6_type mld_type
192#define mld6_code mld_code
193#define mld6_cksum mld_cksum
194#define mld6_maxdelay mld_maxdelay
195#define mld6_reserved mld_reserved
196#define mld6_addr mld_addr
197#endif
198
199/* shortcut macro definitions */
200#define mld_type mld_icmp6_hdr.icmp6_type
201#define mld_code mld_icmp6_hdr.icmp6_code
202#define mld_cksum mld_icmp6_hdr.icmp6_cksum
203#define mld_maxdelay mld_icmp6_hdr.icmp6_data16[0]
204#define mld_reserved mld_icmp6_hdr.icmp6_data16[1]
205
206#define MLD_MINLEN 24
207
208/*
209 * Neighbor Discovery
210 */
211
212struct nd_router_solicit { /* router solicitation */
213 struct icmp6_hdr nd_rs_hdr;
214 /* could be followed by options */
215} __packed;
216
217#define nd_rs_type nd_rs_hdr.icmp6_type
218#define nd_rs_code nd_rs_hdr.icmp6_code
219#define nd_rs_cksum nd_rs_hdr.icmp6_cksum
220#define nd_rs_reserved nd_rs_hdr.icmp6_data32[0]
221
222struct nd_router_advert { /* router advertisement */
223 struct icmp6_hdr nd_ra_hdr;
224 u_int32_t nd_ra_reachable; /* reachable time */
225 u_int32_t nd_ra_retransmit; /* retransmit timer */
226 /* could be followed by options */
227} __packed;
228
229#define nd_ra_type nd_ra_hdr.icmp6_type
230#define nd_ra_code nd_ra_hdr.icmp6_code
231#define nd_ra_cksum nd_ra_hdr.icmp6_cksum
232#define nd_ra_curhoplimit nd_ra_hdr.icmp6_data8[0]
233#define nd_ra_flags_reserved nd_ra_hdr.icmp6_data8[1]
234#define ND_RA_FLAG_MANAGED 0x80
235#define ND_RA_FLAG_OTHER 0x40
236#define ND_RA_FLAG_HOME_AGENT 0x20
237
238/*
Lorenzo Colittice7c4042013-07-01 17:07:03 +0900239 * Router preference values based on RFC4191.
Steinar H. Gunderson6846a452011-01-20 01:31:36 +0100240 */
241#define ND_RA_FLAG_RTPREF_MASK 0x18 /* 00011000 */
242
243#define ND_RA_FLAG_RTPREF_HIGH 0x08 /* 00001000 */
244#define ND_RA_FLAG_RTPREF_MEDIUM 0x00 /* 00000000 */
245#define ND_RA_FLAG_RTPREF_LOW 0x18 /* 00011000 */
246#define ND_RA_FLAG_RTPREF_RSV 0x10 /* 00010000 */
247
248#define nd_ra_router_lifetime nd_ra_hdr.icmp6_data16[1]
249
250struct nd_neighbor_solicit { /* neighbor solicitation */
251 struct icmp6_hdr nd_ns_hdr;
252 struct in6_addr nd_ns_target; /*target address */
253 /* could be followed by options */
254} __packed;
255
256#define nd_ns_type nd_ns_hdr.icmp6_type
257#define nd_ns_code nd_ns_hdr.icmp6_code
258#define nd_ns_cksum nd_ns_hdr.icmp6_cksum
259#define nd_ns_reserved nd_ns_hdr.icmp6_data32[0]
260
261struct nd_neighbor_advert { /* neighbor advertisement */
262 struct icmp6_hdr nd_na_hdr;
263 struct in6_addr nd_na_target; /* target address */
264 /* could be followed by options */
265} __packed;
266
267#define nd_na_type nd_na_hdr.icmp6_type
268#define nd_na_code nd_na_hdr.icmp6_code
269#define nd_na_cksum nd_na_hdr.icmp6_cksum
270#define nd_na_flags_reserved nd_na_hdr.icmp6_data32[0]
271#if BYTE_ORDER == BIG_ENDIAN
272#define ND_NA_FLAG_ROUTER 0x80000000
273#define ND_NA_FLAG_SOLICITED 0x40000000
274#define ND_NA_FLAG_OVERRIDE 0x20000000
275#else
276#if BYTE_ORDER == LITTLE_ENDIAN
277#define ND_NA_FLAG_ROUTER 0x80
278#define ND_NA_FLAG_SOLICITED 0x40
279#define ND_NA_FLAG_OVERRIDE 0x20
280#endif
281#endif
282
283struct nd_redirect { /* redirect */
284 struct icmp6_hdr nd_rd_hdr;
285 struct in6_addr nd_rd_target; /* target address */
286 struct in6_addr nd_rd_dst; /* destination address */
287 /* could be followed by options */
288} __packed;
289
290#define nd_rd_type nd_rd_hdr.icmp6_type
291#define nd_rd_code nd_rd_hdr.icmp6_code
292#define nd_rd_cksum nd_rd_hdr.icmp6_cksum
293#define nd_rd_reserved nd_rd_hdr.icmp6_data32[0]
294
295struct nd_opt_hdr { /* Neighbor discovery option header */
296 u_int8_t nd_opt_type;
297 u_int8_t nd_opt_len;
298 /* followed by option specific data*/
299} __packed;
300
301#define ND_OPT_SOURCE_LINKADDR 1
302#define ND_OPT_TARGET_LINKADDR 2
303#define ND_OPT_PREFIX_INFORMATION 3
304#define ND_OPT_REDIRECTED_HEADER 4
305#define ND_OPT_MTU 5
306#define ND_OPT_ADVINTERVAL 7
307#define ND_OPT_HOMEAGENT_INFO 8
308#define ND_OPT_SOURCE_ADDRLIST 9
309#define ND_OPT_TARGET_ADDRLIST 10
Lorenzo Colittice7c4042013-07-01 17:07:03 +0900310#define ND_OPT_MAP 23 /* RFC 5380 */
311#define ND_OPT_ROUTE_INFO 24 /* RFC 4191 */
312#define ND_OPT_RDNSS 25 /* RFC 6016 */
313#define ND_OPT_DNSSL 31 /* RFC 6016 */
Steinar H. Gunderson6846a452011-01-20 01:31:36 +0100314
315struct nd_opt_route_info { /* route info */
316 u_int8_t nd_opt_rti_type;
317 u_int8_t nd_opt_rti_len;
318 u_int8_t nd_opt_rti_prefixlen;
319 u_int8_t nd_opt_rti_flags;
320 u_int32_t nd_opt_rti_lifetime;
321 /* prefix follows */
322};
323
324struct nd_opt_prefix_info { /* prefix information */
325 u_int8_t nd_opt_pi_type;
326 u_int8_t nd_opt_pi_len;
327 u_int8_t nd_opt_pi_prefix_len;
328 u_int8_t nd_opt_pi_flags_reserved;
329 u_int32_t nd_opt_pi_valid_time;
330 u_int32_t nd_opt_pi_preferred_time;
331 u_int32_t nd_opt_pi_reserved2;
332 struct in6_addr nd_opt_pi_prefix;
333} __packed;
334
335#define ND_OPT_PI_FLAG_ONLINK 0x80
336#define ND_OPT_PI_FLAG_AUTO 0x40
337
338struct nd_opt_rd_hdr { /* redirected header */
339 u_int8_t nd_opt_rh_type;
340 u_int8_t nd_opt_rh_len;
341 u_int16_t nd_opt_rh_reserved1;
342 u_int32_t nd_opt_rh_reserved2;
343 /* followed by IP header and data */
344} __packed;
345
346struct nd_opt_mtu { /* MTU option */
347 u_int8_t nd_opt_mtu_type;
348 u_int8_t nd_opt_mtu_len;
349 u_int16_t nd_opt_mtu_reserved;
350 u_int32_t nd_opt_mtu_mtu;
351} __packed;
352
Lorenzo Colittice7c4042013-07-01 17:07:03 +0900353struct nd_opt_rdnss { /* RDNSS option RFC 6106 */
Steinar H. Gunderson6846a452011-01-20 01:31:36 +0100354 u_int8_t nd_opt_rdnss_type;
355 u_int8_t nd_opt_rdnss_len;
356 u_int16_t nd_opt_rdnss_reserved;
357 u_int32_t nd_opt_rdnss_lifetime;
358 /* followed by list of IP prefixes */
359} __packed;
360
Lorenzo Colittice7c4042013-07-01 17:07:03 +0900361struct nd_opt_dnssl { /* DNSSL option RFC 6106 */
362 u_int8_t nd_opt_dnssl_type;
363 u_int8_t nd_opt_dnssl_len;
364 u_int16_t nd_opt_dnssl_reserved;
365 u_int32_t nd_opt_dnssl_lifetime;
366 /* followed by list of IP prefixes */
367} __packed;
368
Steinar H. Gunderson6846a452011-01-20 01:31:36 +0100369/*
370 * icmp6 namelookup
371 */
372
373struct icmp6_namelookup {
374 struct icmp6_hdr icmp6_nl_hdr;
375 u_int8_t icmp6_nl_nonce[8];
376 int32_t icmp6_nl_ttl;
377#if 0
378 u_int8_t icmp6_nl_len;
379 u_int8_t icmp6_nl_name[3];
380#endif
381 /* could be followed by options */
382} __packed;
383
384/*
385 * icmp6 node information
386 */
387struct icmp6_nodeinfo {
388 struct icmp6_hdr icmp6_ni_hdr;
389 u_int8_t icmp6_ni_nonce[8];
390 /* could be followed by reply data */
391} __packed;
392
393#define ni_type icmp6_ni_hdr.icmp6_type
394#define ni_code icmp6_ni_hdr.icmp6_code
395#define ni_cksum icmp6_ni_hdr.icmp6_cksum
396#define ni_qtype icmp6_ni_hdr.icmp6_data16[0]
397#define ni_flags icmp6_ni_hdr.icmp6_data16[1]
398
399#define NI_QTYPE_NOOP 0 /* NOOP */
400#define NI_QTYPE_SUPTYPES 1 /* Supported Qtypes */
401#define NI_QTYPE_FQDN 2 /* FQDN (draft 04) */
402#define NI_QTYPE_DNSNAME 2 /* DNS Name */
403#define NI_QTYPE_NODEADDR 3 /* Node Addresses */
404#define NI_QTYPE_IPV4ADDR 4 /* IPv4 Addresses */
405
406#if BYTE_ORDER == BIG_ENDIAN
407#define NI_SUPTYPE_FLAG_COMPRESS 0x1
408#define NI_FQDN_FLAG_VALIDTTL 0x1
409#elif BYTE_ORDER == LITTLE_ENDIAN
410#define NI_SUPTYPE_FLAG_COMPRESS 0x0100
411#define NI_FQDN_FLAG_VALIDTTL 0x0100
412#endif
413
414#ifdef NAME_LOOKUPS_04
415#if BYTE_ORDER == BIG_ENDIAN
416#define NI_NODEADDR_FLAG_LINKLOCAL 0x1
417#define NI_NODEADDR_FLAG_SITELOCAL 0x2
418#define NI_NODEADDR_FLAG_GLOBAL 0x4
419#define NI_NODEADDR_FLAG_ALL 0x8
420#define NI_NODEADDR_FLAG_TRUNCATE 0x10
421#define NI_NODEADDR_FLAG_ANYCAST 0x20 /* just experimental. not in spec */
422#elif BYTE_ORDER == LITTLE_ENDIAN
423#define NI_NODEADDR_FLAG_LINKLOCAL 0x0100
424#define NI_NODEADDR_FLAG_SITELOCAL 0x0200
425#define NI_NODEADDR_FLAG_GLOBAL 0x0400
426#define NI_NODEADDR_FLAG_ALL 0x0800
427#define NI_NODEADDR_FLAG_TRUNCATE 0x1000
428#define NI_NODEADDR_FLAG_ANYCAST 0x2000 /* just experimental. not in spec */
429#endif
430#else /* draft-ietf-ipngwg-icmp-name-lookups-05 (and later?) */
431#if BYTE_ORDER == BIG_ENDIAN
432#define NI_NODEADDR_FLAG_TRUNCATE 0x1
433#define NI_NODEADDR_FLAG_ALL 0x2
434#define NI_NODEADDR_FLAG_COMPAT 0x4
435#define NI_NODEADDR_FLAG_LINKLOCAL 0x8
436#define NI_NODEADDR_FLAG_SITELOCAL 0x10
437#define NI_NODEADDR_FLAG_GLOBAL 0x20
438#define NI_NODEADDR_FLAG_ANYCAST 0x40 /* just experimental. not in spec */
439#elif BYTE_ORDER == LITTLE_ENDIAN
440#define NI_NODEADDR_FLAG_TRUNCATE 0x0100
441#define NI_NODEADDR_FLAG_ALL 0x0200
442#define NI_NODEADDR_FLAG_COMPAT 0x0400
443#define NI_NODEADDR_FLAG_LINKLOCAL 0x0800
444#define NI_NODEADDR_FLAG_SITELOCAL 0x1000
445#define NI_NODEADDR_FLAG_GLOBAL 0x2000
446#define NI_NODEADDR_FLAG_ANYCAST 0x4000 /* just experimental. not in spec */
447#endif
448#endif
449
450struct ni_reply_fqdn {
451 u_int32_t ni_fqdn_ttl; /* TTL */
452 u_int8_t ni_fqdn_namelen; /* length in octets of the FQDN */
453 u_int8_t ni_fqdn_name[3]; /* XXX: alignment */
454} __packed;
455
456/*
457 * Router Renumbering. as router-renum-08.txt
458 */
459struct icmp6_router_renum { /* router renumbering header */
460 struct icmp6_hdr rr_hdr;
461 u_int8_t rr_segnum;
462 u_int8_t rr_flags;
463 u_int16_t rr_maxdelay;
464 u_int32_t rr_reserved;
465} __packed;
466
467#define ICMP6_RR_FLAGS_TEST 0x80
468#define ICMP6_RR_FLAGS_REQRESULT 0x40
469#define ICMP6_RR_FLAGS_FORCEAPPLY 0x20
470#define ICMP6_RR_FLAGS_SPECSITE 0x10
471#define ICMP6_RR_FLAGS_PREVDONE 0x08
472
473#define rr_type rr_hdr.icmp6_type
474#define rr_code rr_hdr.icmp6_code
475#define rr_cksum rr_hdr.icmp6_cksum
476#define rr_seqnum rr_hdr.icmp6_data32[0]
477
478struct rr_pco_match { /* match prefix part */
479 u_int8_t rpm_code;
480 u_int8_t rpm_len;
481 u_int8_t rpm_ordinal;
482 u_int8_t rpm_matchlen;
483 u_int8_t rpm_minlen;
484 u_int8_t rpm_maxlen;
485 u_int16_t rpm_reserved;
486 struct in6_addr rpm_prefix;
487} __packed;
488
489#define RPM_PCO_ADD 1
490#define RPM_PCO_CHANGE 2
491#define RPM_PCO_SETGLOBAL 3
492#define RPM_PCO_MAX 4
493
494struct rr_pco_use { /* use prefix part */
495 u_int8_t rpu_uselen;
496 u_int8_t rpu_keeplen;
497 u_int8_t rpu_ramask;
498 u_int8_t rpu_raflags;
499 u_int32_t rpu_vltime;
500 u_int32_t rpu_pltime;
501 u_int32_t rpu_flags;
502 struct in6_addr rpu_prefix;
503} __packed;
504#define ICMP6_RR_PCOUSE_RAFLAGS_ONLINK 0x80
505#define ICMP6_RR_PCOUSE_RAFLAGS_AUTO 0x40
506
507#if BYTE_ORDER == BIG_ENDIAN
508#define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME 0x80000000
509#define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME 0x40000000
510#elif BYTE_ORDER == LITTLE_ENDIAN
511#define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME 0x80
512#define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME 0x40
513#endif
514
515struct rr_result { /* router renumbering result message */
516 u_int16_t rrr_flags;
517 u_int8_t rrr_ordinal;
518 u_int8_t rrr_matchedlen;
519 u_int32_t rrr_ifid;
520 struct in6_addr rrr_prefix;
521} __packed;
522#if BYTE_ORDER == BIG_ENDIAN
523#define ICMP6_RR_RESULT_FLAGS_OOB 0x0002
524#define ICMP6_RR_RESULT_FLAGS_FORBIDDEN 0x0001
525#elif BYTE_ORDER == LITTLE_ENDIAN
526#define ICMP6_RR_RESULT_FLAGS_OOB 0x0200
527#define ICMP6_RR_RESULT_FLAGS_FORBIDDEN 0x0100
528#endif
529
530/*
531 * icmp6 filter structures.
532 */
533
534struct icmp6_filter {
535 u_int32_t icmp6_filt[8];
536};
537
Lorenzo Colittibfc6a592013-07-03 15:42:06 +0900538/*
539 * BEGIN android-changed
540 * Linux and *BSD kernels use opposite values to indicate pass/block in ICMPv6
541 * filters, and assign a different value to the ICMP6_FILTER sockopt.
542 */
543#define ICMP6_FILTER 1
544
Steinar H. Gunderson6846a452011-01-20 01:31:36 +0100545#define ICMP6_FILTER_SETPASSALL(filterp) \
Steinar H. Gunderson6846a452011-01-20 01:31:36 +0100546 (void)memset(filterp, 0x00, sizeof(struct icmp6_filter))
Lorenzo Colittibfc6a592013-07-03 15:42:06 +0900547#define ICMP6_FILTER_SETBLOCKALL(filterp) \
548 (void)memset(filterp, 0xff, sizeof(struct icmp6_filter))
Steinar H. Gunderson6846a452011-01-20 01:31:36 +0100549#define ICMP6_FILTER_SETPASS(type, filterp) \
Steinar H. Gunderson6846a452011-01-20 01:31:36 +0100550 (((filterp)->icmp6_filt[(type) >> 5]) &= ~(1 << ((type) & 31)))
Lorenzo Colittibfc6a592013-07-03 15:42:06 +0900551#define ICMP6_FILTER_SETBLOCK(type, filterp) \
552 (((filterp)->icmp6_filt[(type) >> 5]) |= (1 << ((type) & 31)))
Steinar H. Gunderson6846a452011-01-20 01:31:36 +0100553#define ICMP6_FILTER_WILLPASS(type, filterp) \
Steinar H. Gunderson6846a452011-01-20 01:31:36 +0100554 ((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) == 0)
Lorenzo Colittibfc6a592013-07-03 15:42:06 +0900555#define ICMP6_FILTER_WILLBLOCK(type, filterp) \
556 ((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) != 0)
557/*
558 * END android-changed
559 */
Steinar H. Gunderson6846a452011-01-20 01:31:36 +0100560
561/*
562 * Variables related to this implementation
563 * of the internet control message protocol version 6.
564 */
565
566/*
567 * IPv6 ICMP statistics.
568 * Each counter is an unsigned 64-bit value.
569 */
570#define ICMP6_STAT_ERROR 0 /* # of calls to icmp6_error */
571#define ICMP6_STAT_CANTERROR 1 /* no error (old was icmp) */
572#define ICMP6_STAT_TOOFREQ 2 /* no error (rate limitation) */
573#define ICMP6_STAT_OUTHIST 3 /* # of output messages */
574 /* space for 256 counters */
575#define ICMP6_STAT_BADCODE 259 /* icmp6_code out of range */
576#define ICMP6_STAT_TOOSHORT 260 /* packet < sizeof(struct icmp6_hdr) */
577#define ICMP6_STAT_CHECKSUM 261 /* bad checksum */
578#define ICMP6_STAT_BADLEN 262 /* calculated bound mismatch */
579 /*
580 * number of responses; this member is inherited from the netinet code,
581 * but for netinet6 code, it is already available in outhist[].
582 */
583#define ICMP6_STAT_REFLECT 263
584#define ICMP6_STAT_INHIST 264 /* # of input messages */
585 /* space for 256 counters */
586#define ICMP6_STAT_ND_TOOMANYOPT 520 /* too many ND options */
587#define ICMP6_STAT_OUTERRHIST 521
588 /* space for 13 counters */
589#define ICMP6_STAT_PMTUCHG 534 /* path MTU changes */
590#define ICMP6_STAT_ND_BADOPT 535 /* bad ND options */
591#define ICMP6_STAT_BADNS 536 /* bad neighbor solicititation */
592#define ICMP6_STAT_BADNA 537 /* bad neighbor advertisement */
593#define ICMP6_STAT_BADRS 538 /* bad router solicitiation */
594#define ICMP6_STAT_BADRA 539 /* bad router advertisement */
595#define ICMP6_STAT_BADREDIRECT 540 /* bad redirect message */
Lorenzo Colittice7c4042013-07-01 17:07:03 +0900596#define ICMP6_STAT_DROPPED_RAROUTE 541 /* discarded routes from router advertisement */
Steinar H. Gunderson6846a452011-01-20 01:31:36 +0100597
Lorenzo Colittice7c4042013-07-01 17:07:03 +0900598#define ICMP6_NSTATS 542
Steinar H. Gunderson6846a452011-01-20 01:31:36 +0100599
600#define ICMP6_ERRSTAT_DST_UNREACH_NOROUTE 0
601#define ICMP6_ERRSTAT_DST_UNREACH_ADMIN 1
602#define ICMP6_ERRSTAT_DST_UNREACH_BEYONDSCOPE 2
603#define ICMP6_ERRSTAT_DST_UNREACH_ADDR 3
604#define ICMP6_ERRSTAT_DST_UNREACH_NOPORT 4
605#define ICMP6_ERRSTAT_PACKET_TOO_BIG 5
606#define ICMP6_ERRSTAT_TIME_EXCEED_TRANSIT 6
607#define ICMP6_ERRSTAT_TIME_EXCEED_REASSEMBLY 7
608#define ICMP6_ERRSTAT_PARAMPROB_HEADER 8
609#define ICMP6_ERRSTAT_PARAMPROB_NEXTHEADER 9
610#define ICMP6_ERRSTAT_PARAMPROB_OPTION 10
611#define ICMP6_ERRSTAT_REDIRECT 11
612#define ICMP6_ERRSTAT_UNKNOWN 12
613
614/*
615 * Names for ICMP sysctl objects
616 */
617#define ICMPV6CTL_STATS 1
618#define ICMPV6CTL_REDIRACCEPT 2 /* accept/process redirects */
619#define ICMPV6CTL_REDIRTIMEOUT 3 /* redirect cache time */
620#if 0 /*obsoleted*/
621#define ICMPV6CTL_ERRRATELIMIT 5 /* ICMPv6 error rate limitation */
622#endif
623#define ICMPV6CTL_ND6_PRUNE 6
624#define ICMPV6CTL_ND6_DELAY 8
625#define ICMPV6CTL_ND6_UMAXTRIES 9
626#define ICMPV6CTL_ND6_MMAXTRIES 10
627#define ICMPV6CTL_ND6_USELOOPBACK 11
628/*#define ICMPV6CTL_ND6_PROXYALL 12 obsoleted, do not reuse here */
629#define ICMPV6CTL_NODEINFO 13
630#define ICMPV6CTL_ERRPPSLIMIT 14 /* ICMPv6 error pps limitation */
631#define ICMPV6CTL_ND6_MAXNUDHINT 15
632#define ICMPV6CTL_MTUDISC_HIWAT 16
633#define ICMPV6CTL_MTUDISC_LOWAT 17
634#define ICMPV6CTL_ND6_DEBUG 18
635#define ICMPV6CTL_ND6_DRLIST 19
636#define ICMPV6CTL_ND6_PRLIST 20
637#define ICMPV6CTL_ND6_MAXQLEN 24
638#define ICMPV6CTL_MAXID 25
639
640#define ICMPV6CTL_NAMES { \
641 { 0, 0 }, \
642 { 0, 0 }, \
643 { "rediraccept", CTLTYPE_INT }, \
644 { "redirtimeout", CTLTYPE_INT }, \
645 { 0, 0 }, \
646 { 0, 0 }, \
647 { "nd6_prune", CTLTYPE_INT }, \
648 { 0, 0 }, \
649 { "nd6_delay", CTLTYPE_INT }, \
650 { "nd6_umaxtries", CTLTYPE_INT }, \
651 { "nd6_mmaxtries", CTLTYPE_INT }, \
652 { "nd6_useloopback", CTLTYPE_INT }, \
653 { 0, 0 }, \
654 { "nodeinfo", CTLTYPE_INT }, \
655 { "errppslimit", CTLTYPE_INT }, \
656 { "nd6_maxnudhint", CTLTYPE_INT }, \
657 { "mtudisc_hiwat", CTLTYPE_INT }, \
658 { "mtudisc_lowat", CTLTYPE_INT }, \
659 { "nd6_debug", CTLTYPE_INT }, \
660 { 0, 0 }, \
661 { 0, 0 }, \
662 { 0, 0 }, \
663 { 0, 0 }, \
664 { 0, 0 }, \
665 { "nd6_maxqueuelen", CTLTYPE_INT }, \
666}
667
Steinar H. Gunderson6846a452011-01-20 01:31:36 +0100668#ifdef _KERNEL
669struct rtentry;
670struct rttimer;
671struct in6_multi;
672
673void icmp6_init(void);
674void icmp6_paramerror(struct mbuf *, int);
675void icmp6_error(struct mbuf *, int, int, int);
676void icmp6_error2(struct mbuf *, int, int, int, struct ifnet *);
677int icmp6_input(struct mbuf **, int *, int);
678void icmp6_fasttimo(void);
679void icmp6_reflect(struct mbuf *, size_t);
680void icmp6_prepare(struct mbuf *);
681void icmp6_redirect_input(struct mbuf *, int);
682void icmp6_redirect_output(struct mbuf *, struct rtentry *);
683int icmp6_sysctl(int *, u_int, void *, size_t *, void *, size_t);
684
685void icmp6_statinc(u_int);
686
687struct ip6ctlparam;
688void icmp6_mtudisc_update(struct ip6ctlparam *, int);
689void icmp6_mtudisc_callback_register(void (*)(struct in6_addr *));
690
691/* XXX: is this the right place for these macros? */
692#define icmp6_ifstat_inc(ifp, tag) \
693do { \
694 if (ifp) \
695 ((struct in6_ifextra *)((ifp)->if_afdata[AF_INET6]))->icmp6_ifstat->tag++; \
696} while (/*CONSTCOND*/ 0)
697
698#define icmp6_ifoutstat_inc(ifp, type, code) \
699do { \
700 icmp6_ifstat_inc(ifp, ifs6_out_msg); \
701 switch(type) { \
702 case ICMP6_DST_UNREACH: \
703 icmp6_ifstat_inc(ifp, ifs6_out_dstunreach); \
704 if (code == ICMP6_DST_UNREACH_ADMIN) \
705 icmp6_ifstat_inc(ifp, ifs6_out_adminprohib); \
706 break; \
707 case ICMP6_PACKET_TOO_BIG: \
708 icmp6_ifstat_inc(ifp, ifs6_out_pkttoobig); \
709 break; \
710 case ICMP6_TIME_EXCEEDED: \
711 icmp6_ifstat_inc(ifp, ifs6_out_timeexceed); \
712 break; \
713 case ICMP6_PARAM_PROB: \
714 icmp6_ifstat_inc(ifp, ifs6_out_paramprob); \
715 break; \
716 case ICMP6_ECHO_REQUEST: \
717 icmp6_ifstat_inc(ifp, ifs6_out_echo); \
718 break; \
719 case ICMP6_ECHO_REPLY: \
720 icmp6_ifstat_inc(ifp, ifs6_out_echoreply); \
721 break; \
722 case MLD_LISTENER_QUERY: \
723 icmp6_ifstat_inc(ifp, ifs6_out_mldquery); \
724 break; \
725 case MLD_LISTENER_REPORT: \
726 icmp6_ifstat_inc(ifp, ifs6_out_mldreport); \
727 break; \
728 case MLD_LISTENER_DONE: \
729 icmp6_ifstat_inc(ifp, ifs6_out_mlddone); \
730 break; \
731 case ND_ROUTER_SOLICIT: \
732 icmp6_ifstat_inc(ifp, ifs6_out_routersolicit); \
733 break; \
734 case ND_ROUTER_ADVERT: \
735 icmp6_ifstat_inc(ifp, ifs6_out_routeradvert); \
736 break; \
737 case ND_NEIGHBOR_SOLICIT: \
738 icmp6_ifstat_inc(ifp, ifs6_out_neighborsolicit); \
739 break; \
740 case ND_NEIGHBOR_ADVERT: \
741 icmp6_ifstat_inc(ifp, ifs6_out_neighboradvert); \
742 break; \
743 case ND_REDIRECT: \
744 icmp6_ifstat_inc(ifp, ifs6_out_redirect); \
745 break; \
746 } \
747} while (/*CONSTCOND*/ 0)
748
749extern int icmp6_rediraccept; /* accept/process redirects */
750extern int icmp6_redirtimeout; /* cache time for redirect routes */
751#endif /* _KERNEL */
752
Lorenzo Colittice7c4042013-07-01 17:07:03 +0900753#ifdef ICMP6_STRINGS
754/* Info: http://www.iana.org/assignments/icmpv6-parameters */
755
756static const char * const icmp6_type_err[] = {
757 "reserved0", "unreach", "packet_too_big", "timxceed", "paramprob",
758 NULL
759};
760
761static const char * const icmp6_type_info[] = {
762 "echo", "echoreply",
763 "mcastlistenq", "mcastlistenrep", "mcastlistendone",
764 "rtsol", "rtadv", "neighsol", "neighadv", "redirect",
765 "routerrenum", "nodeinfoq", "nodeinfor", "invneighsol", "invneighrep",
766 "mcastlistenrep2", "haad_req", "haad_rep",
767 "mobile_psol", "mobile_padv", "cga_sol", "cga_adv",
768 "experimental150", "mcast_rtadv", "mcast_rtsol", "mcast_rtterm",
769 "fmipv6_msg", "rpl_control", NULL
770};
771
772static const char * const icmp6_code_none[] = { "none", NULL };
773
774static const char * const icmp6_code_unreach[] = {
775 "noroute", "admin", "beyondscope", "addr", "port",
776 "srcaddr_policy", "reject_route", "source_route_err", NULL
777};
778
779static const char * const icmp6_code_timxceed[] = {
780 "intrans", "reass", NULL
781};
782
783static const char * const icmp6_code_paramprob[] = {
784 "hdr_field", "nxthdr_type", "option", NULL
785};
786
787/* not all informational icmps that have codes have a names array */
788#endif
789
Steinar H. Gunderson6846a452011-01-20 01:31:36 +0100790#endif /* !_NETINET_ICMP6_H_ */