use flowscope::driver::{DriverBuilder, SlotHandle};
use flowscope::extract::{FiveTuple, FiveTupleKey};
use crate::protocol::{Dispatch, MessageProtocol, Protocol, ProtocolInitError};
#[derive(Debug, Clone, Copy)]
pub struct Smb;
impl MessageProtocol for Smb {}
impl Protocol for Smb {
type Message = flowscope::smb::SmbMessage;
const NAME: &'static str = "smb";
fn dispatch() -> Dispatch {
Dispatch::Tcp(vec![flowscope::smb::SMB_PORT])
}
fn register(
builder: &mut DriverBuilder<FiveTuple>,
) -> Result<SlotHandle<Self::Message, FiveTupleKey>, ProtocolInitError> {
let ports = match Self::dispatch() {
Dispatch::Tcp(p) => p,
_ => unreachable!("Smb::dispatch is Dispatch::Tcp by construction"),
};
Ok(builder.session_on_ports(flowscope::smb::SmbParser::new(), ports))
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn dispatch_targets_tcp_445() {
match Smb::dispatch() {
Dispatch::Tcp(ports) => assert_eq!(ports, vec![445]),
other => panic!("expected Dispatch::Tcp, got {other:?}"),
}
}
#[test]
fn name_matches_flowscope_kind() {
assert_eq!(Smb::NAME, flowscope::smb::parser_kind());
}
}