Class ldns_zone

Class ldns_zone

class ldns.ldns_zone

Zone definitions

Usage

This class is able to read and parse the content of zone file by doing:

>>> import ldns
>>> zone = ldns.ldns_zone.new_frm_fp(open("zone.txt","r"), None, 0, ldns.LDNS_RR_CLASS_IN)
>>> print zone.soa()
example.    600     IN      SOA     example. admin.example. 2008022501 28800 7200 604800 18000
>>> print zone.rrs()
example.    600     IN      MX      10 mail.example.
example.    600     IN      NS      ns1.example.
example.    600     IN      NS      ns2.example.
example.    600     IN      A       192.168.1.1

The zone.txt file contains the following records:

$ORIGIN example.
$TTL 600

example.        IN SOA  example. admin.example. (
                                2008022501 ; serial
                                28800      ; refresh (8 hours)
                                7200       ; retry (2 hours)
                                604800     ; expire (1 week)
                                18000      ; minimum (5 hours)
                                )

@       IN      MX      10 mail.example.
@       IN      NS      ns1
@       IN      NS      ns2
@       IN      A       192.168.1.1
glue_rr_list()

Retrieve all resource records from the zone that are glue records.

The resulting list does are pointer references to the zone’s data.

Due to the current zone implementation (as a list of rr’s), this function is extremely slow. Another (probably better) way to do this is to use an ldns_dnssec_zone structure and the mark_glue function

Returns:(ldns_rr_list *) the rr_list with the glue
static new_frm_fp(file, origin, ttl, rr_class=1, raiseException=True)

Creates a new zone object from given file pointer

Parameters:
  • file – a file object
  • origin – (ldns_rdf) the zones’ origin
  • ttl – default ttl to use
  • rr_class – efault class to use (IN)
  • raiseException – if True, an exception occurs in case a zone instance can’t be created
Returns:

zone instance or None. If an instance can’t be created and raiseException is True, an exception occurs.

static new_frm_fp_l(file, origin, ttl, rr_class, raiseException=True)

Create a new zone from a file, keep track of the line numbering

Parameters:
  • file – a file object
  • origin – (ldns_rdf) the zones’ origin
  • ttl – default ttl to use
  • rr_class – efault class to use (IN)
  • raiseException – if True, an exception occurs in case a zone instance can’t be created
Returns:

  • zone - zone instance or None. If an instance can’t be created and raiseException is True, an exception occurs.
  • line - used for error msg, to get to the line number

print_to_file(output)

Prints the data in the zone to the given file stream (in presentation format).

push_rr(rr)

push an single rr to a zone structure.

This function use pointer copying, so the rr_list structure inside z is modified!

Parameters:rr – the rr to add
Returns:(bool) a true on succes otherwise falsed
push_rr_list(list)

push an rrlist to a zone structure.

This function use pointer copying, so the rr_list structure inside z is modified!

Parameters:list – the list to add
Returns:(bool) a true on succes otherwise falsed
rr_count()

Returns the number of resource records in the zone, NOT counting the SOA record.

Returns:(size_t) the number of rr’s in the zone
rrs()

Get a list of a zone’s content.

Note that the SOA isn’t included in this list. You need to get the with ldns_zone_soa.

Returns:(ldns_rr_list *) the rrs from this zone
set_rrs(rrlist)

Set the zone’s contents.

Parameters:rrlist – the rrlist to use
set_soa(soa)

Set the zone’s soa record.

Parameters:soa – the soa to set
sign(key_list)

Signs the zone, and returns a newly allocated signed zone.

Parameters:key_list – list of keys to sign with
Returns:(ldns_zone *) signed zone
sign_nsec3(key_list, algorithm, flags, iterations, salt_length, salt)

Signs the zone with NSEC3, and returns a newly allocated signed zone.

Parameters:
  • key_list – list of keys to sign with
  • algorithm – the NSEC3 hashing algorithm to use
  • flags – NSEC3 flags
  • iterations – the number of NSEC3 hash iterations to use
  • salt_length – the length (in octets) of the NSEC3 salt
  • salt – the NSEC3 salt data
Returns:

(ldns_zone *) signed zone

soa()

Return the soa record of a zone.

Returns:(ldns_rr *) the soa record in the zone
sort()

Sort the rrs in a zone, with the current impl.

this is slow

Table Of Contents

Previous topic

Class ldns_rr_list

Next topic

Class ldns_key