From 17dcb390741aacef72de78b7493d46a6aa4f4187 Mon Sep 17 00:00:00 2001 From: Tom Thorogood Date: Fri, 4 Jan 2019 03:02:22 +1030 Subject: [PATCH] Use (net.IP).Equal in isDuplicate functions (#882) --- duplicate_generate.go | 4 +++- zduplicate.go | 21 +++------------------ 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/duplicate_generate.go b/duplicate_generate.go index 83ac1cf7..26383ac9 100644 --- a/duplicate_generate.go +++ b/duplicate_generate.go @@ -103,7 +103,7 @@ func main() { // For some reason, a and aaaa don't pop up as *types.Slice here (mostly like because the are // *indirectly* defined as a slice in the net package). - if _, ok := st.Field(i).Type().(*types.Slice); ok || st.Tag(i) == `dns:"a"` || st.Tag(i) == `dns:"aaaa"` { + if _, ok := st.Field(i).Type().(*types.Slice); ok { o2("if len(r1.%s) != len(r2.%s) {\nreturn false\n}") if st.Tag(i) == `dns:"cdomain-name"` || st.Tag(i) == `dns:"domain-name"` { @@ -128,6 +128,8 @@ func main() { switch st.Tag(i) { case `dns:"-"`: // ignored + case `dns:"a"`, `dns:"aaaa"`: + o2("if !r1.%s.Equal(r2.%s) {\nreturn false\n}") case `dns:"cdomain-name"`, `dns:"domain-name"`: o2("if !isDulicateName(r1.%s, r2.%s) {\nreturn false\n}") default: diff --git a/zduplicate.go b/zduplicate.go index 44b98906..88523ccd 100644 --- a/zduplicate.go +++ b/zduplicate.go @@ -138,26 +138,16 @@ func isDuplicateRdata(r1, r2 RR) bool { // isDuplicate() functions func isDuplicateA(r1, r2 *A) bool { - if len(r1.A) != len(r2.A) { + if !r1.A.Equal(r2.A) { return false } - for i := 0; i < len(r1.A); i++ { - if r1.A[i] != r2.A[i] { - return false - } - } return true } func isDuplicateAAAA(r1, r2 *AAAA) bool { - if len(r1.AAAA) != len(r2.AAAA) { + if !r1.AAAA.Equal(r2.AAAA) { return false } - for i := 0; i < len(r1.AAAA); i++ { - if r1.AAAA[i] != r2.AAAA[i] { - return false - } - } return true } @@ -375,14 +365,9 @@ func isDuplicateL32(r1, r2 *L32) bool { if r1.Preference != r2.Preference { return false } - if len(r1.Locator32) != len(r2.Locator32) { + if !r1.Locator32.Equal(r2.Locator32) { return false } - for i := 0; i < len(r1.Locator32); i++ { - if r1.Locator32[i] != r2.Locator32[i] { - return false - } - } return true }