use lazy_static::lazy_static;
use proc_macro2::Span;
use quote::quote;
use retina_core::filter::{DataType, Level, SubscriptionSpec};
use std::collections::HashMap;
use crate::*;
lazy_static! {
pub static ref DATATYPES: HashMap<&'static str, DataType> = {
HashMap::from([
("ConnRecord", DataType::new_default_connection("ConnRecord")),
(
"ConnDuration",
DataType::new_default_connection("ConnDuration"),
),
("PktCount", DataType::new_default_connection("PktCount")),
("ByteCount", DataType::new_default_connection("ByteCount")),
(
"InterArrivals",
DataType::new_default_connection("InterArrivals"),
),
(
"ConnHistory",
DataType::new_default_connection("ConnHistory"),
),
(
"HttpTransaction",
DataType::new_default_session(
"HttpTransaction",
HttpTransaction::stream_protocols(),
),
),
(
"DnsTransaction",
DataType::new_default_session("DnsTransaction", DnsTransaction::stream_protocols()),
),
(
"TlsHandshake",
DataType::new_default_session("TlsHandshake", TlsHandshake::stream_protocols()),
),
(
"QuicStream",
DataType::new_default_session("QuicStream", QuicStream::stream_protocols()),
),
(
"SshHandshake",
DataType::new_default_session("SshHandshake", SshHandshake::stream_protocols()),
),
("ZcFrame", DataType::new_default_packet("ZcFrame")),
("Payload", DataType::new_default_packet("Payload")),
("SessionList", {
DataType {
level: Level::Connection,
needs_parse: true,
track_sessions: true,
needs_update: false,
needs_reassembly: false,
needs_packet_track: false,
stream_protos: vec!["tls", "dns", "http", "quic", "ssh"],
as_str: "SessionList",
}
}),
("BidirZcPktStream", { DataType::new_default_pktlist("BidirZcPktStream", false) }),
("OrigZcPktStream", { DataType::new_default_pktlist("OrigZcPktStream", false) }),
("RespZcPktStream", { DataType::new_default_pktlist("RespZcPktStream", false) }),
("OrigZcPktsReassembled", { DataType::new_default_pktlist("OrigZcPktsReassembled", true) }),
("RespZcPktsReassembled", { DataType::new_default_pktlist("RespZcPktsReassembled", true) }),
("BidirPktStream", { DataType::new_default_pktlist("BidirPktStream", false) }),
("OrigPktStream", { DataType::new_default_pktlist("OrigPktStream", false) }),
("RespPktStream", { DataType::new_default_pktlist("RespPktStream", false) }),
("OrigPktsReassembled", { DataType::new_default_pktlist("OrigPktsReassembled", true) }),
("RespPktsReassembled", { DataType::new_default_pktlist("RespPktsReassembled", true) }),
("CoreId", { DataType::new_default_static("CoreId") }),
("FiveTuple", { DataType::new_default_static("FiveTuple") }),
("EtherTCI", { DataType::new_default_static("EtherTCI") }),
("EthAddr", { DataType::new_default_static("EthAddr") }),
("FilterStr", { DataType::new_default_static("FilterStr") }),
])
};
}
lazy_static! {
pub static ref DIRECTLY_TRACKED: HashMap<&'static str, &'static str> = HashMap::from([
("SessionList", "sessions"),
("CoreId", "core_id")
]);
#[doc(hidden)]
pub static ref FILTER_STR: &'static str = "FilterStr";
}
pub type SessionList = Vec<Session>;
pub type FilterStr<'a> = &'a str;
impl<'a> FromSubscription for FilterStr<'a> {
fn from_subscription(spec: &SubscriptionSpec) -> proc_macro2::TokenStream {
let str = syn::LitStr::new(&spec.filter, Span::call_site());
quote! { &#str }
}
}