/* checksum.h: IP/UDP/TCP checksum routines on the Sparc. * * Copyright(C) 1995 Linus Torvalds * Copyright(C) 1995 Miguel de Icaza * Copyright(C) 1996 David S. Miller * Copyright(C) 1996 Eddie C. Dost * Copyright(C) 1997 Jakub Jelinek * * derived from: * Alpha checksum c-code * ix86 inline assembly * RFC1071 Computing the Internet Checksum
*/
#include <linux/in6.h> #include <linux/uaccess.h>
/* computes the checksum of a memory block at buff, length len, * and adds in "sum" (32-bit) * * returns a 32-bit number suitable for feeding into itself * or csum_tcpudp_magic * * this function must be called with even lengths, except * for the last fragment, which may be odd * * it's best to have buff aligned on a 32-bit boundary
*/
__wsum csum_partial(constvoid *buff, int len, __wsum sum);
/* the same as csum_partial, but copies from fs:src while it * checksums * * here even more important to align src and dst on a 32-bit (or even * better 64-bit) boundary
*/
/* ihl is always 5 or greater, almost always is 5, and iph is word aligned * the majority of the time.
*/ staticinline __sum16 ip_fast_csum(constvoid *iph, unsignedint ihl)
{
__sum16 sum;
/* Note: We must read %2 before we touch %0 for the first time, * because GCC can legitimately use the same register for * both operands.
*/
__asm__ __volatile__("sub\t%2, 4, %%g4\n\t" "ld\t[%1 + 0x00], %0\n\t" "ld\t[%1 + 0x04], %%g2\n\t" "ld\t[%1 + 0x08], %%g3\n\t" "addcc\t%%g2, %0, %0\n\t" "addxcc\t%%g3, %0, %0\n\t" "ld\t[%1 + 0x0c], %%g2\n\t" "ld\t[%1 + 0x10], %%g3\n\t" "addxcc\t%%g2, %0, %0\n\t" "addx\t%0, %%g0, %0\n" "1:\taddcc\t%%g3, %0, %0\n\t" "add\t%1, 4, %1\n\t" "addxcc\t%0, %%g0, %0\n\t" "subcc\t%%g4, 1, %%g4\n\t" "be,a\t2f\n\t" "sll\t%0, 16, %%g2\n\t" "b\t1b\n\t" "ld\t[%1 + 0x10], %%g3\n" "2:\taddcc\t%0, %%g2, %%g2\n\t" "srl\t%%g2, 16, %0\n\t" "addx\t%0, %%g0, %0\n\t" "xnor\t%%g0, %0, %0"
: "=r" (sum), "=&r" (iph)
: "r" (ihl), "1" (iph)
: "g2", "g3", "g4", "cc", "memory"); return sum;
}
/* Fold a partial checksum without adding pseudo headers. */ staticinline __sum16 csum_fold(__wsum sum)
{ unsignedint tmp;
/* this routine is used for miscellaneous IP-like checksums, mainly in icmp.c */ staticinline __sum16 ip_compute_csum(constvoid *buff, int len)
{ return csum_fold(csum_partial(buff, len, 0));
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.