xref: /qemu/include/net/checksum.h (revision 84026301694b98dd08272e613da3497b17023d5c)
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 
235acf5ea4SDmitry 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 
295acf5ea4SDmitry Fleytman static inline uint32_t
305acf5ea4SDmitry Fleytman net_checksum_add(int len, uint8_t *buf)
315acf5ea4SDmitry Fleytman {
325acf5ea4SDmitry Fleytman     return net_checksum_add_cont(len, buf, 0);
335acf5ea4SDmitry Fleytman }
345acf5ea4SDmitry Fleytman 
355acf5ea4SDmitry Fleytman static inline uint16_t
365acf5ea4SDmitry Fleytman net_raw_checksum(uint8_t *data, int length)
375acf5ea4SDmitry Fleytman {
385acf5ea4SDmitry Fleytman     return net_checksum_finish(net_checksum_add(length, data));
395acf5ea4SDmitry Fleytman }
405acf5ea4SDmitry Fleytman 
41*84026301SDmitry Fleytman /**
42*84026301SDmitry Fleytman  * net_checksum_add_iov: scatter-gather vector checksumming
43*84026301SDmitry Fleytman  *
44*84026301SDmitry Fleytman  * @iov: input scatter-gather array
45*84026301SDmitry Fleytman  * @iov_cnt: number of array elements
46*84026301SDmitry Fleytman  * @iov_off: starting iov offset for checksumming
47*84026301SDmitry Fleytman  * @size: length of data to be checksummed
48*84026301SDmitry Fleytman  */
49*84026301SDmitry Fleytman uint32_t net_checksum_add_iov(const struct iovec *iov,
50*84026301SDmitry Fleytman                               const unsigned int iov_cnt,
51*84026301SDmitry Fleytman                               uint32_t iov_off, uint32_t size);
52*84026301SDmitry Fleytman 
537200ac3cSMark McLoughlin #endif /* QEMU_NET_CHECKSUM_H */
54