Commit 7228fb73 authored by Brickner_cp's avatar Brickner_cp

GRE refactoring.

parent 433ea023
......@@ -6,14 +6,14 @@ namespace PcapDotNet.Packets.Ethernet
public abstract class EthernetBaseDatagram : Datagram
{
/// <summary>
/// Ethernet type (next protocol).
/// Header length in bytes.
/// </summary>
public abstract EthernetType EtherType { get; }
public abstract int HeaderLength { get; }
/// <summary>
/// Header length in bytes.
/// Ethernet type (next protocol).
/// </summary>
public abstract int HeaderLength { get; }
public abstract EthernetType EtherType { get; }
/// <summary>
/// The Ethernet payload.
......
......@@ -29,6 +29,9 @@ namespace PcapDotNet.Packets.Ethernet
/// </summary>
public const int HeaderLengthValue = Offset.EtherTypeLength + sizeof(ushort);
/// <summary>
/// Header length in bytes.
/// </summary>
public override int HeaderLength
{
get { return HeaderLengthValue; }
......
......@@ -28,7 +28,7 @@ namespace PcapDotNet.Packets.Gre
/// +-----+---------------------------------------------------------------------+
/// </pre>
/// </summary>
public sealed class GreDatagram : Datagram
public sealed class GreDatagram : EthernetBaseDatagram
{
private static class Offset
{
......@@ -72,7 +72,7 @@ namespace PcapDotNet.Packets.Gre
/// <summary>
/// The length of the full GRE header on bytes.
/// </summary>
public int HeaderLength
public override int HeaderLength
{
get
{
......@@ -80,6 +80,14 @@ namespace PcapDotNet.Packets.Gre
}
}
/// <summary>
/// Ethernet type (next protocol).
/// </summary>
public override EthernetType EtherType
{
get { return ProtocolType; }
}
/// <summary>
/// If the Checksum Present bit is set to 1, then the Checksum field is present and contains valid information.
/// If either the Checksum Present bit or the Routing Present bit are set, BOTH the Checksum and Offset fields are present in the GRE packet.
......@@ -320,30 +328,6 @@ namespace PcapDotNet.Packets.Gre
};
}
/// <summary>
/// The Ethernet payload.
/// </summary>
public Datagram Payload
{
get { return PayloadDatagrams.Payload; }
}
/// <summary>
/// The Ethernet payload as an IPv4 datagram.
/// </summary>
public IpV4Datagram IpV4
{
get { return PayloadDatagrams.IpV4; }
}
/// <summary>
/// The Ethernet payload as an ARP datagram.
/// </summary>
public ArpDatagram Arp
{
get { return PayloadDatagrams.Arp; }
}
/// <summary>
/// A GRE Datagram is valid if its length is enough for the GRE header, its routing information is valid,
/// the bits for future use are set to 0, it has acknowledgment sequence number only if it's Enhanced GRE,
......@@ -354,7 +338,7 @@ namespace PcapDotNet.Packets.Gre
{
if (Length < HeaderMinimumLength || Length < HeaderLength)
return false;
Datagram payloadByProtocolType = PayloadDatagrams.Get(ProtocolType);
Datagram payloadByProtocolType = PayloadByEtherType;
return (IsValidRouting && FutureUseBits == 0 &&
(Version == GreVersion.EnhancedGre || Version == GreVersion.Gre && !AcknowledgmentSequenceNumberPresent) &&
(!ChecksumPresent || IsChecksumCorrect) &&
......@@ -513,18 +497,6 @@ namespace PcapDotNet.Packets.Gre
}
}
private EthernetPayloadDatagrams PayloadDatagrams
{
get
{
return _payloadDatagrams ?? (_payloadDatagrams = new EthernetPayloadDatagrams(Length >= HeaderLength
? new Datagram(Buffer, StartOffset + HeaderLength,
Length - HeaderLength)
: null));
}
}
private EthernetPayloadDatagrams _payloadDatagrams;
private ReadOnlyCollection<GreSourceRouteEntry> _routing;
private bool _isValidRouting = true;
private bool? _isChecksumCorrect;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment