runtime fixes and multicast ignore

This commit is contained in:
2026-03-19 14:59:29 +07:00
parent 29ff686341
commit 5f9cf382ea
2 changed files with 22 additions and 23 deletions
+10 -18
View File
@@ -7,18 +7,14 @@ pub mod mobile;
use crate::{ use crate::{
RUNTIME, Session, RUNTIME, Session,
connections::dns::DnsHandler, connections::dns::DnsHandler,
tun::{ tun::{engine::Engine, routing::setup_platform_routing, tun::Tun},
engine::Engine,
routing::{reset_platform_routing, setup_platform_routing},
tun::Tun,
},
}; };
use netrunner_core::proxy::{connection::connection::ConnectionRole, network::Network}; use netrunner_core::proxy::{connection::connection::ConnectionRole, network::Network};
use netrunner_logger::{error, info}; use netrunner_logger::{error, info};
use smoltcp::{iface::Config, phy::DeviceCapabilities}; use smoltcp::{iface::Config, phy::DeviceCapabilities};
use std::net::Ipv4Addr; use std::net::Ipv4Addr;
use std::sync::Arc; use std::sync::Arc;
use tokio::{runtime::Runtime, signal}; use tokio::runtime::Runtime;
use tokio_util::sync::CancellationToken; use tokio_util::sync::CancellationToken;
fn get_runtime() -> &'static Runtime { fn get_runtime() -> &'static Runtime {
@@ -91,7 +87,7 @@ impl SessionManager {
.tun_name("netr0") .tun_name("netr0")
.address((10, 0, 0, 1)) .address((10, 0, 0, 1))
.netmask((255, 255, 255, 0)) .netmask((255, 255, 255, 0))
.mtu(1200) .mtu(1280)
.up(); .up();
}) })
.expect("Failed to init TUN") .expect("Failed to init TUN")
@@ -105,7 +101,7 @@ impl SessionManager {
} }
}; };
setup_platform_routing(&remote_address); let _ = setup_platform_routing(&remote_address);
let config = Config::new(smoltcp::wire::HardwareAddress::Ip); let config = Config::new(smoltcp::wire::HardwareAddress::Ip);
let mut caps = DeviceCapabilities::default(); let mut caps = DeviceCapabilities::default();
@@ -131,26 +127,22 @@ impl SessionManager {
engine.activate(); engine.activate();
let cancel_token_for_engine = cancel_token.clone(); let cancel_token_for_engine = cancel_token.clone();
std::thread::spawn(move || {
info!("Dedicated OS thread started for Engine");
let rt = tokio::runtime::Builder::new_current_thread() tokio::spawn(async move {
.enable_all() info!("Engine async task started");
.build()
.unwrap();
rt.block_on(async {
tokio::select! { tokio::select! {
// Добавляем обработку результата прямо здесь
res = engine.run(tun_device) => { res = engine.run(tun_device) => {
error!("Engine loop error: {:?}", res); // Теперь эта ветка возвращает (), так как мы обработали результат
info!("Engine loop finished: {:?}", res);
}, },
_ = cancel_token_for_engine.cancelled() => { _ = cancel_token_for_engine.cancelled() => {
info!("Engine thread shutting down via token"); info!("Engine task shutting down via token");
} }
} }
}); });
}); });
});
Arc::new(Session { Arc::new(Session {
cancel_token: sesison_token, cancel_token: sesison_token,
+7
View File
@@ -120,6 +120,13 @@ impl Engine {
break; break;
} }
if n >= 20 && buf[0] >> 4 == 4 {
let dest_ip = &buf[16..20];
if dest_ip[0] >= 224 && dest_ip[0] <= 239 {
continue;
}
}
let mut token = TokenBuffer::with_capacity(n); let mut token = TokenBuffer::with_capacity(n);
token.extend_from_slice(&buf[..n]); token.extend_from_slice(&buf[..n]);