/// Convert an extension header parsing error to an IP packet
/// parsing error.
Convert an extension header parsing error to an IP packet
parsing error.
Convert an extension header parsing error to an IP packet parsing error .
fn ext_hdr_err_fn(hdr: &FixedHeader, err: Ipv6ExtensionHeaderParsingError) -> IpParseError<Ipv6> {
    // Below, we set parameter problem data's `pointer` to `(IPV6_FIXED_HDR_LEN as u32) + pointer`
    // since the the `pointer` we get from an `Ipv6ExtensionHeaderParsingError` is calculated
    // from the start of the extension headers, but within an IPv6 packet, extension headers
    // start right after the fixed header with a length of `IPV6_FIXED_HDR_LEN` so we add `pointer`
    // to `IPV6_FIXED_HDR_LEN` to get the pointer to the field with the parameter problem error
    // from the start of the IPv6 packet. We know `(IPV6_FIXED_HDR_LEN as u32) + pointer` will
    // not overflow because the maximum size of an IPv6 packet is 65575 bytes (fixed header +
    // extension headers + body) and 65575 definitely fits within an `u32`. Note, this may no longer
    // hold true if/when jumbogram packets are supported.
    // TODO(ghanan): If pointer calculation overflows, drop the packet instead of sending back an
    //               ICMP response since we'll almost certainly never encounter this in practice.
    match err {
        Ipv6ExtensionHeaderParsingError::ErroneousHeaderField {
            pointer,
            must_send_icmp,
            header_len,
        } => IpParseError::ParameterProblem {
            src_ip: Ipv6Addr::new(hdr.src_ip),
            dst_ip: Ipv6Addr::new(hdr.dst_ip),
            code: Icmpv6ParameterProblemCode::ErroneousHeaderField,
            pointer: pointer.checked_add(IPV6_FIXED_HDR_LEN as u32).unwrap_or(0),
            must_send_icmp,
            header_len: IPV6_FIXED_HDR_LEN + header_len,
        },
        Ipv6ExtensionHeaderParsingError::UnrecognizedNextHeader {
            pointer,
            must_send_icmp,
            header_len,
        } => IpParseError::ParameterProblem {
            src_ip: Ipv6Addr::new(hdr.src_ip),
            dst_ip: Ipv6Addr::new(hdr.dst_ip),
            code: Icmpv6ParameterProblemCode::UnrecognizedNextHeaderType,
            pointer: pointer.checked_add(IPV6_FIXED_HDR_LEN as u32).unwrap_or(0),
            must_send_icmp,
            header_len: IPV6_FIXED_HDR_LEN + header_len,
        },
        Ipv6ExtensionHeaderParsingError::UnrecognizedOption {
            pointer,
            must_send_icmp,
            header_len,
        } => IpParseError::ParameterProblem {
            src_ip: Ipv6Addr::new(hdr.src_ip),
            dst_ip: Ipv6Addr::new(hdr.dst_ip),
            code: Icmpv6ParameterProblemCode::UnrecognizedIpv6Option,
            pointer: pointer.checked_add(IPV6_FIXED_HDR_LEN as u32).unwrap_or(0),
            must_send_icmp,
            header_len: IPV6_FIXED_HDR_LEN + header_len,
        },
        Ipv6ExtensionHeaderParsingError::BufferExhausted
        | Ipv6ExtensionHeaderParsingError::MalformedData => {
            // Unexpectedly running out of a buffer or encountering malformed
            // data when parsing is a formatting error.
            IpParseError::Parse { error: ParseError::Format }
        }
    }
}
fn ext_hdr_err_fn ( hdr : & FixedHeader , err : Ipv6ExtensionHeaderParsingError ) -> IpParseError < Ipv6 > { // Below, we set parameter problem data's `pointer` to `(IPV6_FIXED_HDR_LEN as u32) + pointer` // since the the `pointer` we get from an `Ipv6ExtensionHeaderParsingError` is calculated // from the start of the extension headers, but within an IPv6 packet, extension headers // start right after the fixed header with a length of `IPV6_FIXED_HDR_LEN` so we add `pointer` // to `IPV6_FIXED_HDR_LEN` to get the pointer to the field with the parameter problem error // from the start of the IPv6 packet. We know `(IPV6_FIXED_HDR_LEN as u32) + pointer` will // not overflow because the maximum size of an IPv6 packet is 65575 bytes (fixed header + // extension headers + body) and 65575 definitely fits within an `u32`. Note, this may no longer // hold true if/when jumbogram packets are supported. // TODO(ghanan): If pointer calculation overflows, drop the packet instead of sending back an //               ICMP response since we'll almost certainly never encounter this in practice. match err { Ipv6ExtensionHeaderParsingError :: ErroneousHeaderField { pointer , must_send_icmp , header_len , } => IpParseError :: ParameterProblem { src_ip : Ipv6Addr :: new ( hdr . src_ip ) , dst_ip : Ipv6Addr :: new ( hdr . dst_ip ) , code : Icmpv6ParameterProblemCode :: ErroneousHeaderField , pointer : pointer . checked_add ( IPV6_FIXED_HDR_LEN as u32 ) . unwrap_or ( 0 ) , must_send_icmp , header_len : IPV6_FIXED_HDR_LEN + header_len , } , Ipv6ExtensionHeaderParsingError :: UnrecognizedNextHeader { pointer , must_send_icmp , header_len , } => IpParseError :: ParameterProblem { src_ip : Ipv6Addr :: new ( hdr . src_ip ) , dst_ip : Ipv6Addr :: new ( hdr . dst_ip ) , code : Icmpv6ParameterProblemCode :: UnrecognizedNextHeaderType , pointer : pointer . checked_add ( IPV6_FIXED_HDR_LEN as u32 ) . unwrap_or ( 0 ) , must_send_icmp , header_len : IPV6_FIXED_HDR_LEN + header_len , } , Ipv6ExtensionHeaderParsingError :: UnrecognizedOption { pointer , must_send_icmp , header_len , } => IpParseError :: ParameterProblem { src_ip : Ipv6Addr :: new ( hdr . src_ip ) , dst_ip : Ipv6Addr :: new ( hdr . dst_ip ) , code : Icmpv6ParameterProblemCode :: UnrecognizedIpv6Option , pointer : pointer . checked_add ( IPV6_FIXED_HDR_LEN as u32 ) . unwrap_or ( 0 ) , must_send_icmp , header_len : IPV6_FIXED_HDR_LEN + header_len , } , Ipv6ExtensionHeaderParsingError :: BufferExhausted | Ipv6ExtensionHeaderParsingError :: MalformedData => { // Unexpectedly running out of a buffer or encountering malformed // data when parsing is a formatting error. IpParseError :: Parse { error : ParseError :: Format } } } }
Convert an extension header parsing error to an IP packet
parsing error.
Convert an extension header parsing error to an IP packet parsing error .
hdr
&FixedHeader
err
Ipv6ExtensionHeaderParsingError