diff options
| author | zedddie <rust@zedddie.rs> | 2026-03-15 14:59:11 +0100 |
|---|---|---|
| committer | tuturuu <zedddiezxc@gmail.com> | 2026-03-15 14:59:11 +0100 |
| commit | 06d4e558cdf97b64e4cbc95becf1b25c1c24950e (patch) | |
| tree | 885b243d572a31d15e9007b05aa310f27307bc11 | |
| parent | cb61a2eda096bd9900878034c77145baf1fbf416 (diff) | |
sniffing early work
use `tun` crate examope for starters, to map all traffic through tun
virtual interface, in next commits will push these packets to sniffing
module which will deciede further modifications of proxies based by
user's Config.
| -rw-r--r-- | src/geoparsers/geoip2.rs | 2 | ||||
| -rw-r--r-- | src/main.rs | 8 | ||||
| -rw-r--r-- | src/sniffing/headers.rs | 1 | ||||
| -rw-r--r-- | src/sniffing/mod.rs | 2 | ||||
| -rw-r--r-- | src/startup.rs | 25 |
5 files changed, 36 insertions, 2 deletions
diff --git a/src/geoparsers/geoip2.rs b/src/geoparsers/geoip2.rs index af5d03e..9323280 100644 --- a/src/geoparsers/geoip2.rs +++ b/src/geoparsers/geoip2.rs @@ -33,7 +33,7 @@ pub struct Rule { pub action: RouteAction, } -pub fn parse_ruleset(config: NSCConfig) -> Result<Rules, Box<dyn std::error::Error>> { +pub fn parse_ruleset(config: Config) -> Result<Rules, Box<dyn std::error::Error>> { let reader = maxminddb::Reader::open_readfile(config.geo_files[0].clone())?; // Ok(()) diff --git a/src/main.rs b/src/main.rs index 438b85e..958e39d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,12 @@ mod config; mod geoparsers; +mod sniffing; +mod startup; + +use startup::init; + +use std::io::Read; fn main() { - println!("Hello, world!"); + init(); } diff --git a/src/sniffing/headers.rs b/src/sniffing/headers.rs index e69de29..836cf32 100644 --- a/src/sniffing/headers.rs +++ b/src/sniffing/headers.rs @@ -0,0 +1 @@ +// Here we will recieve bytes and try to get their destanation & apply Rules for them. diff --git a/src/sniffing/mod.rs b/src/sniffing/mod.rs new file mode 100644 index 0000000..dec0be3 --- /dev/null +++ b/src/sniffing/mod.rs @@ -0,0 +1,2 @@ +pub mod headers; +mod metadata; diff --git a/src/startup.rs b/src/startup.rs new file mode 100644 index 0000000..32ed278 --- /dev/null +++ b/src/startup.rs @@ -0,0 +1,25 @@ +// Here we iniitialize systems crucial for nsc +use std::io::Read; + +pub fn init() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> { + let mut config = tun::Configuration::default(); + config + .address((10, 0, 0, 9)) + .netmask((255, 255, 255, 0)) + .destination((10, 0, 0, 1)) + .up(); + + #[cfg(target_os = "linux")] + config.platform_config(|config| { + // requiring root privilege to acquire complete functions + config.ensure_root_privileges(true); + }); + + let mut dev = tun::create(&config)?; + let mut buf = [0; 4096]; + + loop { + let amount = dev.read(&mut buf)?; + println!("{:?}", &buf[0..amount]); + } +} |
