plugin/hosts: add wildcard support (#8185)

* plugin/hosts: add wildcard support for owner names

Signed-off-by: youknowforsearch <amirhebrahimzader@gmail.com>

* plugin/hosts: document wildcard owner name support

Signed-off-by: youknowforsearch <amirhebrahimzader@gmail.com>

* plugin/hosts: remove unused lookupStaticHost

Signed-off-by: Amirhossein Ebrahimzade <amirhossein.e@smartech.ir>

---------

Signed-off-by: youknowforsearch <amirhebrahimzader@gmail.com>
Signed-off-by: Amirhossein Ebrahimzade <amirhossein.e@smartech.ir>
Co-authored-by: Amirhossein Ebrahimzade <amirhossein.e@smartech.ir>
This commit is contained in:
Amirhossein Ebrahimzade
2026-06-25 08:38:08 +03:30
committed by GitHub
parent e45ad5f87a
commit 6805f6f8a0
5 changed files with 174 additions and 24 deletions

18
plugin/hosts/wildcard.go Normal file
View File

@@ -0,0 +1,18 @@
package hosts
import "github.com/miekg/dns"
// isWildcardName reports whether name is a wildcard owner name (*.example.com.).
func isWildcardName(name string) bool {
return len(name) >= 2 && name[0] == '*' && name[1] == '.'
}
// replaceWithAsteriskLabel replaces the leftmost label with '*'.
func replaceWithAsteriskLabel(qname string) string {
i, shot := dns.NextLabel(qname, 0)
if shot {
return ""
}
return "*." + qname[i:]
}