mirror of
https://github.com/tun2proxy/tun2proxy.git
synced 2025-06-23 01:20:52 +00:00
Add auto setup method
This commit is contained in:
parent
d4127af422
commit
1a4a8c4c16
5 changed files with 205 additions and 1 deletions
21
src/main.rs
21
src/main.rs
|
@ -1,6 +1,8 @@
|
|||
use clap::Parser;
|
||||
use env_logger::Env;
|
||||
use std::process::exit;
|
||||
|
||||
use tun2proxy::setup::{get_default_cidrs, Setup};
|
||||
use tun2proxy::Options;
|
||||
use tun2proxy::{main_entry, Proxy};
|
||||
|
||||
|
@ -25,6 +27,10 @@ struct Args {
|
|||
default_value = "virtual"
|
||||
)]
|
||||
dns: ArgDns,
|
||||
|
||||
/// Setup
|
||||
#[arg(short, long, value_name = "method", value_enum)]
|
||||
setup: ArgSetup,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, clap::ValueEnum)]
|
||||
|
@ -33,6 +39,11 @@ enum ArgDns {
|
|||
None,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, clap::ValueEnum)]
|
||||
enum ArgSetup {
|
||||
Auto,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
dotenvy::dotenv().ok();
|
||||
env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();
|
||||
|
@ -47,7 +58,17 @@ fn main() {
|
|||
options = options.with_virtual_dns();
|
||||
}
|
||||
|
||||
let mut setup: Setup;
|
||||
if args.setup == ArgSetup::Auto {
|
||||
setup = Setup::new(&args.tun, &args.proxy.addr.ip(), get_default_cidrs());
|
||||
if let Err(e) = setup.setup() {
|
||||
log::error!("{e}");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if let Err(e) = main_entry(&args.tun, args.proxy, options) {
|
||||
log::error!("{e}");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue