Trait IpPacket

Source
pub trait IpPacket<I: FilterIpExt> {
    type TransportPacket<'a>: MaybeTransportPacket
       where Self: 'a;
    type TransportPacketMut<'a>: MaybeTransportPacketMut<I>
       where Self: 'a;
    type IcmpError<'a>: MaybeIcmpErrorPayload<I>
       where Self: 'a;
    type IcmpErrorMut<'a>: MaybeIcmpErrorMut<I>
       where Self: 'a;

    // Required methods
    fn src_addr(&self) -> I::Addr;
    fn set_src_addr(&mut self, addr: I::Addr);
    fn dst_addr(&self) -> I::Addr;
    fn set_dst_addr(&mut self, addr: I::Addr);
    fn protocol(&self) -> Option<I::Proto>;
    fn maybe_transport_packet<'a>(&'a self) -> Self::TransportPacket<'a>;
    fn transport_packet_mut<'a>(&'a mut self) -> Self::TransportPacketMut<'a>;
    fn maybe_icmp_error<'a>(&'a self) -> Self::IcmpError<'a>;
    fn icmp_error_mut<'a>(&'a mut self) -> Self::IcmpErrorMut<'a>;

    // Provided method
    fn conntrack_packet(&self) -> Option<PacketMetadata<I>> { ... }
}
Expand description

An IP packet that provides header inspection.

Required Associated Types§

Source

type TransportPacket<'a>: MaybeTransportPacket where Self: 'a

The type that provides access to transport-layer header inspection, if a transport header is contained in the body of the IP packet.

Source

type TransportPacketMut<'a>: MaybeTransportPacketMut<I> where Self: 'a

The type that provides access to transport-layer header modification, if a transport header is contained in the body of the IP packet.

Source

type IcmpError<'a>: MaybeIcmpErrorPayload<I> where Self: 'a

The type that provides access to IP- and transport-layer information within an ICMP error packet, if this IP packet contains one.

Source

type IcmpErrorMut<'a>: MaybeIcmpErrorMut<I> where Self: 'a

The type that provides mutable access to the message within an ICMP error packet, if this IP packet contains one.

Required Methods§

Source

fn src_addr(&self) -> I::Addr

The source IP address of the packet.

Source

fn set_src_addr(&mut self, addr: I::Addr)

Sets the source IP address of the packet.

Source

fn dst_addr(&self) -> I::Addr

The destination IP address of the packet.

Source

fn set_dst_addr(&mut self, addr: I::Addr)

Sets the destination IP address of the packet.

Source

fn protocol(&self) -> Option<I::Proto>

The IP protocol of the packet.

Source

fn maybe_transport_packet<'a>(&'a self) -> Self::TransportPacket<'a>

Returns a type that provides access to the transport-layer packet contained in the body of the IP packet, if one exists.

This method returns an owned type parameterized on a lifetime that is tied to the lifetime of Self, rather than, for example, a reference to a non-parameterized type (&Self::TransportPacket). This is because implementors may need to parse the transport header from the body of the IP packet and materialize the results into a new type when this is called, but that type may also need to retain a reference to the backing buffer in order to modify the transport header.

Source

fn transport_packet_mut<'a>(&'a mut self) -> Self::TransportPacketMut<'a>

Returns a type that provides the ability to modify the transport-layer packet contained in the body of the IP packet, if one exists.

This method returns an owned type parameterized on a lifetime that is tied to the lifetime of Self, rather than, for example, a reference to a non-parameterized type (&Self::TransportPacketMut). This is because implementors may need to parse the transport header from the body of the IP packet and materialize the results into a new type when this is called, but that type may also need to retain a reference to the backing buffer in order to modify the transport header.

Source

fn maybe_icmp_error<'a>(&'a self) -> Self::IcmpError<'a>

Returns a type that provides the ability to access the IP- and transport-layer headers contained within the body of the ICMP error message, if one exists in this packet.

NOTE: See the note on IpPacket::maybe_transport_packet.

Source

fn icmp_error_mut<'a>(&'a mut self) -> Self::IcmpErrorMut<'a>

Returns a type that provides the ability to modify the IP- and transport-layer headers contained within the body of the ICMP error message, if one exists in this packet.

NOTE: See the note on IpPacket::transport_packet_mut.

Provided Methods§

Source

fn conntrack_packet(&self) -> Option<PacketMetadata<I>>

The header information to be used for connection tracking.

For the transport header, this currently returns the same information as IpPacket::maybe_transport_packet, but may be different for packets such as ICMP errors. In that case, we care about the inner IP packet for connection tracking, but use the outer header for filtering.

