-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdelegation_utils.go
58 lines (50 loc) · 1.47 KB
/
delegation_utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* Copyright 2024 Johan Stenstam, johan.stenstam@internetstiftelsen.se
*/
package tapir
import (
"log"
"github.com/miekg/dns"
)
func (zd *ZoneData) FindGlue(nsrrs RRset) *RRset {
zd.Logger.Printf("FindGlue: nsrrs: %v", nsrrs)
var glue, maybe_glue RRset
var nsname string
child := nsrrs.RRs[0].Header().Name
for _, rr := range nsrrs.RRs {
if nsrr, ok := rr.(*dns.NS); ok {
nsname = nsrr.Ns
zd.Logger.Printf("FindGlue: child '%s' has a nameserver '%s'", child, nsname)
var nsnamerrs *OwnerData
switch zd.ZoneType {
case 3:
nsnidx := zd.OwnerIndex[nsname]
nsnamerrs = &zd.Owners[nsnidx]
case 2:
tmp := zd.Data[nsname]
nsnamerrs = &tmp
}
if nsnamerrs != nil {
log.Printf("FindGlue nsname='%s': there are RRs", nsname)
if ns_A_rrs, ok := nsnamerrs.RRtypes[dns.TypeA]; ok {
log.Printf("FindGlue for nsname='%s': there are A RRs", nsname)
// Ok, we found an A RR
maybe_glue.RRs = append(maybe_glue.RRs, ns_A_rrs.RRs...)
}
if ns_AAAA_rrs, ok := nsnamerrs.RRtypes[dns.TypeAAAA]; ok {
log.Printf("FindGlue for nsname='%s': there are AAAA RRs", nsname)
// Ok, we found an AAAA RR
maybe_glue.RRs = append(maybe_glue.RRs, ns_AAAA_rrs.RRs...)
}
}
}
}
if len(maybe_glue.RRs) == 0 {
log.Printf("FindGlue: no glue for child=%s found in %s", child, zd.ZoneName)
} else {
log.Printf("FindGlue: found %d glue RRs child=%s in %s",
len(glue.RRs), child, zd.ZoneName)
glue = maybe_glue
}
return &glue
}