aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet/ip/ip4_format.c
diff options
context:
space:
mode:
authorBenoît Ganne <bganne@cisco.com>2020-08-31 18:59:34 +0200
committerDamjan Marion <dmarion@me.com>2020-09-01 12:03:27 +0000
commit6e334e3e77bb156a9317a37500077a218a04f7a3 (patch)
treefa2caf364ba7d99ca7e3895c37bb1047c6be8c0f /src/vnet/ip/ip4_format.c
parent1d104c5ecdce37301fdfea0e62a533a2e5342ee0 (diff)
ip: fix ip zero checksum verification
In one's complement, there are two representations of zero: the all zero and the all one bit values, often referred to as +0 and -0. See RFC 1624 section 3 for more details. This used to be taken care of in ip4_header_checksum(), but it is no longer the case. The check ip->checksum == ip4_header_checksum (ip) is no longer correct in the -0 case. Always use ip4_header_checksum_is_valid() instead (which behaves correctly since 9a79a1ab931c3b5a7ae07d6f0fcfef7c4368a2c4). Type: fix Fixes: e5f0050c7a5d411f96af6401797529d58825e2af Change-Id: Iacc6b60645a834287b085aecb9e3fdb4554cf0cf Signed-off-by: Benoît Ganne <bganne@cisco.com>
Diffstat (limited to 'src/vnet/ip/ip4_format.c')
-rw-r--r--src/vnet/ip/ip4_format.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/vnet/ip/ip4_format.c b/src/vnet/ip/ip4_format.c
index 786a01d396b..c6639b20716 100644
--- a/src/vnet/ip/ip4_format.c
+++ b/src/vnet/ip/ip4_format.c
@@ -150,9 +150,10 @@ format_ip4_header (u8 * s, va_list * args)
/* Check and report invalid checksums. */
{
- u16 c = ip4_header_checksum (ip);
- if (c != ip->checksum)
- s = format (s, " (should be 0x%04x)", clib_net_to_host_u16 (c));
+ if (!ip4_header_checksum_is_valid (ip))
+ s =
+ format (s, " (should be 0x%04x)",
+ clib_net_to_host_u16 (ip4_header_checksum (ip)));
}
s = format (s, " dscp %U ecn %U",