2 * Licensed under the GPL
5 #ifndef __UM_SYSDEP_CHECKSUM_H
6 #define __UM_SYSDEP_CHECKSUM_H
8 #include "linux/string.h"
10 #include "asm/uaccess.h"
12 extern unsigned csum_partial(const unsigned char *buff
, unsigned len
,
16 * Note: when you get a NULL pointer exception here this means someone
17 * passed in an incorrect kernel address to one of these functions.
19 * If you use these functions directly please don't forget the
24 unsigned int csum_partial_copy_nocheck(const unsigned char *src
, unsigned char *dst
,
27 memcpy(dst
, src
, len
);
28 return(csum_partial(dst
, len
, sum
));
32 unsigned int csum_partial_copy_from_user(const unsigned char *src
,
33 unsigned char *dst
, int len
, int sum
,
36 if(copy_from_user(dst
, src
, len
)){
40 return csum_partial(dst
, len
, sum
);
44 * csum_fold - Fold and invert a 32bit checksum.
45 * sum: 32bit unfolded sum
47 * Fold a 32bit running checksum to 16bit and invert it. This is usually
48 * the last step before putting a checksum into a packet.
49 * Make sure not to mix with 64bit checksums.
51 static inline unsigned int csum_fold(unsigned int sum
)
57 : "r" (sum
<< 16), "0" (sum
& 0xffff0000)
63 * csum_tcpup_nofold - Compute an IPv4 pseudo header checksum.
64 * @saddr: source address
65 * @daddr: destination address
66 * @len: length of packet
67 * @proto: ip protocol of packet
68 * @sum: initial sum to be added in (32bit unfolded)
70 * Returns the pseudo header checksum the input data. Result is
73 static inline unsigned long
74 csum_tcpudp_nofold(unsigned saddr
, unsigned daddr
, unsigned short len
,
75 unsigned short proto
, unsigned int sum
)
82 : "g" (daddr
), "g" (saddr
), "g" ((ntohs(len
)<<16)+proto
*256), "0" (sum
));
87 * computes the checksum of the TCP/UDP pseudo-header
88 * returns a 16-bit checksum, already complemented
90 static inline unsigned short int csum_tcpudp_magic(unsigned long saddr
,
96 return csum_fold(csum_tcpudp_nofold(saddr
,daddr
,len
,proto
,sum
));
100 * ip_fast_csum - Compute the IPv4 header checksum efficiently.
102 * ihl: length of header / 4
104 static inline unsigned short ip_fast_csum(unsigned char *iph
, unsigned int ihl
)
108 asm( " movl (%1), %0\n"
114 "1: adcl 16(%1), %0\n"
125 /* Since the input registers which are loaded with iph and ipl
126 are modified, we must also specify them as outputs, or gcc
127 will assume they contain their original values. */
128 : "=r" (sum
), "=r" (iph
), "=r" (ihl
)
129 : "1" (iph
), "2" (ihl
)
134 static inline unsigned add32_with_carry(unsigned a
, unsigned b
)
143 extern unsigned short ip_compute_csum(unsigned char * buff
, int len
);