Commit 7228fb73 authored by Brickner_cp's avatar Brickner_cp

GRE refactoring.

parent 433ea023
...@@ -6,14 +6,14 @@ namespace PcapDotNet.Packets.Ethernet ...@@ -6,14 +6,14 @@ namespace PcapDotNet.Packets.Ethernet
public abstract class EthernetBaseDatagram : Datagram public abstract class EthernetBaseDatagram : Datagram
{ {
/// <summary> /// <summary>
/// Ethernet type (next protocol). /// Header length in bytes.
/// </summary> /// </summary>
public abstract EthernetType EtherType { get; } public abstract int HeaderLength { get; }
/// <summary> /// <summary>
/// Header length in bytes. /// Ethernet type (next protocol).
/// </summary> /// </summary>
public abstract int HeaderLength { get; } public abstract EthernetType EtherType { get; }
/// <summary> /// <summary>
/// The Ethernet payload. /// The Ethernet payload.
......
...@@ -29,6 +29,9 @@ namespace PcapDotNet.Packets.Ethernet ...@@ -29,6 +29,9 @@ namespace PcapDotNet.Packets.Ethernet
/// </summary> /// </summary>
public const int HeaderLengthValue = Offset.EtherTypeLength + sizeof(ushort); public const int HeaderLengthValue = Offset.EtherTypeLength + sizeof(ushort);
/// <summary>
/// Header length in bytes.
/// </summary>
public override int HeaderLength public override int HeaderLength
{ {
get { return HeaderLengthValue; } get { return HeaderLengthValue; }
......
...@@ -28,7 +28,7 @@ namespace PcapDotNet.Packets.Gre ...@@ -28,7 +28,7 @@ namespace PcapDotNet.Packets.Gre
/// +-----+---------------------------------------------------------------------+ /// +-----+---------------------------------------------------------------------+
/// </pre> /// </pre>
/// </summary> /// </summary>
public sealed class GreDatagram : Datagram public sealed class GreDatagram : EthernetBaseDatagram
{ {
private static class Offset private static class Offset
{ {
...@@ -72,7 +72,7 @@ namespace PcapDotNet.Packets.Gre ...@@ -72,7 +72,7 @@ namespace PcapDotNet.Packets.Gre
/// <summary> /// <summary>
/// The length of the full GRE header on bytes. /// The length of the full GRE header on bytes.
/// </summary> /// </summary>
public int HeaderLength public override int HeaderLength
{ {
get get
{ {
...@@ -80,6 +80,14 @@ namespace PcapDotNet.Packets.Gre ...@@ -80,6 +80,14 @@ namespace PcapDotNet.Packets.Gre
} }
} }
/// <summary>
/// Ethernet type (next protocol).
/// </summary>
public override EthernetType EtherType
{
get { return ProtocolType; }
}
/// <summary> /// <summary>
/// If the Checksum Present bit is set to 1, then the Checksum field is present and contains valid information. /// 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. /// 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 ...@@ -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> /// <summary>
/// A GRE Datagram is valid if its length is enough for the GRE header, its routing information is valid, /// 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, /// 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 ...@@ -354,7 +338,7 @@ namespace PcapDotNet.Packets.Gre
{ {
if (Length < HeaderMinimumLength || Length < HeaderLength) if (Length < HeaderMinimumLength || Length < HeaderLength)
return false; return false;
Datagram payloadByProtocolType = PayloadDatagrams.Get(ProtocolType); Datagram payloadByProtocolType = PayloadByEtherType;
return (IsValidRouting && FutureUseBits == 0 && return (IsValidRouting && FutureUseBits == 0 &&
(Version == GreVersion.EnhancedGre || Version == GreVersion.Gre && !AcknowledgmentSequenceNumberPresent) && (Version == GreVersion.EnhancedGre || Version == GreVersion.Gre && !AcknowledgmentSequenceNumberPresent) &&
(!ChecksumPresent || IsChecksumCorrect) && (!ChecksumPresent || IsChecksumCorrect) &&
...@@ -512,19 +496,7 @@ namespace PcapDotNet.Packets.Gre ...@@ -512,19 +496,7 @@ namespace PcapDotNet.Packets.Gre
return _isValidRouting; return _isValidRouting;
} }
} }
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 ReadOnlyCollection<GreSourceRouteEntry> _routing;
private bool _isValidRouting = true; private bool _isValidRouting = true;
private bool? _isChecksumCorrect; 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