Fix the nsec/3 length calculation

This overshoots, 'cause it only counts the windows, not the
actual bitmap sizes in the window. But it keeps the code
simple and fast.
This commit is contained in:
Miek Gieben 2013-06-27 20:19:02 +01:00
parent 3f40afaafd
commit 9fa50d8ac2
2 changed files with 22 additions and 7 deletions

4
msg.go
View File

@ -1255,7 +1255,7 @@ func (dns *Msg) Pack() (msg []byte, err error) {
dh.Nscount = uint16(len(ns)) dh.Nscount = uint16(len(ns))
dh.Arcount = uint16(len(extra)) dh.Arcount = uint16(len(extra))
msg = make([]byte, dns.packLen()+10) // TODO(miekg): +10 should go soon msg = make([]byte, dns.packLen()+1) // TODO(miekg): +10 should go soon
// Pack it in: header and then the pieces. // Pack it in: header and then the pieces.
off := 0 off := 0
off, err = packStructCompress(&dh, msg, off, compression, dns.Compress) off, err = packStructCompress(&dh, msg, off, compression, dns.Compress)
@ -1489,8 +1489,8 @@ func compressionLenSearch(c map[string]int, s string) (int, bool) {
} }
off, end = NextLabel(s, off) off, end = NextLabel(s, off)
} }
// TODO(miek): not sure if need, leave this for later debugging
if _, ok := c[s[off:]]; ok { if _, ok := c[s[off:]]; ok {
println("HIERO", s[off:]) // TODO(miek): remove this println
return len(s[off:]), true return len(s[off:]), true
} }
return 0, false return 0, false

View File

@ -756,9 +756,16 @@ func (rr *NSEC) String() string {
} }
func (rr *NSEC) len() int { func (rr *NSEC) len() int {
l := len(rr.NextDomain) + 1 l := rr.Hdr.len() + len(rr.NextDomain) + 1
return rr.Hdr.len() + l + 32 + 1 lastwindow := uint32(2^32+1)
// TODO: +32 is max type bitmap for _, t := range rr.TypeBitMap {
window := t / 256
if uint32(window) != lastwindow {
l += 1 + 32
}
lastwindow = uint32(window)
}
return l
} }
type DS struct { type DS struct {
@ -1023,8 +1030,16 @@ func (rr *NSEC3) String() string {
} }
func (rr *NSEC3) len() int { func (rr *NSEC3) len() int {
return rr.Hdr.len() + 6 + len(rr.Salt)/2 + 1 + len(rr.NextDomain) + 1 + 32 l := rr.Hdr.len() + 6 + len(rr.Salt)/2 + 1 + len(rr.NextDomain) + 1
// TODO: +32 is MAX type bit map lastwindow := uint32(2^32+1)
for _, t := range rr.TypeBitMap {
window := t / 256
if uint32(window) != lastwindow {
l += 1 + 32
}
lastwindow = uint32(window)
}
return l
} }
type NSEC3PARAM struct { type NSEC3PARAM struct {