mirror of
https://github.com/tun2proxy/tun2proxy.git
synced 2025-04-27 17:26:04 +00:00
Add file descriptor and MTU to CLI arguments
This commit is contained in:
parent
500f6ef21f
commit
fb3ad33b53
1 changed files with 16 additions and 1 deletions
17
src/main.rs
17
src/main.rs
|
@ -19,6 +19,14 @@ struct Args {
|
||||||
#[arg(short, long, value_name = "name", default_value = "tun0")]
|
#[arg(short, long, value_name = "name", default_value = "tun0")]
|
||||||
tun: String,
|
tun: String,
|
||||||
|
|
||||||
|
/// File descriptor of the tun interface
|
||||||
|
#[arg(long, value_name = "fd")]
|
||||||
|
tun_fd: Option<i32>,
|
||||||
|
|
||||||
|
/// MTU of the tun interface (only with tunnel file descriptor)
|
||||||
|
#[arg(long, value_name = "mtu", default_value = "1500")]
|
||||||
|
tun_mtu: usize,
|
||||||
|
|
||||||
/// Proxy URL in the form proto://[username[:password]@]host:port
|
/// Proxy URL in the form proto://[username[:password]@]host:port
|
||||||
#[arg(short, long, value_parser = Proxy::from_url, value_name = "URL")]
|
#[arg(short, long, value_parser = Proxy::from_url, value_name = "URL")]
|
||||||
proxy: Proxy,
|
proxy: Proxy,
|
||||||
|
@ -67,6 +75,14 @@ fn main() -> ExitCode {
|
||||||
options = options.with_virtual_dns();
|
options = options.with_virtual_dns();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let interface = match args.tun_fd {
|
||||||
|
None => NetworkInterface::Named(args.tun.clone()),
|
||||||
|
Some(fd) => {
|
||||||
|
options = options.with_mtu(args.tun_mtu);
|
||||||
|
NetworkInterface::Fd(fd)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if let Err(e) = (|| -> Result<(), Error> {
|
if let Err(e) = (|| -> Result<(), Error> {
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
{
|
{
|
||||||
|
@ -89,7 +105,6 @@ fn main() -> ExitCode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let interface = NetworkInterface::Named(args.tun);
|
|
||||||
main_entry(&interface, &args.proxy, options)?;
|
main_entry(&interface, &args.proxy, options)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Add table
Reference in a new issue