tweaks to give more power to unbound package
This commit is contained in:
parent
534433a714
commit
2d2b4f5e64
10
dnssec.go
10
dnssec.go
|
@ -117,7 +117,7 @@ func (k *RR_DNSKEY) KeyTag() uint16 {
|
|||
keywire.Algorithm = k.Algorithm
|
||||
keywire.PublicKey = k.PublicKey
|
||||
wire := make([]byte, DefaultMsgSize)
|
||||
n, ok := packStruct(keywire, wire, 0)
|
||||
n, ok := PackStruct(keywire, wire, 0)
|
||||
if !ok {
|
||||
return 0
|
||||
}
|
||||
|
@ -155,7 +155,7 @@ func (k *RR_DNSKEY) ToDS(h int) *RR_DS {
|
|||
keywire.Algorithm = k.Algorithm
|
||||
keywire.PublicKey = k.PublicKey
|
||||
wire := make([]byte, DefaultMsgSize)
|
||||
n, ok := packStruct(keywire, wire, 0)
|
||||
n, ok := PackStruct(keywire, wire, 0)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
@ -236,7 +236,7 @@ func (s *RR_RRSIG) Sign(k PrivateKey, rrset []RR) error {
|
|||
|
||||
// Create the desired binary blob
|
||||
signdata := make([]byte, DefaultMsgSize)
|
||||
n, ok := packStruct(sigwire, signdata, 0)
|
||||
n, ok := PackStruct(sigwire, signdata, 0)
|
||||
if !ok {
|
||||
return ErrPack
|
||||
}
|
||||
|
@ -348,7 +348,7 @@ func (s *RR_RRSIG) Verify(k *RR_DNSKEY, rrset []RR) error {
|
|||
sigwire.SignerName = strings.ToLower(s.SignerName)
|
||||
// Create the desired binary blob
|
||||
signeddata := make([]byte, DefaultMsgSize)
|
||||
n, ok := packStruct(sigwire, signeddata, 0)
|
||||
n, ok := PackStruct(sigwire, signeddata, 0)
|
||||
if !ok {
|
||||
return ErrPack
|
||||
}
|
||||
|
@ -683,7 +683,7 @@ func rawSignatureData(rrset []RR, s *RR_RRSIG) (buf []byte) {
|
|||
}
|
||||
// 6.2. Canonical RR Form. (5) - origTTL
|
||||
wire := make([]byte, r.Len()*2)
|
||||
off, ok1 := packRR(r1, wire, 0, nil, false)
|
||||
off, ok1 := PackRR(r1, wire, 0, nil, false)
|
||||
if !ok1 {
|
||||
return nil
|
||||
}
|
||||
|
|
28
msg.go
28
msg.go
|
@ -649,7 +649,7 @@ func structValue(any interface{}) reflect.Value {
|
|||
return reflect.ValueOf(any).Elem()
|
||||
}
|
||||
|
||||
func packStruct(any interface{}, msg []byte, off int) (off1 int, ok bool) {
|
||||
func PackStruct(any interface{}, msg []byte, off int) (off1 int, ok bool) {
|
||||
off, ok = packStructValue(structValue(any), msg, off, nil, false)
|
||||
return off, ok
|
||||
}
|
||||
|
@ -1010,7 +1010,7 @@ func unpackUint16(msg []byte, off int) (v uint16, off1 int) {
|
|||
return
|
||||
}
|
||||
|
||||
func unpackStruct(any interface{}, msg []byte, off int) (off1 int, ok bool) {
|
||||
func UnpackStruct(any interface{}, msg []byte, off int) (off1 int, ok bool) {
|
||||
off, ok = unpackStructValue(structValue(any), msg, off)
|
||||
return off, ok
|
||||
}
|
||||
|
@ -1056,7 +1056,7 @@ func packBase32(s []byte) ([]byte, error) {
|
|||
}
|
||||
|
||||
// Resource record packer.
|
||||
func packRR(rr RR, msg []byte, off int, compression map[string]int, compress bool) (off1 int, ok bool) {
|
||||
func PackRR(rr RR, msg []byte, off int, compression map[string]int, compress bool) (off1 int, ok bool) {
|
||||
if rr == nil {
|
||||
return len(msg), false
|
||||
}
|
||||
|
@ -1070,11 +1070,11 @@ func packRR(rr RR, msg []byte, off int, compression map[string]int, compress boo
|
|||
}
|
||||
|
||||
// Resource record unpacker.
|
||||
func unpackRR(msg []byte, off int) (rr RR, off1 int, ok bool) {
|
||||
func UnpackRR(msg []byte, off int) (rr RR, off1 int, ok bool) {
|
||||
// unpack just the header, to find the rr type and length
|
||||
var h RR_Header
|
||||
off0 := off
|
||||
if off, ok = unpackStruct(&h, msg, off); !ok {
|
||||
if off, ok = UnpackStruct(&h, msg, off); !ok {
|
||||
return nil, len(msg), false
|
||||
}
|
||||
end := off + int(h.Rdlength)
|
||||
|
@ -1085,7 +1085,7 @@ func unpackRR(msg []byte, off int) (rr RR, off1 int, ok bool) {
|
|||
} else {
|
||||
rr = mk()
|
||||
}
|
||||
off, ok = unpackStruct(rr, msg, off0)
|
||||
off, ok = UnpackStruct(rr, msg, off0)
|
||||
if off != end {
|
||||
return &h, end, true
|
||||
}
|
||||
|
@ -1219,13 +1219,13 @@ func (dns *Msg) Pack() (msg []byte, ok bool) {
|
|||
off, ok = packStructCompress(&question[i], msg, off, compression, dns.Compress)
|
||||
}
|
||||
for i := 0; i < len(answer); i++ {
|
||||
off, ok = packRR(answer[i], msg, off, compression, dns.Compress)
|
||||
off, ok = PackRR(answer[i], msg, off, compression, dns.Compress)
|
||||
}
|
||||
for i := 0; i < len(ns); i++ {
|
||||
off, ok = packRR(ns[i], msg, off, compression, dns.Compress)
|
||||
off, ok = PackRR(ns[i], msg, off, compression, dns.Compress)
|
||||
}
|
||||
for i := 0; i < len(extra); i++ {
|
||||
off, ok = packRR(extra[i], msg, off, compression, dns.Compress)
|
||||
off, ok = PackRR(extra[i], msg, off, compression, dns.Compress)
|
||||
}
|
||||
if !ok {
|
||||
return nil, false
|
||||
|
@ -1239,7 +1239,7 @@ func (dns *Msg) Unpack(msg []byte) bool {
|
|||
var dh Header
|
||||
off := 0
|
||||
var ok bool
|
||||
if off, ok = unpackStruct(&dh, msg, off); !ok {
|
||||
if off, ok = UnpackStruct(&dh, msg, off); !ok {
|
||||
return false
|
||||
}
|
||||
dns.Id = dh.Id
|
||||
|
@ -1261,16 +1261,16 @@ func (dns *Msg) Unpack(msg []byte) bool {
|
|||
dns.Extra = make([]RR, dh.Arcount)
|
||||
|
||||
for i := 0; i < len(dns.Question); i++ {
|
||||
off, ok = unpackStruct(&dns.Question[i], msg, off)
|
||||
off, ok = UnpackStruct(&dns.Question[i], msg, off)
|
||||
}
|
||||
for i := 0; i < len(dns.Answer); i++ {
|
||||
dns.Answer[i], off, ok = unpackRR(msg, off)
|
||||
dns.Answer[i], off, ok = UnpackRR(msg, off)
|
||||
}
|
||||
for i := 0; i < len(dns.Ns); i++ {
|
||||
dns.Ns[i], off, ok = unpackRR(msg, off)
|
||||
dns.Ns[i], off, ok = UnpackRR(msg, off)
|
||||
}
|
||||
for i := 0; i < len(dns.Extra); i++ {
|
||||
dns.Extra[i], off, ok = unpackRR(msg, off)
|
||||
dns.Extra[i], off, ok = UnpackRR(msg, off)
|
||||
}
|
||||
if !ok {
|
||||
return false
|
||||
|
|
2
nsecx.go
2
nsecx.go
|
@ -38,7 +38,7 @@ func HashName(label string, ha uint8, iter uint16, salt string) string {
|
|||
saltwire := new(saltWireFmt)
|
||||
saltwire.Salt = salt
|
||||
wire := make([]byte, DefaultMsgSize)
|
||||
n, ok := packStruct(saltwire, wire, 0)
|
||||
n, ok := PackStruct(saltwire, wire, 0)
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
|
|
18
tsig.go
18
tsig.go
|
@ -193,7 +193,7 @@ func TsigGenerate(m *Msg, secret, requestMAC string, timersOnly bool) ([]byte, s
|
|||
t.OrigId = m.MsgHdr.Id
|
||||
|
||||
tbuf := make([]byte, t.Len())
|
||||
if off, ok := packRR(t, tbuf, 0, nil, false); ok {
|
||||
if off, ok := PackRR(t, tbuf, 0, nil, false); ok {
|
||||
tbuf = tbuf[:off] // reset to actual size used
|
||||
} else {
|
||||
return nil, "", ErrPack
|
||||
|
@ -257,7 +257,7 @@ func tsigBuffer(msgbuf []byte, rr *RR_TSIG, requestMAC string, timersOnly bool)
|
|||
m.MACSize = uint16(len(requestMAC) / 2)
|
||||
m.MAC = requestMAC
|
||||
buf = make([]byte, len(requestMAC)) // long enough
|
||||
n, _ := packStruct(m, buf, 0)
|
||||
n, _ := PackStruct(m, buf, 0)
|
||||
buf = buf[:n]
|
||||
}
|
||||
|
||||
|
@ -266,7 +266,7 @@ func tsigBuffer(msgbuf []byte, rr *RR_TSIG, requestMAC string, timersOnly bool)
|
|||
tsig := new(timerWireFmt)
|
||||
tsig.TimeSigned = rr.TimeSigned
|
||||
tsig.Fudge = rr.Fudge
|
||||
n, _ := packStruct(tsig, tsigvar, 0)
|
||||
n, _ := PackStruct(tsig, tsigvar, 0)
|
||||
tsigvar = tsigvar[:n]
|
||||
} else {
|
||||
tsig := new(tsigWireFmt)
|
||||
|
@ -279,7 +279,7 @@ func tsigBuffer(msgbuf []byte, rr *RR_TSIG, requestMAC string, timersOnly bool)
|
|||
tsig.Error = rr.Error
|
||||
tsig.OtherLen = rr.OtherLen
|
||||
tsig.OtherData = rr.OtherData
|
||||
n, _ := packStruct(tsig, tsigvar, 0)
|
||||
n, _ := PackStruct(tsig, tsigvar, 0)
|
||||
tsigvar = tsigvar[:n]
|
||||
}
|
||||
|
||||
|
@ -302,7 +302,7 @@ func stripTsig(msg []byte) ([]byte, *RR_TSIG, error) {
|
|||
off := 0
|
||||
tsigoff := 0
|
||||
var ok bool
|
||||
if off, ok = unpackStruct(&dh, msg, off); !ok {
|
||||
if off, ok = UnpackStruct(&dh, msg, off); !ok {
|
||||
return nil, nil, ErrUnpack
|
||||
}
|
||||
if dh.Arcount == 0 {
|
||||
|
@ -320,17 +320,17 @@ func stripTsig(msg []byte) ([]byte, *RR_TSIG, error) {
|
|||
dns.Extra = make([]RR, dh.Arcount)
|
||||
|
||||
for i := 0; i < len(dns.Question); i++ {
|
||||
off, ok = unpackStruct(&dns.Question[i], msg, off)
|
||||
off, ok = UnpackStruct(&dns.Question[i], msg, off)
|
||||
}
|
||||
for i := 0; i < len(dns.Answer); i++ {
|
||||
dns.Answer[i], off, ok = unpackRR(msg, off)
|
||||
dns.Answer[i], off, ok = UnpackRR(msg, off)
|
||||
}
|
||||
for i := 0; i < len(dns.Ns); i++ {
|
||||
dns.Ns[i], off, ok = unpackRR(msg, off)
|
||||
dns.Ns[i], off, ok = UnpackRR(msg, off)
|
||||
}
|
||||
for i := 0; i < len(dns.Extra); i++ {
|
||||
tsigoff = off
|
||||
dns.Extra[i], off, ok = unpackRR(msg, off)
|
||||
dns.Extra[i], off, ok = UnpackRR(msg, off)
|
||||
if dns.Extra[i].Header().Rrtype == TypeTSIG {
|
||||
rr = dns.Extra[i].(*RR_TSIG)
|
||||
// Adjust Arcount.
|
||||
|
|
Loading…
Reference in New Issue