Skip to content

Commit

Permalink
Merge pull request #338 from miekg/edns-fix
Browse files Browse the repository at this point in the history
Optimize IsEdns0
  • Loading branch information
miekg committed Apr 9, 2016
2 parents 7e024ce + 51f75ca commit c70f867
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,13 @@ func (dns *Msg) IsTsig() *TSIG {
// record in the additional section will do. It returns the OPT record
// found or nil.
func (dns *Msg) IsEdns0() *OPT {
for _, r := range dns.Extra {
if r.Header().Rrtype == TypeOPT {
return r.(*OPT)
// EDNS0 is at the end of the additional section, start there.
// We might want to change this to *only* look at the last two
// records. So we see TSIG and/or OPT - this a slightly bigger
// change though.
for i := len(dns.Extra) - 1; i >= 0; i-- {
if dns.Extra[i].Header().Rrtype == TypeOPT {
return dns.Extra[i].(*OPT)
}
}
return nil
Expand Down

0 comments on commit c70f867

Please sign in to comment.