summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2023-03-26 13:08:31 +0700
committerShulhan <ms@kilabit.info>2023-03-26 13:45:53 +0700
commitd9f275710016bb09cbdc8a973344401749e7d11b (patch)
tree1005bde1af31a9844a7674bcbddec060b4b19019
parent3fe8e4bcbc3e450a8bc7f35148e5860ce84311da (diff)
downloadpakakeh.go-d9f275710016bb09cbdc8a973344401749e7d11b.tar.xz
lib/net: changes the PopulateQuery logic
Previously, PopulateQuery only add the passed dname if the number of dots is greater than 0. After inspecting the result from dig and getenv, the dots seems does not affect the query. For example, if we have A record for domain "kilabit", both of those tools query name "kilabit" without adding local domain or domain in search.
-rw-r--r--lib/net/resolvconf.go14
-rw-r--r--lib/net/resolvconf_example_test.go5
2 files changed, 10 insertions, 9 deletions
diff --git a/lib/net/resolvconf.go b/lib/net/resolvconf.go
index 052e3e86..faf12c50 100644
--- a/lib/net/resolvconf.go
+++ b/lib/net/resolvconf.go
@@ -326,8 +326,10 @@ func (rc *ResolvConf) sanitize() {
}
// PopulateQuery given a domain name to be resolved, generate list of names
-// to be queried based on registered Domain and Search in the resolv.conf.
-// The dname itself will be on top of the list if its contains any dot.
+// to be queried based on registered Search in the resolv.conf.
+// The dname itself will be on top of the list.
+// If the number of dots in dname less than NDots then each Search domain will
+// be appended as suffix and added to the list.
func (rc *ResolvConf) PopulateQuery(dname string) (queries []string) {
var (
s string
@@ -342,11 +344,9 @@ func (rc *ResolvConf) PopulateQuery(dname string) (queries []string) {
}
}
- if ndots > 0 {
- queries = append(queries, dname)
- }
- if len(rc.Domain) > 0 {
- queries = append(queries, dname+"."+rc.Domain)
+ queries = append(queries, dname)
+ if ndots >= rc.NDots {
+ return queries
}
for _, s = range rc.Search {
queries = append(queries, dname+"."+s)
diff --git a/lib/net/resolvconf_example_test.go b/lib/net/resolvconf_example_test.go
index e2cd341f..a3e8cb6e 100644
--- a/lib/net/resolvconf_example_test.go
+++ b/lib/net/resolvconf_example_test.go
@@ -11,6 +11,7 @@ func ExampleResolvConf_PopulateQuery() {
resconf = &ResolvConf{
Domain: "internal",
Search: []string{"my.internal"},
+ NDots: 1,
}
queries []string
)
@@ -20,6 +21,6 @@ func ExampleResolvConf_PopulateQuery() {
queries = resconf.PopulateQuery("a.machine")
fmt.Println(queries)
//Output:
- //[vpn.internal vpn.my.internal]
- //[a.machine a.machine.internal a.machine.my.internal]
+ //[vpn vpn.my.internal]
+ //[a.machine]
}