From 893eef5871ad3b78be58ed77e8283f75015e5eb6 Mon Sep 17 00:00:00 2001 From: asxalex Date: Tue, 22 Oct 2024 15:48:10 +0800 Subject: [PATCH] packet --- src/network/packet.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/network/packet.rs b/src/network/packet.rs index cc4ca3e..8f4c555 100644 --- a/src/network/packet.rs +++ b/src/network/packet.rs @@ -100,6 +100,7 @@ pub async fn handle_packet(eee: &Node, addr: SocketAddr, buf: &[u8]) -> Result<( }; match pkt_type { PacketType::Data => { + debug!("got data"); let from_sock = get_sdlan_sock_from_socketaddr(addr).unwrap(); debug!("[PPP]Rx data from {}", from_sock.to_string()); if !eee.is_authorized() { @@ -131,6 +132,7 @@ pub async fn handle_packet(eee: &Node, addr: SocketAddr, buf: &[u8]) -> Result<( handle_tun_packet(eee, &from_sock, !data.is_p2p, data).await; } PacketType::StunProbeReply => { + debug!("got StunProbeReply"); let Ok(reply) = SdlStunProbeReply::decode(&buf[1..]) else { error!("failed to decode SdlStunReply"); return Ok(()); @@ -138,9 +140,11 @@ pub async fn handle_packet(eee: &Node, addr: SocketAddr, buf: &[u8]) -> Result<( eee.send_nat_probe_reply(reply.cookie, reply).await; } PacketType::StunReply => { + debug!("got stun reply"); // stun reply, like pong } PacketType::Register => { + debug!("got Register"); if !eee.is_authorized() { error!("dropping REGISTER received before authorized"); return Ok(()); @@ -149,6 +153,7 @@ pub async fn handle_packet(eee: &Node, addr: SocketAddr, buf: &[u8]) -> Result<( let _ = handle_packet_register(eee, &buf[1..], false, &from_sock).await; } PacketType::RegisterACK => { + debug!("got RegisterACK"); if !eee.is_authorized() { error!("dropping REGISTER received before authorized"); return Ok(()); @@ -763,10 +768,15 @@ async fn handle_tun_packet( Ok((hdr, rest)) => { let edge = get_edge(); let self_mac = edge.device_config.get_mac(); + /* if hdr.destination != self_mac && hdr.destination != BROADCAST_MAC { - error!("packet not direct to us"); + error!( + "packet to [{:?}] not direct to us", + mac_to_string(&hdr.destination) + ); return; } + */ if hdr.ether_type == ARP { let mut arp = ArpHdr::from_slice(&data);