pub enum LaxIpSlice<'a> {
Ipv4(LaxIpv4Slice<'a>),
Ipv6(LaxIpv6Slice<'a>),
}
Expand description
Slice containing laxly separated IPv4 or IPv6 headers & payload.
Compared to the normal IpSlice
this slice allows the
payload to be incomplete/cut off and errors to be present in
the IpPayload.
The main use cases for “laxly” parsed slices are are:
- Parsing packets that have been cut off. This is, for example, useful to parse packets returned via ICMP as these usually only contain the start.
- Parsing packets where the
total_len
(for IPv4) orpayload_len
(for IPv6) have not yet been set. This can be useful when parsing packets which have been recorded in a layer before the length field was set (e.g. before the operating system set the length fields).
Variants§
Ipv4(LaxIpv4Slice<'a>)
The ipv4 header & the decoded extension headers.
Ipv6(LaxIpv6Slice<'a>)
The ipv6 header & the decoded extension headers.
Implementations§
Source§impl<'a> LaxIpSlice<'a>
impl<'a> LaxIpSlice<'a>
Sourcepub fn ipv4(&self) -> Option<&LaxIpv4Slice<'_>>
pub fn ipv4(&self) -> Option<&LaxIpv4Slice<'_>>
Returns a reference to the Ipv4Slice
if self
is a IpSlice::Ipv4
.
Sourcepub fn ipv6(&self) -> Option<&LaxIpv6Slice<'_>>
pub fn ipv6(&self) -> Option<&LaxIpv6Slice<'_>>
Returns a reference to the Ipv6Slice
if self
is a IpSlice::Ipv6
.
Sourcepub fn is_fragmenting_payload(&self) -> bool
pub fn is_fragmenting_payload(&self) -> bool
Returns true if the payload is fragmented.
Sourcepub fn source_addr(&self) -> IpAddr
pub fn source_addr(&self) -> IpAddr
Return the source address as an core::net::Ipvddr.
Sourcepub fn destination_addr(&self) -> IpAddr
pub fn destination_addr(&self) -> IpAddr
Return the destination address as an core::net::IpAddr.
Sourcepub fn payload(&self) -> &LaxIpPayloadSlice<'a>
pub fn payload(&self) -> &LaxIpPayloadSlice<'a>
Returns a slice containing the data after the IP header and IP extensions headers.
Sourcepub fn payload_ip_number(&self) -> IpNumber
pub fn payload_ip_number(&self) -> IpNumber
Returns the ip number the type of payload of the IP packet.
This function returns the ip number stored in the last IP header or extension header.
Sourcepub fn from_slice(
slice: &[u8],
) -> Result<(LaxIpSlice<'_>, Option<(HeaderSliceError, Layer)>), LaxHeaderSliceError>
pub fn from_slice( slice: &[u8], ) -> Result<(LaxIpSlice<'_>, Option<(HeaderSliceError, Layer)>), LaxHeaderSliceError>
Separates IP headers (include extension headers) & the IP payload from the given slice as far as possible without encountering an error and with less strict length checks. This function is useful for cut off packet or for packets with unset length fields.
If you want to only receive correct IpPayloads use IpSlice::from_slice
instead.
The main use cases for this functions are:
- Parsing packets that have been cut off. This is, for example, useful to parse packets returned via ICMP as these usually only contain the start.
- Parsing packets where the
total_len
(for IPv4) orpayload_length
(for IPv6) have not yet been set. This can be useful when parsing packets which have been recorded in a layer before the length field was set (e.g. before the operating system set the length fields).
§Differences to IpSlice::from_slice
:
- Errors in the expansion headers will only stop the parsing and return an
Ok
with the successfully parsed parts and the error as optional. Only if an unrecoverable error is encountered in the IP header itself anErr
is returned. In the normalfrom_slice
function anErr
is returned if an error is encountered in an extension header. from_slice_lax
ignores inconsistenttotal_len
(in IPv4 headers) and inconsistentpayload_length
(in IPv6 headers) values. When these length values in the IP header are inconsistent the length of the given slice is used as a substitute.
You can check if the slice length was used as a substitute by checking
if result.payload().len_source
is set to LenSource::Slice
.
If a substitution was not needed len_source
is set to
LenSource::Ipv4HeaderTotalLen
or LenSource::Ipv6HeaderPayloadLen
.
§When is the slice length used as a fallback?
For IPv4 packets the slice length is used as a fallback/substitute
if the total_length
field in the IPv4 header is:
- Bigger then the given slice (payload cannot fully be separated).
- Too small to contain at least the IPv4 header.
For IPv6 packet the slice length is used as a fallback/substitute
if the payload_length
is
- Bigger then the given slice (payload cannot fully be separated).
- The value
0
.
Trait Implementations§
Source§impl<'a> Clone for LaxIpSlice<'a>
impl<'a> Clone for LaxIpSlice<'a>
Source§fn clone(&self) -> LaxIpSlice<'a>
fn clone(&self) -> LaxIpSlice<'a>
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source
. Read more