Skip to content

Commit

Permalink
a test case for name conflicts between 3 nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
keepsimple1 committed Nov 2, 2024
1 parent bee200c commit 1e4dc56
Show file tree
Hide file tree
Showing 4 changed files with 290 additions and 119 deletions.
30 changes: 19 additions & 11 deletions src/dns_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#[cfg(feature = "logging")]
use crate::log::debug;
use crate::{
service_info::{decode_txt, valid_ip_on_intf},
service_info::{decode_txt, valid_ip_on_intf, DnsRegistry},
Error, Result, ServiceInfo,
};
use if_addrs::Interface;
Expand Down Expand Up @@ -355,10 +355,6 @@ pub(crate) trait DnsRecordExt: fmt::Debug {
self.get_record().get_name()
}

fn get_original_name(&self) -> &str {
self.get_record().get_original_name()
}

fn get_type(&self) -> u16 {
self.get_record().entry.ty
}
Expand Down Expand Up @@ -1279,21 +1275,33 @@ impl DnsOutgoing {
msg: &DnsIncoming,
service: &ServiceInfo,
intf: &Interface,
dns_registry: &DnsRegistry,
) {
let intf_addrs = service.get_addrs_on_intf(intf);
if intf_addrs.is_empty() {
debug!("No addrs on LAN of intf {:?}", intf);
return;
}

// check if we changed our name due to conflicts.
let service_fullname = match dns_registry.name_changes.get(service.get_fullname()) {
Some(new_name) => new_name,
None => service.get_fullname(),
};

let hostname = match dns_registry.name_changes.get(service.get_hostname()) {
Some(new_name) => new_name,
None => service.get_hostname(),
};

let ptr_added = self.add_answer(
msg,
DnsPointer::new(
service.get_type(),
RR_TYPE_PTR,
CLASS_IN,
service.get_other_ttl(),
service.get_fullname().to_string(),
service_fullname.to_string(),
),
);

Expand All @@ -1309,32 +1317,32 @@ impl DnsOutgoing {
RR_TYPE_PTR,
CLASS_IN,
service.get_other_ttl(),
service.get_fullname().to_string(),
service_fullname.to_string(),
));
}

// Add recommended additional answers according to
// https://tools.ietf.org/html/rfc6763#section-12.1.
self.add_additional_answer(DnsSrv::new(
service.get_fullname(),
service_fullname,
CLASS_IN | CLASS_CACHE_FLUSH,
service.get_host_ttl(),
service.get_priority(),
service.get_weight(),
service.get_port(),
service.get_hostname().to_string(),
hostname.to_string(),
));

self.add_additional_answer(DnsTxt::new(
service.get_fullname(),
service_fullname,
CLASS_IN | CLASS_CACHE_FLUSH,
service.get_host_ttl(),
service.generate_txt(),
));

for address in intf_addrs {
self.add_additional_answer(DnsAddress::new(
service.get_hostname(),
hostname,
ip_address_to_type(&address),
CLASS_IN | CLASS_CACHE_FLUSH,
service.get_host_ttl(),
Expand Down
Loading

0 comments on commit 1e4dc56

Please sign in to comment.