From: Igor Maravic <[email protected]> Instead of getting checksum out of OSPF header, zeroing checksum location, calculating checksum and comparing if computed and received checksum are equal, just checksum received packet and see if result is equal to 0. Based on: http://en.wikipedia.org/wiki/Header_checksum
In case the received checksum is invalid, calculate it and print it out in exception message. Signed-off-by: Igor Maravic <[email protected]> --- xorp/ospf/packet.cc | 14 +++++++++----- 1 files changed, 9 insertions(+), 5 deletions(-) diff --git a/xorp/ospf/packet.cc b/xorp/ospf/packet.cc index 2b8c772..af29f94 100644 --- a/xorp/ospf/packet.cc +++ b/xorp/ospf/packet.cc @@ -288,9 +288,8 @@ Packet::decode_standard_header(uint8_t *ptr, size_t& len) throw(InvalidPacket) // Extract the checksum and check the packet. uint16_t checksum_inpacket = extract_16(&ptr[Packet::CHECKSUM_OFFSET]); - // Zero the checksum location. - embed_16(&ptr[Packet::CHECKSUM_OFFSET], 0); - uint16_t checksum_actual = checksum(ptr, len); + + uint16_t verify_checksum = checksum(ptr, len); // Restore the zero'd fields. switch(version) { @@ -300,17 +299,22 @@ Packet::decode_standard_header(uint8_t *ptr, size_t& len) throw(InvalidPacket) case OspfTypes::V3: break; } - embed_16(&ptr[Packet::CHECKSUM_OFFSET], checksum_inpacket); if (0 == checksum_inpacket && OspfTypes::CRYPTOGRAPHIC_AUTHENTICATION == get_auth_type()) return get_standard_header_length(); - if (checksum_inpacket != checksum_actual) + if (verify_checksum != 0) { + //Calculate valid checksum for debugging purposes + + // Zero the checksum location. + embed_16(&ptr[Packet::CHECKSUM_OFFSET], 0); + uint16_t checksum_actual = checksum(ptr, len); xorp_throw(InvalidPacket, c_format("Checksum mismatch expected %#x received %#x", checksum_actual, checksum_inpacket)); + } // Return the offset at which continued processing can take place. return get_standard_header_length(); -- 1.7.5.4 _______________________________________________ Xorp-hackers mailing list [email protected] http://mailman.ICSI.Berkeley.EDU/mailman/listinfo/xorp-hackers
