[mdns] add native mDNS support in OT (#9797)

This commit introduces native mDNS support within the OpenThread
stack, implementing RFC 6762 compliant registration of hosts,
services, and keys. It supports the following functionalities:

- Sending probes to claim names.
- Sending announcements on initial registration and changes.
- Sending "goodbye" announcements when unregistered or upon record
  removal.
- Negative responses (NSEC).
- Support for service sub-types and their addition/removal.
- Support for `_services._dns-sd._udp` queries (all service types).
- Responding to queries (including "QU" questions).
- Delay mechanism when responding to multi-question query messages,
  ensuring unique answers.
- Providing extra records in the Additional Data section if not
  already in the Answer section (e.g., on a PTR query, include SRV
  and host AAAA addresses).
- Implementing Known-Answer Suppression.
- Supporting multi-packet queries with known answers in follow-up
  messages.
- Rate-limiting record multicasts (once per second).
- Rate-limiting probe responses (once per 250ms).
- Detecting conflicts after probes.
- Limiting the size of emitted responses or probes, breaking into
  multiple messages if necessary.
- Detecting self originating messages (sent by mDNS module).
- Support for service browser.
- Support for service resolvers (SRV and TXT records) and IPv4/IPv6
  address resolvers for hostnames.
- Introduces smart cache management:
  - Passively caches service records for active browsers.
  - Passively caches address records for active service resolvers.
- Enables multiple simultaneous browsers/resolvers for the same
  service/host.

This commit introduces public `otMdns` OpenThread APIs and related CLI
commands for the mDNS module.

For platform abstraction, `otPlatMdns` APIs are defined in
`mdns_socket.h` (e.g., to send or receive mDNS messages):

- An implementation of the platform APIs is provided for posix.
- Also under the simulation platform, a simplified implementation of the
  `otPlatMdns` APIs is provided (intended for testing).

This commit also adds a detailed `test_mdns` unit test, validating
various functionalities and covering potential edge cases.
This commit is contained in:
Abtin Keshavarzian
2024-04-09 08:32:01 -07:00
committed by GitHub
parent 6de5cd8256
commit bf41332061
41 changed files with 18547 additions and 3 deletions
@@ -79,6 +79,7 @@
#define OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE 1
#define OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE 1
#define OPENTHREAD_CONFIG_MLR_ENABLE 1
#define OPENTHREAD_CONFIG_MULTICAST_DNS_ENABLE 1
#define OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE 0
#define OPENTHREAD_CONFIG_NAT64_BORDER_ROUTING_ENABLE 1
#define OPENTHREAD_CONFIG_NAT64_TRANSLATOR_ENABLE 1
@@ -99,5 +100,6 @@
#define OPENTHREAD_CONFIG_DNS_DSO_MOCK_PLAT_APIS_ENABLE 1
#define OPENTHREAD_CONFIG_BORDER_ROUTING_MOCK_PLAT_APIS_ENABLE 1
#define OPENTHREAD_CONFIG_DNS_UPSTREAM_QUERY_MOCK_PLAT_APIS_ENABLE 1
#define OPENTHREAD_CONFIG_MULTICAST_DNS_MOCK_PLAT_APIS_ENABLE 1
#endif // OT_CORE_CONFIG_CHECK_SIZE_BR_H_
@@ -69,6 +69,7 @@ add_library(openthread-simulation
flash.c
infra_if.c
logging.c
mdns_socket.c
misc.c
multipan.c
radio.c
+569
View File
@@ -0,0 +1,569 @@
/*
* Copyright (c) 2024, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "platform-simulation.h"
#include <openthread/nat64.h>
#include <openthread/platform/mdns_socket.h>
#if OPENTHREAD_CONFIG_MULTICAST_DNS_ENABLE
//---------------------------------------------------------------------------------------------------------------------
#if OPENTHREAD_SIMULATION_MDNS_SOCKET_IMPLEMENT_POSIX
// Provide a simplified POSIX based implementation of `otPlatMdns`
// platform APIs. This is intended for testing.
#include <openthread/ip6.h>
#include <arpa/inet.h>
#include <errno.h>
#include <net/if.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include "simul_utils.h"
#include "utils/code_utils.h"
#define MAX_BUFFER_SIZE 1600
#define MDNS_PORT 5353
static bool sEnabled = false;
static uint32_t sInfraIfIndex;
static int sMdnsFd4 = -1;
static int sMdnsFd6 = -1;
/* this is a portability hack */
#ifndef IPV6_ADD_MEMBERSHIP
#ifdef IPV6_JOIN_GROUP
#define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
#endif
#endif
#ifndef IPV6_DROP_MEMBERSHIP
#ifdef IPV6_LEAVE_GROUP
#define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP
#endif
#endif
#define VerifyOrDie(aCondition, aErrMsg) \
do \
{ \
if (!(aCondition)) \
{ \
fprintf(stderr, "\n\r" aErrMsg ". errono:%s\n\r", strerror(errno)); \
exit(1); \
} \
} while (false)
static void SetReuseAddrPort(int aFd)
{
int ret;
int yes = 1;
ret = setsockopt(aFd, SOL_SOCKET, SO_REUSEADDR, (char *)&yes, sizeof(yes));
VerifyOrDie(ret >= 0, "setsocketopt(SO_REUSEADDR) failed");
ret = setsockopt(aFd, SOL_SOCKET, SO_REUSEPORT, (char *)&yes, sizeof(yes));
VerifyOrDie(ret >= 0, "setsocketopt(SO_REUSEPORT) failed");
}
static void OpenIp4Socket(uint32_t aInfraIfIndex)
{
OT_UNUSED_VARIABLE(aInfraIfIndex);
struct sockaddr_in addr;
int fd;
int ret;
uint8_t u8;
int value;
fd = socket(AF_INET, SOCK_DGRAM, 0);
VerifyOrDie(fd >= 0, "socket() failed");
#ifdef __linux__
{
char nameBuffer[IF_NAMESIZE];
const char *ifname;
ifname = if_indextoname(aInfraIfIndex, nameBuffer);
VerifyOrDie(ifname != NULL, "if_indextoname() failed");
ret = setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, ifname, strlen(ifname));
VerifyOrDie(ret >= 0, "setsocketopt(SO_BINDTODEVICE) failed");
}
#else
value = aInfraIfIndex;
ret = setsockopt(fd, IPPROTO_IP, IP_BOUND_IF, &value, sizeof(value));
#endif
u8 = 255;
ret = setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL, &u8, sizeof(u8));
VerifyOrDie(ret >= 0, "setsocketopt(IP_MULTICAST_TTL) failed");
value = 255;
ret = setsockopt(fd, IPPROTO_IP, IP_TTL, &value, sizeof(value));
VerifyOrDie(ret >= 0, "setsocketopt(IP_TTL) failed");
u8 = 1;
ret = setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP, &u8, sizeof(u8));
VerifyOrDie(ret >= 0, "setsocketopt(IP_MULTICAST_LOOP) failed");
SetReuseAddrPort(fd);
{
struct ip_mreqn mreqn;
memset(&mreqn, 0, sizeof(mreqn));
mreqn.imr_multiaddr.s_addr = inet_addr("224.0.0.251");
mreqn.imr_ifindex = aInfraIfIndex;
ret = setsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF, &mreqn, sizeof(mreqn));
VerifyOrDie(ret >= 0, "setsocketopt(IP_MULTICAST_IF) failed");
}
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = htonl(INADDR_ANY);
addr.sin_port = htons(MDNS_PORT);
ret = bind(fd, (struct sockaddr *)&addr, sizeof(addr));
VerifyOrDie(ret >= 0, "bind() failed");
sMdnsFd4 = fd;
}
static void JoinOrLeaveIp4MulticastGroup(bool aJoin, uint32_t aInfraIfIndex)
{
struct ip_mreqn mreqn;
int ret;
memset(&mreqn, 0, sizeof(mreqn));
mreqn.imr_multiaddr.s_addr = inet_addr("224.0.0.251");
mreqn.imr_ifindex = aInfraIfIndex;
if (aJoin)
{
// Suggested workaround for netif not dropping
// a previous multicast membership.
setsockopt(sMdnsFd4, IPPROTO_IP, IP_DROP_MEMBERSHIP, &mreqn, sizeof(mreqn));
}
ret = setsockopt(sMdnsFd4, IPPROTO_IP, aJoin ? IP_ADD_MEMBERSHIP : IP_DROP_MEMBERSHIP, &mreqn, sizeof(mreqn));
VerifyOrDie(ret >= 0, "setsocketopt(IP_ADD/DROP_MEMBERSHIP) failed");
}
static void OpenIp6Socket(uint32_t aInfraIfIndex)
{
OT_UNUSED_VARIABLE(aInfraIfIndex);
struct sockaddr_in6 addr6;
int fd;
int ret;
int value;
fd = socket(AF_INET6, SOCK_DGRAM, 0);
VerifyOrDie(fd >= 0, "socket() failed");
#ifdef __linux__
{
char nameBuffer[IF_NAMESIZE];
const char *ifname;
ifname = if_indextoname(aInfraIfIndex, nameBuffer);
VerifyOrDie(ifname != NULL, "if_indextoname() failed");
ret = setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, ifname, strlen(ifname));
VerifyOrDie(ret >= 0, "setsocketopt(SO_BINDTODEVICE) failed");
}
#else
value = aInfraIfIndex;
ret = setsockopt(fd, IPPROTO_IPV6, IPV6_BOUND_IF, &value, sizeof(value));
#endif
value = 255;
ret = setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &value, sizeof(value));
VerifyOrDie(ret >= 0, "setsocketopt(IPV6_MULTICAST_HOPS) failed");
value = 255;
ret = setsockopt(fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &value, sizeof(value));
VerifyOrDie(ret >= 0, "setsocketopt(IPV6_UNICAST_HOPS) failed");
value = 1;
ret = setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &value, sizeof(value));
VerifyOrDie(ret >= 0, "setsocketopt(IPV6_V6ONLY) failed");
value = aInfraIfIndex;
ret = setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_IF, &value, sizeof(value));
VerifyOrDie(ret >= 0, "setsocketopt(IPV6_MULTICAST_IF) failed");
value = 1;
ret = setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, &value, sizeof(value));
VerifyOrDie(ret >= 0, "setsocketopt(IPV6_MULTICAST_LOOP) failed");
SetReuseAddrPort(fd);
memset(&addr6, 0, sizeof(addr6));
addr6.sin6_family = AF_INET6;
addr6.sin6_port = htons(MDNS_PORT);
ret = bind(fd, (struct sockaddr *)&addr6, sizeof(addr6));
VerifyOrDie(ret >= 0, "bind() failed");
sMdnsFd6 = fd;
}
static void JoinOrLeaveIp6MulticastGroup(bool aJoin, uint32_t aInfraIfIndex)
{
struct ipv6_mreq mreq6;
int ret;
memset(&mreq6, 0, sizeof(mreq6));
inet_pton(AF_INET6, "ff02::fb", &mreq6.ipv6mr_multiaddr);
mreq6.ipv6mr_interface = (int)aInfraIfIndex;
if (aJoin)
{
// Suggested workaround for netif not dropping
// a previous multicast membership.
setsockopt(sMdnsFd6, IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP, &mreq6, sizeof(mreq6));
}
ret = setsockopt(sMdnsFd6, IPPROTO_IPV6, aJoin ? IPV6_ADD_MEMBERSHIP : IPV6_DROP_MEMBERSHIP, &mreq6, sizeof(mreq6));
VerifyOrDie(ret >= 0, "setsocketopt(IP6_ADD/DROP_MEMBERSHIP) failed");
}
otError otPlatMdnsSetListeningEnabled(otInstance *aInstance, bool aEnable, uint32_t aInfraIfIndex)
{
OT_UNUSED_VARIABLE(aInstance);
if (aEnable)
{
otEXPECT(!sEnabled);
OpenIp4Socket(aInfraIfIndex);
JoinOrLeaveIp4MulticastGroup(/* aJoin */ true, aInfraIfIndex);
OpenIp6Socket(aInfraIfIndex);
JoinOrLeaveIp6MulticastGroup(/* aJoin */ true, aInfraIfIndex);
sEnabled = true;
sInfraIfIndex = aInfraIfIndex;
}
else
{
otEXPECT(sEnabled);
JoinOrLeaveIp4MulticastGroup(/* aJoin */ false, aInfraIfIndex);
JoinOrLeaveIp6MulticastGroup(/* aJoin */ false, aInfraIfIndex);
close(sMdnsFd4);
close(sMdnsFd6);
sEnabled = false;
}
exit:
return OT_ERROR_NONE;
}
void otPlatMdnsSendMulticast(otInstance *aInstance, otMessage *aMessage, uint32_t aInfraIfIndex)
{
OT_UNUSED_VARIABLE(aInstance);
OT_UNUSED_VARIABLE(aInfraIfIndex);
uint8_t buffer[MAX_BUFFER_SIZE];
uint16_t length;
int bytes;
otEXPECT(sEnabled);
length = otMessageRead(aMessage, 0, buffer, sizeof(buffer));
otMessageFree(aMessage);
{
struct sockaddr_in addr;
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = inet_addr("224.0.0.251");
addr.sin_port = htons(MDNS_PORT);
bytes = sendto(sMdnsFd4, buffer, length, 0, (struct sockaddr *)&addr, sizeof(addr));
VerifyOrDie((bytes == length), "sendTo(sMdnsFd4) failed");
}
{
struct sockaddr_in6 addr6;
memset(&addr6, 0, sizeof(addr6));
addr6.sin6_family = AF_INET6;
addr6.sin6_port = htons(MDNS_PORT);
inet_pton(AF_INET6, "ff02::fb", &addr6.sin6_addr);
bytes = sendto(sMdnsFd6, buffer, length, 0, (struct sockaddr *)&addr6, sizeof(addr6));
VerifyOrDie((bytes == length), "sendTo(sMdnsFd6) failed");
}
exit:
return;
}
void otPlatMdnsSendUnicast(otInstance *aInstance, otMessage *aMessage, const otPlatMdnsAddressInfo *aAddress)
{
OT_UNUSED_VARIABLE(aInstance);
otIp4Address ip4Addr;
uint8_t buffer[MAX_BUFFER_SIZE];
uint16_t length;
int bytes;
otEXPECT(sEnabled);
length = otMessageRead(aMessage, 0, buffer, sizeof(buffer));
otMessageFree(aMessage);
if (otIp4FromIp4MappedIp6Address(&aAddress->mAddress, &ip4Addr) == OT_ERROR_NONE)
{
struct sockaddr_in addr;
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
memcpy(&addr.sin_addr.s_addr, &ip4Addr, sizeof(otIp4Address));
addr.sin_port = htons(MDNS_PORT);
bytes = sendto(sMdnsFd4, buffer, length, 0, (struct sockaddr *)&addr, sizeof(addr));
VerifyOrDie((bytes == length), "sendTo(sMdnsFd4) failed");
}
else
{
struct sockaddr_in6 addr6;
memset(&addr6, 0, sizeof(addr6));
addr6.sin6_family = AF_INET6;
addr6.sin6_port = htons(MDNS_PORT);
memcpy(&addr6.sin6_addr, &aAddress->mAddress, sizeof(otIp6Address));
bytes = sendto(sMdnsFd6, buffer, length, 0, (struct sockaddr *)&addr6, sizeof(addr6));
VerifyOrDie((bytes == length), "sendTo(sMdnsFd6) failed");
}
exit:
return;
}
void platformMdnsSocketUpdateFdSet(fd_set *aReadFdSet, int *aMaxFd)
{
otEXPECT(sEnabled);
utilsAddFdToFdSet(sMdnsFd4, aReadFdSet, aMaxFd);
utilsAddFdToFdSet(sMdnsFd6, aReadFdSet, aMaxFd);
exit:
return;
}
void platformMdnsSocketProcess(otInstance *aInstance, const fd_set *aReadFdSet)
{
otEXPECT(sEnabled);
if (FD_ISSET(sMdnsFd4, aReadFdSet))
{
uint8_t buffer[MAX_BUFFER_SIZE];
struct sockaddr_in sockaddr;
otPlatMdnsAddressInfo addrInfo;
otMessage *message;
socklen_t len = sizeof(sockaddr);
ssize_t rval;
memset(&sockaddr, 0, sizeof(sockaddr));
rval = recvfrom(sMdnsFd4, (char *)&buffer, sizeof(buffer), 0, (struct sockaddr *)&sockaddr, &len);
VerifyOrDie(rval >= 0, "recvfrom() failed");
message = otIp6NewMessage(aInstance, NULL);
VerifyOrDie(message != NULL, "otIp6NewMessage() failed");
VerifyOrDie(otMessageAppend(message, buffer, (uint16_t)rval) == OT_ERROR_NONE, "otMessageAppend() failed");
memset(&addrInfo, 0, sizeof(addrInfo));
otIp4ToIp4MappedIp6Address((otIp4Address *)(&sockaddr.sin_addr.s_addr), &addrInfo.mAddress);
addrInfo.mPort = MDNS_PORT;
addrInfo.mInfraIfIndex = sInfraIfIndex;
otPlatMdnsHandleReceive(aInstance, message, /* aInUnicast */ false, &addrInfo);
}
if (FD_ISSET(sMdnsFd6, aReadFdSet))
{
uint8_t buffer[MAX_BUFFER_SIZE];
struct sockaddr_in6 sockaddr6;
otPlatMdnsAddressInfo addrInfo;
otMessage *message;
socklen_t len = sizeof(sockaddr6);
ssize_t rval;
memset(&sockaddr6, 0, sizeof(sockaddr6));
rval = recvfrom(sMdnsFd6, (char *)&buffer, sizeof(buffer), 0, (struct sockaddr *)&sockaddr6, &len);
VerifyOrDie(rval >= 0, "recvfrom(sMdnsFd6) failed");
message = otIp6NewMessage(aInstance, NULL);
VerifyOrDie(message != NULL, "otIp6NewMessage() failed");
VerifyOrDie(otMessageAppend(message, buffer, (uint16_t)rval) == OT_ERROR_NONE, "otMessageAppend() failed");
memset(&addrInfo, 0, sizeof(addrInfo));
memcpy(&addrInfo.mAddress, &sockaddr6.sin6_addr, sizeof(otIp6Address));
addrInfo.mPort = MDNS_PORT;
addrInfo.mInfraIfIndex = sInfraIfIndex;
otPlatMdnsHandleReceive(aInstance, message, /* aInUnicast */ false, &addrInfo);
}
exit:
return;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Add weak implementation of `ot` APIs for RCP build. Note that
// `simulation` platform does not get `OPENTHREAD_RADIO` config)
OT_TOOL_WEAK uint16_t otMessageRead(const otMessage *aMessage, uint16_t aOffset, void *aBuf, uint16_t aLength)
{
OT_UNUSED_VARIABLE(aMessage);
OT_UNUSED_VARIABLE(aOffset);
OT_UNUSED_VARIABLE(aBuf);
OT_UNUSED_VARIABLE(aLength);
fprintf(stderr, "\n\rWeak otMessageRead() is incorrectly used\n\r");
exit(1);
return 0;
}
OT_TOOL_WEAK void otMessageFree(otMessage *aMessage)
{
OT_UNUSED_VARIABLE(aMessage);
fprintf(stderr, "\n\rWeak otMessageFree() is incorrectly used\n\r");
exit(1);
}
OT_TOOL_WEAK otMessage *otIp6NewMessage(otInstance *aInstance, const otMessageSettings *aSettings)
{
OT_UNUSED_VARIABLE(aInstance);
OT_UNUSED_VARIABLE(aSettings);
fprintf(stderr, "\n\rWeak otIp6NewMessage() is incorrectly used\n\r");
exit(1);
return NULL;
}
OT_TOOL_WEAK otError otMessageAppend(otMessage *aMessage, const void *aBuf, uint16_t aLength)
{
OT_UNUSED_VARIABLE(aMessage);
OT_UNUSED_VARIABLE(aBuf);
OT_UNUSED_VARIABLE(aLength);
fprintf(stderr, "\n\rWeak otMessageFree() is incorrectly used\n\r");
exit(1);
return OT_ERROR_NOT_IMPLEMENTED;
}
OT_TOOL_WEAK void otIp4ToIp4MappedIp6Address(const otIp4Address *aIp4Address, otIp6Address *aIp6Address)
{
OT_UNUSED_VARIABLE(aIp4Address);
OT_UNUSED_VARIABLE(aIp6Address);
fprintf(stderr, "\n\rWeak otIp4ToIp4MappedIp6Address() is incorrectly used\n\r");
exit(1);
}
OT_TOOL_WEAK otError otIp4FromIp4MappedIp6Address(const otIp6Address *aIp6Address, otIp4Address *aIp4Address)
{
OT_UNUSED_VARIABLE(aIp6Address);
OT_UNUSED_VARIABLE(aIp4Address);
fprintf(stderr, "\n\rWeak otIp4FromIp4MappedIp6Address() is incorrectly used\n\r");
exit(1);
return OT_ERROR_NOT_IMPLEMENTED;
}
OT_TOOL_WEAK void otPlatMdnsHandleReceive(otInstance *aInstance,
otMessage *aMessage,
bool aIsUnicast,
const otPlatMdnsAddressInfo *aAddress)
{
OT_UNUSED_VARIABLE(aInstance);
OT_UNUSED_VARIABLE(aMessage);
OT_UNUSED_VARIABLE(aIsUnicast);
OT_UNUSED_VARIABLE(aAddress);
fprintf(stderr, "\n\rWeak otPlatMdnsHandleReceive() is incorrectly used\n\r");
exit(1);
}
//---------------------------------------------------------------------------------------------------------------------
#else // OPENTHREAD_SIMULATION_MDNS_SOCKET_IMPLEMENT_POSIX
otError otPlatMdnsSetListeningEnabled(otInstance *aInstance, bool aEnable, uint32_t aInfraIfIndex)
{
OT_UNUSED_VARIABLE(aInstance);
OT_UNUSED_VARIABLE(aEnable);
OT_UNUSED_VARIABLE(aInfraIfIndex);
return OT_ERROR_NOT_IMPLEMENTED;
}
void otPlatMdnsSendMulticast(otInstance *aInstance, otMessage *aMessage, uint32_t aInfraIfIndex)
{
OT_UNUSED_VARIABLE(aInstance);
OT_UNUSED_VARIABLE(aInfraIfIndex);
otMessageFree(aMessage);
}
void otPlatMdnsSendUnicast(otInstance *aInstance, otMessage *aMessage, const otPlatMdnsAddressInfo *aAddress)
{
OT_UNUSED_VARIABLE(aInstance);
OT_UNUSED_VARIABLE(aAddress);
otMessageFree(aMessage);
}
#endif // OPENTHREAD_SIMULATION_MDNS_SOCKET_IMPLEMENT_POSIX
#endif // OPENTHREAD_CONFIG_MULTICAST_DNS_ENABLE
@@ -103,3 +103,16 @@
#ifndef OPENTHREAD_SIMULATION_MAX_NETWORK_SIZE
#define OPENTHREAD_SIMULATION_MAX_NETWORK_SIZE 33
#endif
/**
* @def OPENTHREAD_SIMULATION_MDNS_SOCKET_IMPLEMENT_POSIX
*
* Define as 1 for the simulation platform to provide a simplified implementation of `otPlatMdns` APIs using posix
* socket.
*
* This is intended for testing of the OpenThread Multicast DNS (mDNS) module.
*
*/
#ifndef OPENTHREAD_SIMULATION_MDNS_SOCKET_IMPLEMENT_POSIX
#define OPENTHREAD_SIMULATION_MDNS_SOCKET_IMPLEMENT_POSIX 0
#endif
@@ -341,6 +341,28 @@ void platformInfraIfProcess(otInstance *aInstance, const fd_set *aReadFdSet, con
#endif // OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
#if OPENTHREAD_CONFIG_MULTICAST_DNS_ENABLE && OPENTHREAD_SIMULATION_MDNS_SOCKET_IMPLEMENT_POSIX
/**
* Updates the file descriptor sets with file descriptors used by the mDNS socket.
*
* @param[in,out] aReadFdSet A pointer to the read file descriptors.
* @param[in,out] aMaxFd A pointer to the max file descriptor.
*
*/
void platformMdnsSocketUpdateFdSet(fd_set *aReadFdSet, int *aMaxFd);
/**
* Performs mDNs Socket processing.
*
* @param[in] aInstance The OpenThread instance structure.
* @param[in] aReadFdSet A pointer to the read file descriptors.
*
*/
void platformMdnsSocketProcess(otInstance *aInstance, const fd_set *aReadFdSet);
#endif
/**
* Shuts down the BLE service used by OpenThread.
*
+6
View File
@@ -295,6 +295,9 @@ void otSysProcessDrivers(otInstance *aInstance)
#if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
platformInfraIfUpdateFdSet(&read_fds, &write_fds, &max_fd);
#endif
#if OPENTHREAD_CONFIG_MULTICAST_DNS_ENABLE && OPENTHREAD_SIMULATION_MDNS_SOCKET_IMPLEMENT_POSIX
platformMdnsSocketUpdateFdSet(&read_fds, &max_fd);
#endif
#if OPENTHREAD_CONFIG_BLE_TCAT_ENABLE
platformBleUpdateFdSet(&read_fds, &write_fds, &timeout, &max_fd);
@@ -329,6 +332,9 @@ void otSysProcessDrivers(otInstance *aInstance)
#if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
platformInfraIfProcess(aInstance, &read_fds, &write_fds);
#endif
#if OPENTHREAD_CONFIG_MULTICAST_DNS_ENABLE && OPENTHREAD_SIMULATION_MDNS_SOCKET_IMPLEMENT_POSIX
platformMdnsSocketProcess(aInstance, &read_fds);
#endif
if (gTerminate)
{