1178172Simp/*-
2178172Simp * Copyright (c) 1990 The Regents of the University of California.
3178172Simp * All rights reserved.
4178172Simp *
5178172Simp * Redistribution and use in source and binary forms, with or without
6178172Simp * modification, are permitted provided that the following conditions
7178172Simp * are met:
8178172Simp * 1. Redistributions of source code must retain the above copyright
9178172Simp *    notice, this list of conditions and the following disclaimer.
10178172Simp * 2. Redistributions in binary form must reproduce the above copyright
11178172Simp *    notice, this list of conditions and the following disclaimer in the
12178172Simp *    documentation and/or other materials provided with the distribution.
13178172Simp * 4. Neither the name of the University nor the names of its contributors
14178172Simp *    may be used to endorse or promote products derived from this software
15178172Simp *    without specific prior written permission.
16178172Simp *
17178172Simp * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18178172Simp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19178172Simp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20178172Simp * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21178172Simp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22178172Simp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23178172Simp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24178172Simp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25178172Simp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26178172Simp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27178172Simp * SUCH DAMAGE.
28178172Simp *
29178172Simp *	from tahoe:	in_cksum.c	1.2	86/01/05
30178172Simp *	from:		@(#)in_cksum.c	1.3 (Berkeley) 1/19/91
31178172Simp *	from: Id: in_cksum.c,v 1.8 1995/12/03 18:35:19 bde Exp
32178172Simp *	from: src/sys/alpha/include/in_cksum.h,v 1.7 2005/03/02 21:33:20 joerg
33178172Simp * $FreeBSD: releng/10.2/sys/mips/include/in_cksum.h 235941 2012-05-24 22:00:48Z bz $
34178172Simp */
35178172Simp
36178172Simp#ifndef _MACHINE_IN_CKSUM_H_
37178172Simp#define	_MACHINE_IN_CKSUM_H_	1
38178172Simp
39178172Simp#include <sys/cdefs.h>
40178172Simp
41178172Simp#define	in_cksum(m, len)	in_cksum_skip(m, len, 0)
42178172Simp
43235941Sbz#if defined(IPVERSION) && (IPVERSION == 4)
44178172Simp/*
45178172Simp * It it useful to have an Internet checksum routine which is inlineable
46178172Simp * and optimized specifically for the task of computing IP header checksums
47178172Simp * in the normal case (where there are no options and the header length is
48178172Simp * therefore always exactly five 32-bit words.
49178172Simp */
50178172Simp#ifdef __CC_SUPPORTS___INLINE
51178172Simp
52178172Simpstatic __inline void
53178172Simpin_cksum_update(struct ip *ip)
54178172Simp{
55178172Simp	int __tmpsum;
56178172Simp	__tmpsum = (int)ntohs(ip->ip_sum) + 256;
57178172Simp	ip->ip_sum = htons(__tmpsum + (__tmpsum >> 16));
58178172Simp}
59178172Simp
60178172Simp#else
61178172Simp
62178172Simp#define	in_cksum_update(ip)						\
63178172Simp	do {								\
64178172Simp		int __tmpsum;						\
65178172Simp		__tmpsum = (int)ntohs(ip->ip_sum) + 256;		\
66178172Simp		ip->ip_sum = htons(__tmpsum + (__tmpsum >> 16));	\
67178172Simp	} while(0)
68178172Simp
69178172Simp#endif
70235941Sbz#endif
71178172Simp
72178172Simp#ifdef _KERNEL
73235941Sbz#if defined(IPVERSION) && (IPVERSION == 4)
74178172Simpu_int in_cksum_hdr(const struct ip *ip);
75235941Sbz#endif
76178172Simpu_short in_addword(u_short sum, u_short b);
77178172Simpu_short in_pseudo(u_int sum, u_int b, u_int c);
78178172Simpu_short in_cksum_skip(struct mbuf *m, int len, int skip);
79178172Simp#endif
80178172Simp
81178172Simp#endif /* _MACHINE_IN_CKSUM_H_ */
82