From patchwork Wed May 23 17:58:05 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Hershberger X-Patchwork-Id: 160987 X-Patchwork-Delegate: joe.hershberger@gmail.com 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 45940B6FB6 for ; Thu, 24 May 2012 04:00:22 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 34219280D2; Wed, 23 May 2012 19:59:49 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de 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 fOtXLPy2pf1A; Wed, 23 May 2012 19:59:48 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 897E7280D9; Wed, 23 May 2012 19:58:47 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A5FD7280A2 for ; Wed, 23 May 2012 19:58:24 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de 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 McZIxlXmV49K for ; Wed, 23 May 2012 19:58:23 +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 spamkiller06.natinst.com (mailserver6.natinst.com [130.164.80.6]) by theia.denx.de (Postfix) with ESMTP id 1EC5B28084 for ; Wed, 23 May 2012 19:58:19 +0200 (CEST) Received: from mailserv58-us.natinst.com (nb-hsrp-1338.natinst.com [130.164.19.133]) by spamkiller06.natinst.com (8.14.4/8.14.4) with ESMTP id q4NHwI1G032295; Wed, 23 May 2012 12:58:18 -0500 Received: from localhost.localdomain ([130.164.14.197]) by mailserv58-us.natinst.com (Lotus Domino Release 8.5.2FP3) with ESMTP id 2012052312581833-530913 ; Wed, 23 May 2012 12:58:18 -0500 From: Joe Hershberger To: u-boot@lists.denx.de Date: Wed, 23 May 2012 12:58:05 -0500 Message-Id: <1337795897-19231-10-git-send-email-joe.hershberger@ni.com> X-Mailer: git-send-email 1.6.0.2 In-Reply-To: <1332891772-17279-1-git-send-email-joe.hershberger@ni.com> References: <1332891772-17279-1-git-send-email-joe.hershberger@ni.com> X-MIMETrack: Itemize by SMTP Server on MailServ58-US/AUS/H/NIC(Release 8.5.2FP3|July 10, 2011) at 05/23/2012 12:58:18 PM, Serialize by Router on MailServ58-US/AUS/H/NIC(Release 8.5.2FP3|July 10, 2011) at 05/23/2012 12:58:18 PM, Serialize complete at 05/23/2012 12:58:18 PM X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.7.7724, 1.0.260, 0.0.0000 definitions=2012-05-23_01:2012-05-23, 2012-05-22, 1970-01-01 signatures=0 Cc: Joe Hershberger Subject: [U-Boot] [PATCH v3 09/21] net: cosmetic: Split struct ip_udp_hdr into ip_hdr X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Add a structure that only contains IP header fields to be used by functions that don't need UDP Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE Signed-off-by: Joe Hershberger Cc: Joe Hershberger --- Changes for v2: - Split apart from "Un-typedef variables in net" - Created a new IP_UDP_hdr struct and removed UDP members from IP_hdr - Renamed structs from *_t to *_hdr since they are nolonger types Changes for v3: - Change IP_hdr to ip_hdr - Split this out from the previous patch include/net.h | 32 ++++++++++++++++++++++++-------- net/net.c | 16 ++++++++-------- net/ping.c | 10 +++++----- 3 files changed, 37 insertions(+), 21 deletions(-) diff --git a/include/net.h b/include/net.h index 3e4f304..7692153 100644 --- a/include/net.h +++ b/include/net.h @@ -194,9 +194,9 @@ typedef struct { #define IPPROTO_UDP 17 /* User Datagram Protocol */ /* - * Internet Protocol (IP) + UDP header. + * Internet Protocol (IP) header. */ -struct ip_udp_hdr { +struct ip_hdr { uchar ip_hl_v; /* header length and version */ uchar ip_tos; /* type of service */ ushort ip_len; /* total length */ @@ -207,10 +207,6 @@ struct ip_udp_hdr { ushort ip_sum; /* checksum */ IPaddr_t ip_src; /* Source IP address */ IPaddr_t ip_dst; /* Destination IP address */ - ushort udp_src; /* UDP source port */ - ushort udp_dst; /* UDP destination port */ - ushort udp_len; /* Length of UDP packet */ - ushort udp_xsum; /* Checksum */ }; #define IP_OFFS 0x1fff /* ip offset *= 8 */ @@ -219,10 +215,30 @@ struct ip_udp_hdr { #define IP_FLAGS_DFRAG 0x4000 /* don't fragments */ #define IP_FLAGS_MFRAG 0x2000 /* more fragments */ -#define IP_HDR_SIZE_NO_UDP (sizeof(struct ip_udp_hdr) - 8) +#define IP_HDR_SIZE (sizeof(struct ip_hdr)) + +/* + * Internet Protocol (IP) + UDP header. + */ +struct ip_udp_hdr { + uchar ip_hl_v; /* header length and version */ + uchar ip_tos; /* type of service */ + ushort ip_len; /* total length */ + ushort ip_id; /* identification */ + ushort ip_off; /* fragment offset field */ + uchar ip_ttl; /* time to live */ + uchar ip_p; /* protocol */ + ushort ip_sum; /* checksum */ + IPaddr_t ip_src; /* Source IP address */ + IPaddr_t ip_dst; /* Destination IP address */ + ushort udp_src; /* UDP source port */ + ushort udp_dst; /* UDP destination port */ + ushort udp_len; /* Length of UDP packet */ + ushort udp_xsum; /* Checksum */ +}; #define IP_UDP_HDR_SIZE (sizeof(struct ip_udp_hdr)) -#define UDP_HDR_SIZE (IP_UDP_HDR_SIZE - IP_HDR_SIZE_NO_UDP) +#define UDP_HDR_SIZE (IP_UDP_HDR_SIZE - IP_HDR_SIZE) /* * Address Resolution Protocol (ARP) header. diff --git a/net/net.c b/net/net.c index f0e8a67..2bf5631 100644 --- a/net/net.c +++ b/net/net.c @@ -663,7 +663,7 @@ NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport, int len) static struct rpc_t rpc_specimen; #define IP_PKTSIZE (CONFIG_NET_MAXDEFRAG + sizeof(rpc_specimen.u.reply)) -#define IP_MAXUDP (IP_PKTSIZE - IP_HDR_SIZE_NO_UDP) +#define IP_MAXUDP (IP_PKTSIZE - IP_HDR_SIZE) /* * this is the packet being assembled, either data or frag control. @@ -688,11 +688,11 @@ static struct ip_udp_hdr *__NetDefragment(struct ip_udp_hdr *ip, int *lenp) u16 ip_off = ntohs(ip->ip_off); /* payload starts after IP header, this fragment is in there */ - payload = (struct hole *)(pkt_buff + IP_HDR_SIZE_NO_UDP); + payload = (struct hole *)(pkt_buff + IP_HDR_SIZE); offset8 = (ip_off & IP_OFFS); thisfrag = payload + offset8; start = offset8 * 8; - len = ntohs(ip->ip_len) - IP_HDR_SIZE_NO_UDP; + len = ntohs(ip->ip_len) - IP_HDR_SIZE; if (start + len > IP_MAXUDP) /* fragment extends too far */ return NULL; @@ -705,7 +705,7 @@ static struct ip_udp_hdr *__NetDefragment(struct ip_udp_hdr *ip, int *lenp) payload[0].prev_hole = 0; first_hole = 0; /* any IP header will work, copy the first we received */ - memcpy(localip, ip, IP_HDR_SIZE_NO_UDP); + memcpy(localip, ip, IP_HDR_SIZE); } /* @@ -788,12 +788,12 @@ static struct ip_udp_hdr *__NetDefragment(struct ip_udp_hdr *ip, int *lenp) } /* finally copy this fragment and possibly return whole packet */ - memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE_NO_UDP, len); + memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len); if (!done) return NULL; localip->ip_len = htons(total_len); - *lenp = total_len + IP_HDR_SIZE_NO_UDP; + *lenp = total_len + IP_HDR_SIZE; return localip; } @@ -983,7 +983,7 @@ NetReceive(uchar *inpkt, int len) if ((ip->ip_hl_v & 0x0f) > 0x05) return; /* Check the Checksum of the header */ - if (!NetCksumOk((uchar *)ip, IP_HDR_SIZE_NO_UDP / 2)) { + if (!NetCksumOk((uchar *)ip, IP_HDR_SIZE / 2)) { puts("checksum bad\n"); return; } @@ -1273,7 +1273,7 @@ void NetSetIP(uchar *xip, IPaddr_t dest, int dport, int sport, int len) ip->udp_dst = htons(dport); ip->udp_len = htons(UDP_HDR_SIZE + len); ip->udp_xsum = 0; - ip->ip_sum = ~NetCksum((uchar *)ip, IP_HDR_SIZE_NO_UDP / 2); + ip->ip_sum = ~NetCksum((uchar *)ip, IP_HDR_SIZE / 2); } void copy_filename(char *dst, const char *src, int size) diff --git a/net/ping.c b/net/ping.c index 6a2e85d..8542e22 100644 --- a/net/ping.c +++ b/net/ping.c @@ -44,7 +44,7 @@ static int ping_send(void) /* IP_HDR_SIZE / 4 (not including UDP) */ ip->ip_hl_v = 0x45; ip->ip_tos = 0; - ip->ip_len = htons(IP_HDR_SIZE_NO_UDP + 8); + ip->ip_len = htons(IP_HDR_SIZE + 8); ip->ip_id = htons(NetIPID++); ip->ip_off = htons(IP_FLAGS_DFRAG); /* Don't fragment */ ip->ip_ttl = 255; @@ -54,7 +54,7 @@ static int ping_send(void) NetCopyIP((void *)&ip->ip_src, &NetOurIP); /* - "" - */ NetCopyIP((void *)&ip->ip_dst, &NetPingIP); - ip->ip_sum = ~NetCksum((uchar *)ip, IP_HDR_SIZE_NO_UDP / 2); + ip->ip_sum = ~NetCksum((uchar *)ip, IP_HDR_SIZE / 2); s = &ip->udp_src; /* XXX ICMP starts here */ s[0] = htons(0x0800); /* echo-request, code */ @@ -65,7 +65,7 @@ static int ping_send(void) /* size of the waiting packet */ NetArpWaitTxPacketSize = - (pkt - NetArpWaitTxPacket) + IP_HDR_SIZE_NO_UDP + 8; + (pkt - NetArpWaitTxPacket) + IP_HDR_SIZE + 8; /* and do the ARP request */ NetArpWaitTry = 1; @@ -125,12 +125,12 @@ void ping_receive(Ethernet_t *et, struct ip_udp_hdr *ip, int len) NetCopyIP((void *)&ip->ip_dst, &ip->ip_src); NetCopyIP((void *)&ip->ip_src, &NetOurIP); ip->ip_sum = ~NetCksum((uchar *)ip, - IP_HDR_SIZE_NO_UDP >> 1); + IP_HDR_SIZE >> 1); icmph->type = ICMP_ECHO_REPLY; icmph->checksum = 0; icmph->checksum = ~NetCksum((uchar *)icmph, - (len - IP_HDR_SIZE_NO_UDP) >> 1); + (len - IP_HDR_SIZE) >> 1); (void) eth_send((uchar *)et, ETHER_HDR_SIZE + len); return;