Commit 34309d46 authored by Brickner_cp's avatar Brickner_cp

DNS

parent b2a71f17
......@@ -207,6 +207,9 @@ namespace PcapDotNet.Packets.TestUtils
new IpV6Address(addressSuffixValue),
random.NextDnsDomainName());
case DnsType.Sink:
return new DnsResourceDataSink(random.NextEnum<DnsSinkCoding>(), random.NextByte(), random.NextDataSegment(random.Next(100)));
default:
return new DnsResourceDataAnything(random.NextDataSegment(random.Next(100)));
}
......
......@@ -3030,7 +3030,7 @@ namespace PcapDotNet.Packets.Dns
public const int ConstantPartLength = Offset.Certificate;
public DnsResourceDataCertificate()
: this(DnsCertificateType.Pkix, 0, DnsAlgorithm.None, Datagram.Empty)
: this(DnsCertificateType.Pkix, 0, DnsAlgorithm.None, DataSegment.Empty)
{
}
......@@ -3228,4 +3228,451 @@ namespace PcapDotNet.Packets.Dns
return (MaxPrefixLength - prefixLength + 7) / 8;
}
}
/// <summary>
/// Eastlake.
/// </summary>
public enum DnsSinkCodingSubcoding : ushort
{
/// <summary>
/// The SNMP subset of ASN.1.
/// Basic Encoding Rules.
/// </summary>
Asn1SnmpBer = 0x0101,
/// <summary>
/// The SNMP subset of ASN.1.
/// Distinguished Encoding Rules.
/// </summary>
Asn1SnmpDer = 0x0102,
/// <summary>
/// The SNMP subset of ASN.1.
/// Packed Encoding Rules Aligned.
/// </summary>
Asn1SnmpPer = 0x0103,
/// <summary>
/// The SNMP subset of ASN.1.
/// Packed Encoding Rules Unaligned.
/// </summary>
Asn1SnmpPerUnaligned = 0x0104,
/// <summary>
/// The SNMP subset of ASN.1.
/// Canonical Encoding Rules.
/// </summary>
Asn1SnmpCer = 0x0105,
/// <summary>
/// The SNMP subset of ASN.1.
/// An OID preceded by a one byte unsigned length appears at the beginning of the data area to indicate which private encoding.
/// </summary>
Asn1SnmpPrivate = 0x01FE,
/// <summary>
/// OSI ASN.1 1990 [ASN.1].
/// Basic Encoding Rules.
/// </summary>
Asn1Osi1990Ber = 0x0201,
/// <summary>
/// OSI ASN.1 1990 [ASN.1].
/// Distinguished Encoding Rules.
/// </summary>
Asn1Osi1990Der = 0x0202,
/// <summary>
/// OSI ASN.1 1990 [ASN.1].
/// Packed Encoding Rules Aligned.
/// </summary>
Asn1Osi1990Per = 0x0203,
/// <summary>
/// OSI ASN.1 1990 [ASN.1].
/// Packed Encoding Rules Unaligned.
/// </summary>
Asn1Osi1990PerUnaligned = 0x0204,
/// <summary>
/// OSI ASN.1 1990 [ASN.1].
/// Canonical Encoding Rules.
/// </summary>
Asn1Osi1990Cer = 0x0205,
/// <summary>
/// OSI ASN.1 1990 [ASN.1].
/// An OID preceded by a one byte unsigned length appears at the beginning of the data area to indicate which private encoding.
/// </summary>
Asn1Osi1990Private = 0x02FE,
/// <summary>
/// OSI ASN.1 1994.
/// Basic Encoding Rules.
/// </summary>
Asn1Osi1994Ber = 0x0301,
/// <summary>
/// OSI ASN.1 1994.
/// Distinguished Encoding Rules.
/// </summary>
Asn1Osi1994Der = 0x0302,
/// <summary>
/// OSI ASN.1 1994.
/// Packed Encoding Rules Aligned.
/// </summary>
Asn1Osi1994Per = 0x0303,
/// <summary>
/// OSI ASN.1 1994.
/// Packed Encoding Rules Unaligned.
/// </summary>
Asn1Osi1994PerUnaligned = 0x0304,
/// <summary>
/// OSI ASN.1 1994.
/// Canonical Encoding Rules.
/// </summary>
Asn1Osi1994Cer = 0x0305,
/// <summary>
/// OSI ASN.1 1994.
/// An OID preceded by a one byte unsigned length appears at the beginning of the data area to indicate which private encoding.
/// </summary>
Asn1Osi1994Private = 0x03FE,
/// <summary>
/// Private abstract syntax notations.
/// This coding value will not be assigned to a standard abstract syntax notation.
/// An OSI Object Identifier (OID) preceded by a one byte unsigned length appears at the beginning of the data area to indicate which private abstract syntax is being used.
/// Basic Encoding Rules.
/// </summary>
AsnPrivateBer = 0x3F01,
/// <summary>
/// Private abstract syntax notations.
/// This coding value will not be assigned to a standard abstract syntax notation.
/// An OSI Object Identifier (OID) preceded by a one byte unsigned length appears at the beginning of the data area to indicate which private abstract syntax is being used.
/// Distinguished Encoding Rules.
/// </summary>
AsnPrivateDer = 0x3F02,
/// <summary>
/// Private abstract syntax notations.
/// This coding value will not be assigned to a standard abstract syntax notation.
/// An OSI Object Identifier (OID) preceded by a one byte unsigned length appears at the beginning of the data area to indicate which private abstract syntax is being used.
/// Packed Encoding Rules Aligned.
/// </summary>
AsnPrivatePer = 0x3F03,
/// <summary>
/// Private abstract syntax notations.
/// This coding value will not be assigned to a standard abstract syntax notation.
/// An OSI Object Identifier (OID) preceded by a one byte unsigned length appears at the beginning of the data area to indicate which private abstract syntax is being used.
/// Packed Encoding Rules Unaligned.
/// </summary>
AsnPrivatePerUnaligned = 0x3F04,
/// <summary>
/// Private abstract syntax notations.
/// This coding value will not be assigned to a standard abstract syntax notation.
/// An OSI Object Identifier (OID) preceded by a one byte unsigned length appears at the beginning of the data area to indicate which private abstract syntax is being used.
/// Canonical Encoding Rules.
/// </summary>
AsnPrivateCer = 0x3F05,
/// <summary>
/// Private abstract syntax notations.
/// This coding value will not be assigned to a standard abstract syntax notation.
/// An OSI Object Identifier (OID) preceded by a one byte unsigned length appears at the beginning of the data area to indicate which private abstract syntax is being used.
/// An OID preceded by a one byte unsigned length appears in the data area just after the coding OID.
/// </summary>
AsnPrivatePrivate = 0x3FFE,
/// <summary>
/// MIME structured data [RFC 2045, 2046].
/// The data portion is a MIME structured message.
/// The "MIME-Version:" header line may be omitted unless the version is other than "1.0".
/// Note that, to some extent, the size limitations of DNS RRs may be overcome in the MIME case by using the "Content-Type: message/external-body" mechanism.
/// 7 bit.
/// </summary>
Mime7Bit = 0x4101,
/// <summary>
/// MIME structured data [RFC 2045, 2046].
/// The data portion is a MIME structured message.
/// The "MIME-Version:" header line may be omitted unless the version is other than "1.0".
/// Note that, to some extent, the size limitations of DNS RRs may be overcome in the MIME case by using the "Content-Type: message/external-body" mechanism.
/// 8 bit.
/// </summary>
Mime8Bit = 0x4102,
/// <summary>
/// MIME structured data [RFC 2045, 2046].
/// The data portion is a MIME structured message.
/// The "MIME-Version:" header line may be omitted unless the version is other than "1.0".
/// Note that, to some extent, the size limitations of DNS RRs may be overcome in the MIME case by using the "Content-Type: message/external-body" mechanism.
/// Binary.
/// </summary>
MimeBinary = 0x4103,
/// <summary>
/// MIME structured data [RFC 2045, 2046].
/// The data portion is a MIME structured message.
/// The "MIME-Version:" header line may be omitted unless the version is other than "1.0".
/// Note that, to some extent, the size limitations of DNS RRs may be overcome in the MIME case by using the "Content-Type: message/external-body" mechanism.
/// Quoted-printable.
/// </summary>
MimeQuotedPrintable = 0x4104,
/// <summary>
/// MIME structured data [RFC 2045, 2046].
/// The data portion is a MIME structured message.
/// The "MIME-Version:" header line may be omitted unless the version is other than "1.0".
/// Note that, to some extent, the size limitations of DNS RRs may be overcome in the MIME case by using the "Content-Type: message/external-body" mechanism.
/// Base 64.
/// </summary>
MimeBase64 = 0x4105,
/// <summary>
/// MIME structured data [RFC 2045, 2046].
/// The data portion is a MIME structured message.
/// The "MIME-Version:" header line may be omitted unless the version is other than "1.0".
/// Note that, to some extent, the size limitations of DNS RRs may be overcome in the MIME case by using the "Content-Type: message/external-body" mechanism.
/// The data portion must start with an "x-" token denoting the private content-transfer-encoding immediately followed by one null (zero) octet
/// followed by the remainder of the MIME object.
/// </summary>
MimePrivate = 0x41FE,
/// <summary>
/// Text tagged data.
/// The data potion consists of text formated as specified in the TXT RR except that the first and every subsequent odd numbered text item
/// is considered to be a tag labeling the immediately following text item.
/// If there are an odd number of text items overall, then the last is considered to label a null text item.
/// Syntax of the tags is as specified in RFC 1738 for the "Common Internet Scheme Syntax" without the two leading slashes ("//").
/// Thus any organization with a domain name can assign tags without fear of conflict.
/// ASCII.
/// </summary>
TextTaggedDataAscii = 0x4201,
/// <summary>
/// Text tagged data.
/// The data potion consists of text formated as specified in the TXT RR except that the first and every subsequent odd numbered text item
/// is considered to be a tag labeling the immediately following text item.
/// If there are an odd number of text items overall, then the last is considered to label a null text item.
/// Syntax of the tags is as specified in RFC 1738 for the "Common Internet Scheme Syntax" without the two leading slashes ("//").
/// Thus any organization with a domain name can assign tags without fear of conflict.
/// UTF-7 [RFC 1642].
/// </summary>
TextTaggedDataUtf7 = 0x4202,
/// <summary>
/// Text tagged data.
/// The data potion consists of text formated as specified in the TXT RR except that the first and every subsequent odd numbered text item
/// is considered to be a tag labeling the immediately following text item.
/// If there are an odd number of text items overall, then the last is considered to label a null text item.
/// Syntax of the tags is as specified in RFC 1738 for the "Common Internet Scheme Syntax" without the two leading slashes ("//").
/// Thus any organization with a domain name can assign tags without fear of conflict.
/// UTF-8 [RFC 2044].
/// </summary>
TextTaggedDataUtf8 = 0x4203,
/// <summary>
/// Text tagged data.
/// The data potion consists of text formated as specified in the TXT RR except that the first and every subsequent odd numbered text item
/// is considered to be a tag labeling the immediately following text item.
/// If there are an odd number of text items overall, then the last is considered to label a null text item.
/// Syntax of the tags is as specified in RFC 1738 for the "Common Internet Scheme Syntax" without the two leading slashes ("//").
/// Thus any organization with a domain name can assign tags without fear of conflict.
/// ASCII with MIME header escapes [RFC 2047].
/// </summary>
TextTaggedDataAsciiMimeHeaderEscapes = 0x4204,
/// <summary>
/// Text tagged data.
/// The data potion consists of text formated as specified in the TXT RR except that the first and every subsequent odd numbered text item
/// is considered to be a tag labeling the immediately following text item.
/// If there are an odd number of text items overall, then the last is considered to label a null text item.
/// Syntax of the tags is as specified in RFC 1738 for the "Common Internet Scheme Syntax" without the two leading slashes ("//").
/// Thus any organization with a domain name can assign tags without fear of conflict.
/// Each text item must start with a domain name [RFC 1034] denoting the private text encoding immediately followed by one null (zero) octet
/// followed by the remainder of the text item.
/// </summary>
TextTaggedDataPrivate = 0x42FE,
}
/// <summary>
/// Eastlake.
/// </summary>
public enum DnsSinkCoding : byte
{
/// <summary>
/// The SNMP subset of ASN.1.
/// </summary>
Asn1Snmp = 0x01,
/// <summary>
/// OSI ASN.1 1990 [ASN.1].
/// </summary>
Asn1Osi1990 = 0x02,
/// <summary>
/// OSI ASN.1 1994.
/// </summary>
Asn1Osi1994 = 0x03,
/// <summary>
/// Private abstract syntax notations.
/// This coding value will not be assigned to a standard abstract syntax notation.
/// An OSI Object Identifier (OID) preceded by a one byte unsigned length appears at the beginning of the data area to indicate which private abstract syntax is being used.
/// </summary>
AsnPrivate = 0x3F,
/// <summary>
/// DNS RRs.
/// The data portion consists of DNS resource records as they would be transmitted in a DNS response section.
/// The subcoding octet is the number of RRs in the data area as an unsigned integer.
/// Domain names may be compressed via pointers as in DNS replies.
/// The origin for the pointers is the beginning of the RDATA section of the SINK RR.
/// Thus the SINK RR is safe to cache since only code that knows how to parse the data portion need know of and can expand these compressions.
/// </summary>
DnsResourceRecords = 0x40,
/// <summary>
/// MIME structured data [RFC 2045, 2046].
/// The data portion is a MIME structured message.
/// The "MIME-Version:" header line may be omitted unless the version is other than "1.0".
/// The top level Content-Transfer-Encoding may be encoded into the subcoding octet.
/// Note that, to some extent, the size limitations of DNS RRs may be overcome in the MIME case by using the "Content-Type: message/external-body" mechanism.
/// </summary>
Mime = 0x41,
/// <summary>
/// Text tagged data.
/// The data potion consists of text formated as specified in the TXT RR except that the first and every subsequent odd numbered text item
/// is considered to be a tag labeling the immediately following text item.
/// If there are an odd number of text items overall, then the last is considered to label a null text item.
/// Syntax of the tags is as specified in RFC 1738 for the "Common Internet Scheme Syntax" without the two leading slashes ("//").
/// Thus any organization with a domain name can assign tags without fear of conflict.
/// </summary>
TextTaggedData = 0x42,
/// <summary>
/// Private formats indicated by a URL.
/// The format of the data portion is indicated by an initial URL [RFC 1738] which is terminated by a zero valued octet
/// followed by the data with that format.
/// The subcoding octet is available for whatever use the private formating wishes to make of it.
/// The manner in which the URL specifies the format is not defined but presumably the retriever will recognize the URL or the data it points to.
/// </summary>
PrivateByUrl = 0xFE
}
/// <summary>
/// Eastlake.
/// <pre>
/// +-----+--------+-----------+
/// | bit | 0-7 | 8-15 |
/// +-----+--------+-----------+
/// | 0 | coding | subcoding |
/// +-----+--------+-----------+
/// | 16 | data |
/// | | |
/// +-----+--------------------+
/// </pre>
/// </summary>
[DnsTypeRegistration(Type = DnsType.Sink)]
public sealed class DnsResourceDataSink: DnsResourceDataSimple, IEquatable<DnsResourceDataSink>
{
private static class Offset
{
public const int Coding = 0;
public const int Subcoding = Coding + sizeof(byte);
public const int Data = Subcoding + sizeof(byte);
}
public const int ConstantPartLength = Offset.Data;
public DnsResourceDataSink()
: this(DnsSinkCodingSubcoding.Asn1SnmpBer, DataSegment.Empty)
{
}
public DnsResourceDataSink(DnsSinkCodingSubcoding codingSubcoding, DataSegment data)
: this((DnsSinkCoding)((ushort)codingSubcoding >> 8), (byte)((ushort)codingSubcoding & 0x00FF), data)
{
}
public DnsResourceDataSink(DnsSinkCoding coding, byte subcoding, DataSegment data)
{
Coding = coding;
Subcoding = subcoding;
Data = data;
}
/// <summary>
/// Gives the general structure of the data.
/// </summary>
public DnsSinkCoding Coding { get; private set; }
/// <summary>
/// Provides additional information depending on the value of the coding.
/// </summary>
public byte Subcoding { get; private set; }
/// <summary>
/// Returns a combination of coding and subcoding.
/// Has a valid enum value if the subcoding is defined specifically for the coding.
/// </summary>
public DnsSinkCodingSubcoding CodingSubcoding
{
get
{
ushort codingSubcoding = (ushort)(((ushort)Coding << 8) | Subcoding);
return (DnsSinkCodingSubcoding)codingSubcoding;
}
}
/// <summary>
/// Variable length and could be null in some cases.
/// </summary>
public DataSegment Data { get; private set; }
public bool Equals(DnsResourceDataSink other)
{
return other != null &&
Coding.Equals(other.Coding) &&
Subcoding.Equals(other.Subcoding) &&
Data.Equals(other.Data);
}
public override bool Equals(DnsResourceData other)
{
return Equals(other as DnsResourceDataSink);
}
internal override int GetLength()
{
return ConstantPartLength + Data.Length;
}
internal override void WriteDataSimple(byte[] buffer, int offset)
{
buffer.Write(offset + Offset.Coding, (byte)Coding);
buffer.Write(offset + Offset.Subcoding, Subcoding);
Data.Write(buffer, offset + Offset.Data);
}
internal override DnsResourceData CreateInstance(DataSegment data)
{
if (data.Length < ConstantPartLength)
return null;
DnsSinkCoding coding = (DnsSinkCoding)data[Offset.Coding];
byte subcoding = data[Offset.Subcoding];
DataSegment dataValue = data.SubSegment(Offset.Data, data.Length - ConstantPartLength);
return new DnsResourceDataSink(coding, subcoding, dataValue);
}
}
}
......@@ -285,6 +285,7 @@
/// <summary>
/// Eastlake.
/// SINK.
/// Payload type: DnsResourceDataSink.
/// </summary>
Sink = 40,
......
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