From c5f5ea433a4e9ada3eedbac0571719a73f32a065 Mon Sep 17 00:00:00 2001 From: alex Date: Wed, 15 Apr 2026 11:37:10 +0800 Subject: [PATCH] linux's dns hook is ok --- src/bin/punchnet/main.rs | 8 ++++++-- src/network/tun_linux.rs | 9 +++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/bin/punchnet/main.rs b/src/bin/punchnet/main.rs index ad51d1d..00b7a9d 100755 --- a/src/bin/punchnet/main.rs +++ b/src/bin/punchnet/main.rs @@ -35,6 +35,7 @@ use sdlan_sn_rs::utils::Mac; use sdlan_sn_rs::utils::Result; use sdlan_sn_rs::utils::create_or_load_uuid; use tokio::runtime::Runtime; +use tracing::debug; use tracing::error; use std::net::ToSocketAddrs; @@ -248,13 +249,14 @@ async fn daemonize_me( let mut started = true; */ - + println!("waiting for ctrl-c"); match tokio::signal::ctrl_c().await { Ok(()) => { edge.quic_endpoint.close(0u32.into(), "bye".as_bytes()); println!("quic is quitting"); delete_pid_file(); let _ = restore_dns(); + debug!("restored dns"); } Err(err) => { eprintln!("failed to listen for shutdown signal: {}", err); @@ -360,7 +362,9 @@ fn main() { } }; let result = unsafe { - kill(pid, SIGTERM) + use libc::SIGINT; + + kill(pid, SIGINT) }; if result != 0 { let err = io::Error::last_os_error(); diff --git a/src/network/tun_linux.rs b/src/network/tun_linux.rs index 7bac715..255cc75 100755 --- a/src/network/tun_linux.rs +++ b/src/network/tun_linux.rs @@ -858,6 +858,7 @@ pub fn get_install_channel() -> String { } fn check_has_resolvectl() -> bool { + return false; let res = Command::new("resolvectl") .arg("status") .output(); @@ -947,10 +948,15 @@ pub fn modify_resolv_conf(new_nameservers: &[String], search_domain: &str, keep_ let reader = BufReader::new(file); let mut lines = Vec::new(); + for ns in new_nameservers { + lines.push(format!("nameserver {}", ns)) + } + /* let mut inserted = false; let mut encounted_nameserver = false; let mut search_added = false; + for line in reader.lines() { let line = line?; let trimmed = line.trim(); @@ -982,6 +988,7 @@ pub fn modify_resolv_conf(new_nameservers: &[String], search_domain: &str, keep_ if !search_added { lines.push(format!("search {}", search_domain)); } + */ // 原子写入:先写临时文件 let tmp_dir = Path::new("/etc"); @@ -992,6 +999,8 @@ pub fn modify_resolv_conf(new_nameservers: &[String], search_domain: &str, keep_ } tmp_file.flush()?; + debug!("added to /etc/resolve.conf: {:?}", lines); + // 设置权限 fs::set_permissions(&tmp_path, perms)?; #[cfg(unix)]