diff --git a/src/core/dns.c b/src/core/dns.c index 42667ba7e..a740458bf 100644 --- a/src/core/dns.c +++ b/src/core/dns.c @@ -110,6 +110,10 @@ static dns_setserver_callback_t s_dns_setserver_callback = NULL; #include #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) @@ -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) { diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index 6a8517e30..23febc7f4 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -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