This commit is contained in:
asxalex 2024-10-22 15:48:10 +08:00
parent 32bbdc4f78
commit 893eef5871

View File

@ -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);