#[cfg(feature = "icmp")]
use flowscope::driver::{DriverBuilder, SlotHandle};
#[cfg(feature = "icmp")]
use flowscope::extract::{FiveTuple, FiveTupleKey};
#[cfg(feature = "icmp")]
use crate::protocol::{Dispatch, FlowProtocol, MessageProtocol, Protocol, ProtocolInitError};
#[derive(Debug, Clone, Copy)]
pub struct Icmp;
#[cfg(feature = "icmp")]
impl Protocol for Icmp {
type Message = flowscope::icmp::IcmpMessage;
const NAME: &'static str = flowscope::icmp::PARSER_KIND;
fn dispatch() -> Dispatch {
Dispatch::Icmp
}
fn register(
builder: &mut DriverBuilder<FiveTuple>,
) -> Result<SlotHandle<Self::Message, FiveTupleKey>, ProtocolInitError> {
Ok(builder.datagram_broadcast(flowscope::icmp::IcmpParser::new()))
}
fn make_slot(
handle: SlotHandle<Self::Message, FiveTupleKey>,
) -> Box<dyn crate::monitor::ProtocolSlot> {
Box::new(crate::monitor::registry::IcmpSlot::new(handle))
}
}
#[cfg(feature = "icmp")]
impl FlowProtocol for Icmp {}
#[cfg(feature = "icmp")]
impl MessageProtocol for Icmp {}
#[cfg(all(test, feature = "icmp"))]
mod tests {
use super::*;
#[test]
fn dispatch_is_icmp() {
assert!(matches!(<Icmp as Protocol>::dispatch(), Dispatch::Icmp));
}
#[test]
fn name_matches_flowscope_parser_kind() {
assert_eq!(<Icmp as Protocol>::NAME, flowscope::icmp::PARSER_KIND);
}
#[test]
fn register_returns_handle() {
let mut b = flowscope::driver::Driver::builder(FiveTuple::bidirectional());
let h = <Icmp as Protocol>::register(&mut b);
assert!(h.is_ok());
}
}