checksum.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /* SCTP kernel reference Implementation
  3. * Copyright (c) 1999-2001 Motorola, Inc.
  4. * Copyright (c) 2001-2003 International Business Machines, Corp.
  5. *
  6. * This file is part of the SCTP kernel reference Implementation
  7. *
  8. * SCTP Checksum functions
  9. *
  10. * Please send any bug reports or fixes you make to the
  11. * email address(es):
  12. * lksctp developers <linux-sctp@vger.kernel.org>
  13. *
  14. * Written or modified by:
  15. * Dinakaran Joseph
  16. * Jon Grimm <jgrimm@us.ibm.com>
  17. * Sridhar Samudrala <sri@us.ibm.com>
  18. * Vlad Yasevich <vladislav.yasevich@hp.com>
  19. */
  20. #ifndef __sctp_checksum_h__
  21. #define __sctp_checksum_h__
  22. #include <linux/types.h>
  23. #include <linux/sctp.h>
  24. static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
  25. unsigned int offset)
  26. {
  27. struct sctphdr *sh = (struct sctphdr *)(skb->data + offset);
  28. __le32 old = sh->checksum;
  29. u32 new;
  30. sh->checksum = 0;
  31. new = ~skb_crc32c(skb, offset, skb->len - offset, ~0);
  32. sh->checksum = old;
  33. return cpu_to_le32(new);
  34. }
  35. #endif /* __sctp_checksum_h__ */