Skip to content

Commit

Permalink
g3proxy: enable hickory feature
Browse files Browse the repository at this point in the history
  • Loading branch information
zh-jq-b committed Mar 13, 2024
1 parent a720db5 commit 2d0d660
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 7 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion g3proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ tokio-util = { workspace = true, features = ["io"] }
rustc_version.workspace = true

[features]
default = ["lua54", "python", "c-ares", "geoip"]
default = ["lua54", "python", "c-ares", "hickory", "geoip"]
lua = ["mlua"]
luajit = ["lua", "mlua/luajit"]
lua51 = ["lua", "mlua/lua51"]
Expand Down
4 changes: 4 additions & 0 deletions g3proxy/src/config/resolver/hickory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ impl HickoryResolverConfig {
self.driver.get_server_port()
}

pub(crate) fn get_encryption_summary(&self) -> Option<String> {
self.driver.get_encryption().map(|c| c.summary())
}

pub(crate) fn parse(
map: &yaml::Hash,
position: Option<YamlDocPosition>,
Expand Down
3 changes: 2 additions & 1 deletion lib/g3-resolver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ c-ares-resolver = { workspace = true, optional = true }
c-ares-sys = { workspace = true, optional = true } # for DEP_ version check
hickory-client = { workspace = true, optional = true }
hickory-proto = { workspace = true, optional = true, features = ["tokio-runtime"] }
rustls = { workspace = true, optional = true }
rustls-pki-types = { workspace = true, optional = true }
flume = { workspace = true, optional = true, features = ["async"] }
async-recursion = { workspace = true, optional = true }
Expand All @@ -30,5 +31,5 @@ g3-hickory-client = { workspace = true, optional = true }
default = []
c-ares = ["dep:c-ares", "dep:c-ares-resolver", "dep:c-ares-sys"]
vendored-c-ares = ["c-ares", "c-ares-resolver/vendored", "c-ares/vendored"]
hickory = ["dep:hickory-client", "dep:hickory-proto", "dep:flume", "dep:rustls-pki-types", "dep:async-recursion", "dep:g3-hickory-client", "g3-types/rustls"]
hickory = ["dep:hickory-client", "dep:hickory-proto", "dep:flume", "dep:rustls", "dep:rustls-pki-types", "dep:async-recursion", "dep:g3-hickory-client", "g3-types/rustls"]
quic = ["g3-types?/quic", "g3-hickory-client?/quic"]
11 changes: 6 additions & 5 deletions lib/g3-resolver/src/driver/hickory/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ use async_recursion::async_recursion;
use hickory_client::client::{AsyncClient, ClientHandle};
use hickory_proto::iocompat::AsyncIoTokioAsStd;
use hickory_proto::rr::{DNSClass, Name, RData, RecordType};
use rustls::{ClientConfig, ServerName};
use rustls::ClientConfig;
use rustls_pki_types::ServerName;
use tokio::net::{TcpStream, UdpSocket};
use tokio::sync::mpsc;

Expand Down Expand Up @@ -307,7 +308,7 @@ impl HickoryClientConfig {
async fn new_dns_over_tls_client(
&self,
tls_client: ClientConfig,
tls_name: ServerName,
tls_name: ServerName<'static>,
) -> anyhow::Result<AsyncClient> {
use hickory_proto::BufDnsStreamHandle;

Expand Down Expand Up @@ -337,7 +338,7 @@ impl HickoryClientConfig {
async fn new_dns_over_h2_client(
&self,
tls_client: ClientConfig,
tls_name: ServerName,
tls_name: ServerName<'static>,
) -> anyhow::Result<AsyncClient> {
let client_connect = g3_hickory_client::io::h2::connect(
self.target,
Expand All @@ -359,7 +360,7 @@ impl HickoryClientConfig {
async fn new_dns_over_quic_client(
&self,
tls_client: ClientConfig,
tls_name: &ServerName,
tls_name: &ServerName<'static>,
) -> anyhow::Result<AsyncClient> {
let tls_name = match tls_name {
ServerName::DnsName(domain) => domain.as_ref().to_string(),
Expand Down Expand Up @@ -387,7 +388,7 @@ impl HickoryClientConfig {
async fn new_dns_over_h3_client(
&self,
tls_client: ClientConfig,
tls_name: &ServerName,
tls_name: &ServerName<'static>,
) -> anyhow::Result<AsyncClient> {
let tls_name = match tls_name {
ServerName::DnsName(domain) => domain.as_ref().to_string(),
Expand Down
14 changes: 14 additions & 0 deletions lib/g3-types/src/net/dns/encryption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,20 @@ impl DnsEncryptionConfigBuilder {
self.tls_config = config_builder;
}

pub fn summary(&self) -> String {
match &self.tls_name {
ServerName::DnsName(n) => format!("{}({})", self.protocol.as_str(), n.as_ref()),
ServerName::IpAddress(ip) => {
format!(
"{}({})",
self.protocol.as_str(),
std::net::IpAddr::from(*ip)
)
}
_ => format!("{}(other)", self.protocol.as_str()), // FIXME support other server name variants
}
}

pub fn build_tls_client_config(&self) -> anyhow::Result<RustlsClientConfig> {
self.tls_config.build()
}
Expand Down

0 comments on commit 2d0d660

Please sign in to comment.