Make the IsTsig and IsEdn0 more usefull by returning the record
This commit is contained in:
parent
2df0407ffe
commit
68961f2f5b
|
@ -164,8 +164,8 @@ func (w *reply) receive() (*Msg, error) {
|
|||
}
|
||||
w.rtt = time.Since(w.t)
|
||||
m.Size = n
|
||||
if m.IsTsig() {
|
||||
secret := m.Extra[len(m.Extra)-1].(*RR_TSIG).Hdr.Name
|
||||
if t := m.IsTsig(); t != nil {
|
||||
secret := t.Hdr.Name
|
||||
if _, ok := w.client.TsigSecret[secret]; !ok {
|
||||
w.tsigStatus = ErrSecret
|
||||
return m, nil
|
||||
|
@ -249,9 +249,9 @@ func (w *reply) readClient(p []byte) (n int, err error) {
|
|||
// signature is calculated.
|
||||
func (w *reply) send(m *Msg) (err error) {
|
||||
var out []byte
|
||||
if m.IsTsig() {
|
||||
if t := m.IsTsig(); t != nil {
|
||||
mac := ""
|
||||
name := m.Extra[len(m.Extra)-1].(*RR_TSIG).Hdr.Name
|
||||
name := t.Hdr.Name
|
||||
if _, ok := w.client.TsigSecret[name]; !ok {
|
||||
return ErrSecret
|
||||
}
|
||||
|
|
19
defaults.go
19
defaults.go
|
@ -196,23 +196,26 @@ func (dns *Msg) IsIxfr() (ok bool) {
|
|||
}
|
||||
|
||||
// IsTsig checks if the message has a TSIG record as the last record
|
||||
// in the additional section.
|
||||
func (dns *Msg) IsTsig() (ok bool) {
|
||||
// in the additional section. It returns the TSIG record found or nil.
|
||||
func (dns *Msg) IsTsig() *RR_TSIG {
|
||||
if len(dns.Extra) > 0 {
|
||||
return dns.Extra[len(dns.Extra)-1].Header().Rrtype == TypeTSIG
|
||||
if dns.Extra[len(dns.Extra)-1].Header().Rrtype == TypeTSIG {
|
||||
return dns.Extra[len(dns.Extra)-1].(*RR_TSIG)
|
||||
}
|
||||
}
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
// IsEdns0 checks if the message has a EDNS0 (OPT) record, any EDNS0
|
||||
// record in the additional section will do.
|
||||
func (dns *Msg) IsEdns0() (ok bool) {
|
||||
// record in the additional section will do. It returns the OPT record
|
||||
// found or nil.
|
||||
func (dns *Msg) IsEdns0() *RR_OPT {
|
||||
for _, r := range dns.Extra {
|
||||
if r.Header().Rrtype == TypeOPT {
|
||||
return true
|
||||
return r.(*RR_OPT)
|
||||
}
|
||||
}
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
// IsDomainName checks if s is a valid domainname, it returns
|
||||
|
|
|
@ -330,8 +330,8 @@ func (c *conn) serve() {
|
|||
}
|
||||
|
||||
w.tsigStatus = nil
|
||||
if req.IsTsig() {
|
||||
secret := req.Extra[len(req.Extra)-1].(*RR_TSIG).Hdr.Name
|
||||
if t := req.IsTsig(); t != nil {
|
||||
secret := t.Hdr.Name
|
||||
if _, ok := w.conn.tsigSecret[secret]; !ok {
|
||||
w.tsigStatus = ErrKeyAlg
|
||||
}
|
||||
|
@ -360,8 +360,8 @@ func (w *response) Write(m *Msg) (err error) {
|
|||
if m == nil {
|
||||
return &Error{Err: "nil message"}
|
||||
}
|
||||
if m.IsTsig() {
|
||||
data, w.tsigRequestMAC, err = TsigGenerate(m, w.conn.tsigSecret[m.Extra[len(m.Extra)-1].(*RR_TSIG).Hdr.Name], w.tsigRequestMAC, w.tsigTimersOnly)
|
||||
if t := m.IsTsig(); t != nil {
|
||||
data, w.tsigRequestMAC, err = TsigGenerate(m, w.conn.tsigSecret[t.Hdr.Name], w.tsigRequestMAC, w.tsigTimersOnly)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
2
tsig.go
2
tsig.go
|
@ -154,7 +154,7 @@ type timerWireFmt struct {
|
|||
// timersOnly is false.
|
||||
// If something goes wrong an error is returned, otherwise it is nil.
|
||||
func TsigGenerate(m *Msg, secret, requestMAC string, timersOnly bool) ([]byte, string, error) {
|
||||
if !m.IsTsig() {
|
||||
if m.IsTsig() == nil {
|
||||
panic("TSIG not last RR in additional")
|
||||
}
|
||||
// If we barf here, the caller is to blame
|
||||
|
|
Loading…
Reference in New Issue