Setting payloadsize seems to impact printing qclass

93 views
Skip to first unread message

Craig Despeaux

unread,
Jun 29, 2015, 11:40:17 AM6/29/15
to dns...@googlegroups.com
Hi Alex,

I've run into a problem where Dnsruby returns "1" or "CLASS1" as the qclass for an RR when I am setting the payload size for the OPT record.  I've simplified one of my tests below using +bufsize=1 that clearly illustrates the problem for printing "CLASS1".  You can see in QUESTION section, as well as the ANSWER section that "IN" is not printing as the query class.  I've added some puts statements to show the message that is being sent, as well as the response being received.  This is causing some of my tests to fail when I attempt to verify the resource records returned.  There seems to be some sort of conflict with klass?  I am using Dnsruby version 1.58.0.  I am setting payload size as shown below:

      options_array = options.split()
      #
      #  If +bufsize is present, we need to do that first
      #
      bufsz = options_array.select { |entry| entry =~ /^\+bufsize=/ }
      unless bufsz.empty?
        bufsize = bufsz[0].split('=')[1].to_i
        optrr = RR::OPT.new(bufsize)
        options_array.delete(bufsz[0])
      end

      options_array.each do |option|
        case option
        when '+aa'
          msg.header.aa = true
        when '+ad'
          msg.header.ad = true
        ...
        ...
        ...
      end


[deploy@rec25-jump test]$ cucumber -p dev5-brn features/test.feature 
Running in dev-recursive5-brn environment
Using the dev5-brn profile...
Feature: Test

  Scenario: Test                                                           # features/test.feature:3
    Given the DNS nameserver is recproxy1                                  # features/step_definitions/dns_steps.rb:194

Message sent: #<Dnsruby::Message:0x007fa775dcd100 @header=#<Dnsruby::Header:0x007fa775dcd0b0 @id=8529, @qr=false, @opcode=Query, @aa=false, @ad=false, @tc=false, @rd=true, @ra=false, @cd=false, @rcode=NOERROR, @qdcount=1, @nscount=0, @ancount=0, @arcount=1>, @question=[#<Dnsruby::Question:0x007fa775dcc638 @qtype=ANY, @qclass=IN, @qname=#<Dnsruby::Name: net.>>], @answer=[], @authority=[], @additional=[#<Dnsruby::RR::OPT:0x007fa775dcc8b8 @type=OPT, @ttl=0, @options=nil, @klass=CLASS1>], @tsigstate=:Unsigned, @signing=false, @tsigkey=nil, @answerfrom=nil, @answerip=nil, @send_raw=true, @do_validation=true, @do_caching=false, @security_level=UNCHECKED, @security_error=nil, @cached=false>

Response received: #<Dnsruby::Message:0x007fa775db5118 @header=#<Dnsruby::Header:0x007fa775da7270 @id=8529, @qr=true, @opcode=Query, @aa=false, @ad=false, @tc=true, @rd=true, @ra=true, @cd=false, @rcode=NOERROR, @qdcount=1, @nscount=0, @ancount=5, @arcount=1>, @question=[#<Dnsruby::Question:0x007fa775d92af0 @qtype=ANY, @qclass=CLASS1, @qname=#<Dnsruby::Name: net.>>], @answer=[#<Dnsruby::RR::IN::NS:0x007fa775d750e0 @rdata=#<Dnsruby::Name: a.gtld-servers.net.>, @domainname=#<Dnsruby::Name: a.gtld-servers.net.>, @name=#<Dnsruby::Name: net.>, @ttl=172800, @type=NS, @klass=CLASS1>, #<Dnsruby::RR::IN::RRSIG:0x007fa775d710d0 @algorithm=RSASHA256, @type_covered=NS, @original_ttl=172800, @inception=1388577600, @expiration=2114424000, @key_tag=7884, @labels=1, @signers_name=#<Dnsruby::Name: net.>, @signature="\x127w\x10\xB0I:q;\xED\xCC\x902\x91\xEE\xE4DK\xA5q\xF7?E\xA9\x86\xB53}\x8AS\xCBO\xF3\xE0\xF0\x10\xFB!\xF2V\x1D\x84\xF6f\x9C\x84N1wJ\x1D\xF7\xC7}\x1C\xA5[;\xA5\xC15\x96\xEA\xBC:\xAE\x98H\xCD\xFCSX\xF6\x87\xFC\xC1\xA7@\xA5Ck\xC7\xFE\xEEJ\xAC\xC0\x83\xEC\t\x06\x17\xDC\xAE\xBBMSNk\x86&\x9E\xFC\xA4RIY\x87\xC9y.\xA8vv\xB7\xED\xE7\xC5C+*t\xB0\xA7'\x0F,\x19", @rdata=[2, 8, 1, 172800, 2114424000, 1388577600, 7884, #<Dnsruby::Name: net.>, "\x127w\x10\xB0I:q;\xED\xCC\x902\x91\xEE\xE4DK\xA5q\xF7?E\xA9\x86\xB53}\x8AS\xCBO\xF3\xE0\xF0\x10\xFB!\xF2V\x1D\x84\xF6f\x9C\x84N1wJ\x1D\xF7\xC7}\x1C\xA5[;\xA5\xC15\x96\xEA\xBC:\xAE\x98H\xCD\xFCSX\xF6\x87\xFC\xC1\xA7@\xA5Ck\xC7\xFE\xEEJ\xAC\xC0\x83\xEC\t\x06\x17\xDC\xAE\xBBMSNk\x86&\x9E\xFC\xA4RIY\x87\xC9y.\xA8vv\xB7\xED\xE7\xC5C+*t\xB0\xA7'\x0F,\x19"], @name=#<Dnsruby::Name: net.>, @ttl=172800, @type=RRSIG, @klass=CLASS1>, #<Dnsruby::RR::IN::SOA:0x007fa775d382f8 @rdata=[#<Dnsruby::Name: a.gtld-servers.net.>, #<Dnsruby::Name: nstld.verisign-grs.com.>, 1253813139, 1800, 900, 604800, 86400], @mname=#<Dnsruby::Name: a.gtld-servers.net.>, @rname=#<Dnsruby::Name: nstld.verisign-grs.com.>, @serial=1253813139, @refresh=1800, @retry=900, @expire=604800, @minimum=86400, @name=#<Dnsruby::Name: net.>, @ttl=900, @type=SOA, @klass=CLASS1>, #<Dnsruby::RR::IN::RRSIG:0x007fa775d2d538 @algorithm=RSASHA256, @type_covered=SOA, @original_ttl=900, @inception=1388577600, @expiration=2114424000, @key_tag=7884, @labels=1, @signers_name=#<Dnsruby::Name: net.>, @signature="\x02\xE1\x8F\x88\xFB\x00y\x04\xFFQ\xC8\xDE}\e\xFDm \xF4\x9C\xBF\x14\xD8$\x8B=\xAC\xDA\x10\xFD\x9CZ\x01\xE9|\xEF\t\x89>\x8D\r\f\x7F\xBC\xE8\xAC%c\xE2w\x16n\xE3\xFE\xC7GVun\xF3\x11\xB1\xE8au\x84/(-\xDA\xEFX\xDA\x18\xB3\xE77\x10\x94\xEA\xEE\x96\x96\x18\"FG\xD4nT\xB8;\xBD[\xB4\x15[\xE6\xC4\x85\xA0\xFB\x87]\xC6\"\x9D5\x81w\x80\xADS\x8A\xECc\xD4\xB3\x1F\x14\xDE\x9E#\x12OL\xC5J\xBA", @rdata=[6, 8, 1, 900, 2114424000, 1388577600, 7884, #<Dnsruby::Name: net.>, "\x02\xE1\x8F\x88\xFB\x00y\x04\xFFQ\xC8\xDE}\e\xFDm \xF4\x9C\xBF\x14\xD8$\x8B=\xAC\xDA\x10\xFD\x9CZ\x01\xE9|\xEF\t\x89>\x8D\r\f\x7F\xBC\xE8\xAC%c\xE2w\x16n\xE3\xFE\xC7GVun\xF3\x11\xB1\xE8au\x84/(-\xDA\xEFX\xDA\x18\xB3\xE77\x10\x94\xEA\xEE\x96\x96\x18\"FG\xD4nT\xB8;\xBD[\xB4\x15[\xE6\xC4\x85\xA0\xFB\x87]\xC6\"\x9D5\x81w\x80\xADS\x8A\xECc\xD4\xB3\x1F\x14\xDE\x9E#\x12OL\xC5J\xBA"], @name=#<Dnsruby::Name: net.>, @ttl=900, @type=RRSIG, @klass=CLASS1>, #<Dnsruby::RR::IN::NSEC:0x007fa775d28f38 @rdata=[#<Dnsruby::Name: a.gtld-servers.net.>, [NS, SOA, RRSIG, NSEC, DNSKEY]], @next_domain=#<Dnsruby::Name: a.gtld-servers.net.>, @types=[NS, SOA, RRSIG, NSEC, DNSKEY], @name=#<Dnsruby::Name: net.>, @ttl=86400, @type=NSEC, @klass=CLASS1>], @authority=[], @additional=[#<#<Class:0x007fa775d28290>:0x007fa775d28060 @type=OPT, @ttl=32768, @options=nil, @klass=CLASSCLASS4096, @name=#<Dnsruby::Name: .>>], @tsigstate=:Unsigned, @signing=false, @tsigkey=nil, @answerfrom="192.168.0.94", @answerip="192.168.0.94", @send_raw=false, @do_validation=true, @do_caching=true, @security_level=UNCHECKED, @security_error=nil, @cached=false, @answersize=486>
    When I query for qname "net" and qtype "any" with options "+bufsize=1" # features/step_definitions/dns_steps.rb:293
      
      ;; Answer received from 192.168.0.94 (486 bytes)
      ;;
      ;; Security Level : UNCHECKED
      ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 8529
      ;; flags: qr tc rd ra; QUERY: 1, ANSWER: 5, AUTHORITY: 0, ADDITIONAL: 1
      
      OPT pseudo-record : payloadsize 4096, xrcode 0, version 0, flags 32768
      
      
      ;; QUESTION SECTION (1  record)
      ;; net.   CLASS1  ANY
      
      ;; ANSWER SECTION (5  records)
      net.      172800  CLASS1  NS      a.gtld-servers.net.
      net.      172800  CLASS1  RRSIG   NS RSASHA256 1 172800 20370101120000 ( 20140101120000 7884 net. Ejd3ELBJOnE77cyQMpHu5ERLpXH3P0WphrUzfYpTy0/z4PAQ+yHyVh2E9machE4xd0od98d9HKVbO6XBNZbqvDqumEjN/FNY9of8wadApUNrx/7uSqzAg+wJBhfcrrtNU05rhiae/KRSSVmHyXkuqHZ2t+3nxUMrKnSwpycPLBk= )
      net.      900     CLASS1  SOA     a.gtld-servers.net. nstld.verisign-grs.com. 1253813139 1800 900 604800 86400
      net.      900     CLASS1  RRSIG   SOA RSASHA256 1 900 20370101120000 ( 20140101120000 7884 net. AuGPiPsAeQT/UcjefRv9bSD0nL8U2CSLPazaEP2cWgHpfO8JiT6NDQx/vOisJWPidxZu4/7HR1Z1bvMRsehhdYQvKC3a71jaGLPnNxCU6u6WlhgiRkfUblS4O71btBVb5sSFoPuHXcYinTWBd4CtU4rsY9SzHxTeniMST0zFSro= )
      net.      86400   CLASS1  NSEC    a.gtld-servers.net. ( NS SOA RRSIG NSEC DNSKEY )
    Then the rcode should be "NOERROR"                                     # features/step_definitions/dns_steps.rb:358

