From c8d0f3850f469312e9c5315c7c1f1c3925c76340 Mon Sep 17 00:00:00 2001 From: lubeilin <1791778603@qq.com> Date: Mon, 29 May 2023 22:49:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9ttl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- switch/src/handle/recv_handler.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/switch/src/handle/recv_handler.rs b/switch/src/handle/recv_handler.rs index d3aa721..8c5f8b3 100644 --- a/switch/src/handle/recv_handler.rs +++ b/switch/src/handle/recv_handler.rs @@ -121,7 +121,6 @@ impl RecvHandler { if net_packet.ttl() == 0 { return Ok(()); } - net_packet.set_ttl(net_packet.ttl() - 1); let source = net_packet.source(); let current_device = self.current_device.load(); if source == current_device.virtual_ip() { @@ -138,14 +137,15 @@ impl RecvHandler { log::warn!("转发数据,目的地址错误:{:?},当前网络:{:?},route_key:{:?}",destination,current_device.virtual_network,route_key); return Ok(()); } + net_packet.set_ttl(net_packet.ttl() - 1); let ttl = net_packet.ttl(); - if ttl > 1 { + if ttl > 0 { // 转发 if let Some(route) = self.channel.route(&destination) { if route.metric <= net_packet.ttl() { self.channel.send_to_route(net_packet.buffer(), &route.route_key())?; } - } else if (ttl > 2 || destination == current_device.virtual_gateway()) + } else if (ttl > 1 || destination == current_device.virtual_gateway()) && source != current_device.virtual_gateway() { //网关默认要转发一次,生存时间不够的发到网关也会被丢弃 self.channel.send_to_addr(net_packet.buffer(), current_device.connect_server)?;