Skip to content

Commit

Permalink
修改ttl
Browse files Browse the repository at this point in the history
  • Loading branch information
vnt-dev committed May 29, 2023
1 parent b846f54 commit c8d0f38
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions switch/src/handle/recv_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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)?;
Expand Down

0 comments on commit c8d0f38

Please sign in to comment.