Commit ea5c39de authored by Brickner_cp's avatar Brickner_cp

IPv6

parent f1adbe20
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
/// RFC 5570.
/// CALIPSO Domain of Interpretation (DOI)
/// </summary>
public enum IpV6CalipsoDomainOfInterpretation : uint
{
/// <summary>
/// RFC 5570.
/// Must not appear in any IPv6 packet on any network.
/// </summary>
Null = 0x0000,
}
}
\ No newline at end of file
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
/// RFC 2460.
/// </summary>
public abstract class IpV6ExtensionHeader
{
protected IpV6ExtensionHeader(IpV4Protocol nextHeader)
{
NextHeader = nextHeader;
}
public IpV4Protocol NextHeader { get; private set; }
}
}
\ No newline at end of file
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
/// RFC 2460.
/// +-----+-------------+-------------------------+
/// | Bit | 0-7 | 8-15 |
/// +-----+-------------+-------------------------+
/// | 0 | Next Header | Header Extension Length |
/// +-----+-------------+-------------------------+
/// | 16 | Options |
/// | ... | |
/// +-----+---------------------------------------+
/// </summary>
public class IpV6ExtensionHeaderHopByHopOptions : IpV6ExtensionHeader
{
private static class Offset
{
public const int NextHeader = 0;
public const int HeaderExtensionLength = 1;
public const int Options = 2;
}
public const int MinimumLength = 8;
private IpV6ExtensionHeaderHopByHopOptions(IpV4Protocol nextHeader, IpV6Options options)
: base(nextHeader)
{
Options = options;
}
public IpV6Options Options { get; private set; }
internal static IpV6ExtensionHeaderHopByHopOptions Parse(DataSegment data, out int numBytesRead)
{
numBytesRead = 0;
if (data.Length < MinimumLength)
return null;
IpV4Protocol nextHeader = (IpV4Protocol)data[Offset.NextHeader];
int length = (data[Offset.HeaderExtensionLength] + 1) * 8;
if (data.Length < length)
return null;
IpV6Options options = new IpV6Options(data.Subsegment(Offset.Options, length - Offset.Options));
numBytesRead = length;
return new IpV6ExtensionHeaderHopByHopOptions(nextHeader, options);
}
}
}
\ No newline at end of file
using PcapDotNet.Packets.Ip;
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
/// RFC 2460.
/// <pre>
/// +-----+-------------+-------------------------+
/// | Bit | 0-7 | 8-15 |
/// +-----+-------------+-------------------------+
/// | 0 | Option Type | Opt Data Len (optional) |
/// +-----+-------------+-------------------------+
/// | 16 | Option Data (optional) |
/// | ... | |
/// +-----+---------------------------------------+
/// </pre>
/// </summary>
public abstract class IpV6Option : Option
{
/// <summary>
/// The type of the IP option.
/// </summary>
public IpV6OptionType OptionType { get; private set; }
internal abstract IpV6Option CreateInstance(DataSegment data);
protected IpV6Option(IpV6OptionType type)
{
OptionType = type;
}
internal override void Write(byte[] buffer, ref int offset)
{
buffer[offset++] = (byte)OptionType;
}
public override int Length
{
get { return sizeof(byte); }
}
}
}
\ No newline at end of file
using System;
using System.Linq;
using PcapDotNet.Base;
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
/// RFC 5570.
/// <pre>
/// +-----+-------------+-----------------+
/// | Bit | 0-7 | 8-15 |
/// +-----+-------------+-----------------+
/// | 0 | Option Type | Opt Data Len |
/// +-----+-------------+-----------------+
/// | 16 | Domain of Interpretation |
/// | | |
/// +-----+-------------+-----------------+
/// | 48 | Cmpt Lengt | Sens Level |
/// +-----+-------------+-----------------+
/// | 64 | Checksum (CRC-16) |
/// +-----+-------------------------------+
/// | 80 | Compartment Bitmap (Optional) |
/// | ... | |
/// +-----+-------------------------------+
/// </pre>
/// </summary>
[IpV6OptionTypeRegistration(IpV6OptionType.Calipso)]
public class IpV6OptionCalipso : IpV6OptionComplex
{
private static class Offset
{
public const int DomainOfInterpretation = 0;
public const int CompartmentLength = DomainOfInterpretation + sizeof(uint);
public const int SensitivityLevel = CompartmentLength + sizeof(byte);
public const int Checksum = SensitivityLevel + sizeof(byte);
public const int CompartmentBitmap = Checksum + sizeof(ushort);
}
public const int OptionDataMinimumLength = Offset.CompartmentBitmap;
public IpV6OptionCalipso(IpV6CalipsoDomainOfInterpretation domainOfInterpretation, byte sensitivityLevel, ushort checksum, DataSegment compartmentBitmap)
: base(IpV6OptionType.Calipso)
{
if (compartmentBitmap.Length % sizeof(int) != 0)
throw new ArgumentException(string.Format("Compartment Bitmap length must divide by {0}.", sizeof(int)), "compartmentBitmap");
if (compartmentBitmap.Length / sizeof(int) > byte.MaxValue)
{
throw new ArgumentOutOfRangeException(string.Format("Compartment Bitmap length must not be bigger than {0}.", byte.MaxValue * sizeof(int)),
"compartmentBitmap");
}
DomainOfInterpretation = domainOfInterpretation;
SensitivityLevel = sensitivityLevel;
Checksum = checksum;
CompartmentBitmap = compartmentBitmap;
}
/// <summary>
/// The DOI identifies the rules under which this datagram must be handled and protected.
/// </summary>
public IpV6CalipsoDomainOfInterpretation DomainOfInterpretation { get; private set; }
/// <summary>
/// Specifies the size of the Compartment Bitmap field in 32-bit words.
/// The minimum value is zero, which is used only when the information in this packet is not in any compartment.
/// (In that situation, the CALIPSO Sensitivity Label has no need for a Compartment Bitmap).
/// </summary>
public byte CompartmentLength { get { return (byte)(CompartmentLengthInBytes / sizeof(int)); } }
/// <summary>
/// Specifies the size of the Compartment Bitmap field in bytes.
/// The minimum value is zero, which is used only when the information in this packet is not in any compartment.
/// (In that situation, the CALIPSO Sensitivity Label has no need for a Compartment Bitmap).
/// </summary>
public int CompartmentLengthInBytes
{
get { return CompartmentBitmap.Length; }
}
/// <summary>
/// Contains an opaque octet whose value indicates the relative sensitivity of the data contained in this datagram in the context of the indicated DOI.
/// The values of this field must be ordered, with 00000000 being the lowest Sensitivity Level and 11111111 being the highest Sensitivity Level.
/// However, in a typical deployment, not all 256 Sensitivity Levels will be in use.
/// So the set of valid Sensitivity Level values depends upon the CALIPSO DOI in use.
/// This sensitivity ordering rule is necessary so that Intermediate Systems (e.g., routers or MLS guards) will be able to apply MAC policy
/// with minimal per-packet computation and minimal configuration.
/// </summary>
public byte SensitivityLevel { get; private set; }
/// <summary>
/// Contains the a CRC-16 checksum as defined in RFC 1662.
/// The checksum is calculated over the entire CALIPSO option in this packet, including option header, zeroed-out checksum field, option contents,
/// and any required padding zero bits.
/// The checksum must always be computed on transmission and must always be verified on reception.
/// This checksum only provides protection against accidental corruption of the CALIPSO option in cases where neither the underlying medium
/// nor other mechanisms, such as the IP Authentication Header (AH), are available to protect the integrity of this option.
/// Note that the checksum field is always required, even when other integrity protection mechanisms (e.g., AH) are used.
/// </summary>
public ushort Checksum { get; private set; }
public bool IsChecksumCorrect
{
get
{
if (_isChecksumCorrect == null)
{
byte[] domainOfInterpretationBytes = new byte[sizeof(uint)];
domainOfInterpretationBytes.Write(0, (uint)DomainOfInterpretation, Endianity.Big);
ushort expectedValue =
PppFrameCheckSequenceCalculator.CalculateFcs16(
new byte[0].Concat((byte)OptionType, (byte)DataLength).Concat(domainOfInterpretationBytes)
.Concat<byte>(CompartmentLength, SensitivityLevel, 0, 0).Concat(CompartmentBitmap));
_isChecksumCorrect = (Checksum == expectedValue);
}
return _isChecksumCorrect.Value;
}
}
/// <summary>
/// Each bit represents one compartment within the DOI.
/// Each "1" bit within an octet in the Compartment Bitmap field represents a separate compartment under whose rules the data in this packet
/// must be protected.
/// Hence, each "0" bit indicates that the compartment corresponding with that bit is not applicable to the data in this packet.
/// The assignment of identity to individual bits within a Compartment Bitmap for a given DOI is left to the owner of that DOI.
/// This specification represents a Releasability on the wire as if it were an inverted Compartment.
/// So the Compartment Bitmap holds the sum of both logical Releasabilities and also logical Compartments for a given DOI value.
/// The encoding of the Releasabilities in this field is described elsewhere in this document.
/// The Releasability encoding is designed to permit the Compartment Bitmap evaluation to occur without the evaluator necessarily knowing
/// the human semantic associated with each bit in the Compartment Bitmap.
/// In turn, this facilitates the implementation and configuration of Mandatory Access Controls based on the Compartment Bitmap
/// within IPv6 routers or guard devices.
/// </summary>
public DataSegment CompartmentBitmap { get; private set; }
internal override int DataLength
{
get { return OptionDataMinimumLength + CompartmentLengthInBytes; }
}
internal override IpV6Option CreateInstance(DataSegment data)
{
if (data.Length < OptionDataMinimumLength)
return null;
IpV6CalipsoDomainOfInterpretation domainOfInterpretation = (IpV6CalipsoDomainOfInterpretation)data.ReadUInt(Offset.DomainOfInterpretation,
Endianity.Big);
byte compartmentLength = data[Offset.CompartmentLength];
int compartmentLengthInBytes = compartmentLength * sizeof(int);
if (OptionDataMinimumLength + compartmentLengthInBytes > data.Length)
return null;
byte sensitivityLevel = data[Offset.SensitivityLevel];
ushort checksum = data.ReadUShort(Offset.Checksum, Endianity.Big);
DataSegment compartmentBitmap = data.Subsegment(Offset.CompartmentBitmap, compartmentLengthInBytes);
return new IpV6OptionCalipso(domainOfInterpretation, sensitivityLevel, checksum, compartmentBitmap);
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(ref offset, (uint)DomainOfInterpretation, Endianity.Big);
buffer.Write(ref offset, CompartmentLength);
buffer.Write(ref offset, SensitivityLevel);
buffer.Write(ref offset, Checksum, Endianity.Big);
buffer.Write(ref offset, CompartmentBitmap);
}
private bool? _isChecksumCorrect;
}
}
\ No newline at end of file
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
/// RFC 2460.
/// <pre>
/// +-----+-------------+--------------+
/// | Bit | 0-7 | 8-15 |
/// +-----+-------------+--------------+
/// | 0 | Option Type | Opt Data Len |
/// +-----+-------------+--------------+
/// | 16 | Option Data |
/// | ... | |
/// +-----+----------------------------+
/// </pre>
/// </summary>
public abstract class IpV6OptionComplex : IpV6Option
{
protected IpV6OptionComplex(IpV6OptionType type)
: base(type)
{
}
public override sealed int Length
{
get { return base.Length + sizeof (byte) + DataLength; }
}
internal abstract int DataLength { get; }
internal override sealed void Write(byte[] buffer, ref int offset)
{
base.Write(buffer, ref offset);
buffer[offset++] = (byte)DataLength;
WriteData(buffer, ref offset);
}
internal abstract void WriteData(byte[] buffer, ref int offset);
}
}
\ No newline at end of file
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
/// Charles Lynn.
/// http://ana-3.lcs.mit.edu/~jnc/nimrod/eidoption.txt
/// Endpoint Identifier Option.
/// <pre>
/// +-----+-------------+--------------+
/// | Bit | 0-7 | 8-15 |
/// +-----+-------------+--------------+
/// | 0 | Option Type | Opt Data Len |
/// +-----+-------------+--------------+
/// | 16 | Src Len | Dst Len |
/// +-----+-------------+--------------+
/// | 32 | Source EID |
/// | ... | |
/// +-----+----------------------------+
/// | | Destination EID |
/// | ... | |
/// +-----+----------------------------+
/// </pre>
/// </summary>
[IpV6OptionTypeRegistration(IpV6OptionType.EndpointIdentification)]
public class IpV6OptionEndpointIdentification : IpV6OptionComplex
{
private static class Offset
{
public const int SourceEndpointIdentifierLength = 0;
public const int DestinationEndpointIdentifierLength = SourceEndpointIdentifierLength + sizeof(byte);
public const int SourceEndpointIdentifier = DestinationEndpointIdentifierLength + sizeof(byte);
}
public const int OptionDataMinimumLength = Offset.SourceEndpointIdentifier;
public IpV6OptionEndpointIdentification(DataSegment sourceEndpointIdentifier, DataSegment destinationEndpointIdentifier)
: base(IpV6OptionType.EndpointIdentification)
{
SourceEndpointIdentifier = sourceEndpointIdentifier;
DestinationEndpointIdentifier = destinationEndpointIdentifier;
}
public DataSegment SourceEndpointIdentifier { get; private set; }
public DataSegment DestinationEndpointIdentifier { get; private set; }
internal IpV6OptionEndpointIdentification()
: this(DataSegment.Empty, DataSegment.Empty)
{
}
internal override IpV6Option CreateInstance(DataSegment data)
{
if (data.Length < OptionDataMinimumLength)
return null;
int sourceEndpointIdentifierLength = data[Offset.SourceEndpointIdentifierLength];
int destinationEndpointIdentifierLength = data[Offset.DestinationEndpointIdentifierLength];
if (data.Length != OptionDataMinimumLength + sourceEndpointIdentifierLength + destinationEndpointIdentifierLength)
return null;
DataSegment sourceEndpointIdentifier = data.Subsegment(Offset.SourceEndpointIdentifier, sourceEndpointIdentifierLength);
int destinationEndpointIdentifierOffset = Offset.SourceEndpointIdentifier + sourceEndpointIdentifierLength;
DataSegment destinationEndpointIdentifier = data.Subsegment(destinationEndpointIdentifierOffset, destinationEndpointIdentifierLength);
return new IpV6OptionEndpointIdentification(sourceEndpointIdentifier, destinationEndpointIdentifier);
}
internal override int DataLength
{
get { return OptionDataMinimumLength + SourceEndpointIdentifier.Length + DestinationEndpointIdentifier.Length; }
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(ref offset, (byte)SourceEndpointIdentifier.Length);
buffer.Write(ref offset, (byte)DestinationEndpointIdentifier.Length);
buffer.Write(ref offset, SourceEndpointIdentifier);
buffer.Write(ref offset, DestinationEndpointIdentifier);
}
}
}
\ No newline at end of file
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
/// RFC 6275.
/// Home Address Option.
/// <pre>
/// +-----+-------------+--------------+
/// | Bit | 0-7 | 8-15 |
/// +-----+-------------+--------------+
/// | 0 | Option Type | Opt Data Len |
/// +-----+-------------+--------------+
/// | 16 | Home Address |
/// | | |
/// | | |
/// | | |
/// | | |
/// | | |
/// | | |
/// | | |
/// +-----+----------------------------+
/// </pre>
/// </summary>
[IpV6OptionTypeRegistration(IpV6OptionType.HomeAddress)]
public class IpV6OptionHomeAddress : IpV6OptionComplex
{
public const int OptionDataLength = IpV6Address.SizeOf;
public IpV6OptionHomeAddress(IpV6Address homeAddress)
: base(IpV6OptionType.HomeAddress)
{
HomeAddress = homeAddress;
}
/// <summary>
/// The home address of the mobile node sending the packet.
/// This address must be a unicast routable address.
/// </summary>
public IpV6Address HomeAddress { get; private set; }
internal IpV6OptionHomeAddress()
: this(IpV6Address.Zero)
{
}
internal override IpV6Option CreateInstance(DataSegment data)
{
if (data.Length != OptionDataLength)
return null;
IpV6Address homeAddress = data.ReadIpV6Address(0, Endianity.Big);
return new IpV6OptionHomeAddress(homeAddress);
}
internal override int DataLength
{
get { return OptionDataLength; }
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(ref offset, HomeAddress, Endianity.Big);
}
}
}
\ No newline at end of file
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
/// RFC irtf-rrg-ilnp-noncev6-06.
/// http://tools.ietf.org/html/draft-irtf-rrg-ilnp-noncev6-06
/// IPv6 Nonce Destination Option for ILNPv6.
/// <pre>
/// +-----+-------------+--------------+
/// | Bit | 0-7 | 8-15 |
/// +-----+-------------+--------------+
/// | 0 | Option Type | Opt Data Len |
/// +-----+-------------+--------------+
/// | 16 | Nonce Value |
/// | ... | |
/// +-----+----------------------------+
/// </pre>
/// </summary>
[IpV6OptionTypeRegistration(IpV6OptionType.IlnpNonce)]
public class IpV6OptionIlnpNonce : IpV6OptionComplex
{
public IpV6OptionIlnpNonce(DataSegment nonce)
: base(IpV6OptionType.IlnpNonce)
{
Nonce = nonce;
}
/// <summary>
/// An unpredictable cryptographically random value used to prevent off-path attacks on an ILNP session.
/// </summary>
public DataSegment Nonce { get; private set; }
internal IpV6OptionIlnpNonce()
: this(DataSegment.Empty)
{
}
internal override IpV6Option CreateInstance(DataSegment data)
{
return new IpV6OptionIlnpNonce(data);
}
internal override int DataLength
{
get { return Nonce.Length; }
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(ref offset, Nonce);
}
}
}
\ No newline at end of file
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
/// RFC 2675.
/// <pre>
/// +-----+-------------+--------+
/// | Bit | 0-7 | 8-15 |
/// +-----+-------------+--------+
/// | 0 | Option Type | 4 |
/// +-----+-------------+--------+
/// | 16 | Jumbo Payload Length |
/// | | |
/// +-----+----------------------+
/// </pre>
/// </summary>
[IpV6OptionTypeRegistration(IpV6OptionType.JumboPayload)]
public class IpV6OptionJumboPayload : IpV6OptionComplex
{
public const int OptionDataLength = sizeof(uint);
public IpV6OptionJumboPayload(uint jumboPayloadLength) : base(IpV6OptionType.JumboPayload)
{
JumboPayloadLength = jumboPayloadLength;
}
/// <summary>
/// Length of the IPv6 packet in octets, excluding the IPv6 header but including the Hop-by-Hop Options header and any other extension headers present.
/// Must be greater than 65,535.
/// </summary>
public uint JumboPayloadLength { get; private set; }
internal override IpV6Option CreateInstance(DataSegment data)
{
if (data.Length != OptionDataLength)
return null;
return new IpV6OptionJumboPayload(data.ReadUInt(0, Endianity.Big));
}
internal override int DataLength
{
get { return OptionDataLength; }
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(ref offset, JumboPayloadLength, Endianity.Big);
}
}
}
\ No newline at end of file
using System;
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
/// RFC ietf-6man-lineid-08.
/// http://tools.ietf.org/html/draft-ietf-6man-lineid-08
/// Line Identification Destination Option.
/// <pre>
/// +-----+---------------------+
/// | Bit | 0-7 |
/// +-----+---------------------+
/// | 0 | Option Type |
/// +-----+---------------------+
/// | 8 | Opt Data Len |
/// +-----+---------------------+
/// | 16 | LineIDLen |
/// +-----+---------------------+
/// | 24 | Line Identification |
/// | ... | |
/// +-----+---------------------+
/// </pre>
/// </summary>
[IpV6OptionTypeRegistration(IpV6OptionType.LineIdentification)]
public class IpV6OptionLineIdentificationDestination : IpV6OptionComplex
{
private static class Offset
{
public const int LineIdentificationLength = 0;
public const int LineIdentification = LineIdentificationLength + sizeof(byte);
}
public const int OptionDataMinimumLength = Offset.LineIdentification;
public IpV6OptionLineIdentificationDestination(DataSegment lineIdentification)
: base(IpV6OptionType.LineIdentification)
{
if (lineIdentification.Length > byte.MaxValue)
{
throw new ArgumentOutOfRangeException("lineIdentification", lineIdentification,
string.Format("Cannot be longer than {0} bytes.", byte.MaxValue));
}
LineIdentification = lineIdentification;
}
/// <summary>
/// Variable length data inserted by the AN describing the subscriber agent circuit identifier
/// corresponding to the logical access loop port of the AN from which the RS was initiated.
/// The line identification must be unique across all the ANs that share a link to the edge router.
/// </summary>
public DataSegment LineIdentification { get; private set; }
internal IpV6OptionLineIdentificationDestination()
: this(DataSegment.Empty)
{
}
internal override IpV6Option CreateInstance(DataSegment data)
{
if (data.Length < OptionDataMinimumLength)
return null;
int lineIdentificationLegnth = data[Offset.LineIdentificationLength];
if (data.Length != OptionDataMinimumLength + lineIdentificationLegnth)
return null;
DataSegment lineIdentification = data.Subsegment(Offset.LineIdentification, data.Length - Offset.LineIdentification);
return new IpV6OptionLineIdentificationDestination(lineIdentification);
}
internal override int DataLength
{
get { return OptionDataMinimumLength + LineIdentification.Length; }
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(ref offset, (byte)LineIdentification.Length);
buffer.Write(ref offset, LineIdentification);
}
}
}
\ No newline at end of file
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
/// +-----+-----+
/// | Bit | 0-7 |
/// +-----+-----+
/// | 0 | 0 |
/// +-----+-----+
/// </summary>
[IpV6OptionTypeRegistration(IpV6OptionType.Pad1)]
public class IpV6OptionPad1 : IpV6OptionSimple
{
public const int OptionLength = sizeof(byte);
public IpV6OptionPad1()
: base(IpV6OptionType.Pad1)
{
}
internal override IpV6Option CreateInstance(DataSegment data)
{
return new IpV6OptionPad1();
}
}
}
\ No newline at end of file
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
/// RFC 2460.
/// <pre>
/// +-----+-------------+--------------+
/// | Bit | 0-7 | 8-15 |
/// +-----+-------------+--------------+
/// | 0 | Option Type | N |
/// +-----+-------------+--------------+
/// | 16 | 0 |
/// | ... | |
/// +-----+----------------------------+
/// </pre>
/// </summary>
[IpV6OptionTypeRegistration(IpV6OptionType.PadN)]
public class IpV6OptionPadN : IpV6OptionComplex
{
public IpV6OptionPadN(int paddingDataLength) : base(IpV6OptionType.PadN)
{
PaddingDataLength = paddingDataLength;
}
public int PaddingDataLength { get; private set; }
internal override IpV6Option CreateInstance(DataSegment data)
{
return new IpV6OptionPadN(data.Length);
}
internal override int DataLength
{
get { return PaddingDataLength; }
}
internal override void WriteData(byte[] buffer, ref int offset)
{
offset += PaddingDataLength;
}
}
}
\ No newline at end of file
using PcapDotNet.Packets.Ip;
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
/// RFC 4782.
/// <pre>
/// +-----+-------------+------+----------+--------------+-------+-------+
/// | Bit | 0-7 | 8-15 | 16-19 | 20-23 | 24-29 | 30-31 |
/// +-----+-------------+------+----------+--------------+-------+-------+
/// | 0 | Option Type | 6 | Function | Rate Request | QS TTL |
/// +-----+-------------+------+----------+--------------+-------+-------+
/// | 32 | QS Nonce | R |
/// +-----+------------------------------------------------------+-------+
/// </pre>
/// </summary>
[IpV6OptionTypeRegistration(IpV6OptionType.QuickStart)]
public class IpV6OptionQuickStart : IpV6OptionComplex, IIpOptionQuickStart
{
public const int OptionDataLength = IpOptionQuickStartCommon.DataLength;
public IpV6OptionQuickStart(IpV4OptionQuickStartFunction function, byte rate, byte ttl, uint nonce)
: base(IpV6OptionType.QuickStart)
{
IpOptionQuickStartCommon.AssertValidParameters(function, rate, ttl, nonce);
Function = function;
Rate = rate;
Ttl = ttl;
Nonce = nonce;
}
public IpV4OptionQuickStartFunction Function { get; private set; }
public byte Rate { get; private set; }
public int RateKbps
{
get { return IpOptionQuickStartCommon.CalcRateKbps(Rate); }
}
public byte Ttl { get; private set; }
public uint Nonce { get; private set; }
internal override int DataLength
{
get { return OptionDataLength; }
}
internal override IpV6Option CreateInstance(DataSegment data)
{
if (data.Length != OptionDataLength)
return null;
IpV4OptionQuickStartFunction function;
byte rate;
byte ttl;
uint nonce;
IpOptionQuickStartCommon.ReadData(data, out function, out rate, out ttl, out nonce);
return new IpV6OptionQuickStart(function, rate, ttl, nonce);
}
internal override void WriteData(byte[] buffer, ref int offset)
{
IpOptionQuickStartCommon.WriteData(buffer, ref offset, Function, Rate, Ttl, Nonce);
}
}
}
\ No newline at end of file
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
/// RFC 2711.
/// <pre>
/// +-----+-------------+--------+
/// | Bit | 0-7 | 8-15 |
/// +-----+-------------+--------+
/// | 0 | Option Type | 2 |
/// +-----+-------------+--------+
/// | 16 | Router Alert Type |
/// +-----+----------------------+
/// </pre>
/// </summary>
[IpV6OptionTypeRegistration(IpV6OptionType.RouterAlert)]
public class IpV6OptionRouterAlert : IpV6OptionComplex
{
public const int OptionDataLength = sizeof(ushort);
public IpV6OptionRouterAlert(IpV6RouterAlertType routerAlertType)
: base(IpV6OptionType.RouterAlert)
{
RouterAlertType = routerAlertType;
}
/// <summary>
/// Type of router alert.
/// </summary>
public IpV6RouterAlertType RouterAlertType { get; private set; }
internal override IpV6Option CreateInstance(DataSegment data)
{
if (data.Length != OptionDataLength)
return null;
return new IpV6OptionRouterAlert((IpV6RouterAlertType)data.ReadUShort(0, Endianity.Big));
}
internal override int DataLength
{
get { return OptionDataLength; }
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(ref offset, (ushort)RouterAlertType, Endianity.Big);
}
}
}
\ No newline at end of file
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
/// RFC 6553.
/// Routing Protocol for Low-Power and Lossy Networks option.
/// <pre>
/// +-----+---+---+---+-----+---------------+
/// | Bit | 0 | 1 | 2 | 3-7 | 8-15 |
/// +-----+---+---+---+-----+---------------+
/// | 0 | Option Type | Opt Data Len |
/// +-----+---+---+---+-----+---------------+
/// | 16 | O | R | F | 0 | RPLInstanceID |
/// +-----+---+---+---+-----+---------------+
/// | 32 | SenderRank |
/// +-----+---------------------------------+
/// | 48 | (sub-TLVs) |
/// | ... | |
/// +-----+---------------------------------+
/// </pre>
/// </summary>
[IpV6OptionTypeRegistration(IpV6OptionType.RplOption)]
public class IpV6OptionRoutingProtocolLowPowerAndLossyNetworks : IpV6OptionComplex
{
private static class Offset
{
public const int Down = 0;
public const int RankError = Down;
public const int ForwardingError = RankError;
public const int RplInstanceId = ForwardingError + sizeof(byte);
public const int SenderRank = RplInstanceId + sizeof(byte);
public const int SubTlvs = SenderRank + sizeof(ushort);
}
private static class Mask
{
public const byte Down = 0x80;
public const byte RankError = 0x40;
public const byte ForwardingError = 0x20;
}
public const int OptionDataMinimumLength = Offset.SubTlvs;
public IpV6OptionRoutingProtocolLowPowerAndLossyNetworks(bool down, bool rankError, bool forwardingError, byte rplInstanceId, ushort senderRank,
DataSegment subTlvs)
: base(IpV6OptionType.EndpointIdentification)
{
Down = down;
RankError = rankError;
ForwardingError = forwardingError;
RplInstanceId = rplInstanceId;
SenderRank = senderRank;
SubTlvs = subTlvs;
}
/// <summary>
/// Indicating whether the packet is expected to progress Up or Down.
/// A router sets the Down flag when the packet is expected to progress Down (using DAO routes),
/// and clears it when forwarding toward the DODAG root (to a node with a lower Rank).
/// A host or RPL leaf node must set the Down flag to 0.
/// </summary>
public bool Down { get; private set; }
/// <summary>
/// Indicating whether a Rank error was detected.
/// A Rank error is detected when there is a mismatch in the relative Ranks and the direction as indicated in the Down flag.
/// A host or RPL leaf node must set the Rank Error flag to 0.
/// </summary>
public bool RankError { get; private set; }
/// <summary>
/// Indicating that this node cannot forward the packet further towards the destination.
/// The Forward Error flag might be set by a child node that does not have a route to destination for a packet with the Down flag set.
/// A host or RPL leaf node must set the Forwarding error flag to 0.
/// </summary>
public bool ForwardingError { get; private set; }
/// <summary>
/// Indicating the DODAG instance along which the packet is sent.
/// </summary>
public byte RplInstanceId { get; private set; }
/// <summary>
/// Set to zero by the source and to DAGRank(rank) by a router that forwards inside the RPL network.
/// </summary>
public ushort SenderRank{ get; private set; }
/// <summary>
/// A RPL device must skip over any unrecognized sub-TLVs and attempt to process any additional sub-TLVs that may appear after.
/// </summary>
public DataSegment SubTlvs { get; private set; }
internal IpV6OptionRoutingProtocolLowPowerAndLossyNetworks()
: this(false, false, false, 0, 0, DataSegment.Empty)
{
}
internal override IpV6Option CreateInstance(DataSegment data)
{
if (data.Length < OptionDataMinimumLength)
return null;
bool down = data.ReadBool(Offset.Down, Mask.Down);
bool rankError = data.ReadBool(Offset.RankError, Mask.RankError);
bool forwardingError = data.ReadBool(Offset.ForwardingError, Mask.ForwardingError);
byte rplInstanceId = data[Offset.RplInstanceId];
ushort senderRank = data.ReadUShort(Offset.SenderRank, Endianity.Big);
DataSegment subTlvs = data.Subsegment(Offset.SubTlvs, data.Length - Offset.SubTlvs);
return new IpV6OptionRoutingProtocolLowPowerAndLossyNetworks(down, rankError, forwardingError, rplInstanceId, senderRank, subTlvs);
}
internal override int DataLength
{
get { return OptionDataMinimumLength + SubTlvs.Length; }
}
internal override void WriteData(byte[] buffer, ref int offset)
{
byte flags = (byte)((Down ? Mask.Down : 0) | (RankError ? Mask.RankError : 0) | (ForwardingError ? Mask.ForwardingError : 0));
buffer.Write(ref offset, flags);
buffer.Write(ref offset, RplInstanceId);
buffer.Write(ref offset, SenderRank, Endianity.Big);
buffer.Write(ref offset, SubTlvs);
}
}
}
\ No newline at end of file
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
/// RFC 2460.
/// <pre>
/// +-----+-------------+
/// | Bit | 0-7 |
/// +-----+-------------+
/// | 0 | Option Type |
/// +-----+-------------+
/// </pre>
/// </summary>
public abstract class IpV6OptionSimple : IpV6Option
{
protected IpV6OptionSimple(IpV6OptionType type) : base(type)
{
}
public override sealed int Length
{
get { return base.Length; }
}
internal override sealed void Write(byte[] buffer, ref int offset)
{
base.Write(buffer, ref offset);
}
}
}
\ No newline at end of file
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
/// RFC 6621.
/// Simplified Multicast Forwarding Duplicate Packet Detection.
/// <pre>
/// +-----+---+------------------+
/// | Bit | 0 | 1-7 |
/// +-----+---+------------------+
/// | 0 | Option Type |
/// +-----+----------------------+
/// | 8 | Opt Data Len |
/// +-----+---+------------------+
/// | 16 | H | DPD Identifier |
/// +-----+---+ Option Fields |
/// | ... | or Hash Assist Value |
/// +-----+----------------------+
/// </pre>
/// </summary>
[IpV6OptionTypeRegistration(IpV6OptionType.SmfDpd)]
public abstract class IpV6OptionSmfDpd : IpV6OptionComplex
{
private static class Offset
{
public const int HashIndicator = 0;
}
private static class Mask
{
public const int HashIndicator = 0x80;
}
public const int OptionDataMinimumLength = Offset.HashIndicator + sizeof(byte);
protected IpV6OptionSmfDpd()
: base(IpV6OptionType.SmfDpd)
{
}
/// <summary>
/// Identifying DPD marking type.
/// 0 == sequence-based approach with optional TaggerId and a tuple-based sequence number. See <see cref="IpV6OptionSmfDpdSequenceBased"/>.
/// 1 == indicates a hash assist value (HAV) field follows to aid in avoiding hash-based DPD collisions.
/// </summary>
public abstract bool HashIndicator { get; }
internal override IpV6Option CreateInstance(DataSegment data)
{
if (data.Length < OptionDataMinimumLength)
return null;
bool hashIndicator = data.ReadBool(Offset.HashIndicator, Mask.HashIndicator);
if (hashIndicator)
return new IpV6OptionSmfDpdSequenceHashAssistValue(data);
return IpV6OptionSmfDpdSequenceBased.CreateSpecificInstance(data);
}
}
}
\ No newline at end of file
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
/// RFC 6621.
/// Simplified Multicast Forwarding Duplicate Packet Detection.
/// Sequence-based approach.
/// Default Tagger ID.
/// <pre>
/// +-----+---+-------+--------+
/// | Bit | 0 | 1-3 | 4-7 |
/// +-----+---+-------+--------+
/// | 0 | Option Type |
/// +-----+--------------------+
/// | 8 | Opt Data Len |
/// +-----+---+-------+--------+
/// | 16 | 0 | TidTy | TidLen |
/// +-----+---+-------+--------+
/// | 24 | TaggerId |
/// | ... | |
/// +-----+--------------------+
/// | | Identifier |
/// | ... | |
/// +-----+--------------------+
/// </pre>
/// </summary>
public class IpV6OptionSmfDpdDefault : IpV6OptionSmfDpdSequenceBased
{
public IpV6OptionSmfDpdDefault(DataSegment taggerId, DataSegment identifier)
: base(identifier)
{
TaggerId = taggerId;
}
public DataSegment TaggerId { get; private set; }
/// <summary>
/// The length of the Tagger Id.
/// </summary>
public override int TaggerIdLength
{
get { return TaggerId.Length; }
}
/// <summary>
/// Indicating the presence and type of the optional TaggerId field.
/// </summary>
public override IpV6TaggerIdType TaggerIdType
{
get { return IpV6TaggerIdType.Default; }
}
internal override void WriteTaggerId(byte[] buffer, ref int offset)
{
buffer.Write(ref offset, TaggerId);
}
}
}
\ No newline at end of file
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
/// RFC 6621.
/// Simplified Multicast Forwarding Duplicate Packet Detection.
/// Sequence-based approach.
/// IPv4 tagger ID.
/// <pre>
/// +-----+---+-------+--------+
/// | Bit | 0 | 1-3 | 4-7 |
/// +-----+---+-------+--------+
/// | 0 | Option Type |
/// +-----+--------------------+
/// | 8 | Opt Data Len |
/// +-----+---+-------+--------+
/// | 16 | 0 | TidTy | TidLen |
/// +-----+---+-------+--------+
/// | 24 | TaggerId |
/// | | |
/// | | |
/// | | |
/// +-----+--------------------+
/// | 56 | Identifier |
/// | ... | |
/// +-----+--------------------+
/// </pre>
/// </summary>
public class IpV6OptionSmfDpdIpV4 : IpV6OptionSmfDpdSequenceBased
{
public IpV6OptionSmfDpdIpV4(IpV4Address taggerId, DataSegment identifier)
:base(identifier)
{
TaggerId = taggerId;
}
public IpV4Address TaggerId { get; private set; }
/// <summary>
/// The length of the Tagger Id.
/// </summary>
public override int TaggerIdLength
{
get { return IpV4Address.SizeOf; }
}
/// <summary>
/// Indicating the presence and type of the optional TaggerId field.
/// </summary>
public override IpV6TaggerIdType TaggerIdType
{
get { return IpV6TaggerIdType.IpV4; }
}
internal override void WriteTaggerId(byte[] buffer, ref int offset)
{
buffer.Write(ref offset, TaggerId, Endianity.Big);
}
}
}
\ No newline at end of file
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
/// RFC 6621.
/// Simplified Multicast Forwarding Duplicate Packet Detection.
/// Sequence-based approach.
/// IPv6 tagger ID.
/// <pre>
/// +-----+---+-------+--------+
/// | Bit | 0 | 1-3 | 4-7 |
/// +-----+---+-------+--------+
/// | 0 | Option Type |
/// +-----+--------------------+
/// | 8 | Opt Data Len |
/// +-----+---+-------+--------+
/// | 16 | 0 | TidTy | TidLen |
/// +-----+---+-------+--------+
/// | 24 | TaggerId |
/// | | |
/// | | |
/// | | |
/// | | |
/// | | |
/// | | |
/// | | |
/// | | |
/// | | |
/// | | |
/// | | |
/// | | |
/// | | |
/// | | |
/// | | |
/// +-----+--------------------+
/// | 152 | Identifier |
/// | ... | |
/// +-----+--------------------+
/// </pre>
/// </summary>
public class IpV6OptionSmfDpdIpV6 : IpV6OptionSmfDpdSequenceBased
{
public IpV6OptionSmfDpdIpV6(IpV6Address taggerId, DataSegment identifier)
: base(identifier)
{
TaggerId = taggerId;
}
public IpV6Address TaggerId { get; private set; }
/// <summary>
/// The length of the Tagger Id.
/// </summary>
public override int TaggerIdLength
{
get { return IpV6Address.SizeOf; }
}
/// <summary>
/// Indicating the presence and type of the optional TaggerId field.
/// </summary>
public override IpV6TaggerIdType TaggerIdType
{
get { return IpV6TaggerIdType.IpV6; }
}
internal override void WriteTaggerId(byte[] buffer, ref int offset)
{
buffer.Write(ref offset, TaggerId, Endianity.Big);
}
}
}
\ No newline at end of file
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
/// RFC 6621.
/// Simplified Multicast Forwarding Duplicate Packet Detection.
/// Sequence-based approach.
/// Null Tagger ID.
/// <pre>
/// +-----+---+-------+--------+
/// | Bit | 0 | 1-3 | 4-7 |
/// +-----+---+-------+--------+
/// | 0 | Option Type |
/// +-----+--------------------+
/// | 8 | Opt Data Len |
/// +-----+---+-------+--------+
/// | 16 | 0 | TidTy | TidLen |
/// +-----+---+-------+--------+
/// | 24 | Identifier |
/// | ... | |
/// +-----+--------------------+
/// </pre>
/// </summary>
public class IpV6OptionSmfDpdNull : IpV6OptionSmfDpdSequenceBased
{
public IpV6OptionSmfDpdNull(DataSegment identifier)
: base(identifier)
{
}
/// <summary>
/// The length of the Tagger Id.
/// </summary>
public override int TaggerIdLength
{
get { return 0; }
}
/// <summary>
/// Indicating the presence and type of the optional TaggerId field.
/// </summary>
public override IpV6TaggerIdType TaggerIdType
{
get { return IpV6TaggerIdType.Null; }
}
internal override void WriteTaggerId(byte[] buffer, ref int offset)
{
}
}
}
\ No newline at end of file
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
/// RFC 6621.
/// Simplified Multicast Forwarding Duplicate Packet Detection.
/// Sequence-based approach.
/// <pre>
/// +-----+---+-------+--------+
/// | Bit | 0 | 1-3 | 4-7 |
/// +-----+---+-------+--------+
/// | 0 | Option Type |
/// +-----+--------------------+
/// | 8 | Opt Data Len |
/// +-----+---+-------+--------+
/// | 16 | 0 | TidTy | TidLen |
/// +-----+---+-------+--------+
/// | 24 | TaggerId |
/// | ... | |
/// +-----+--------------------+
/// | | Identifier |
/// | ... | |
/// +-----+--------------------+
/// </pre>
/// </summary>
public abstract class IpV6OptionSmfDpdSequenceBased : IpV6OptionSmfDpd
{
private static class Offset
{
public const int TaggerIdType = 0;
public const int TaggerIdLength = TaggerIdType;
public const int TaggerId = TaggerIdLength + sizeof(byte);
}
private static class Mask
{
public const byte TaggerIdType = 0x70;
public const byte TaggerIdLength = 0x0F;
}
private static class Shift
{
public const int TaggerIdType = 4;
}
/// <summary>
/// The length of the Tagger Id.
/// </summary>
public abstract int TaggerIdLength { get; }
/// <summary>
/// DPD packet Identifier.
/// When the TaggerId field is present, the Identifier can be considered a unique packet identifier
/// in the context of the TaggerId:srcAddr:dstAddr tuple.
/// When the TaggerId field is not present, then it is assumed that the source applied the SMF_DPD option
/// and the Identifier can be considered unique in the context of the IPv6 packet header srcAddr:dstAddr tuple.
/// </summary>
public DataSegment Identifier { get; private set; }
/// <summary>
/// Identifying DPD marking type.
/// 0 == sequence-based approach with optional TaggerId and a tuple-based sequence number. See <see cref="IpV6OptionSmfDpdSequenceBased"/>.
/// 1 == indicates a hash assist value (HAV) field follows to aid in avoiding hash-based DPD collisions.
/// </summary>
public override bool HashIndicator
{
get { return false; }
}
/// <summary>
/// Indicating the presence and type of the optional TaggerId field.
/// </summary>
public abstract IpV6TaggerIdType TaggerIdType { get; }
protected IpV6OptionSmfDpdSequenceBased(DataSegment identifier)
{
Identifier = identifier;
}
internal override int DataLength
{
get { return OptionDataMinimumLength + TaggerIdLength + Identifier.Length; }
}
internal override void WriteData(byte[] buffer, ref int offset)
{
byte taggerIdInfo = (byte)(((byte)TaggerIdType << Shift.TaggerIdType) & Mask.TaggerIdType);
if (TaggerIdType != IpV6TaggerIdType.Null)
taggerIdInfo |= (byte)((TaggerIdLength - 1) & Mask.TaggerIdLength);
buffer.Write(ref offset, taggerIdInfo);
WriteTaggerId(buffer, ref offset);
buffer.Write(ref offset, Identifier);
}
internal abstract void WriteTaggerId(byte[] buffer, ref int offset);
internal static IpV6OptionSmfDpdSequenceBased CreateSpecificInstance(DataSegment data)
{
IpV6TaggerIdType taggerIdType = (IpV6TaggerIdType)((data[Offset.TaggerIdType] & Mask.TaggerIdType) >> Shift.TaggerIdType);
int taggerIdLength = (taggerIdType == IpV6TaggerIdType.Null ? 0 : (data[Offset.TaggerIdLength] & Mask.TaggerIdLength) + 1);
if (data.Length < Offset.TaggerId + taggerIdLength)
return null;
DataSegment identifier = data.Subsegment(Offset.TaggerId + taggerIdLength, data.Length - Offset.TaggerId - taggerIdLength);
switch (taggerIdType)
{
case IpV6TaggerIdType.Null:
return new IpV6OptionSmfDpdNull(identifier);
case IpV6TaggerIdType.Default:
return new IpV6OptionSmfDpdDefault(data.Subsegment(Offset.TaggerId, taggerIdLength), identifier);
case IpV6TaggerIdType.IpV4:
if (taggerIdLength != IpV4Address.SizeOf)
return null;
IpV4Address ipV4Address = data.ReadIpV4Address(0, Endianity.Big);
return new IpV6OptionSmfDpdIpV4(ipV4Address, identifier);
case IpV6TaggerIdType.IpV6:
if (taggerIdLength != IpV6Address.SizeOf)
return null;
IpV6Address ipV6Address = data.ReadIpV6Address(0, Endianity.Big);
return new IpV6OptionSmfDpdIpV6(ipV6Address, identifier);
default:
return null;
}
}
}
}
\ No newline at end of file
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
/// RFC 6621.
/// Simplified Multicast Forwarding Duplicate Packet Detection.
/// Hash assist value.
/// <pre>
/// +-----+---+----------+
/// | Bit | 0 | 1-7 |
/// +-----+---+----------+
/// | 0 | Option Type |
/// +-----+--------------+
/// | 8 | Opt Data Len |
/// +-----+---+----------+
/// | 16 | 1 | Hash |
/// +-----+---+ Assist |
/// | ... | Value (HAV) |
/// +-----+--------------+
/// </pre>
/// </summary>
public class IpV6OptionSmfDpdSequenceHashAssistValue : IpV6OptionSmfDpd
{
private static class Offset
{
public const int HashAssistValue = 0;
}
public IpV6OptionSmfDpdSequenceHashAssistValue(DataSegment data)
{
byte[] hashAssistValueBuffer = new byte[data.Length - Offset.HashAssistValue];
data.Buffer.BlockCopy(data.StartOffset + Offset.HashAssistValue, hashAssistValueBuffer, 0, hashAssistValueBuffer.Length);
hashAssistValueBuffer[0] &= 0x7F;
HashAssistValue = new DataSegment(hashAssistValueBuffer);
}
/// <summary>
/// Hash assist value (HAV) used to facilitate H-DPD operation.
/// </summary>
public DataSegment HashAssistValue { get; private set; }
internal override int DataLength
{
get { return HashAssistValue.Length; }
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(ref offset, (byte)(HashAssistValue[0] | 0x80));
buffer.Write(ref offset, HashAssistValue.Subsegment(1, HashAssistValue.Length - 1));
}
public override bool HashIndicator
{
get { return true; }
}
}
}
\ No newline at end of file
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
/// RFC 2473.
/// <pre>
/// +-----+----------------------------+--------+
/// | Bit | 0-7 | 8-15 |
/// +-----+----------------------------+--------+
/// | 0 | Option Type | 1 |
/// +-----+----------------------------+--------+
/// | 16 | Tunnel Encapsulation Limit |
/// +-----+----------------------------+
/// </pre>
/// </summary>
[IpV6OptionTypeRegistration(IpV6OptionType.TunnelEncapsulationLimit)]
public class IpV6OptionTunnelEncapsulationLimit : IpV6OptionComplex
{
public const int OptionDataLength = sizeof(byte);
public IpV6OptionTunnelEncapsulationLimit(byte tunnelEncapsulationLimit)
: base(IpV6OptionType.JumboPayload)
{
TunnelEncapsulationLimit = tunnelEncapsulationLimit;
}
/// <summary>
/// How many further levels of encapsulation are permitted for the packet.
/// </summary>
public byte TunnelEncapsulationLimit { get; private set; }
internal override IpV6Option CreateInstance(DataSegment data)
{
if (data.Length != OptionDataLength)
return null;
return new IpV6OptionTunnelEncapsulationLimit(data[0]);
}
internal override int DataLength
{
get { return OptionDataLength; }
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(ref offset, TunnelEncapsulationLimit);
}
}
}
\ No newline at end of file
namespace PcapDotNet.Packets.IpV6
{
public enum IpV6OptionType : byte
{
/// <summary>
/// RFC 2460.
/// </summary>
Pad1 = 0x00,
/// <summary>
/// RFC 2460.
/// </summary>
PadN = 0x01,
/// <summary>
/// RFC 2675.
/// </summary>
JumboPayload = 0xC2,
/// <summary>
/// RFC 2473.
/// </summary>
TunnelEncapsulationLimit = 0x04,
/// <summary>
/// RFC 2711.
/// </summary>
RouterAlert = 0x05,
/// <summary>
/// RFC 4782, Errata 2034.
/// </summary>
QuickStart = 0x26,
/// <summary>
/// RFC 5570.
/// </summary>
Calipso = 0x07,
/// <summary>
/// RFC 6621.
/// </summary>
SmfDpd = 0x08,
/// <summary>
/// RFC 6275.
/// </summary>
HomeAddress = 0xC9,
/// <summary>
/// Charles Lynn.
/// </summary>
EndpointIdentification = 0x8A,
/// <summary>
/// RFC 6553.
/// </summary>
RplOption = 0x63,
/// <summary>
/// RFC irtf-rrg-ilnp-noncev6-06.
/// </summary>
IlnpNonce = 0x8B,
/// <summary>
/// RFC ietf-6man-lineid-08.
/// </summary>
LineIdentification = 0x8C,
}
}
\ No newline at end of file
using System;
namespace PcapDotNet.Packets.IpV6
{
internal sealed class IpV6OptionTypeRegistrationAttribute : Attribute
{
public IpV6OptionTypeRegistrationAttribute(IpV6OptionType optionType)
{
OptionType = optionType;
}
public IpV6OptionType OptionType { get; private set; }
}
}
\ No newline at end of file
using System;
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
/// RFC 2460.
/// <pre>
/// +-----+-------------+--------------+
/// | Bit | 0-7 | 8-15 |
/// +-----+-------------+--------------+
/// | 0 | Option Type | Opt Data Len |
/// +-----+-------------+--------------+
/// | 16 | Option Data |
/// | ... | |
/// +-----+----------------------------+
/// </pre>
/// </summary>
public class IpV6OptionUnknown : IpV6OptionComplex
{
public IpV6OptionUnknown(IpV6OptionType type, DataSegment data)
: base(type)
{
Data = data;
}
public DataSegment Data { get; private set; }
internal override IpV6Option CreateInstance(DataSegment data)
{
throw new InvalidOperationException("IpV6OptionUnknown shouldn't be registered.");
}
internal override int DataLength
{
get { return Data.Length; }
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(ref offset, Data);
}
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using PcapDotNet.Base;
using PcapDotNet.Packets.Ip;
namespace PcapDotNet.Packets.IpV6
{
public class IpV6Options : Options<IpV6Option>
{
public IpV6Options(DataSegment data) : this(Read(data))
{
}
private IpV6Options(Tuple<IList<IpV6Option>, bool> optionsAndIsValid) : base(optionsAndIsValid.Item1, optionsAndIsValid.Item2, null)
{
}
public static Tuple<IList<IpV6Option>, bool> Read(DataSegment data)
{
int offset = 0;
List<IpV6Option> options = new List<IpV6Option>();
bool isValid = true;
while (offset < data.Length)
{
IpV6OptionType optionType = (IpV6OptionType)data[offset++];
if (optionType == IpV6OptionType.Pad1)
{
options.Add(new IpV6OptionPad1());
continue;
}
if (offset >= data.Length)
{
isValid = false;
break;
}
byte optionDataLength = data[offset++];
if (offset + optionDataLength > data.Length)
{
isValid = false;
break;
}
IpV6Option option = CreateOption(optionType, data.Subsegment(ref offset, optionDataLength));
if (option == null)
{
isValid = false;
break;
}
options.Add(option);
}
return new Tuple<IList<IpV6Option>, bool>(options, isValid);
}
private static IpV6Option CreateOption(IpV6OptionType optionType, DataSegment data)
{
IpV6Option prototype;
if (!_prototypes.TryGetValue(optionType, out prototype))
return new IpV6OptionUnknown(optionType, data);
return prototype.CreateInstance(data);
}
private static readonly Dictionary<IpV6OptionType, IpV6Option> _prototypes = InitializePrototypes();
private static Dictionary<IpV6OptionType, IpV6Option> InitializePrototypes()
{
var prototypes =
from type in Assembly.GetExecutingAssembly().GetTypes()
where typeof(IpV6Option).IsAssignableFrom(type) &&
GetRegistrationAttribute(type) != null
select new
{
GetRegistrationAttribute(type).OptionType,
Option = (IpV6Option)Activator.CreateInstance(type)
};
return prototypes.ToDictionary(option => option.OptionType, option => option.Option);
}
private static IpV6OptionTypeRegistrationAttribute GetRegistrationAttribute(Type type)
{
var registraionAttributes = type.GetCustomAttributes<IpV6OptionTypeRegistrationAttribute>(false);
if (!registraionAttributes.Any())
return null;
return registraionAttributes.First();
}
}
}
\ No newline at end of file
This diff is collapsed.
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
/// The type of the Tagger ID for <see cref="IpV6OptionSmfDpdSequenceBased"/>
/// </summary>
public enum IpV6TaggerIdType : byte
{
/// <summary>
/// No TaggerId field is present.
/// </summary>
Null = 0,
/// <summary>
/// A TaggerId of non-specific context is present.
/// </summary>
Default = 1,
/// <summary>
/// A TaggerId representing an IPv4 address is present.
/// </summary>
IpV4 = 2,
/// <summary>
/// A TaggerId representing an IPv6 address is present.
/// </summary>
IpV6 = 3,
}
}
\ No newline at end of file
using System.Collections.Generic;
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
/// RFC 1662.
/// </summary>
public static class PppFrameCheckSequenceCalculator
{
private const ushort InitialValue = 0xffff;
/// <summary>
/// Calculate FCS16.
/// </summary>
public static ushort CalculateFcs16(IEnumerable<byte> values)
{
return CalculateFcs16(InitialValue, values);
}
public static ushort CalculateFcs16(ushort fcs, IEnumerable<byte> values)
{
foreach (byte value in values)
{
ushort tableValue = _fcsTable[(fcs ^ value) & 0xff];
fcs = (ushort)((fcs >> 8) ^ tableValue);
}
return fcs;
}
private static readonly ushort[] _fcsTable =
new ushort[]
{
0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
};
}
}
\ No newline at end of file
......@@ -316,6 +316,38 @@
<Compile Include="Igmp\IgmpRecordType.cs" />
<Compile Include="Igmp\IgmpMessageType.cs" />
<Compile Include="Igmp\IIgmpLayerWithGroupAddress.cs" />
<Compile Include="IpV6\IpV6CalipsoDomainOfInterpretation.cs" />
<Compile Include="IpV6\IpV6ExtensionHeader.cs" />
<Compile Include="IpV6\IpV6ExtensionHeaderHopByHopOptions.cs" />
<Compile Include="IpV6\IpV6Option.cs" />
<Compile Include="IpV6\IpV6OptionCalipso.cs" />
<Compile Include="IpV6\IpV6OptionComplex.cs" />
<Compile Include="IpV6\IpV6OptionEndpointIdentification.cs" />
<Compile Include="IpV6\IpV6OptionHomeAddress.cs" />
<Compile Include="IpV6\IpV6OptionIlnpNonce.cs" />
<Compile Include="IpV6\IpV6OptionJumboPayload.cs" />
<Compile Include="IpV6\IpV6OptionLineIdentificationDestination.cs" />
<Compile Include="IpV6\IpV6OptionPad1.cs" />
<Compile Include="IpV6\IpV6OptionPadN.cs" />
<Compile Include="IpV6\IpV6OptionQuickStart.cs" />
<Compile Include="IpV6\IpV6OptionRouterAlert.cs" />
<Compile Include="IpV6\IpV6OptionRoutingProtocolLowPowerAndLossyNetworks.cs" />
<Compile Include="IpV6\IpV6Options.cs" />
<Compile Include="IpV6\IpV6OptionSimple.cs" />
<Compile Include="IpV6\IpV6OptionSmfDpd.cs" />
<Compile Include="IpV6\IpV6OptionSmfDpdDefault.cs" />
<Compile Include="IpV6\IpV6OptionSmfDpdIpV4.cs" />
<Compile Include="IpV6\IpV6OptionSmfDpdIpV6.cs" />
<Compile Include="IpV6\IpV6OptionSmfDpdNull.cs" />
<Compile Include="IpV6\IpV6OptionSmfDpdSequenceBased.cs" />
<Compile Include="IpV6\IpV6OptionSmfDpdSequenceHashAssistValue.cs" />
<Compile Include="IpV6\IpV6OptionTunnelEncapsulationLimit.cs" />
<Compile Include="IpV6\IpV6OptionType.cs" />
<Compile Include="IpV6\IpV6OptionTypeRegistrationAttribute.cs" />
<Compile Include="IpV6\IpV6OptionUnknown.cs" />
<Compile Include="IpV6\IpV6RouterAlertType.cs" />
<Compile Include="IpV6\IpV6TaggerIdType.cs" />
<Compile Include="IpV6\PppFrameCheckSequenceCalculator.cs" />
<Compile Include="Ip\V4Option.cs" />
<Compile Include="Ip\IIpOptionQuickStart.cs" />
<Compile Include="IpV4\IpV4OptionTypeRegistrationAttribute.cs" />
......
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