checksum.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* SCTP kernel reference Implementation
  2. * Copyright (c) 1999-2001 Motorola, Inc.
  3. * Copyright (c) 2001-2003 International Business Machines, Corp.
  4. *
  5. * This file is part of the SCTP kernel reference Implementation
  6. *
  7. * SCTP Checksum functions
  8. *
  9. * The SCTP reference implementation is free software;
  10. * you can redistribute it and/or modify it under the terms of
  11. * the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2, or (at your option)
  13. * any later version.
  14. *
  15. * The SCTP reference implementation is distributed in the hope that it
  16. * will be useful, but WITHOUT ANY WARRANTY; without even the implied
  17. * ************************
  18. * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  19. * See the GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with GNU CC; see the file COPYING. If not, write to
  23. * the Free Software Foundation, 59 Temple Place - Suite 330,
  24. * Boston, MA 02111-1307, USA.
  25. *
  26. * Please send any bug reports or fixes you make to the
  27. * email address(es):
  28. * lksctp developers <linux-sctp@vger.kernel.org>
  29. *
  30. * Written or modified by:
  31. * Dinakaran Joseph
  32. * Jon Grimm <jgrimm@us.ibm.com>
  33. * Sridhar Samudrala <sri@us.ibm.com>
  34. *
  35. * Rewritten to use libcrc32c by:
  36. * Vlad Yasevich <vladislav.yasevich@hp.com>
  37. */
  38. #ifndef __sctp_checksum_h__
  39. #define __sctp_checksum_h__
  40. #include <linux/types.h>
  41. #include <net/sctp/sctp.h>
  42. #include <linux/crc32c.h>
  43. #include <linux/crc32.h>
  44. static inline __wsum sctp_csum_update(const void *buff, int len, __wsum sum)
  45. {
  46. /* This uses the crypto implementation of crc32c, which is either
  47. * implemented w/ hardware support or resolves to __crc32c_le().
  48. */
  49. return crc32c(sum, buff, len);
  50. }
  51. static inline __wsum sctp_csum_combine(__wsum csum, __wsum csum2,
  52. int offset, int len)
  53. {
  54. return __crc32c_le_combine(csum, csum2, len);
  55. }
  56. static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
  57. unsigned int offset)
  58. {
  59. struct sctphdr *sh = sctp_hdr(skb);
  60. __le32 ret, old = sh->checksum;
  61. const struct skb_checksum_ops ops = {
  62. .update = sctp_csum_update,
  63. .combine = sctp_csum_combine,
  64. };
  65. sh->checksum = 0;
  66. ret = cpu_to_le32(~__skb_checksum(skb, offset, skb->len - offset,
  67. ~(__u32)0, &ops));
  68. sh->checksum = old;
  69. return ret;
  70. }
  71. #endif /* __sctp_checksum_h__ */