style: switch rustfmt to hard tabs; document tests-separate rule in TODO

- rustfmt.toml: hard_tabs = true.
- TODO §0.7: tests live in tests/, no #[cfg(test)] modules in code files.
This commit is contained in:
Loki 2026-11-15 22:34:29 +01:00
parent d8393e0f39
commit a90f0da226
Signed by: boba
GPG key ID: 6CDE87BC9A778D97
96 changed files with 6542 additions and 6537 deletions

View file

@ -3,12 +3,12 @@ use serde::Deserialize;
/// Секция `[detect]`: детекторы распределённых атак.
#[derive(Debug, Clone, Default, Deserialize)]
pub struct DetectConfig {
#[serde(default)]
pub prefix: DetectPrefixConfig,
#[serde(default)]
pub autoban: DetectAutobanConfig,
#[serde(default)]
pub alert: DetectAlertConfig,
#[serde(default)]
pub prefix: DetectPrefixConfig,
#[serde(default)]
pub autoban: DetectAutobanConfig,
#[serde(default)]
pub alert: DetectAlertConfig,
}
/// Секция `[detect.autoban]`: авто-бан источников по репутации и сигналам
@ -16,150 +16,150 @@ pub struct DetectConfig {
/// TTL берётся из `ban.ban_duration_secs`.
#[derive(Debug, Clone, Deserialize)]
pub struct DetectAutobanConfig {
#[serde(default)]
pub enabled: bool,
#[serde(default = "default_autoban_reputation_threshold")]
pub reputation_threshold: i32,
#[serde(default)]
pub enabled: bool,
#[serde(default = "default_autoban_reputation_threshold")]
pub reputation_threshold: i32,
}
impl Default for DetectAutobanConfig {
fn default() -> Self {
Self {
enabled: false,
reputation_threshold: default_autoban_reputation_threshold(),
}
}
fn default() -> Self {
Self {
enabled: false,
reputation_threshold: default_autoban_reputation_threshold(),
}
}
}
fn default_autoban_reputation_threshold() -> i32 {
-50
-50
}
/// Секция `[detect.alert]`: webhook-алерты на переходах состояния атаки
/// («атака началась» / «атака закончилась»).
#[derive(Debug, Clone, Default, Deserialize)]
pub struct DetectAlertConfig {
#[serde(default)]
pub webhook_url: Option<String>,
#[serde(default)]
pub webhook_url: Option<String>,
}
/// Секция `[detect.prefix]`: subnet-level детектор распределённых атак.
#[derive(Debug, Clone, Deserialize)]
pub struct DetectPrefixConfig {
#[serde(default)]
pub enabled: bool,
#[serde(default = "default_prefix_syn_threshold")]
pub syn_threshold: u64,
#[serde(default = "default_prefix_window_secs")]
pub window_secs: u64,
#[serde(default = "default_prefix_min_unique_sources")]
pub min_unique_sources: u64,
#[serde(default)]
pub enabled: bool,
#[serde(default = "default_prefix_syn_threshold")]
pub syn_threshold: u64,
#[serde(default = "default_prefix_window_secs")]
pub window_secs: u64,
#[serde(default = "default_prefix_min_unique_sources")]
pub min_unique_sources: u64,
}
impl Default for DetectPrefixConfig {
fn default() -> Self {
Self {
enabled: false,
syn_threshold: default_prefix_syn_threshold(),
window_secs: default_prefix_window_secs(),
min_unique_sources: default_prefix_min_unique_sources(),
}
}
fn default() -> Self {
Self {
enabled: false,
syn_threshold: default_prefix_syn_threshold(),
window_secs: default_prefix_window_secs(),
min_unique_sources: default_prefix_min_unique_sources(),
}
}
}
fn default_prefix_syn_threshold() -> u64 {
500
500
}
fn default_prefix_window_secs() -> u64 {
10
10
}
fn default_prefix_min_unique_sources() -> u64 {
16
16
}
/// Секция `[protocol]`: протокольные обработчики (plugin-by-feature).
#[cfg(any(feature = "protocol-http", feature = "protocol-minecraft"))]
#[derive(Debug, Clone, Default, Deserialize)]
pub struct ProtocolConfig {
#[cfg(feature = "protocol-http")]
#[serde(default)]
pub http: HttpProtocolConfig,
#[cfg(feature = "protocol-minecraft")]
#[serde(default)]
pub minecraft: MinecraftProtocolConfig,
#[cfg(feature = "protocol-http")]
#[serde(default)]
pub http: HttpProtocolConfig,
#[cfg(feature = "protocol-minecraft")]
#[serde(default)]
pub minecraft: MinecraftProtocolConfig,
}
#[cfg(feature = "protocol-minecraft")]
#[derive(Debug, Clone, Deserialize)]
pub struct MinecraftProtocolConfig {
#[serde(default = "default_minecraft_enabled")]
pub enabled: bool,
#[serde(default = "default_minecraft_max_frame_bytes")]
pub max_frame_bytes: usize,
#[serde(default = "default_minecraft_timeout_secs")]
pub timeout_secs: u64,
#[serde(default, alias = "proxy_protocol")]
pub send_proxy_protocol: bool,
#[serde(default = "default_minecraft_enabled")]
pub enabled: bool,
#[serde(default = "default_minecraft_max_frame_bytes")]
pub max_frame_bytes: usize,
#[serde(default = "default_minecraft_timeout_secs")]
pub timeout_secs: u64,
#[serde(default, alias = "proxy_protocol")]
pub send_proxy_protocol: bool,
}
#[cfg(feature = "protocol-minecraft")]
impl Default for MinecraftProtocolConfig {
fn default() -> Self {
Self {
enabled: default_minecraft_enabled(),
max_frame_bytes: default_minecraft_max_frame_bytes(),
timeout_secs: default_minecraft_timeout_secs(),
send_proxy_protocol: false,
}
}
fn default() -> Self {
Self {
enabled: default_minecraft_enabled(),
max_frame_bytes: default_minecraft_max_frame_bytes(),
timeout_secs: default_minecraft_timeout_secs(),
send_proxy_protocol: false,
}
}
}
#[cfg(feature = "protocol-minecraft")]
fn default_minecraft_enabled() -> bool {
!cfg!(feature = "protocol-http")
!cfg!(feature = "protocol-http")
}
#[cfg(feature = "protocol-minecraft")]
fn default_minecraft_max_frame_bytes() -> usize {
8192
8192
}
#[cfg(feature = "protocol-minecraft")]
fn default_minecraft_timeout_secs() -> u64 {
5
5
}
/// Секция `[protocol.http]`: политика HTTP/1.1-обработчика на edge-ноде.
#[cfg(feature = "protocol-http")]
#[derive(Debug, Clone, Deserialize)]
pub struct HttpProtocolConfig {
#[serde(default = "default_http_max_header_bytes")]
pub max_header_bytes: usize,
#[serde(default = "default_http_timeout_secs")]
pub timeout_secs: u64,
#[serde(default)]
pub blocked_paths: Vec<String>,
#[serde(default)]
pub require_user_agent: bool,
#[serde(default = "default_http_max_header_bytes")]
pub max_header_bytes: usize,
#[serde(default = "default_http_timeout_secs")]
pub timeout_secs: u64,
#[serde(default)]
pub blocked_paths: Vec<String>,
#[serde(default)]
pub require_user_agent: bool,
}
#[cfg(feature = "protocol-http")]
impl Default for HttpProtocolConfig {
fn default() -> Self {
Self {
max_header_bytes: default_http_max_header_bytes(),
timeout_secs: default_http_timeout_secs(),
blocked_paths: Vec::new(),
require_user_agent: false,
}
}
fn default() -> Self {
Self {
max_header_bytes: default_http_max_header_bytes(),
timeout_secs: default_http_timeout_secs(),
blocked_paths: Vec::new(),
require_user_agent: false,
}
}
}
#[cfg(feature = "protocol-http")]
fn default_http_max_header_bytes() -> usize {
8192
8192
}
#[cfg(feature = "protocol-http")]
fn default_http_timeout_secs() -> u64 {
5
5
}

View file

@ -4,241 +4,241 @@ use std::str::FromStr;
#[derive(Debug, Clone, Deserialize)]
pub struct BindConfig {
#[serde(default = "default_bind_address")]
pub address: String,
#[serde(default = "default_bind_port")]
pub port: u16,
#[serde(default = "default_bind_address")]
pub address: String,
#[serde(default = "default_bind_port")]
pub port: u16,
}
impl Default for BindConfig {
fn default() -> Self {
Self {
address: default_bind_address(),
port: default_bind_port(),
}
}
fn default() -> Self {
Self {
address: default_bind_address(),
port: default_bind_port(),
}
}
}
fn default_bind_address() -> String {
"0.0.0.0".to_string()
"0.0.0.0".to_string()
}
fn default_bind_port() -> u16 {
25565
25565
}
/// Generic upstream-бэкенды (список addr:port) за edge-нодой.
#[derive(Debug, Clone, Deserialize)]
pub struct BackendConfig {
#[serde(default = "default_upstreams")]
pub upstreams: Vec<String>,
#[serde(default = "default_upstreams")]
pub upstreams: Vec<String>,
}
impl Default for BackendConfig {
fn default() -> Self {
Self {
upstreams: default_upstreams(),
}
}
fn default() -> Self {
Self {
upstreams: default_upstreams(),
}
}
}
fn default_upstreams() -> Vec<String> {
vec!["127.0.0.1:25566".to_string()]
vec!["127.0.0.1:25566".to_string()]
}
#[derive(Debug, Clone, Deserialize)]
pub struct WorkerConfig {
#[serde(default = "default_worker_count")]
pub count: usize,
#[serde(default = "default_worker_count")]
pub count: usize,
}
impl Default for WorkerConfig {
fn default() -> Self {
Self { count: 4 }
}
fn default() -> Self {
Self { count: 4 }
}
}
fn default_worker_count() -> usize {
4
4
}
#[derive(Debug, Clone, Deserialize)]
pub struct LimitsConfig {
#[serde(default = "default_handshake_timeout")]
pub handshake_timeout_secs: u64,
#[serde(default = "default_max_connections_per_ip")]
pub max_connections_per_ip: u32,
#[serde(default = "default_rate_limit_pps")]
pub rate_limit_pps: f64,
#[serde(default = "default_rate_limit_burst")]
pub rate_limit_burst: f64,
#[serde(default = "default_handshake_timeout")]
pub handshake_timeout_secs: u64,
#[serde(default = "default_max_connections_per_ip")]
pub max_connections_per_ip: u32,
#[serde(default = "default_rate_limit_pps")]
pub rate_limit_pps: f64,
#[serde(default = "default_rate_limit_burst")]
pub rate_limit_burst: f64,
}
impl Default for LimitsConfig {
fn default() -> Self {
Self {
handshake_timeout_secs: default_handshake_timeout(),
max_connections_per_ip: default_max_connections_per_ip(),
rate_limit_pps: default_rate_limit_pps(),
rate_limit_burst: default_rate_limit_burst(),
}
}
fn default() -> Self {
Self {
handshake_timeout_secs: default_handshake_timeout(),
max_connections_per_ip: default_max_connections_per_ip(),
rate_limit_pps: default_rate_limit_pps(),
rate_limit_burst: default_rate_limit_burst(),
}
}
}
fn default_handshake_timeout() -> u64 {
5
5
}
fn default_max_connections_per_ip() -> u32 {
10
10
}
fn default_rate_limit_pps() -> f64 {
5.0
5.0
}
fn default_rate_limit_burst() -> f64 {
10.0
10.0
}
#[derive(Debug, Clone, Deserialize)]
pub struct BanConfig {
#[serde(default = "default_ban_duration")]
pub ban_duration_secs: u64,
#[serde(default = "default_ban_duration")]
pub ban_duration_secs: u64,
}
impl Default for BanConfig {
fn default() -> Self {
Self {
ban_duration_secs: default_ban_duration(),
}
}
fn default() -> Self {
Self {
ban_duration_secs: default_ban_duration(),
}
}
}
fn default_ban_duration() -> u64 {
3600
3600
}
#[derive(Debug, Clone, Deserialize)]
pub struct PowConfig {
#[serde(default)]
pub enabled: bool,
#[serde(default = "default_pow_difficulty")]
pub difficulty: u8,
#[serde(default)]
pub enabled: bool,
#[serde(default = "default_pow_difficulty")]
pub difficulty: u8,
}
impl Default for PowConfig {
fn default() -> Self {
Self {
enabled: false,
difficulty: default_pow_difficulty(),
}
}
fn default() -> Self {
Self {
enabled: false,
difficulty: default_pow_difficulty(),
}
}
}
fn default_pow_difficulty() -> u8 {
4
4
}
/// CIDR network allowed to send inbound PROXY protocol headers.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct TrustedProxyCidr {
network: IpAddr,
prefix_len: u8,
network: IpAddr,
prefix_len: u8,
}
impl TrustedProxyCidr {
#[must_use]
pub fn contains(&self, ip: IpAddr) -> bool {
match (self.network, ip) {
(IpAddr::V4(network), IpAddr::V4(ip)) => {
let mask = if self.prefix_len == 0 {
0
} else {
u32::MAX << (32 - self.prefix_len)
};
u32::from(network) & mask == u32::from(ip) & mask
},
(IpAddr::V6(network), IpAddr::V6(ip)) => {
let mask = if self.prefix_len == 0 {
0
} else {
u128::MAX << (128 - self.prefix_len)
};
u128::from(network) & mask == u128::from(ip) & mask
},
_ => false,
}
}
#[must_use]
pub fn contains(&self, ip: IpAddr) -> bool {
match (self.network, ip) {
(IpAddr::V4(network), IpAddr::V4(ip)) => {
let mask = if self.prefix_len == 0 {
0
} else {
u32::MAX << (32 - self.prefix_len)
};
u32::from(network) & mask == u32::from(ip) & mask
},
(IpAddr::V6(network), IpAddr::V6(ip)) => {
let mask = if self.prefix_len == 0 {
0
} else {
u128::MAX << (128 - self.prefix_len)
};
u128::from(network) & mask == u128::from(ip) & mask
},
_ => false,
}
}
}
impl FromStr for TrustedProxyCidr {
type Err = String;
type Err = String;
fn from_str(value: &str) -> Result<Self, Self::Err> {
let (address, prefix) = match value.split_once('/') {
Some((address, prefix)) => (address, Some(prefix)),
None => (value, None),
};
let network = IpAddr::from_str(address).map_err(|_| format!("invalid trusted proxy CIDR: {value}"))?;
let max_prefix = if network.is_ipv4() { 32 } else { 128 };
let prefix_len = match prefix {
Some(prefix) => prefix
.parse::<u8>()
.map_err(|_| format!("invalid trusted proxy CIDR prefix: {value}"))?,
None => max_prefix,
};
if prefix_len > max_prefix {
return Err(format!("trusted proxy CIDR prefix is too large: {value}"));
}
let network = match network {
IpAddr::V4(ip) => IpAddr::V4(Ipv4Addr::from(u32::from(ip) & mask_v4(prefix_len))),
IpAddr::V6(ip) => IpAddr::V6(Ipv6Addr::from(u128::from(ip) & mask_v6(prefix_len))),
};
Ok(Self { network, prefix_len })
}
fn from_str(value: &str) -> Result<Self, Self::Err> {
let (address, prefix) = match value.split_once('/') {
Some((address, prefix)) => (address, Some(prefix)),
None => (value, None),
};
let network = IpAddr::from_str(address).map_err(|_| format!("invalid trusted proxy CIDR: {value}"))?;
let max_prefix = if network.is_ipv4() { 32 } else { 128 };
let prefix_len = match prefix {
Some(prefix) => prefix
.parse::<u8>()
.map_err(|_| format!("invalid trusted proxy CIDR prefix: {value}"))?,
None => max_prefix,
};
if prefix_len > max_prefix {
return Err(format!("trusted proxy CIDR prefix is too large: {value}"));
}
let network = match network {
IpAddr::V4(ip) => IpAddr::V4(Ipv4Addr::from(u32::from(ip) & mask_v4(prefix_len))),
IpAddr::V6(ip) => IpAddr::V6(Ipv6Addr::from(u128::from(ip) & mask_v6(prefix_len))),
};
Ok(Self { network, prefix_len })
}
}
impl<'de> Deserialize<'de> for TrustedProxyCidr {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let value = String::deserialize(deserializer)?;
value.parse().map_err(serde::de::Error::custom)
}
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let value = String::deserialize(deserializer)?;
value.parse().map_err(serde::de::Error::custom)
}
}
fn mask_v4(prefix: u8) -> u32 {
if prefix == 0 { 0 } else { u32::MAX << (32 - prefix) }
if prefix == 0 { 0 } else { u32::MAX << (32 - prefix) }
}
fn mask_v6(prefix: u8) -> u128 {
if prefix == 0 { 0 } else { u128::MAX << (128 - prefix) }
if prefix == 0 { 0 } else { u128::MAX << (128 - prefix) }
}
#[derive(Debug, Clone, Deserialize)]
pub struct ProxyProtocolConfig {
#[serde(default)]
pub ingress_enabled: bool,
#[serde(default)]
pub trusted_cidrs: Vec<TrustedProxyCidr>,
#[serde(default = "default_proxy_protocol_timeout_ms")]
pub ingress_timeout_ms: u64,
#[serde(default = "default_proxy_protocol_max_header_bytes")]
pub max_header_bytes: usize,
#[serde(default)]
pub ingress_enabled: bool,
#[serde(default)]
pub trusted_cidrs: Vec<TrustedProxyCidr>,
#[serde(default = "default_proxy_protocol_timeout_ms")]
pub ingress_timeout_ms: u64,
#[serde(default = "default_proxy_protocol_max_header_bytes")]
pub max_header_bytes: usize,
}
impl Default for ProxyProtocolConfig {
fn default() -> Self {
Self {
ingress_enabled: false,
trusted_cidrs: Vec::new(),
ingress_timeout_ms: default_proxy_protocol_timeout_ms(),
max_header_bytes: default_proxy_protocol_max_header_bytes(),
}
}
fn default() -> Self {
Self {
ingress_enabled: false,
trusted_cidrs: Vec::new(),
ingress_timeout_ms: default_proxy_protocol_timeout_ms(),
max_header_bytes: default_proxy_protocol_max_header_bytes(),
}
}
}
fn default_proxy_protocol_timeout_ms() -> u64 {
750
750
}
fn default_proxy_protocol_max_header_bytes() -> usize {
512
512
}

