Comments (6)
local answers, err, tries = r:query(host_name, { qtype = r.TYPE_A })
the answers also have some cname (type:5) value....
from lua-resty-dns.
local ans, err = r:tcp_query(host, { qtype = TYPE_A })
if not ans then
ngx.log(ngx.ERR, "got an error on query: ", err)
return ngx.exit(ngx.HTTP_GATEWAY_TIMEOUT)
end
for k,answer in pairs(ans) do
return answer.address
end
from lua-resty-dns.
local ans, err = r:tcp_query(host, { qtype = TYPE_A }) if not ans then ngx.log(ngx.ERR, "got an error on query: ", err) return ngx.exit(ngx.HTTP_GATEWAY_TIMEOUT) end for k,answer in pairs(ans) do return answer.address end
Three questions:
- Should it be
TYPE_A
orr.TYPE_A
? Which one is correct? - Is changing
r.TYPE_A
toTYPE_A
exactly the change that turns this piece of code from non-working to working? - If 2. is true, does it mean that
TYPE_A
is a global constant andr.TYPE_A
is nil, which is why{ qtype = r.TYPE_A }
is effectively{}
?
from lua-resty-dns.
@rulatir No, when I wrote it I made a mistake, there must be r.TYPE_A
this is 100% working code with checks for return ipv4 or ipv6 depends on which version the connection was made from
local r, err = resolver:new{
nameservers = something
retrans = 5,
timeout = 5000,
no_recurse = true
}
if not r then
ngx.log(ngx.ERR, "resolver communicate error: ", err)
return
end
local qtype
if checkIfIpv4(ngx.var.remote_addr) then -- check from what version of IPv we get the request
qtype = r.TYPE_A
else
qtype = r.TYPE_AAAA
end
local ans, err = r:tcp_query(host, { qtype = qtype })
if not ans then
ngx.log(ngx.ERR, "got an error on query: ", err)
return ngx.exit(ngx.HTTP_BAD_GATEWAY) --or something else
end
if ans.errcode ~= nil then -- check if we get errcode in ans query
return ngx.exit(ngx.HTTP_BAD_GATEWAY) --or something else
else
if not next(ans) then -- check for empty ans
ngx.exit(ngx.HTTP_BAD_GATEWAY) --or something else
end
for k,answer in pairs(ans) do -- itr ans-query for get raw IP from ans
if not answer.address then
return ngx.exit(ngx.HTTP_BAD_GATEWAY) -- --or something else
else
return answer.address
end
end
end
checkIfIpv4 func code
local function checkIfIpv4(ip)
if ip == nil or type(ip) ~= "string" then
return false
end
-- check for format 1.11.111.111 for ipv4
local chunks = {ip:match("(%d+)%.(%d+)%.(%d+)%.(%d+)")}
if (#chunks == 4) then
for _,v in pairs(chunks) do
if (tonumber(v) < 0 or tonumber(v) > 255) then
return false
end
end
return true
else
return false
end
end
from lua-resty-dns.
Thanks!
from lua-resty-dns.
@rulatir you're welcome :)
from lua-resty-dns.
Related Issues (20)
- /etc/hosts support? HOT 3
- Getting "failed to set peer name: resource temporarily unavailable" when using the module
- How does the module process for cache? HOT 2
- add "nameservers" to docs HOT 1
- the TCP client does not do any retries ('retrans' option) HOT 3
- dead resolver raises exception HOT 2
- how does the r:query parameter option:qtype? HOT 4
- is it possible to cache the answers for 15 secs? HOT 2
- Test case failing on rhel 7.6 ppc64le platform HOT 1
- domain name resolution on pure ipv6 kubernetes HOT 1
- 域名解析报错 code=3
- How to get the fixed TTL?
- wire format HOT 5
- Return domain name by ip address HOT 1
- Error doing NS query
- tcp_sock is closed after tcp_query
- Use EDNS
- Does it support access via proxy?
- DNS ERROR HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lua-resty-dns.