[dns-client] add config to bind socket to thread netif (#12085)

This commit introduces a new configuration option
`OPENTHREAD_CONFIG_DNS_CLIENT_BIND_UDP_TO_THREAD_NETIF` to control
which network interface the DNS client's UDP socket binds to.

When this config is set to 1, the socket is bound to the Thread
network interface (`Ip6::kNetifThreadInternal`).

When the config is set to 0, the socket is bound to the unspecified
network interface (`Ip6::kNetifUnspecified`), allowing DNS messages
to be sent and received over any available network interface. By
default this new config is disabled.

A new CMake option `OT_DNS_CLIENT_BIND_UDP_THREAD_NETIF` is also added
to allow easy configuration of this feature.

The test configurations are updated to ensure both behaviors are
covered.
This commit is contained in:
Abtin Keshavarzian
2025-11-08 11:02:07 -08:00
committed by GitHub
parent 75c5d220de
commit ced33033e9
5 changed files with 24 additions and 3 deletions
+1
View File
@@ -204,6 +204,7 @@ ot_option(OT_DHCP6_CLIENT OPENTHREAD_CONFIG_DHCP6_CLIENT_ENABLE "DHCP6 client")
ot_option(OT_DHCP6_SERVER OPENTHREAD_CONFIG_DHCP6_SERVER_ENABLE "DHCP6 server")
ot_option(OT_DIAGNOSTIC OPENTHREAD_CONFIG_DIAG_ENABLE "diagnostic")
ot_option(OT_DNS_CLIENT OPENTHREAD_CONFIG_DNS_CLIENT_ENABLE "DNS client")
ot_option(OT_DNS_CLIENT_BIND_UDP_THREAD_NETIF OPENTHREAD_CONFIG_DNS_CLIENT_BIND_UDP_TO_THREAD_NETIF "bind DNS client socket to Thread netif")
ot_option(OT_DNS_CLIENT_OVER_TCP OPENTHREAD_CONFIG_DNS_CLIENT_OVER_TCP_ENABLE "Enable dns query over tcp")
ot_option(OT_DNS_DSO OPENTHREAD_CONFIG_DNS_DSO_ENABLE "DNS Stateful Operations (DSO)")
ot_option(OT_DNS_UPSTREAM_QUERY OPENTHREAD_CONFIG_DNS_UPSTREAM_QUERY_ENABLE "Allow sending DNS queries to upstream")
+11
View File
@@ -170,6 +170,17 @@
#define OPENTHREAD_CONFIG_DNS_CLIENT_DEFAULT_SERVICE_MODE OT_DNS_SERVICE_MODE_SRV_TXT_OPTIMIZE
#endif
/**
* @def OPENTHREAD_CONFIG_DNS_CLIENT_BIND_UDP_TO_THREAD_NETIF
*
* Define as 1 to bind DNS client UDP socket to the internal Thread network interface. When set to 0, the socket is
* bound to the unspecified network interface, allowing it to send and receive DNS messages over any network interface.
*
*/
#ifndef OPENTHREAD_CONFIG_DNS_CLIENT_BIND_UDP_TO_THREAD_NETIF
#define OPENTHREAD_CONFIG_DNS_CLIENT_BIND_UDP_TO_THREAD_NETIF 0
#endif
/**
* @def OPENTHREAD_CONFIG_DNS_CLIENT_OVER_TCP_ENABLE
*
+5
View File
@@ -792,7 +792,12 @@ Error Client::Start(void)
{
Error error;
#if OPENTHREAD_CONFIG_DNS_CLIENT_BIND_UDP_TO_THREAD_NETIF
SuccessOrExit(error = mSocket.Open(Ip6::kNetifThreadInternal));
#else
SuccessOrExit(error = mSocket.Open(Ip6::kNetifUnspecified));
#endif
SuccessOrExit(error = mSocket.Bind(0));
exit:
@@ -72,12 +72,14 @@
#define OPENTHREAD_CONFIG_NAT64_PORT_TRANSLATION_ENABLE 1
// The following two features (`USE_HEAP`) are set explicitly on posix `toranj`
// to validate the build with these config. The `toranj` build under simulation
// platform covers the opposite configs (allows `USE_HEAP`).
// The following features are set explicitly on posix `toranj`
// to validate the build with these config. The `toranj` build
// under simulation platform covers the opposite configs.
#define OPENTHREAD_CONFIG_BORDER_ROUTING_USE_HEAP_ENABLE 0
#define OPENTHREAD_CONFIG_TREL_USE_HEAP_ENABLE 1
#define OPENTHREAD_CONFIG_DNS_CLIENT_BIND_UDP_TO_THREAD_NETIF 0
#endif /* OPENTHREAD_CORE_TORANJ_CONFIG_POSIX_H_ */
@@ -49,6 +49,8 @@
#define OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE 1
#define OPENTHREAD_CONFIG_DNS_CLIENT_BIND_UDP_TO_THREAD_NETIF 1
#define OPENTHREAD_CONFIG_PLATFORM_DNSSD_ENABLE 1
#define OPENTHREAD_CONFIG_PLATFORM_DNSSD_ALLOW_RUN_TIME_SELECTION 1