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.
This commit is contained in:
parent
cb61a2eda0
commit
06d4e558cd
5 changed files with 36 additions and 2 deletions
|
|
@ -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(())
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
// Here we will recieve bytes and try to get their destanation & apply Rules for them.
|
||||
2
src/sniffing/mod.rs
Normal file
2
src/sniffing/mod.rs
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
pub mod headers;
|
||||
mod metadata;
|
||||
25
src/startup.rs
Normal file
25
src/startup.rs
Normal file
|
|
@ -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]);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue