ip6_checksum.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * INET An implementation of the TCP/IP protocol suite for the LINUX
  3. * operating system. INET is implemented using the BSD Socket
  4. * interface as the means of communication with the user level.
  5. *
  6. * Checksumming functions for IPv6
  7. *
  8. * Authors: Jorge Cwik, <jorge@laser.satlink.net>
  9. * Arnt Gulbrandsen, <agulbra@nvg.unit.no>
  10. * Borrows very liberally from tcp.c and ip.c, see those
  11. * files for more names.
  12. *
  13. * This program is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU General Public License
  15. * as published by the Free Software Foundation; either version
  16. * 2 of the License, or (at your option) any later version.
  17. */
  18. /*
  19. * Fixes:
  20. *
  21. * Ralf Baechle : generic ipv6 checksum
  22. * <ralf@waldorf-gmbh.de>
  23. */
  24. #ifndef _CHECKSUM_IPV6_H
  25. #define _CHECKSUM_IPV6_H
  26. #include <asm/types.h>
  27. #include <asm/byteorder.h>
  28. #include <net/ip.h>
  29. #include <asm/checksum.h>
  30. #include <linux/in6.h>
  31. #ifndef _HAVE_ARCH_IPV6_CSUM
  32. static __inline__ __sum16 csum_ipv6_magic(const struct in6_addr *saddr,
  33. const struct in6_addr *daddr,
  34. __u32 len, unsigned short proto,
  35. __wsum csum)
  36. {
  37. int carry;
  38. __u32 ulen;
  39. __u32 uproto;
  40. __u32 sum = (__force u32)csum;
  41. sum += (__force u32)saddr->s6_addr32[0];
  42. carry = (sum < (__force u32)saddr->s6_addr32[0]);
  43. sum += carry;
  44. sum += (__force u32)saddr->s6_addr32[1];
  45. carry = (sum < (__force u32)saddr->s6_addr32[1]);
  46. sum += carry;
  47. sum += (__force u32)saddr->s6_addr32[2];
  48. carry = (sum < (__force u32)saddr->s6_addr32[2]);
  49. sum += carry;
  50. sum += (__force u32)saddr->s6_addr32[3];
  51. carry = (sum < (__force u32)saddr->s6_addr32[3]);
  52. sum += carry;
  53. sum += (__force u32)daddr->s6_addr32[0];
  54. carry = (sum < (__force u32)daddr->s6_addr32[0]);
  55. sum += carry;
  56. sum += (__force u32)daddr->s6_addr32[1];
  57. carry = (sum < (__force u32)daddr->s6_addr32[1]);
  58. sum += carry;
  59. sum += (__force u32)daddr->s6_addr32[2];
  60. carry = (sum < (__force u32)daddr->s6_addr32[2]);
  61. sum += carry;
  62. sum += (__force u32)daddr->s6_addr32[3];
  63. carry = (sum < (__force u32)daddr->s6_addr32[3]);
  64. sum += carry;
  65. ulen = (__force u32)htonl((__u32) len);
  66. sum += ulen;
  67. carry = (sum < ulen);
  68. sum += carry;
  69. uproto = (__force u32)htonl(proto);
  70. sum += uproto;
  71. carry = (sum < uproto);
  72. sum += carry;
  73. return csum_fold((__force __wsum)sum);
  74. }
  75. #endif
  76. #endif