1 /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 /* 3 * Copyright (c) 2022 Huawei Device Co., Ltd. 4 * 5 * Description: Provides some functionalities for 6 * checksum calculation in the NewIP protocol. 7 * 8 * Author: Yang Yanjun <yangyanjun@huawei.com> 9 * 10 * Data: 2022-07-18 11 */ 12 #ifndef _NIP_CHECKSUM_H 13 #define _NIP_CHECKSUM_H 14 15 #include "nip_addr.h" 16 17 struct nip_pseudo_header { 18 struct nip_addr saddr; /* Source address, network order.(big end) */ 19 struct nip_addr daddr; /* Destination address, network order.(big end) */ 20 unsigned short check_len; /* network order.(big end) */ 21 unsigned char nexthdr; /* Upper-layer Protocol Type: IPPROTO_UDP */ 22 }; 23 24 /* The checksum is calculated when the packet is received 25 * Note: 26 * 1.chksum_header->check_len is network order.(big end) 27 * 2.data_len is host order. 28 */ 29 unsigned short nip_check_sum_parse(unsigned char *data, 30 unsigned short check_len, 31 struct nip_pseudo_header *chksum_header); 32 33 /* The checksum is calculated when the packet is sent 34 * Note: 35 * 1.chksum_header->check_len is network order.(big end) 36 * 2.data_len is host order. 37 */ 38 unsigned short nip_check_sum_build(unsigned char *data, 39 unsigned short data_len, 40 struct nip_pseudo_header *chksum_header); 41 42 #endif /* _NIP_CHECKSUM_H */ 43 44