v4 socket绑定网卡
This commit is contained in:
@@ -76,6 +76,7 @@ pub fn parse_args_config() -> anyhow::Result<Option<(Config, Vec<String>, bool)>
|
||||
opts.optmulti("", "vnt-mapping", "vnt-mapping", "<mapping>");
|
||||
opts.optopt("f", "", "配置文件", "<conf>");
|
||||
opts.optopt("", "compressor", "压缩算法", "<lz4>");
|
||||
opts.optopt("", "local-ipv4", "指定本地ipv4网卡IP", "<IP>");
|
||||
opts.optflag("", "disable-stats", "关闭流量统计");
|
||||
opts.optflag("", "allow-wg", "允许接入WireGuard");
|
||||
//"后台运行时,查看其他设备列表"
|
||||
@@ -283,6 +284,15 @@ pub fn parse_args_config() -> anyhow::Result<Option<(Config, Vec<String>, bool)>
|
||||
#[cfg(feature = "port_mapping")]
|
||||
let port_mapping_list = matches.opt_strs("mapping");
|
||||
let vnt_mapping_list = matches.opt_strs("vnt-mapping");
|
||||
let local_ipv4: Option<String> = matches.opt_get("local-ipv4").unwrap();
|
||||
let local_ipv4 = local_ipv4
|
||||
.map(|v| Ipv4Addr::from_str(&v).expect(&format!("'--local-ipv4 {}' error", v)));
|
||||
if let Some(local_ipv4) = local_ipv4 {
|
||||
if local_ipv4.is_unspecified() || local_ipv4.is_broadcast() || local_ipv4.is_multicast()
|
||||
{
|
||||
return Err(anyhow::anyhow!("'--local-ipv4 {}' invalid", local_ipv4));
|
||||
}
|
||||
}
|
||||
let disable_stats = matches.opt_present("disable-stats");
|
||||
let allow_wire_guard = matches.opt_present("allow-wg");
|
||||
let compressor = if let Some(compressor) = matches.opt_str("compressor").as_ref() {
|
||||
@@ -326,6 +336,7 @@ pub fn parse_args_config() -> anyhow::Result<Option<(Config, Vec<String>, bool)>
|
||||
compressor,
|
||||
!disable_stats,
|
||||
allow_wire_guard,
|
||||
local_ipv4,
|
||||
) {
|
||||
Ok(config) => config,
|
||||
Err(e) => {
|
||||
@@ -378,6 +389,7 @@ fn get_description(key: &str, language: &str) -> String {
|
||||
("--compressor-lz4 <lz4>", ("启用压缩,可选值lz4,例如 --compressor lz4", "Enable compression, option lz4, e.g., --compressor lz4")),
|
||||
("--compressor-zstd <zstd>", ("启用压缩,可选值zstd<,level>,level为压缩级别,例如 --compressor zstd,10", "Enable compression, options zstd<,level>, level is compression level, e.g., --compressor zstd,10")),
|
||||
("--vnt-mapping <x>", ("vnt地址映射,例如 --vnt-mapping tcp:80-10.26.0.10:80 映射目标是vnt网络或其子网中的设备", "VNT address mapping, e.g., --vnt-mapping tcp:80-10.26.0.10:80 maps to a device in VNT network or its subnet")),
|
||||
("--local-ipv4", ("本地出口网卡的ipv4地址", "IPv4 address of local export network card")),
|
||||
("--disable-stats", ("关闭流量统计", "Disable traffic statistics")),
|
||||
("--list", ("后台运行时,查看其他设备列表", "View list of other devices when running in background")),
|
||||
("--all", ("后台运行时,查看其他设备完整信息", "View complete information of other devices when running in background")),
|
||||
@@ -564,6 +576,10 @@ fn print_usage(program: &str, _opts: Options) {
|
||||
" --vnt-mapping <x> {}",
|
||||
green(get_description("--vnt-mapping <x>", &language).to_string())
|
||||
);
|
||||
println!(
|
||||
" --local-ipv4 <IP> {}",
|
||||
get_description("--local-ipv4", &language)
|
||||
);
|
||||
println!(
|
||||
" --disable-stats {}",
|
||||
get_description("--disable-stats", &language)
|
||||
|
||||
@@ -48,6 +48,7 @@ pub struct FileConfig {
|
||||
pub disable_stats: bool,
|
||||
// 允许传递wg流量
|
||||
pub allow_wire_guard: bool,
|
||||
pub local_ipv4: Option<Ipv4Addr>,
|
||||
}
|
||||
|
||||
impl Default for FileConfig {
|
||||
@@ -93,6 +94,7 @@ impl Default for FileConfig {
|
||||
vnt_mapping: vec![],
|
||||
disable_stats: false,
|
||||
allow_wire_guard: false,
|
||||
local_ipv4: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -181,6 +183,7 @@ pub fn read_config(file_path: &str) -> anyhow::Result<(Config, Vec<String>, bool
|
||||
compressor,
|
||||
!file_conf.disable_stats,
|
||||
file_conf.allow_wire_guard,
|
||||
file_conf.local_ipv4,
|
||||
)?;
|
||||
|
||||
Ok((config, file_conf.vnt_mapping, file_conf.cmd))
|
||||
|
||||
Reference in New Issue
Block a user