Subtlety: For ICMP packets, only request/response messages will have a transport packet defined (and currently only ECHO messages do). This gets us basic tracking for free, and lets us implicitly ignore ICMP errors, which are not meant to be tracked.

If other ICMP message types eventually have TransportPacket impls, then this would lead to multiple message types being mapped to the same tuple if they happen to have the same ID.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<B: SplitByteSliceMut> IpPacket<Ipv4> for Ipv4Packet<B>

Source§

type TransportPacket<'a> = &'a Ipv4Packet<B> where Self: 'a

Source§

type TransportPacketMut<'a> = Option<ParsedTransportHeaderMut<'a, Ipv4>> where B: 'a

Source§

type IcmpError<'a> = &'a Ipv4Packet<B> where Self: 'a

Source§

type IcmpErrorMut<'a> = Option<ParsedIcmpErrorMut<'a, Ipv4>> where B: 'a

Source§

fn src_addr(&self) -> Ipv4Addr

Source§

fn set_src_addr(&mut self, addr: Ipv4Addr)

Source§

fn dst_addr(&self) -> Ipv4Addr

Source§

fn set_dst_addr(&mut self, addr: Ipv4Addr)

Source§

fn protocol(&self) -> Option<Ipv4Proto>

Source§

fn maybe_transport_packet(&self) -> Self::TransportPacket<'_>

Source§

fn transport_packet_mut(&mut self) -> Self::TransportPacketMut<'_>

Source§

fn maybe_icmp_error<'a>(&'a self) -> Self::IcmpError<'a>

Source§

fn icmp_error_mut<'a>(&'a mut self) -> Self::IcmpErrorMut<'a>

Source§

impl<B: SplitByteSliceMut> IpPacket<Ipv4> for Ipv4PacketRaw<B>

Source§

type TransportPacket<'a> = &'a Ipv4PacketRaw<B> where Self: 'a

Source§

type TransportPacketMut<'a> = Option<ParsedTransportHeaderMut<'a, Ipv4>> where B: 'a

Source§

type IcmpError<'a> = &'a Ipv4PacketRaw<B> where Self: 'a

Source§

type IcmpErrorMut<'a> = Option<ParsedIcmpErrorMut<'a, Ipv4>> where B: 'a

Source§

fn src_addr(&self) -> Ipv4Addr

Source§

fn set_src_addr(&mut self, addr: Ipv4Addr)

Source§

fn dst_addr(&self) -> Ipv4Addr

Source§

fn set_dst_addr(&mut self, addr: Ipv4Addr)

Source§

fn protocol(&self) -> Option<Ipv4Proto>

Source§

fn maybe_transport_packet<'a>(&'a self) -> Self::TransportPacket<'a>

Source§

fn transport_packet_mut<'a>(&'a mut self) -> Self::TransportPacketMut<'a>

Source§

fn maybe_icmp_error<'a>(&'a self) -> Self::IcmpError<'a>

Source§

fn icmp_error_mut<'a>(&'a mut self) -> Self::IcmpErrorMut<'a>

Source§

impl<B: SplitByteSliceMut> IpPacket<Ipv6> for Ipv6Packet<B>

Source§

type TransportPacket<'a> = &'a Ipv6Packet<B> where Self: 'a

Source§

type TransportPacketMut<'a> = Option<ParsedTransportHeaderMut<'a, Ipv6>> where B: 'a

Source§

type IcmpError<'a> = &'a Ipv6Packet<B> where Self: 'a

Source§

type IcmpErrorMut<'a> = Option<ParsedIcmpErrorMut<'a, Ipv6>> where B: 'a

Source§

fn src_addr(&self) -> Ipv6Addr

Source§

fn set_src_addr(&mut self, addr: Ipv6Addr)

Source§

fn dst_addr(&self) -> Ipv6Addr

Source§

fn set_dst_addr(&mut self, addr: Ipv6Addr)

Source§

fn protocol(&self) -> Option<Ipv6Proto>

Source§

fn maybe_transport_packet(&self) -> Self::TransportPacket<'_>

Source§

fn transport_packet_mut(&mut self) -> Self::TransportPacketMut<'_>

Source§

fn maybe_icmp_error<'a>(&'a self) -> Self::IcmpError<'a>

Source§

fn icmp_error_mut<'a>(&'a mut self) -> Self::IcmpErrorMut<'a>

Source§

impl<B: SplitByteSliceMut> IpPacket<Ipv6> for Ipv6PacketRaw<B>

Source§

