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

WIP: initial migration to trust-dns 0.19 #17

Closed
wants to merge 1 commit into from
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
2,429 changes: 1,229 additions & 1,200 deletions Cargo.lock

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,23 @@ serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
url_serde = { version = "0.2", default-features = false }
base64 = "0.11"
base64 = "0.12"
regex = "1.3"
r2d2 = "0.8"
r2d2_redis = "0.11"
redis = "0.12"
r2d2_redis = "0.13"
redis = "0.16"
rocket = { version = "0.4", default-features = false }
rocket_contrib = { version = "0.4", features = ["json"], default-features = false }
trust-dns = { version = "0.13", default-features = false }
trust-dns-server = { version = "0.13", default-features = false }
trust-dns-proto = { version = "*", default-features = false, features = ["tokio-runtime", "dnssec-ring", "serde"]}
trust-dns-server = { version = "*", default-features = false, features = ["dns-over-https-rustls", "dns-over-rustls", "dnssec-ring"] }
rand = "0.7"
farmhash = "1.1"
http_req = { version = "0.5", features = ["rust-tls"], default-features = false }
http_req = { version = "0.6", features = ["rust-tls"], default-features = false }
maxminddb = "0.13"
tempfile = "3.1"
flate2 = "1.0"
tar = "0.4"
tokio = "0.2"

[profile.dev]
opt-level = 0
Expand Down
2 changes: 1 addition & 1 deletion src/dns/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Copyright: 2019, Valerian Saliou <[email protected]>
// License: Mozilla Public License v2.0 (MPL v2.0)

use trust_dns::op::ResponseCode;
use trust_dns_proto::op::ResponseCode;

#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize)]
pub enum CodeName {
Expand Down
59 changes: 41 additions & 18 deletions src/dns/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ use rand::thread_rng;
use std::collections::HashMap;
use std::net::IpAddr;
use std::sync::RwLock;
use trust_dns::op::{Message, MessageType, OpCode, Query, ResponseCode};
use trust_dns::rr::dnssec::SupportedAlgorithms;
use trust_dns::rr::{Name, Record, RecordType as TrustRecordType};
use trust_dns_proto::op::{Message, MessageType, OpCode, Query, ResponseCode};
use trust_dns_proto::rr::dnssec::SupportedAlgorithms;
use trust_dns_proto::rr::{Name, Record, RecordType as TrustRecordType};
use trust_dns_server::authority::{AuthLookup, Authority};
use trust_dns_server::authority::AuthLookupIter::Records;
use trust_dns_server::server::{Request, RequestHandler};
use trust_dns_server::authority::LookupError;
use trust_dns_server::store::in_memory::InMemoryAuthority;


use super::code::CodeName;
use super::health::{DNSHealth, DNSHealthStatus};
Expand All @@ -25,18 +29,36 @@ use crate::geo::region::RegionCode;
use crate::store::store::{StoreError, StoreRecord};
use crate::APP_CONF;
use crate::APP_STORE;
use trust_dns_server::server::ResponseHandler;
use trust_dns_server::authority::MessageResponseBuilder;
use std::future::Future;
use trust_dns_server::authority::MessageResponse;

pub type Authority2 = InMemoryAuthority;

pub struct DNSHandler {
authorities: HashMap<Name, RwLock<Authority>>,
authorities: HashMap<Name, RwLock<Authority2>>,
}


pub struct DoneNow;

impl Future for DoneNow {
type Output = ();
fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
Poll::Ready(())
}
}

