eculocate

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 0275110a7c0110f7e20cf00aa5b2b5d87f310a9f
parent 139751508544210ed473a3afc44c948dc20a6b81
Author: Daniel Barlow <dan@telent.net>
Date:   Sun, 28 Dec 2025 15:18:05 +0000

send additional RRs in response

* this is not quite according to SHOULD as it doesn't do transitive -
so there is no A record in the PTR response

* we don't check whether the additional is also in the responses,
so there may be duplicates

* I don't know what happens if we make a packet that's too bug

Diffstat:
Mecu-esp32/src/wifi.rs | 17+++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/ecu-esp32/src/wifi.rs b/ecu-esp32/src/wifi.rs @@ -68,7 +68,7 @@ const CACHE_FLUSH : u16 = 1<<15; // our needs because it doesn't own its "data" attribute - it's just a // reference. So we need structures that can own the data -#[derive(Clone)] +#[derive(Clone,Debug)] enum RData { Raw(Vec<u8>), Srv { target: String, port: u16, priority: u16, weight: u16 }, @@ -112,7 +112,7 @@ impl RData { } } - +#[derive(Debug)] struct DnsResource { name : String, ty : ResourceType, @@ -203,8 +203,8 @@ impl DnsDatabase { results } - fn additional(&self, r: DnsResource) -> Vec<&DnsResource> { - match r.data { + fn additional(&self, r: &DnsResource) -> Vec<&DnsResource> { + match &r.data { RData::Srv { target, port:_, priority:_, weight:_ } => { self.find(target, ResourceType::Wildcard) }, @@ -228,6 +228,7 @@ impl DnsDatabase { async fn send_response(sock: &UdpSocket<'_>, id: u16, endpoint: IpEndpoint, + db: &DnsDatabase, question: Option<&Question<'_>>, answers: Vec<&DnsResource>) { @@ -245,10 +246,14 @@ async fn send_response(sock: &UdpSocket<'_>, flags.set_qr(MessageType::Reply); flags.set_authoritative(true); + let mut additional : Vec<ResourceRecord> = Vec::new(); let mut answers : Vec<ResourceRecord> = { let mut rrs = Vec::new(); for a in answers { rrs.push(a.to_resource_record()); + for r in db.additional(a).into_iter() { + additional.push(r.to_resource_record()); + }; } rrs }; @@ -259,7 +264,7 @@ async fn send_response(sock: &UdpSocket<'_>, questions, &mut answers, &mut [], - &mut []); + &mut additional); let mut data_buf = [0; 4096]; // Serialize the message into the buffer @@ -298,7 +303,7 @@ async fn send_responses(sock: &UdpSocket<'_>, message.flags().raw(), meta.endpoint); - send_response(&sock, q_id, MDNS_ENDPOINT, None, relevant).await + send_response(&sock, q_id, MDNS_ENDPOINT, &db, None, relevant).await }