all: fix LAN hostname checking condition

The LAN hostname in question is FQDN, "." suffix must be trimmed before
checking.

While at it, also add tests for LAN/PTR query checking functions.
This commit is contained in:
Cuong Manh Le
2023-12-04 18:39:02 +07:00
committed by Cuong Manh Le
parent f9a3f4c045
commit 5897c174d3
5 changed files with 81 additions and 3 deletions
+5 -3
View File
@@ -806,6 +806,7 @@ func isPrivatePtrLookup(m *dns.Msg) bool {
return false
}
// isLanHostnameQuery reports whether DNS message is an A/AAAA query with LAN hostname.
func isLanHostnameQuery(m *dns.Msg) bool {
if m == nil || len(m.Question) == 0 {
return false
@@ -816,7 +817,8 @@ func isLanHostnameQuery(m *dns.Msg) bool {
default:
return false
}
return !strings.Contains(q.Name, ".") ||
strings.HasSuffix(q.Name, ".domain") ||
strings.HasSuffix(q.Name, ".lan")
name := strings.TrimSuffix(q.Name, ".")
return !strings.Contains(name, ".") ||
strings.HasSuffix(name, ".domain") ||
strings.HasSuffix(name, ".lan")
}