From 7da3d0bcb7cb3d6658920e22d73ae15cb624b503 Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Sun, 9 Jan 2011 22:02:25 +0100 Subject: [PATCH] Fix the NSEC(3) bitmap --- msg.go | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ types.go | 8 +++++--- 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/msg.go b/msg.go index 02b9ae65..09635f22 100644 --- a/msg.go +++ b/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) diff --git a/types.go b/types.go index 089c1753..fe31d928 100644 --- a/types.go +++ b/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 {