Skip to content

Commit

Permalink
dns: add support for Legacy Unicast Responses
Browse files Browse the repository at this point in the history
As per RFC 6762 Section 6.7 (Legacy Unicast Responses)

"If the source UDP port in a received Multicast DNS query is not port
5353, this indicates that the querier originating the query is a
simple resolver such as described in Section 5.1, "One-Shot Multicast
DNS Queries", which does not fully implement all of Multicast DNS.
In this case, the Multicast DNS responder MUST send a UDP response
directly back to the querier, via unicast, to the query packet's
source IP address and port.  This unicast response MUST be a
conventional unicast response as would be generated by a conventional
Unicast DNS server; for example, it MUST repeat the query ID and the
question given in the query message."

Therefore, umdns should not ignore DNS questions coming from non-
multicast sources, and also provide question section which is not
usually provided in mDNS responses.

Signed-off-by: Mohd Husaam Mehdi <[email protected]>
  • Loading branch information
mhusaam committed Feb 13, 2025
1 parent a10d76d commit f057643
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions dns.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,17 @@ parse_question(struct interface *iface, struct sockaddr *from, char *name, struc
char *host;

/* TODO: Multicast if more than one quarter of TTL has passed */
if (is_unicast) {
if (is_unicast || port != MCAST_PORT) {
to = from;
if (interface_multicast(iface))
iface = interface_get(iface->name, iface->type | SOCKTYPE_BIT_UNICAST);
} else {
/* if the query is from multicast port, no need for original buffer
* while responding as per rfc 6762, section 6:
* Multicast DNS responses MUST NOT contain any questions in the
* Question Section. */
orig_buffer = NULL;
orig_len = 0;
}

DBG(1, "Q -> %s %s\n", dns_type_string(q->type), name);
Expand Down Expand Up @@ -465,10 +472,6 @@ dns_handle_packet(struct interface *iface, struct sockaddr *from, uint16_t port,
return;
}

if (h->questions && !interface_multicast(iface) && port != MCAST_PORT)
/* silently drop unicast questions that dont originate from port 5353 */
return;

while (h->questions-- > 0) {
char *name = dns_consume_name(buffer, len, &b, &rlen);
struct dns_question *q;
Expand Down

0 comments on commit f057643

Please sign in to comment.