17200ac3cSMark McLoughlin /* 27200ac3cSMark McLoughlin * IP checksumming functions. 37200ac3cSMark McLoughlin * (c) 2008 Gerd Hoffmann <kraxel@redhat.com> 47200ac3cSMark McLoughlin * 57200ac3cSMark McLoughlin * This program is free software; you can redistribute it and/or modify 67200ac3cSMark McLoughlin * it under the terms of the GNU General Public License as published by 77200ac3cSMark McLoughlin * the Free Software Foundation; under version 2 of the License. 87200ac3cSMark McLoughlin * 97200ac3cSMark McLoughlin * This program is distributed in the hope that it will be useful, 107200ac3cSMark McLoughlin * but WITHOUT ANY WARRANTY; without even the implied warranty of 117200ac3cSMark McLoughlin * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 127200ac3cSMark McLoughlin * GNU General Public License for more details. 137200ac3cSMark McLoughlin * 147200ac3cSMark McLoughlin * You should have received a copy of the GNU General Public License 157200ac3cSMark McLoughlin * along with this program; if not, see <http://www.gnu.org/licenses/>. 167200ac3cSMark McLoughlin */ 177200ac3cSMark McLoughlin 187200ac3cSMark McLoughlin #ifndef QEMU_NET_CHECKSUM_H 197200ac3cSMark McLoughlin #define QEMU_NET_CHECKSUM_H 207200ac3cSMark McLoughlin 217200ac3cSMark McLoughlin #include <stdint.h> 227200ac3cSMark McLoughlin 23*5acf5ea4SDmitry Fleytman uint32_t net_checksum_add_cont(int len, uint8_t *buf, int seq); 247200ac3cSMark McLoughlin uint16_t net_checksum_finish(uint32_t sum); 257200ac3cSMark McLoughlin uint16_t net_checksum_tcpudp(uint16_t length, uint16_t proto, 267200ac3cSMark McLoughlin uint8_t *addrs, uint8_t *buf); 277200ac3cSMark McLoughlin void net_checksum_calculate(uint8_t *data, int length); 287200ac3cSMark McLoughlin 29*5acf5ea4SDmitry Fleytman static inline uint32_t 30*5acf5ea4SDmitry Fleytman net_checksum_add(int len, uint8_t *buf) 31*5acf5ea4SDmitry Fleytman { 32*5acf5ea4SDmitry Fleytman return net_checksum_add_cont(len, buf, 0); 33*5acf5ea4SDmitry Fleytman } 34*5acf5ea4SDmitry Fleytman 35*5acf5ea4SDmitry Fleytman static inline uint16_t 36*5acf5ea4SDmitry Fleytman net_raw_checksum(uint8_t *data, int length) 37*5acf5ea4SDmitry Fleytman { 38*5acf5ea4SDmitry Fleytman return net_checksum_finish(net_checksum_add(length, data)); 39*5acf5ea4SDmitry Fleytman } 40*5acf5ea4SDmitry Fleytman 417200ac3cSMark McLoughlin #endif /* QEMU_NET_CHECKSUM_H */ 42