Struct etherparse::Ipv6Extensions
source · pub struct Ipv6Extensions {
pub hop_by_hop_options: Option<Ipv6RawExtHeader>,
pub destination_options: Option<Ipv6RawExtHeader>,
pub routing: Option<Ipv6RoutingExtensions>,
pub fragment: Option<Ipv6FragmentHeader>,
pub auth: Option<IpAuthHeader>,
}
Expand description
IPv6 extension headers present after the ip header.
Currently supported:
- Authentication Header
- Hop by Hop Options Header
- Destination Options Header (before and after routing headers)
- Routing Header
- Fragment
- Authentication Header
Currently not supported:
- Encapsulating Security Payload Header (ESP)
- Host Identity Protocol (HIP)
- IP Mobility
- Site Multihoming by IPv6 Intermediation (SHIM6)
Fields§
§hop_by_hop_options: Option<Ipv6RawExtHeader>
§destination_options: Option<Ipv6RawExtHeader>
§routing: Option<Ipv6RoutingExtensions>
§fragment: Option<Ipv6FragmentHeader>
§auth: Option<IpAuthHeader>
Implementations§
source§impl Ipv6Extensions
impl Ipv6Extensions
sourcepub const MIN_LEN: usize = 0usize
pub const MIN_LEN: usize = 0usize
Minimum length required for extension header in bytes/octets. Which is zero as no extension headers are required.
sourcepub const MAX_LEN: usize = 9_228usize
pub const MAX_LEN: usize = 9_228usize
Maximum summed up length of all extension headers in bytes/octets.
sourcepub fn from_slice(
start_ip_number: IpNumber,
slice: &[u8]
) -> Result<(Ipv6Extensions, IpNumber, &[u8]), HeaderSliceError>
pub fn from_slice( start_ip_number: IpNumber, slice: &[u8] ) -> Result<(Ipv6Extensions, IpNumber, &[u8]), HeaderSliceError>
Reads as many extension headers as possible from the slice.
Returns the found ipv6 extension headers, the next header ip number after the read headers and a slice containing the rest of the packet after the read headers.
Note that this function can only handle ipv6 extensions if each extension header does occur at most once, except for destination options headers which are allowed to exist once in front of a routing header and once after a routing header.
In case that more extension headers then can fit into a Ipv6Extensions
struct are
encountered, the parsing is stoped at the point where the data would no longer fit into
the struct. In such a scenario a struct with the data that could be parsed is returned
together with the next header ip number and slice containing the unparsed data.
It is in the responsibility of the caller to handle a scenario like this.
The reason that no error is generated, is that even though according to RFC 8200 packets “should” not contain more then one occurence of an extension header the RFC also specifies that “IPv6 nodes must accept and attempt to process extension headers in any order and occurring any number of times in the same packet”. So packets with multiple headers “should” not exist, but are still valid IPv6 packets. As such this function does not generate a parsing error, as it is not an invalid packet, but if packets like these are encountered the user of this function has to themself decide how to handle packets like these.
The only exception is if an hop by hop header is located somewhere else then directly at
the start. In this case an ReadError::Ipv6HopByHopHeaderNotAtStart
error is generated as
the hop by hop header is required to be located directly after the IPv6 header according
to RFC 8200.
sourcepub fn from_slice_lax(
start_ip_number: IpNumber,
slice: &[u8]
) -> (Ipv6Extensions, IpNumber, &[u8], Option<(HeaderSliceError, Layer)>)
pub fn from_slice_lax( start_ip_number: IpNumber, slice: &[u8] ) -> (Ipv6Extensions, IpNumber, &[u8], Option<(HeaderSliceError, Layer)>)
Reads as many extension headers as possible from the slice until a non IPv6 extension header or an error gets encountered.
This function differs from Ipv6Extensions::from_slice
in that it returns the successfully
parsed parts together with the error. While Ipv6Extensions::from_slice
only returns an
error.
Note that this function (same as Ipv6Extensions::from_slice
) will stop parsing as soon
as more headers then can be stored in Ipv6Extensions
are encountered. E.g. if there is
more then one “auth” header the function returns as soon as the second “auth” header is
encountered.
sourcepub fn read<T: Read + Seek + Sized>(
reader: &mut T,
start_ip_number: IpNumber
) -> Result<(Ipv6Extensions, IpNumber), HeaderReadError>
Available on crate feature std
only.
pub fn read<T: Read + Seek + Sized>( reader: &mut T, start_ip_number: IpNumber ) -> Result<(Ipv6Extensions, IpNumber), HeaderReadError>
std
only.Reads as many extension headers as possible from the reader and returns the found ipv6 extension headers and the next header ip number.
If no extension headers are present an unfilled struct and the original first_header
ip number is returned.
Note that this function can only handle ipv6 extensions if each extension header does occur at most once, except for destination options headers which are allowed to exist once in front of a routing header and once after a routing header.
In case that more extension headers then can fit into a Ipv6Extensions
struct are
encountered, the parsing is stoped at the point where the data would no longer fit into
the struct. In such a scenario a struct with the data that could be parsed is returned
together with the next header ip number that identfies which header could be read next.
It is in the responsibility of the caller to handle a scenario like this.
The reason that no error is generated, is that even though according to RFC 8200, packets “should” not contain more then one occurence of an extension header, the RFC also specifies that “IPv6 nodes must accept and attempt to process extension headers in any order and occurring any number of times in the same packet”. So packets with multiple headers “should” not exist, but are still valid IPv6 packets. As such this function does not generate a parsing error, as it is not an invalid packet, but if packets like these are encountered the user of this function has to themself decide how to handle packets like these.
The only exception is if an hop by hop header is located somewhere else then directly at
the start. In this case an ReadError::Ipv6HopByHopHeaderNotAtStart
error is generated as
the hop by hop header is required to be located directly after the IPv6 header according
to RFC 8200.
sourcepub fn read_limited<T: Read + Seek + Sized>(
reader: &mut LimitedReader<T>,
start_ip_number: IpNumber
) -> Result<(Ipv6Extensions, IpNumber), HeaderLimitedReadError>
Available on crate feature std
only.
pub fn read_limited<T: Read + Seek + Sized>( reader: &mut LimitedReader<T>, start_ip_number: IpNumber ) -> Result<(Ipv6Extensions, IpNumber), HeaderLimitedReadError>
std
only.Reads as many extension headers as possible from the limited reader and returns the found ipv6 extension headers and the next header ip number.
If no extension headers are present an unfilled struct and the original first_header
ip number is returned.
Note that this function can only handle ipv6 extensions if each extension header does occur at most once, except for destination options headers which are allowed to exist once in front of a routing header and once after a routing header.
In case that more extension headers then can fit into a Ipv6Extensions
struct are
encountered, the parsing is stoped at the point where the data would no longer fit into
the struct. In such a scenario a struct with the data that could be parsed is returned
together with the next header ip number that identfies which header could be read next.
It is in the responsibility of the caller to handle a scenario like this.
The reason that no error is generated, is that even though according to RFC 8200, packets “should” not contain more then one occurence of an extension header, the RFC also specifies that “IPv6 nodes must accept and attempt to process extension headers in any order and occurring any number of times in the same packet”. So packets with multiple headers “should” not exist, but are still valid IPv6 packets. As such this function does not generate a parsing error, as it is not an invalid packet, but if packets like these are encountered the user of this function has to themself decide how to handle packets like these.
The only exception is if an hop by hop header is located somewhere else then directly at
the start. In this case an ReadError::Ipv6HopByHopHeaderNotAtStart
error is generated as
the hop by hop header is required to be located directly after the IPv6 header according
to RFC 8200.
sourcepub fn write<T: Write + Sized>(
&self,
writer: &mut T,
first_header: IpNumber
) -> Result<(), HeaderWriteError>
Available on crate feature std
only.
pub fn write<T: Write + Sized>( &self, writer: &mut T, first_header: IpNumber ) -> Result<(), HeaderWriteError>
std
only.Writes the given headers to a writer based on the order defined in the next_header fields of the headers and the first header_id passed to this function.
It is required that all next header are correctly set in the headers
and no other ipv6 header extensions follow this header. If this is not
the case an err::ipv6_exts::HeaderWriteError::Content
error is
returned.
sourcepub fn header_len(&self) -> usize
pub fn header_len(&self) -> usize
Length of the all present headers in bytes.
sourcepub fn set_next_headers(&mut self, last_protocol_number: IpNumber) -> IpNumber
pub fn set_next_headers(&mut self, last_protocol_number: IpNumber) -> IpNumber
Sets all the next_header fields of the headers based on the adviced default order with the given protocol number as last “next header” value. The return value is the protocol number of the first existing extension header that should be entered in the ipv6 header as next_header.
If no extension headers are present the value of the argument is returned.
sourcepub fn next_header(
&self,
first_next_header: IpNumber
) -> Result<IpNumber, ExtsWalkError>
pub fn next_header( &self, first_next_header: IpNumber ) -> Result<IpNumber, ExtsWalkError>
Return next header based on the extension headers and the first ip protocol number.
sourcepub fn is_fragmenting_payload(&self) -> bool
pub fn is_fragmenting_payload(&self) -> bool
Returns true if a fragmentation header is present in the extensions that fragments the payload.
Note: A fragmentation header can still be present even if the return value is false in case the fragmentation headers don’t fragment the payload. This is the case if the offset of all fragmentation header is 0 and the more fragment bit is not set.
Trait Implementations§
source§impl Clone for Ipv6Extensions
impl Clone for Ipv6Extensions
source§fn clone(&self) -> Ipv6Extensions
fn clone(&self) -> Ipv6Extensions
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for Ipv6Extensions
impl Debug for Ipv6Extensions
source§impl Default for Ipv6Extensions
impl Default for Ipv6Extensions
source§fn default() -> Ipv6Extensions
fn default() -> Ipv6Extensions
source§impl PartialEq for Ipv6Extensions
impl PartialEq for Ipv6Extensions
source§fn eq(&self, other: &Ipv6Extensions) -> bool
fn eq(&self, other: &Ipv6Extensions) -> bool
self
and other
values to be equal, and is used
by ==
.