Commit b9e2fbb1 authored by Brickner_cp's avatar Brickner_cp

GRE

parent caa669f1
......@@ -102,9 +102,11 @@ namespace PcapDotNet.Packets.Test
greLayer.Checksum = actualGre.Checksum;
}
Assert.AreEqual(greLayer, actualGreLayer, "Layer");
Assert.AreNotEqual(random.NextGreLayer(), actualGreLayer, "Not Layer");
Assert.AreEqual(greLayer.Length, actualGre.HeaderLength);
Assert.IsTrue(actualGre.KeyPresent ^ (greLayer.Key == null));
MoreAssert.IsSmaller(8, actualGre.RecursionControl);
MoreAssert.IsSmaller(32, actualGre.Flags);
Assert.IsTrue(actualGre.RoutingPresent ^ (greLayer.Routing == null && greLayer.RoutingOffset == null));
Assert.IsTrue(actualGre.SequenceNumberPresent ^ (greLayer.SequenceNumber == null));
Assert.IsTrue(!actualGre.StrictSourceRoute || actualGre.RoutingPresent);
......
......@@ -640,18 +640,19 @@ namespace PcapDotNet.Packets.TestUtils
}
return new GreLayer
{
Version = random.NextEnum<GreVersion>(),
ProtocolType = random.NextEnum(EthernetType.None),
ChecksumPresent = isChecksum,
Checksum = isChecksum && random.NextBool() ? (ushort?)random.NextUShort() : null,
Key = random.NextBool() ? (uint?)random.NextUInt() : null,
SequenceNumber = random.NextBool() ? (uint?)random.NextUInt() : null,
RecursionControl = random.NextByte(8),
Routing = routing == null ? null : routing.AsReadOnly(),
RoutingOffset = routingOffset,
StrictSourceRoute = strictSourceRoute,
};
{
Version = random.NextEnum<GreVersion>(),
ProtocolType = random.NextEnum(EthernetType.None),
ChecksumPresent = isChecksum,
Checksum = isChecksum && random.NextBool() ? (ushort?)random.NextUShort() : null,
Key = random.NextBool() ? (uint?)random.NextUInt() : null,
SequenceNumber = random.NextBool() ? (uint?)random.NextUInt() : null,
RecursionControl = random.NextByte(8),
Flags = random.NextByte(32),
Routing = routing == null ? null : routing.AsReadOnly(),
RoutingOffset = routingOffset,
StrictSourceRoute = strictSourceRoute,
};
}
// ICMP
......
......@@ -258,6 +258,7 @@ namespace PcapDotNet.Packets.Gre
Version = Version,
ProtocolType = ProtocolType,
RecursionControl = RecursionControl,
Flags = Flags,
ChecksumPresent = ChecksumPresent,
Checksum = ChecksumPresent ? (ushort?)Checksum : null,
Key = KeyPresent ? (uint?)Key : null,
......@@ -288,7 +289,7 @@ namespace PcapDotNet.Packets.Gre
}
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,
ReadOnlyCollection<GreSourceRouteEntry> routing, ushort? routingOffset, bool strictSourceRoute)
{
......@@ -300,7 +301,7 @@ namespace PcapDotNet.Packets.Gre
(strictSourceRoute ? Mask.StrictSourceRoute : (byte)0) |
(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);
......
......@@ -11,6 +11,7 @@ namespace PcapDotNet.Packets.Gre
public GreVersion Version { get; set; }
public EthernetType ProtocolType { get; set; }
public byte RecursionControl { get; set; }
public byte Flags { get; set; }
public bool ChecksumPresent { get; set; }
public ushort? Checksum { get; set; }
public uint? Key { get; set; }
......@@ -29,7 +30,7 @@ namespace PcapDotNet.Packets.Gre
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)
......@@ -44,6 +45,7 @@ namespace PcapDotNet.Packets.Gre
Version.Equals(other.Version) &&
ProtocolType.Equals(other.ProtocolType) &&
RecursionControl.Equals(other.RecursionControl) &&
Flags.Equals(other.Flags) &&
ChecksumPresent.Equals(other.ChecksumPresent) &&
(Checksum == null ? other.Checksum == null : Checksum.Equals(other.Checksum)) &&
(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