Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions examples/socks4_basic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
- address: 127.0.0.1:50000
protocol:
type: socks4
- address: 127.0.0.1:50001
protocol:
type: socks4
rules:
# allow connections to all ips
mask: 0.0.0.0/0
action: allow
client_chain:
address: 127.0.0.1:50000
protocol:
type: socks4
16 changes: 16 additions & 0 deletions src/config/types/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,10 @@ pub enum ClientProxyConfig {
#[serde(default, skip_serializing_if = "Option::is_none")]
password: Option<String>,
},
Socks4 {
#[serde(default, skip_serializing_if = "is_false")]
dns_enabled: bool,
},
#[serde(
alias = "ss",
deserialize_with = "deserialize_shadowsocks_client",
Expand Down Expand Up @@ -448,6 +452,7 @@ impl ClientProxyConfig {
ClientProxyConfig::Direct => "Direct",
ClientProxyConfig::Http { .. } => "HTTP",
ClientProxyConfig::Socks { .. } => "SOCKS5",
ClientProxyConfig::Socks4 { .. } => "SOCKS4",
ClientProxyConfig::Shadowsocks { .. } => "Shadowsocks",
ClientProxyConfig::Snell { .. } => "Snell",
ClientProxyConfig::Vless { .. } => "VLESS",
Expand Down Expand Up @@ -618,6 +623,17 @@ password: "pass"
assert!(matches!(result.unwrap(), ClientProxyConfig::Socks { .. }));
}

#[test]
fn test_client_proxy_config_socks4() {
let yaml = r#"
type: socks4
dns_enabled: true
"#;
let result: Result<ClientProxyConfig, _> = serde_yaml::from_str(yaml);
assert!(result.is_ok());
assert!(matches!(result.unwrap(), ClientProxyConfig::Socks4 { .. }));
}

#[test]
fn test_client_proxy_config_http() {
let yaml = r#"
Expand Down
33 changes: 33 additions & 0 deletions src/config/types/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,12 @@ pub enum ServerProxyConfig {
#[serde(default = "default_true")]
udp_enabled: bool,
},
Socks4 {
/// Enable DNS functionality (SOCKS4a).
/// When false, SOCKS4 returns "request rejected".
#[serde(default = "default_true")]
dns_enabled: bool,
},
#[serde(
alias = "ss",
deserialize_with = "deserialize_shadowsocks_server",
Expand Down Expand Up @@ -787,6 +793,7 @@ impl std::fmt::Display for ServerProxyConfig {
match self {
Self::Http { .. } => write!(f, "HTTP"),
Self::Socks { .. } => write!(f, "SOCKS"),
Self::Socks4 { .. } => write!(f, "SOCKS4"),
Self::Shadowsocks { .. } => write!(f, "Shadowsocks"),
Self::Snell { .. } => write!(f, "Snell"),
Self::Vless { .. } => write!(f, "Vless"),
Expand Down Expand Up @@ -872,6 +879,20 @@ mod tests {
}
}

fn create_test_server_config_socks4() -> ServerConfig {
ServerConfig {
bind_location: BindLocation::Address(
NetLocation::from_ip_addr(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 1080).into(),
),
protocol: ServerProxyConfig::Socks4 { dns_enabled: false },
transport: Transport::Tcp,
tcp_settings: None,
quic_settings: None,
rules: NoneOrSome::None,
dns: None,
}
}

fn create_test_server_config_shadowsocks() -> ServerConfig {
ServerConfig {
bind_location: BindLocation::Path(PathBuf::from("/tmp/ss.sock")),
Expand Down Expand Up @@ -1123,6 +1144,18 @@ mod tests {
));
}

#[test]
fn test_server_config_socks4() {
let original = create_test_server_config_socks4();
let yaml_str = serde_yaml::to_string(&original).expect("Failed to serialize");
let deserialized: ServerConfig =
serde_yaml::from_str(&yaml_str).expect("Failed to deserialize");
assert!(matches!(
deserialized.protocol,
ServerProxyConfig::Socks4 { .. }
));
}

#[test]
fn test_server_config_shadowsocks() {
let original = create_test_server_config_shadowsocks();
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ mod shadowsocks;
mod slide_buffer;
mod snell;
mod socket_util;
mod socks4_handler;
mod socks5_udp_relay;
mod socks_handler;
mod stream_reader;
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ mod shadowsocks;
mod slide_buffer;
mod snell;
mod socket_util;
mod socks4_handler;
mod socks5_udp_relay;
mod socks_handler;
mod stream_reader;
Expand Down
Loading