View file

@ -12,6 +12,6 @@ pub use detect::MinecraftProtocolConfig;
pub use detect::ProtocolConfig;
pub use detect::{DetectAlertConfig, DetectAutobanConfig, DetectConfig, DetectPrefixConfig};
pub use edge::{
BackendConfig, BanConfig, BindConfig, LimitsConfig, PowConfig, ProxyProtocolConfig, TrustedProxyCidr, WorkerConfig,
BackendConfig, BanConfig, BindConfig, LimitsConfig, PowConfig, ProxyProtocolConfig, TrustedProxyCidr, WorkerConfig,
};
pub use platform::{LoggingConfig, MetricsConfig, StoreConfig, XdpConfig};

View file

@ -2,166 +2,166 @@ use serde::Deserialize;
#[derive(Debug, Clone, Deserialize)]
pub struct StoreConfig {
pub redis_url: Option<String>,
#[serde(default = "default_blacklist_cache_ttl")]
pub blacklist_cache_ttl_secs: u64,
pub clickhouse_url: Option<String>,
pub redis_url: Option<String>,
#[serde(default = "default_blacklist_cache_ttl")]
pub blacklist_cache_ttl_secs: u64,
pub clickhouse_url: Option<String>,
}
impl Default for StoreConfig {
fn default() -> Self {
Self {
redis_url: None,
blacklist_cache_ttl_secs: default_blacklist_cache_ttl(),
clickhouse_url: None,
}
}
fn default() -> Self {
Self {
redis_url: None,
blacklist_cache_ttl_secs: default_blacklist_cache_ttl(),
clickhouse_url: None,
}
}
}
fn default_blacklist_cache_ttl() -> u64 {
300
300
}
#[derive(Debug, Clone, Deserialize)]
pub struct XdpConfig {
#[serde(default)]
pub enabled: bool,
#[serde(default = "default_xdp_interface")]
pub interface: String,
#[serde(default = "default_xdp_port_start")]
pub protected_port_start: u16,
#[serde(default = "default_xdp_port_end")]
pub protected_port_end: u16,
/// "pass" | "drop" | "rate-limit" → G_UDP_POLICY.
#[serde(default = "default_xdp_udp_policy")]
pub udp_policy: String,
#[serde(default = "default_xdp_udp_hit_count")]
pub udp_rate_hit_count: u32,
#[serde(default = "default_xdp_udp_window_ms")]
pub udp_rate_window_ms: u64,
#[serde(default)]
pub syn_challenge_enabled: bool,
/// 128-битный hex (16 символов) для G_CHALLENGE_SECRET; None = плейсхолдер из config.h.
#[serde(default)]
pub challenge_secret_hex: Option<String>,
#[serde(default = "default_xdp_challenge_timeout_ms")]
pub challenge_timeout_ms: u32,
#[serde(default = "default_xdp_throttle_enabled")]
pub throttle_enabled: bool,
#[serde(default = "default_xdp_events_enabled")]
pub events_enabled: bool,
/// OPT-IN: авто-бан по ringbuf-событиям XDP. По умолчанию выключен
/// («по умолчанию безопасно»): без него события только логируются.
#[serde(default)]
pub auto_ban_enabled: bool,
/// Длительность авто-бана в секундах (для RATE_LIMIT/CONN_DROP).
#[serde(default = "default_xdp_auto_ban_duration_secs")]
pub auto_ban_duration_secs: u64,
/// Порог `conn->fails` для авто-бана по EVENT_CONN_DROP (см. universal_filter.c:368).
#[serde(default = "default_xdp_auto_ban_conn_drop_fails")]
pub auto_ban_conn_drop_fails: u8,
#[serde(default)]
pub enabled: bool,
#[serde(default = "default_xdp_interface")]
pub interface: String,
#[serde(default = "default_xdp_port_start")]
pub protected_port_start: u16,
#[serde(default = "default_xdp_port_end")]
pub protected_port_end: u16,
/// "pass" | "drop" | "rate-limit" → G_UDP_POLICY.
#[serde(default = "default_xdp_udp_policy")]
pub udp_policy: String,
#[serde(default = "default_xdp_udp_hit_count")]
pub udp_rate_hit_count: u32,
#[serde(default = "default_xdp_udp_window_ms")]
pub udp_rate_window_ms: u64,
#[serde(default)]
pub syn_challenge_enabled: bool,
/// 128-битный hex (16 символов) для G_CHALLENGE_SECRET; None = плейсхолдер из config.h.
#[serde(default)]
pub challenge_secret_hex: Option<String>,
#[serde(default = "default_xdp_challenge_timeout_ms")]
pub challenge_timeout_ms: u32,
#[serde(default = "default_xdp_throttle_enabled")]
pub throttle_enabled: bool,
#[serde(default = "default_xdp_events_enabled")]
pub events_enabled: bool,
/// OPT-IN: авто-бан по ringbuf-событиям XDP. По умолчанию выключен
/// («по умолчанию безопасно»): без него события только логируются.
#[serde(default)]
pub auto_ban_enabled: bool,
/// Длительность авто-бана в секундах (для RATE_LIMIT/CONN_DROP).
#[serde(default = "default_xdp_auto_ban_duration_secs")]
pub auto_ban_duration_secs: u64,
/// Порог `conn->fails` для авто-бана по EVENT_CONN_DROP (см. universal_filter.c:368).
#[serde(default = "default_xdp_auto_ban_conn_drop_fails")]
pub auto_ban_conn_drop_fails: u8,
}
impl Default for XdpConfig {
fn default() -> Self {
Self {
enabled: false,
interface: default_xdp_interface(),
protected_port_start: default_xdp_port_start(),
protected_port_end: default_xdp_port_end(),
udp_policy: default_xdp_udp_policy(),
udp_rate_hit_count: default_xdp_udp_hit_count(),
udp_rate_window_ms: default_xdp_udp_window_ms(),
syn_challenge_enabled: false,
challenge_secret_hex: None,
challenge_timeout_ms: default_xdp_challenge_timeout_ms(),
throttle_enabled: default_xdp_throttle_enabled(),
events_enabled: default_xdp_events_enabled(),
auto_ban_enabled: false,
auto_ban_duration_secs: default_xdp_auto_ban_duration_secs(),
auto_ban_conn_drop_fails: default_xdp_auto_ban_conn_drop_fails(),
}
}
fn default() -> Self {
Self {
enabled: false,
interface: default_xdp_interface(),
protected_port_start: default_xdp_port_start(),
protected_port_end: default_xdp_port_end(),
udp_policy: default_xdp_udp_policy(),
udp_rate_hit_count: default_xdp_udp_hit_count(),
udp_rate_window_ms: default_xdp_udp_window_ms(),
syn_challenge_enabled: false,
challenge_secret_hex: None,
challenge_timeout_ms: default_xdp_challenge_timeout_ms(),
throttle_enabled: default_xdp_throttle_enabled(),
events_enabled: default_xdp_events_enabled(),
auto_ban_enabled: false,
auto_ban_duration_secs: default_xdp_auto_ban_duration_secs(),
auto_ban_conn_drop_fails: default_xdp_auto_ban_conn_drop_fails(),
}
}
}
fn default_xdp_interface() -> String {
"eth0".to_string()
"eth0".to_string()
}
fn default_xdp_port_start() -> u16 {
1
1
}
fn default_xdp_port_end() -> u16 {
65535
65535
}
fn default_xdp_udp_policy() -> String {
"pass".to_string()
"pass".to_string()
}
fn default_xdp_udp_hit_count() -> u32 {
100
100
}
fn default_xdp_udp_window_ms() -> u64 {
1000
1000
}
fn default_xdp_challenge_timeout_ms() -> u32 {
3000
3000
}
fn default_xdp_throttle_enabled() -> bool {
true
true
}
fn default_xdp_events_enabled() -> bool {
true
true
}
fn default_xdp_auto_ban_duration_secs() -> u64 {
60
60
}
fn default_xdp_auto_ban_conn_drop_fails() -> u8 {
3
3
}
#[derive(Debug, Clone, Deserialize)]
pub struct LoggingConfig {
#[serde(default = "default_log_level")]
pub level: String,
#[serde(default = "default_log_format")]
pub format: String,
#[serde(default = "default_log_level")]
pub level: String,
#[serde(default = "default_log_format")]
pub format: String,
}
impl Default for LoggingConfig {
fn default() -> Self {
Self {
level: default_log_level(),
format: default_log_format(),
}
}
fn default() -> Self {
Self {
level: default_log_level(),
format: default_log_format(),
}
}
}
fn default_log_level() -> String {
"info".to_string()
"info".to_string()
}
fn default_log_format() -> String {
"text".to_string()
"text".to_string()
}
#[derive(Debug, Clone, Deserialize)]
pub struct MetricsConfig {
#[serde(default = "default_metrics_enabled")]
pub enabled: bool,
#[serde(default = "default_metrics_port")]
pub port: u16,
#[serde(default = "default_metrics_enabled")]
pub enabled: bool,
#[serde(default = "default_metrics_port")]
pub port: u16,
}
impl Default for MetricsConfig {
fn default() -> Self {
Self {
enabled: default_metrics_enabled(),
port: default_metrics_port(),
}
}
fn default() -> Self {
Self {
enabled: default_metrics_enabled(),
port: default_metrics_port(),
}
}
}
fn default_metrics_enabled() -> bool {
true
true
}
fn default_metrics_port() -> u16 {
9090
9090
}