[dnssd] support generic record queries via discovery proxy and SRP (#11357)

This commit enhances the OpenThread DNSSD name server/resolver and its
native Discovery Proxy to support queries for arbitrary record
types.

To enable this, a new set of `otPlatDnssd` APIs are introduced for
generic `RecordQuerier`. These APIs mirror the existing APIs in the
OpenThread native mDNS module, allowing direct use of the native mDNS
implementation.

The discovery proxy implementation is updated to start and stop the
mDNS `RecordQuerier` when receiving a query for an arbitrary record
type, passing the first response record back to the client.

The unit tests `test_dnssd_discovery_proxy` and `test_dns_client`
are updated to cover all the newly added behaviors in discovery proxy.
This commit is contained in:
Abtin Keshavarzian
2025-04-23 12:14:05 -07:00
committed by GitHub
parent 4be7e8baa2
commit 20aefc2215
18 changed files with 1378 additions and 239 deletions
+46
View File
@@ -3581,6 +3581,52 @@ class NodeImpl:
index = index + (5 if result[ins] else 1)
return result
def dns_query(self, rrtype, first_label, next_labels, server=None, port=53):
"""
Send a DNS query for a given record type and name.
Output is an array of records (as dictionary) with string keys and values.
[
{'RecordType': '25',
'RecordLength': '78',
'TTL': '7105',
'Section': 'answer',
'Name': 'ins1._IPPS._TCP.DEFAULT.SERVICE.ARPA.',
'RecordData': '[001900010000a0610...d45d3]'
}
]
"""
cmd = f'dns query {rrtype} {first_label} {next_labels}'
if server is not None:
cmd += f' {server} {port}'
self.send_command(cmd)
self.simulator.go(10)
output = self._expect_command_output()
# Example output:
# DNS query response for ins1._IPPS._TCP.DEFAULT.SERVICE.ARPA.
# 0)
# RecordType:25, RecordLength:78, TTL:7105, Section:answer
# Name:ins1._IPPS._TCP.DEFAULT.SERVICE.ARPA.
# RecordData:[00190001000...cdb]
# Done
result = []
index = 1 # Skip first line
while (index < len(output)):
if (index > len(output) - 4):
break
record = {}
for line in output[index + 1:index + 4]:
for item in line.strip().split(','):
k, v = item.split(':')
record[k.strip()] = v.strip()
result.append(record)
index += 4
return result
def set_mliid(self, mliid: str):
cmd = f'mliid {mliid}'
self.send_command(cmd)