]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
net: Use new checksum functions
authorSimon Glass <sjg@chromium.org>
Tue, 20 Jan 2015 05:16:08 +0000 (22:16 -0700)
committerLothar Waßmann <LW@KARO-electronics.de>
Tue, 1 Sep 2015 11:50:46 +0000 (13:50 +0200)
Drop the old checksum functions in favour of the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
include/net.h
net/net.c
net/ping.c

index 0b338ff4e63c9cff6b266a4fd9617d4fbf523efd..9b24a9a3595848cf375b0a6ed2b16e261b60ceb4 100644 (file)
@@ -512,10 +512,6 @@ unsigned add_ip_checksums(unsigned offset, unsigned sum, unsigned new_sum);
  */
 int ip_checksum_ok(const void *addr, unsigned nbytes);
 
-/* Checksum */
-extern int     NetCksumOk(uchar *, int);       /* Return true if cksum OK */
-extern uint    NetCksum(uchar *, int);         /* Calculate the checksum */
-
 /* Callbacks */
 extern rxhand_f *net_get_udp_handler(void);    /* Get UDP RX packet handler */
 extern void net_set_udp_handler(rxhand_f *);   /* Set UDP RX packet handler */
index 30ecfcc403cfe0b168987d05e39db6e821e864f8..cd3bc931874fa065a8fab4e1aaa2017806f2798a 100644 (file)
--- a/net/net.c
+++ b/net/net.c
@@ -1092,7 +1092,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 / 2)) {
+               if (!ip_checksum_ok((uchar *)ip, IP_HDR_SIZE)) {
                        debug("checksum bad\n");
                        return;
                }
@@ -1296,27 +1296,6 @@ common:
 }
 /**********************************************************************/
 
-int
-NetCksumOk(uchar *ptr, int len)
-{
-       return !((NetCksum(ptr, len) + 1) & 0xfffe);
-}
-
-
-unsigned
-NetCksum(uchar *ptr, int len)
-{
-       ulong   xsum;
-       ushort *p = (ushort *)ptr;
-
-       xsum = 0;
-       while (len-- > 0)
-               xsum += *p++;
-       xsum = (xsum & 0xffff) + (xsum >> 16);
-       xsum = (xsum & 0xffff) + (xsum >> 16);
-       return xsum & 0xffff;
-}
-
 int
 NetEthHdrSize(void)
 {
@@ -1416,7 +1395,7 @@ void net_set_udp_header(uchar *pkt, IPaddr_t dest, int dport, int sport,
        net_set_ip_header(pkt, dest, NetOurIP);
        ip->ip_len   = htons(IP_UDP_HDR_SIZE + len);
        ip->ip_p     = IPPROTO_UDP;
-       ip->ip_sum   = ~NetCksum((uchar *)ip, IP_HDR_SIZE >> 1);
+       ip->ip_sum   = compute_ip_checksum(ip, IP_HDR_SIZE);
 
        ip->udp_src  = htons(sport);
        ip->udp_dst  = htons(dport);
index 2be56ed929575c25c1cfa78c7c89e7da31d32be7..366f51825f9ecbff62354eeae1aeb2c49b4aa25b 100644 (file)
@@ -29,14 +29,14 @@ static void set_icmp_header(uchar *pkt, IPaddr_t dest)
 
        ip->ip_len   = htons(IP_ICMP_HDR_SIZE);
        ip->ip_p     = IPPROTO_ICMP;
-       ip->ip_sum   = ~NetCksum((uchar *)ip, IP_HDR_SIZE >> 1);
+       ip->ip_sum   = compute_ip_checksum(ip, IP_HDR_SIZE);
 
        icmp->type = ICMP_ECHO_REQUEST;
        icmp->code = 0;
        icmp->checksum = 0;
        icmp->un.echo.id = 0;
        icmp->un.echo.sequence = htons(PingSeqNo++);
-       icmp->checksum = ~NetCksum((uchar *)icmp, ICMP_HDR_SIZE >> 1);
+       icmp->checksum = compute_ip_checksum(icmp, ICMP_HDR_SIZE);
 }
 
 static int ping_send(void)
@@ -101,13 +101,11 @@ void ping_receive(struct ethernet_hdr *et, struct ip_udp_hdr *ip, int len)
                ip->ip_off = 0;
                NetCopyIP((void *)&ip->ip_dst, &ip->ip_src);
                NetCopyIP((void *)&ip->ip_src, &NetOurIP);
-               ip->ip_sum = ~NetCksum((uchar *)ip,
-                                      IP_HDR_SIZE >> 1);
+               ip->ip_sum = compute_ip_checksum(ip, IP_HDR_SIZE);
 
                icmph->type = ICMP_ECHO_REPLY;
                icmph->checksum = 0;
-               icmph->checksum = ~NetCksum((uchar *)icmph,
-                       (len - IP_HDR_SIZE) >> 1);
+               icmph->checksum = compute_ip_checksum(icmph, len - IP_HDR_SIZE);
                NetSendPacket((uchar *)et, eth_hdr_size + len);
                return;
 /*     default: