duplicate.go 955 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package dns
  2. //go:generate go run duplicate_generate.go
  3. // IsDuplicate checks of r1 and r2 are duplicates of each other, excluding the TTL.
  4. // So this means the header data is equal *and* the RDATA is the same. Return true
  5. // is so, otherwise false.
  6. // It's a protocol violation to have identical RRs in a message.
  7. func IsDuplicate(r1, r2 RR) bool {
  8. // Check whether the record header is identical.
  9. if !r1.Header().isDuplicate(r2.Header()) {
  10. return false
  11. }
  12. // Check whether the RDATA is identical.
  13. return r1.isDuplicate(r2)
  14. }
  15. func (r1 *RR_Header) isDuplicate(_r2 RR) bool {
  16. r2, ok := _r2.(*RR_Header)
  17. if !ok {
  18. return false
  19. }
  20. if r1.Class != r2.Class {
  21. return false
  22. }
  23. if r1.Rrtype != r2.Rrtype {
  24. return false
  25. }
  26. if !isDuplicateName(r1.Name, r2.Name) {
  27. return false
  28. }
  29. // ignore TTL
  30. return true
  31. }
  32. // isDuplicateName checks if the domain names s1 and s2 are equal.
  33. func isDuplicateName(s1, s2 string) bool { return equal(s1, s2) }