diff --git a/CHANGELOG b/CHANGELOG index 5da24c95..3ddf9511 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -5,6 +5,8 @@ HISTORY * [Enter new changes just after this line - do not remove this line] ++ New features: + 2017-11-20: Joel Cunningham + * netconn: add LWIP_HOOK_NETCONN_EXTERNAL_RESOLVE to use external DNS resolver (patch #9427) 2017-11-14: Joel Cunningham * netifapi: Add thread safe ARP cache APIs (task #14724) diff --git a/src/api/api_lib.c b/src/api/api_lib.c index 9c7b249f..2541f41e 100644 --- a/src/api/api_lib.c +++ b/src/api/api_lib.c @@ -69,6 +69,10 @@ #include "lwip/priv/tcp_priv.h" #include "lwip/priv/tcpip_priv.h" +#ifdef LWIP_HOOK_FILENAME +#include LWIP_HOOK_FILENAME +#endif + #include #define API_MSG_VAR_REF(name) API_VAR_REF(name) @@ -1209,6 +1213,16 @@ netconn_gethostbyname(const char *name, ip_addr_t *addr) } #endif +#ifdef LWIP_HOOK_NETCONN_EXTERNAL_RESOLVE +#if LWIP_IPV4 && LWIP_IPV6 + if (LWIP_HOOK_NETCONN_EXTERNAL_RESOLVE(name, addr, dns_addrtype, &err)) { +#else + if (LWIP_HOOK_NETCONN_EXTERNAL_RESOLVE(name, addr, NETCONN_DNS_DEFAULT, &err)) { +#endif /* LWIP_IPV4 && LWIP_IPV6 */ + return err; + } +#endif /* LWIP_HOOK_NETCONN_EXTERNAL_RESOLVE */ + API_VAR_ALLOC(struct dns_api_msg, MEMP_DNS_API_MSG, msg, ERR_MEM); #if LWIP_MPU_COMPATIBLE strncpy(API_VAR_REF(msg).name, name, DNS_MAX_NAME_LENGTH - 1); diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index 2b5a765b..54bc01e4 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -2911,6 +2911,28 @@ #ifdef __DOXYGEN__ #define LWIP_HOOK_DHCP_PARSE_OPTION(netif, dhcp, state, msg, msg_type, option, len, pbuf, offset) #endif + +/** + * LWIP_HOOK_NETCONN_EXTERNAL_RESOLVE(name, addr, addrtype, err) + * Called from netconn APIs (not usable with callback apps) allowing an + * external DNS resolver (which uses sequential API) to handle the query. + * Signature: + * int my_hook(const char *name, ip_addr_t *addr, u8_t addrtype, err_t *err) + * Arguments: + * - name: hostname to resolve + * - addr: output host address + * - 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_NETCONN_EXTERNAL_RESOLVE(name, addr, addrtype, err) +#endif /** * @} */