class Dnsruby::ZoneTransfer

This class performs zone transfers as per RFC1034 (AXFR) and RFC1995 (IXFR).

Attributes

connect_timeout[RW]

Sets the connect timeout in seconds

klass[RW]

The class - defaults to IN

last_tsigstate[R]

Returns the tsigstate of the last transfer (nil if no TSIG signed transfer has occurred)

port[RW]

The port to connect to - defaults to 53

serial[RW]

If using IXFR, this is the SOA serial number to start the incrementals from

server[RW]

The nameserver to use for the zone transfer - defaults to system config

src_address[RW]

The source address to connect to

transfer_type[RW]

What type of transfer to do (IXFR or AXFR) - defaults to AXFR

tsig[R]

The TSIG record used to sign the transfer

Public Class Methods

new() click to toggle source
# File lib/dnsruby/zone_transfer.rb, line 50
def initialize
  @server=Config.new.nameserver[0]
  @transfer_type = Types.AXFR
  @klass=Classes.IN
  @port=53
  @serial=0
  @tsig = nil
  @axfr = nil
  @src_address = nil
  @connect_timeout = 5
end

Public Instance Methods

compare_serial(s1, s2) click to toggle source

Compare two serials according to RFC 1982. Return 0 if equal, -1 if s1 is bigger, 1 if s1 is smaller.

# File lib/dnsruby/zone_transfer.rb, line 227
def compare_serial(s1, s2)
  if s1 == s2
    return 0
  end
  if s1 < s2 and (s2 - s1) < (2**31)
    return 1
  end
  if s1 > s2 and (s1 - s2) > (2**31)
    return 1
  end
  if s1 < s2 and (s2 - s1) > (2**31)
    return -1
  end
  if s1 > s2 and (s1 - s2) < (2**31)
    return -1
  end
  return 0
end
transfer(zone) click to toggle source

Perform a zone transfer (RFC1995) If an IXFR query is unsuccessful, then AXFR is tried (and @transfer_type is set to AXFR) TCP is used as the only transport

If AXFR is performed, then the zone will be returned as a set of records :

zt = Dnsruby::ZoneTransfer.new
zt.transfer_type = Dnsruby::Types.AXFR
zt.server = "ns0.validation-test-servers.nominet.org.uk"
zone = zt.transfer("validation-test-servers.nominet.org.uk")
soa = zone[0]
rec1 = zone[1]
print zone.to_s

If IXFR is performed, then the incrementals will be returned as a set of Deltas. Each Delta contains the start and end SOA serial number, as well as an array of adds and deletes that occurred between the start and end.

zt = Dnsruby::ZoneTransfer.new
zt.transfer_type = Dnsruby::Types.IXFR
zt.server = "ns0.validation-test-servers.nominet.org.uk"
zt.serial = 2007090401
deltas = zt.transfer("validation-test-servers.nominet.org.uk")
assert_equal("Should show up in transfer", deltas[0].adds[1].data)
# File lib/dnsruby/zone_transfer.rb, line 88
def transfer(zone)
  servers = @server
  if (servers.class == String)
    servers=[servers]
  end
  xfr = nil
  exception = nil
  servers.each do |server|
    begin
      server=Config.resolve_server(server)
      xfr = do_transfer(zone, server)
      break
    rescue Exception => e
      exception = e
    end
  end
  if (xfr == nil && exception != nil)
    raise exception
  end
  return xfr
end
tsig=(*args) click to toggle source

Sets the TSIG to sign the zone transfer with. Pass in either a Dnsruby::RR::TSIG, or a key_name and key (or just a key) Pass in nil to stop tsig signing.

  • res.tsig=(tsig_rr)

  • res.tsig=(key_name, key)

  • res.tsig=nil # Don't sign the transfer

# File lib/dnsruby/zone_transfer.rb, line 45
def tsig=(*args)
  @tsig = Resolver.get_tsig(args)
end