ip6_checksum.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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__ unsigned short int csum_ipv6_magic(struct in6_addr *saddr,
  33. struct in6_addr *daddr,
  34. __u16 len,
  35. unsigned short proto,
  36. unsigned int csum)
  37. {
  38. int carry;
  39. __u32 ulen;
  40. __u32 uproto;
  41. csum += saddr->s6_addr32[0];
  42. carry = (csum < saddr->s6_addr32[0]);
  43. csum += carry;
  44. csum += saddr->s6_addr32[1];
  45. carry = (csum < saddr->s6_addr32[1]);
  46. csum += carry;
  47. csum += saddr->s6_addr32[2];
  48. carry = (csum < saddr->s6_addr32[2]);
  49. csum += carry;
  50. csum += saddr->s6_addr32[3];
  51. carry = (csum < saddr->s6_addr32[3]);
  52. csum += carry;
  53. csum += daddr->s6_addr32[0];
  54. carry = (csum < daddr->s6_addr32[0]);
  55. csum += carry;
  56. csum += daddr->s6_addr32[1];
  57. carry = (csum < daddr->s6_addr32[1]);
  58. csum += carry;
  59. csum += daddr->s6_addr32[2];
  60. carry = (csum < daddr->s6_addr32[2]);
  61. csum += carry;
  62. csum += daddr->s6_addr32[3];
  63. carry = (csum < daddr->s6_addr32[3]);
  64. csum += carry;
  65. ulen = htonl((__u32) len);
  66. csum += ulen;
  67. carry = (csum < ulen);
  68. csum += carry;
  69. uproto = htonl(proto);
  70. csum += uproto;
  71. carry = (csum < uproto);
  72. csum += carry;
  73. return csum_fold(csum);
  74. }
  75. #endif
  76. #endif