1 /* inet_ipv6.h
2  *
3  * Wireshark - Network traffic analyzer
4  * By Gerald Combs <gerald@wireshark.org>
5  * Copyright 1998 Gerald Combs
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  */
9 
10 #ifndef __INET_IPV6_H__
11 #define __INET_IPV6_H__
12 
13 #include <glib.h>
14 
15 #define IPv6_ADDR_SIZE  16
16 
17 #define IPv6_HDR_SIZE           40
18 #define IPv6_FRAGMENT_HDR_SIZE  8
19 
20 typedef struct e_in6_addr {
21     guint8 bytes[16];           /* 128 bit IPv6 address */
22 } ws_in6_addr;
23 
24 /*
25  * Definition for internet protocol version 6.
26  * RFC 2460
27  */
28 struct ws_ip6_hdr {
29     guint32     ip6h_vc_flow;           /* version, class, flow */
30     guint16     ip6h_plen;              /* payload length */
31     guint8      ip6h_nxt;               /* next header */
32     guint8      ip6h_hlim;              /* hop limit */
33     ws_in6_addr ip6h_src;               /* source address */
34     ws_in6_addr ip6h_dst;               /* destination address */
35 };
36 
37 /*
38  * Extension Headers
39  */
40 
41 struct ip6_ext {
42     guchar ip6e_nxt;
43     guchar ip6e_len;
44 };
45 
46 /* Routing header */
47 struct ip6_rthdr {
48     guint8 ip6r_nxt;        /* next header */
49     guint8 ip6r_len;        /* length in units of 8 octets */
50     guint8 ip6r_type;       /* routing type */
51     guint8 ip6r_segleft;    /* segments left */
52     /* followed by routing type specific data */
53 };
54 
55 /* Type 0 Routing header */
56 struct ip6_rthdr0 {
57     guint8 ip6r0_nxt;       /* next header */
58     guint8 ip6r0_len;       /* length in units of 8 octets */
59     guint8 ip6r0_type;      /* always zero */
60     guint8 ip6r0_segleft;   /* segments left */
61     guint8 ip6r0_reserved;  /* reserved field */
62     guint8 ip6r0_slmap[3];  /* strict/loose bit map */
63     /* followed by up to 127 addresses */
64     ws_in6_addr ip6r0_addr[1];
65 };
66 
67 /* Fragment header */
68 struct ip6_frag {
69     guint8  ip6f_nxt;       /* next header */
70     guint8  ip6f_reserved;  /* reserved field */
71     guint16 ip6f_offlg;     /* offset, reserved, and flag */
72     guint32 ip6f_ident;     /* identification */
73 };
74 
75 #define IP6F_OFF_MASK           0xfff8 /* mask out offset from _offlg */
76 #define IP6F_RESERVED_MASK      0x0006 /* reserved bits in ip6f_offlg */
77 #define IP6F_MORE_FRAG          0x0001 /* more-fragments flag */
78 
79 
80 /**
81  * Unicast Scope
82  * Note that we must check topmost 10 bits only, not 16 bits (see RFC2373).
83  */
in6_addr_is_linklocal(const ws_in6_addr * a)84 static inline gboolean in6_addr_is_linklocal(const ws_in6_addr *a)
85 {
86     return (a->bytes[0] == 0xfe) && ((a->bytes[1] & 0xc0) == 0x80);
87 }
88 
in6_addr_is_sitelocal(const ws_in6_addr * a)89 static inline gboolean in6_addr_is_sitelocal(const ws_in6_addr *a)
90 {
91     return (a->bytes[0] == 0xfe) && ((a->bytes[1] & 0xc0) == 0xc0);
92 }
93 
94 /**
95  * Multicast
96  */
in6_addr_is_multicast(const ws_in6_addr * a)97 static inline gboolean in6_addr_is_multicast(const ws_in6_addr *a)
98 {
99     return a->bytes[0] == 0xff;
100 }
101 
102 #endif
103