impl RequestHandler for DNSHandler {
fn handle_request(&self, request: &Request) -> Message {
type ResponseFuture=DoneNow;

fn handle_request<R: ResponseHandler>(&self, request: Request, response_handle: R) -> Self::ResponseFuture {
let request_message = &request.message;

trace!("request: {:?}", request_message);

let response: Message = match request_message.message_type() {
let response: MessageResponse = match request_message.message_type() {
MessageType::Query => match request_message.op_code() {
OpCode::Query => {
let response = self.lookup(request.src.ip(), &request_message);
Expand All @@ -48,7 +70,7 @@ impl RequestHandler for DNSHandler {
code @ _ => {
error!("unimplemented opcode: {:?}", code);

Message::error_msg(
MessageResponseBuilder::error_msg(
request_message.id(),
request_message.op_code(),
ResponseCode::NotImp,
Expand All @@ -61,15 +83,15 @@ impl RequestHandler for DNSHandler {
request_message.id()
);

Message::error_msg(
MessageResponseBuilder::error_msg(
request_message.id(),
request_message.op_code(),
ResponseCode::NotImp,
)
}
};

response
Box::pin(response_handle.send_response(response).into())
}
}

Expand All @@ -80,7 +102,7 @@ impl DNSHandler {
}
}

pub fn upsert(&mut self, name: Name, authority: Authority) {
pub fn upsert(&mut self, name: Name, authority: Authority2) {
self.authorities.insert(name, RwLock::new(authority));
}

Expand All @@ -106,7 +128,8 @@ impl DNSHandler {
let supported_algorithms = SupportedAlgorithms::new();

// Attempt to resolve from local store
let records_local = authority.search(query, false, supported_algorithms);
let mut rt = tokio::runtime::Runtime::new().unwrap();
let records_local = rt.block_on(async { authority.search(query, false, supported_algorithms) } );

if !records_local.is_empty() {
debug!("found records for query from local store: {}", query);
Expand Down Expand Up @@ -172,7 +195,7 @@ impl DNSHandler {
false,
);
}
AuthLookup::Records(..) => {
AuthLookup::Records {.. } => {
panic!("error, should return noerror")
}
};
Expand Down Expand Up @@ -203,7 +226,7 @@ impl DNSHandler {
response
}

fn find_auth_recurse(&self, name: &Name) -> Option<&RwLock<Authority>> {
fn find_auth_recurse(&self, name: &Name) -> Option<&RwLock<Authority2>> {
let authority = self.authorities.get(name);

if authority.is_some() {
Expand All @@ -220,7 +243,7 @@ impl DNSHandler {
}

fn records_from_store(
authority: &Authority,
authority: &Authority2,
zone_name: &Option<ZoneName>,
source: IpAddr,
query: &Query,
Expand Down Expand Up @@ -286,7 +309,7 @@ impl DNSHandler {
}

fn records_from_store_attempt(
authority: &Authority,
authority: &Authority2,
source: IpAddr,
zone_name: &Option<ZoneName>,
query_name_client: &Name,
Expand Down Expand Up @@ -550,7 +573,7 @@ impl DNSHandler {
response: &mut Message,
zone_name: &Option<ZoneName>,
mut records: Vec<Record>,
authority: &Authority,
authority: &Authority2,
supported_algorithms: SupportedAlgorithms,
) {
let has_records = !records.is_empty();
Expand Down Expand Up @@ -580,7 +603,7 @@ impl DNSHandler {
fn stamp_response(
request: &Message,
response: &mut Message,
authority: &Authority,
authority: &Authority2,
supported_algorithms: SupportedAlgorithms,
code: ResponseCode,
zone_name: &Option<ZoneName>,
Expand Down Expand Up @@ -638,6 +661,6 @@ impl DNSHandler {
}

// No alternate record found, consider name as non-existing.
return Ok(false);
Ok(false)
}
}
14 changes: 8 additions & 6 deletions src/dns/listen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
use std::collections::BTreeMap;
use std::net::{TcpListener, UdpSocket};
use std::time::Duration;
use trust_dns::rr::rdata::SOA;
use trust_dns::rr::{Name, RData, Record, RecordSet, RecordType, RrKey};
use trust_dns_proto::rr::rdata::SOA;
use trust_dns_proto::rr::{Name, RData, Record, RecordSet, RecordType};
use trust_dns_server::authority::{Authority, ZoneType};
use trust_dns_server::server::ServerFuture;

use super::handler::Authority2;

use super::handler::DNSHandler;
use crate::APP_CONF;

Expand Down Expand Up @@ -71,7 +73,7 @@ impl DNSListen {
}
}

fn map_authority(zone_name: &str) -> Result<(Name, Authority), ()> {
fn map_authority(zone_name: &str) -> Result<(Name, Authority2), ()> {
if let Ok(name) = Name::parse(zone_name, Some(&Name::new())) {
let mut records = BTreeMap::new();

Expand All @@ -91,7 +93,7 @@ impl DNSListen {
)),
));

records.insert(RrKey::new(&name, RecordType::SOA), soa_records);
records.insert(RecordSet::new(&name, RecordType::SOA, 1337), soa_records);

// Insert base NS records
let mut ns_records = RecordSet::new(&name, RecordType::NS, SERIAL_DEFAULT);
Expand All @@ -111,11 +113,11 @@ impl DNSListen {
);
}

records.insert(RrKey::new(&name, RecordType::NS), ns_records);
records.insert(RecordSet::new(&name, RecordType::NS, 1337), ns_records);

Ok((
name.to_owned(),
Authority::new(name, records, ZoneType::Master, false, false),
Authority2::new(name, records, ZoneType::Master, false, false),
))
} else {
Err(())
Expand Down
6 changes: 3 additions & 3 deletions src/dns/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ use std::cmp;
use std::collections::HashSet;
use std::ops::Deref;
use std::{fmt, str};
use trust_dns::rr::rdata::mx::MX;
use trust_dns::rr::rdata::txt::TXT;
use trust_dns::rr::{Name as TrustName, RData as TrustRData, RecordType as TrustRecordType};
use trust_dns_proto::rr::rdata::mx::MX;
use trust_dns_proto::rr::rdata::txt::TXT;
use trust_dns_proto::rr::{Name as TrustName, RData as TrustRData, RecordType as TrustRecordType};

use crate::geo::country::CountryCode;

Expand Down
2 changes: 1 addition & 1 deletion src/dns/zone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rocket::request::FromParam;
use serde::de::{Error as DeserializeError, Unexpected, Visitor};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::{fmt, str};
use trust_dns::rr::Name as TrustName;
use trust_dns_proto::rr::Name as TrustName;

use crate::APP_CONF;

Expand Down
38 changes: 19 additions & 19 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@ extern crate lazy_static;
extern crate serde_derive;
#[macro_use]
extern crate rocket;
extern crate base64;
extern crate farmhash;
extern crate flate2;
extern crate http_req;
extern crate maxminddb;
extern crate r2d2;
extern crate r2d2_redis;
extern crate rand;
extern crate redis;
extern crate regex;
extern crate rocket_contrib;
extern crate serde;
extern crate serde_json;
extern crate tar;
extern crate tempfile;
extern crate toml;
extern crate trust_dns;
extern crate trust_dns_server;
extern crate url_serde;
use base64;
use farmhash;
use flate2;
use http_req;
use maxminddb;
use r2d2;
use r2d2_redis;
use rand;
use redis;
use regex;
use rocket_contrib;
use serde;
use serde_json;
use tar;
use tempfile;
use toml;
use trust_dns_proto;
use trust_dns_server;
use url_serde;

mod config;
mod dns;
Expand Down