1 scenario (1 passed)
3 steps (3 passed)
0m0.606s

Thanks in advance for your help,
Craig

Alex Dalitz

unread,
Jun 30, 2015, 2:08:28 AM6/30/15
to Craig Despeaux, dns...@googlegroups.com
Hi - 

I’m sorry, I think I must be missing something.

Did you say you were setting the EDNS buffer size to 1? If so, do you think that this could be the cause of your problems?

Thanks,


Alex.

--
You received this message because you are subscribed to the Google Groups "dnsruby" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dnsruby+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dnsruby/b17a877e-2568-419a-99a9-09f0ef8a0df2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Craig Despeaux

unread,
Jun 30, 2015, 11:12:10 AM6/30/15
to dns...@googlegroups.com
Keep in mind that we use Dnsruby for testing and our DNS servers need to be ready to handle any DNS request, whether it's valid or not.  Just because I advertise the buffer size as 1 doesn't mean the DNS resolver is going to honor it, but it's a valid test case.  I'm guessing that if I run this test with tcpdump that the qclass in the returned RRSets will not be any different than if I specify +bufsize = 512, but I will verify that today.  I don't have to set +bufsize=1 to see the problem, but that was the easiest example to reproduce.  Currently, I have tests that fail after tests that tests that set +bufsize where the qclass is returned by Dnsruby as 1.   It's very odd.  It's almost as if some global variable is being set which causes later tests to produce the wrong qclass.  For instance, I can do two queries back to back, one with +bufsize=1, followed by one with +bufsize=512.  The qclass will still be printed as CLASS1 in the second response.  I can then reverse them.  The qclass is correct for +bufsize=512 but shows as CLASS1 for +bufsize=1.  I will get the tcpdump and will also see if I can reproduce this with a standalone script outside of Cucumber.  

Craig

Craig Despeaux

unread,
Jun 30, 2015, 12:06:12 PM6/30/15
to dns...@googlegroups.com
Check this out.  I don't even have to send the DNS query.  After the second msg is created, the third one shows @qclass=CLASS1 in the question section.  I did run my test with tcpdump and I didn't see any difference in the queries or the responses received.  How is the third Message object affected by something I did in the second one?

[cdespeau@goterps ~]$ gem list dnsruby

*** LOCAL GEMS ***

dnsruby (1.58.0, 1.55)
vrsn-ie-dnsruby (1.57.0.1, 1.54.517.5, 1.54.517.3, 1.54.517.2)

[cdespeau@goterps ~]$ cat test.rb
require 'dnsruby'
include Dnsruby

msg = Message.new('net', 'any', 'IN')
puts msg.inspect
msg = Message.new('net', 'any', 'IN')
optrr = RR::OPT.new(1)
msg.add_additional(optrr)
puts msg.inspect
msg = Message.new('net', 'any', 'IN')
puts msg.inspect

