Skip to content

Commit 63faafa

Browse files
committed
[dns] try empty search scope
1 parent 720c50b commit 63faafa

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

apicast/src/resty/resolver.lua

+9-15
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ local default_resolver_port = 53
3131
local _M = {
3232
_VERSION = '0.1',
3333
_nameservers = {},
34-
search = {}
34+
search = { '' }
3535
}
3636

3737
local mt = { __index = _M }
@@ -67,7 +67,7 @@ function _M.parse_nameservers(path)
6767

6868
ngx.log(ngx.DEBUG, '/etc/resolv.conf:\n', resolv_conf)
6969

70-
local search = {}
70+
local search = { '' }
7171
local nameservers = { search = search }
7272
local resolver = getenv('RESOLVER')
7373
local domains = match(resolv_conf, 'search%s+([^\n]+)')
@@ -216,18 +216,13 @@ local function lookup(dns, qname, search, options)
216216
ngx.log(ngx.DEBUG, 'host is ip address: ', qname)
217217
answers = { new_answer(qname) }
218218
else
219-
answers, err = dns:query(qname, options)
219+
for i=1, #search do
220+
local query = qname .. '.' .. search[i]
221+
ngx.log(ngx.DEBUG, 'resolver query: ', qname, ' search: ', search[i], ' query: ', query)
222+
answers, err = dns:query(query, options)
220223

221-
if not has_tld(qname) and not have_addresses(answers) then
222-
for i=1, #search do
223-
224-
local query = qname .. '.' .. search[i]
225-
ngx.log(ngx.DEBUG, 'resolver query: ', qname, ' search: ', search[i], ' query: ', query)
226-
answers, err = dns:query(query, options)
227-
228-
if answers and not answers.errcode and #answers > 0 then
229-
break
230-
end
224+
if answers and not answers.errcode and #answers > 0 then
225+
break
231226
end
232227
end
233228
end
@@ -249,8 +244,7 @@ function _M.get_servers(self, qname, opts)
249244
end
250245

251246
local cache = self.cache
252-
local search = self.search or {}
253-
247+
local search = self.search or _M.search
254248

255249
-- TODO: pass proper options to dns resolver (like SRV query type)
256250

docker-compose.yml

+6
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,16 @@ services:
2121
environment:
2222
TEST_NGINX_BINARY: openresty
2323
TEST_NGINX_REDIS_HOST: redis
24+
dns_search:
25+
- example.com
2426
test:
2527
image: ${IMAGE_NAME}
2628
depends_on:
2729
- gateway
2830
entrypoint: ""
2931
dns: 127.0.0.1
32+
dns_search:
33+
- example.com
3034
prove:
3135
image: ${IMAGE_NAME}
3236
user: root
@@ -35,6 +39,8 @@ services:
3539
TEST_NGINX_APICAST_PATH: /opt/app
3640
TEST_NGINX_REDIS_HOST: redis
3741
command: prove
42+
dns_search:
43+
- example.com
3844
depends_on:
3945
- redis
4046
volumes:

0 commit comments

Comments
 (0)