Skip to content
This repository has been archived by the owner on Dec 20, 2023. It is now read-only.

Commit

Permalink
Integration: updates for merging with nest/stable.
Browse files Browse the repository at this point in the history
  • Loading branch information
james woodyatt authored and james woodyatt committed Nov 3, 2017
1 parent 6b529be commit 767e3f6
Showing 1 changed file with 40 additions and 44 deletions.
84 changes: 40 additions & 44 deletions src/core/dns.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,6 @@ struct dns_table_entry {
u8_t tmr;
#if DNS_MAX_ADDRS_PER_NAME > 1
u8_t is_multi;
dns_found_callbackX found;
#else
dns_found_callback found;
#endif
void *arg;
u8_t retries;
Expand Down Expand Up @@ -347,7 +344,6 @@ const ip_addr_t dns_mquery_v6group = DNS_MQUERY_IPV6_GROUP_INIT;
* Initialize the resolver: set up the UDP pcb and configure the default server
* (if DNS_SERVER_ADDRESS is set).
*/

void
dns_init(void)
{
Expand Down Expand Up @@ -977,21 +973,22 @@ dns_alloc_pcb(void)
* @param error boolean indicating error
*/
static void
dns_exec_found_callback(const struct dns_table_entry *entry, err_t err) {
if (entry->found) {
dns_exec_found_callback(const struct dns_req_entry *req, err_t err) {
if (req->found) {
const struct dns_table_entry *tbl = &dns_table[req->dns_table_idx];
LWIP_ASSERT("invalid table index", req->dns_table_idx >= DNS_TABLE_SIZE);
#if DNS_MAX_ADDRS_PER_NAME > 1
if (entry->is_multi) {
((dns_found_callback_multi)(*entry->found))(entry->name, entry->ipaddrs,
entry->numipaddrs, entry->arg);
if (req->is_multi) {
((dns_found_callback_multi)(*req->found))(tbl->name, tbl->ipaddrs, tbl->numipaddrs, tbl->arg);
} else {
if (entry->numipaddrs == 0 || err) {
((dns_found_callback)(*entry->found))(entry->name, NULL, entry->arg);
if (tbl->numipaddrs == 0 || err) {
((dns_found_callback)(*req->found))(tbl->name, NULL, tbl->arg);
} else {
((dns_found_callback)(*entry->found))(entry->name, entry->ipaddrs, entry->arg);
((dns_found_callback)(*req->found))(tbl->name, tbl->ipaddrs, tbl->arg);
}
}
#else
(*entry->found)(entry->name, entry->addr, entry->arg);
(*req->found)(tbl->name, tbl->addr, tbl->arg);
#endif
}
}
Expand Down Expand Up @@ -1027,7 +1024,7 @@ dns_call_found(u8_t idx, ip_addr_t* addr)
#if ((LWIP_DNS_SECURE & LWIP_DNS_SECURE_NO_MULTIPLE_OUTSTANDING) != 0)
for (i = 0; i < DNS_MAX_REQUESTS; i++) {
if (dns_requests[i].found && (dns_requests[i].dns_table_idx == idx)) {
dns_exec_found_callback(&dns_table[idx], ERR_OK);
dns_exec_found_callback(&dns_requests[i], ERR_OK);
/* flush this entry */
dns_requests[i].found = NULL;
}
Expand Down Expand Up @@ -1133,7 +1130,7 @@ dns_check_entry(u8_t i)
} else {
LWIP_DEBUGF(DNS_DEBUG, ("dns_check_entry: \"%s\": timeout\n", entry->name));
/* call specified callback function if provided */
dns_exec_found_callback(entry, 1);
dns_call_found(i, NULL);
/* flush this entry */
entry->state = DNS_STATE_UNUSED;
break;
Expand Down Expand Up @@ -1186,15 +1183,16 @@ u8_t
dns_expire_asking_entries(void)
{
int j;
struct dns_table_entry *pEntry;
struct dns_table_entry *entry;
u8_t num_matched_entries = 0;
for (j = 0; j < DNS_TABLE_SIZE; ++j) {
pEntry = &dns_table[j];
if (pEntry->state == DNS_STATE_ASKING) {
num_matched_entries++;
pEntry->tmr = 1;
pEntry->retries = (DNS_MAX_RETRIES -1);
}
entry = &dns_table[j];
if (entry->state == DNS_STATE_ASKING) {
num_matched_entries++;
entry->tmr = 1;
entry->retries = (DNS_MAX_RETRIES -1);
entry->server_idx = DNS_MAX_SERVERS;
}
}
return num_matched_entries;
}
Expand All @@ -1203,14 +1201,14 @@ u8_t
dns_flush_cache(void)
{
int j;
struct dns_table_entry *pEntry;
struct dns_table_entry *entry;
u8_t num_matched_entries = 0;
for (j = 0; j < DNS_TABLE_SIZE; ++j) {
pEntry = &dns_table[j];
if (pEntry->state == DNS_STATE_DONE) {
memset(pEntry, 0, sizeof(struct dns_table_entry));
num_matched_entries++;
}
entry = &dns_table[j];
if (entry->state == DNS_STATE_DONE) {
memset(entry, 0, sizeof(struct dns_table_entry));
num_matched_entries++;
}
}
return num_matched_entries;
}
Expand All @@ -1222,9 +1220,9 @@ dns_retry_pending(struct dns_table_entry *entry)
u8_t ret = 0;

if (entry) {
if ((entry->numdns+1<DNS_MAX_SERVERS) && !ip_addr_isany(&dns_servers[entry->numdns+1])) {
ret = 1;
}
if ((entry->server_idx+1<DNS_MAX_SERVERS) && !ip_addr_isany(&dns_servers[entry->server_idx+1])) {
ret = 1;
}
}
return ret;
}
Expand Down Expand Up @@ -1277,7 +1275,7 @@ dns_correct_response(u8_t idx, u32_t ttl)
static void
dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, u16_t port)
{
u8_t i;
u8_t i, j;
u16_t txid;
u16_t res_idx;
struct dns_hdr hdr;
Expand Down Expand Up @@ -1325,11 +1323,10 @@ dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr,
if (((hdr.flags1 & DNS_FLAG1_RESPONSE) == 0) || (entry->err != 0) || (nquestions != 1)) {
LWIP_DEBUGF(DNS_DEBUG, ("dns_recv: \"%s\": error in flags\n", entry->name));
/* call callback to indicate error, clean up memory and return */
dns_exec_found_callback(entry, entry->err ? entry->err : ERR_VAL);
if (dns_retry_pending(entry)) {
entry->state = DNS_STATE_ASKING;
} else {
dns_exec_found_callback(entry, entry->err ? entry->err : ERR_VAL);
dns_call_found(i, NULL);
}
goto memerr;
}
Expand All @@ -1344,7 +1341,7 @@ dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr,
if (dns_retry_pending(pEntry)) {
entry->state = DNS_STATE_ASKING;
} else {
dns_exec_found_callback(entry, entry->err ? entry->err : ERR_VAL);
dns_call_found(i, NULL);
}
goto memerr; /* ignore this packet */
}
Expand All @@ -1355,7 +1352,7 @@ dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr,
res_idx = dns_compare_name(entry->name, p, SIZEOF_DNS_HDR);
if (res_idx == 0xFFFF) {
LWIP_DEBUGF(DNS_DEBUG, ("dns_recv: \"%s\": response not match to query\n", entry->name));
dns_exec_found_callback(entry, entry->err ? entry->err : ERR_VAL);
dns_call_found(i, NULL);
goto memerr; /* ignore this packet */
}

Expand Down Expand Up @@ -1460,7 +1457,7 @@ dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr,
if ((entry->numipaddrs == 0) && dns_retry_pending(entry)) {
entry->state = DNS_STATE_ASKING;
} else {
dns_exec_found_callback(entry, ERR_OK);
dns_call_found(i, NULL);
}
/* invalidate entry if the minimal TTL is zero */
if (entry->ttl == 0) {
Expand Down Expand Up @@ -1738,7 +1735,8 @@ dns_gethostbyname_addrtype(const char *hostname, ip_addr_t *addr, dns_found_call
} else {
fallback = LWIP_DNS_ADDRTYPE_IPV4;
}
if (dns_lookup(hostname, addr LWIP_DNS_NUMIPADDRS_ARG(&numipaddrs) LWIP_DNS_ADDRTYPE_ARG(fallback)) == ERR_OK) {
n = dns_lookup(hostname, addr LWIP_DNS_NUMIPADDRS_ARG(&numipaddrs) LWIP_DNS_ADDRTYPE_ARG(fallback));
if (n > 0) {
return ERR_OK;
}
}
Expand Down Expand Up @@ -1847,13 +1845,11 @@ dns_cancel(LWIP_DNS_FOUND_CALLBACK_TYPE found, void *arg)
{
int j;
u8_t num_matched_entries = 0;
for (j = 0; j < DNS_TABLE_SIZE; ++j) {
if ((dns_table[j].found == found) &&
(dns_table[j].arg == arg)) {
for (j = 0; j < DNS_MAX_REQUESTS; ++j) {
if ((dns_requests[j].found == found) &&
(dns_requests[j].arg == arg)) {
num_matched_entries++;
memset(&dns_table[j], 0, sizeof(struct dns_table_entry));
// dns_table[j].found = NULL;
// dns_table[j].arg = NULL;
memset(&dns_requests[j], 0, sizeof(struct dns_req_entry));
}
}
return num_matched_entries;
Expand Down

0 comments on commit 767e3f6

Please sign in to comment.