[cdespeau@goterps ~]$ ruby test.rb 
#<Dnsruby::Message:0x0000000205f648 @header=#<Dnsruby::Header:0x0000000205f5f8 @id=6043, @qr=false, @opcode=Query, @aa=false, @ad=false, @tc=false, @rd=false, @ra=false, @cd=false, @rcode=NOERROR, @qdcount=1, @nscount=0, @ancount=0, @arcount=0>, @question=[#<Dnsruby::Question:0x0000000205eec8 @qtype=ANY, @qclass=IN, @qname=#<Dnsruby::Name: net.>>], @answer=[], @authority=[], @additional=[], @tsigstate=:Unsigned, @signing=false, @tsigkey=nil, @answerfrom=nil, @answerip=nil, @send_raw=false, @do_validation=true, @do_caching=true, @security_level=UNCHECKED, @security_error=nil, @cached=false>
#<Dnsruby::Message:0x0000000205d618 @header=#<Dnsruby::Header:0x0000000205d5c8 @id=20843, @qr=false, @opcode=Query, @aa=false, @ad=false, @tc=false, @rd=false, @ra=false, @cd=false, @rcode=NOERROR, @qdcount=1, @nscount=0, @ancount=0, @arcount=1>, @question=[#<Dnsruby::Question:0x0000000205ce20 @qtype=ANY, @qclass=IN, @qname=#<Dnsruby::Name: net.>>], @answer=[], @authority=[], @additional=[#<Dnsruby::RR::OPT:0x0000000205cad8 @type=OPT, @ttl=0, @options=nil, @klass=CLASS1>], @tsigstate=:Unsigned, @signing=false, @tsigkey=nil, @answerfrom=nil, @answerip=nil, @send_raw=false, @do_validation=true, @do_caching=true, @security_level=UNCHECKED, @security_error=nil, @cached=false>
#<Dnsruby::Message:0x00000002052fd8 @header=#<Dnsruby::Header:0x00000002052f88 @id=998, @qr=false, @opcode=Query, @aa=false, @ad=false, @tc=false, @rd=false, @ra=false, @cd=false, @rcode=NOERROR, @qdcount=1, @nscount=0, @ancount=0, @arcount=0>, @question=[#<Dnsruby::Question:0x00000002052790 @qtype=ANY, @qclass=CLASS1, @qname=#<Dnsruby::Name: net.>>], @answer=[], @authority=[], @additional=[], @tsigstate=:Unsigned, @signing=false, @tsigkey=nil, @answerfrom=nil, @answerip=nil, @send_raw=false, @do_validation=true, @do_caching=true, @security_level=UNCHECKED, @security_error=nil, @cached=false>


On Monday, June 29, 2015 at 11:40:17 AM UTC-4, Craig Despeaux wrote:

Keith Bennett

unread,
Jun 30, 2015, 2:13:24 PM6/30/15
to Craig Despeaux, dns...@googlegroups.com
Craig -

I suggest that you create one or more Minitest test functions to illustrate these issues.

You wouldn't need to create a new test file, you could put it in an appropriate existing one.

This would be helpful in a few ways:

* Express the issue very simply without any proprietary context so that it will be much easier for others to understand
* Easily reproducible; no need for proprietary test code or Cucumber
* Long lived as a regression test after fix, if it's a bug that needs fixing
* The process of distilling the issue to its simpler form often results in better understanding, and may even indicate that the error is somewhere else
* a precise piece of information would be tested rather than having the reader comb through output

- Keith


--
You received this message because you are subscribed to the Google Groups "dnsruby" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dnsruby+u...@googlegroups.com.

Alex Dalitz

unread,
Jul 1, 2015, 2:09:19 AM7/1/15
to Craig Despeaux, dns...@googlegroups.com
Hi Craig - 

Thanks very much for this, it’s extremely useful.

I agree that this is surprising behaviour.

It’s not actually incorrect behaviour - all the responses given by dnsruby are perfectly correct. They are just surprising, as I would have expected "CLASS1" to be displayed as “IN” - as your test code presumably does.

Again, I should point out that “CLASS1” is in fact “IN” (under RFC3597 rules), so there is nothing actually wrong with the response - it is just surprising.

Also, the way in which you have provoked the error is very interesting.

I will have a look at these today - however, the UK is having its hottest day for a decade today, so I may spend some time swimming in rivers…

Thanks!


Alex.

-- 
You received this message because you are subscribed to the Google Groups "dnsruby" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dnsruby+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dnsruby/2bc890f2-8864-4d45-a4f2-09a7b776e6fd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alex Dalitz

unread,
Jul 1, 2015, 2:27:02 AM7/1/15
to Craig Despeaux, dns...@googlegroups.com
Hi - 

This is now fixed, in commit afef012.

Thanks for the report!


Alex.


For more options, visit https://groups.google.com/d/optout.

Craig Despeaux

unread,
Jul 1, 2015, 9:14:42 AM7/1/15
to dns...@googlegroups.com
Alex,

Thanks for the speedy turnaround.  I will test this out today.  Hopefully, it also resolves the problem where qclass shows up as "1".  That one is a little tougher to reproduce as easily as "CLASS1" but some combination of my tests makes it occur in our nightly builds.  I'll let you know what happens.

Enjoy your swim in the river -- sounds like fun!

Craig 


On Monday, June 29, 2015 at 11:40:17 AM UTC-4, Craig Despeaux wrote:

Craig Despeaux

unread,
Jul 2, 2015, 2:22:57 PM7/2/15
to dns...@googlegroups.com
Do you see anywhere else in the code where qclass could go astray?  Your commit corrects the problem with +bufsize=1 causing qclass to show up as "CLASS1", but I am still having problems with qclass showing up as "1".  I can't put my finger on what query is causing this.  I have a Cucumber test that runs queries through a DNS proxy that corrupts packets.  The munger runs on the localhost and forwards to my DNS server so I point the Dnsruby resolver at localhost, port 5300.  The munger selects a random byte in the packet and copies it to another location in the packet and then forwards the packet to my DNS server.  At some point during that test, all message objects created show @qclass=1 in the question section.  This causes two tests that follow this test to fail because they evaluate the question section.  The subsequent tests create a brand new resolver pointing directly at my DNS server under test.  I am at a loss.  I am currently circumventing this problem by hard-coding "IN" in the actual question for compare so it matches my expected question, but I don't really feel like I should have to do that.  Help?

Craig


On Monday, June 29, 2015 at 11:40:17 AM UTC-4, Craig Despeaux wrote:

Alex Dalitz

unread,
Jul 2, 2015, 4:18:49 PM7/2/15
to Craig Despeaux, dns...@googlegroups.com
Try commit afef012..fe88b05 ?

Thanks,


Alex.

--
You received this message because you are subscribed to the Google Groups "dnsruby" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dnsruby+u...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Craig Despeaux

unread,
Jul 6, 2015, 9:17:20 AM7/6/15
to dns...@googlegroups.com
Alex,

I manually applied both of those changes and unfortunately there was no change in the behaviour.


Craig

On Monday, June 29, 2015 at 11:40:17 AM UTC-4, Craig Despeaux wrote:

Craig Despeaux

unread,
Jul 6, 2015, 12:20:50 PM7/6/15
to dns...@googlegroups.com
I'm sorry to report that applying those commits made no difference either.  I added some debug code to my function that creates the Message object as follows:

 def create_msg(qname, qtype, options)

    msg = Message.new(qname, qtype, @qclass)
    STDOUT.puts msg.inspect
    STDOUT.puts "overriding qclass to #{@qclass}"
    msg.question[0].qclass = @qclass
    STDOUT.puts msg.inspect

It's actually quite interesting that once the first message is created with qclass set to 1 even my attempt to override it back to "IN" fails, as you can see in the printed output below:

