mirror of
https://github.com/miekg/dns.git
synced 2025-10-12 10:21:00 +02:00
More stuff for IXFR
This commit is contained in:
parent
c7df8fa36c
commit
22f34ec885
1
TODO
1
TODO
@ -5,6 +5,7 @@ Todo:
|
|||||||
* Parsing from strings, going with goyacc and own lexer
|
* Parsing from strings, going with goyacc and own lexer
|
||||||
* NSEC and nsec3 closest encloser helper functions
|
* NSEC and nsec3 closest encloser helper functions
|
||||||
* TKEY
|
* TKEY
|
||||||
|
* Large TXT records
|
||||||
|
|
||||||
Issues:
|
Issues:
|
||||||
* Check the network order, it works now, but this is on Intel??
|
* Check the network order, it works now, but this is on Intel??
|
||||||
|
@ -9,31 +9,38 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var serial *int = flag.Int("serial", 0, "Perform an IXFR with the given serial")
|
var serial *int = flag.Int("serial", 0, "Perform an IXFR with the given serial")
|
||||||
|
var onesoa *bool = flag.Bool("1soa", false, "Don't print the last SOA")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
res := new(dns.Resolver)
|
res := new(dns.Resolver)
|
||||||
res.FromFile("/etc/resolv.conf")
|
res.FromFile("/etc/resolv.conf")
|
||||||
res.Servers[0] = "213.154.224.1"
|
|
||||||
|
|
||||||
ch := make(chan dns.RR)
|
ch := make(chan dns.RR)
|
||||||
|
|
||||||
m := new(dns.Msg)
|
m := new(dns.Msg)
|
||||||
m.Question = make([]dns.Question, 1)
|
m.Question = make([]dns.Question, 1)
|
||||||
if *serial > 0 {
|
if *serial > 0 {
|
||||||
m.Question[0] = dns.Question{"tjeb.nl.", dns.TypeIXFR, dns.ClassINET}
|
m.Question[0] = dns.Question{"miek.nl.", dns.TypeIXFR, dns.ClassINET}
|
||||||
soa := new(dns.RR_SOA)
|
soa := new(dns.RR_SOA)
|
||||||
soa.Hdr = dns.RR_Header{"tjeb.nl.", dns.TypeSOA, dns.ClassINET, 14400, 0}
|
soa.Hdr = dns.RR_Header{"miek.nl.", dns.TypeSOA, dns.ClassINET, 14400, 0}
|
||||||
soa.Serial = uint32(*serial)
|
soa.Serial = uint32(*serial)
|
||||||
m.Ns = make([]dns.RR, 1)
|
m.Ns = make([]dns.RR, 1)
|
||||||
m.Ns[0] = soa
|
m.Ns[0] = soa
|
||||||
go res.Ixfr(m, ch)
|
go res.Ixfr(m, ch)
|
||||||
} else {
|
} else {
|
||||||
m.Question[0] = dns.Question{"tjeb.nl.", dns.TypeAXFR, dns.ClassINET}
|
m.Question[0] = dns.Question{"miek.nl.", dns.TypeAXFR, dns.ClassINET}
|
||||||
go res.Axfr(m, ch)
|
go res.Axfr(m, ch)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
soa := false
|
||||||
for x := range ch {
|
for x := range ch {
|
||||||
|
if x.Header().Rrtype == dns.TypeSOA {
|
||||||
|
if *onesoa && soa {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
soa = true
|
||||||
|
}
|
||||||
fmt.Printf("%v\n",x)
|
fmt.Printf("%v\n",x)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
41
resolver.go
41
resolver.go
@ -136,7 +136,7 @@ Server:
|
|||||||
continue Server
|
continue Server
|
||||||
}
|
}
|
||||||
state := FIRST
|
state := FIRST
|
||||||
var serial int // The first serial seen is the current server serial
|
var serial uint32 // The first serial seen is the current server serial
|
||||||
var _ = serial
|
var _ = serial
|
||||||
|
|
||||||
defer c.Close()
|
defer c.Close()
|
||||||
@ -161,30 +161,37 @@ Server:
|
|||||||
|
|
||||||
if state == FIRST {
|
if state == FIRST {
|
||||||
// A single SOA RR signals "no changes"
|
// A single SOA RR signals "no changes"
|
||||||
if len(in.Answer) == 1 && checkSOA(in, true) {
|
if len(in.Answer) == 1 && checkAxfrSOA(in, true) {
|
||||||
c.Close()
|
c.Close()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// But still check if the returned answer is ok
|
// But still check if the returned answer is ok
|
||||||
if !checkSOA(in, true) {
|
if !checkAxfrSOA(in, true) {
|
||||||
c.Close()
|
c.Close()
|
||||||
continue Server
|
continue Server
|
||||||
}
|
}
|
||||||
// This serial is important
|
// This serial is important
|
||||||
serial = int(in.Answer[0].(*RR_SOA).Serial)
|
serial = in.Answer[0].(*RR_SOA).Serial
|
||||||
sendFromMsg(in, m)
|
sendFromMsg(in, m)
|
||||||
state = SECOND
|
state = SECOND
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now we need to check each message for SOA records, to see what we need to do
|
// Now we need to check each message for SOA records, to see what we need to do
|
||||||
if state != FIRST {
|
if state != FIRST {
|
||||||
if !checkSOA(in, false) {
|
// If the last record in the IXFR contains the servers' SOA
|
||||||
|
// we should quit
|
||||||
|
|
||||||
|
// for _, r := range in.Answer {
|
||||||
|
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
if !checkAxfrSOA(in, false) {
|
||||||
// Soa record not the last one
|
// Soa record not the last one
|
||||||
sendFromMsg(in, m)
|
sendFromMsg(in, m)
|
||||||
continue
|
continue
|
||||||
} else{
|
} else{
|
||||||
c.Close()
|
|
||||||
sendFromMsg(in, m)
|
sendFromMsg(in, m)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -252,7 +259,7 @@ Server:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if first {
|
if first {
|
||||||
if !checkSOA(in, true) {
|
if !checkAxfrSOA(in, true) {
|
||||||
c.Close()
|
c.Close()
|
||||||
continue Server
|
continue Server
|
||||||
}
|
}
|
||||||
@ -261,12 +268,11 @@ Server:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !first {
|
if !first {
|
||||||
if !checkSOA(in, false) {
|
if !checkAxfrSOA(in, false) {
|
||||||
// Soa record not the last one
|
// Soa record not the last one
|
||||||
sendFromMsg(in, m)
|
sendFromMsg(in, m)
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
c.Close()
|
|
||||||
sendFromMsg(in, m)
|
sendFromMsg(in, m)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -439,7 +445,7 @@ func recvTCP(c net.Conn) ([]byte, os.Error) {
|
|||||||
// Check if he SOA record exists in the Answer section of
|
// Check if he SOA record exists in the Answer section of
|
||||||
// the packet. If first is true the first RR must be a soa
|
// the packet. If first is true the first RR must be a soa
|
||||||
// if false, the last one should be a SOA
|
// if false, the last one should be a SOA
|
||||||
func checkSOA(in *Msg, first bool) bool {
|
func checkAxfrSOA(in *Msg, first bool) bool {
|
||||||
if len(in.Answer) > 0 {
|
if len(in.Answer) > 0 {
|
||||||
if first {
|
if first {
|
||||||
return in.Answer[0].Header().Rrtype == TypeSOA
|
return in.Answer[0].Header().Rrtype == TypeSOA
|
||||||
@ -450,6 +456,21 @@ func checkSOA(in *Msg, first bool) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Same as Axfr one, but now also check the serial
|
||||||
|
func checkIxfrSOA(in *Msg, first bool, serial uint32) bool {
|
||||||
|
if len(in.Answer) > 0 {
|
||||||
|
if first {
|
||||||
|
return in.Answer[0].Header().Rrtype == TypeSOA &&
|
||||||
|
in.Answer[0].(*RR_SOA).Serial == serial
|
||||||
|
} else {
|
||||||
|
return in.Answer[len(in.Answer)-1].Header().Rrtype == TypeSOA &&
|
||||||
|
in.Answer[len(in.Answer)-1].(*RR_SOA).Serial == serial
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Send the answer section to the channel
|
// Send the answer section to the channel
|
||||||
func sendFromMsg(in *Msg, c chan RR) {
|
func sendFromMsg(in *Msg, c chan RR) {
|
||||||
for _, r := range in.Answer {
|
for _, r := range in.Answer {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user