Commit b9e2fbb1 authored by Brickner_cp's avatar Brickner_cp

GRE

parent caa669f1
...@@ -102,9 +102,11 @@ namespace PcapDotNet.Packets.Test ...@@ -102,9 +102,11 @@ namespace PcapDotNet.Packets.Test
greLayer.Checksum = actualGre.Checksum; greLayer.Checksum = actualGre.Checksum;
} }
Assert.AreEqual(greLayer, actualGreLayer, "Layer"); Assert.AreEqual(greLayer, actualGreLayer, "Layer");
Assert.AreNotEqual(random.NextGreLayer(), actualGreLayer, "Not Layer");
Assert.AreEqual(greLayer.Length, actualGre.HeaderLength); Assert.AreEqual(greLayer.Length, actualGre.HeaderLength);
Assert.IsTrue(actualGre.KeyPresent ^ (greLayer.Key == null)); Assert.IsTrue(actualGre.KeyPresent ^ (greLayer.Key == null));
MoreAssert.IsSmaller(8, actualGre.RecursionControl); MoreAssert.IsSmaller(8, actualGre.RecursionControl);
MoreAssert.IsSmaller(32, actualGre.Flags);
Assert.IsTrue(actualGre.RoutingPresent ^ (greLayer.Routing == null && greLayer.RoutingOffset == null)); Assert.IsTrue(actualGre.RoutingPresent ^ (greLayer.Routing == null && greLayer.RoutingOffset == null));
Assert.IsTrue(actualGre.SequenceNumberPresent ^ (greLayer.SequenceNumber == null)); Assert.IsTrue(actualGre.SequenceNumberPresent ^ (greLayer.SequenceNumber == null));
Assert.IsTrue(!actualGre.StrictSourceRoute || actualGre.RoutingPresent); Assert.IsTrue(!actualGre.StrictSourceRoute || actualGre.RoutingPresent);
......
...@@ -640,18 +640,19 @@ namespace PcapDotNet.Packets.TestUtils ...@@ -640,18 +640,19 @@ namespace PcapDotNet.Packets.TestUtils
} }
return new GreLayer return new GreLayer
{ {
Version = random.NextEnum<GreVersion>(), Version = random.NextEnum<GreVersion>(),
ProtocolType = random.NextEnum(EthernetType.None), ProtocolType = random.NextEnum(EthernetType.None),
ChecksumPresent = isChecksum, ChecksumPresent = isChecksum,
Checksum = isChecksum && random.NextBool() ? (ushort?)random.NextUShort() : null, Checksum = isChecksum && random.NextBool() ? (ushort?)random.NextUShort() : null,
Key = random.NextBool() ? (uint?)random.NextUInt() : null, Key = random.NextBool() ? (uint?)random.NextUInt() : null,
SequenceNumber = random.NextBool() ? (uint?)random.NextUInt() : null, SequenceNumber = random.NextBool() ? (uint?)random.NextUInt() : null,
RecursionControl = random.NextByte(8), RecursionControl = random.NextByte(8),
Routing = routing == null ? null : routing.AsReadOnly(), Flags = random.NextByte(32),
RoutingOffset = routingOffset, Routing = routing == null ? null : routing.AsReadOnly(),
StrictSourceRoute = strictSourceRoute, RoutingOffset = routingOffset,
}; StrictSourceRoute = strictSourceRoute,
};
} }
// ICMP // ICMP
......
...@@ -258,6 +258,7 @@ namespace PcapDotNet.Packets.Gre ...@@ -258,6 +258,7 @@ namespace PcapDotNet.Packets.Gre
Version = Version, Version = Version,
ProtocolType = ProtocolType, ProtocolType = ProtocolType,
RecursionControl = RecursionControl, RecursionControl = RecursionControl,
Flags = Flags,
ChecksumPresent = ChecksumPresent, ChecksumPresent = ChecksumPresent,
Checksum = ChecksumPresent ? (ushort?)Checksum : null, Checksum = ChecksumPresent ? (ushort?)Checksum : null,
Key = KeyPresent ? (uint?)Key : null, Key = KeyPresent ? (uint?)Key : null,
...@@ -288,7 +289,7 @@ namespace PcapDotNet.Packets.Gre ...@@ -288,7 +289,7 @@ namespace PcapDotNet.Packets.Gre
} }
internal static void WriteHeader(byte[] buffer, int offset, internal static void WriteHeader(byte[] buffer, int offset,
byte recursionControl, GreVersion version, EthernetType protocolType, byte recursionControl, byte flags, GreVersion version, EthernetType protocolType,
bool checksumPresent, uint? key, uint? sequenceNumber, bool checksumPresent, uint? key, uint? sequenceNumber,
ReadOnlyCollection<GreSourceRouteEntry> routing, ushort? routingOffset, bool strictSourceRoute) ReadOnlyCollection<GreSourceRouteEntry> routing, ushort? routingOffset, bool strictSourceRoute)
{ {
...@@ -300,7 +301,7 @@ namespace PcapDotNet.Packets.Gre ...@@ -300,7 +301,7 @@ namespace PcapDotNet.Packets.Gre
(strictSourceRoute ? Mask.StrictSourceRoute : (byte)0) | (strictSourceRoute ? Mask.StrictSourceRoute : (byte)0) |
(recursionControl & Mask.RecursionControl))); (recursionControl & Mask.RecursionControl)));
buffer.Write(offset + Offset.Version, (byte)((byte)version & Mask.Version)); buffer.Write(offset + Offset.Flags, (byte)(((flags << Shift.Flags) & Mask.Flags) | ((byte)version & Mask.Version)));
buffer.Write(offset + Offset.ProtocolType, (ushort)protocolType, Endianity.Big); buffer.Write(offset + Offset.ProtocolType, (ushort)protocolType, Endianity.Big);
......
...@@ -11,6 +11,7 @@ namespace PcapDotNet.Packets.Gre ...@@ -11,6 +11,7 @@ namespace PcapDotNet.Packets.Gre
public GreVersion Version { get; set; } public GreVersion Version { get; set; }
public EthernetType ProtocolType { get; set; } public EthernetType ProtocolType { get; set; }
public byte RecursionControl { get; set; } public byte RecursionControl { get; set; }
public byte Flags { get; set; }
public bool ChecksumPresent { get; set; } public bool ChecksumPresent { get; set; }
public ushort? Checksum { get; set; } public ushort? Checksum { get; set; }
public uint? Key { get; set; } public uint? Key { get; set; }
...@@ -29,7 +30,7 @@ namespace PcapDotNet.Packets.Gre ...@@ -29,7 +30,7 @@ namespace PcapDotNet.Packets.Gre
public override void Write(byte[] buffer, int offset, int payloadLength, ILayer previousLayer, ILayer nextLayer) public override void Write(byte[] buffer, int offset, int payloadLength, ILayer previousLayer, ILayer nextLayer)
{ {
GreDatagram.WriteHeader(buffer, offset, RecursionControl, Version, ProtocolType, ChecksumPresent, Key, SequenceNumber, Routing, RoutingOffset, StrictSourceRoute); GreDatagram.WriteHeader(buffer, offset, RecursionControl, Flags, Version, ProtocolType, ChecksumPresent, Key, SequenceNumber, Routing, RoutingOffset, StrictSourceRoute);
} }
public override void Finalize(byte[] buffer, int offset, int payloadLength, ILayer nextLayer) public override void Finalize(byte[] buffer, int offset, int payloadLength, ILayer nextLayer)
...@@ -44,6 +45,7 @@ namespace PcapDotNet.Packets.Gre ...@@ -44,6 +45,7 @@ namespace PcapDotNet.Packets.Gre
Version.Equals(other.Version) && Version.Equals(other.Version) &&
ProtocolType.Equals(other.ProtocolType) && ProtocolType.Equals(other.ProtocolType) &&
RecursionControl.Equals(other.RecursionControl) && RecursionControl.Equals(other.RecursionControl) &&
Flags.Equals(other.Flags) &&
ChecksumPresent.Equals(other.ChecksumPresent) && ChecksumPresent.Equals(other.ChecksumPresent) &&
(Checksum == null ? other.Checksum == null : Checksum.Equals(other.Checksum)) && (Checksum == null ? other.Checksum == null : Checksum.Equals(other.Checksum)) &&
(Key == null ? other.Key == null : Key.Equals(other.Key)) && (Key == null ? other.Key == null : Key.Equals(other.Key)) &&
......
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