A lot of DNS fixes.
This commit is contained in:
Generated
+1
-1
@@ -45,7 +45,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "alfis"
|
||||
version = "0.8.5"
|
||||
version = "0.8.6"
|
||||
dependencies = [
|
||||
"bincode",
|
||||
"blakeout",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "alfis"
|
||||
version = "0.8.5"
|
||||
version = "0.8.6"
|
||||
authors = ["Revertron <alfis@revertron.com>"]
|
||||
edition = "2021"
|
||||
build = "build.rs"
|
||||
|
||||
+23
-33
@@ -76,7 +76,7 @@ impl BlockchainFilter {
|
||||
// Create DnsPacket
|
||||
let mut packet = DnsPacket::new();
|
||||
packet.header.authoritative_answer = true;
|
||||
packet.header.rescode = ResultCode::NOERROR;
|
||||
packet.header.rescode = ResultCode::NXDOMAIN;
|
||||
packet.questions.push(DnsQuestion::new(String::from(qname), qtype));
|
||||
let serial = self.context.lock().unwrap().chain.get_soa_serial();
|
||||
BlockchainFilter::add_soa_record(zone, serial, &mut packet);
|
||||
@@ -198,9 +198,9 @@ impl DnsFilter for BlockchainFilter {
|
||||
}
|
||||
|
||||
let mut answers: Vec<DnsRecord> = Vec::new();
|
||||
let a_record = qtype == QueryType::A || qtype == QueryType::AAAA;
|
||||
let mut cname: Option<DnsRecord> = None;
|
||||
for mut record in data.records.iter_mut() {
|
||||
if record.get_querytype() == qtype || (a_record && record.get_querytype() == QueryType::CNAME) {
|
||||
if record.get_querytype() == qtype || record.get_querytype() == QueryType::CNAME {
|
||||
match &mut record {
|
||||
DnsRecord::A { domain, .. }
|
||||
| DnsRecord::AAAA { domain, .. }
|
||||
@@ -211,7 +211,7 @@ impl DnsFilter for BlockchainFilter {
|
||||
| DnsRecord::MX { domain, .. }
|
||||
| DnsRecord::UNKNOWN { domain, .. }
|
||||
| DnsRecord::SOA { domain, .. }
|
||||
| DnsRecord::TXT { domain, .. } if domain == "@" => {
|
||||
| DnsRecord::TXT { domain, .. } if (domain == "@" && subdomain.is_empty()) || domain == &subdomain => {
|
||||
*domain = String::from(qname);
|
||||
}
|
||||
_ => ()
|
||||
@@ -220,40 +220,26 @@ impl DnsFilter for BlockchainFilter {
|
||||
match record.get_domain() {
|
||||
None => {}
|
||||
Some(domain) => {
|
||||
if domain == top_domain {
|
||||
answers.push(record.clone());
|
||||
} else if domain == subdomain {
|
||||
match &mut record {
|
||||
DnsRecord::A { domain, .. }
|
||||
| DnsRecord::AAAA { domain, .. }
|
||||
| DnsRecord::NS { domain, .. }
|
||||
| DnsRecord::CNAME { domain, .. }
|
||||
| DnsRecord::SRV { domain, .. }
|
||||
| DnsRecord::TLSA { domain, .. }
|
||||
| DnsRecord::MX { domain, .. }
|
||||
| DnsRecord::UNKNOWN { domain, .. }
|
||||
| DnsRecord::SOA { domain, .. }
|
||||
| DnsRecord::TXT { domain, .. } => {
|
||||
*domain = String::from(qname);
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
if domain == qname || domain == subdomain {
|
||||
if record.get_querytype() == QueryType::CNAME {
|
||||
cname = Some(record.clone());
|
||||
} else {
|
||||
answers.push(record.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if answers.is_empty() && cname.is_some() {
|
||||
answers.push(cname.unwrap());
|
||||
}
|
||||
let mut domain_exists = !answers.is_empty();
|
||||
if answers.is_empty() {
|
||||
// If there are no records found we search for *.domain.tld record
|
||||
for mut record in data.records {
|
||||
if record.get_querytype() == qtype {
|
||||
match record.get_domain() {
|
||||
None => {}
|
||||
Some(domain) => {
|
||||
if domain == top_domain {
|
||||
answers.push(record.clone());
|
||||
} else if domain == "*" {
|
||||
let record_domain = record.get_domain().unwrap_or(String::new());
|
||||
if record.get_querytype() == qtype && record_domain == "*" {
|
||||
match &mut record {
|
||||
DnsRecord::A { domain, .. }
|
||||
| DnsRecord::AAAA { domain, .. }
|
||||
@@ -271,14 +257,18 @@ impl DnsFilter for BlockchainFilter {
|
||||
}
|
||||
answers.push(record.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
if !domain_exists && (record_domain == subdomain || record_domain == "*") {
|
||||
domain_exists = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//debug!("Answers: {:?}", &answers);
|
||||
return self.create_packet(qname, qtype, zone, answers);
|
||||
if let Some(mut packet) = self.create_packet(qname, qtype, zone, answers) {
|
||||
if domain_exists && packet.answers.is_empty() {
|
||||
packet.header.rescode = ResultCode::NOERROR;
|
||||
}
|
||||
return Some(packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -297,7 +297,7 @@ impl Peers {
|
||||
}
|
||||
}
|
||||
|
||||
// If someone has less blocks (we mined a new block) we send a ping with our height
|
||||
// If someone has fewer blocks (we mined a new block) we send a ping with our height
|
||||
if self.need_behind_ping() {
|
||||
let mut rng = rand::thread_rng();
|
||||
match self.peers
|
||||
|
||||
Reference in New Issue
Block a user