#<Dnsruby::Message:0x007f4c23cdb088 @header=#<Dnsruby::Header:0x007f4c23cdb010 @id=18370, @qr=false, @opcode=Query, @aa=false, @ad=false, @tc=false, @rd=false, @ra=false, @cd=false, @rcode=NOERROR, @qdcount=1, @nscount=0, @ancount=0, @arcount=0>, @question=[#<Dnsruby::Question:0x007f4c23cd9918 @qtype=AAAA, @qclass=IN, @qname=#<Dnsruby::Name: google.com.>>], @answer=[], @authority=[], @additional=[], @tsigstate=:Unsigned, @signing=false, @tsigkey=nil, @answerfrom=nil, @answerip=nil, @send_raw=false, @do_validation=true, @do_caching=true, @security_level=UNCHECKED, @security_error=nil, @cached=false>
overriding qclass to IN
#<Dnsruby::Message:0x007f4c23cdb088 @header=#<Dnsruby::Header:0x007f4c23cdb010 @id=18370, @qr=false, @opcode=Query, @aa=false, @ad=false, @tc=false, @rd=false, @ra=false, @cd=false, @rcode=NOERROR, @qdcount=1, @nscount=0, @ancount=0, @arcount=0>, @question=[#<Dnsruby::Question:0x007f4c23cd9918 @qtype=AAAA, @qclass=IN, @qname=#<Dnsruby::Name: google.com.>>], @answer=[], @authority=[], @additional=[], @tsigstate=:Unsigned, @signing=false, @tsigkey=nil, @answerfrom=nil, @answerip=nil, @send_raw=false, @do_validation=true, @do_caching=true, @security_level=UNCHECKED, @security_error=nil, @cached=false>
#<Dnsruby::Message:0x007f4c23c4fd58 @header=#<Dnsruby::Header:0x007f4c23c4fce0 @id=64255, @qr=false, @opcode=Query, @aa=false, @ad=false, @tc=false, @rd=false, @ra=false, @cd=false, @rcode=NOERROR, @qdcount=1, @nscount=0, @ancount=0, @arcount=0>, @question=[#<Dnsruby::Question:0x007f4c23c4dd28 @qtype=AAAA, @qclass=1, @qname=#<Dnsruby::Name: google.com.>>], @answer=[], @authority=[], @additional=[], @tsigstate=:Unsigned, @signing=false, @tsigkey=nil, @answerfrom=nil, @answerip=nil, @send_raw=false, @do_validation=true, @do_caching=true, @security_level=UNCHECKED, @security_error=nil, @cached=false>
overriding qclass to IN
#<Dnsruby::Message:0x007f4c23c4fd58 @header=#<Dnsruby::Header:0x007f4c23c4fce0 @id=64255, @qr=false, @opcode=Query, @aa=false, @ad=false, @tc=false, @rd=false, @ra=false, @cd=false, @rcode=NOERROR, @qdcount=1, @nscount=0, @ancount=0, @arcount=0>, @question=[#<Dnsruby::Question:0x007f4c23c4dd28 @qtype=AAAA, @qclass=1, @qname=#<Dnsruby::Name: google.com.>>], @answer=[], @authority=[], @additional=[], @tsigstate=:Unsigned, @signing=false, @tsigkey=nil, @answerfrom=nil, @answerip=nil, @send_raw=false, @do_validation=true, @do_caching=true, @security_level=UNCHECKED, @security_error=nil, @cached=false>


Craig




On Monday, June 29, 2015 at 11:40:17 AM UTC-4, Craig Despeaux wrote:

Craig Despeaux

unread,
Jul 6, 2015, 1:58:31 PM7/6/15
to dns...@googlegroups.com
Hi Alex,

This might help you figure it out.  I added the following puts statements at the top of the initialize function in code_mapper.rb:

     def initialize(arg) #:nodoc: all
      if self.class == Dnsruby::Classes
        STDOUT.puts "arg: #{arg}"
        STDOUT.puts @@arrays[self.class].inspect
      end

The output below shows what is printed at the time that qclass seems to go bad.  You'll notice that in the @values hash, the value of 1 has changed from "IN" to "1".  I hope this helps you pinpoint the problem.


