增加参数关闭ip代理
This commit is contained in:
@@ -85,8 +85,8 @@ features说明
|
|||||||
| server_encrypt | 支持服务端加密 | 是 |
|
| server_encrypt | 支持服务端加密 | 是 |
|
||||||
| ip_proxy | 内置ip代理 | 是 |
|
| ip_proxy | 内置ip代理 | 是 |
|
||||||
|
|
||||||
如果编译时去除了内置的ip代理,则可以使用nat转发来实现点对网
|
如果编译时去除了内置的ip代理(或使用--no-proxy关闭了代理),则可以使用网卡NAT转发来实现点对网,
|
||||||
|
一般来说使用网卡NAT转发会比内置的ip代理性能更好
|
||||||
<details> <summary>NAT配置可参考如下示例,点击展开</summary>
|
<details> <summary>NAT配置可参考如下示例,点击展开</summary>
|
||||||
|
|
||||||
### 在出口一端做如下配置
|
### 在出口一端做如下配置
|
||||||
|
|||||||
@@ -80,6 +80,11 @@
|
|||||||
取值ipv4/ipv6,选择只使用ipv4打洞或者只使用ipv6打洞,默认两则都会使用
|
取值ipv4/ipv6,选择只使用ipv4打洞或者只使用ipv6打洞,默认两则都会使用
|
||||||
### --port `<port>`
|
### --port `<port>`
|
||||||
取值0~65535,指定本地监听的端口,默认取随机端口
|
取值0~65535,指定本地监听的端口,默认取随机端口
|
||||||
|
### --cmd
|
||||||
|
开启交互式命令,开启后可以直接在窗口下输入命令,如需后台运行请勿开启
|
||||||
|
### --no-proxy
|
||||||
|
关闭内置的ip代理,内置的代理较为简单,而且一般来说直接使用网卡NAT转发性能会更高,
|
||||||
|
有需要可以自行配置NAT转发,[可参考‘编译’小节中的NAT配置](https://github.com/lbl8603/vnt#%E7%BC%96%E8%AF%91)
|
||||||
### -f `<conf>`
|
### -f `<conf>`
|
||||||
指定配置文件
|
指定配置文件
|
||||||
配置文件采用yaml格式,可参考:
|
配置文件采用yaml格式,可参考:
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ pub struct FileConfig {
|
|||||||
pub tcp: bool,
|
pub tcp: bool,
|
||||||
pub ip: Option<String>,
|
pub ip: Option<String>,
|
||||||
pub relay: bool,
|
pub relay: bool,
|
||||||
|
pub no_proxy: bool,
|
||||||
pub server_encrypt: bool,
|
pub server_encrypt: bool,
|
||||||
pub parallel: usize,
|
pub parallel: usize,
|
||||||
pub cipher_model: String,
|
pub cipher_model: String,
|
||||||
@@ -55,6 +56,7 @@ impl Default for FileConfig {
|
|||||||
tcp: false,
|
tcp: false,
|
||||||
ip: None,
|
ip: None,
|
||||||
relay: false,
|
relay: false,
|
||||||
|
no_proxy: false,
|
||||||
server_encrypt: false,
|
server_encrypt: false,
|
||||||
parallel: 1,
|
parallel: 1,
|
||||||
cipher_model: "aes_gcm".to_string(),
|
cipher_model: "aes_gcm".to_string(),
|
||||||
@@ -145,6 +147,8 @@ pub fn read_config(file_path: &str) -> io::Result<(Config, bool)> {
|
|||||||
file_conf.tcp,
|
file_conf.tcp,
|
||||||
virtual_ip,
|
virtual_ip,
|
||||||
file_conf.relay,
|
file_conf.relay,
|
||||||
|
#[cfg(feature = "ip_proxy")]
|
||||||
|
file_conf.no_proxy,
|
||||||
file_conf.server_encrypt,
|
file_conf.server_encrypt,
|
||||||
file_conf.parallel,
|
file_conf.parallel,
|
||||||
cipher_model,
|
cipher_model,
|
||||||
|
|||||||
+10
-1
@@ -58,6 +58,7 @@ fn main() {
|
|||||||
opts.optopt("", "punch", "取值ipv4/ipv6", "<punch>");
|
opts.optopt("", "punch", "取值ipv4/ipv6", "<punch>");
|
||||||
opts.optopt("", "port", "监听的端口", "<port>");
|
opts.optopt("", "port", "监听的端口", "<port>");
|
||||||
opts.optflag("", "cmd", "开启窗口输入");
|
opts.optflag("", "cmd", "开启窗口输入");
|
||||||
|
opts.optflag("", "no-proxy", "关闭内置代理");
|
||||||
opts.optopt("f", "", "配置文件", "<conf>");
|
opts.optopt("f", "", "配置文件", "<conf>");
|
||||||
//"后台运行时,查看其他设备列表"
|
//"后台运行时,查看其他设备列表"
|
||||||
opts.optflag("", "list", "后台运行时,查看其他设备列表");
|
opts.optflag("", "list", "后台运行时,查看其他设备列表");
|
||||||
@@ -258,6 +259,8 @@ fn main() {
|
|||||||
.unwrap_or(PunchModel::All);
|
.unwrap_or(PunchModel::All);
|
||||||
let port = matches.opt_get::<u16>("port").unwrap_or(None).unwrap_or(0);
|
let port = matches.opt_get::<u16>("port").unwrap_or(None).unwrap_or(0);
|
||||||
let cmd = matches.opt_present("cmd");
|
let cmd = matches.opt_present("cmd");
|
||||||
|
#[cfg(feature = "ip_proxy")]
|
||||||
|
let no_proxy = matches.opt_present("no-proxy");
|
||||||
let config = Config::new(
|
let config = Config::new(
|
||||||
tap,
|
tap,
|
||||||
token,
|
token,
|
||||||
@@ -274,6 +277,8 @@ fn main() {
|
|||||||
tcp_channel,
|
tcp_channel,
|
||||||
virtual_ip,
|
virtual_ip,
|
||||||
relay,
|
relay,
|
||||||
|
#[cfg(feature = "ip_proxy")]
|
||||||
|
no_proxy,
|
||||||
server_encrypt,
|
server_encrypt,
|
||||||
parallel,
|
parallel,
|
||||||
cipher_model,
|
cipher_model,
|
||||||
@@ -528,10 +533,14 @@ fn print_usage(program: &str, _opts: Options) {
|
|||||||
&enums[1..]
|
&enums[1..]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
println!(" --finger 增加数据指纹校验,可增加安全性,如果服务端开启指纹校验,则客户端也必须开启");
|
if !enums.is_empty() {
|
||||||
|
println!(" --finger 增加数据指纹校验,可增加安全性,如果服务端开启指纹校验,则客户端也必须开启");
|
||||||
|
}
|
||||||
println!(" --punch <punch> 取值ipv4/ipv6,ipv4表示仅使用ipv4打洞");
|
println!(" --punch <punch> 取值ipv4/ipv6,ipv4表示仅使用ipv4打洞");
|
||||||
println!(" --port <port> 取值0~65535,指定本地监听的端口,默认取随机端口");
|
println!(" --port <port> 取值0~65535,指定本地监听的端口,默认取随机端口");
|
||||||
println!(" --cmd 开启交互式命令,使用此参数开启控制台输入");
|
println!(" --cmd 开启交互式命令,使用此参数开启控制台输入");
|
||||||
|
#[cfg(feature = "ip_proxy")]
|
||||||
|
println!(" --no-proxy 关闭内置代理,如需点对网则需要配置网卡NAT转发");
|
||||||
|
|
||||||
println!();
|
println!();
|
||||||
println!(
|
println!(
|
||||||
|
|||||||
@@ -146,6 +146,7 @@ fn new_sync(env: &mut JNIEnv, config: JObject) -> Result<VntUtilSync, Error> {
|
|||||||
None,
|
None,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
|
false,
|
||||||
1,
|
1,
|
||||||
cipher_model,
|
cipher_model,
|
||||||
finger,
|
finger,
|
||||||
|
|||||||
+1
-1
@@ -44,7 +44,7 @@ protobuf-codegen = "3.2.0"
|
|||||||
protoc-bin-vendored = "3.0.0"
|
protoc-bin-vendored = "3.0.0"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["server_encrypt","aes_gcm","aes_cbc","aes_ecb","sm4_cbc"]
|
default = ["server_encrypt","aes_gcm","aes_cbc","aes_ecb","sm4_cbc","ip_proxy"]
|
||||||
openssl = ["openssl-sys"]
|
openssl = ["openssl-sys"]
|
||||||
# 从源码编译
|
# 从源码编译
|
||||||
openssl-vendored = ["openssl-sys/vendored"]
|
openssl-vendored = ["openssl-sys/vendored"]
|
||||||
|
|||||||
+6
-1
@@ -302,7 +302,7 @@ impl VntUtil {
|
|||||||
Some(ExternalRoute::new(config.in_ips))
|
Some(ExternalRoute::new(config.in_ips))
|
||||||
};
|
};
|
||||||
#[cfg(feature = "ip_proxy")]
|
#[cfg(feature = "ip_proxy")]
|
||||||
let (tcp_proxy, udp_proxy, ip_proxy_map) = if config.out_ips.is_empty() {
|
let (tcp_proxy, udp_proxy, ip_proxy_map) = if config.out_ips.is_empty() || config.no_proxy {
|
||||||
(None, None, None)
|
(None, None, None)
|
||||||
} else {
|
} else {
|
||||||
let (tcp_proxy, udp_proxy, ip_proxy_map) = crate::ip_proxy::init_proxy(
|
let (tcp_proxy, udp_proxy, ip_proxy_map) = crate::ip_proxy::init_proxy(
|
||||||
@@ -582,6 +582,8 @@ pub struct Config {
|
|||||||
pub tcp: bool,
|
pub tcp: bool,
|
||||||
pub ip: Option<Ipv4Addr>,
|
pub ip: Option<Ipv4Addr>,
|
||||||
pub relay: bool,
|
pub relay: bool,
|
||||||
|
#[cfg(feature = "ip_proxy")]
|
||||||
|
pub no_proxy: bool,
|
||||||
pub server_encrypt: bool,
|
pub server_encrypt: bool,
|
||||||
pub parallel: usize,
|
pub parallel: usize,
|
||||||
pub cipher_model: CipherModel,
|
pub cipher_model: CipherModel,
|
||||||
@@ -607,6 +609,7 @@ impl Config {
|
|||||||
tcp: bool,
|
tcp: bool,
|
||||||
ip: Option<Ipv4Addr>,
|
ip: Option<Ipv4Addr>,
|
||||||
relay: bool,
|
relay: bool,
|
||||||
|
#[cfg(feature = "ip_proxy")] no_proxy: bool,
|
||||||
server_encrypt: bool,
|
server_encrypt: bool,
|
||||||
parallel: usize,
|
parallel: usize,
|
||||||
cipher_model: CipherModel,
|
cipher_model: CipherModel,
|
||||||
@@ -635,6 +638,8 @@ impl Config {
|
|||||||
tcp,
|
tcp,
|
||||||
ip,
|
ip,
|
||||||
relay,
|
relay,
|
||||||
|
#[cfg(feature = "ip_proxy")]
|
||||||
|
no_proxy,
|
||||||
server_encrypt,
|
server_encrypt,
|
||||||
parallel,
|
parallel,
|
||||||
cipher_model,
|
cipher_model,
|
||||||
|
|||||||
@@ -233,57 +233,9 @@ impl ChannelDataHandler {
|
|||||||
if self.out_external_route.allow(&ipv4.destination_ip()) {
|
if self.out_external_route.allow(&ipv4.destination_ip()) {
|
||||||
#[cfg(feature = "ip_proxy")]
|
#[cfg(feature = "ip_proxy")]
|
||||||
if let Some(ip_proxy_map) = &self.ip_proxy_map {
|
if let Some(ip_proxy_map) = &self.ip_proxy_map {
|
||||||
match ipv4.protocol() {
|
if ip_proxy_map.recv_handle(&mut ipv4, source, destination)? {
|
||||||
ipv4::protocol::Protocol::Tcp => {
|
return Ok(());
|
||||||
if ip_proxy_map.tcp_handler.recv_handle(
|
|
||||||
&mut ipv4,
|
|
||||||
source,
|
|
||||||
destination,
|
|
||||||
)? {
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ipv4::protocol::Protocol::Udp => {
|
|
||||||
if ip_proxy_map.udp_handler.recv_handle(
|
|
||||||
&mut ipv4,
|
|
||||||
source,
|
|
||||||
destination,
|
|
||||||
)? {
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[cfg(not(target_os = "android"))]
|
|
||||||
ipv4::protocol::Protocol::Icmp => {
|
|
||||||
if ip_proxy_map.icmp_handler.recv_handle(
|
|
||||||
&mut ipv4,
|
|
||||||
source,
|
|
||||||
destination,
|
|
||||||
)? {
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
log::warn!(
|
|
||||||
"不支持的ip代理ipv4协议{:?}:{}->{}->{}",
|
|
||||||
ipv4.protocol(),
|
|
||||||
source,
|
|
||||||
destination,
|
|
||||||
ipv4.destination_ip()
|
|
||||||
);
|
|
||||||
return Err(Error::Warn(
|
|
||||||
"不支持的ip代理ipv4协议".to_string(),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
log::warn!(
|
|
||||||
"不支持ip代理{:?}:{}->{}->{}",
|
|
||||||
ipv4.protocol(),
|
|
||||||
source,
|
|
||||||
destination,
|
|
||||||
ipv4.destination_ip()
|
|
||||||
);
|
|
||||||
return Err(Error::Warn("不支持ip代理".to_string()));
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log::warn!(
|
log::warn!(
|
||||||
|
|||||||
@@ -188,17 +188,8 @@ pub fn base_handle(
|
|||||||
}
|
}
|
||||||
#[cfg(feature = "ip_proxy")]
|
#[cfg(feature = "ip_proxy")]
|
||||||
if let Some(proxy_map) = proxy_map {
|
if let Some(proxy_map) = proxy_map {
|
||||||
match protocol {
|
let mut ipv4_packet = IpV4Packet::new(net_packet.payload_mut())?;
|
||||||
Protocol::Tcp => {
|
proxy_map.send_handle(&mut ipv4_packet)?;
|
||||||
let mut ipv4_packet = IpV4Packet::new(net_packet.payload_mut())?;
|
|
||||||
proxy_map.tcp_handler.send_handle(&mut ipv4_packet)?;
|
|
||||||
}
|
|
||||||
Protocol::Udp => {
|
|
||||||
let mut ipv4_packet = IpV4Packet::new(net_packet.payload_mut())?;
|
|
||||||
proxy_map.udp_handler.send_handle(&mut ipv4_packet)?;
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
client_cipher.encrypt_ipv4(&mut net_packet)?;
|
client_cipher.encrypt_ipv4(&mut net_packet)?;
|
||||||
//优先发到直连到地址
|
//优先发到直连到地址
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ use std::{io, thread};
|
|||||||
|
|
||||||
use crossbeam_utils::atomic::AtomicCell;
|
use crossbeam_utils::atomic::AtomicCell;
|
||||||
use dashmap::DashMap;
|
use dashmap::DashMap;
|
||||||
|
use packet::ip::ipv4;
|
||||||
use tokio::net::UdpSocket;
|
use tokio::net::UdpSocket;
|
||||||
|
|
||||||
use packet::ip::ipv4::packet::IpV4Packet;
|
use packet::ip::ipv4::packet::IpV4Packet;
|
||||||
@@ -173,3 +174,43 @@ pub fn send(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ProxyHandler for IpProxyMap {
|
||||||
|
fn recv_handle(
|
||||||
|
&self,
|
||||||
|
ipv4: &mut IpV4Packet<&mut [u8]>,
|
||||||
|
source: Ipv4Addr,
|
||||||
|
destination: Ipv4Addr,
|
||||||
|
) -> io::Result<bool> {
|
||||||
|
match ipv4.protocol() {
|
||||||
|
ipv4::protocol::Protocol::Tcp => {
|
||||||
|
self.tcp_handler.recv_handle(ipv4, source, destination)
|
||||||
|
}
|
||||||
|
ipv4::protocol::Protocol::Udp => {
|
||||||
|
self.udp_handler.recv_handle(ipv4, source, destination)
|
||||||
|
}
|
||||||
|
#[cfg(not(target_os = "android"))]
|
||||||
|
ipv4::protocol::Protocol::Icmp => {
|
||||||
|
self.icmp_handler.recv_handle(ipv4, source, destination)
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
log::warn!(
|
||||||
|
"不支持的ip代理ipv4协议{:?}:{}->{}->{}",
|
||||||
|
ipv4.protocol(),
|
||||||
|
source,
|
||||||
|
destination,
|
||||||
|
ipv4.destination_ip()
|
||||||
|
);
|
||||||
|
Ok(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn send_handle(&self, ipv4: &mut IpV4Packet<&mut [u8]>) -> io::Result<()> {
|
||||||
|
match ipv4.protocol() {
|
||||||
|
ipv4::protocol::Protocol::Tcp => self.tcp_handler.send_handle(ipv4),
|
||||||
|
ipv4::protocol::Protocol::Udp => self.udp_handler.send_handle(ipv4),
|
||||||
|
_ => Ok(()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user