type TransportPacket<'a> = &'a Ipv6PacketRaw<B> where Self: 'a

Source§

type TransportPacketMut<'a> = Option<ParsedTransportHeaderMut<'a, Ipv6>> where B: 'a

Source§

type IcmpError<'a> = &'a Ipv6PacketRaw<B> where Self: 'a

Source§

type IcmpErrorMut<'a> = Option<ParsedIcmpErrorMut<'a, Ipv6>> where B: 'a

Source§

fn src_addr(&self) -> Ipv6Addr

Source§

fn set_src_addr(&mut self, addr: Ipv6Addr)

Source§

fn dst_addr(&self) -> Ipv6Addr

Source§

fn set_dst_addr(&mut self, addr: Ipv6Addr)

Source§

fn protocol(&self) -> Option<Ipv6Proto>

Source§

fn maybe_transport_packet<'a>(&'a self) -> Self::TransportPacket<'a>

Source§

fn transport_packet_mut(&mut self) -> Self::TransportPacketMut<'_>

Source§

fn maybe_icmp_error<'a>(&'a self) -> Self::IcmpError<'a>

Source§

fn icmp_error_mut<'a>(&'a mut self) -> Self::IcmpErrorMut<'a>

Source§

impl<I: FilterIpExt> IpPacket<I> for Infallible

Source§

type TransportPacket<'a> = Infallible where Self: 'a

Source§

type TransportPacketMut<'a> = Infallible where Self: 'a

Source§

type IcmpError<'a> = Infallible where Self: 'a

Source§

type IcmpErrorMut<'a> = Infallible where Self: 'a

Source§

fn src_addr(&self) -> I::Addr

Source§

fn set_src_addr(&mut self, _addr: I::Addr)

Source§

fn dst_addr(&self) -> I::Addr

Source§

fn protocol(&self) -> Option<I::Proto>

Source§

fn set_dst_addr(&mut self, _addr: I::Addr)

Source§

fn maybe_transport_packet<'a>(&'a self) -> Self::TransportPacket<'a>

Source§

fn transport_packet_mut<'a>(&'a mut self) -> Self::TransportPacketMut<'a>

Source§

fn maybe_icmp_error<'a>(&'a self) -> Self::IcmpError<'a>

Source§

fn icmp_error_mut<'a>(&'a mut self) -> Self::IcmpErrorMut<'a>

Source§

impl<I: FilterIpExt, S: TransportPacketSerializer<I>, B: IpPacketBuilder<I>> IpPacket<I> for Nested<S, B>

Source§

type TransportPacket<'a> = &'a S where Self: 'a

Source§

type TransportPacketMut<'a> = &'a mut S where Self: 'a

Source§

type IcmpError<'a> = &'a S where Self: 'a

Source§

type IcmpErrorMut<'a> = &'a mut S where Self: 'a

Source§

fn src_addr(&self) -> I::Addr

Source§

fn set_src_addr(&mut self, addr: I::Addr)

Source§

fn dst_addr(&self) -> I::Addr

Source§

fn set_dst_addr(&mut self, addr: I::Addr)

Source§

fn protocol(&self) -> Option<I::Proto>

Source§

fn maybe_transport_packet(&self) -> Self::TransportPacket<'_>

Source§

fn transport_packet_mut(&mut self) -> Self::TransportPacketMut<'_>

Source§

fn maybe_icmp_error<'a>(&'a self) -> Self::IcmpError<'a>

Source§

fn icmp_error_mut<'a>(&'a mut self) -> Self::IcmpErrorMut<'a>

Implementors§

Source§

impl<I: FilterIpExt, B: BufferMut> IpPacket<I> for ForwardedPacket<I, B>

Source§

type TransportPacket<'a> = &'a ForwardedPacket<I, B> where Self: 'a

Source§

type TransportPacketMut<'a> = Option<ParsedTransportHeaderMut<'a, I>> where Self: 'a

Source§

type IcmpError<'a> = &'a ForwardedPacket<I, B> where Self: 'a

Source§

type IcmpErrorMut<'a> = Option<ParsedIcmpErrorMut<'a, I>> where Self: 'a

Source§

impl<I: FilterIpExt, S: TransportPacketSerializer<I>> IpPacket<I> for TxPacket<'_, I, S>

Source§

type TransportPacket<'a> = &'a S where Self: 'a

Source§

type TransportPacketMut<'a> = &'a mut S where Self: 'a

Source§

type IcmpError<'a> = &'a S where Self: 'a

Source§

type IcmpErrorMut<'a> = &'a mut S where Self: 'a