binator_network/ip_protocol.rs
1//! Handles parsing of Internet Protocol fields (shared between ipv4 and ipv6)
2
3use binator::{
4 base::octet,
5 utils::Utils,
6 Contexting,
7 CoreAtom,
8 Parse,
9 Parsed,
10 Streaming,
11};
12
13use crate::struct_variants;
14
15struct_variants! {
16 IPProtocol, protocol, u8:
17 /// IPv6 Hop-by-Hop Option
18 HOPOPT => 0x00,
19 /// Internet Control Message Protocol
20 ICMP => 0x01,
21 /// Internet Group Management Protocol
22 IGMP => 0x02,
23 /// Gateway-to-Gateway Protocol
24 GGP => 0x03,
25 /// IP in IP
26 IP_IN_IP => 0x04,
27 /// Internet Stream Protocol
28 ST => 0x05,
29 /// Transmission Control Protocol
30 TCP => 0x06,
31 /// Core-based trees
32 CBT => 0x07,
33 /// Exterior Gateway Protocol
34 EGP => 0x08,
35 /// Interior Gateway Protocol
36 IGP => 0x09,
37 /// BBN RCC Monitoring
38 BBN_RCC_MON => 0x0A,
39 /// Network Voice Protocol
40 NVP_II => 0x0B,
41 /// Xerox PUP
42 PUP => 0x0C,
43 /// ARGUS
44 ARGUS => 0x0D,
45 /// EMCON
46 EMCON => 0x0E,
47 /// Cross Net Debugger
48 XNET => 0x0F,
49 /// Chaos
50 CHAOS => 0x10,
51 /// User Datagram Protocol
52 UDP => 0x11,
53 /// Multiplexing
54 MUX => 0x12,
55 /// DCN Measurement Subsystems
56 DCN_MEAS => 0x13,
57 /// Host Monitoring Protocol
58 HMP => 0x14,
59 /// Packet Radio Measurement
60 PRM => 0x15,
61 /// XEROX NS IDP
62 XNS_IDP => 0x16,
63 /// Trunk-1
64 TRUNK_1 => 0x17,
65 /// Trunk-2
66 TRUNK_2 => 0x18,
67 /// Leaf-1
68 LEAF_1 => 0x19,
69 /// Leaf-2
70 LEAF_2 => 0x1A,
71 /// Reliable Data Protocol
72 RDP => 0x1B,
73 /// Internet Reliable Transaction Protocol
74 IRTP => 0x1C,
75 /// ISO Transport Protocol Class 4
76 ISO_TP4 => 0x1D,
77 /// Bulk Data Transfer Protocol
78 NETBLT => 0x1E,
79 /// MFE Network Services Protocol
80 MFE_NSP => 0x1F,
81 /// MERIT Internodal Protocol
82 MERIT_INP => 0x20,
83 /// Datagram Congestion Control Protocol
84 DCCP => 0x21,
85 /// Third Party Connect Protocol
86 PC3 => 0x22,
87 /// Inter-Domain Policy Routing Protocol
88 IDPR => 0x23,
89 /// Xpress Transport Protocol
90 XTP => 0x24,
91 /// Datagram Delivery Protocol
92 DDP => 0x25,
93 /// IDPR Control Message Transport Protocol
94 IDPR_CMTP => 0x26,
95 /// TP++ Transport Protocol
96 TP => 0x27,
97 /// IL Transport Protocol
98 IL => 0x28,
99 /// IPv6 Encapsulation
100 IPV6 => 0x29,
101 /// Source Demand Routing Protocol
102 SDRP => 0x2A,
103 /// Routing Header for IPv6
104 IPV6_ROUTE => 0x2B,
105 /// Fragment Header for IPv6
106 IPV6_FRAG => 0x2C,
107 /// Inter-Domain Routing Protocol
108 IDRP => 0x2D,
109 /// Resource Reservation Protocol
110 RSVP => 0x2E,
111 /// Generic Routing Encapsulation
112 GRE => 0x2F,
113 /// Dynamic Source Routing Protocol
114 DSR => 0x30,
115 /// Burroughs Network Architecture
116 BNA => 0x31,
117 /// Encapsulating Security Payload
118 ESP => 0x32,
119 /// Authentication Header
120 AH => 0x33,
121 /// Integrated Net Layer Security Protocol
122 I_NLSP => 0x34,
123 /// SwIPe
124 SWIPE => 0x35,
125 /// NBMA Address Resolution Protocol
126 NARP => 0x36,
127 /// IP Mobility (Min Encap)
128 MOBILE => 0x37,
129 /// Transport Layer Security Protocol (using Kryptonet key management)
130 TLSP => 0x38,
131 /// Simple Key-Management for Internet Protocol
132 SKIP => 0x39,
133 /// ICMP for IPv6
134 ICMP_6 => 0x3A,
135 /// No Next Header for IPv6
136 NO_NXT_6 => 0x3B,
137 /// Destination Options for IPv6
138 OPTS_6 => 0x3C,
139 /// Any host internal protocol
140 AHIP => 0x3D,
141 /// CFTP
142 CFTP => 0x3E,
143 /// Any local network
144 ALN => 0x3F,
145 /// SATNET and Backroom EXPAK
146 SAT_EXPAK => 0x40,
147 /// Kryptolan
148 KRYPTOLAN => 0x41,
149 /// MIT Remote Virtual Disk Protocol
150 RVD => 0x42,
151 /// Internet Pluribus Packet Core
152 IPPC => 0x43,
153 /// Any distributed file system
154 ADFS => 0x44,
155 /// SATNET Monitoring
156 SAT_MON => 0x45,
157 /// VISA Protocol
158 VISA => 0x46,
159 /// Internet Packet Core Utility
160 IPCU => 0x47,
161 /// Computer Protocol Network Executive
162 CPNX => 0x48,
163 /// Computer Protocol Heart Beat
164 CPHB => 0x49,
165 /// Wang Span Network
166 WSN => 0x4A,
167 /// Packet Video Protocol
168 PVP => 0x4B,
169 /// Backroom SATNET Monitoring
170 BR_SAT_MON => 0x4C,
171 /// SUN ND PROTOCOL-Temporary
172 SUN_ND => 0x4D,
173 /// WIDEBAND Monitoring
174 WB_MON => 0x4E,
175 /// WIDEBAND EXPAK
176 WB_EXPAK => 0x4F,
177 /// International Organization for Standardization Internet Protocol
178 ISO_IP => 0x50,
179 /// Versatile Message Transaction Protocol
180 VMTP => 0x51,
181 /// Secure Versatile Message Transaction Protocol
182 SECURE_VMTP => 0x52,
183 /// VINES
184 VINES => 0x53,
185 /// TTP or Internet Protocol Traffic Manager
186 TTP_OR_IPTM => 0x54,
187 /// NSFNET-IGP
188 NSFNET_IGP => 0x55,
189 /// Dissimilar Gateway Protocol
190 DGP => 0x56,
191 /// TCF
192 TCF => 0x57,
193 /// EIGRP
194 EIGRP => 0x58,
195 /// Open Shortest Path First
196 OSPF => 0x59,
197 /// Sprite RPC Protocol
198 SPRITE_RPC => 0x5A,
199 /// Locus Address Resolution Protocol
200 LARP => 0x5B,
201 /// Multicast Transport Protocol
202 MTP => 0x5C,
203 /// AX.25
204 AX25 => 0x5D,
205 /// KA9Q NOS compatible IP over IP tunneling
206 OS => 0x5E,
207 /// Mobile Internetworking Control Protocol
208 MICP => 0x5F,
209 /// Semaphore Communications Sec. Pro
210 SCC_SP => 0x60,
211 /// Ethernet-within-IP Encapsulation
212 ETHERIP => 0x61,
213 /// Encapsulation Header
214 ENCAP => 0x62,
215 /// Any private encryption scheme
216 APES => 0x63,
217 /// GMTP
218 GMTP => 0x64,
219 /// Ipsilon Flow Management Protocol
220 IFMP => 0x65,
221 /// PNNI over IP
222 PNNI => 0x66,
223 /// Protocol Independent Multicast
224 PIM => 0x67,
225 /// IBM's ARIS (Aggregate Route IP Switching) Protocol
226 ARIS => 0x68,
227 /// SCPS (Space Communications Protocol Standards)
228 SCPS => 0x69,
229 /// QNX
230 QNX => 0x6A,
231 /// Active Networks
232 AN => 0x6B,
233 /// IP Payload Compression Protocol
234 IP_COMP => 0x6C,
235 /// Sitara Networks Protocol
236 SNP => 0x6D,
237 /// Compaq Peer Protocol
238 COMPAQ_PEER => 0x6E,
239 /// IPX in IP
240 IPX_IN_IP => 0x6F,
241 /// Virtual Router Redundancy Protocol, Common Address Redundancy Protocol (not IANA assigned)
242 VRRP => 0x70,
243 /// PGM Reliable Transport Protocol
244 PGM => 0x71,
245 /// Any 0-hop protocol
246 AHP => 0x72,
247 /// Layer Two Tunneling Protocol Version 3
248 L2TP => 0x73,
249 /// D-II Data Exchange (DDX)
250 DDX => 0x74,
251 /// Interactive Agent Transfer Protocol
252 IATP => 0x75,
253 /// Schedule Transfer Protocol
254 STP => 0x76,
255 /// SpectraLink Radio Protocol
256 SRP => 0x77,
257 /// Universal Transport Interface Protocol
258 UTI => 0x78,
259 /// Simple Message Protocol
260 SMP => 0x79,
261 /// Simple Multicast Protocol
262 SM => 0x7A,
263 /// Performance Transparency Protocol
264 PTP => 0x7B,
265 /// IS-IS over IPv4 Intermediate System to Intermediate System (IS-IS) Protocol over IPv4
266 IS_IS => 0x7C,
267 /// Flexible Intra-AS Routing Environment
268 FIRE => 0x7D,
269 /// Combat Radio Transport Protocol
270 CRTP => 0x7E,
271 /// Combat Radio User Datagram
272 CRUDP => 0x7F,
273 /// Service-Specific Connection-Oriented Protocol in a Multilink and Connectionless Environment
274 SSCOPMCE => 0x80,
275 /// IPLT
276 IPLT => 0x81,
277 /// Secure Packet Shield
278 SPS => 0x82,
279 /// Private IP Encapsulation within IP
280 PIPE => 0x83,
281 /// Stream Control Transmission Protocol
282 SCTP => 0x84,
283 /// Fibre Channel
284 FC => 0x85,
285 /// Reservation Protocol (RSVP) End-to-End Ignore
286 RSVP_IGNORE => 0x86,
287 /// Mobility Extension Header for IPv6
288 MOBILITY_6 => 0x87,
289 /// Lightweight User Datagram Protocol
290 UDP_LITE => 0x88,
291 /// Multiprotocol Label Switching Encapsulated in IP
292 MPLS_IN_IP => 0x89,
293 /// MANET Protocols
294 MANET => 0x8A,
295 /// Host Identity Protocol
296 HIP => 0x8B,
297 /// Site Multihoming by IPv6 Intermediation
298 SHIM_6 => 0x8C,
299 /// Wrapped Encapsulating Security Payload
300 WESP => 0x8D,
301 /// Robust Header Compression
302 ROHC => 0x8E,
303}
304
305pub(crate) fn ip_protocol<Stream, Context>(stream: Stream) -> Parsed<IPProtocol, Stream, Context>
306where
307 Stream: Streaming,
308 Context: Contexting<CoreAtom<Stream>>,
309 Stream::Item: Into<u8>,
310{
311 octet.map(IPProtocol::new).parse(stream)
312}
313
314#[cfg(test)]
315mod tests {
316 use binator::{
317 context::Ignore,
318 Parsed,
319 };
320
321 use super::IPProtocol;
322
323 #[test]
324 fn ip_protocol() {
325 let tests = [
326 ([1], IPProtocol::ICMP),
327 ([6], IPProtocol::TCP),
328 ([17], IPProtocol::UDP),
329 ];
330
331 for (stream, expected) in tests {
332 assert_eq!(
333 super::ip_protocol::<_, Ignore>(&stream[..]),
334 Parsed::Success {
335 stream: &[][..],
336 token: expected
337 }
338 );
339 }
340 }
341}