pub(crate) mod config;
pub mod enterprise_registry;
pub(crate) mod fast_parse;
pub mod field_types;
pub mod field_value;
pub mod ipfix;
pub mod metrics;
pub(crate) mod pending_flows;
pub mod template_events;
pub mod ttl;
pub mod v9;
pub use config::ParserConfig;
pub(crate) use config::ParserFields;
pub use config::{
Config, ConfigError, DEFAULT_MAX_RECORDS_PER_FLOWSET, DEFAULT_MAX_TEMPLATE_CACHE_SIZE,
MAX_FIELD_COUNT,
};
pub use pending_flows::PendingFlowsConfig;
pub(crate) use config::TemplateId;
pub(crate) use pending_flows::{PendingFlowCache, PendingFlowEntry};
use crate::variable_versions::metrics::CacheMetricsInner;
use crate::variable_versions::ttl::TtlConfig;
#[non_exhaustive]
#[derive(Debug, Clone, serde::Serialize)]
pub struct NoTemplateInfo {
pub template_id: u16,
pub raw_data: Vec<u8>,
pub truncated: bool,
}
impl NoTemplateInfo {
pub fn new(template_id: u16, raw_data: Vec<u8>) -> Self {
Self {
template_id,
raw_data,
truncated: false,
}
}
}
impl PartialEq for NoTemplateInfo {
fn eq(&self, other: &Self) -> bool {
self.template_id == other.template_id
&& self.raw_data == other.raw_data
&& self.truncated == other.truncated
}
}
impl Eq for NoTemplateInfo {}
pub(crate) fn calculate_padding(body_size: usize) -> &'static [u8] {
const PADDING: [u8; 3] = [0u8; 3];
const PADDING_SIZES: [usize; 4] = [0, 3, 2, 1];
let padding_len = PADDING_SIZES[body_size % 4];
&PADDING[..padding_len]
}
#[inline]
pub(crate) fn get_valid_template<T: Clone>(
cache: &mut lru::LruCache<TemplateId, ttl::TemplateWithTtl<std::sync::Arc<T>>>,
id: &TemplateId,
ttl_config: &Option<TtlConfig>,
metrics: &mut CacheMetricsInner,
) -> Option<std::sync::Arc<T>> {
if let Some(wrapped) = cache.peek(id) {
if let Some(config) = ttl_config
&& wrapped.is_expired(config)
{
cache.pop(id);
metrics.record_expiration();
return None;
}
let template = std::sync::Arc::clone(&wrapped.template);
cache.promote(id);
return Some(template);
}
None
}
pub(crate) fn peek_valid_template<T: Clone>(
cache: &mut lru::LruCache<TemplateId, ttl::TemplateWithTtl<std::sync::Arc<T>>>,
id: &TemplateId,
ttl_config: &Option<TtlConfig>,
metrics: &mut CacheMetricsInner,
) -> Option<std::sync::Arc<T>> {
if let Some(wrapped) = cache.peek(id) {
if let Some(config) = ttl_config
&& wrapped.is_expired(config)
{
cache.pop(id);
metrics.record_expiration();
return None;
}
return Some(std::sync::Arc::clone(&wrapped.template));
}
None
}