Fix the NSEC(3) bitmap

This commit is contained in:
Miek Gieben 2011-01-09 22:02:25 +01:00
parent 15fedf72e7
commit 7da3d0bcb7
2 changed files with 58 additions and 3 deletions

53
msg.go
View File

@ -429,6 +429,59 @@ func unpackStructValue(val *reflect.StructValue, msg []byte, off int) (off1 int,
opt[0].Data = hex.EncodeToString(msg[off1 : off1+int(optlen)]) opt[0].Data = hex.EncodeToString(msg[off1 : off1+int(optlen)])
fv.Set(reflect.NewValue(opt).(*reflect.SliceValue)) fv.Set(reflect.NewValue(opt).(*reflect.SliceValue))
off = off1 + int(optlen) off = off1 + int(optlen)
case "NSEC": // NSEC/NSEC3
if off+1 > len(msg) {
// there is none
break
}
// Fix multple windows TODO(mg)
nsec := make([]uint16, 256) // use append TODO(mg)
ni := 0
window := int(msg[off])
blocks := int(msg[off+1])
if off+blocks > len(msg) {
return len(msg), false
}
off += 2
for i := 0; i < blocks; i++ {
b := msg[off+i]
// Check the bits one by one, and set the type
if b&0x1 == 0x1 {
nsec[ni] = uint16(window*256 + i*8 + 7)
ni++
}
if b&0x2 == 0x2 {
nsec[ni] = uint16(window*256 + i*8 + 6)
ni++
}
if b&0x4 == 0x4 {
nsec[ni] = uint16(window*256 + i*8 + 5)
ni++
}
if b&0x8 == 0x8 {
nsec[ni] = uint16(window*256 + i*8 + 4)
ni++
}
if b&0x10 == 0x10 {
nsec[ni] = uint16(window*256 + i*8 + 3)
ni++
}
if b&0x20 == 0x20 {
nsec[ni] = uint16(window*256 + i*8 + 2)
ni++
}
if b&0x40 == 0x40 {
nsec[ni] = uint16(window*256 + i*8 + 1)
ni++
}
if b&0x80 == 0x80 {
nsec[ni] = uint16(window*256 + i*8 + 0)
ni++
}
}
nsec = nsec[:ni]
fv.Set(reflect.NewValue(nsec).(*reflect.SliceValue))
off += blocks
} }
case *reflect.StructValue: case *reflect.StructValue:
off, ok = unpackStructValue(fv, msg, off) off, ok = unpackStructValue(fv, msg, off)

View File

@ -420,9 +420,11 @@ func (rr *RR_NSEC) Header() *RR_Header {
} }
func (rr *RR_NSEC) String() string { func (rr *RR_NSEC) String() string {
return rr.Hdr.String() + s := rr.Hdr.String() + " " + rr.NextDomain
" " + rr.NextDomain + for i:=0; i < len(rr.TypeBitMap); i++ {
" " + "bitmap" s = s + " " + Rr_str[rr.TypeBitMap[i]]
}
return s
} }
type RR_DS struct { type RR_DS struct {