use crate::packet::Layer;
use super::{
ICMPV6_DESTINATION_UNREACHABLE, ICMPV6_ECHO_REPLY, ICMPV6_ECHO_REQUEST,
ICMPV6_PARAMETER_PROBLEM, ICMPV6_TIME_EXCEEDED, ICMP_DESTINATION_UNREACHABLE, ICMP_ECHO_REPLY,
ICMP_ECHO_REQUEST, ICMP_PARAMETER_PROBLEM, ICMP_TIME_EXCEEDED,
};
mod extensions;
pub use self::extensions::*;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum IcmpKind {
DestinationUnreachable,
TimeExceeded,
ParameterProblem,
EchoRequest,
EchoReply,
}
impl IcmpKind {
pub const fn ipv4_type(self) -> u8 {
match self {
Self::DestinationUnreachable => ICMP_DESTINATION_UNREACHABLE,
Self::TimeExceeded => ICMP_TIME_EXCEEDED,
Self::ParameterProblem => ICMP_PARAMETER_PROBLEM,
Self::EchoRequest => ICMP_ECHO_REQUEST,
Self::EchoReply => ICMP_ECHO_REPLY,
}
}
pub const fn ipv6_type(self) -> u8 {
match self {
Self::DestinationUnreachable => ICMPV6_DESTINATION_UNREACHABLE,
Self::TimeExceeded => ICMPV6_TIME_EXCEEDED,
Self::ParameterProblem => ICMPV6_PARAMETER_PROBLEM,
Self::EchoRequest => ICMPV6_ECHO_REQUEST,
Self::EchoReply => ICMPV6_ECHO_REPLY,
}
}
}
pub trait IcmpLayer: Layer {
fn icmp_type_value(&self) -> u8;
fn code_value(&self) -> u8;
fn checksum_value(&self) -> Option<u16>;
fn identifier_value(&self) -> Option<u16>;
fn sequence_number_value(&self) -> Option<u16>;
fn kind(&self) -> Option<IcmpKind>;
fn is_echo_request(&self) -> bool {
self.kind() == Some(IcmpKind::EchoRequest)
}
fn is_echo_reply(&self) -> bool {
self.kind() == Some(IcmpKind::EchoReply)
}
}