aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock11
-rw-r--r--Cargo.toml2
-rw-r--r--src/main.rs14
3 files changed, 24 insertions, 3 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 6458965..af8b714 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -613,15 +613,26 @@ dependencies = [
name = "rsdsl_dnsd"
version = "0.1.2"
dependencies = [
+ "byteorder",
"bytes",
"dns-message-parser",
"notify",
"rsdsl_dhcp4d",
+ "rsdsl_he_config",
"serde_json",
"thiserror",
]
[[package]]
+name = "rsdsl_he_config"
+version = "0.1.0"
+source = "git+https://github.com/rsdsl/he_config.git#602b64314e53db90923a32c93ebe95c12db69d4c"
+dependencies = [
+ "ipnet",
+ "serde",
+]
+
+[[package]]
name = "rsdsl_ip_config"
version = "0.1.0"
source = "git+https://github.com/rsdsl/ip_config.git#e13adb9cc9367ad93f1e947335b0d56108015999"
diff --git a/Cargo.toml b/Cargo.toml
index 2e1976e..bb9a877 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -6,9 +6,11 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
+byteorder = "1.4.3"
bytes = "1.4.0"
dns-message-parser = "0.7.0"
notify = "5.1.0"
rsdsl_dhcp4d = { git = "https://github.com/rsdsl/dhcp4d.git", version = "0.1.3" }
+rsdsl_he_config = { git = "https://github.com/rsdsl/he_config.git", version = "0.1.0" }
serde_json = "1.0"
thiserror = "1.0"
diff --git a/src/main.rs b/src/main.rs
index b9f449a..b899f3a 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -7,6 +7,7 @@ use std::sync::{Arc, RwLock};
use std::thread;
use std::time::{Duration, SystemTime};
+use byteorder::{ByteOrder, NetworkEndian as NE};
use bytes::Bytes;
use dns_message_parser::question::{QType, Question};
use dns_message_parser::rr::{A, RR};
@@ -14,6 +15,7 @@ use dns_message_parser::{Dns, Flags, Opcode, RCode};
use notify::event::{AccessKind, AccessMode, CreateKind};
use notify::{Event, EventKind, RecursiveMode, Watcher};
use rsdsl_dhcp4d::lease::Lease;
+use rsdsl_he_config::{Config, UsableConfig};
fn refresh_leases(cache: Arc<RwLock<Vec<Lease>>>) -> Result<()> {
let mut watcher = notify::recommended_watcher(move |res: notify::Result<Event>| match res {
@@ -84,6 +86,10 @@ fn read_leases(cache: Arc<RwLock<Vec<Lease>>>) -> Result<()> {
fn main() -> Result<()> {
println!("[dnsd] init");
+ let mut file = File::open("/data/he6in4.conf")?;
+ let he: Config = serde_json::from_reader(&mut file)?;
+ let he: UsableConfig = he.into();
+
let leases = Arc::new(RwLock::new(Vec::new()));
read_leases(leases.clone())?;
@@ -93,7 +99,7 @@ fn main() -> Result<()> {
Err(e) => println!("{}", e),
});
- let sock = UdpSocket::bind("0.0.0.0:53")?;
+ let sock = UdpSocket::bind("[::]:53")?;
loop {
let mut buf = [0; 1024];
@@ -102,7 +108,9 @@ fn main() -> Result<()> {
let is_local = match raddr.ip() {
IpAddr::V4(addr) => addr.is_private(),
- IpAddr::V6(_) => false, // no IPv6 support for now
+ IpAddr::V6(addr) => {
+ he.tn64.contains(&addr) || he.rt64.contains(&addr) || he.rt48.contains(&addr)
+ }
};
if !is_local {
@@ -281,6 +289,6 @@ fn is_dhcp_known(hostname: String, leases: Arc<RwLock<Vec<Lease>>>) -> Result<bo
fn subnet_id(addr: &IpAddr) -> u8 {
match addr {
IpAddr::V4(v4) => v4.octets()[2],
- IpAddr::V6(v6) => v6.octets()[7],
+ IpAddr::V6(v6) => NE::read_u16(&v6.octets()[6..8]) as u8,
}
}