#<Dnsruby::Message:0x007faa10461e98 @header=#<Dnsruby::Header:0x007faa10461da8 @id=40207, @qr=false, @opcode=Query, @aa=false, @ad=false, @tc=false, @rd=false, @ra=false, @cd=false, @rcode=NOERROR, @qdcount=1, @nscount=0, @ancount=0, @arcount=0>, @question=[#<Dnsruby::Question:0x007faa1045b4a8 @qtype=A, @qclass=IN, @qname=#<Dnsruby::Name: google.com.>>], @answer=[], @authority=[], @additional=[], @tsigstate=:Unsigned, @signing=false, @tsigkey=nil, @answerfrom=nil, @answerip=nil, @send_raw=false, @do_validation=true, @do_caching=true, @security_level=UNCHECKED, @security_error=nil, @cached=false>
overriding qclass to IN
arg: IN
#<Dnsruby::CodeMapper::Arrays:0x007faa104a6fc0 @strings={"IN"=>1, "CH"=>3, "HS"=>4, "NONE"=>254, "ANY"=>255, "CLASS512"=>512, "0"=>0, "CLASS4096"=>4096, "7"=>7, "CLASS56321"=>56321, "CLASS164"=>164}, @stringsdown={"in"=>1, "ch"=>3, "hs"=>4, "none"=>254, "any"=>255, "class512"=>512, "0"=>0, "class4096"=>4096, "7"=>7, "class56321"=>56321, "class164"=>164}, @values={1=>"IN", 3=>"CH", 4=>"HS", 254=>"NONE", 255=>"ANY", 512=>"CLASS512", 0=>"0", 4096=>"CLASS4096", 7=>"7", 56321=>"CLASS56321", 164=>"CLASS164"}, @maxcode=197>
#<Dnsruby::Message:0x007faa10461e98 @header=#<Dnsruby::Header:0x007faa10461da8 @id=40207, @qr=false, @opcode=Query, @aa=false, @ad=false, @tc=false, @rd=false, @ra=false, @cd=false, @rcode=NOERROR, @qdcount=1, @nscount=0, @ancount=0, @arcount=0>, @question=[#<Dnsruby::Question:0x007faa1045b4a8 @qtype=A, @qclass=IN, @qname=#<Dnsruby::Name: google.com.>>], @answer=[], @authority=[], @additional=[], @tsigstate=:Unsigned, @signing=false, @tsigkey=nil, @answerfrom=nil, @answerip=nil, @send_raw=false, @do_validation=true, @do_caching=true, @security_level=UNCHECKED, @security_error=nil, @cached=false>
arg: 512
#<Dnsruby::CodeMapper::Arrays:0x007faa104a6fc0 @strings={"IN"=>1, "CH"=>3, "HS"=>4, "NONE"=>254, "ANY"=>255, "CLASS512"=>512, "0"=>0, "CLASS4096"=>4096, "7"=>7, "CLASS56321"=>56321, "CLASS164"=>164}, @stringsdown={"in"=>1, "ch"=>3, "hs"=>4, "none"=>254, "any"=>255, "class512"=>512, "0"=>0, "class4096"=>4096, "7"=>7, "class56321"=>56321, "class164"=>164}, @values={1=>"IN", 3=>"CH", 4=>"HS", 254=>"NONE", 255=>"ANY", 512=>"CLASS512", 0=>"0", 4096=>"CLASS4096", 7=>"7", 56321=>"CLASS56321", 164=>"CLASS164"}, @maxcode=197>
arg: CLASS512
#<Dnsruby::CodeMapper::Arrays:0x007faa104a6fc0 @strings={"IN"=>1, "CH"=>3, "HS"=>4, "NONE"=>254, "ANY"=>255, "CLASS512"=>512, "0"=>0, "CLASS4096"=>4096, "7"=>7, "CLASS56321"=>56321, "CLASS164"=>164}, @stringsdown={"in"=>1, "ch"=>3, "hs"=>4, "none"=>254, "any"=>255, "class512"=>512, "0"=>0, "class4096"=>4096, "7"=>7, "class56321"=>56321, "class164"=>164}, @values={1=>"IN", 3=>"CH", 4=>"HS", 254=>"NONE", 255=>"ANY", 512=>"CLASS512", 0=>"0", 4096=>"CLASS4096", 7=>"7", 56321=>"CLASS56321", 164=>"CLASS164"}, @maxcode=197>
arg: 1
#<Dnsruby::CodeMapper::Arrays:0x007faa104a6fc0 @strings={"IN"=>1, "CH"=>3, "HS"=>4, "NONE"=>254, "ANY"=>255, "CLASS512"=>512, "0"=>0, "CLASS4096"=>4096, "7"=>7, "CLASS56321"=>56321, "CLASS164"=>164}, @stringsdown={"in"=>1, "ch"=>3, "hs"=>4, "none"=>254, "any"=>255, "class512"=>512, "0"=>0, "class4096"=>4096, "7"=>7, "class56321"=>56321, "class164"=>164}, @values={1=>"IN", 3=>"CH", 4=>"HS", 254=>"NONE", 255=>"ANY", 512=>"CLASS512", 0=>"0", 4096=>"CLASS4096", 7=>"7", 56321=>"CLASS56321", 164=>"CLASS164"}, @maxcode=198>
arg: IN
#<Dnsruby::CodeMapper::Arrays:0x007faa104a6fc0 @strings={"IN"=>1, "CH"=>3, "HS"=>4, "NONE"=>254, "ANY"=>255, "CLASS512"=>512, "0"=>0, "CLASS4096"=>4096, "7"=>7, "CLASS56321"=>56321, "CLASS164"=>164}, @stringsdown={"in"=>1, "ch"=>3, "hs"=>4, "none"=>254, "any"=>255, "class512"=>512, "0"=>0, "class4096"=>4096, "7"=>7, "class56321"=>56321, "class164"=>164}, @values={1=>"IN", 3=>"CH", 4=>"HS", 254=>"NONE", 255=>"ANY", 512=>"CLASS512", 0=>"0", 4096=>"CLASS4096", 7=>"7", 56321=>"CLASS56321", 164=>"CLASS164"}, @maxcode=198>
arg: 4096
#<Dnsruby::CodeMapper::Arrays:0x007faa104a6fc0 @strings={"IN"=>1, "CH"=>3, "HS"=>4, "NONE"=>254, "ANY"=>255, "CLASS512"=>512, "0"=>0, "CLASS4096"=>4096, "7"=>7, "CLASS56321"=>56321, "CLASS164"=>164}, @stringsdown={"in"=>1, "ch"=>3, "hs"=>4, "none"=>254, "any"=>255, "class512"=>512, "0"=>0, "class4096"=>4096, "7"=>7, "class56321"=>56321, "class164"=>164}, @values={1=>"IN", 3=>"CH", 4=>"HS", 254=>"NONE", 255=>"ANY", 512=>"CLASS512", 0=>"0", 4096=>"CLASS4096", 7=>"7", 56321=>"CLASS56321", 164=>"CLASS164"}, @maxcode=198>
arg: 0
#<Dnsruby::CodeMapper::Arrays:0x007faa104a6fc0 @strings={"IN"=>1, "CH"=>3, "HS"=>4, "NONE"=>254, "ANY"=>255, "CLASS512"=>512, "0"=>0, "CLASS4096"=>4096, "7"=>7, "CLASS56321"=>56321, "CLASS164"=>164}, @stringsdown={"in"=>1, "ch"=>3, "hs"=>4, "none"=>254, "any"=>255, "class512"=>512, "0"=>0, "class4096"=>4096, "7"=>7, "class56321"=>56321, "class164"=>164}, @values={1=>"IN", 3=>"CH", 4=>"HS", 254=>"NONE", 255=>"ANY", 512=>"CLASS512", 0=>"0", 4096=>"CLASS4096", 7=>"7", 56321=>"CLASS56321", 164=>"CLASS164"}, @maxcode=198>
arg: IN
#<Dnsruby::CodeMapper::Arrays:0x007faa104a6fc0 @strings={"IN"=>1, "CH"=>3, "HS"=>4, "NONE"=>254, "ANY"=>255, "CLASS512"=>512, "0"=>0, "CLASS4096"=>4096, "7"=>7, "CLASS56321"=>56321, "CLASS164"=>164, "1"=>1}, @stringsdown={"in"=>1, "ch"=>3, "hs"=>4, "none"=>254, "any"=>255, "class512"=>512, "0"=>0, "class4096"=>4096, "7"=>7, "class56321"=>56321, "class164"=>164, "1"=>1}, @values={1=>"1", 3=>"CH", 4=>"HS", 254=>"NONE", 255=>"ANY", 512=>"CLASS512", 0=>"0", 4096=>"CLASS4096", 7=>"7", 56321=>"CLASS56321", 164=>"CLASS164"}, @maxcode=213>
arg: 1
#<Dnsruby::CodeMapper::Arrays:0x007faa104a6fc0 @strings={"IN"=>1, "CH"=>3, "HS"=>4, "NONE"=>254, "ANY"=>255, "CLASS512"=>512, "0"=>0, "CLASS4096"=>4096, "7"=>7, "CLASS56321"=>56321, "CLASS164"=>164, "1"=>1}, @stringsdown={"in"=>1, "ch"=>3, "hs"=>4, "none"=>254, "any"=>255, "class512"=>512, "0"=>0, "class4096"=>4096, "7"=>7, "class56321"=>56321, "class164"=>164, "1"=>1}, @values={1=>"1", 3=>"CH", 4=>"HS", 254=>"NONE", 255=>"ANY", 512=>"CLASS512", 0=>"0", 4096=>"CLASS4096", 7=>"7", 56321=>"CLASS56321", 164=>"CLASS164"}, @maxcode=213>
#<Dnsruby::Message:0x007faa104172d0 @header=#<Dnsruby::Header:0x007faa10417168 @id=62426, @qr=false, @opcode=Query, @aa=false, @ad=false, @tc=false, @rd=false, @ra=false, @cd=false, @rcode=NOERROR, @qdcount=1, @nscount=0, @ancount=0, @arcount=0>, @question=[#<Dnsruby::Question:0x007faa10415098 @qtype=A, @qclass=1, @qname=#<Dnsruby::Name: google.com.>>], @answer=[], @authority=[], @additional=[], @tsigstate=:Unsigned, @signing=false, @tsigkey=nil, @answerfrom=nil, @answerip=nil, @send_raw=false, @do_validation=true, @do_caching=true, @security_level=UNCHECKED, @security_error=nil, @cached=false>
overriding qclass to IN
arg: IN
#<Dnsruby::CodeMapper::Arrays:0x007faa104a6fc0 @strings={"IN"=>1, "CH"=>3, "HS"=>4, "NONE"=>254, "ANY"=>255, "CLASS512"=>512, "0"=>0, "CLASS4096"=>4096, "7"=>7, "CLASS56321"=>56321, "CLASS164"=>164, "1"=>1}, @stringsdown={"in"=>1, "ch"=>3, "hs"=>4, "none"=>254, "any"=>255, "class512"=>512, "0"=>0, "class4096"=>4096, "7"=>7, "class56321"=>56321, "class164"=>164, "1"=>1}, @values={1=>"1", 3=>"CH", 4=>"HS", 254=>"NONE", 255=>"ANY", 512=>"CLASS512", 0=>"0", 4096=>"CLASS4096", 7=>"7", 56321=>"CLASS56321", 164=>"CLASS164"}, @maxcode=213>
#<Dnsruby::Message:0x007faa104172d0 @header=#<Dnsruby::Header:0x007faa10417168 @id=62426, @qr=false, @opcode=Query, @aa=false, @ad=false, @tc=false, @rd=false, @ra=false, @cd=false, @rcode=NOERROR, @qdcount=1, @nscount=0, @ancount=0, @arcount=0>, @question=[#<Dnsruby::Question:0x007faa10415098 @qtype=A, @qclass=1, @qname=#<Dnsruby::Name: google.com.>>], @answer=[], @authority=[], @additional=[], @tsigstate=:Unsigned, @signing=false, @tsigkey=nil, @answerfrom=nil, @answerip=nil, @send_raw=false, @do_validation=true, @do_caching=true, @security_level=UNCHECKED, @security_error=nil, @cached=false>

