forked from luvit/luvit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request luvit#945 from n1tehawk/20170131_resolvebyip
dns: Add the ability to handle numeric addresses
- Loading branch information
Showing
3 changed files
with
26 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ limitations under the License. | |
-- https://github.com/openresty/lua-resty-dns/blob/master/lib/resty/dns/resolver.lua | ||
--[[lit-meta | ||
name = "luvit/dns" | ||
version = "2.0.2" | ||
version = "2.0.3" | ||
dependencies = { | ||
"luvit/[email protected]", | ||
"luvit/[email protected]", | ||
|
@@ -51,6 +51,7 @@ local byte = string.byte | |
local gsub = string.gsub | ||
local sub = string.sub | ||
local format = string.format | ||
local match = string.match | ||
local band = bit.band | ||
local bor = bit.bor | ||
local rshift = bit.rshift | ||
|
@@ -604,6 +605,20 @@ local function parse_response(buf, id, server) | |
end | ||
|
||
local function _query(servers, name, dnsclass, qtype, callback) | ||
|
||
-- Try to resolve IPs directly, without contacting DNS servers | ||
if (qtype == TYPE_A and match(name, "^%d+%.%d+%.%d+%.%d+$")) -- numeric IPv4 | ||
or (qtype == TYPE_AAAA and match(name, "^[:%x]+$")) -- hexadecimal IPv6 | ||
then | ||
-- Answer query 'locally', by passing suitable arguments to the callback | ||
-- function. This reports a single address result, with no (`nil`) name, | ||
-- an empty "server" table and a TTL of 0. | ||
callback(nil, { | ||
{address = name, type = qtype, class = CLASS_IN, server = {}, ttl = 0} | ||
}) | ||
return | ||
end | ||
|
||
local tries, max_tries, server, tcp_iter, udp_iter, get_server_iter | ||
|
||
tries = 1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ return { | |
"luvit/[email protected]", | ||
"luvit/[email protected]", | ||
"luvit/[email protected]", | ||
"luvit/[email protected].2", | ||
"luvit/[email protected].3", | ||
"luvit/[email protected]", | ||
"luvit/[email protected]", | ||
"luvit/[email protected]", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters