netget/server/socks5/filter.rs
1//! SOCKS5 filter configuration
2
3use super::AUTH_METHOD_NO_AUTH;
4use serde::{Deserialize, Serialize};
5
6/// Filter mode for SOCKS5 connections
7#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
8pub enum FilterMode {
9 /// Allow all connections without asking LLM
10 AllowAll,
11 /// Deny all connections
12 DenyAll,
13 /// Always ask LLM for every connection
14 AskLlm,
15 /// Only ask LLM when filter patterns match
16 Selective,
17}
18
19/// SOCKS5 proxy filter configuration
20#[derive(Debug, Clone, Serialize, Deserialize)]
21pub struct Socks5FilterConfig {
22 /// Supported authentication methods
23 /// 0x00 = No authentication
24 /// 0x02 = Username/Password
25 pub auth_methods: Vec<u8>,
26
27 /// Default action when no filter matches (for Selective mode)
28 /// "allow" or "deny"
29 pub default_action: String,
30
31 /// Filter mode
32 pub filter_mode: FilterMode,
33
34 /// Regex patterns for target hosts (domains or IPs)
35 /// If any pattern matches, filter is triggered
36 pub target_host_patterns: Vec<String>,
37
38 /// Port ranges to match [(start, end), ...]
39 /// If target port is in any range, filter is triggered
40 pub target_port_ranges: Vec<(u16, u16)>,
41
42 /// Username patterns (for authenticated connections)
43 pub username_patterns: Vec<String>,
44
45 /// Whether to enable MITM inspection by default
46 pub mitm_by_default: bool,
47}
48
49impl Default for Socks5FilterConfig {
50 fn default() -> Self {
51 Self {
52 auth_methods: vec![AUTH_METHOD_NO_AUTH],
53 default_action: "allow".to_string(),
54 filter_mode: FilterMode::Selective,
55 target_host_patterns: Vec::new(),
56 target_port_ranges: Vec::new(),
57 username_patterns: Vec::new(),
58 mitm_by_default: false,
59 }
60 }
61}