dotpcap/packetnet

GRE decoding not correct (wrong byte and false bitmask)

Bart-Baekelandt opened this issue · 3 comments

The GRE protocol is not correctly parsed by the PacketNet library

in GrePacket.cs

original code :
public bool HasCheckSum => 8 == (Header.Bytes[Header.Offset + 1] & 0x8);
public bool HasKey => 2 == (Header.Bytes[Header.Offset + 1] & 0x2);
public bool HasReserved => 4 == (Header.Bytes[Header.Offset + 1] & 0x4);
public bool HasSequence => 1 == (Header.Bytes[Header.Offset + 1] & 0x1);

proposal for new code :
public bool HasCheckSum => 0x80 == (Header.Bytes[Header.Offset + 0] & 0x80);
public bool HasKey => 0x20 == (Header.Bytes[Header.Offset + 0] & 0x20);
public bool HasReserved => false; // 4 == (Header.Bytes[Header.Offset + 1] & 0x4);
public bool HasSequence => 0x10 == (Header.Bytes[Header.Offset + 0] & 0x10);

See also https://en.wikipedia.org/wiki/Generic_Routing_Encapsulation

Example where the original code fails :
gre_seq_2.zip

Can you submit a PR for this and a test @Bart-Baekelandt?

gre_screenshot

See also decoding in Wireshark

Should be fixed now, so closing.