add Apex function, to access a zonesapex
This commit is contained in:
parent
ea947838d8
commit
c6e75de70e
18
zone.go
18
zone.go
|
@ -3,6 +3,7 @@ package dns
|
|||
// A structure for handling zone data
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/miekg/radix"
|
||||
"math/rand"
|
||||
"runtime"
|
||||
|
@ -356,6 +357,23 @@ func (z *Zone) RemoveRRset(s string, t uint16) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Apex returns the zone's apex records (SOA, NS and possibly other). If the
|
||||
// apex can not be found (thereby making it an illegal DNS zone) it returns nil.
|
||||
// Updating the zone's SOA serial, provided the apex exists:
|
||||
//
|
||||
// z.Apex.RR[TypeSOA][0].(*RR_SOA).Serial++
|
||||
//
|
||||
// Note the a) this increment is not protected by locks and b) if you use DNSSEC
|
||||
// you MUST resign the SOA record.
|
||||
func (z *Zone) Apex() *ZoneData {
|
||||
apex, e := z.Find(z.Origin)
|
||||
if !e {
|
||||
fmt.Printf("%#v\n", apex)
|
||||
return nil
|
||||
}
|
||||
return apex
|
||||
}
|
||||
|
||||
// Find looks up the ownername s in the zone and returns the
|
||||
// data and true when an exact match is found. If an exact find isn't
|
||||
// possible the first parent node with a non-nil Value is returned and
|
||||
|
|
27
zone_test.go
27
zone_test.go
|
@ -1,6 +1,7 @@
|
|||
package dns
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
@ -20,6 +21,32 @@ func TestRadixName(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestApex(t *testing.T) {
|
||||
f, err := os.Open("t/miek.nl.signed_test")
|
||||
if err != nil {
|
||||
t.Logf("Failed to open zone file")
|
||||
t.Fail()
|
||||
}
|
||||
defer f.Close()
|
||||
z := NewZone("miek.nl.")
|
||||
to := ParseZone(f, "miek.nl.", "t/miek.nl.signed_test")
|
||||
for rr := range to {
|
||||
if rr.Error == nil {
|
||||
z.Insert(rr.RR)
|
||||
} else {
|
||||
t.Logf("Error %s\n", rr.Error.Error())
|
||||
}
|
||||
}
|
||||
apex := z.Apex()
|
||||
if apex == nil {
|
||||
t.Fatalf("Apex not found")
|
||||
}
|
||||
t.Logf("Apex found %s", apex.RR[TypeSOA][0].String())
|
||||
apex.RR[TypeSOA][0].(*RR_SOA).Serial++
|
||||
apex = z.Apex()
|
||||
t.Logf("Apex found %s", z.Apex().RR[TypeSOA][0].String())
|
||||
}
|
||||
|
||||
func TestInsert(t *testing.T) {
|
||||
z := NewZone("miek.nl.")
|
||||
mx, _ := NewRR("foo.miek.nl. MX 10 mx.miek.nl.")
|
||||
|
|
Loading…
Reference in New Issue