Thanks,

Craig



On Monday, June 29, 2015 at 11:40:17 AM UTC-4, Craig Despeaux wrote:

Alex Dalitz

unread,
Jul 7, 2015, 1:38:02 AM7/7/15
to Craig Despeaux, dns...@googlegroups.com
Hi Craig - 

Yes, I think it is fairly clear that the CodeMapper is having the 1->IN mapping overridden to be 1->1.

The question is : why is this happening?

I currently have no idea what the code you are running is doing. It would be immensely helpful to me if you could somehow narrow the bug down to a specific test-case, which demonstrates the failure.

I’ve had a look at all the places where I can imagine this bug might occur, but none of them seem to help. Without further details, I’m not really sure where to look.

Is it possible for you to keep a tab on the class of your messages, and simply stop at the first point at which you notice they are incorrect? Once I have an idea of how you are stimulating this failure, it should be pretty easy to fix…

Thanks!


Alex.

-- 
You received this message because you are subscribed to the Google Groups "dnsruby" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dnsruby+u...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Craig Despeaux

unread,
Jul 7, 2015, 10:26:36 AM7/7/15
to dns...@googlegroups.com
Okay, maybe this will help.  Through my own debugging, I know that Classes.new('IN') returns the wrong value after I pop a response off the queue.  I added debugging to my test code to print Classes.new('IN') three times:

  STDOUT.puts "before send"
  STDOUT.puts Classes.new('IN')
  @dns_server.send_async(msg, queue)
  STDOUT.puts "after send"
  STDOUT.puts Classes.new('IN')
  id, @dns_response, error = queue.pop
  STDOUT.puts "after pop"
  STDOUT.puts Classes.new('IN')

I know based on that it was corrupted "after pop".  I then altered the add_pair function in code.mapper.rb as follows to produce a stack trace when the value goes bad:

 #  Add new a code to the CodeMapper
    def CodeMapper.add_pair(string, code)
      array = @@arrays[self]
      STDOUT.puts array.inspect
      array.strings.store(string, code)
      array.values=array.strings.invert
      array.stringsdown.store(string.downcase, code)
      array.maxcode+=1
      STDOUT.puts array.inspect
      begin
        takeacrap if array.values[1] == "1"
      rescue Exception => e
        STDOUT.puts e.backtrace
      end
    end

And here is the output produced from that:

#<Dnsruby::CodeMapper::Arrays:0x007fa87bfaae80 @strings={"IN"=>1, "CH"=>3, "HS"=>4, "NONE"=>254, "ANY"=>255, "CLASS512"=>512, "0"=>0, "CLASS4096"=>4096, "CLASS28519"=>28519, "CLASS27904"=>27904, "CLASS65535"=>65535, "CLASS3072"=>3072, "CLASS257"=>257}, @stringsdown={"in"=>1, "ch"=>3, "hs"=>4, "none"=>254, "any"=>255, "class512"=>512, "0"=>0, "class4096"=>4096, "class28519"=>28519, "class27904"=>27904, "class65535"=>65535, "class3072"=>3072, "class257"=>257}, @values={1=>"IN", 3=>"CH", 4=>"HS", 254=>"NONE", 255=>"ANY", 512=>"CLASS512", 0=>"0", 4096=>"CLASS4096", 28519=>"CLASS28519", 27904=>"CLASS27904", 65535=>"CLASS65535", 3072=>"CLASS3072", 257=>"CLASS257"}, @maxcode=1894>
#<Dnsruby::CodeMapper::Arrays:0x007fa87bfaae80 @strings={"IN"=>1, "CH"=>3, "HS"=>4, "NONE"=>254, "ANY"=>255, "CLASS512"=>512, "0"=>0, "CLASS4096"=>4096, "CLASS28519"=>28519, "CLASS27904"=>27904, "CLASS65535"=>65535, "CLASS3072"=>3072, "CLASS257"=>257, "1"=>1}, @stringsdown={"in"=>1, "ch"=>3, "hs"=>4, "none"=>254, "any"=>255, "class512"=>512, "0"=>0, "class4096"=>4096, "class28519"=>28519, "class27904"=>27904, "class65535"=>65535, "class3072"=>3072, "class257"=>257, "1"=>1}, @values={1=>"1", 3=>"CH", 4=>"HS", 254=>"NONE", 255=>"ANY", 512=>"CLASS512", 0=>"0", 4096=>"CLASS4096", 28519=>"CLASS28519", 27904=>"CLASS27904", 65535=>"CLASS65535", 3072=>"CLASS3072", 257=>"CLASS257"}, @maxcode=1895>
/home/deploy/GIT/recursive-dns/test/vendor/bundle/ruby/2.1.0/gems/vrsn-ie-dnsruby-1.58.0/lib/vrsn-ie-dnsruby/code_mappers.rb:59:in `unknown_string'
/home/deploy/GIT/recursive-dns/test/vendor/bundle/ruby/2.1.0/gems/vrsn-ie-dnsruby-1.58.0/lib/vrsn-ie-dnsruby/code_mapper.rb:115:in `initialize'
/home/deploy/GIT/recursive-dns/test/vendor/bundle/ruby/2.1.0/gems/vrsn-ie-dnsruby-1.58.0/lib/vrsn-ie-dnsruby/code_mapper.rb:99:in `new'
/home/deploy/GIT/recursive-dns/test/vendor/bundle/ruby/2.1.0/gems/vrsn-ie-dnsruby-1.58.0/lib/vrsn-ie-dnsruby/code_mapper.rb:99:in `method_missing'
/home/deploy/GIT/recursive-dns/test/vendor/bundle/ruby/2.1.0/gems/vrsn-ie-dnsruby-1.58.0/lib/vrsn-ie-dnsruby/code_mapper.rb:80:in `add_pair'
/home/deploy/GIT/recursive-dns/test/vendor/bundle/ruby/2.1.0/gems/vrsn-ie-dnsruby-1.58.0/lib/vrsn-ie-dnsruby/code_mapper.rb:93:in `unknown_code'
/home/deploy/GIT/recursive-dns/test/vendor/bundle/ruby/2.1.0/gems/vrsn-ie-dnsruby-1.58.0/lib/vrsn-ie-dnsruby/code_mapper.rb:122:in `initialize'
/home/deploy/GIT/recursive-dns/test/vendor/bundle/ruby/2.1.0/gems/vrsn-ie-dnsruby-1.58.0/lib/vrsn-ie-dnsruby/resource/OPT.rb:100:in `new'
/home/deploy/GIT/recursive-dns/test/vendor/bundle/ruby/2.1.0/gems/vrsn-ie-dnsruby-1.58.0/lib/vrsn-ie-dnsruby/resource/OPT.rb:100:in `xrcode'
/home/deploy/GIT/recursive-dns/test/vendor/bundle/ruby/2.1.0/gems/vrsn-ie-dnsruby-1.58.0/lib/vrsn-ie-dnsruby/message/message.rb:405:in `rcode'
/home/deploy/GIT/recursive-dns/test/vendor/bundle/ruby/2.1.0/gems/vrsn-ie-dnsruby-1.58.0/lib/vrsn-ie-dnsruby/message/message.rb:195:in `get_exception'
/home/deploy/GIT/recursive-dns/test/vendor/bundle/ruby/2.1.0/gems/vrsn-ie-dnsruby-1.58.0/lib/vrsn-ie-dnsruby/select_thread.rb:349:in `block in send_response_to_client'
/home/deploy/GIT/recursive-dns/test/vendor/bundle/ruby/2.1.0/gems/vrsn-ie-dnsruby-1.58.0/lib/vrsn-ie-dnsruby/select_thread.rb:330:in `each'
/home/deploy/GIT/recursive-dns/test/vendor/bundle/ruby/2.1.0/gems/vrsn-ie-dnsruby-1.58.0/lib/vrsn-ie-dnsruby/select_thread.rb:330:in `send_response_to_client'
/home/deploy/GIT/recursive-dns/test/vendor/bundle/ruby/2.1.0/gems/vrsn-ie-dnsruby-1.58.0/lib/vrsn-ie-dnsruby/select_thread.rb:318:in `process_message'
/home/deploy/GIT/recursive-dns/test/vendor/bundle/ruby/2.1.0/gems/vrsn-ie-dnsruby-1.58.0/lib/vrsn-ie-dnsruby/select_thread.rb:283:in `block in process_ready'
/home/deploy/GIT/recursive-dns/test/vendor/bundle/ruby/2.1.0/gems/vrsn-ie-dnsruby-1.58.0/lib/vrsn-ie-dnsruby/select_thread.rb:276:in `each'
/home/deploy/GIT/recursive-dns/test/vendor/bundle/ruby/2.1.0/gems/vrsn-ie-dnsruby-1.58.0/lib/vrsn-ie-dnsruby/select_thread.rb:276:in `process_ready'
/home/deploy/GIT/recursive-dns/test/vendor/bundle/ruby/2.1.0/gems/vrsn-ie-dnsruby-1.58.0/lib/vrsn-ie-dnsruby/select_thread.rb:221:in `do_select'
/home/deploy/GIT/recursive-dns/test/vendor/bundle/ruby/2.1.0/gems/vrsn-ie-dnsruby-1.58.0/lib/vrsn-ie-dnsruby/select_thread.rb:70:in `block (2 levels) in initialize'

