199040Sbenno/*- 299040Sbenno * Copyright (c) 1990 The Regents of the University of California. 399040Sbenno * All rights reserved. 499040Sbenno * 599040Sbenno * Redistribution and use in source and binary forms, with or without 699040Sbenno * modification, are permitted provided that the following conditions 799040Sbenno * are met: 899040Sbenno * 1. Redistributions of source code must retain the above copyright 999040Sbenno * notice, this list of conditions and the following disclaimer. 1099040Sbenno * 2. Redistributions in binary form must reproduce the above copyright 1199040Sbenno * notice, this list of conditions and the following disclaimer in the 1299040Sbenno * documentation and/or other materials provided with the distribution. 1399040Sbenno * 4. Neither the name of the University nor the names of its contributors 1499040Sbenno * may be used to endorse or promote products derived from this software 1599040Sbenno * without specific prior written permission. 1699040Sbenno * 1799040Sbenno * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 1899040Sbenno * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1999040Sbenno * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2099040Sbenno * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2199040Sbenno * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2299040Sbenno * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2399040Sbenno * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2499040Sbenno * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2599040Sbenno * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2699040Sbenno * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2799040Sbenno * SUCH DAMAGE. 2899040Sbenno * 2999040Sbenno * from tahoe: in_cksum.c 1.2 86/01/05 3099040Sbenno * from: @(#)in_cksum.c 1.3 (Berkeley) 1/19/91 3199040Sbenno * from: Id: in_cksum.c,v 1.8 1995/12/03 18:35:19 bde Exp 3299040Sbenno * $FreeBSD: releng/10.2/sys/powerpc/include/in_cksum.h 235941 2012-05-24 22:00:48Z bz $ 3399040Sbenno */ 3499040Sbenno 3599040Sbenno#ifndef _MACHINE_IN_CKSUM_H_ 3699040Sbenno#define _MACHINE_IN_CKSUM_H_ 1 3799040Sbenno 3899040Sbenno#include <sys/cdefs.h> 3999040Sbenno 4099040Sbenno#define in_cksum(m, len) in_cksum_skip(m, len, 0) 4199040Sbenno 42235941Sbz#if defined(IPVERSION) && (IPVERSION == 4) 4399040Sbenno/* 4499040Sbenno * It it useful to have an Internet checksum routine which is inlineable 4599040Sbenno * and optimized specifically for the task of computing IP header checksums 4699040Sbenno * in the normal case (where there are no options and the header length is 4799040Sbenno * therefore always exactly five 32-bit words. 4899040Sbenno */ 49143063Sjoerg#ifdef __CC_SUPPORTS___INLINE 5099040Sbenno 5199040Sbennostatic __inline void 5299040Sbennoin_cksum_update(struct ip *ip) 5399040Sbenno{ 5499040Sbenno int __tmpsum; 5599040Sbenno __tmpsum = (int)ntohs(ip->ip_sum) + 256; 5699040Sbenno ip->ip_sum = htons(__tmpsum + (__tmpsum >> 16)); 5799040Sbenno} 5899040Sbenno 5999040Sbenno#else 6099040Sbenno 6199040Sbenno#define in_cksum_update(ip) \ 6299040Sbenno do { \ 6399040Sbenno int __tmpsum; \ 6499040Sbenno __tmpsum = (int)ntohs(ip->ip_sum) + 256; \ 6599040Sbenno ip->ip_sum = htons(__tmpsum + (__tmpsum >> 16)); \ 6699040Sbenno } while(0) 6799040Sbenno 6899040Sbenno#endif 69235941Sbz#endif 7099040Sbenno 7199040Sbenno#ifdef _KERNEL 72235941Sbz#if defined(IPVERSION) && (IPVERSION == 4) 7399040Sbennou_int in_cksum_hdr(const struct ip *ip); 74235941Sbz#endif 7599040Sbennou_short in_addword(u_short sum, u_short b); 7699040Sbennou_short in_pseudo(u_int sum, u_int b, u_int c); 7799040Sbennou_short in_cksum_skip(struct mbuf *m, int len, int skip); 7899040Sbenno#endif 7999040Sbenno 8099040Sbenno#endif /* _MACHINE_IN_CKSUM_H_ */ 81