diff --git a/clash_lib/src/session.rs b/clash_lib/src/session.rs index be5a17399..0ada4166e 100644 --- a/clash_lib/src/session.rs +++ b/clash_lib/src/session.rs @@ -1,5 +1,6 @@ use std::collections::HashMap; use std::fmt::{Debug, Display, Formatter}; +use std::sync::atomic::{AtomicBool, AtomicU32, Ordering}; use std::{ io, net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr}, @@ -375,8 +376,6 @@ pub struct Session { pub source: SocketAddr, /// The proxy target address of a proxy connection. pub destination: SocksAddr, - /// The packet mark SO_MARK - pub packet_mark: Option, /// The bind interface pub iface: Option, } @@ -409,7 +408,6 @@ impl Default for Session { typ: Type::Http, source: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 0), destination: SocksAddr::any_ipv4(), - packet_mark: None, iface: None, } } @@ -431,7 +429,6 @@ impl Debug for Session { .field("network", &self.network) .field("source", &self.source) .field("destination", &self.destination) - .field("packet_mark", &self.packet_mark) .field("iface", &self.iface) .finish() } @@ -444,7 +441,6 @@ impl Clone for Session { typ: self.typ, source: self.source, destination: self.destination.clone(), - packet_mark: self.packet_mark, iface: self.iface.as_ref().cloned(), } } @@ -461,3 +457,15 @@ fn invalid_atyp() -> io::Error { fn insuff_bytes() -> io::Error { io::Error::new(io::ErrorKind::Other, "insufficient bytes") } + + +static GLOBAL_MARK: AtomicU32 = AtomicU32::new(0); +static ENABLE_MARK: AtomicBool = AtomicBool::new(false); +/// get socket SO_MARK that outgoing socket should use +pub fn get_somark() -> Option { + if ENABLE_MARK.load(Ordering::Relaxed) { + Some(GLOBAL_MARK.load(Ordering::Relaxed)) + } else { + None + } +} \ No newline at end of file