It appears that things go south when Dnsruby is processing a response.  Perhaps, the munger corrupted the rcode/xrcode in the DNS packet and that is what Dnsruby is having difficulty processing.


Craig

On Monday, June 29, 2015 at 11:40:17 AM UTC-4, Craig Despeaux wrote:

Alex Dalitz

unread,
Jul 7, 2015, 10:53:23 AM7/7/15
to Craig Despeaux, dns...@googlegroups.com
Thanks - that’s very helpful.

Would you be able to print the message sent and received when this happens, please? Either pretty printed or binary, anything is fine.

Thanks!


Alex.

--
You received this message because you are subscribed to the Google Groups "dnsruby" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dnsruby+u...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Craig Despeaux

unread,
Jul 7, 2015, 4:51:07 PM7/7/15
to dns...@googlegroups.com
I changed my test code to below:

  msg = create_msg(qname, qtype, options)


  STDOUT.puts "before send"
  STDOUT.puts Classes.new('IN')
  STDOUT.puts msg.inspect

  @dns_server.send_async(msg, queue)
  STDOUT.puts "after send"
  STDOUT.puts Classes.new('IN')
  id, @dns_response, error = queue.pop
  STDOUT.puts "after pop"
  STDOUT.puts Classes.new('IN')
  unless "#{Classes.new("IN")}" == "IN"
    STDOUT.puts "dns response"
    STDOUT.puts @dns_response.inspect
    STDOUT.puts "dns response"
  end

And when it fell into the unless block, the previous message and response printed are provided below:

before send
IN
#<Dnsruby::Message:0x007f568c7f6b08 @header=#<Dnsruby::Header:0x007f568c7f6a40 @id=21190, @qr=false, @opcode=Query, @aa=false, @ad=false, @tc=false, @rd=true, @ra=false, @cd=false, @rcode=NOERROR, @qdcount=1, @nscount=0, @ancount=0, @arcount=1>, @question=[#<Dnsruby::Question:0x007f568c7f5dc0 @qtype=A, @qclass=IN, @qname=#<Dnsruby::Name: google.com.>>], @answer=[], @authority=[], @additional=[#<Dnsruby::RR::OPT:0x007f568c7f52d0 @type=OPT, @ttl=0, @options=nil, @klass=CLASS512>], @tsigstate=:Unsigned, @signing=false, @tsigkey=nil, @answerfrom=nil, @answerip=nil, @send_raw=true, @do_validation=true, @do_caching=false, @security_level=UNCHECKED, @security_error=nil, @cached=false>
after send
IN
after pop
1
dns response
#<Dnsruby::Message:0x007f568c7f0208 @header=#<Dnsruby::Header:0x007f568c7dfae8 @id=21190, @qr=true, @opcode=Query, @aa=false, @ad=false, @tc=false, @rd=true, @ra=true, @cd=false, @rcode=NOERROR, @qdcount=1, @nscount=0, @ancount=0, @arcount=1>, @question=[#<Dnsruby::Question:0x007f568c7deff8 @qtype=A, @qclass=IN, @qname=#<Dnsruby::Name: google.com.>>], @answer=[], @authority=[], @additional=[#<#<Class:0x007f568c7deaf8>:0x007f568c7de918 @type=OPT, @ttl=16809984, @options=nil, @klass=CLASS4096, @name=#<Dnsruby::Name: .>>], @tsigstate=:Unsigned, @signing=false, @tsigkey=nil, @answerfrom="127.0.0.1", @answerip="127.0.0.1", @send_raw=false, @do_validation=true, @do_caching=true, @security_level=UNCHECKED, @security_error=nil, @cached=false, @answersize=39>
dns response


Craig

On Monday, June 29, 2015 at 11:40:17 AM UTC-4, Craig Despeaux wrote:

Alex Dalitz

unread,
Jul 8, 2015, 1:35:45 AM7/8/15
to Craig Despeaux, dns...@googlegroups.com
Hi - 

I ran this:

require 'dnsruby'
include Dnsruby
  msg = Message.new("bbc.co.uk", "A")
@dns_server = Resolver.new()
queue = Queue.new()

  STDOUT.puts "before send"
  STDOUT.puts Classes.new('IN')
  STDOUT.puts msg.inspect
  @dns_server.send_async(msg, queue)
  STDOUT.puts "after send"
  STDOUT.puts Classes.new('IN')
  id, @dns_response, error = queue.pop
  STDOUT.puts "after pop"
  STDOUT.puts Classes.new('IN')
  unless "#{Classes.new("IN")}" == "IN"
    STDOUT.puts "dns response"
    STDOUT.puts @dns_response.inspect
    STDOUT.puts "dns response"
  end

and got this :

before send
IN
#<Dnsruby::Message:0x007f8e11206ab0 @header=#<Dnsruby::Header:0x007f8e11206a60 @id=30756, @qr=false, @opcode=Query, @aa=false, @ad=false, @tc=false, @rd=false, @ra=false, @cd=false, @rcode=NOERROR, @qdcount=1, @nscount=0, @ancount=0, @arcount=0>, @question=[#<Dnsruby::Question:0x007f8e11206448 @qtype=A, @qclass=IN, @qname=#<Dnsruby::Name: bbc.co.uk.>>], @answer=[], @authority=[], @additional=[], @tsigstate=:Unsigned, @signing=false, @tsigkey=nil, @answerfrom=nil, @answerip=nil, @send_raw=false, @do_validation=true, @do_caching=true, @security_level=UNCHECKED, @security_error=nil, @cached=false>
after send
IN
after pop
IN

I’m afraid that I really am going to need some code which demonstrates the problem. This code seems to work just fine.

Is it possible, please, to print out the contents of the message which is making this fail? Once I know which message you have, then I will be able to fix the problem. Just now, I do not see any failure.

Thanks!


Alex.


-- 
You received this message because you are subscribed to the Google Groups "dnsruby" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dnsruby+u...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Craig Despeaux

unread,
Jul 8, 2015, 9:27:29 AM7/8/15
to dns...@googlegroups.com
Hi Alex,

