use std::net::IpAddr;
use ipnet::IpNet;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone)]
pub enum ParsedRule {
Domain(String),
DomainSuffix(String),
DomainKeyword(String),
IpCidr(IpNet),
DstPort(u16),
SrcIpCidr(IpNet),
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "UPPERCASE")]
pub enum Action {
Direct,
Reject,
#[serde(untagged)]
Outbound(String),
}
impl Action {
pub fn is_direct(&self) -> bool {
matches!(self, Action::Direct)
}
pub fn is_reject(&self) -> bool {
matches!(self, Action::Reject)
}
}
#[derive(Debug)]
pub(crate) enum EngineRule {
RuleSet { name: String, action: Action },
GeoIp { code: String, action: Action },
Inline { rule: ParsedRule, action: Action },
Final { action: Action },
}
#[derive(Debug)]
pub struct MatchContext<'a> {
pub domain: Option<&'a str>,
pub dest_ip: Option<IpAddr>,
pub dest_port: u16,
pub src_ip: IpAddr,
}