commit 7696ac0277cdd685429501da59c1675444a93ee0
parent 39df2730b9f0640bbb86a37819a67397fdaba02d
Author: Daniel Barlow <dan@telent.net>
Date: Tue, 30 Dec 2025 23:56:51 +0000
handle unicast (QU) and legacy (post != 5353) queries
Diffstat:
2 files changed, 27 insertions(+), 27 deletions(-)
diff --git a/ecu-esp32/src/wifi.rs b/ecu-esp32/src/wifi.rs
@@ -113,15 +113,11 @@ impl<'a> MdnsResponder<'a> {
question: Option<&Question<'_>>,
answers: Vec<&DnsResource>) {
- let questions = match question {
- Some(q) =>&mut [*q][..],
- None => &mut [][..]
- };
+ let legacy = question != None;
let db = &self.database;
let mut flags = Flags::new();
-
flags.set_qr(MessageType::Reply);
flags.set_authoritative(true);
@@ -143,6 +139,22 @@ impl<'a> MdnsResponder<'a> {
}
let mut additional : Vec<ResourceRecord> = additional.into_iter().collect();
+
+ let questions = match question {
+ Some(q) =>&mut [*q][..],
+ None => &mut [][..]
+ };
+
+ if legacy {
+ // force class = IN (no cache-flush) and ttl to 10 seconds
+ answers = answers.iter().map(|rr| {
+ ResourceRecord::new(rr.name(), rr.ty(), 1, 10, rr.data())
+ }).collect();
+ additional = additional.iter().map(|rr| {
+ ResourceRecord::new(rr.name(), rr.ty(), 1, 10, rr.data())
+ }).collect();
+ }
+
let message = Message::new(
id,
flags,
@@ -183,7 +195,15 @@ impl<'a> MdnsResponder<'a> {
message.flags().raw(),
meta.endpoint);
- self.send_response(q_id, MDNS_ENDPOINT, None, relevant).await
+ let unicast = (q.class() & (1<<15)) != 0;
+ let legacy = meta.endpoint.port != 5353;
+ if legacy {
+ self.send_response(q_id, meta.endpoint, Some(q), relevant).await
+ } else if unicast {
+ self.send_response(0, meta.endpoint, None, relevant).await
+ } else {
+ self.send_response(0, MDNS_ENDPOINT, None, relevant).await
+ }
}
}
}
diff --git a/notes.md b/notes.md
@@ -200,28 +200,10 @@ but not the PTR records because other devices could also legitimately
have those
-
-
** do we need to do NSEC?
** handle QU and legacy queries
- // RFC: "Multicast DNS responses MUST NOT contain any questions in the
- // Question Section. ". However, responses to "legacy" queries (port != 5353)
- // should have a question section just like traditional DNS
- if q.name().eq(&Label::from("&my_hostname")) {
- // if meta.endpoint.port == 5353 {
- // send_advert(&sock, q_id, MDNS_ENDPOINT, None, &my_address).await;
- // } else if (q.class() & 0x8000) != 0 {
- // log::info!("unicast");
- // send_advert(&sock, q_id, meta.endpoint, None, &my_address).await;
- // } else {
- // // legacy unicast, send questions
- // send_advert(&sock, q_id, meta.endpoint, Some(q), &my_address).await;
- // }
- // log::info!("IT ME");
- }
-
5.4 Questions Requesting Unicast Responses
- top bit in the class field of a DNS question is the unicast-response bit
@@ -241,11 +223,9 @@ if source port != 5353
- don't set cache-flush bit
- ttl <= 10s
-
-
-
** compress responses
+
* write the udp server
- on reception of a packet containing table numbers, start streaming those