From 2fbdfe920e39f8de21347c601f61c7801846738f Mon Sep 17 00:00:00 2001 From: lbl8603 <49143209+lbl8603@users.noreply.github.com> Date: Thu, 8 Aug 2024 22:02:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=BB=91=E5=AE=9A=E7=BD=91?= =?UTF-8?q?=E5=8D=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnt/src/core/conn.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/vnt/src/core/conn.rs b/vnt/src/core/conn.rs index 5aa4755..7821c85 100644 --- a/vnt/src/core/conn.rs +++ b/vnt/src/core/conn.rs @@ -12,6 +12,7 @@ use crate::channel::context::ChannelContext; use crate::channel::idle::Idle; use crate::channel::punch::{NatInfo, Punch}; use crate::channel::sender::IpPacketSender; +use crate::channel::socket::LocalInterface; use crate::channel::{init_channel, init_context, Route, RouteKey}; use crate::cipher::Cipher; #[cfg(feature = "server_encrypt")] @@ -29,7 +30,7 @@ use crate::tun_tap_device::tun_create_helper::{DeviceAdapter, TunDeviceHelper}; use crate::tun_tap_device::vnt_device::DeviceWrite; use crate::util::limit::TrafficMeterMultiAddress; use crate::util::{Scheduler, StopManager}; -use crate::{nat, VntCallback}; +use crate::{channel, nat, VntCallback}; #[derive(Clone)] pub struct Vnt { @@ -137,9 +138,16 @@ impl VntInner { } else { nat::local_ipv4() }; - - let default_interface = config.local_interface.clone(); - log::info!("default_interface = {:?}", default_interface); + let default_interface = if config.in_ips.is_empty() { + //没有改变路由,不需要绑定网卡 + LocalInterface::default() + } else { + //vnt的流量都走这个接口 + let default_interface = + channel::socket::get_best_interface(local_ipv4.unwrap_or(Ipv4Addr::UNSPECIFIED))?; + log::info!("default_interface = {:?}", default_interface); + default_interface + }; //基础信息 let config_info = BaseConfigInfo::new(