refactor(fakedns): FakeIPServer.get(domain) now returns Option<IpAddr>; cleaned unused deps
This commit is contained in:
parent
7954859517
commit
bb417b8a6d
6 changed files with 52 additions and 29 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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<ClearnetPolicy>,
|
||||
pub killswitch_mode: Option<KillSwitchPolicy>,
|
||||
}
|
||||
|
||||
#[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<Policy>,
|
||||
}
|
||||
|
||||
// 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),
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ pub trait FakeIPOptions {
|
|||
ip_type: IPStrategies,
|
||||
) -> Result<IpAddr, std::io::Error>;
|
||||
async fn init_resolver(&mut self, link: String) -> Result<(), std::io::Error>;
|
||||
fn get(&self, domain: &str) -> Result<IpAddr, std::io::Error>;
|
||||
fn get(&self, domain: &str) -> Option<IpAddr>;
|
||||
}
|
||||
|
||||
fn generate_ip_from(network: Ipv4Addr, prefix: u32) -> Ipv4Addr {
|
||||
|
|
@ -62,16 +62,14 @@ 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<IpAddr>
|
||||
/// if addr.is_some() {
|
||||
/// println("{}", addr.unwrap()); // -> IpAddr
|
||||
/// }
|
||||
/// ```
|
||||
fn get(&self, domain: &str) -> Result<IpAddr, std::io::Error> {
|
||||
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<IpAddr> {
|
||||
self.entries.get(domain).copied()
|
||||
}
|
||||
|
||||
/// FakeIPServer function which init's integrated DNS resolver for
|
||||
|
|
|
|||
|
|
@ -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<dyn std::error::Error + Send + Sync + 'static>> {
|
||||
let mut config = tun::Configuration::default();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue