dotpcap / packetnet

Official repository - High performance .Net assembly for dissecting and constructing network packets such as ethernet, ip, tcp, udp etc.
Mozilla Public License 2.0
483 stars 104 forks source link

OSPF V2 packet with link-local signaling (LLS) data not handled correctly #157

Open Bart-Baekelandt opened 3 years ago

Bart-Baekelandt commented 3 years ago

OSPF V2 packet with link-local signaling (LLS) data is not extracted correctly. The length of the LLS data is not determined by the OSPF header but by the IP header.

See RFC for this : https://datatracker.ietf.org/doc/html/rfc5613#section-2

The problem is that when an OSPF V2 packet is extracted Extract() then the length of the resulting packet does not include the LLS data. This is because the OspfV2Packet constructor does not contain a payload part.

Proposed solution :

protected OspfV2Packet(byte[] bytes, int offset) { Log.Debug(""); Header = new ByteArraySegment(bytes, offset, OspfV2Fields.HeaderLength); Version = OspfVersion.OspfV2;

// ==== BEGIN ADDITIONAL CODE =====
// Add payload 
ushort OspfPacketLength = (ushort)(bytes.Length - offset);
ushort OspfDataLength = (ushort)(PacketLength - OspfV2Fields.HeaderLength); ;
if (OspfPacketLength > PacketLength)
{
    OspfDataLength = (ushort)(OspfPacketLength - OspfV2Fields.HeaderLength);
}

PayloadPacketOrData = new LazySlim<PacketOrByteArraySegment>(() =>
{
    var result = new PacketOrByteArraySegment();
    // store the payload bytes
    result.ByteArraySegment = new ByteArraySegment(bytes, offset + OspfV2Fields.HeaderLength, OspfDataLength, bytes.Length); ;
    return result;
});
// ==== END ADDITIONAL CODE =====

}

Example trace added ospf_lls.zip .

PhyxionNL commented 3 years ago

Feel free to submit a PR for this.