duplicate.go 953 B

12345678910111213141516171819202122232425262728293031323334353637
  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. Returns true
  5. // if so, otherwise false. It's a protocol violation to have identical RRs in a message.
  6. func IsDuplicate(r1, r2 RR) bool {
  7. // Check whether the record header is identical.
  8. if !r1.Header().isDuplicate(r2.Header()) {
  9. return false
  10. }
  11. // Check whether the RDATA is identical.
  12. return r1.isDuplicate(r2)
  13. }
  14. func (r1 *RR_Header) isDuplicate(_r2 RR) bool {
  15. r2, ok := _r2.(*RR_Header)
  16. if !ok {
  17. return false
  18. }
  19. if r1.Class != r2.Class {
  20. return false
  21. }
  22. if r1.Rrtype != r2.Rrtype {
  23. return false
  24. }
  25. if !isDuplicateName(r1.Name, r2.Name) {
  26. return false
  27. }
  28. // ignore TTL
  29. return true
  30. }
  31. // isDuplicateName checks if the domain names s1 and s2 are equal.
  32. func isDuplicateName(s1, s2 string) bool { return equal(s1, s2) }