]> git.proxmox.com Git - mirror_frr.git/blame - isisd/iso_checksum.c
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / isisd / iso_checksum.c
CommitLineData
acddc0ed 1// SPDX-License-Identifier: GPL-2.0-or-later
eb5d44eb 2/*
3 * IS-IS Rout(e)ing protocol - iso_checksum.c
4 * ISO checksum related routines
5 *
6 * Copyright (C) 2001,2002 Sampo Saaristo
d62a17ae 7 * Tampere University of Technology
eb5d44eb 8 * Institute of Communications Engineering
eb5d44eb 9 */
10
11#include <zebra.h>
12#include "iso_checksum.h"
6a270cd9 13#include "checksum.h"
eb5d44eb 14
15/*
16 * Calculations of the OSI checksum.
17 * ISO/IEC 8473 defines the sum as
18 *
19 * L
20 * sum a (mod 255) = 0
21 * 1 i
22 *
d62a17ae 23 * L
eb5d44eb 24 * sum (L-i+1)a (mod 255) = 0
25 * 1 i
26 *
27 */
28
29/*
30 * Verifies that the checksum is correct.
31 * Return 0 on correct and 1 on invalid checksum.
32 * Based on Annex C.4 of ISO/IEC 8473
eb5d44eb 33 */
34
d7c0a89a 35int iso_csum_verify(uint8_t *buffer, int len, uint16_t csum, int offset)
f390d2c7 36{
d7c0a89a
QY
37 uint16_t checksum;
38 uint32_t c0;
39 uint32_t c1;
eb5d44eb 40
d62a17ae 41 c0 = csum & 0xff00;
42 c1 = csum & 0x00ff;
eb5d44eb 43
d62a17ae 44 /*
45 * If both are zero return correct
46 */
47 if (c0 == 0 && c1 == 0)
48 return 0;
eb5d44eb 49
d62a17ae 50 /*
51 * If either, but not both are zero return incorrect
52 */
53 if (c0 == 0 || c1 == 0)
54 return 1;
f390d2c7 55
d62a17ae 56 checksum = fletcher_checksum(buffer, len, offset);
af8ac8f9 57 if (checksum == htons(csum))
d62a17ae 58 return 0;
59 return 1;
eb5d44eb 60}