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