Update the Win32 Nmakefiles to reflect the move of the color code into
[obnox/wireshark/wip.git] / packet-ipv6.h
1 /* packet-ipv6.h
2  * Definitions for IPv6 packet disassembly 
3  *
4  * $Id: packet-ipv6.h,v 1.11 1999/12/06 20:20:35 guy Exp $
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@zing.org>
8  * Copyright 1998 Gerald Combs
9  *
10  * 
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  * 
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  * 
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24  */
25
26 #ifndef __PACKET_IPV6_H_DEFINED__
27 #define __PACKET_IPV6_H_DEFINED__
28
29 struct e_in6_addr {
30         union {
31                 guint32  u6_addr32[4];
32                 guint16  u6_addr16[8];
33                 guint8   u6_addr8[16];
34         } u6_addr;                      /* 128 bit IP6 address */
35 };
36
37 #ifdef s6_addr32
38 #undef s6_addr32
39 #endif
40
41 #ifdef s6_addr16
42 #undef s6_addr16
43 #endif
44
45 #ifdef s6_addr8
46 #undef s6_addr8
47 #endif
48
49 #ifdef s6_addr
50 #undef s6_addr
51 #endif
52
53 #define s6_addr32 u6_addr.u6_addr32
54 #define s6_addr16 u6_addr.u6_addr16
55 #define s6_addr8  u6_addr.u6_addr8
56 #define s6_addr   u6_addr.u6_addr8
57
58 #define INET6_ADDRSTRLEN        46
59
60 /*
61  * Definition for internet protocol version 6.
62  * RFC 1883
63  */
64 struct ip6_hdr {
65         union {
66                 struct ip6_hdrctl {
67                         guint32 ip6_un1_flow;   /* 20 bits of flow-ID */
68                         guint16 ip6_un1_plen;   /* payload length */
69                         guint8  ip6_un1_nxt;    /* next header */
70                         guint8  ip6_un1_hlim;   /* hop limit */
71                 } ip6_un1;
72                 guint8 ip6_un2_vfc;     /* 4 bits version, 4 bits class */
73         } ip6_ctlun;
74         struct e_in6_addr ip6_src;      /* source address */
75         struct e_in6_addr ip6_dst;      /* destination address */
76 };
77
78 #define ip6_vfc         ip6_ctlun.ip6_un2_vfc
79 #define ip6_flow        ip6_ctlun.ip6_un1.ip6_un1_flow
80 #define ip6_plen        ip6_ctlun.ip6_un1.ip6_un1_plen
81 #define ip6_nxt         ip6_ctlun.ip6_un1.ip6_un1_nxt
82 #define ip6_hlim        ip6_ctlun.ip6_un1.ip6_un1_hlim
83 #define ip6_hops        ip6_ctlun.ip6_un1.ip6_un1_hlim
84
85 /* Offsets of fields within an IPv6 header. */
86 #define IP6H_CTL        0
87 #define IP6H_CTL_FLOW   0
88 #define IP6H_CTL_PLEN   4
89 #define IP6H_CTL_NXT    6
90 #define IP6H_CTL_HLIM   7
91 #define IP6H_CTL_VFC    0
92 #define IP6H_SRC        8
93 #define IP6H_DST        24
94
95 #ifdef WORDS_BIGENDIAN
96 #define IPV6_FLOWINFO_MASK      0x0fffffff      /* flow info (28 bits) */
97 #define IPV6_FLOWLABEL_MASK     0x000fffff      /* flow label (20 bits) */
98 #else
99 #define IPV6_FLOWINFO_MASK      0xffffff0f      /* flow info (28 bits) */
100 #define IPV6_FLOWLABEL_MASK     0xffff0f00      /* flow label (20 bits) */
101 #endif
102
103 /*
104  * Extension Headers
105  */
106
107 struct  ip6_ext {
108         u_char  ip6e_nxt;
109         u_char  ip6e_len;
110 };
111
112 /* Hop-by-Hop options header */
113 /* XXX should we pad it to force alignment on an 8-byte boundary? */
114 struct ip6_hbh {
115         guint8 ip6h_nxt;        /* next header */
116         guint8 ip6h_len;        /* length in units of 8 octets */
117         /* followed by options */
118 };
119
120 /* Destination options header */
121 /* XXX should we pad it to force alignment on an 8-byte boundary? */
122 struct ip6_dest {
123         guint8 ip6d_nxt;        /* next header */
124         guint8 ip6d_len;        /* length in units of 8 octets */
125         /* followed by options */
126 };
127
128 /* Option types and related macros */
129 #define IP6OPT_PAD1             0x00    /* 00 0 00000 */
130 #define IP6OPT_PADN             0x01    /* 00 0 00001 */
131 #define IP6OPT_JUMBO            0xC2    /* 11 0 00010 = 194 */
132 #define IP6OPT_JUMBO_LEN        6
133 #define IP6OPT_RTALERT          0x05    /* 00 0 00101 */
134 #define IP6OPT_RTALERT_LEN      4
135 #define IP6OPT_RTALERT_MLD      0       /* Datagram contains MLD message */
136 #define IP6OPT_RTALERT_RSVP     1       /* Datagram contains RSVP message */
137 #define IP6OPT_MINLEN           2
138
139 #define IP6OPT_TYPE(o)          ((o) & 0xC0)
140 #define IP6OPT_TYPE_SKIP        0x00
141 #define IP6OPT_TYPE_DISCARD     0x40
142 #define IP6OPT_TYPE_FORCEICMP   0x80
143 #define IP6OPT_TYPE_ICMP        0xC0
144
145 #define IP6OPT_MUTABLE          0x20
146
147 /* Routing header */
148 struct ip6_rthdr {
149         guint8  ip6r_nxt;       /* next header */
150         guint8  ip6r_len;       /* length in units of 8 octets */
151         guint8  ip6r_type;      /* routing type */
152         guint8  ip6r_segleft;   /* segments left */
153         /* followed by routing type specific data */
154 };
155
156 /* Type 0 Routing header */
157 struct ip6_rthdr0 {
158         guint8  ip6r0_nxt;              /* next header */
159         guint8  ip6r0_len;              /* length in units of 8 octets */
160         guint8  ip6r0_type;             /* always zero */
161         guint8  ip6r0_segleft;  /* segments left */
162         guint8  ip6r0_reserved; /* reserved field */
163         guint8  ip6r0_slmap[3]; /* strict/loose bit map */
164         struct e_in6_addr  ip6r0_addr[1];       /* up to 23 addresses */
165 };
166
167 /* Fragment header */
168 struct ip6_frag {
169         guint8  ip6f_nxt;               /* next header */
170         guint8  ip6f_reserved;  /* reserved field */
171         guint16 ip6f_offlg;             /* offset, reserved, and flag */
172         guint32 ip6f_ident;             /* identification */
173 };
174
175 #if BYTE_ORDER == BIG_ENDIAN
176 #define IP6F_OFF_MASK           0xfff8  /* mask out offset from _offlg */
177 #define IP6F_RESERVED_MASK      0x0006  /* reserved bits in ip6f_offlg */
178 #define IP6F_MORE_FRAG          0x0001  /* more-fragments flag */
179 #else /* BYTE_ORDER == LITTLE_ENDIAN */
180 #define IP6F_OFF_MASK           0xf8ff  /* mask out offset from _offlg */
181 #define IP6F_RESERVED_MASK      0x0600  /* reserved bits in ip6f_offlg */
182 #define IP6F_MORE_FRAG          0x0100  /* more-fragments flag */
183 #endif /* BYTE_ORDER == LITTLE_ENDIAN */
184
185 /*
186  * Definition for ICMPv6.
187  * RFC 1885
188  */
189
190 #define ICMPV6_PLD_MAXLEN       1232    /* IPV6_MMTU - sizeof(struct ip6_hdr)
191                                            - sizeof(struct icmp6_hdr) */
192
193 struct icmp6_hdr {
194         guint8  icmp6_type;     /* type field */
195         guint8  icmp6_code;     /* code field */
196         guint16 icmp6_cksum;    /* checksum field */
197         union {
198                 guint32 icmp6_un_data32[1]; /* type-specific field */
199                 guint16 icmp6_un_data16[2]; /* type-specific field */
200                 guint8  icmp6_un_data8[4];  /* type-specific field */
201         } icmp6_dataun;
202 };
203
204 #define icmp6_data32    icmp6_dataun.icmp6_un_data32
205 #define icmp6_data16    icmp6_dataun.icmp6_un_data16
206 #define icmp6_data8     icmp6_dataun.icmp6_un_data8
207 #define icmp6_pptr      icmp6_data32[0]         /* parameter prob */
208 #define icmp6_mtu       icmp6_data32[0]         /* packet too big */
209 #define icmp6_id        icmp6_data16[0]         /* echo request/reply */
210 #define icmp6_seq       icmp6_data16[1]         /* echo request/reply */
211 #define icmp6_maxdelay  icmp6_data16[0]         /* mcast group membership */
212
213 #define ICMP6_DST_UNREACH               1       /* dest unreachable, codes: */
214 #define ICMP6_PACKET_TOO_BIG            2       /* packet too big */
215 #define ICMP6_TIME_EXCEEDED             3       /* time exceeded, code: */
216 #define ICMP6_PARAM_PROB                4       /* ip6 header bad */
217
218 #define ICMP6_ECHO_REQUEST              128     /* echo service */
219 #define ICMP6_ECHO_REPLY                129     /* echo reply */
220 #define ICMP6_MEMBERSHIP_QUERY          130     /* group membership query */
221 #define MLD6_LISTENER_QUERY             130     /* multicast listener query */
222 #define ICMP6_MEMBERSHIP_REPORT         131     /* group membership report */
223 #define MLD6_LISTENER_REPORT            131     /* multicast listener report */
224 #define ICMP6_MEMBERSHIP_REDUCTION      132     /* group membership termination */
225 #define MLD6_LISTENER_DONE              132     /* multicast listener done */
226
227 #define ND_ROUTER_SOLICIT               133     /* router solicitation */
228 #define ND_ROUTER_ADVERT                134     /* router advertisment */
229 #define ND_NEIGHBOR_SOLICIT             135     /* neighbor solicitation */
230 #define ND_NEIGHBOR_ADVERT              136     /* neighbor advertisment */
231 #define ND_REDIRECT                     137     /* redirect */
232
233 #define ICMP6_ROUTER_RENUMBERING        138     /* router renumbering */
234
235 /* xxx: actually not assigned yet */
236 #define ICMP6_WRUREQUEST                140     /* who are you request */
237 #define ICMP6_WRUREPLY                  141     /* who are you reply */
238 #define ICMP6_FQDN_QUERY                140     /* FQDN query */
239 #define ICMP6_FQDN_REPLY                141     /* FQDN reply */
240
241 #define ICMP6_MAXTYPE                   141
242
243 #define ICMP6_DST_UNREACH_NOROUTE       0       /* no route to destination */
244 #define ICMP6_DST_UNREACH_ADMIN         1       /* administratively prohibited */
245 #define ICMP6_DST_UNREACH_NOTNEIGHBOR   2       /* not a neighbor */
246 #define ICMP6_DST_UNREACH_ADDR          3       /* address unreachable */
247 #define ICMP6_DST_UNREACH_NOPORT        4       /* port unreachable */
248
249 #define ICMP6_TIME_EXCEED_TRANSIT       0       /* ttl==0 in transit */
250 #define ICMP6_TIME_EXCEED_REASSEMBLY    1       /* ttl==0 in reass */
251
252 #define ICMP6_PARAMPROB_HEADER          0       /* erroneous header field */
253 #define ICMP6_PARAMPROB_NEXTHEADER      1       /* unrecognized next header */
254 #define ICMP6_PARAMPROB_OPTION          2       /* unrecognized option */
255
256 #define ICMP6_INFOMSG_MASK              0x80    /* all informational messages */
257
258 #define ICMP6_ROUTER_RENUMBERING_COMMAND  0     /* rr command */
259 #define ICMP6_ROUTER_RENUMBERING_RESULT   1     /* rr result */
260 #define ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET   255     /* rr seq num reset */
261
262 /*
263  * Multicast Listener Discovery
264  */
265 struct mld6_hdr {
266         struct icmp6_hdr        mld6_hdr;
267         struct e_in6_addr               mld6_addr; /* multicast address */
268 };
269
270 #define mld6_type       mld6_hdr.icmp6_type
271 #define mld6_code       mld6_hdr.icmp6_code
272 #define mld6_cksum      mld6_hdr.icmp6_cksum
273 #define mld6_maxdelay   mld6_hdr.icmp6_data16[0]
274 #define mld6_reserved   mld6_hdr.icmp6_data16[1]
275
276 /*
277  * Neighbor Discovery
278  */
279
280 struct nd_router_solicit {      /* router solicitation */
281         struct icmp6_hdr        nd_rs_hdr;
282         /* could be followed by options */
283 };
284
285 #define nd_rs_type      nd_rs_hdr.icmp6_type
286 #define nd_rs_code      nd_rs_hdr.icmp6_code
287 #define nd_rs_cksum     nd_rs_hdr.icmp6_cksum
288 #define nd_rs_reserved  nd_rs_hdr.icmp6_data32[0]
289
290 struct nd_router_advert {       /* router advertisement */
291         struct icmp6_hdr        nd_ra_hdr;
292         guint32         nd_ra_reachable;        /* reachable time */
293         guint32         nd_ra_retransmit;       /* retransmit timer */
294         /* could be followed by options */
295 };
296
297 #define nd_ra_type              nd_ra_hdr.icmp6_type
298 #define nd_ra_code              nd_ra_hdr.icmp6_code
299 #define nd_ra_cksum             nd_ra_hdr.icmp6_cksum
300 #define nd_ra_curhoplimit       nd_ra_hdr.icmp6_data8[0]
301 #define nd_ra_flags_reserved    nd_ra_hdr.icmp6_data8[1]
302 #define ND_RA_FLAG_MANAGED      0x80
303 #define ND_RA_FLAG_OTHER        0x40
304 #define nd_ra_router_lifetime   nd_ra_hdr.icmp6_data16[1]
305
306 struct nd_neighbor_solicit {    /* neighbor solicitation */
307         struct icmp6_hdr        nd_ns_hdr;
308         struct e_in6_addr               nd_ns_target;   /*target address */
309         /* could be followed by options */
310 };
311
312 #define nd_ns_type              nd_ns_hdr.icmp6_type
313 #define nd_ns_code              nd_ns_hdr.icmp6_code
314 #define nd_ns_cksum             nd_ns_hdr.icmp6_cksum
315 #define nd_ns_reserved          nd_ns_hdr.icmp6_data32[0]
316
317 struct nd_neighbor_advert {     /* neighbor advertisement */
318         struct icmp6_hdr        nd_na_hdr;
319         struct e_in6_addr               nd_na_target;   /* target address */
320         /* could be followed by options */
321 };
322
323 #define nd_na_type              nd_na_hdr.icmp6_type
324 #define nd_na_code              nd_na_hdr.icmp6_code
325 #define nd_na_cksum             nd_na_hdr.icmp6_cksum
326 #define nd_na_flags_reserved    nd_na_hdr.icmp6_data32[0]
327 #if BYTE_ORDER == BIG_ENDIAN
328 #define ND_NA_FLAG_ROUTER               0x80000000
329 #define ND_NA_FLAG_SOLICITED            0x40000000
330 #define ND_NA_FLAG_OVERRIDE             0x20000000
331 #elif BYTE_ORDER == LITTLE_ENDIAN
332 #define ND_NA_FLAG_ROUTER               0x80
333 #define ND_NA_FLAG_SOLICITED            0x40
334 #define ND_NA_FLAG_OVERRIDE             0x20
335 #endif
336
337 struct nd_redirect {            /* redirect */
338         struct icmp6_hdr        nd_rd_hdr;
339         struct e_in6_addr               nd_rd_target;   /* target address */
340         struct e_in6_addr               nd_rd_dst;      /* destination address */
341         /* could be followed by options */
342 };
343
344 #define nd_rd_type              nd_rd_hdr.icmp6_type
345 #define nd_rd_code              nd_rd_hdr.icmp6_code
346 #define nd_rd_cksum             nd_rd_hdr.icmp6_cksum
347 #define nd_rd_reserved          nd_rd_hdr.icmp6_data32[0]
348
349 struct nd_opt_hdr {             /* Neighbor discovery option header */
350         guint8  nd_opt_type;
351         guint8  nd_opt_len;
352         /* followed by option specific data*/
353 };
354
355 #define ND_OPT_SOURCE_LINKADDR          1
356 #define ND_OPT_TARGET_LINKADDR          2
357 #define ND_OPT_PREFIX_INFORMATION       3
358 #define ND_OPT_REDIRECTED_HEADER        4
359 #define ND_OPT_MTU                      5
360
361 struct nd_opt_prefix_info {     /* prefix information */
362         guint8  nd_opt_pi_type;
363         guint8  nd_opt_pi_len;
364         guint8  nd_opt_pi_prefix_len;
365         guint8  nd_opt_pi_flags_reserved;
366         guint32 nd_opt_pi_valid_time;
367         guint32 nd_opt_pi_preferred_time;
368         guint32 nd_opt_pi_reserved2;
369         struct e_in6_addr       nd_opt_pi_prefix;
370 };
371
372 #define ND_OPT_PI_FLAG_ONLINK           0x80
373 #define ND_OPT_PI_FLAG_AUTO             0x40
374
375 struct nd_opt_rd_hdr {         /* redirected header */
376         guint8  nd_opt_rh_type;
377         guint8  nd_opt_rh_len;
378         guint16 nd_opt_rh_reserved1;
379         guint32 nd_opt_rh_reserved2;
380         /* followed by IP header and data */
381 };
382
383 struct nd_opt_mtu {             /* MTU option */
384         guint8  nd_opt_mtu_type;
385         guint8  nd_opt_mtu_len;
386         guint16 nd_opt_mtu_reserved;
387         guint32 nd_opt_mtu_mtu;
388 };
389
390 #if 0
391 /* disregard until used. We have to decide how to handle guint64 */ 
392 /*
393  * icmp6 namelookup
394  */
395
396 struct icmp6_namelookup {
397         struct icmp6_hdr        icmp6_nl_hdr;
398         guint64 icmp6_nl_nonce;
399         guint32 icmp6_nl_ttl;
400 #if 0
401         guint8  icmp6_nl_len;
402         guint8  icmp6_nl_name[3];
403 #endif
404         /* could be followed by options */
405 };
406 #endif
407
408 /*
409  * Router Renumbering. as router-renum-05.txt
410  */
411 #if BYTE_ORDER == BIG_ENDIAN /* net byte order */
412 struct icmp6_router_renum {     /* router renumbering header */
413         struct icmp6_hdr        rr_hdr;
414         guint8          rr_segnum;
415         guint32         rr_test : 1;
416         guint32         rr_reqresult : 1;
417         guint32         rr_forceapply : 1;
418         guint32         rr_specsite : 1;
419         guint32         rr_prevdone : 1;
420         guint32         rr_flags_reserved : 3;
421         guint16         rr_maxdelay;
422         guint32         rr_reserved;
423 };
424 #elif BYTE_ORDER == LITTLE_ENDIAN
425 struct icmp6_router_renum {     /* router renumbering header */
426         struct icmp6_hdr        rr_hdr;
427         guint8          rr_segnum;
428         guint32         rr_flags_reserved : 3;
429         guint32         rr_prevdone : 1;
430         guint32         rr_specsite : 1;
431         guint32         rr_forceapply : 1;
432         guint32         rr_reqresult : 1;
433         guint32         rr_test : 1;
434         guint16         rr_maxdelay;
435         guint32         rr_reserved;
436 };
437 #endif /* BYTE_ORDER */
438
439 #define rr_type                 rr_hdr.icmp6_type
440 #define rr_code                 rr_hdr.icmp6_code
441 #define rr_cksum                rr_hdr.icmp6_cksum
442 #define rr_seqnum               rr_hdr.icmp6_data32[0]
443
444 struct rr_pco_match {           /* match prefix part */
445         guint8  rpm_code;
446         guint8  rpm_len;
447         guint8  rpm_ordinal;
448         guint8  rpm_matchlen;
449         guint8  rpm_minlen;
450         guint8  rpm_maxlen;
451         guint16 rpm_reserved;
452         struct e_in6_addr       rpm_prefix;
453 };
454
455 #define RPM_PCO_ADD             1
456 #define RPM_PCO_CHANGE          2
457 #define RPM_PCO_SETGLOBAL       3
458 #define RPM_PCO_MAX             4
459
460 #if BYTE_ORDER == BIG_ENDIAN /* net byte order */
461 struct rr_pco_use {             /* use prefix part */
462         guint8  rpu_uselen;
463         guint8  rpu_keeplen;
464         guint32 rpu_mask_onlink : 1;
465         guint32 rpu_mask_autonomous : 1;
466         guint32 rpu_mask_reserved : 6;
467         guint32 rpu_onlink : 1;
468         guint32 rpu_autonomous : 1;
469         guint32 rpu_raflags_reserved : 6;
470         guint32 rpu_vltime;
471         guint32 rpu_pltime;
472         guint32 rpu_decr_vltime : 1;
473         guint32 rpu_decr_pltime : 1;
474         guint32 rpu_flags_reserved : 6;
475         guint32 rpu_reserved : 24;
476         struct e_in6_addr rpu_prefix;
477 };
478 #elif BYTE_ORDER == LITTLE_ENDIAN
479 struct rr_pco_use {             /* use prefix part */
480         guint8  rpu_uselen;
481         guint8  rpu_keeplen;
482         guint32 rpu_mask_reserved : 6;
483         guint32 rpu_mask_autonomous : 1;
484         guint32 rpu_mask_onlink : 1;
485         guint32 rpu_raflags_reserved : 6;
486         guint32 rpu_autonomous : 1;
487         guint32 rpu_onlink : 1;
488         guint32 rpu_vltime;
489         guint32 rpu_pltime;
490         guint32 rpu_flags_reserved : 6;
491         guint32 rpu_decr_pltime : 1;
492         guint32 rpu_decr_vltime : 1;
493         guint32 rpu_reserved : 24;
494         struct e_in6_addr rpu_prefix;
495 };
496 #endif /* BYTE_ORDER */
497
498 #if BYTE_ORDER == BIG_ENDIAN /* net byte order */
499 struct rr_result {              /* router renumbering result message */
500         guint8  rrr_reserved;
501         guint32 rrr_flags_reserved : 6;
502         guint32 rrr_outofbound : 1;
503         guint32 rrr_forbidden : 1;
504         guint8  rrr_ordinal;
505         guint8  rrr_matchedlen;
506         guint32 rrr_ifid;
507         struct e_in6_addr rrr_prefix;
508 };
509 #elif BYTE_ORDER == LITTLE_ENDIAN
510 struct rr_result {              /* router renumbering result message */
511         guint8  rrr_reserved;
512         guint32 rrr_forbidden : 1;
513         guint32 rrr_outofbound : 1;
514         guint32 rrr_flags_reserved : 6;
515         guint8  rrr_ordinal;
516         guint8  rrr_matchedlen;
517         guint32 rrr_ifid;
518         struct e_in6_addr rrr_prefix;
519 };
520 #endif /* BYTE_ORDER */
521
522 #endif /* __PACKET_IPV6_H_DEFINED__ */