diff --git a/Cargo.toml b/Cargo.toml index cd5f4ae..4843ec7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,27 +10,23 @@ build = "build.rs" prost-build = "0.14.3" [dependencies] -arti-client = "0.40.0" hickory-resolver = { version = "0.26.3", features = ["dnssec-ring", "https-ring", "quic-ring", "serde", "tls-ring", "toml"] } -ipnet = "2.12.0" iptables = "0.6.0" maxminddb = "0.27.3" memmap2 = "0.9.10" prost = "0.14.3" prost-types = "0.14.3" rand = "0.10.3" -regex = "1.13.1" rtnetlink = "0.20.0" serde = { version = "1.0.228", features = ["derive"] } smoltcp = "0.14.0" tokio = { version = "1.50.0", features = ["full"] } toml = { version = "1.0.6", features = ["serde"] } -trie = "0.3.0" tun = { version = "0.8.6", features = ["async", "tokio"] } [profile.release] strip = true -lto = true +lto = false codegen-units = 1 opt-level = 3 diff --git a/src/config.rs b/src/config.rs index a5739ec..468a925 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,10 +1,25 @@ use serde::{Deserialize, Serialize}; -#[derive(Deserialize, Serialize, Default)] -pub enum RunTypes { - #[default] - Tor, - I2P, +#[derive(Deserialize, Serialize)] +pub enum KillSwitchPolicy { + #[serde(alias = "allow-proxy")] + AllowProxies, + #[serde(alias = "full")] + Strict, +} + +#[derive(Deserialize, Serialize)] +pub enum ClearnetPolicy { + #[serde(alias = "killswitched")] + Killwitched, + #[serde(alias = "allowed")] + Allowed, +} + +#[derive(Deserialize, Serialize)] +pub struct Policy { + pub clearnet: Option, + pub killswitch_mode: Option, } #[derive(Serialize, Deserialize)] @@ -13,8 +28,8 @@ pub struct Config { pub geo_files: [String; 2], /// Routing settings similar to v2ray pub routing: String, - /// TOR/I2P Proxies - pub mode: RunTypes, + /// Clearnet routing policies + pub policy: Option, } // TODO: Think how to add other anonymisers @@ -26,16 +41,20 @@ pub struct Config { // addr = "127.0.0.1:10808" // type = "SOCKS5" # ... // ``` +// impl Default for Config { fn default() -> Self { Self { geo_files: [ - String::from("/etc/nsc/data/geolite2.mmdb"), - String::from("/etc/nsc/data/geosite.dat"), + String::from("/var/nsc/geodata/geolite2.mmdb"), + String::from("/var/nsc/geodata/geosite.dat"), ], routing: String::from("/etc/nsc/routing.toml"), - mode: RunTypes::Tor, + policy: Some(Policy { + clearnet: Some(ClearnetPolicy::Allowed), + killswitch_mode: Some(KillSwitchPolicy::AllowProxies), + }), } } } diff --git a/src/geoparsers/geoip2.rs b/src/geoparsers/geoip2.rs index 75ab15a..0258b1f 100644 --- a/src/geoparsers/geoip2.rs +++ b/src/geoparsers/geoip2.rs @@ -4,7 +4,7 @@ use serde::Deserialize; use std::net::IpAddr; // For now only MMDB because i cant found .proto schemes of -// V2Ray GeoSite.dat :(( +// V2Ray GeoSite.dat/GeoIP.dat :(( // TODO: V2Ray protobuf parsing && Test 4 ts /// Interface enum for `dst_addr` info diff --git a/src/geoparsers/v2ray/types.rs b/src/geoparsers/v2ray/types.rs index b82fbbf..d7c0436 100644 --- a/src/geoparsers/v2ray/types.rs +++ b/src/geoparsers/v2ray/types.rs @@ -33,7 +33,17 @@ pub mod domain { } } /// Type of domain value. - #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] + #[derive( + Clone, + Copy, + Debug, + PartialEq, + Eq, + Hash, + PartialOrd, + Ord, + ::prost::Enumeration + )] #[repr(i32)] pub enum Type { /// The value is used as is. diff --git a/src/sniffing/dns/dnsfaker.rs b/src/sniffing/dns/dnsfaker.rs index 0f27a95..53f7c94 100644 --- a/src/sniffing/dns/dnsfaker.rs +++ b/src/sniffing/dns/dnsfaker.rs @@ -42,7 +42,7 @@ pub trait FakeIPOptions { ip_type: IPStrategies, ) -> Result; async fn init_resolver(&mut self, link: String) -> Result<(), std::io::Error>; - fn get(&self, domain: &str) -> Result; + fn get(&self, domain: &str) -> Option; } fn generate_ip_from(network: Ipv4Addr, prefix: u32) -> Ipv4Addr { @@ -62,17 +62,15 @@ impl FakeIPOptions for FakeIPServer { /// Just gets an FakeIP addr from FakeIPStorage. /// ```rust /// x = FakeIPServer::new(/* params */); - /// x.add("nosystemd.org") // returns IpAddr, but if it dropped you can call - /// x.get("nosystemd.org").unwrap() // -> IpAddr + /// x.add("nosystemd.org"); // returns IpAddr, but if it dropped you can call + /// let addr = x.get("nosystemd.org"); // -> Option + /// if addr.is_some() { + /// println("{}", addr.unwrap()); // -> IpAddr + /// } /// ``` - fn get(&self, domain: &str) -> Result { - self.entries.get(domain).copied().ok_or_else(|| { - std::io::Error::new( - std::io::ErrorKind::NotFound, - format!("No FakeIP entry found for domain: {domain}"), - ) - }) - } + fn get(&self, domain: &str) -> Option { + self.entries.get(domain).copied() + } /// FakeIPServer function which init's integrated DNS resolver for /// ```rust diff --git a/src/startup.rs b/src/startup.rs index 3a1a09a..d8c7f93 100644 --- a/src/startup.rs +++ b/src/startup.rs @@ -1,6 +1,6 @@ // Here we iniitialize systems crucial for nsc -use crate::sniffing::headers::Protocol; use crate::sniffing::headers::sniff_raw_packets; +use crate::sniffing::types::*; use std::io::Read; pub fn init() -> Result<(), Box> { let mut config = tun::Configuration::default();