Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(network): add DNS servers configuration #83

Merged
merged 6 commits into from
Sep 5, 2024
Merged

Conversation

M0dEx
Copy link
Owner

@M0dEx M0dEx commented Aug 3, 2024

Added DNS configuration for Linux, FreeBSD and MacOS (Windows TBD).

Bumped MSRV to 1.80 due to std::sync::LazyLock.

Closes #76.

@M0dEx M0dEx changed the title feat(network): add DNS servers configuration for Linux, FreeBSD, MacOS feat(network): add DNS servers configuration Aug 4, 2024
@M0dEx M0dEx force-pushed the #76/dns-configuration branch 2 times, most recently from db43fdb to bf61005 Compare August 5, 2024 07:15
Copy link

codecov bot commented Aug 5, 2024

Codecov Report

Attention: Patch coverage is 66.66667% with 12 lines in your changes missing coverage. Please review.

Project coverage is 81.65%. Comparing base (b4ac966) to head (c7b1f3d).
Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
src/utils/command.rs 0.00% 10 Missing ⚠️
src/client.rs 88.88% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #83      +/-   ##
==========================================
+ Coverage   79.71%   81.65%   +1.93%     
==========================================
  Files          18       16       -2     
  Lines         991      943      -48     
==========================================
- Hits          790      770      -20     
+ Misses        201      173      -28     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Added DNS configuration for Linux, FreeBSD and MacOS (Windows TBD).

Bumped MSRV to 1.80 due to stdlib LazyLock.
@bonianchen
Copy link

Do DNS server need to be IP address all the time ?
I mean ... how about some DNS server, such as "ns1.dnsowl.com" ?

I'm a rust lang beginner. Here's how I workaround such case:

[Within src/client.rs]

use rsdns;

async fn resolve_address(lookup_addr: &str, dns_server_addr: &str) -> Result<SocketAddr> {
    if dns_server_addr.len() == 0 {
        lookup_addr.to_socket_addrs()?.next().ok_or_else(|| {
            anyhow!(
                "Connection string '{}' is invalid",
                lookup_addr
            )
        })
    } else {
        let dns_server = dns_server_addr.to_socket_addrs()?.next().unwrap();
        let dns_server_config = rsdns::clients::ClientConfig::with_nameserver(dns_server);
        print!("Query {:?} from DNS {:?}\n", lookup_addr, dns_server_config);
        let mut dns_server_query = rsdns::clients::tokio::Client::new(dns_server_config).await?;

        let mut lookup_addr_itor = lookup_addr.split(':');
        let rrset = dns_server_query.query_rrset::<rsdns::records::data::A>(
            lookup_addr_itor.next().unwrap(), rsdns::records::Class::IN).await?;
        let lookup_ip = rrset.rdata.into_iter().next().unwrap().address;
        print!("Query {:?} get {:?}\n", lookup_addr, lookup_ip);
        let lookup_port_no = lookup_addr_itor.next().unwrap()
            .parse::<u16>().unwrap();
        Ok(SocketAddr::new(std::net::IpAddr::V4(lookup_ip), lookup_port_no ))
    }
}

@M0dEx
Copy link
Owner Author

M0dEx commented Aug 17, 2024

Do DNS server need to be IP address all the time ? I mean ... how about some DNS server, such as "ns1.dnsowl.com" ?

I'm a rust lang beginner. Here's how I workaround such case:

[Within src/client.rs]

use rsdns;

async fn resolve_address(lookup_addr: &str, dns_server_addr: &str) -> Result<SocketAddr> {
    if dns_server_addr.len() == 0 {
        lookup_addr.to_socket_addrs()?.next().ok_or_else(|| {
            anyhow!(
                "Connection string '{}' is invalid",
                lookup_addr
            )
        })
    } else {
        let dns_server = dns_server_addr.to_socket_addrs()?.next().unwrap();
        let dns_server_config = rsdns::clients::ClientConfig::with_nameserver(dns_server);
        print!("Query {:?} from DNS {:?}\n", lookup_addr, dns_server_config);
        let mut dns_server_query = rsdns::clients::tokio::Client::new(dns_server_config).await?;

        let mut lookup_addr_itor = lookup_addr.split(':');
        let rrset = dns_server_query.query_rrset::<rsdns::records::data::A>(
            lookup_addr_itor.next().unwrap(), rsdns::records::Class::IN).await?;
        let lookup_ip = rrset.rdata.into_iter().next().unwrap().address;
        print!("Query {:?} get {:?}\n", lookup_addr, lookup_ip);
        let lookup_port_no = lookup_addr_itor.next().unwrap()
            .parse::<u16>().unwrap();
        Ok(SocketAddr::new(std::net::IpAddr::V4(lookup_ip), lookup_port_no ))
    }
}

I think there are some possible privacy concerns when specifying DNS servers using an FQDN.

So, for now, I feel Quincy should only support specifying DNS servers by their IP address, similar to WireGuard.

@M0dEx M0dEx marked this pull request as ready for review September 5, 2024 06:53
@M0dEx M0dEx merged commit 3fe77b0 into main Sep 5, 2024
5 of 6 checks passed
@M0dEx M0dEx deleted the #76/dns-configuration branch September 5, 2024 07:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add automatic DNS configuration
2 participants