linux/include/net/checksum.h
<<
<3pt/ot/spa12. /ot/form2. /ota <3pt/o href="../linux+v3 v2/include/net/checksum.h"><3pt/otimg src="../.static/gfx/right.png" alt=">>"><3t/spa12.<3tspa1 class="lxr_search"><3pt<3pt/otinput typopthidden" namoptnavtarget" <3pt/otinput typopttext" namoptsearch" idptsearch"><3pt/otbutt typoptsubmit">Search<3pt/oPrefs. /ot/a><3t/spa12.pt/o ot/div2.pt/o otform acv3.1="ajax+*" method="post" onsubmit="return false;"><3tinput typopthidden" namoptajax_lookup" idptajax_lookup" . tdiv idptfile_contents"2
o o1t/a>tspa1 class="comment">/*t/spa12.o o2t/a>tspa1 class="comment"> * INET         An implementan>
  of the TCP/IP protocol suite for the LINUXt/spa12.o o3t/a>tspa1 class="comment"> *              operan>ng system.  INET is implemented us>ng the  BSD Sockett/spa12.o o4t/a>tspa1 class="comment"> *              interface as the means of communican>
  with the user level.t/spa12.o o5t/a>tspa1 class="comment"> *t/spa12.o o6t/a>tspa1 class="comment"> *              Checksumm>ng funcv3.1s for IP, TCP, UDP and so ont/spa12.o o7t/a>tspa1 class="comment"> *t/spa12.o o8t/a>tspa1 class="comment"> * Authors:     Jorge Cwik, <jorge@laser.satlink.net>t/spa12.o o9t/a>tspa1 class="comment"> *              Arnt Gulbrandsen, <agulbra@nvg.unit.no>t/spa12.o 3.18a>tspa1 class="comment"> *              Borrows very liberally from tcp.c and ip.c, see thoset/spa12.o 11t/a>tspa1 class="comment"> *              files for more namos.t/spa12.o 12t/a>tspa1 class="comment"> *t/spa12.o 13t/a>tspa1 class="comment"> *              This program is free software; you ca1 redistribute it and/ort/spa12.o 14t/a>tspa1 class="comment"> *              modify it under the terms of the GNU General Public Licenset/spa12.o 15t/a>tspa1 class="comment"> *              as published by the Free Software Foundan>
 ; either versiont/spa12.o 16t/a>tspa1 class="comment"> *              2 of the License, or (at your   v3.1) any later version.t/spa12.o 17t/a>tspa1 class="comment"> */t/spa12.o 18t/a>.o 19t/a>#ifndefota href="+code=_CHECKSUM_H" class="sref">_CHECKSUM_Ht/a>.o 2.18a>#defineota href="+code=_CHECKSUM_H" class="sref">_CHECKSUM_Ht/a>.o 21t/a>.o 22t/a>#include <linux/errno.ht/a>>.o 23t/a>#include <asm/typos.ht/a>>.o 24t/a>#include <asm/byteorder.ht/a>>.o 25t/a>#include <asm/uaccess.ht/a>>.o 26t/a>#include <asm/checksum.ht/a>>.o 27t/a>.o 28t/a>#ifndefota href="+code=_HAVE_ARCH_COPY_AND_CSUM_FROM_USER" class="sref">_HAVE_ARCH_COPY_AND_CSUM_FROM_USERt/a>.o 29t/a>staticota href="+code=inline" class="sref">inlinet/a>.o 3.18a>ta href="+code=__wsum" class="sref">__wsum18a>ota href="+code=csum_and_copy_from_user" class="sref">csum_and_copy_from_user18a>o(const voidota href="+code=__user" class="sref">__user18a>o*ta href="+code=src" class="sref">src18a>, voido*ta href="+code=dst" class="sref">dst18a>,.o 31t/a>                                      intota href="+code=len" class="sref">len18a>, ta href="+code=__wsum" class="sref">__wsum18a>ota href="+code=sum" class="sref">sum18a>, into*ta href="+code=err_ptr" class="sref">err_ptr18a>).o 32t/a>{.o 33t/a>        if (ta href="+code=access_ok" class="sref">access_okt/a>(ta href="+code=VERIFY_READ" class="sref">VERIFY_READ18a>, ta href="+code=src" class="sref">src18a>, ta href="+code=len" class="sref">len18a>)).o 34t/a>                return ta href="+code=csum_partial_copy_from_user" class="sref">csum_partial_copy_from_usert/a>(ta href="+code=src" class="sref">src18a>, ta href="+code=dst" class="sref">dst18a>,ota href="+code=len" class="sref">len18a>, ta href="+code=sum" class="sref">sum18a>, ta href="+code=err_ptr" class="sref">err_ptr18a>);.o 35t/a>.o 36t/a>        if (ta href="+code=len" class="sref">len18a>).o 37t/a>                *ta href="+code=err_ptr" class="sref">err_ptr18a> = -ta href="+code=EFAULT" class="sref">EFAULT18a>;.o 38t/a>.o 39t/a>        return ta href="+code=sum" class="sref">sum18a>;.o 4.18a>}.o 41t/a>#endif.o 42t/a>.o 43t/a>#ifndefota href="+code=HAVE_CSUM_COPY_USER" class="sref">HAVE_CSUM_COPY_USERt/a>.o 44t/a>staticota href="+code=__inline__" class="sref">__inline__18a>ota href="+code=__wsum" class="sref">__wsum18a>ota href="+code=csum_and_copy_to_user" class="sref">csum_and_copy_to_usert/a>.o 45t/a>(const voido*ta href="+code=src" class="sref">src18a>, voidota href="+code=__user" class="sref">__user18a>o*ta href="+code=dst" class="sref">dst18a>,ointota href="+code=len" class="sref">len18a>, ta href="+code=__wsum" class="sref">__wsum18a>ota href="+code=sum" class="sref">sum18a>, into*ta href="+code=err_ptr" class="sref">err_ptr18a>).o 46t/a>{.o 47t/a>        ta href="+code=sum" class="sref">sum18a> = ta href="+code=csum_partial" class="sref">csum_partialt/a>(ta href="+code=src" class="sref">src18a>, ta href="+code=len" class="sref">len18a>, ta href="+code=sum" class="sref">sum18a>);.o 48t/a>.o 49t/a>        if (ta href="+code=access_ok" class="sref">access_okt/a>(ta href="+code=VERIFY_WRITE" class="sref">VERIFY_WRITE18a>, ta href="+code=dst" class="sref">dst18a>,ota href="+code=len" class="sref">len18a>)) {.o 50t/a>                if (ta href="+code=copy_to_user" class="sref">copy_to_usert/a>(ta href="+code=dst" class="sref">dst18a>,ota href="+code=src" class="sref">src18a>, ta href="+code=len" class="sref">len18a>) == 0).o 51t/a>                        return ta href="+code=sum" class="sref">sum18a>;.o 52t/a>        }.o 53t/a>        if (ta href="+code=len" class="sref">len18a>).o 54t/a>                *ta href="+code=err_ptr" class="sref">err_ptr18a> = -ta href="+code=EFAULT" class="sref">EFAULT18a>;.o 55t/a>.o 56t/a>        return (ta href="+code=__force" class="sref">__force18a>ota href="+code=__wsum" class="sref">__wsum18a>)-1; tspa1 class="comment">/* invalidochecksum */t/spa12.o 5718a>}.o 58t/a>#endif.o 59t/a>.o 60t/a>staticota href="+code=inline" class="sref">inlinet/a>ota href="+code=__wsum" class="sref">__wsum18a>ota href="+code=csum_add" class="sref">csum_addt/a>(ta href="+code=__wsum" class="sref">__wsum18a>ota href="+code=csum" class="sref">csum18a>, ta href="+code=__wsum" class="sref">__wsum18a>ota href="+code=addend" class="sref">addend18a>).o 61t/a>{.o 62t/a>        ta href="+code=u32" class="sref">u32t/a> ta href="+code=res" class="sref">res18a> = (ta href="+code=__force" class="sref">__force18a>ota href="+code=u32" class="sref">u32t/a>)ta href="+code=csum" class="sref">csum18a>;.o 63t/a>        ta href="+code=res" class="sref">res18a> += (ta href="+code=__force" class="sref">__force18a>ota href="+code=u32" class="sref">u32t/a>)ta href="+code=addend" class="sref">addend18a>;.o 64t/a>        return (ta href="+code=__force" class="sref">__force18a>ota href="+code=__wsum" class="sref">__wsum18a>)(ta href="+code=res" class="sref">res18a> + (ta href="+code=res" class="sref">res18a> < (ta href="+code=__force" class="sref">__force18a>ota href="+code=u32" class="sref">u32t/a>)ta href="+code=addend" class="sref">addend18a>));.o 6518a>}.o 66t/a>.o 67t/a>staticota href="+code=inline" class="sref">inlinet/a>ota href="+code=__wsum" class="sref">__wsum18a>ota href="+code=csum_sub" class="sref">csum_subt/a>(ta href="+code=__wsum" class="sref">__wsum18a>ota href="+code=csum" class="sref">csum18a>, ta href="+code=__wsum" class="sref">__wsum18a>ota href="+code=addend" class="sref">addend18a>).o 68t/a>{.o 69t/a>        return ta href="+code=csum_add" class="sref">csum_addt/a>(ta href="+code=csum" class="sref">csum18a>, ~ta href="+code=addend" class="sref">addend18a>);.o 7.18a>}.o 71t/a>.o 72t/a>staticota href="+code=inline" class="sref">inlinet/a>ota href="+code=__wsum" class="sref">__wsum18a>.o 73t/a>ta href="+code=csum_block_add" class="sref">csum_block_addt/a>(ta href="+code=__wsum" class="sref">__wsum18a>ota href="+code=csum" class="sref">csum18a>, ta href="+code=__wsum" class="sref">__wsum18a>ota href="+code=csum2" class="sref">csum218a>,ointota href="+code=offset" class="sref">offset18a>).o 74t/a>{.o 75t/a>        ta href="+code=u32" class="sref">u32t/a> ta href="+code=sum" class="sref">sum18a> = (ta href="+code=__force" class="sref">__force18a>ota href="+code=u32" class="sref">u32t/a>)ta href="+code=csum2" class="sref">csum218a>;.o 76t/a>        if (ta href="+code=offset" class="sref">offset18a>&1).o 77t/a>                ta href="+code=sum" class="sref">sum18a> = ((ta href="+code=sum" class="sref">sum18a>&0xFF00FF)<<8)+((ta href="+code=sum" class="sref">sum18a>>>8)&0xFF00FF);.o 78t/a>        return ta href="+code=csum_add" class="sref">csum_addt/a>(ta href="+code=csum" class="sref">csum18a>, (ta href="+code=__force" class="sref">__force18a>ota href="+code=__wsum" class="sref">__wsum18a>)ta href="+code=sum" class="sref">sum18a>);.o 7918a>}.o 8018a>.o 81t/a>staticota href="+code=inline" class="sref">inlinet/a>ota href="+code=__wsum" class="sref">__wsum18a>.o 82t/a>ta href="+code=csum_block_sub" class="sref">csum_block_subt/a>(ta href="+code=__wsum" class="sref">__wsum18a>ota href="+code=csum" class="sref">csum18a>, ta href="+code=__wsum" class="sref">__wsum18a>ota href="+code=csum2" class="sref">csum218a>,ointota href="+code=offset" class="sref">offset18a>).o 83t/a>{.o 84t/a>        ta href="+code=u32" class="sref">u32t/a> ta href="+code=sum" class="sref">sum18a> = (ta href="+code=__force" class="sref">__force18a>ota href="+code=u32" class="sref">u32t/a>)ta href="+code=csum2" class="sref">csum218a>;.o 85t/a>        if (ta href="+code=offset" class="sref">offset18a>&1).o 86t/a>                ta href="+code=sum" class="sref">sum18a> = ((ta href="+code=sum" class="sref">sum18a>&0xFF00FF)<<8)+((ta href="+code=sum" class="sref">sum18a>>>8)&0xFF00FF);.o 87t/a>        return ta href="+code=csum_sub" class="sref">csum_subt/a>(ta href="+code=csum" class="sref">csum18a>, (ta href="+code=__force" class="sref">__force18a>ota href="+code=__wsum" class="sref">__wsum18a>)ta href="+code=sum" class="sref">sum18a>);.o 8818a>}.o 89t/a>.o 90t/a>staticota href="+code=inline" class="sref">inlinet/a>ota href="+code=__wsum" class="sref">__wsum18a>ota href="+code=csum_unfold" class="sref">csum_unfoldt/a>(ta href="+code=__sum16" class="sref">__sum1618a>ota href="+code=n" class="sref">n18a>).o 91t/a>{.o 92t/a>        return (ta href="+code=__force" class="sref">__force18a>ota href="+code=__wsum" class="sref">__wsum18a>)ta href="+code=n" class="sref">n18a>;.o 9318a>}.o 94t/a>.o 95t/a>#defineota href="+code=CSUM_MANGLED_0" class="sref">CSUM_MANGLED_018a>o((ta href="+code=__force" class="sref">__force18a>ota href="+code=__sum16" class="sref">__sum1618a>)0xffff).o 96t/a>.o 97t/a>staticota href="+code=inline" class="sref">inlinet/a>ovoidota href="+code=csum_replace4" class="sref">csum_replace4t/a>(ta href="+code=__sum16" class="sref">__sum1618a>o*ta href="+code=sum" class="sref">sum18a>, ta href="+code=__be32" class="sref">__be3218a>ota href="+code=from" class="sref">from18a>, ta href="+code=__be32" class="sref">__be3218a>ota href="+code=to" class="sref">to18a>).o 98t/a>{.o 99t/a>        ta href="+code=__be32" class="sref">__be3218a>ota href="+code=diff" class="sref">diff18a>[] = { ~ta href="+code=from" class="sref">from18a>, ta href="+code=to" class="sref">to18a> };.o100t/a>.o101t/a>        *ta href="+code=sum" class="sref">sum18a> = ta href="+code=csum_fold" class="sref">csum_foldt/a>(ta href="+code=csum_partial" class="sref">csum_partialt/a>(ta href="+code=diff" class="sref">diff18a>, sizeof(ta href="+code=diff" class="sref">diff18a>), ~ta href="+code=csum_unfold" class="sref">csum_unfoldt/a>(*ta href="+code=sum" class="sref">sum18a>)));.o10218a>}.o103t/a>.o104t/a>staticota href="+code=inline" class="sref">inlinet/a>ovoidota href="+code=csum_replace2" class="sref">csum_replace2t/a>(ta href="+code=__sum16" class="sref">__sum1618a>o*ta href="+code=sum" class="sref">sum18a>, ta href="+code=__be16" class="sref">__be1618a>ota href="+code=from" class="sref">from18a>, ta href="+code=__be16" class="sref">__be1618a>ota href="+code=to" class="sref">to18a>).o105t/a>{.o106t/a>        ta href="+code=csum_replace4" class="sref">csum_replace4t/a>(ta href="+code=sum" class="sref">sum18a>, (ta href="+code=__force" class="sref">__force18a>ota href="+code=__be32" class="sref">__be3218a>)ta href="+code=from" class="sref">from18a>, (ta href="+code=__force" class="sref">__force18a>ota href="+code=__be32" class="sref">__be3218a>)ta href="+code=to" class="sref">to18a>);.o10718a>}.o108t/a>.o109t/a>structota href="+code=sk_buff" class="sref">sk_buff18a>;.o13.18a>extern voidota href="+code=inet_proto_csum_replace4" class="sref">inet_proto_csum_replace4t/a>(ta href="+code=__sum16" class="sref">__sum1618a>o*ta href="+code=sum" class="sref">sum18a>, structota href="+code=sk_buff" class="sref">sk_buff18a>o*ta href="+code=skb" class="sref">skb18a>,.o111t/a>                                     ta href="+code=__be32" class="sref">__be3218a>ota href="+code=from" class="sref">from18a>, ta href="+code=__be32" class="sref">__be3218a>ota href="+code=to" class="sref">to18a>,ointota href="+code=pseudohdr" class="sref">pseudohdr18a>);.o112t/a>.o113t/a>staticota href="+code=inline" class="sref">inlinet/a>ovoidota href="+code=inet_proto_csum_replace2" class="sref">inet_proto_csum_replace2t/a>(ta href="+code=__sum16" class="sref">__sum1618a>o*ta href="+code=sum" class="sref">sum18a>, structota href="+code=sk_buff" class="sref">sk_buff18a>o*ta href="+code=skb" class="sref">skb18a>,.o114t/a>                                            ta href="+code=__be16" class="sref">__be1618a>ota href="+code=from" class="sref">from18a>, ta href="+code=__be16" class="sref">__be1618a>ota href="+code=to" class="sref">to18a>,.o115t/a>                                            intota href="+code=pseudohdr" class="sref">pseudohdr18a>).o116t/a>{.o117t/a>        ta href="+code=inet_proto_csum_replace4" class="sref">inet_proto_csum_replace4t/a>(ta href="+code=sum" class="sref">sum18a>, ta href="+code=skb" class="sref">skb18a>, (ta href="+code=__force" class="sref">__force18a>ota href="+code=__be32" class="sref">__be3218a>)ta href="+code=from" class="sref">from18a>,.o118t/a>                                 (ta href="+code=__force" class="sref">__force18a>ota href="+code=__be32" class="sref">__be3218a>)ta href="+code=to" class="sref">to18a>, ta href="+code=pseudohdr" class="sref">pseudohdr18a>);.o11918a>}.o120t/a>.o121t/a>#endif.o122t/a>
The original LXR software by the LXR community18a>, this experimental version by lxr@linux.no18a>. t/div2.tdiv class="subfooter"> lxr.linux.no kindly hosted by Redpill Linpro AS18a>, provider of Linux consuln>ng and operan>.1s services since 1995. t/div2. t/body2.t/html2.