From patchwork Wed Apr 8 06:41:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Hershberger X-Patchwork-Id: 459111 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id B3237140082 for ; Wed, 8 Apr 2015 16:43:41 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A65B0A742D; Wed, 8 Apr 2015 08:43:38 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id bTwg87XcvqWr; Wed, 8 Apr 2015 08:43:38 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 66923A7423; Wed, 8 Apr 2015 08:43:37 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id B0149A7440 for ; Wed, 8 Apr 2015 08:43:30 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id m5tRKfMoIEII for ; Wed, 8 Apr 2015 08:43:30 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from ni.com (skprod2.natinst.com [130.164.80.23]) by theia.denx.de (Postfix) with ESMTPS id 22F3DA7422 for ; Wed, 8 Apr 2015 08:43:27 +0200 (CEST) Received: from us-aus-mgwout2.amer.corp.natinst.com (nb-snip2-1338.natinst.com [130.164.19.135]) by us-aus-skprod2.natinst.com (8.15.0.59/8.15.0.59) with ESMTP id t386hQFR008097 for ; Wed, 8 Apr 2015 01:43:26 -0500 Received: from linux-xvxi.natinst.com ([130.164.14.198]) by us-aus-mgwout2.amer.corp.natinst.com (Lotus Domino Release 8.5.3FP6) with ESMTP id 2015040801432607-960401 ; Wed, 8 Apr 2015 01:43:26 -0500 From: Joe Hershberger To: u-boot@lists.denx.de Date: Wed, 8 Apr 2015 01:41:15 -0500 Message-Id: <1428475285-25836-16-git-send-email-joe.hershberger@ni.com> X-Mailer: git-send-email 1.7.11.5 In-Reply-To: <1428475285-25836-1-git-send-email-joe.hershberger@ni.com> References: <1428095695-23368-1-git-send-email-joe.hershberger@ni.com> <1428475285-25836-1-git-send-email-joe.hershberger@ni.com> X-MIMETrack: Itemize by SMTP Server on US-AUS-MGWOut2/AUS/H/NIC(Release 8.5.3FP6|November 21, 2013) at 04/08/2015 01:43:26 AM, Serialize by Router on US-AUS-MGWOut2/AUS/H/NIC(Release 8.5.3FP6|November 21, 2013) at 04/08/2015 01:43:26 AM, Serialize complete at 04/08/2015 01:43:26 AM X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2015-04-08_03:, , signatures=0 Cc: Joe Hershberger Subject: [U-Boot] [PATCH v2 15/25] net: cosmetic: Clean up DNS variables and functions X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Make a thorough pass through all variables and function names contained within dns.c and remove CamelCase and improve naming. Signed-off-by: Joe Hershberger Acked-by: Simon Glass --- Changes in v2: None common/cmd_net.c | 6 +++--- include/net.h | 4 ++-- net/dns.c | 53 +++++++++++++++++++++++++---------------------------- net/dns.h | 2 +- net/net.c | 2 +- 5 files changed, 32 insertions(+), 35 deletions(-) diff --git a/common/cmd_net.c b/common/cmd_net.c index 1deebf2..0270ac3 100644 --- a/common/cmd_net.c +++ b/common/cmd_net.c @@ -393,12 +393,12 @@ int do_dns(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) return CMD_RET_FAILURE; } - NetDNSResolve = argv[1]; + net_dns_resolve = argv[1]; if (argc == 3) - NetDNSenvvar = argv[2]; + net_dns_env_var = argv[2]; else - NetDNSenvvar = NULL; + net_dns_env_var = NULL; if (NetLoop(DNS) < 0) { printf("dns lookup of %s failed, check setup\n", argv[1]); diff --git a/include/net.h b/include/net.h index 9343ade..1275ffe 100644 --- a/include/net.h +++ b/include/net.h @@ -502,8 +502,8 @@ extern u32 net_boot_file_size; extern u32 net_boot_file_expected_size_in_blocks; #if defined(CONFIG_CMD_DNS) -extern char *NetDNSResolve; /* The host to resolve */ -extern char *NetDNSenvvar; /* the env var to put the ip into */ +extern char *net_dns_resolve; /* The host to resolve */ +extern char *net_dns_env_var; /* the env var to put the ip into */ #endif #if defined(CONFIG_CMD_PING) diff --git a/net/dns.c b/net/dns.c index 50d78ae..cf4ed86 100644 --- a/net/dns.c +++ b/net/dns.c @@ -29,13 +29,12 @@ #include "dns.h" -char *NetDNSResolve; /* The host to resolve */ -char *NetDNSenvvar; /* The envvar to store the answer in */ +char *net_dns_resolve; /* The host to resolve */ +char *net_dns_env_var; /* The envvar to store the answer in */ -static int DnsOurPort; +static int dns_our_port; -static void -DnsSend(void) +static void dns_send(void) { struct header *header; int n, name_len; @@ -44,12 +43,12 @@ DnsSend(void) const char *name; 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); p = pkt; /* Prepare DNS packet header */ - header = (struct header *) pkt; + header = (struct header *)pkt; header->tid = 1; header->flags = htons(0x100); /* standard query */ header->nqueries = htons(1); /* Just one query */ @@ -59,7 +58,7 @@ DnsSend(void) /* Encode DNS 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 { s = strchr(name, '.'); @@ -88,15 +87,14 @@ DnsSend(void) n = p - pkt; /* Total packet length */ debug("Packet size %d\n", n); - DnsOurPort = random_port(); + dns_our_port = random_port(); 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"); } -static void -DnsTimeout(void) +static void dns_timeout_handler(void) { puts("Timeout\n"); net_set_state(NETLOOP_FAIL); @@ -109,20 +107,20 @@ static void dns_handler(uchar *pkt, unsigned dest, struct in_addr sip, const unsigned char *p, *e, *s; u16 type, i; int found, stop, dlen; - char IPStr[22]; + char ip_str[22]; struct in_addr ip_addr; debug("%s\n", __func__); - if (dest != DnsOurPort) + if (dest != dns_our_port) return; for (i = 0; i < len; i += 4) 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: */ - header = (struct header *) pkt; + header = (struct header *)pkt; if (ntohs(header->nqueries) != 1) return; @@ -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 */ for (found = stop = 0; !stop && &p[12] < e; ) { - /* Skip possible name in CNAME answer */ if (*p != 0xc0) { while (*p && &p[12] < e) @@ -170,7 +167,8 @@ static void dns_handler(uchar *pkt, unsigned dest, struct in_addr sip, p += 12 + dlen; } else if (type == DNS_A_RECORD) { debug("Found A-record\n"); - found = stop = 1; + found = 1; + stop = 1; } else { debug("Unknown type\n"); stop = 1; @@ -178,33 +176,32 @@ static void dns_handler(uchar *pkt, unsigned dest, struct in_addr sip, } if (found && &p[12] < e) { - dlen = get_unaligned_be16(p+10); p += 12; memcpy(&ip_addr, p, 4); if (p + dlen <= e) { - ip_to_string(ip_addr, IPStr); - printf("%s\n", IPStr); - if (NetDNSenvvar) - setenv(NetDNSenvvar, IPStr); - } else + ip_to_string(ip_addr, ip_str); + printf("%s\n", ip_str); + if (net_dns_env_var) + setenv(net_dns_env_var, ip_str); + } else { puts("server responded with invalid IP number\n"); + } } net_set_state(NETLOOP_SUCCESS); } -void -DnsStart(void) +void dns_start(void) { debug("%s\n", __func__); - NetSetTimeout(DNS_TIMEOUT, DnsTimeout); + NetSetTimeout(DNS_TIMEOUT, dns_timeout_handler); net_set_udp_handler(dns_handler); /* Clear a previous MAC address, the server IP might have changed. */ memset(net_server_ethaddr, 0, sizeof(net_server_ethaddr)); - DnsSend(); + dns_send(); } diff --git a/net/dns.h b/net/dns.h index dbc3890..c4e96af 100644 --- a/net/dns.h +++ b/net/dns.h @@ -31,6 +31,6 @@ struct header { unsigned char data[1]; /* Data, variable length */ }; -extern void DnsStart(void); /* Begin DNS */ +void dns_start(void); /* Begin DNS */ #endif diff --git a/net/net.c b/net/net.c index 3c8b608..1133f79 100644 --- a/net/net.c +++ b/net/net.c @@ -427,7 +427,7 @@ restart: #endif #if defined(CONFIG_CMD_DNS) case DNS: - DnsStart(); + dns_start(); break; #endif #if defined(CONFIG_CMD_LINK_LOCAL)