Skip to content

Commit

Permalink
dns: Add support for external resolve hook in TCPIP context
Browse files Browse the repository at this point in the history
2.1.3-esp: 0606eed feat(lwip): Add DNS external resolve hook
  • Loading branch information
wqx6 authored and david-cermak committed Sep 11, 2024
1 parent 0deed15 commit 3a393c9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/core/dns.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ static dns_setserver_callback_t s_dns_setserver_callback = NULL;
#include <stdbool.h>
#endif

#ifdef LWIP_HOOK_FILENAME
#include LWIP_HOOK_FILENAME
#endif

/** Random generator function to create random TXIDs and source ports for queries */
#ifndef DNS_RAND_TXID
#if ((LWIP_DNS_SECURE & LWIP_DNS_SECURE_RAND_XID) != 0)
Expand Down Expand Up @@ -1735,6 +1739,14 @@ dns_gethostbyname_addrtype(const char *hostname, ip_addr_t *addr, dns_found_call
return ERR_ARG;
}

#ifdef LWIP_HOOK_DNS_EXTERNAL_RESOLVE
{
err_t err = ERR_OK;
if (LWIP_HOOK_DNS_EXTERNAL_RESOLVE(hostname, addr, found, callback_arg, dns_addrtype, &err)) {
return err;
}
}
#endif /* LWIP_HOOK_DNS_EXTERNAL_RESOLVE */

#if LWIP_HAVE_LOOPIF
if (strcmp(hostname, "localhost") == 0) {
Expand Down
28 changes: 28 additions & 0 deletions src/include/lwip/opt.h
Original file line number Diff line number Diff line change
Expand Up @@ -3150,6 +3150,34 @@
#define LWIP_HOOK_IP6_SELECT_SRC_ADDR(netif, dest)
#endif

/**
* LWIP_HOOK_DNS_EXTERNAL_RESOLVE(name, addr, found, callback_arg, addrtype, err):
* Called from dns APIs (usable with callback apps) allowing an
* external DNS resolver (which uses sequential API) to handle the query.
* The external resolver is called from LwIP thread context. Please carefully use this hook
* to avoid thread issues(such as deadlock).
* Signature:\code{.c}
* int my_hook(const char *name, ip_addr_t *addr, dns_found_callback found, void *callback_arg,
* u8_t addrtype, err_t *err)
* \endcode
* Arguments:
* - name: hostname to resolve
* - addr: output host address
* - found: dns host address found callback
* - callback_arg: found callback argument
* - addrtype: type of address to query
* - err: output error
* Return values:
* - 0: Hook has not consumed hostname query, query continues into DNS module
* - != 0: Hook has consumed the query
*
* err must also be checked to determine if the hook consumed the query, but
* the query failed
*/
#ifdef __DOXYGEN__
#define LWIP_HOOK_DNS_EXTERNAL_RESOLVE(name, addr, found, callback_arg, addrtype, err)
#endif

/**
* LWIP_HOOK_VLAN_CHECK(netif, eth_hdr, vlan_hdr):
* Called from ethernet_input() if VLAN support is enabled
Expand Down

0 comments on commit 3a393c9

Please sign in to comment.