diff --git a/Cargo.lock b/Cargo.lock index 9d5ff0c..a883dfc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -75,12 +75,6 @@ dependencies = [ "windows-sys 0.59.0", ] -[[package]] -name = "autocfg" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" - [[package]] name = "backtrace" version = "0.3.71" @@ -102,12 +96,6 @@ version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" -[[package]] -name = "bytes" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "325918d6fe32f23b19878fe4b34794ae41fc19ddbe53b10571a4874d44ffd39b" - [[package]] name = "cc" version = "1.2.5" @@ -264,14 +252,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" [[package]] -name = "lock_api" -version = "0.4.12" +name = "log" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] name = "memchr" @@ -288,23 +272,22 @@ dependencies = [ "adler", ] -[[package]] -name = "mio" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2886843bf800fba2e3377cff24abf6379b4c4d5c6681eaf9ea5b0d15090450bd" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.52.0", -] - [[package]] name = "no-std-net" version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43794a0ace135be66a25d3ae77d41b91615fb68ae937f904090203e81f755b65" +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] + [[package]] name = "object" version = "0.32.2" @@ -320,35 +303,18 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + [[package]] name = "owo-colors" version = "3.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" -[[package]] -name = "parking_lot" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets", -] - [[package]] name = "pin-project-lite" version = "0.2.15" @@ -464,15 +430,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "redox_syscall" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" -dependencies = [ - "bitflags", -] - [[package]] name = "regex" version = "1.11.1" @@ -515,7 +472,7 @@ dependencies = [ "serde_regex", "simple-dns", "socket2", - "tokio", + "tracing-subscriber", ] [[package]] @@ -530,12 +487,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - [[package]] name = "serde" version = "1.0.217" @@ -593,15 +544,6 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" -[[package]] -name = "signal-hook-registry" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" -dependencies = [ - "libc", -] - [[package]] name = "simple-dns" version = "0.9.1" @@ -654,35 +596,6 @@ dependencies = [ "once_cell", ] -[[package]] -name = "tokio" -version = "1.42.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cec9b21b0450273377fc97bd4c33a8acffc8c996c987a7c5b319a0083707551" -dependencies = [ - "backtrace", - "bytes", - "libc", - "mio", - "parking_lot", - "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.52.0", -] - -[[package]] -name = "tokio-macros" -version = "2.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "tracing" version = "0.1.41" @@ -713,15 +626,29 @@ dependencies = [ "tracing-subscriber", ] +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + [[package]] name = "tracing-subscriber" version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8189decb5ac0fa7bc8b96b7cb9b2701d60d48805aca84a238004d665fcc4008" dependencies = [ + "nu-ansi-term", "sharded-slab", + "smallvec", "thread_local", "tracing-core", + "tracing-log", ] [[package]] @@ -742,12 +669,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - [[package]] name = "winapi" version = "0.3.9" diff --git a/Cargo.toml b/Cargo.toml index e15bdc5..739dea6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,4 +13,4 @@ serde_json = "1.0.134" serde_regex = "1.1.0" simple-dns = "0.9.1" socket2 = { version = "0.5.8", features = ["all"] } -tokio = { version = "1.42.0", features = ["full"] } +tracing-subscriber = "0.3.19" diff --git a/Readme.md b/Readme.md index bd7e91b..af9a0b7 100644 --- a/Readme.md +++ b/Readme.md @@ -11,8 +11,8 @@ and answers, with this you can decide what queries get relayed and which get blo `mdns-relay -c ` where config is a json file containing these options: ```json { - "interfaces: "A regex used to filter interfaces on which to listen, to exclude for example the public net or VPNs completely", - // A list of rules to be applied to incoming packages" + "interfaces": "A regex used to filter interfaces on which to listen, to exclude for example the public net or VPNs completely", + // A list of rules to be applied to incoming packages "rules" : [ { "from": "A regex to match the incoming interface", diff --git a/src/main.rs b/src/main.rs index e7294b0..0dff47e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,11 +10,11 @@ use simple_dns::Packet; use socket2::{Domain, Protocol, Socket, Type}; use std::fs::File; use std::io::BufReader; +use std::net::UdpSocket; use std::{ collections::HashSet, net::{Ipv4Addr, SocketAddr, SocketAddrV4}, }; -use tokio::net::UdpSocket; fn get_iface(from: &SocketAddr, ifaces: &Vec) -> Result { for i in ifaces { @@ -69,8 +69,7 @@ struct Config { rules: Vec, } -#[tokio::main] -async fn main() -> Result<()> { +fn main() -> Result<()> { let cli = Cli::parse(); let file = File::open(cli.config)?; let reader = BufReader::new(file); @@ -109,20 +108,19 @@ async fn main() -> Result<()> { }) }) .collect::>>()?; - //println!("{:?}", interfaces); - let mut buf = [0; 1024]; - let socket = UdpSocket::from_std(socket.into())?; + let mut buf = [0u8; 4096]; + let socket: UdpSocket = socket.into(); loop { - match socket.recv_from(&mut buf).await { - Ok((_l, from)) => { + match socket.recv_from(&mut buf) { + Ok((l, from)) => { + let buf = &buf[0..l]; if interfaces .iter() .any(|x| x.iface.ips.iter().any(|y| y.ip() == from.ip())) { continue; } - let packet = Packet::parse(&buf)?; - //println!("{:?} {:?}\n", from, packet); + let packet = Packet::parse(buf)?; let iface = match get_iface(&from, &interfaces) { Err(_) => { eprintln!("Invalid packet received from {}", from); @@ -151,7 +149,7 @@ async fn main() -> Result<()> { if out.contains(&i.iface.name) { println!("sending packet on {}", i.iface.name); let sock_addr = SocketAddrV4::new(ADDR, 5353).into(); - i.socket.send_to(&buf, &sock_addr)?; + i.socket.send_to(buf, &sock_addr)?; } } // socket.send_to(&buf, addr);