diff --git a/CHANGELOG b/CHANGELOG index 89ba1eae..6673cb9b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -19,6 +19,10 @@ HISTORY ++ New features: + 2010-02-01: Simon Goldschmidt + * opt.h, memp_std.h, dns.h, netdb.c, memp.c: Let netdb use a memp pool + for allocating memory when getaddrinfo() is called. + 2010-01-31: Simon Goldschmidt * dhcp.h, dhcp.c: Reworked the code that parses DHCP options: parse them once instead of parsing for every option. This also removes diff --git a/src/api/netdb.c b/src/api/netdb.c index 06290190..60c196b2 100644 --- a/src/api/netdb.c +++ b/src/api/netdb.c @@ -39,8 +39,10 @@ #include "lwip/err.h" #include "lwip/mem.h" +#include "lwip/memp.h" #include "lwip/ip_addr.h" #include "lwip/api.h" +#include "lwip/dns.h" #include #include @@ -235,7 +237,7 @@ lwip_freeaddrinfo(struct addrinfo *ai) while (ai != NULL) { next = ai->ai_next; - mem_free(ai); + memp_free(MEMP_NETDB, ai); ai = next; } } @@ -305,7 +307,10 @@ lwip_getaddrinfo(const char *nodename, const char *servname, LWIP_ASSERT("namelen is too long", (namelen + 1) <= (mem_size_t)-1); total_size += namelen + 1; } - ai = mem_malloc(total_size); + /* If this fails, please report to lwip-devel! :-) */ + LWIP_ASSERT("total_size <= NETDB_ELEM_SIZE: please report this!", + total_size <= NETDB_ELEM_SIZE); + ai = memp_malloc(MEMP_NETDB); if (ai == NULL) { goto memerr; } @@ -338,7 +343,7 @@ lwip_getaddrinfo(const char *nodename, const char *servname, return 0; memerr: if (ai != NULL) { - mem_free(ai); + memp_free(MEMP_NETDB, ai); } return EAI_MEMORY; } diff --git a/src/core/memp.c b/src/core/memp.c index 29d5307c..229886d1 100644 --- a/src/core/memp.c +++ b/src/core/memp.c @@ -56,6 +56,7 @@ #include "lwip/ip_frag.h" #include "lwip/snmp_structs.h" #include "lwip/snmp_msg.h" +#include "lwip/dns.h" #include diff --git a/src/include/lwip/dns.h b/src/include/lwip/dns.h index e5f4b7a3..b86d12fd 100644 --- a/src/include/lwip/dns.h +++ b/src/include/lwip/dns.h @@ -66,6 +66,13 @@ #define DNS_RRCLASS_HS 4 /* Hesiod [Dyer 87] */ #define DNS_RRCLASS_FLUSH 0x800 /* Flush bit */ +/* The size used for the next line is rather a hack, but it prevents including socket.h in all files + that include memp.h, and that would possibly break portability (since socket.h defines some types + and constants possibly already define by the OS). + Calculation rule: + sizeof(struct addrinfo) + sizeof(struct sockaddr_in) + DNS_MAX_NAME_LENGTH + 1 byte zero-termination */ +#define NETDB_ELEM_SIZE (32 + 16 + DNS_MAX_NAME_LENGTH + 1) + /** Callback which is invoked when a hostname is found. * A function of this type must be implemented by the application using the DNS resolver. * @param name pointer to the name that was looked up. @@ -75,15 +82,10 @@ */ typedef void (*dns_found_callback)(const char *name, struct ip_addr *ipaddr, void *callback_arg); - void dns_init(void); - void dns_tmr(void); - void dns_setserver(u8_t numdns, struct ip_addr *dnsserver); - struct ip_addr dns_getserver(u8_t numdns); - err_t dns_gethostbyname(const char *hostname, struct ip_addr *addr, dns_found_callback found, void *callback_arg); diff --git a/src/include/lwip/memp_std.h b/src/include/lwip/memp_std.h index 17396dfd..6aad9ddd 100644 --- a/src/include/lwip/memp_std.h +++ b/src/include/lwip/memp_std.h @@ -74,6 +74,9 @@ LWIP_MEMPOOL(SNMP_NODE, MEMP_NUM_SNMP_NODE, sizeof(struct mib_list_no LWIP_MEMPOOL(SNMP_VARBIND, MEMP_NUM_SNMP_VARBIND, sizeof(struct snmp_varbind), "SNMP_VARBIND") LWIP_MEMPOOL(SNMP_VALUE, MEMP_NUM_SNMP_VALUE, SNMP_MAX_VALUE_SIZE, "SNMP_VALUE") #endif /* LWIP_SNMP */ +#if LWIP_DNS && LWIP_SOCKET +LWIP_MEMPOOL(NETDB, MEMP_NUM_NETDB, NETDB_ELEM_SIZE, "NETDB") +#endif /* LWIP_DNS && LWIP_SOCKET */ /* * A list of pools of pbuf's used by LWIP. diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index 73dbc269..8509a3f0 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -362,6 +362,14 @@ #define MEMP_NUM_SNMP_VALUE 3 #endif +/** + * MEMP_NUM_NETDB: the number of concurrently running lwip_addrinfo() calls + * (before freeing the corresponding memory using lwip_freeaddrinfo()). + */ +#ifndef MEMP_NUM_NETDB +#define MEMP_NUM_NETDB 1 +#endif + /** * PBUF_POOL_SIZE: the number of buffers in the pbuf pool. */