mirror of
https://github.com/miekg/dns.git
synced 2025-10-15 11:51:00 +02:00
Fix the NSEC(3) bitmap
This commit is contained in:
parent
15fedf72e7
commit
7da3d0bcb7
53
msg.go
53
msg.go
@ -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)])
|
||||
fv.Set(reflect.NewValue(opt).(*reflect.SliceValue))
|
||||
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:
|
||||
off, ok = unpackStructValue(fv, msg, off)
|
||||
|
8
types.go
8
types.go
@ -420,9 +420,11 @@ func (rr *RR_NSEC) Header() *RR_Header {
|
||||
}
|
||||
|
||||
func (rr *RR_NSEC) String() string {
|
||||
return rr.Hdr.String() +
|
||||
" " + rr.NextDomain +
|
||||
" " + "bitmap"
|
||||
s := rr.Hdr.String() + " " + rr.NextDomain
|
||||
for i:=0; i < len(rr.TypeBitMap); i++ {
|
||||
s = s + " " + Rr_str[rr.TypeBitMap[i]]
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
type RR_DS struct {
|
||||
|
Loading…
x
Reference in New Issue
Block a user