Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,806 changes: 1,180 additions & 626 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
resolver = "2"
resolver = "3"
members = [
"dcompass",
"dmatcher",
Expand Down
2 changes: 1 addition & 1 deletion dcompass/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "dcompass"
version = "0.3.0-alpha.1"
authors = ["Harry Ying <lexugeyky@outlook.com>"]
edition = "2021"
edition = "2024"
description = "Rule-based high performance DNS server with multi-upstreams, DoT and DoH supports."
repository = "https://github.com/LEXUGE/dcompass"
license = "GPL-3.0"
Expand Down
2 changes: 1 addition & 1 deletion dmatcher/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "dmatcher"
version = "0.1.11"
authors = ["Harry Ying <lexugeyky@outlook.com>"]
edition = "2021"
edition = "2024"
description = "A simple domain matching algorithm, intended to be fast."
repository = "https://github.com/LEXUGE/dmatcher"
license = "GPL-3.0"
Expand Down
2 changes: 1 addition & 1 deletion droute/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "droute"
version = "0.3.0-alpha.1"
authors = ["Harry Ying <lexugeyky@outlook.com>"]
edition = "2021"
edition = "2024"
description = "Routing mechanism lib for dcompass the DNS server."
repository = "https://github.com/LEXUGE/dcompass"
license = "GPL-3.0"
Expand Down
6 changes: 3 additions & 3 deletions droute/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,20 @@ where
}
}

impl<A: Hash + ?Sized, B: Hash + ?Sized> Hash for (dyn KeyPair<A, B> + '_) {
impl<A: Hash + ?Sized, B: Hash + ?Sized> Hash for dyn KeyPair<A, B> + '_ {
fn hash<H: Hasher>(&self, state: &mut H) {
self.a().hash(state);
self.b().hash(state);
}
}

impl<A: Eq + ?Sized, B: Eq + ?Sized> PartialEq for (dyn KeyPair<A, B> + '_) {
impl<A: Eq + ?Sized, B: Eq + ?Sized> PartialEq for dyn KeyPair<A, B> + '_ {
fn eq(&self, other: &Self) -> bool {
self.a() == other.a() && self.b() == other.b()
}
}

