Commit 9c02de2e authored by Brickner_cp's avatar Brickner_cp

IPv6

Code Coverage 95.63%
parent 89e9eb33
......@@ -108,6 +108,7 @@ namespace PcapDotNet.Core.Test
protocol == IpV4Protocol.Skip ||
protocol == IpV4Protocol.Bna ||
protocol == IpV4Protocol.InterDomainRoutingProtocol ||
protocol == IpV4Protocol.ActiveNetworks ||
protocol == IpV4Protocol.RemoteVirtualDiskProtocol))
return false;
......
......@@ -423,6 +423,75 @@ namespace PcapDotNet.Packets.Test
Assert.IsNull(new IpV6AccessNetworkIdentifierSubOptionNetworkIdentifier(false, DataSegment.Empty, new DataSegment(new byte[256])));
}
[TestMethod]
public void IpV6AccessNetworkIdentifierSubOptionNetworkIdentifierDataTooShort()
{
Packet packet = PacketBuilder.Build(
DateTime.Now,
new EthernetLayer(),
new IpV6Layer
{
ExtensionHeaders =
new IpV6ExtensionHeaders(
new IpV6ExtensionHeaderMobilityBindingError(
IpV4Protocol.Skip, 0, IpV6BindingErrorStatus.UnrecognizedMhTypeValue, IpV6Address.Zero,
new IpV6MobilityOptions(
new IpV6MobilityOptionAccessNetworkIdentifier(
new IpV6AccessNetworkIdentifierSubOptions(
new IpV6AccessNetworkIdentifierSubOptionNetworkIdentifier(false, DataSegment.Empty, DataSegment.Empty))))))
});
Assert.IsTrue(packet.IsValid);
--packet.Buffer[14 + 40 + 24 + 2 + 1];
Packet invalidPacket = new Packet(packet.Buffer, DateTime.Now, DataLinkKind.Ethernet);
Assert.IsFalse(invalidPacket.IsValid);
}
[TestMethod]
public void IpV6AccessNetworkIdentifierSubOptionNetworkIdentifierDataTooShortForNetworkName()
{
Packet packet = PacketBuilder.Build(
DateTime.Now,
new EthernetLayer(),
new IpV6Layer
{
ExtensionHeaders =
new IpV6ExtensionHeaders(
new IpV6ExtensionHeaderMobilityBindingError(
IpV4Protocol.Skip, 0, IpV6BindingErrorStatus.UnrecognizedMhTypeValue, IpV6Address.Zero,
new IpV6MobilityOptions(
new IpV6MobilityOptionAccessNetworkIdentifier(
new IpV6AccessNetworkIdentifierSubOptions(
new IpV6AccessNetworkIdentifierSubOptionNetworkIdentifier(false, new DataSegment(new byte[1]), DataSegment.Empty))))))
});
Assert.IsTrue(packet.IsValid);
--packet.Buffer[14 + 40 + 24 + 2 + 1];
Packet invalidPacket = new Packet(packet.Buffer, DateTime.Now, DataLinkKind.Ethernet);
Assert.IsFalse(invalidPacket.IsValid);
}
[TestMethod]
public void IpV6AccessNetworkIdentifierSubOptionNetworkIdentifierDataTooShortForAccessPointName()
{
Packet packet = PacketBuilder.Build(
DateTime.Now,
new EthernetLayer(),
new IpV6Layer
{
ExtensionHeaders =
new IpV6ExtensionHeaders(
new IpV6ExtensionHeaderMobilityBindingError(
IpV4Protocol.Skip, 0, IpV6BindingErrorStatus.UnrecognizedMhTypeValue, IpV6Address.Zero,
new IpV6MobilityOptions(
new IpV6MobilityOptionAccessNetworkIdentifier(
new IpV6AccessNetworkIdentifierSubOptions(
new IpV6AccessNetworkIdentifierSubOptionNetworkIdentifier(false, DataSegment.Empty, new DataSegment(new byte[1])))))))
});
Assert.IsTrue(packet.IsValid);
--packet.Buffer[14 + 40 + 24 + 2 + 1];
Packet invalidPacket = new Packet(packet.Buffer, DateTime.Now, DataLinkKind.Ethernet);
Assert.IsFalse(invalidPacket.IsValid);
}
[TestMethod]
[ExpectedException(typeof(ArgumentOutOfRangeException), AllowDerivedTypes = false)]
public void IpV6ExtensionHeaderRoutingRplCommonPrefixNotCommon()
......@@ -918,8 +987,54 @@ namespace PcapDotNet.Packets.Test
new IpV6MobilityOptionMobileNodeIdentifier(IpV6MobileNodeIdentifierSubtype.NetworkAccessIdentifier, new DataSegment(new byte[1])),
new IpV6MobilityOptionMobileNodeIdentifier(IpV6MobileNodeIdentifierSubtype.NetworkAccessIdentifier, new DataSegment(new byte[2])));
Assert.IsFalse(
new IpV6MobilityOptionMobileNodeIdentifier(IpV6MobileNodeIdentifierSubtype.NetworkAccessIdentifier, new DataSegment(new byte[1])).Equals(
null as IpV6MobilityOptionMobileNodeIdentifier));
new IpV6MobilityOptionMobileNodeIdentifier(IpV6MobileNodeIdentifierSubtype.NetworkAccessIdentifier, new DataSegment(new byte[1])).Equals(null));
}
[TestMethod]
public void IpV6OptionsDataTooShortForReadingOptionDataLength()
{
Packet packet = PacketBuilder.Build(
DateTime.Now,
new EthernetLayer(),
new IpV6Layer
{
ExtensionHeaders =
new IpV6ExtensionHeaders(
new IpV6ExtensionHeaderDestinationOptions(
IpV4Protocol.Skip, new IpV6Options(new IpV6OptionPadN(3), new IpV6OptionPad1())))
});
Assert.IsTrue(packet.IsValid);
packet.Buffer[14 + 40 + 7] = (byte)IpV6OptionType.PadN;
Packet invalidPacket = new Packet(packet.Buffer, DateTime.Now, DataLinkKind.Ethernet);
Assert.IsFalse(invalidPacket.IsValid);
}
[TestMethod]
public void IpV6OptionsDataTooShortForOptionDataLength()
{
Packet packet = PacketBuilder.Build(
DateTime.Now,
new EthernetLayer(),
new IpV6Layer
{
ExtensionHeaders =
new IpV6ExtensionHeaders(
new IpV6ExtensionHeaderDestinationOptions(
IpV4Protocol.Skip, new IpV6Options(new IpV6OptionPadN(4))))
});
Assert.IsTrue(packet.IsValid);
packet.Buffer[14 + 40 + 3] = 50;
Packet invalidPacket = new Packet(packet.Buffer, DateTime.Now, DataLinkKind.Ethernet);
Assert.IsFalse(invalidPacket.IsValid);
}
[TestMethod]
public void IpV6OptionsEnumerableConstructor()
{
IpV6Options options = new IpV6Options(new IpV6Option[]{new IpV6OptionPad1()}.Concat(new IpV6OptionPad1()));
Assert.AreEqual(2, options.Count);
Assert.AreEqual(new IpV6OptionPad1(), options[0]);
Assert.AreEqual(new IpV6OptionPad1(), options[1]);
}
}
}
......@@ -23,18 +23,6 @@ namespace PcapDotNet.Packets.IpV6
/// </summary>
public IpV6MobilityOptionType OptionType { get; private set; }
internal abstract IpV6MobilityOption CreateInstance(DataSegment data);
protected IpV6MobilityOption(IpV6MobilityOptionType type)
{
OptionType = type;
}
internal override void Write(byte[] buffer, ref int offset)
{
buffer[offset++] = (byte)OptionType;
}
public override int Length
{
get { return sizeof(byte); }
......@@ -51,6 +39,20 @@ namespace PcapDotNet.Packets.IpV6
OptionType == other.OptionType && Length == other.Length && EqualsData(other);
}
public virtual bool IsValid { get { return true; } }
protected IpV6MobilityOption(IpV6MobilityOptionType type)
{
OptionType = type;
}
internal abstract IpV6MobilityOption CreateInstance(DataSegment data);
internal override void Write(byte[] buffer, ref int offset)
{
buffer[offset++] = (byte)OptionType;
}
internal abstract bool EqualsData(IpV6MobilityOption other);
}
}
\ No newline at end of file
......@@ -31,6 +31,11 @@ namespace PcapDotNet.Packets.IpV6
/// </summary>
public IpV6AccessNetworkIdentifierSubOptions SubOptions { get; private set; }
public override bool IsValid
{
get { return SubOptions.IsValid; }
}
internal override IpV6MobilityOption CreateInstance(DataSegment data)
{
return new IpV6MobilityOptionAccessNetworkIdentifier(new IpV6AccessNetworkIdentifierSubOptions(data));
......
......@@ -101,6 +101,9 @@ namespace PcapDotNet.Packets.IpV6
break;
}
if (!option.IsValid)
isValid = false;
options.Add(option);
}
......
......@@ -35,7 +35,9 @@ namespace PcapDotNet.Packets.IpV6
{
if (paddingSize == 0)
return this;
return new IpV6Options(OptionsCollection.Concat(paddingSize == 1 ? (IpV6Option)new IpV6OptionPad1() : new IpV6OptionPadN(paddingSize - 2)));
IEnumerable<IpV6Option> paddedOptions =
OptionsCollection.Concat(paddingSize == 1 ? (IpV6Option)new IpV6OptionPad1() : new IpV6OptionPadN(paddingSize - 2));
return new IpV6Options(new Tuple<IList<IpV6Option>, bool>(paddedOptions.ToList(), IsValid));
}
internal static Tuple<IList<IpV6Option>, bool> Read(DataSegment data)
......
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