DNS: minor coding style fix: pEntry -> entry

This commit is contained in:
Simon Goldschmidt 2014-09-05 21:15:50 +02:00
parent 13add693db
commit 6c7357bbf9

View File

@ -763,7 +763,7 @@ again:
} }
/** /**
* dns_check_entry() - see if pEntry has not yet been queried and, if so, sends out a query. * dns_check_entry() - see if entry has not yet been queried and, if so, sends out a query.
* Check an entry in the dns_table: * Check an entry in the dns_table:
* - send out query for new entries * - send out query for new entries
* - retry old pending entries on timeout (also with different servers) * - retry old pending entries on timeout (also with different servers)
@ -775,24 +775,24 @@ static void
dns_check_entry(u8_t i) dns_check_entry(u8_t i)
{ {
err_t err; err_t err;
struct dns_table_entry *pEntry = &dns_table[i]; struct dns_table_entry *entry = &dns_table[i];
LWIP_ASSERT("array index out of bounds", i < DNS_TABLE_SIZE); LWIP_ASSERT("array index out of bounds", i < DNS_TABLE_SIZE);
switch (pEntry->state) { switch (entry->state) {
case DNS_STATE_NEW: { case DNS_STATE_NEW: {
u16_t txid; u16_t txid;
/* initialize new entry */ /* initialize new entry */
txid = dns_create_txid(); txid = dns_create_txid();
pEntry->txid = txid; entry->txid = txid;
pEntry->state = DNS_STATE_ASKING; entry->state = DNS_STATE_ASKING;
pEntry->numdns = 0; entry->numdns = 0;
pEntry->tmr = 1; entry->tmr = 1;
pEntry->retries = 0; entry->retries = 0;
/* send DNS packet for this entry */ /* send DNS packet for this entry */
err = dns_send(pEntry->numdns, pEntry->name, txid); err = dns_send(entry->numdns, entry->name, txid);
if (err != ERR_OK) { if (err != ERR_OK) {
LWIP_DEBUGF(DNS_DEBUG | LWIP_DBG_LEVEL_WARNING, LWIP_DEBUGF(DNS_DEBUG | LWIP_DBG_LEVEL_WARNING,
("dns_send returned error: %s\n", lwip_strerr(err))); ("dns_send returned error: %s\n", lwip_strerr(err)));
@ -801,29 +801,29 @@ dns_check_entry(u8_t i)
} }
case DNS_STATE_ASKING: case DNS_STATE_ASKING:
if (--pEntry->tmr == 0) { if (--entry->tmr == 0) {
if (++pEntry->retries == DNS_MAX_RETRIES) { if (++entry->retries == DNS_MAX_RETRIES) {
if ((pEntry->numdns+1<DNS_MAX_SERVERS) && !ip_addr_isany(&dns_servers[pEntry->numdns+1])) { if ((entry->numdns+1<DNS_MAX_SERVERS) && !ip_addr_isany(&dns_servers[entry->numdns+1])) {
/* change of server */ /* change of server */
pEntry->numdns++; entry->numdns++;
pEntry->tmr = 1; entry->tmr = 1;
pEntry->retries = 0; entry->retries = 0;
break; break;
} else { } else {
LWIP_DEBUGF(DNS_DEBUG, ("dns_check_entry: \"%s\": timeout\n", pEntry->name)); LWIP_DEBUGF(DNS_DEBUG, ("dns_check_entry: \"%s\": timeout\n", entry->name));
/* call specified callback function if provided */ /* call specified callback function if provided */
dns_call_found(i, NULL); dns_call_found(i, NULL);
/* flush this entry */ /* flush this entry */
pEntry->state = DNS_STATE_UNUSED; entry->state = DNS_STATE_UNUSED;
break; break;
} }
} }
/* wait longer for the next retry */ /* wait longer for the next retry */
pEntry->tmr = pEntry->retries; entry->tmr = entry->retries;
/* send DNS packet for this entry */ /* send DNS packet for this entry */
err = dns_send(pEntry->numdns, pEntry->name, pEntry->txid); err = dns_send(entry->numdns, entry->name, entry->txid);
if (err != ERR_OK) { if (err != ERR_OK) {
LWIP_DEBUGF(DNS_DEBUG | LWIP_DBG_LEVEL_WARNING, LWIP_DEBUGF(DNS_DEBUG | LWIP_DBG_LEVEL_WARNING,
("dns_send returned error: %s\n", lwip_strerr(err))); ("dns_send returned error: %s\n", lwip_strerr(err)));
@ -832,10 +832,10 @@ dns_check_entry(u8_t i)
break; break;
case DNS_STATE_DONE: case DNS_STATE_DONE:
/* if the time to live is nul */ /* if the time to live is nul */
if ((pEntry->ttl == 0) || (--pEntry->ttl == 0)) { if ((entry->ttl == 0) || (--entry->ttl == 0)) {
LWIP_DEBUGF(DNS_DEBUG, ("dns_check_entry: \"%s\": flush\n", pEntry->name)); LWIP_DEBUGF(DNS_DEBUG, ("dns_check_entry: \"%s\": flush\n", entry->name));
/* flush this entry, there cannot be any related pending entries in this state */ /* flush this entry, there cannot be any related pending entries in this state */
pEntry->state = DNS_STATE_UNUSED; entry->state = DNS_STATE_UNUSED;
} }
break; break;
case DNS_STATE_UNUSED: case DNS_STATE_UNUSED:
@ -900,13 +900,13 @@ dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *addr, u16_t
hdr = (struct dns_hdr*)dns_payload; hdr = (struct dns_hdr*)dns_payload;
txid = htons(hdr->id); txid = htons(hdr->id);
for (i = 0; i < DNS_TABLE_SIZE; i++) { for (i = 0; i < DNS_TABLE_SIZE; i++) {
struct dns_table_entry *pEntry = &dns_table[i]; struct dns_table_entry *entry = &dns_table[i];
entry_idx = i; entry_idx = i;
if ((pEntry->state == DNS_STATE_ASKING) && if ((entry->state == DNS_STATE_ASKING) &&
(pEntry->txid == txid)) { (entry->txid == txid)) {
/* This entry is now completed. */ /* This entry is now completed. */
pEntry->state = DNS_STATE_DONE; entry->state = DNS_STATE_DONE;
pEntry->err = hdr->flags2 & DNS_FLAG2_ERR_MASK; entry->err = hdr->flags2 & DNS_FLAG2_ERR_MASK;
/* We only care about the question(s) and the answers. The authrr /* We only care about the question(s) and the answers. The authrr
and the extrarr are simply discarded. */ and the extrarr are simply discarded. */
@ -914,24 +914,24 @@ dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *addr, u16_t
nanswers = htons(hdr->numanswers); nanswers = htons(hdr->numanswers);
/* Check for error. If so, call callback to inform. */ /* Check for error. If so, call callback to inform. */
if (((hdr->flags1 & DNS_FLAG1_RESPONSE) == 0) || (pEntry->err != 0) || (nquestions != 1)) { if (((hdr->flags1 & DNS_FLAG1_RESPONSE) == 0) || (entry->err != 0) || (nquestions != 1)) {
LWIP_DEBUGF(DNS_DEBUG, ("dns_recv: \"%s\": error in flags\n", pEntry->name)); LWIP_DEBUGF(DNS_DEBUG, ("dns_recv: \"%s\": error in flags\n", entry->name));
/* call callback to indicate error, clean up memory and return */ /* call callback to indicate error, clean up memory and return */
goto responseerr; goto responseerr;
} }
/* Check whether response comes from the same network address to which the /* Check whether response comes from the same network address to which the
question was sent. (RFC 5452) */ question was sent. (RFC 5452) */
if (!ip_addr_cmp(addr, &dns_servers[pEntry->numdns])) { if (!ip_addr_cmp(addr, &dns_servers[entry->numdns])) {
/* call callback to indicate error, clean up memory and return */ /* call callback to indicate error, clean up memory and return */
goto responseerr; goto responseerr;
} }
/* Check if the name in the "question" part match with the name in the entry and /* Check if the name in the "question" part match with the name in the entry and
skip it if equal. */ skip it if equal. */
ptr = dns_compare_name(pEntry->name, (char*)dns_payload + SIZEOF_DNS_HDR); ptr = dns_compare_name(entry->name, (char*)dns_payload + SIZEOF_DNS_HDR);
if (ptr == NULL) { if (ptr == NULL) {
LWIP_DEBUGF(DNS_DEBUG, ("dns_recv: \"%s\": response not match to query\n", pEntry->name)); LWIP_DEBUGF(DNS_DEBUG, ("dns_recv: \"%s\": response not match to query\n", entry->name));
/* call callback to indicate error, clean up memory and return */ /* call callback to indicate error, clean up memory and return */
goto responseerr; goto responseerr;
} }
@ -939,7 +939,7 @@ dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *addr, u16_t
/* check if "question" part matches the request */ /* check if "question" part matches the request */
SMEMCPY(&qry, ptr, SIZEOF_DNS_QUERY); SMEMCPY(&qry, ptr, SIZEOF_DNS_QUERY);
if((qry.type != PP_HTONS(DNS_RRTYPE_A)) || (qry.cls != PP_HTONS(DNS_RRCLASS_IN))) { if((qry.type != PP_HTONS(DNS_RRTYPE_A)) || (qry.cls != PP_HTONS(DNS_RRCLASS_IN))) {
LWIP_DEBUGF(DNS_DEBUG, ("dns_recv: \"%s\": response not match to query\n", pEntry->name)); LWIP_DEBUGF(DNS_DEBUG, ("dns_recv: \"%s\": response not match to query\n", entry->name));
/* call callback to indicate error, clean up memory and return */ /* call callback to indicate error, clean up memory and return */
goto responseerr; goto responseerr;
} }
@ -955,18 +955,18 @@ dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *addr, u16_t
if((ans.type == PP_HTONS(DNS_RRTYPE_A)) && (ans.cls == PP_HTONS(DNS_RRCLASS_IN)) && if((ans.type == PP_HTONS(DNS_RRTYPE_A)) && (ans.cls == PP_HTONS(DNS_RRCLASS_IN)) &&
(ans.len == PP_HTONS(sizeof(ip_addr_t))) ) { (ans.len == PP_HTONS(sizeof(ip_addr_t))) ) {
/* read the answer resource record's TTL, and maximize it if needed */ /* read the answer resource record's TTL, and maximize it if needed */
pEntry->ttl = ntohl(ans.ttl); entry->ttl = ntohl(ans.ttl);
if (pEntry->ttl > DNS_MAX_TTL) { if (entry->ttl > DNS_MAX_TTL) {
pEntry->ttl = DNS_MAX_TTL; entry->ttl = DNS_MAX_TTL;
} }
/* read the IP address after answer resource record's header */ /* read the IP address after answer resource record's header */
SMEMCPY(&(pEntry->ipaddr), (ptr + SIZEOF_DNS_ANSWER), sizeof(ip_addr_t)); SMEMCPY(&(entry->ipaddr), (ptr + SIZEOF_DNS_ANSWER), sizeof(ip_addr_t));
LWIP_DEBUGF(DNS_DEBUG, ("dns_recv: \"%s\": response = ", pEntry->name)); LWIP_DEBUGF(DNS_DEBUG, ("dns_recv: \"%s\": response = ", entry->name));
ip_addr_debug_print(DNS_DEBUG, (&(pEntry->ipaddr))); ip_addr_debug_print(DNS_DEBUG, (&(entry->ipaddr)));
LWIP_DEBUGF(DNS_DEBUG, ("\n")); LWIP_DEBUGF(DNS_DEBUG, ("\n"));
/* call specified callback function if provided */ /* call specified callback function if provided */
dns_call_found(entry_idx, &pEntry->ipaddr); dns_call_found(entry_idx, &entry->ipaddr);
if (pEntry->ttl == 0) { if (entry->ttl == 0) {
/* RFC 883, page 29: "Zero values are /* RFC 883, page 29: "Zero values are
interpreted to mean that the RR can only be used for the interpreted to mean that the RR can only be used for the
transaction in progress, and should not be cached." transaction in progress, and should not be cached."
@ -980,7 +980,7 @@ dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *addr, u16_t
} }
--nanswers; --nanswers;
} }
LWIP_DEBUGF(DNS_DEBUG, ("dns_recv: \"%s\": error in response\n", pEntry->name)); LWIP_DEBUGF(DNS_DEBUG, ("dns_recv: \"%s\": error in response\n", entry->name));
/* call callback to indicate error, clean up memory and return */ /* call callback to indicate error, clean up memory and return */
goto responseerr; goto responseerr;
} }
@ -1018,7 +1018,7 @@ dns_enqueue(const char *name, size_t hostnamelen, dns_found_callback found,
{ {
u8_t i; u8_t i;
u8_t lseq, lseqi; u8_t lseq, lseqi;
struct dns_table_entry *pEntry = NULL; struct dns_table_entry *entry = NULL;
size_t namelen; size_t namelen;
struct dns_req_entry* req; struct dns_req_entry* req;
@ -1047,15 +1047,15 @@ dns_enqueue(const char *name, size_t hostnamelen, dns_found_callback found,
lseq = 0; lseq = 0;
lseqi = DNS_TABLE_SIZE; lseqi = DNS_TABLE_SIZE;
for (i = 0; i < DNS_TABLE_SIZE; ++i) { for (i = 0; i < DNS_TABLE_SIZE; ++i) {
pEntry = &dns_table[i]; entry = &dns_table[i];
/* is it an unused entry ? */ /* is it an unused entry ? */
if (pEntry->state == DNS_STATE_UNUSED) { if (entry->state == DNS_STATE_UNUSED) {
break; break;
} }
/* check if this is the oldest completed entry */ /* check if this is the oldest completed entry */
if (pEntry->state == DNS_STATE_DONE) { if (entry->state == DNS_STATE_DONE) {
if ((dns_seqno - pEntry->seqno) > lseq) { if ((dns_seqno - entry->seqno) > lseq) {
lseq = dns_seqno - pEntry->seqno; lseq = dns_seqno - entry->seqno;
lseqi = i; lseqi = i;
} }
} }
@ -1070,7 +1070,7 @@ dns_enqueue(const char *name, size_t hostnamelen, dns_found_callback found,
} else { } else {
/* use the oldest completed one */ /* use the oldest completed one */
i = lseqi; i = lseqi;
pEntry = &dns_table[i]; entry = &dns_table[i];
} }
} }
@ -1098,13 +1098,13 @@ dns_enqueue(const char *name, size_t hostnamelen, dns_found_callback found,
LWIP_DEBUGF(DNS_DEBUG, ("dns_enqueue: \"%s\": use DNS entry %"U16_F"\n", name, (u16_t)(i))); LWIP_DEBUGF(DNS_DEBUG, ("dns_enqueue: \"%s\": use DNS entry %"U16_F"\n", name, (u16_t)(i)));
/* fill the entry */ /* fill the entry */
pEntry->state = DNS_STATE_NEW; entry->state = DNS_STATE_NEW;
pEntry->seqno = dns_seqno; entry->seqno = dns_seqno;
req->found = found; req->found = found;
req->arg = callback_arg; req->arg = callback_arg;
namelen = LWIP_MIN(hostnamelen, DNS_MAX_NAME_LENGTH-1); namelen = LWIP_MIN(hostnamelen, DNS_MAX_NAME_LENGTH-1);
MEMCPY(pEntry->name, name, namelen); MEMCPY(entry->name, name, namelen);
pEntry->name[namelen] = 0; entry->name[namelen] = 0;
dns_seqno++; dns_seqno++;