Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef __ASM_GENERIC_CHECKSUM_H
0003 #define __ASM_GENERIC_CHECKSUM_H
0004 
0005 /*
0006  * computes the checksum of a memory block at buff, length len,
0007  * and adds in "sum" (32-bit)
0008  *
0009  * returns a 32-bit number suitable for feeding into itself
0010  * or csum_tcpudp_magic
0011  *
0012  * this function must be called with even lengths, except
0013  * for the last fragment, which may be odd
0014  *
0015  * it's best to have buff aligned on a 32-bit boundary
0016  */
0017 extern __wsum csum_partial(const void *buff, int len, __wsum sum);
0018 
0019 #ifndef ip_fast_csum
0020 /*
0021  * This is a version of ip_compute_csum() optimized for IP headers,
0022  * which always checksum on 4 octet boundaries.
0023  */
0024 extern __sum16 ip_fast_csum(const void *iph, unsigned int ihl);
0025 #endif
0026 
0027 #ifndef csum_fold
0028 /*
0029  * Fold a partial checksum
0030  */
0031 static inline __sum16 csum_fold(__wsum csum)
0032 {
0033     u32 sum = (__force u32)csum;
0034     sum = (sum & 0xffff) + (sum >> 16);
0035     sum = (sum & 0xffff) + (sum >> 16);
0036     return (__force __sum16)~sum;
0037 }
0038 #endif
0039 
0040 #ifndef csum_tcpudp_nofold
0041 /*
0042  * computes the checksum of the TCP/UDP pseudo-header
0043  * returns a 16-bit checksum, already complemented
0044  */
0045 extern __wsum
0046 csum_tcpudp_nofold(__be32 saddr, __be32 daddr, __u32 len,
0047            __u8 proto, __wsum sum);
0048 #endif
0049 
0050 #ifndef csum_tcpudp_magic
0051 static inline __sum16
0052 csum_tcpudp_magic(__be32 saddr, __be32 daddr, __u32 len,
0053           __u8 proto, __wsum sum)
0054 {
0055     return csum_fold(csum_tcpudp_nofold(saddr, daddr, len, proto, sum));
0056 }
0057 #endif
0058 
0059 /*
0060  * this routine is used for miscellaneous IP-like checksums, mainly
0061  * in icmp.c
0062  */
0063 extern __sum16 ip_compute_csum(const void *buff, int len);
0064 
0065 #endif /* __ASM_GENERIC_CHECKSUM_H */