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

source

pub const MIN_LEN: usize = 0usize

Minimum length required for extension header in bytes/octets. Which is zero as no extension headers are required.

source

pub const MAX_LEN: usize = 9_228usize

Maximum summed up length of all extension headers in bytes/octets.

source

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.

source

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.

source

pub fn read<T: Read + Seek + Sized>( reader: &mut T, start_ip_number: IpNumber ) -> Result<(Ipv6Extensions, IpNumber), HeaderReadError>

Available on crate feature 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.

source

pub 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.

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.

source

pub fn write<T: Write + Sized>( &self, writer: &mut T, first_header: IpNumber ) -> Result<(), HeaderWriteError>

Available on crate feature 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.

source

pub fn header_len(&self) -> usize

Length of the all present headers in bytes.

source

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.

source

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.

source

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.

source

pub fn is_empty(&self) -> bool

Returns true if no IPv6 extension header is present (all fields None).

Trait Implementations§

source§

impl Clone for Ipv6Extensions

source§

fn clone(&self) -> Ipv6Extensions

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Ipv6Extensions

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Ipv6Extensions

source§

fn default() -> Ipv6Extensions

Returns the “default value” for a type. Read more
source§

impl PartialEq for Ipv6Extensions

source§

fn eq(&self, other: &Ipv6Extensions) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for Ipv6Extensions

source§

impl StructuralPartialEq for Ipv6Extensions

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.