]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
net: cosmetic: Split struct ip_udp_hdr into ip_hdr
authorJoe Hershberger <joe.hershberger@ni.com>
Wed, 23 May 2012 07:58:05 +0000 (07:58 +0000)
committerJoe Hershberger <joe.hershberger@ni.com>
Wed, 23 May 2012 22:46:14 +0000 (17:46 -0500)
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 <joe.hershberger@ni.com>
include/net.h
net/net.c
net/ping.c

index 3e4f304204f94f6d2cb132bce81726a6b55b4dc2..7692153b309487b25eb0aa0279b12afb75d665c3 100644 (file)
@@ -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.
index f0e8a6798f9c0f623682314e023073f874d67b0b..2bf5631f0d4de9f3cf5b195b4e92959fec4f9e9b 100644 (file)
--- 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)
index 6a2e85dabc35cb18ca5418a9d1c20b826c6fca93..8542e2299b4b1d597f94330673fd655df60c293a 100644 (file)
@@ -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;