1 //--------------------------------------------------------------------------
2 // Copyright (C) 2014-2021 Cisco and/or its affiliates. All rights reserved.
3 //
4 // This program is free software; you can redistribute it and/or modify it
5 // under the terms of the GNU General Public License Version 2 as published
6 // by the Free Software Foundation.  You may not use, modify or distribute
7 // this program under any other version of the GNU General Public License.
8 //
9 // This program is distributed in the hope that it will be useful, but
10 // WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License along
15 // with this program; if not, write to the Free Software Foundation, Inc.,
16 // 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 //--------------------------------------------------------------------------
18 // icmp6.h author Josh Rosenbaum <jrosenba@cisco.com>
19 
20 #ifndef PROTOCOLS_ICMP6_H
21 #define PROTOCOLS_ICMP6_H
22 
23 #include <cstdint>
24 
25 namespace snort
26 {
27 namespace icmp
28 {
29 constexpr uint16_t ICMP6_HEADER_MIN_LEN = 4;
30 constexpr uint16_t ICMP6_HEADER_NORMAL_LEN = 8;
31 
32 #define ICMPv6_NS_MIN_LEN 24
33 #define ICMPv6_NA_MIN_LEN 24
34 #define ICMPv6_RS_MIN_LEN 24
35 #define ICMPv6_RA_MIN_LEN 16
36 
37 #define ICMPV6_OPTION_SOURCE_LINKLAYER_ADDRESS 1
38 #define ICMPV6_OPTION_TARGET_LINKLAYER_ADDRESS 2
39 #define ICMPV6_OPTION_PREFIX_INFO              3
40 #define ICMPV6_OPTION_REDIRECT_HEADER          4
41 #define ICMPV6_OPTION_MTU                      5
42 
43 //enum class Icmp6Types : std::uint8_t
44 enum Icmp6Types : std::uint8_t
45 {
46     DESTINATION_UNREACHABLE = 1,
47     PACKET_TOO_BIG = 2,
48     TIME_EXCEEDED6 = 3,
49     PARAMETER_PROBLEM = 4,
50     ECHO_REQUEST = 128,
51     ECHO_REPLY = 129,
52     MULTICAST_LISTENER_QUERY = 130,
53     MULTICAST_LISTENER_REPORT = 131,
54     MULTICAST_LISTENER_DONE = 132,
55     ROUTER_SOLICITATION = 133,
56     ROUTER_ADVERTISEMENT = 134,
57     NEIGHBOR_SOLICITATION = 135,
58     NEIGHBOR_ADVERTISEMENT = 136,
59     REDIRECT6 = 137,
60     NODE_INFORMATION_QUERY = 139,
61     NODE_INFORMATION_RESPONSE = 140,
62     INVERSE_NEIGHBOR_DISCOVERY_SOLICITATION = 141,
63     INVERSE_NEIGHBOR_DISCOVERY_ADVERTISEMENT = 142,
64     VERSION_2_MULTICAST_LISTENER_REPORT = 143,
65     HOME_AGENT_ADDRESS_DISCOVERY_REQUEST = 144,
66     HOME_AGENT_ADDRESS_DISCOVERY_REPLY = 145,
67     MOBILE_PREFIX_SOLICITATION = 146,
68     MOBILE_PREFIX_ADVERTISEMENT = 147,
69     CERTIFICATION_PATH_SOLICITATION = 148,
70     CERTIFICATION_PATH_ADVERTISEMENT = 149,
71     MULTICAST_ROUTER_ADVERTISEMENT = 151,
72     MULTICAST_ROUTER_SOLICITATION = 152,
73     MULTICAST_ROUTER_TERMINATION = 153,
74     FMIPV6 = 154,
75     RPL_CONTROL = 155,
76     ILNPV6_LOCATOR_UPDATE = 156,
77     DUPLICATE_ADDRESS_REQUEST = 157,
78     DUPLICATE_ADDRESS_CONFIRMATION = 158,
79     MPL_CONTROL = 159
80 };
81 
82 enum class Icmp6Code : std::uint8_t
83 {
84     /* Type == 1 */
85     UNREACH_NET = 0x00,
86     UNREACH_FILTER_PROHIB = 0x01,
87     UNREACH_INVALID = 0x02,
88     UNREACH_HOST = 0x03,
89     UNREACH_PORT = 0x04,
90 
91     /* Type == ADVERTISEMENT */
92     ADVERTISEMENT = 0X00,
93 };
94 
95 struct Icmp6Hdr
96 {
97     Icmp6Types type;
98     Icmp6Code code;
99     uint16_t csum;
100 
101     union
102     {
103         uint32_t opt32;
104         uint16_t opt16[2];
105         uint8_t opt8[4];
106     };
107 };
108 
109 struct ICMP6TooBig
110 {
111     uint8_t type;
112     uint8_t code;
113     uint16_t csum;
114     uint32_t mtu;
115 };
116 
117 struct ICMP6RouterAdvertisement
118 {
119     uint8_t type;
120     uint8_t code;
121     uint16_t csum;
122     uint8_t num_addrs;
123     uint8_t addr_entry_size;
124     uint16_t lifetime;
125     uint32_t reachable_time;
126     uint32_t retrans_time;
127 };
128 
129 struct ICMP6RouterSolicitation
130 {
131     uint8_t type;
132     uint8_t code;
133     uint16_t csum;
134     uint32_t reserved;
135 };
136 
137 struct ICMP6NodeInfo
138 {
139     uint8_t type;
140     uint8_t code;
141     uint16_t csum;
142     uint16_t qtype;
143     uint16_t flags;
144     uint64_t nonce;
145 };
146 }  // namespace icmp
147 }  // namespace snort
148 
149 #endif
150 
151