push_packet/engine/mod.rs
1//! Defines [`Engine`] traits.
2#[cfg(feature = "linear")]
3pub mod linear;
4
5use crate::{
6 error::Error,
7 loader::Loader,
8 rules::{Rule, RuleId},
9};
10
11/// The Engine trait defines how rules are evaluated in the eBPF program. Each Engine requires a
12/// matching eBPF program.
13pub trait Engine {
14 /// A type corresponding to the [`Engine`]'s [`Loader`]. This is responsible for collecting
15 /// configuration and generating the [`Engine`].
16 type Loader: Loader<Component = Self> + Default;
17 /// The raw bytes of the eBPF program
18 const EBPF_BYTES: &'static [u8];
19
20 /// The eBPF program name
21 const EBPF_PROGRAM_NAME: &'static str;
22
23 /// If this engnine is limited in max capacity, return the capcacity
24 fn capacity(&self) -> Option<usize>;
25 /// Add a rule to the engine
26 ///
27 /// # Errors
28 /// Returns [`Error::EngineAtCapacity`] if the engine cannot accept additional rules.
29 /// Returns additional errors depending on the engine implementation.
30 fn add_rule(&mut self, rule_id: RuleId, rule: &Rule) -> Result<(), Error>;
31 /// Remove a rule from the engine
32 ///
33 /// # Errors
34 /// Returns [`Error::MissingRule`] if the rule id is not present in the filter.
35 /// Returns additional errors depending on the engine implementation.
36 fn remove_rule(&mut self, rule_id: RuleId, rule: &Rule) -> Result<(), Error>;
37}