That was the last message sent by Dnsruby, however, that was not the message processed by the resolver because a byte in the packet was corrupted between Dnsruby and the DNS server.  The problem seems to occur when Dnsruby attempts to deal with the response, which includes the bad data.  I'll have to capture the actual packet that was sent and received with tcpdump.

Maybe there's another alternative here.  Would it be possible to add an option to Dnsruby that instructs it to just send messages and drop any responses on the floor.  I don't really care about the responses in this case and it seems Dnsruby doesn't deal well with bad packets being returned.  My only real concern is that our DNS server doesn't crash when it receives a bad packet.  Then again, maybe I should just change the random packet corruption test to use dig as the client.

I'll capture the tcpdump and send it to you later today.


Craig

On Monday, June 29, 2015 at 11:40:17 AM UTC-4, Craig Despeaux wrote:

Craig Despeaux

unread,
Jul 8, 2015, 10:42:52 AM7/8/15
to dns...@googlegroups.com
Hi Alex,

I captured the tcpdump.  I've attached a tar file showing Wireshark screen shots of the corrupted query and the query response that is returned, in addition to the pcap file.


Craig

On Monday, June 29, 2015 at 11:40:17 AM UTC-4, Craig Despeaux wrote:
tcpdump.tar.gz

Craig Despeaux

unread,
Jul 9, 2015, 11:42:02 AM7/9/15
to dns...@googlegroups.com
Hi Alex,

I'm not sure I can do what you are asking because Dnsruby won't let me.  I took a look at the tcpdump and the packet corruption that was causing us problems and the byte that is being changed is the label length for "com".  It is changed from 0x03 to 0x10.  If I attempt to create that in string form and decode it, Dnsruby complains -- see below:

#!/usr/bin/ruby

gem 'dnsruby', '=1.58'
require 'dnsruby'
include Dnsruby

def do_query(res, msg, q)
  res.send_async(msg, q)
  id, response, error = q.pop
  if response.nil?
    fail "Error: #{error} querying #{qname} and #{qtype} from server #{res.config.nameserver}"
  end
  puts response
end

res = Resolver.new(:nameserver => '8.8.8.8',
                   :dnssec => false,
                   :do_caching => false,
                   :retry_times => 3,
                   :retry_delay => 1,
                   :query_timeout => 1)

qname = "google.com"
qtype = "A"
qclass = "IN"

q = Queue.new

#msg_as_string = "\x44\xc4\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x06\x67\x6f\x6f\x67\x6c\x65\x03\x63\x6f\x6d\x00\x00\x01\x00\x01"
msg_as_string = "\xa8\xc4\x01\x00\x00\x01\x00\x00\x00\x00\x00\x01\x06\x67\x6f\x6f\x67\x6c\x65\x10\x63\x6f\x6d\x00\x00\x12\x00\x01\x00\x00\x29\x10\x00\x00\x00\x00\x00\x0b\x00\x08\x07\x00\x01\x18\x00\xd8\xfd\x0a"
msg = Message.decode(msg_as_string)

puts Classes.new("IN")

do_query(res, msg, q)

puts Classes.new("IN")

msg = Message.new(qname, qtype, qclass)
do_query(res, msg, q)


And here is what I get when I run it:

[cdespeau@goterps ~]$ ruby test.rb
/home/cdespeau/.rvm/gems/ruby-2.1.2/gems/dnsruby-1.58.0/lib/dnsruby/message/decoder.rb:32:in `assert_buffer_position_valid': requested position of 50 must be between 0 and buffer size (48). (Dnsruby::DecodeError)
        from /home/cdespeau/.rvm/gems/ruby-2.1.2/gems/dnsruby-1.58.0/lib/dnsruby/message/decoder.rb:90:in `get_unpack'
        from /home/cdespeau/.rvm/gems/ruby-2.1.2/gems/dnsruby-1.58.0/lib/dnsruby/message/decoder.rb:163:in `get_rr'
        from /home/cdespeau/.rvm/gems/ruby-2.1.2/gems/dnsruby-1.58.0/lib/dnsruby/message/message.rb:584:in `block (2 levels) in decode'
        from /home/cdespeau/.rvm/gems/ruby-2.1.2/gems/dnsruby-1.58.0/lib/dnsruby/message/message.rb:582:in `times'
        from /home/cdespeau/.rvm/gems/ruby-2.1.2/gems/dnsruby-1.58.0/lib/dnsruby/message/message.rb:582:in `block in decode'
        from /home/cdespeau/.rvm/gems/ruby-2.1.2/gems/dnsruby-1.58.0/lib/dnsruby/message/decoder.rb:20:in `initialize'
        from /home/cdespeau/.rvm/gems/ruby-2.1.2/gems/dnsruby-1.58.0/lib/dnsruby/message/message.rb:568:in `new'
        from /home/cdespeau/.rvm/gems/ruby-2.1.2/gems/dnsruby-1.58.0/lib/dnsruby/message/message.rb:568:in `decode'
        from test.rb:31:in `<main>'

I'll keep working on it -- maybe there's another way to do it besides changing the label length.  If you have any thoughts, let me know.


Craig


On Monday, June 29, 2015 at 11:40:17 AM UTC-4, Craig Despeaux wrote:

Alex Dalitz

unread,
Jul 9, 2015, 2:03:07 PM7/9/15
to Craig Despeaux, dns...@googlegroups.com
Try catching error then print? I'll look properly tomorrow but I'll be offline for a few days

Sent from my iPhone
--
You received this message because you are subscribed to the Google Groups "dnsruby" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dnsruby+u...@googlegroups.com.

Craig Despeaux

unread,
Jul 10, 2015, 11:20:41 AM7/10/15
to dns...@googlegroups.com
Hi Alex,

Still working on trying to create and send that bad message with Dnsruby, but I wanted to point out this problem (and solution) I found while attempting to decode a message that includes EDNS subnet:

In resource/OPT.rb I had to change the last line of code in encode_rdata from:

  msg.put_bytes(opt.data)

to:

  msg.put_pack('A*', opt.data)

or I would receive this error:

/home/cdespeau/.rvm/gems/ruby-2.1.2/gems/dnsruby-1.58.0/lib/dnsruby/message/encoder.rb:14:in `put_bytes': incompatible character encodings: ASCII-8BIT and UTF-8 (Encoding::CompatibilityError)
        from /home/cdespeau/.rvm/gems/ruby-2.1.2/gems/dnsruby-1.58.0/lib/dnsruby/resource/OPT.rb:246:in `block in encode_rdata'

Craig 

On Monday, June 29, 2015 at 11:40:17 AM UTC-4, Craig Despeaux wrote:

Alex Dalitz

unread,
Jul 13, 2015, 5:38:12 AM7/13/15
to Craig Despeaux, dns...@googlegroups.com
Hi Craig -

Thanks very much for catching this!

I’ve committed this to github.

Thanks again,


Alex.

-- 
You received this message because you are subscribed to the Google Groups "dnsruby" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dnsruby+u...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Craig Despeaux

unread,
Jul 23, 2015, 9:04:07 AM7/23/15
to dnsruby, craiged...@gmail.com
Hi Alex,

It's been awhile but I wanted to get back to you and let you know I have been unable to come up with a way to recreate this problem by building a message with Dnsruby.  At this point, I'm looking at other alternatives to drive the test where I am corrrupting packets because once Dnsruby deals with a corrupted packet coming back, it negatively impacts tests that follow.  I might look at dnspython and see if it handles this any better.  If you've been able to come up with anything on your end, let me know.

Thanks,
Craig

On Monday, June 29, 2015 at 11:40:17 AM UTC-4, Craig Despeaux wrote:
Reply all
Reply to author
Forward
0 new messages