Enum etherparse::Icmpv6Type
source · [−]pub enum Icmpv6Type {
Unknown {
type_u8: u8,
code_u8: u8,
bytes5to8: [u8; 4],
},
DestinationUnreachable(DestUnreachableCode),
PacketTooBig {
mtu: u32,
},
TimeExceeded(TimeExceededCode),
ParameterProblem(ParameterProblemHeader),
EchoRequest(IcmpEchoHeader),
EchoReply(IcmpEchoHeader),
}Expand description
Different kinds of ICMPv6 messages.
The data stored in this enum corresponds to the statically sized data
at the start of an ICMPv6 packet without the checksum. If you also need
the checksum you can package and Icmpv6Type value in an Icmpv6Header
struct.
Decoding Example (complete packet):
use etherparse::PacketHeaders;
let headers = PacketHeaders::from_ethernet_slice(&packet).unwrap();
use etherparse::TransportHeader::*;
match headers.transport {
Some(Icmpv6(icmp)) => {
use etherparse::Icmpv6Type::*;
match icmp.icmp_type {
// Unknown is used when further decoding is currently not supported for the icmp type & code.
// You can still further decode the packet on your own by using the raw data in this enum
// together with `headers.payload` (contains the packet data after the 8th byte)
Unknown{ type_u8, code_u8, bytes5to8 } => println!("Unknown{{ type_u8: {}, code_u8: {}, bytes5to8: {:?} }}", type_u8, code_u8, bytes5to8),
DestinationUnreachable(header) => println!("{:?}", header),
PacketTooBig { mtu } => println!("TimeExceeded{{ mtu: {} }}", mtu),
TimeExceeded(code) => println!("{:?}", code),
ParameterProblem(header) => println!("{:?}", header),
EchoRequest(header) => println!("{:?}", header),
EchoReply(header) => println!("{:?}", header),
}
},
_ => {},
}Encoding Example (only ICMPv6 part)
To get the on wire bytes of an Icmpv6Type it needs to get packaged
into a Icmpv6Header so the checksum gets calculated.
use etherparse::{Icmpv6Type, icmpv6::DestUnreachableCode};
let t = Icmpv6Type::DestinationUnreachable(
DestUnreachableCode::Address
);
// to calculate the checksum the ip header and the payload
// (in case of dest unreachable the invoking packet) are needed
let header = t.to_header(ip_header.source, ip_header.destination, &invoking_packet).unwrap();
// an ICMPv6 packet is composed of the header and payload
let mut packet = Vec::with_capacity(header.header_len() + invoking_packet.len());
packet.extend_from_slice(&header.to_bytes());
packet.extend_from_slice(&invoking_packet);Variants
Unknown
Fields
type_u8: u8ICMPv6 type (present in the first byte of the ICMPv6 packet).
code_u8: u8ICMPv6 code (present in the 2nd byte of the ICMPv6 packet).
In case of an unknown icmp type is received the header elements of the first 8 bytes/octets are stored raw in this enum value.
What is part of the header for Icmpv6Type::Unknown?
For unknown ICMPv6 type & code combination the first 8 bytes are stored
in the Icmpv6Header and the rest is stored in the payload
(Icmpv6Slice::payload or PacketHeaders::payload).
0 1 2 3 4
+---------------------------------------------------------------+ -
| type_u8 | code_u8 | checksum (in Icmpv6Header) | |
+---------------------------------------------------------------+ | part of header & type
| bytes5to8 | ↓
+---------------------------------------------------------------+ -
| | |
... ... ... | part of payload
| | ↓
+---------------------------------------------------------------+ -DestinationUnreachable(DestUnreachableCode)
Message sent to inform the client that the destination is unreachable for some reason.
What is part of the header for Icmpv6Type::DestinationUnreachable?
For the Icmpv6Type::DestinationUnreachable type the first 8 bytes/octets of the ICMPv6
packet are part of the header. The unused part is not stored and droped.
The offending packet is stored in the payload part of the packet
(Icmpv6Slice::payload & PacketHeaders::payload) and is not part of
the Icmpv6Header.
0 1 2 3 4
+---------------------------------------------------------------+ -
| 1 | [value as u8] | checksum (in Icmpv6Header) | |
+---------------------------------------------------------------+ | part of header & type
| <unused> | ↓
+---------------------------------------------------------------+ -
| | |
| <As much of invoking packet as possible without | | part of payload
... the ICMPv6 packet exceeding the minimum IPv6 MTU> ... |
| | ↓
+---------------------------------------------------------------+ -RFC 4443 Description
A Destination Unreachable message SHOULD be generated by a router, or by the IPv6 layer in the originating node, in response to a packet that cannot be delivered to its destination address for reasons other than congestion. (An ICMPv6 message MUST NOT be generated if a packet is dropped due to congestion.)
PacketTooBig
Fields
mtu: u32The Maximum Transmission Unit of the next-hop link.
Sent if a packet to too big to be forwarded.
What is part of the header for Icmpv6Type::PacketTooBig?
For the Icmpv6Type::PacketTooBig type the first 8 bytes/octets of the ICMPv6
packet are part of the header. The offending packet is stored in the payload part of the packet
(Icmpv6Slice::payload & PacketHeaders::payload) and is not part of
the Icmpv6Header.
0 1 2 3 4
+---------------------------------------------------------------+ -
| 2 | 0 | checksum (in Icmpv6Header) | |
+---------------------------------------------------------------+ | part of header & type
| mtu | ↓
+---------------------------------------------------------------+ -
| | |
| <As much of invoking packet as possible without | | part of payload
... the ICMPv6 packet exceeding the minimum IPv6 MTU> ... |
| | ↓
+---------------------------------------------------------------+ -RFC 4443 Description
A Packet Too Big MUST be sent by a router in response to a packet that it cannot forward because the packet is larger than the MTU of the outgoing link. The information in this message is used as part of the Path MTU Discovery process.
TimeExceeded(TimeExceededCode)
Generated when a datagram had to be discarded due to the hop limit field reaching zero.
What is part of the header for Icmpv6Type::TimeExceeded?
For the Icmpv6Type::TimeExceeded type the first 8 bytes/octets of the ICMPv6
packet are part of the header. The unused part is not stored and droped.
The offending packet is stored in the payload part of the packet
(Icmpv6Slice::payload & PacketHeaders::payload) and is not part of
the Icmpv6Header.
0 1 2 3 4
+---------------------------------------------------------------+ -
| 3 | [value as u8] | checksum (in Icmpv6Header) | |
+---------------------------------------------------------------+ | part of header & type
| <unused> | ↓
+---------------------------------------------------------------+ -
| | |
| <As much of invoking packet as possible without | | part of payload
... the ICMPv6 packet exceeding the minimum IPv6 MTU> ... |
| | ↓
+---------------------------------------------------------------+ -RFC 4443 Description
If a router receives a packet with a Hop Limit of zero, or if a router decrements a packet’s Hop Limit to zero, it MUST discard the packet and originate an ICMPv6 Time Exceeded message with Code 0 to the source of the packet. This indicates either a routing loop or too small an initial Hop Limit value.
An ICMPv6 Time Exceeded message with Code 1 is used to report fragment reassembly timeout, as specified in [IPv6, Section 4.5].
ParameterProblem(ParameterProblemHeader)
Sent if there is a problem with a parameter in a received packet.
What is part of the header for Icmpv6Type::ParameterProblem?
For the Icmpv6Type::ParameterProblem type the first 8 bytes/octets of the ICMPv6
packet are part of the header. The unused part is not stored and droped.
The offending packet is stored in the payload part of the packet
(Icmpv6Slice::payload & PacketHeaders::payload) and is not part of
the Icmpv6Header.
0 1 2 3 4
+---------------------------------------------------------------+ -
| 4 | [value].code | checksum (in Icmpv6Header) | |
+---------------------------------------------------------------+ | part of header & type
| [value].pointer | ↓
+---------------------------------------------------------------+ -
| | |
| <As much of invoking packet as possible without | | part of payload
... the ICMPv6 packet exceeding the minimum IPv6 MTU> ... |
| | ↓
+---------------------------------------------------------------+ -RFC 4443 Description
If an IPv6 node processing a packet finds a problem with a field in the IPv6 header or extension headers such that it cannot complete processing the packet, it MUST discard the packet and SHOULD originate an ICMPv6 Parameter Problem message to the packet’s source, indicating the type and location of the problem.
EchoRequest(IcmpEchoHeader)
Requesting an EchoReply from the receiver.
What is part of the header for Icmpv6Type::EchoRequest?
For the Icmpv6Type::EchoRequest type the first 8 bytes/octets of the
ICMPv6 packet are part of the header. This includes the id and seq
fields. The data part of the ICMP echo request packet is part of the payload
(Icmpv6Slice::payload & PacketHeaders::payload) and not part of the
Icmpv6Header.
0 1 2 3 4
+---------------------------------------------------------------+ -
| 128 | 0 | checksum (in Icmpv6Header) | |
+---------------------------------------------------------------+ | part of header & type
| [value].id | [value].seq | ↓
+---------------------------------------------------------------+ -
| | |
... <data> ... | part of payload
| | ↓
+---------------------------------------------------------------+ -RFC 4443 Description
Every node MUST implement an ICMPv6 Echo responder function that receives Echo Requests and originates corresponding Echo Replies. A node SHOULD also implement an application-layer interface for originating Echo Requests and receiving Echo Replies, for diagnostic purposes.
EchoReply(IcmpEchoHeader)
Response to an EchoRequest message.
What is part of the header for Icmpv6Type::EchoReply?
For the Icmpv6Type::EchoReply type the first 8 bytes/octets of the
ICMPv6 packet are part of the header. This includes the id and seq
fields. The data part of the ICMP echo request packet is part of the payload
(Icmpv6Slice::payload & PacketHeaders::payload) and not part of the
Icmpv6Header.
0 1 2 3 4
+---------------------------------------------------------------+ -
| 129 | 0 | checksum (in Icmpv6Header) | |
+---------------------------------------------------------------+ | part of header & type
| [value].id | [value].seq | ↓
+---------------------------------------------------------------+ -
| | |
... <data> ... | part of payload
| | ↓
+---------------------------------------------------------------+ -RFC 4443 Description
Every node MUST implement an ICMPv6 Echo responder function that receives Echo Requests and originates corresponding Echo Replies. A node SHOULD also implement an application-layer interface for originating Echo Requests and receiving Echo Replies, for diagnostic purposes.
The source address of an Echo Reply sent in response to a unicast Echo Request message MUST be the same as the destination address of that Echo Request message.
An Echo Reply SHOULD be sent in response to an Echo Request message sent to an IPv6 multicast or anycast address. In this case, the source address of the reply MUST be a unicast address belonging to the interface on which the Echo Request message was received.
The data received in the ICMPv6 Echo Request message MUST be returned entirely and unmodified in the ICMPv6 Echo Reply message.
Implementations
sourceimpl Icmpv6Type
impl Icmpv6Type
sourcepub fn type_u8(&self) -> u8
pub fn type_u8(&self) -> u8
Returns the type value (first byte of the ICMPv6 header) of this type.
sourcepub fn code_u8(&self) -> u8
pub fn code_u8(&self) -> u8
Returns the code value (second byte of the ICMPv6 header) of this type.
sourcepub fn calc_checksum(
&self,
source_ip: [u8; 16],
destination_ip: [u8; 16],
payload: &[u8]
) -> Result<u16, ValueError>
pub fn calc_checksum(
&self,
source_ip: [u8; 16],
destination_ip: [u8; 16],
payload: &[u8]
) -> Result<u16, ValueError>
Calculates the checksum of the ICMPv6 header.
Warning: Don't use this method to verfy if a checksum of a received packet is correct. This method assumes that all unused bytes are filled with zeros. If this is not the case the computed checksum value will will be incorrect for a received packet.
If you want to verify that a received packet has a correct checksum use
Icmpv6Slice::is_checksum_valid instead.
sourcepub fn to_header(
self,
source_ip: [u8; 16],
destination_ip: [u8; 16],
payload: &[u8]
) -> Result<Icmpv6Header, ValueError>
pub fn to_header(
self,
source_ip: [u8; 16],
destination_ip: [u8; 16],
payload: &[u8]
) -> Result<Icmpv6Header, ValueError>
Creates a header with the correct checksum.
sourcepub fn header_len(&self) -> usize
pub fn header_len(&self) -> usize
Serialized length of the header in bytes/octets.
Note that this size is not the size of the entire ICMPv6 packet but only the header.
sourcepub fn fixed_payload_size(&self) -> Option<usize>
pub fn fixed_payload_size(&self) -> Option<usize>
If the ICMP type has a fixed size returns the number of bytes that should be present after the header of this type.
Trait Implementations
sourceimpl Clone for Icmpv6Type
impl Clone for Icmpv6Type
sourcefn clone(&self) -> Icmpv6Type
fn clone(&self) -> Icmpv6Type
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source. Read more
sourceimpl Debug for Icmpv6Type
impl Debug for Icmpv6Type
sourceimpl PartialEq<Icmpv6Type> for Icmpv6Type
impl PartialEq<Icmpv6Type> for Icmpv6Type
sourcefn eq(&self, other: &Icmpv6Type) -> bool
fn eq(&self, other: &Icmpv6Type) -> bool
This method tests for self and other values to be equal, and is used
by ==. Read more
sourcefn ne(&self, other: &Icmpv6Type) -> bool
fn ne(&self, other: &Icmpv6Type) -> bool
This method tests for !=.
impl Copy for Icmpv6Type
impl Eq for Icmpv6Type
impl StructuralEq for Icmpv6Type
impl StructuralPartialEq for Icmpv6Type
Auto Trait Implementations
impl RefUnwindSafe for Icmpv6Type
impl Send for Icmpv6Type
impl Sync for Icmpv6Type
impl Unpin for Icmpv6Type
impl UnwindSafe for Icmpv6Type
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more