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