不转发来源和目的相同的数据

This commit is contained in:
lubeilin
2024-03-20 12:21:19 +08:00
parent 30b1e71aa1
commit 9badbe180c
+11 -1
View File
@@ -18,7 +18,7 @@ impl PacketHandler for TurnPacketHandler {
fn handle(
&self,
mut net_packet: NetPacket<&mut [u8]>,
_route_key: RouteKey,
route_key: RouteKey,
context: &Context,
_current_device: &CurrentDeviceInfo,
) -> std::io::Result<()> {
@@ -27,6 +27,16 @@ impl PacketHandler for TurnPacketHandler {
if ttl > 0 {
let destination = net_packet.destination();
if let Some(route) = context.route_table.route_one(&destination) {
if route.addr == route_key.addr {
//防止环路
log::warn!(
"来源和目标相同 {:?},{},{}",
route_key,
net_packet.source(),
net_packet.destination()
);
return Ok(());
}
if route.metric <= ttl {
context.send_by_key(net_packet.buffer(), route.route_key())?;
}