From 9e881eeecd8ddfe30bdc0613f7ce59cd4ebbbc04 Mon Sep 17 00:00:00 2001 From: lubeilin <1791778603@qq.com> Date: Sat, 29 Jul 2023 21:31:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0-o=E9=BB=98=E8=AE=A4ip?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/src/args_parse.rs | 7 +++++-- vnt-cli/README.md | 2 ++ vnt-cli/src/main.rs | 4 ++-- vnt/src/core/mod.rs | 5 ++++- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/common/src/args_parse.rs b/common/src/args_parse.rs index 6155cea..81af384 100644 --- a/common/src/args_parse.rs +++ b/common/src/args_parse.rs @@ -1,6 +1,6 @@ use std::net::Ipv4Addr; -pub fn ips_parse(ips: &Vec) -> Result, String> { +pub fn ips_parse(ips: &Vec,in_ip:bool) -> Result, String> { let mut in_ips_c = vec![]; for x in ips { let mut split = x.split(","); @@ -12,7 +12,10 @@ pub fn ips_parse(ips: &Vec) -> Result, String> let ip = if let Some(ip) = split.next() { ip } else { - return Err("ipv4/mask,ipv4".to_string()); + if in_ip{ + return Err("ipv4/mask,ipv4".to_string()); + } + "0.0.0.0" }; let ip = if let Ok(ip) = ip.parse::() { ip diff --git a/vnt-cli/README.md b/vnt-cli/README.md index e8c75ed..bcaa416 100644 --- a/vnt-cli/README.md +++ b/vnt-cli/README.md @@ -23,6 +23,8 @@ 在B配置 **-o 192.168.0.0/24,192.168.0.10** ,表示允许将192.168.0.0/24的数据从网卡192.168.0.10转发出去 +注:-o 可以不配置出口ip,如直接使用 **-o 192.168.0.0/24** , 这将使用默认ip转发 + ### -w `` 提升通信安全性,使用该密码生成的密钥对客户端数据进行加密,并且服务端无法解密。使用相同密码的客户端才能通信 diff --git a/vnt-cli/src/main.rs b/vnt-cli/src/main.rs index ba046e0..20ed551 100644 --- a/vnt-cli/src/main.rs +++ b/vnt-cli/src/main.rs @@ -140,7 +140,7 @@ async fn main0() { .collect::>(); let in_ip = matches.opt_strs("i"); - let in_ip = match ips_parse(&in_ip) { + let in_ip = match ips_parse(&in_ip, true) { Ok(in_ip) => { in_ip } Err(e) => { print_usage(&program, opts); @@ -150,7 +150,7 @@ async fn main0() { } }; let out_ip = matches.opt_strs("o"); - let out_ip = match ips_parse(&out_ip) { + let out_ip = match ips_parse(&out_ip, false) { Ok(out_ip) => { out_ip } Err(e) => { print_usage(&program, opts); diff --git a/vnt/src/core/mod.rs b/vnt/src/core/mod.rs index d789be7..1936891 100644 --- a/vnt/src/core/mod.rs +++ b/vnt/src/core/mod.rs @@ -184,7 +184,10 @@ impl VntUtil { // NAT检测 let nat_test = NatTest::new(config.nat_test_server.clone(), response.public_ip, response.public_port, local_ip, local_port); - let out_ips = config.out_ips.iter().map(|(_, _, ip)| *ip).collect::>(); + let mut out_ips = config.out_ips.iter().map(|(_, _, ip)| *ip).collect::>(); + if out_ips.remove(&Ipv4Addr::UNSPECIFIED) { + out_ips.insert(local_ip); + } let out_external_route = ExternalRoute::new(config.out_ips); let in_external_route = if config.in_ips.is_empty() { None