11ebcad57SDoug Rabson /*- 2*51369649SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause 3*51369649SPedro F. Giffuni * 41ebcad57SDoug Rabson * Copyright (c) 1990 The Regents of the University of California. 51ebcad57SDoug Rabson * All rights reserved. 61ebcad57SDoug Rabson * 71ebcad57SDoug Rabson * Redistribution and use in source and binary forms, with or without 81ebcad57SDoug Rabson * modification, are permitted provided that the following conditions 91ebcad57SDoug Rabson * are met: 101ebcad57SDoug Rabson * 1. Redistributions of source code must retain the above copyright 111ebcad57SDoug Rabson * notice, this list of conditions and the following disclaimer. 121ebcad57SDoug Rabson * 2. Redistributions in binary form must reproduce the above copyright 131ebcad57SDoug Rabson * notice, this list of conditions and the following disclaimer in the 141ebcad57SDoug Rabson * documentation and/or other materials provided with the distribution. 15fc8c8560SEd Maste * 3. Neither the name of the University nor the names of its contributors 161ebcad57SDoug Rabson * may be used to endorse or promote products derived from this software 171ebcad57SDoug Rabson * without specific prior written permission. 181ebcad57SDoug Rabson * 191ebcad57SDoug Rabson * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 201ebcad57SDoug Rabson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 211ebcad57SDoug Rabson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 221ebcad57SDoug Rabson * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 231ebcad57SDoug Rabson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 241ebcad57SDoug Rabson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 251ebcad57SDoug Rabson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 261ebcad57SDoug Rabson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 271ebcad57SDoug Rabson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 281ebcad57SDoug Rabson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 291ebcad57SDoug Rabson * SUCH DAMAGE. 301ebcad57SDoug Rabson * 311ebcad57SDoug Rabson * from tahoe: in_cksum.c 1.2 86/01/05 321ebcad57SDoug Rabson * from: @(#)in_cksum.c 1.3 (Berkeley) 1/19/91 331ebcad57SDoug Rabson * from: Id: in_cksum.c,v 1.8 1995/12/03 18:35:19 bde Exp 341ebcad57SDoug Rabson * $FreeBSD$ 351ebcad57SDoug Rabson */ 361ebcad57SDoug Rabson 371ebcad57SDoug Rabson #ifndef _MACHINE_IN_CKSUM_H_ 381ebcad57SDoug Rabson #define _MACHINE_IN_CKSUM_H_ 1 391ebcad57SDoug Rabson 40cf4e1c46SPeter Wemm #ifndef _SYS_CDEFS_H_ 41cf4e1c46SPeter Wemm #error this file needs sys/cdefs.h as a prerequisite 42cf4e1c46SPeter Wemm #endif 43cf4e1c46SPeter Wemm 441ebcad57SDoug Rabson #include <sys/cdefs.h> 451ebcad57SDoug Rabson 461ebcad57SDoug Rabson #define in_cksum(m, len) in_cksum_skip(m, len, 0) 471ebcad57SDoug Rabson 48920b9658SBjoern A. Zeeb #if defined(IPVERSION) && (IPVERSION == 4) 491ebcad57SDoug Rabson /* 501ebcad57SDoug Rabson * It it useful to have an Internet checksum routine which is inlineable 511ebcad57SDoug Rabson * and optimized specifically for the task of computing IP header checksums 521ebcad57SDoug Rabson * in the normal case (where there are no options and the header length is 531ebcad57SDoug Rabson * therefore always exactly five 32-bit words. 541ebcad57SDoug Rabson */ 55a5f50ef9SJoerg Wunsch #ifdef __CC_SUPPORTS___INLINE 561ebcad57SDoug Rabson 571ebcad57SDoug Rabson static __inline void 581ebcad57SDoug Rabson in_cksum_update(struct ip *ip) 591ebcad57SDoug Rabson { 601ebcad57SDoug Rabson int __tmpsum; 611ebcad57SDoug Rabson __tmpsum = (int)ntohs(ip->ip_sum) + 256; 621ebcad57SDoug Rabson ip->ip_sum = htons(__tmpsum + (__tmpsum >> 16)); 631ebcad57SDoug Rabson } 641ebcad57SDoug Rabson 651ebcad57SDoug Rabson #else 661ebcad57SDoug Rabson 671ebcad57SDoug Rabson #define in_cksum_update(ip) \ 681ebcad57SDoug Rabson do { \ 691ebcad57SDoug Rabson int __tmpsum; \ 701ebcad57SDoug Rabson __tmpsum = (int)ntohs(ip->ip_sum) + 256; \ 711ebcad57SDoug Rabson ip->ip_sum = htons(__tmpsum + (__tmpsum >> 16)); \ 721ebcad57SDoug Rabson } while(0) 731ebcad57SDoug Rabson 741ebcad57SDoug Rabson #endif 75920b9658SBjoern A. Zeeb #endif 761ebcad57SDoug Rabson 771ebcad57SDoug Rabson #ifdef _KERNEL 78920b9658SBjoern A. Zeeb #if defined(IPVERSION) && (IPVERSION == 4) 791ebcad57SDoug Rabson u_int in_cksum_hdr(const struct ip *ip); 80920b9658SBjoern A. Zeeb #endif 811ebcad57SDoug Rabson u_short in_addword(u_short sum, u_short b); 821ebcad57SDoug Rabson u_short in_pseudo(u_int sum, u_int b, u_int c); 831ebcad57SDoug Rabson u_short in_cksum_skip(struct mbuf *m, int len, int skip); 841ebcad57SDoug Rabson #endif 851ebcad57SDoug Rabson 861ebcad57SDoug Rabson #endif /* _MACHINE_IN_CKSUM_H_ */ 87