checksum.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #ifndef _ALPHA_CHECKSUM_H
  2. #define _ALPHA_CHECKSUM_H
  3. #include <linux/in6.h>
  4. /*
  5. * This is a version of ip_compute_csum() optimized for IP headers,
  6. * which always checksum on 4 octet boundaries.
  7. */
  8. extern unsigned short ip_fast_csum(unsigned char * iph, unsigned int ihl);
  9. /*
  10. * computes the checksum of the TCP/UDP pseudo-header
  11. * returns a 16-bit checksum, already complemented
  12. */
  13. extern unsigned short int csum_tcpudp_magic(unsigned long saddr,
  14. unsigned long daddr,
  15. unsigned short len,
  16. unsigned short proto,
  17. unsigned int sum);
  18. unsigned int csum_tcpudp_nofold(unsigned long saddr, unsigned long daddr,
  19. unsigned short len, unsigned short proto,
  20. unsigned int sum);
  21. /*
  22. * computes the checksum of a memory block at buff, length len,
  23. * and adds in "sum" (32-bit)
  24. *
  25. * returns a 32-bit number suitable for feeding into itself
  26. * or csum_tcpudp_magic
  27. *
  28. * this function must be called with even lengths, except
  29. * for the last fragment, which may be odd
  30. *
  31. * it's best to have buff aligned on a 32-bit boundary
  32. */
  33. extern unsigned int csum_partial(const unsigned char * buff, int len, unsigned int sum);
  34. /*
  35. * the same as csum_partial, but copies from src while it
  36. * checksums
  37. *
  38. * here even more important to align src and dst on a 32-bit (or even
  39. * better 64-bit) boundary
  40. */
  41. unsigned int csum_partial_copy_from_user(const char __user *src, char *dst, int len, unsigned int sum, int *errp);
  42. unsigned int csum_partial_copy_nocheck(const char *src, char *dst, int len, unsigned int sum);
  43. /*
  44. * this routine is used for miscellaneous IP-like checksums, mainly
  45. * in icmp.c
  46. */
  47. extern unsigned short ip_compute_csum(unsigned char * buff, int len);
  48. /*
  49. * Fold a partial checksum without adding pseudo headers
  50. */
  51. static inline unsigned short csum_fold(unsigned int sum)
  52. {
  53. sum = (sum & 0xffff) + (sum >> 16);
  54. sum = (sum & 0xffff) + (sum >> 16);
  55. return ~sum;
  56. }
  57. #define _HAVE_ARCH_IPV6_CSUM
  58. extern unsigned short int csum_ipv6_magic(struct in6_addr *saddr,
  59. struct in6_addr *daddr,
  60. __u32 len,
  61. unsigned short proto,
  62. unsigned int sum);
  63. #endif