-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
iHsin
committed
Apr 13, 2024
1 parent
7b37493
commit 4468162
Showing
10 changed files
with
147 additions
and
19 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use crate::config::internal::config::TunConfig; | ||
|
||
#[cfg(target_os = "linux")] | ||
pub async fn setup(cfg: &mut TunConfig, tun_name: &str) -> anyhow::Result<()> { | ||
use cmd_lib::run_cmd; | ||
|
||
use crate::listen_shutdown; | ||
|
||
if !cfg.auto_route.unwrap_or(false) { | ||
return Ok(()); | ||
} | ||
let mark = cfg.mark.unwrap_or(6969); | ||
cfg.mark = Some(mark); | ||
let table = cfg.table.take().unwrap_or("2233".into()); | ||
cfg.table = Some(table.clone()); | ||
|
||
let ipv6 = false; // TODO read from conf | ||
// TODO chen perm | ||
run_cmd! { | ||
ip route add default dev $tun_name table $table; | ||
ip rule add ipproto icmp table main; | ||
ip rule add not fwmark $mark table $table; | ||
ip rule add table main suppress_prefixlength 0; | ||
}?; | ||
if ipv6 { | ||
run_cmd! { | ||
ip -6 route add default dev $tun_name table $table; | ||
ip -6 rule add ipproto icmp table main; | ||
ip -6 rule add not fwmark $mark table $table; | ||
ip -6 rule add table main suppress_prefixlength 0; | ||
}?; | ||
} | ||
tokio::spawn(async move { | ||
listen_shutdown().await.unwrap(); | ||
tracing::info!("cleaning routes"); | ||
run_cmd!{ | ||
ip rule del not from all fwmark $mark lookup $table; | ||
ip rule del from all lookup main suppress_prefixlength 0; | ||
ip rule del from all ipproto icmp lookup main; | ||
}.unwrap(); | ||
if ipv6 { | ||
run_cmd!{ | ||
ip -6 rule del not from all fwmark $mark lookup $table; | ||
ip -6 rule del from all lookup main suppress_prefixlength 0; | ||
ip -6 rule del from all ipproto icmp lookup main; | ||
}.unwrap(); | ||
} | ||
}); | ||
Ok(()) | ||
} | ||
|
||
#[cfg(not(target_os = "linux"))] | ||
pub fn setup(cfg: &mut TunConfig, tun_name: &str) -> anyhow::Result<()> { | ||
tracing::error!("Auto route not impl!"); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters