Commit 786eac5f authored by Joe Hershberger's avatar Joe Hershberger Committed by Simon Glass

net: cosmetic: Clean up DNS variables and functions

Make a thorough pass through all variables and function names contained
within dns.c and remove CamelCase and improve naming.
Signed-off-by: default avatarJoe Hershberger <joe.hershberger@ni.com>
Acked-by: default avatarSimon Glass <sjg@chromium.org>
parent 6aede5b7
...@@ -393,12 +393,12 @@ int do_dns(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) ...@@ -393,12 +393,12 @@ int do_dns(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
return CMD_RET_FAILURE; return CMD_RET_FAILURE;
} }
NetDNSResolve = argv[1]; net_dns_resolve = argv[1];
if (argc == 3) if (argc == 3)
NetDNSenvvar = argv[2]; net_dns_env_var = argv[2];
else else
NetDNSenvvar = NULL; net_dns_env_var = NULL;
if (NetLoop(DNS) < 0) { if (NetLoop(DNS) < 0) {
printf("dns lookup of %s failed, check setup\n", argv[1]); printf("dns lookup of %s failed, check setup\n", argv[1]);
......
...@@ -508,8 +508,8 @@ extern u32 net_boot_file_size; ...@@ -508,8 +508,8 @@ extern u32 net_boot_file_size;
extern u32 net_boot_file_expected_size_in_blocks; extern u32 net_boot_file_expected_size_in_blocks;
#if defined(CONFIG_CMD_DNS) #if defined(CONFIG_CMD_DNS)
extern char *NetDNSResolve; /* The host to resolve */ extern char *net_dns_resolve; /* The host to resolve */
extern char *NetDNSenvvar; /* the env var to put the ip into */ extern char *net_dns_env_var; /* the env var to put the ip into */
#endif #endif
#if defined(CONFIG_CMD_PING) #if defined(CONFIG_CMD_PING)
......
...@@ -29,13 +29,12 @@ ...@@ -29,13 +29,12 @@
#include "dns.h" #include "dns.h"
char *NetDNSResolve; /* The host to resolve */ char *net_dns_resolve; /* The host to resolve */
char *NetDNSenvvar; /* The envvar to store the answer in */ char *net_dns_env_var; /* The envvar to store the answer in */
static int DnsOurPort; static int dns_our_port;
static void static void dns_send(void)
DnsSend(void)
{ {
struct header *header; struct header *header;
int n, name_len; int n, name_len;
...@@ -44,12 +43,12 @@ DnsSend(void) ...@@ -44,12 +43,12 @@ DnsSend(void)
const char *name; const char *name;
enum dns_query_type qtype = DNS_A_RECORD; enum dns_query_type qtype = DNS_A_RECORD;
name = NetDNSResolve; name = net_dns_resolve;
pkt = (uchar *)(net_tx_packet + net_eth_hdr_size() + IP_UDP_HDR_SIZE); pkt = (uchar *)(net_tx_packet + net_eth_hdr_size() + IP_UDP_HDR_SIZE);
p = pkt; p = pkt;
/* Prepare DNS packet header */ /* Prepare DNS packet header */
header = (struct header *) pkt; header = (struct header *)pkt;
header->tid = 1; header->tid = 1;
header->flags = htons(0x100); /* standard query */ header->flags = htons(0x100); /* standard query */
header->nqueries = htons(1); /* Just one query */ header->nqueries = htons(1); /* Just one query */
...@@ -59,7 +58,7 @@ DnsSend(void) ...@@ -59,7 +58,7 @@ DnsSend(void)
/* Encode DNS name */ /* Encode DNS name */
name_len = strlen(name); name_len = strlen(name);
p = (uchar *) &header->data; /* For encoding host name into packet */ p = (uchar *)&header->data; /* For encoding host name into packet */
do { do {
s = strchr(name, '.'); s = strchr(name, '.');
...@@ -88,15 +87,14 @@ DnsSend(void) ...@@ -88,15 +87,14 @@ DnsSend(void)
n = p - pkt; /* Total packet length */ n = p - pkt; /* Total packet length */
debug("Packet size %d\n", n); debug("Packet size %d\n", n);
DnsOurPort = random_port(); dns_our_port = random_port();
net_send_udp_packet(net_server_ethaddr, net_dns_server, net_send_udp_packet(net_server_ethaddr, net_dns_server,
DNS_SERVICE_PORT, DnsOurPort, n); DNS_SERVICE_PORT, dns_our_port, n);
debug("DNS packet sent\n"); debug("DNS packet sent\n");
} }
static void static void dns_timeout_handler(void)
DnsTimeout(void)
{ {
puts("Timeout\n"); puts("Timeout\n");
net_set_state(NETLOOP_FAIL); net_set_state(NETLOOP_FAIL);
...@@ -109,20 +107,20 @@ static void dns_handler(uchar *pkt, unsigned dest, struct in_addr sip, ...@@ -109,20 +107,20 @@ static void dns_handler(uchar *pkt, unsigned dest, struct in_addr sip,
const unsigned char *p, *e, *s; const unsigned char *p, *e, *s;
u16 type, i; u16 type, i;
int found, stop, dlen; int found, stop, dlen;
char IPStr[22]; char ip_str[22];
struct in_addr ip_addr; struct in_addr ip_addr;
debug("%s\n", __func__); debug("%s\n", __func__);
if (dest != DnsOurPort) if (dest != dns_our_port)
return; return;
for (i = 0; i < len; i += 4) for (i = 0; i < len; i += 4)
debug("0x%p - 0x%.2x 0x%.2x 0x%.2x 0x%.2x\n", debug("0x%p - 0x%.2x 0x%.2x 0x%.2x 0x%.2x\n",
pkt+i, pkt[i], pkt[i+1], pkt[i+2], pkt[i+3]); pkt+i, pkt[i], pkt[i+1], pkt[i+2], pkt[i+3]);
/* We sent one query. We want to have a single answer: */ /* We sent one query. We want to have a single answer: */
header = (struct header *) pkt; header = (struct header *)pkt;
if (ntohs(header->nqueries) != 1) if (ntohs(header->nqueries) != 1)
return; return;
...@@ -151,7 +149,6 @@ static void dns_handler(uchar *pkt, unsigned dest, struct in_addr sip, ...@@ -151,7 +149,6 @@ static void dns_handler(uchar *pkt, unsigned dest, struct in_addr sip,
/* Loop through the answers, we want A type answer */ /* Loop through the answers, we want A type answer */
for (found = stop = 0; !stop && &p[12] < e; ) { for (found = stop = 0; !stop && &p[12] < e; ) {
/* Skip possible name in CNAME answer */ /* Skip possible name in CNAME answer */
if (*p != 0xc0) { if (*p != 0xc0) {
while (*p && &p[12] < e) while (*p && &p[12] < e)
...@@ -170,7 +167,8 @@ static void dns_handler(uchar *pkt, unsigned dest, struct in_addr sip, ...@@ -170,7 +167,8 @@ static void dns_handler(uchar *pkt, unsigned dest, struct in_addr sip,
p += 12 + dlen; p += 12 + dlen;
} else if (type == DNS_A_RECORD) { } else if (type == DNS_A_RECORD) {
debug("Found A-record\n"); debug("Found A-record\n");
found = stop = 1; found = 1;
stop = 1;
} else { } else {
debug("Unknown type\n"); debug("Unknown type\n");
stop = 1; stop = 1;
...@@ -178,33 +176,32 @@ static void dns_handler(uchar *pkt, unsigned dest, struct in_addr sip, ...@@ -178,33 +176,32 @@ static void dns_handler(uchar *pkt, unsigned dest, struct in_addr sip,
} }
if (found && &p[12] < e) { if (found && &p[12] < e) {
dlen = get_unaligned_be16(p+10); dlen = get_unaligned_be16(p+10);
p += 12; p += 12;
memcpy(&ip_addr, p, 4); memcpy(&ip_addr, p, 4);
if (p + dlen <= e) { if (p + dlen <= e) {
ip_to_string(ip_addr, IPStr); ip_to_string(ip_addr, ip_str);
printf("%s\n", IPStr); printf("%s\n", ip_str);
if (NetDNSenvvar) if (net_dns_env_var)
setenv(NetDNSenvvar, IPStr); setenv(net_dns_env_var, ip_str);
} else } else {
puts("server responded with invalid IP number\n"); puts("server responded with invalid IP number\n");
}
} }
net_set_state(NETLOOP_SUCCESS); net_set_state(NETLOOP_SUCCESS);
} }
void void dns_start(void)
DnsStart(void)
{ {
debug("%s\n", __func__); debug("%s\n", __func__);
NetSetTimeout(DNS_TIMEOUT, DnsTimeout); NetSetTimeout(DNS_TIMEOUT, dns_timeout_handler);
net_set_udp_handler(dns_handler); net_set_udp_handler(dns_handler);
/* Clear a previous MAC address, the server IP might have changed. */ /* Clear a previous MAC address, the server IP might have changed. */
memset(net_server_ethaddr, 0, sizeof(net_server_ethaddr)); memset(net_server_ethaddr, 0, sizeof(net_server_ethaddr));
DnsSend(); dns_send();
} }
...@@ -31,6 +31,6 @@ struct header { ...@@ -31,6 +31,6 @@ struct header {
unsigned char data[1]; /* Data, variable length */ unsigned char data[1]; /* Data, variable length */
}; };
extern void DnsStart(void); /* Begin DNS */ void dns_start(void); /* Begin DNS */
#endif #endif
...@@ -427,7 +427,7 @@ restart: ...@@ -427,7 +427,7 @@ restart:
#endif #endif
#if defined(CONFIG_CMD_DNS) #if defined(CONFIG_CMD_DNS)
case DNS: case DNS:
DnsStart(); dns_start();
break; break;
#endif #endif
#if defined(CONFIG_CMD_LINK_LOCAL) #if defined(CONFIG_CMD_LINK_LOCAL)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment