New edns options - example?

Jun 5, 2014 at 12:05 PM

Really pleased to see a new version released with the tcp issue fixed and new edns options.

Would it be possible to supply a brief example as per below of how to use the client subnet option? Doesn;t have to be functional code - Just enough to point me in the right direction.

I currently have the following
                If Not IsNothing(query.EDnsOptions) Then
                    If Not IsNothing(query.EDnsOptions.Options) Then
                        If query.EDnsOptions.Options.Count > 0 Then
                            ' RFC 5001 - NSDI
                            If query.EDnsOptions.Options.Item(0).Type = EDnsOptionType.NsId Then
                                Dim oEncoder As New System.Text.ASCIIEncoding
                                Dim data As Byte() = oEncoder.GetBytes(ServerID)
                                Dim a As New NsIdOption(data)
                            ElseIf query.EDnsOptions.Options.Item(0).Type = EDnsOptionType.ClientSubnet Then
__ _ // how to get and decode client subnet payload?___
                                GenericLogLine("unknown edns option type = " & query.EDnsOptions.Options.Item(0).Type, ErrorLog)
                            End If
                        End If
                        End If
                    End If

Jun 5, 2014 at 12:49 PM
I think I misunderstood in my example above. Has support only for encoding a client subnet and sending in the query been implemented? I think I just figured out how to do that. I'm interested in decoding the same from a querying server, i.e. when using the code as a server rather than a querying client. Is this possible?

Jun 6, 2014 at 9:53 AM

One more thing. I can see I can detect edns option 8 in my code, per the above example when servers are querying my server, but when I try to query it with dig locally using the new +subnet option, the library faults. I pasted the query and data below. This happens when issuing a query such as the dig request below

dig @ +subnet= +edns

dns.vshost.exe Error: 0 : System.Exception: Error parsing dns query ---> System.ArgumentException: Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.
at System.Buffer.BlockCopy(Array src, Int32 srcOffset, Array dst, Int32 dstOffset, Int32 count)
at ARSoft.Tools.Net.Dns.ClientSubnetOption.ParseData(Byte[] resultData, Int32 startPosition, Int32 length)
at ARSoft.Tools.Net.Dns.OptRecord.ParseRecordData(Byte[] resultData, Int32 startPosition, Int32 length)
at ARSoft.Tools.Net.Dns.DnsMessageBase.ParseRecord(Byte[] resultData, Int32& currentPosition)
at ARSoft.Tools.Net.Dns.DnsMessageBase.ParseSection(Byte[] resultData, Int32& currentPosition, List`1 sectionList, Int32 recordCount)
at ARSoft.Tools.Net.Dns.DnsMessageBase.ParseInternal(Byte[] data, SelectTsigKey tsigKeySelector, Byte[] originalMac)
at ARSoft.Tools.Net.Dns.DnsMessageBase.CreateByFlag(Byte[] data, SelectTsigKey tsigKeySelector, Byte[] originalMac)
at ARSoft.Tools.Net.Dns.DnsServer.EndUdpReceive(IAsyncResult ar)
--- End of inner exception stack trace ---
at ARSoft.Tools.Net.Dns.DnsServer.EndUdpReceive(IAsyncResult ar)
Jun 6, 2014 at 6:43 PM

the parsing error is fixed in Release 1.8.1.

Getting the payload is easy: Just cast the EDnsOptionBase item to the correspondig item:
(I hope C# is ok, my VB.Net ist not the best)
if (query.IsEDnsEnabled)
    foreach (EDnsOptionBase option in query.EDnsOptions.Options)
        switch (option.Type)
            case EDnsOptionType.NsId:
                NsIdOption nsIdOption = (NsIdOption) option;

                byte[] payload = nsIdOption.Payload;

                // do something with the payload


            case EDnsOptionType.ClientSubnet:
                ClientSubnetOption subnetOption = (ClientSubnetOption) option;

                IPAddress address = subnetOption.Address;
                byte scopeMask = subnetOption.ScopeNetmask;
                byte sourceMask = subnetOption.SourceNetmask;

                // do something with the payload


            case ...
Jun 9, 2014 at 9:12 AM
Fantastic - Thank you.