fix windows's read tun, fill first 14 bytes with 0's

This commit is contained in:
alex 2026-04-13 19:32:39 +08:00
parent 97a7403015
commit 150d1c8e67
4 changed files with 9 additions and 19 deletions

View File

@ -1,4 +1,4 @@
{ {
"rust-analyzer.cargo.target": "x86_64-pc-windows-gnu", // "rust-analyzer.cargo.target": "x86_64-pc-windows-gnu",
// "rust-analyzer.cargo.features": ["tun"] // "rust-analyzer.cargo.features": ["tun"]
} }

View File

@ -30,6 +30,9 @@ use sdlan_sn_rs::{
utils::{create_or_load_uuid, get_sdlan_sock_from_socketaddr, Result, SDLanError}, utils::{create_or_load_uuid, get_sdlan_sock_from_socketaddr, Result, SDLanError},
}; };
#[cfg(all(feature = "tun", target_os = "windows"))]
compile_error!("tun feature is not supported on windows");
#[derive(Clone)] #[derive(Clone)]
pub enum ConnectionInfo { pub enum ConnectionInfo {

View File

@ -255,7 +255,7 @@ async fn loop_tap(eee: &'static Node, cancel: CancellationToken) {
error!("loop_tap exited"); error!("loop_tap exited");
} }
#[cfg(feature = "tun")] #[cfg(any(feature = "tun", target_os = "windows"))]
fn get_data_from_tun_with_layer2_zeroed(eee: &Node) -> BytesMut { fn get_data_from_tun_with_layer2_zeroed(eee: &Node) -> BytesMut {
let mut temp = BytesMut::zeroed(1514); let mut temp = BytesMut::zeroed(1514);
// let mut temp = BytesMut::with_capacity(1514); // let mut temp = BytesMut::with_capacity(1514);
@ -282,9 +282,9 @@ fn get_data_from_tap_with_layer2(eee: &Node) -> BytesMut {
async fn get_tun_flow(eee: &'static Node, tx: Sender<BytesMut>) { async fn get_tun_flow(eee: &'static Node, tx: Sender<BytesMut>) {
loop { loop {
let buf = tokio::task::spawn_blocking(|| { let buf = tokio::task::spawn_blocking(|| {
#[cfg(feature = "tun")] #[cfg(any(feature = "tun", target_os = "windows"))]
let data = get_data_from_tun_with_layer2_zeroed(eee); let data = get_data_from_tun_with_layer2_zeroed(eee);
#[cfg(not(feature = "tun"))] #[cfg(all(not(feature = "tun"), not(target_os="windows")))]
let data = get_data_from_tap_with_layer2(eee); let data = get_data_from_tap_with_layer2(eee);
data data

View File

@ -328,7 +328,7 @@ impl TunTapPacketHandler for Iface {
if u32::from_be_bytes(ipv4.destination) == DNS_IP { if u32::from_be_bytes(ipv4.destination) == DNS_IP {
// should send to dns // should send to dns
parse_dns_payload(edge, &headers.payload); parse_dns_payload(edge, &headers.payload.slice());
if let Err(e) = edge.udp_sock_for_dns.send_to(&data[14..], format!("{}:15353", edge.server_ip)).await { if let Err(e) = edge.udp_sock_for_dns.send_to(&data[14..], format!("{}:15353", edge.server_ip)).await {
error!("failed to send request to 15353: {}", e); error!("failed to send request to 15353: {}", e);
} }
@ -1029,18 +1029,5 @@ pub async fn arp_reply_arrived(edge: &Node, data: SdlArpResponse) {
} }
} }
/*
fn parse_dns_payload(edge: &Node, payload: &[u8]) { fn parse_dns_payload(edge: &Node, payload: &[u8]) {
match dns_parse::parse(Bytes::from(payload)) {
Ok(packet) => {
packet[0].
if let Some(questions) = packet.questions.first() {
debug!("got dns query for {:?}", questions.qname);
} }
}
Err(e) => {
error!("failed to parse dns packet: {}", e.to_string());
}
}
}
*/