impl<A: Eq + ?Sized, B: Eq + ?Sized> Eq for (dyn KeyPair<A, B> + '_) {}
impl<A: Eq + ?Sized, B: Eq + ?Sized> Eq for dyn KeyPair<A, B> + '_ {}

impl<A: ?Sized, B: ?Sized, C, D> KeyPair<A, B> for (C, D)
where
Expand Down
4 changes: 2 additions & 2 deletions droute/src/router/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ where
T: ScriptBackend,
{
/// Create a RouteBuilder
pub fn new(script: S, upstreams: U) -> Self {
pub const fn new(script: S, upstreams: U) -> Self {
Self {
script,
upstreams,
_phantom: PhantomData::default(),
_phantom: PhantomData,
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions droute/src/router/script/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ pub mod rune_scripting;
pub mod utils;

pub mod builders {
#[cfg(feature = "rhai-scripting")]
pub use super::rhai_scripting::{RhaiScript, RhaiScriptBuilder};
// #[cfg(feature = "rhai-scripting")]
// pub use super::rhai_scripting::{RhaiScript, RhaiScriptBuilder};

#[cfg(feature = "rune-scripting")]
pub use super::rune_scripting::{RuneScript, RuneScriptBuilder};
Expand Down
2 changes: 1 addition & 1 deletion droute/src/router/script/rune_scripting/basis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub static BASIS_MODULE: Lazy<Module> = Lazy::new(|| {
let mut m = Module::new();

// Workaround on https://github.com/rune-rs/rune/issues/399
m.function(&["u8"], |val: usize| val as u8).unwrap();
m.function(["u8"], |val: usize| val as u8).unwrap();

async fn send_default(
upstreams: &Upstreams,
Expand Down
12 changes: 6 additions & 6 deletions droute/src/router/script/rune_scripting/message/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ pub static MSG_MODULE: Lazy<Module> = Lazy::new(|| {
// Record and Option types
{
m.function(
&["DnsRecord", "new"],
["DnsRecord", "new"],
|owner: Dname, class: Class, ttl: u32, data: DnsRecordData| -> DnsRecord {
DnsRecord(domain::base::Record::new(owner.0, class.0, ttl, data.0))
},
Expand Down Expand Up @@ -536,7 +536,7 @@ pub static MSG_MODULE: Lazy<Module> = Lazy::new(|| {
m
);

m.function(&["A", "new"], |addr: IpAddr| -> Result<A, ScriptError> {
m.function(["A", "new"], |addr: IpAddr| -> Result<A, ScriptError> {
match addr.0 {
std::net::IpAddr::V4(addr) => Ok(domain::rdata::A::new(addr).into()),
_ => Err(MessageError::InvalidIpAddrType(addr.0).into()),
Expand Down Expand Up @@ -577,7 +577,7 @@ pub static MSG_MODULE: Lazy<Module> = Lazy::new(|| {
);

m.function(
&["Aaaa", "new"],
["Aaaa", "new"],
|addr: IpAddr| -> Result<Aaaa, ScriptError> {
match addr.0 {
std::net::IpAddr::V6(addr) => Ok(domain::rdata::Aaaa::new(addr).into()),
Expand Down Expand Up @@ -624,7 +624,7 @@ pub static MSG_MODULE: Lazy<Module> = Lazy::new(|| {
})
.unwrap();

m.function(&["Cname", "new"], |cname: Dname| -> Cname {
m.function(["Cname", "new"], |cname: Dname| -> Cname {
domain::rdata::Cname::new(cname.0).into()
})
.unwrap();
Expand Down Expand Up @@ -656,7 +656,7 @@ pub static MSG_MODULE: Lazy<Module> = Lazy::new(|| {
)
.unwrap();

m.function(&["Txt", "new"], |text: &str| -> Result<Txt, ScriptError> {
m.function(["Txt", "new"], |text: &str| -> Result<Txt, ScriptError> {
Ok(domain::rdata::Txt::from_slice(text.as_bytes())?.into())
})
.unwrap();
Expand Down Expand Up @@ -689,7 +689,7 @@ pub static MSG_MODULE: Lazy<Module> = Lazy::new(|| {
);

m.function(
&["ClientSubnet", "new"],
["ClientSubnet", "new"],
|source: u8, scope: u8, addr: IpAddr| -> ClientSubnet {
domain::base::opt::ClientSubnet::new(source, scope, addr.0).into()
},
Expand Down
8 changes: 4 additions & 4 deletions droute/src/router/script/rune_scripting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ impl ScriptBuilder<RuneScript> for RuneScriptBuilder {
let mut context = Context::with_default_modules()?;

// Types module should always install first.
context.install(&types::TYPES_MODULE)?;
context.install(&*types::TYPES_MODULE)?;

context.install(&message::MSG_MODULE)?;
context.install(&basis::BASIS_MODULE)?;
context.install(&utils::UTILS_MODULE)?;
context.install(&*message::MSG_MODULE)?;
context.install(&*basis::BASIS_MODULE)?;
context.install(&*utils::UTILS_MODULE)?;
let runtime = Arc::new(context.runtime());

let mut sources = Sources::new();
Expand Down
10 changes: 5 additions & 5 deletions droute/src/router/script/rune_scripting/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub static UTILS_MODULE: Lazy<Module> = Lazy::new(|| {
// Blackhole
{
m.function(
&["blackhole"],
["blackhole"],
|msg: &Message| -> Result<Message, ScriptError> { Ok(blackhole(&msg.into())?.into()) },
)
.unwrap();
Expand All @@ -60,7 +60,7 @@ pub static UTILS_MODULE: Lazy<Module> = Lazy::new(|| {
m.ty::<Domain>().unwrap();
m.ty::<SealedDomain>().unwrap();

m.function(&["Domain", "new"], Domain::new).unwrap();
m.function(["Domain", "new"], Domain::new).unwrap();
m.inst_fn(
"add_qname",
|mut domain: Domain, qname: &str| -> Result<Domain, ScriptError> {
Expand Down Expand Up @@ -95,7 +95,7 @@ pub static UTILS_MODULE: Lazy<Module> = Lazy::new(|| {
m.ty::<SealedGeoIp>().unwrap();

m.function(
&["GeoIp", "create_default"],
["GeoIp", "create_default"],
|| -> Result<SealedGeoIp, ScriptError> {
Ok(SealedGeoIp(Arc::new(GeoIp::create_default()?)))
},
Expand All @@ -106,7 +106,7 @@ pub static UTILS_MODULE: Lazy<Module> = Lazy::new(|| {
Ok(SealedGeoIp(Arc::new(GeoIp::from_path(path).await?)))
}

m.async_function(&["GeoIp", "from_path"], geoip_from_path)
m.async_function(["GeoIp", "from_path"], geoip_from_path)
.unwrap();

m.inst_fn(
Expand All @@ -123,7 +123,7 @@ pub static UTILS_MODULE: Lazy<Module> = Lazy::new(|| {
m.ty::<IpCidr>().unwrap();
m.ty::<SealedIpCidr>().unwrap();

m.function(&["IpCidr", "new"], IpCidr::new).unwrap();
m.function(["IpCidr", "new"], IpCidr::new).unwrap();
m.inst_fn(
"add_file",
|mut ipcidr: IpCidr, path: &str| -> Result<IpCidr, ScriptError> {
Expand Down
72 changes: 12 additions & 60 deletions droute/src/router/upstreams/upstream/qhandle/https.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,51 +13,6 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

#[cfg(feature = "doh-rustls")]
mod rustls_cfgs {
use once_cell::sync::Lazy;
use rustls::{ClientConfig, OwnedTrustAnchor, RootCertStore};

pub static NO_SNI_CLIENT_CFG: Lazy<ClientConfig> = Lazy::new(|| create_client_config(&false));
pub static CLIENT_CFG: Lazy<ClientConfig> = Lazy::new(|| create_client_config(&true));

fn create_client_config(sni: &bool) -> ClientConfig {
let mut root_store = RootCertStore::empty();
root_store.add_server_trust_anchors(webpki_roots::TLS_SERVER_ROOTS.0.iter().map(|ta| {
OwnedTrustAnchor::from_subject_spki_name_constraints(
ta.subject,
ta.spki,
ta.name_constraints,
)
}));

let mut client_config = ClientConfig::builder()
.with_safe_defaults()
.with_root_certificates(root_store)
.with_no_client_auth();

client_config.enable_sni = *sni; // Disable SNI on need.

client_config
}
}

#[cfg(feature = "doh-native-tls")]
mod native_tls_cfgs {
use native_tls::TlsConnector;
use once_cell::sync::Lazy;

pub static NO_SNI_CLIENT_CFG: Lazy<TlsConnector> =
Lazy::new(|| TlsConnector::builder().use_sni(false).build().unwrap());
pub static CLIENT_CFG: Lazy<TlsConnector> = Lazy::new(|| TlsConnector::new().unwrap());
}

#[cfg(feature = "doh-rustls")]
use rustls_cfgs::{CLIENT_CFG, NO_SNI_CLIENT_CFG};

#[cfg(feature = "doh-native-tls")]
use native_tls_cfgs::{CLIENT_CFG, NO_SNI_CLIENT_CFG};

use super::{ConnInitiator, QHandle, QHandleError, Result};
use async_trait::async_trait;
use bytes::{Bytes, BytesMut};
Expand Down Expand Up @@ -94,16 +49,21 @@ impl Https {
let client = Client::builder()
// The port in socket addr doesn't take effect here per documentation
.resolve(domain, SocketAddr::new(addr, 0))
.use_preconfigured_tls(if sni {
CLIENT_CFG.clone()
} else {
NO_SNI_CLIENT_CFG.clone()
})
.https_only(true)
.user_agent(APP_USER_AGENT)
.connect_timeout(Duration::from_secs(3))
// Disable the inner connection pool
.pool_max_idle_per_host(0);
.pool_max_idle_per_host(0)
.tls_sni(sni);

// Let reqwest initialize the TLS backend with the exact feature/version
// that reqwest itself was compiled with. Passing droute's own
// preconfigured rustls/native-tls connector into reqwest can fail because
// the connector type must match reqwest's internal TLS dependency.
#[cfg(feature = "doh-rustls")]
let client = client.use_rustls_tls();
#[cfg(feature = "doh-native-tls")]
let client = client.use_native_tls();

// Add proxy
let client = if let Some(proxy) = proxy {
Expand All @@ -113,15 +73,7 @@ impl Https {
};

Ok(Self {
client: PostClient(
client.build().map_err(|_| {
std::io::Error::new(
std::io::ErrorKind::Other,
"TLS backend failed to initialize",
)
})?,
uri.clone(),
),
client: PostClient(client.build()?, uri.clone()),
})
}
}
Expand Down