Mercurial > prosody-hg
annotate net/dns.lua @ 14216:2ec517d8d43e
net.unbound: Enable DNSSEC by default with option for turning off
You know what they say about opt-in security.
Enabling DNSSEC in libunbound without a way to turn it off would likely
be a problem for those whose DNS resolvers do not support, or outright
block DNSSEC. The merge algorithm already in place here doesn't have a
way to unset something, so instead a simpler boolean setting is
introduced, similar to some existing ones like use_ipv6/4 and use_dane.
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sun, 07 Jun 2026 20:32:55 +0200 |
| parents | d649d011df45 |
| children |
| rev | line source |
|---|---|
|
1523
841d61be198f
Remove version number from copyright headers
Matthew Wild <mwild1@gmail.com>
parents:
1202
diff
changeset
|
1 -- Prosody IM |
| 615 | 2 -- This file is included with Prosody IM. It has modifications, |
| 3 -- which are hereby placed in the public domain. | |
| 337 | 4 |
| 5 | |
| 6 -- todo: quick (default) header generation | |
| 7 -- todo: nxdomain, error handling | |
| 8 -- todo: cache results of encodeName | |
| 9 | |
| 10 | |
|
12604
bd9e006a7a74
various: Update IETF RFC URLs for tools.ietf.org transition
Kim Alvefur <zash@zash.se>
parents:
12387
diff
changeset
|
11 -- reference: https://www.rfc-editor.org/rfc/rfc1035.html |
|
bd9e006a7a74
various: Update IETF RFC URLs for tools.ietf.org transition
Kim Alvefur <zash@zash.se>
parents:
12387
diff
changeset
|
12 -- reference: https://www.rfc-editor.org/rfc/rfc1876.html (LOC) |
| 337 | 13 |
| 14 | |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
15 local socket = require "socket"; |
|
12974
ba409c67353b
net: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12604
diff
changeset
|
16 local have_timer, timer = pcall(require, "prosody.util.timer"); |
|
ba409c67353b
net: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12604
diff
changeset
|
17 local new_ip = require "prosody.util.ip".new_ip; |
|
ba409c67353b
net: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12604
diff
changeset
|
18 local have_util_net, util_net = pcall(require, "prosody.util.net"); |
|
14078
d649d011df45
Use util.time.now() consistently instead of socket.gettime()
Link Mauve <linkmauve@linkmauve.fr>
parents:
13925
diff
changeset
|
19 local time_now = require "prosody.util.time".now; |
|
3324
070c8ba71b76
net.dns: Handle our own timeouts, including falling onto other servers in resolv.conf if necessary
Matthew Wild <mwild1@gmail.com>
parents:
3057
diff
changeset
|
20 |
|
12974
ba409c67353b
net: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12604
diff
changeset
|
21 local log = require "prosody.util.logger".init("dns"); |
|
10955
7bcfac630b65
net.dns: Add some debug logging
Matthew Wild <mwild1@gmail.com>
parents:
10664
diff
changeset
|
22 |
|
12974
ba409c67353b
net: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12604
diff
changeset
|
23 local _, windows = pcall(require, "prosody.util.windows"); |
|
2067
0ed6369605bf
net.dns: Updated to use util.windows.get_nameservers for enumerating nameservers on Windows.
Waqas Hussain <waqas20@gmail.com>
parents:
2027
diff
changeset
|
24 local is_windows = (_ and windows) or os.getenv("WINDIR"); |
| 337 | 25 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
26 local coroutine, io, math, string, table = |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
27 coroutine, io, math, string, table; |
| 337 | 28 |
|
7527
936b78e9f399
net.dns: remove unused variable unpack [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents:
7500
diff
changeset
|
29 local ipairs, next, pairs, print, setmetatable, tostring, assert, error, select, type = |
|
936b78e9f399
net.dns: remove unused variable unpack [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents:
7500
diff
changeset
|
30 ipairs, next, pairs, print, setmetatable, tostring, assert, error, select, type; |
|
3719
0f87632b87e9
net.dns: Removed dependency on util.ztact by moving ztact.get/set in.
Waqas Hussain <waqas20@gmail.com>
parents:
3544
diff
changeset
|
31 |
|
0f87632b87e9
net.dns: Removed dependency on util.ztact by moving ztact.get/set in.
Waqas Hussain <waqas20@gmail.com>
parents:
3544
diff
changeset
|
32 local ztact = { -- public domain 20080404 lua@ztact.com |
|
0f87632b87e9
net.dns: Removed dependency on util.ztact by moving ztact.get/set in.
Waqas Hussain <waqas20@gmail.com>
parents:
3544
diff
changeset
|
33 get = function(parent, ...) |
|
0f87632b87e9
net.dns: Removed dependency on util.ztact by moving ztact.get/set in.
Waqas Hussain <waqas20@gmail.com>
parents:
3544
diff
changeset
|
34 local len = select('#', ...); |
|
0f87632b87e9
net.dns: Removed dependency on util.ztact by moving ztact.get/set in.
Waqas Hussain <waqas20@gmail.com>
parents:
3544
diff
changeset
|
35 for i=1,len do |
|
0f87632b87e9
net.dns: Removed dependency on util.ztact by moving ztact.get/set in.
Waqas Hussain <waqas20@gmail.com>
parents:
3544
diff
changeset
|
36 parent = parent[select(i, ...)]; |
|
0f87632b87e9
net.dns: Removed dependency on util.ztact by moving ztact.get/set in.
Waqas Hussain <waqas20@gmail.com>
parents:
3544
diff
changeset
|
37 if parent == nil then break; end |
|
0f87632b87e9
net.dns: Removed dependency on util.ztact by moving ztact.get/set in.
Waqas Hussain <waqas20@gmail.com>
parents:
3544
diff
changeset
|
38 end |
|
0f87632b87e9
net.dns: Removed dependency on util.ztact by moving ztact.get/set in.
Waqas Hussain <waqas20@gmail.com>
parents:
3544
diff
changeset
|
39 return parent; |
|
0f87632b87e9
net.dns: Removed dependency on util.ztact by moving ztact.get/set in.
Waqas Hussain <waqas20@gmail.com>
parents:
3544
diff
changeset
|
40 end; |
|
0f87632b87e9
net.dns: Removed dependency on util.ztact by moving ztact.get/set in.
Waqas Hussain <waqas20@gmail.com>
parents:
3544
diff
changeset
|
41 set = function(parent, ...) |
|
0f87632b87e9
net.dns: Removed dependency on util.ztact by moving ztact.get/set in.
Waqas Hussain <waqas20@gmail.com>
parents:
3544
diff
changeset
|
42 local len = select('#', ...); |
|
0f87632b87e9
net.dns: Removed dependency on util.ztact by moving ztact.get/set in.
Waqas Hussain <waqas20@gmail.com>
parents:
3544
diff
changeset
|
43 local key, value = select(len-1, ...); |
|
0f87632b87e9
net.dns: Removed dependency on util.ztact by moving ztact.get/set in.
Waqas Hussain <waqas20@gmail.com>
parents:
3544
diff
changeset
|
44 local cutpoint, cutkey; |
|
0f87632b87e9
net.dns: Removed dependency on util.ztact by moving ztact.get/set in.
Waqas Hussain <waqas20@gmail.com>
parents:
3544
diff
changeset
|
45 |
|
0f87632b87e9
net.dns: Removed dependency on util.ztact by moving ztact.get/set in.
Waqas Hussain <waqas20@gmail.com>
parents:
3544
diff
changeset
|
46 for i=1,len-2 do |
|
0f87632b87e9
net.dns: Removed dependency on util.ztact by moving ztact.get/set in.
Waqas Hussain <waqas20@gmail.com>
parents:
3544
diff
changeset
|
47 local key = select (i, ...) |
|
0f87632b87e9
net.dns: Removed dependency on util.ztact by moving ztact.get/set in.
Waqas Hussain <waqas20@gmail.com>
parents:
3544
diff
changeset
|
48 local child = parent[key] |
| 337 | 49 |
|
3719
0f87632b87e9
net.dns: Removed dependency on util.ztact by moving ztact.get/set in.
Waqas Hussain <waqas20@gmail.com>
parents:
3544
diff
changeset
|
50 if value == nil then |
|
0f87632b87e9
net.dns: Removed dependency on util.ztact by moving ztact.get/set in.
Waqas Hussain <waqas20@gmail.com>
parents:
3544
diff
changeset
|
51 if child == nil then |
|
0f87632b87e9
net.dns: Removed dependency on util.ztact by moving ztact.get/set in.
Waqas Hussain <waqas20@gmail.com>
parents:
3544
diff
changeset
|
52 return; |
|
0f87632b87e9
net.dns: Removed dependency on util.ztact by moving ztact.get/set in.
Waqas Hussain <waqas20@gmail.com>
parents:
3544
diff
changeset
|
53 elseif next(child, next(child)) then |
|
0f87632b87e9
net.dns: Removed dependency on util.ztact by moving ztact.get/set in.
Waqas Hussain <waqas20@gmail.com>
parents:
3544
diff
changeset
|
54 cutpoint = nil; cutkey = nil; |
|
0f87632b87e9
net.dns: Removed dependency on util.ztact by moving ztact.get/set in.
Waqas Hussain <waqas20@gmail.com>
parents:
3544
diff
changeset
|
55 elseif cutpoint == nil then |
|
0f87632b87e9
net.dns: Removed dependency on util.ztact by moving ztact.get/set in.
Waqas Hussain <waqas20@gmail.com>
parents:
3544
diff
changeset
|
56 cutpoint = parent; cutkey = key; |
|
0f87632b87e9
net.dns: Removed dependency on util.ztact by moving ztact.get/set in.
Waqas Hussain <waqas20@gmail.com>
parents:
3544
diff
changeset
|
57 end |
|
0f87632b87e9
net.dns: Removed dependency on util.ztact by moving ztact.get/set in.
Waqas Hussain <waqas20@gmail.com>
parents:
3544
diff
changeset
|
58 elseif child == nil then |
|
0f87632b87e9
net.dns: Removed dependency on util.ztact by moving ztact.get/set in.
Waqas Hussain <waqas20@gmail.com>
parents:
3544
diff
changeset
|
59 child = {}; |
|
0f87632b87e9
net.dns: Removed dependency on util.ztact by moving ztact.get/set in.
Waqas Hussain <waqas20@gmail.com>
parents:
3544
diff
changeset
|
60 parent[key] = child; |
|
0f87632b87e9
net.dns: Removed dependency on util.ztact by moving ztact.get/set in.
Waqas Hussain <waqas20@gmail.com>
parents:
3544
diff
changeset
|
61 end |
|
0f87632b87e9
net.dns: Removed dependency on util.ztact by moving ztact.get/set in.
Waqas Hussain <waqas20@gmail.com>
parents:
3544
diff
changeset
|
62 parent = child |
|
0f87632b87e9
net.dns: Removed dependency on util.ztact by moving ztact.get/set in.
Waqas Hussain <waqas20@gmail.com>
parents:
3544
diff
changeset
|
63 end |
|
0f87632b87e9
net.dns: Removed dependency on util.ztact by moving ztact.get/set in.
Waqas Hussain <waqas20@gmail.com>
parents:
3544
diff
changeset
|
64 |
|
0f87632b87e9
net.dns: Removed dependency on util.ztact by moving ztact.get/set in.
Waqas Hussain <waqas20@gmail.com>
parents:
3544
diff
changeset
|
65 if value == nil and cutpoint then |
|
0f87632b87e9
net.dns: Removed dependency on util.ztact by moving ztact.get/set in.
Waqas Hussain <waqas20@gmail.com>
parents:
3544
diff
changeset
|
66 cutpoint[cutkey] = nil; |
|
0f87632b87e9
net.dns: Removed dependency on util.ztact by moving ztact.get/set in.
Waqas Hussain <waqas20@gmail.com>
parents:
3544
diff
changeset
|
67 else |
|
0f87632b87e9
net.dns: Removed dependency on util.ztact by moving ztact.get/set in.
Waqas Hussain <waqas20@gmail.com>
parents:
3544
diff
changeset
|
68 parent[key] = value; |
|
0f87632b87e9
net.dns: Removed dependency on util.ztact by moving ztact.get/set in.
Waqas Hussain <waqas20@gmail.com>
parents:
3544
diff
changeset
|
69 return value; |
|
0f87632b87e9
net.dns: Removed dependency on util.ztact by moving ztact.get/set in.
Waqas Hussain <waqas20@gmail.com>
parents:
3544
diff
changeset
|
70 end |
|
0f87632b87e9
net.dns: Removed dependency on util.ztact by moving ztact.get/set in.
Waqas Hussain <waqas20@gmail.com>
parents:
3544
diff
changeset
|
71 end; |
|
0f87632b87e9
net.dns: Removed dependency on util.ztact by moving ztact.get/set in.
Waqas Hussain <waqas20@gmail.com>
parents:
3544
diff
changeset
|
72 }; |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
73 local get, set = ztact.get, ztact.set; |
| 337 | 74 |
|
10959
877ceb4feb6d
net.dns: Reduce default timeout to 5s
Matthew Wild <mwild1@gmail.com>
parents:
10958
diff
changeset
|
75 local default_timeout = 5; |
|
10957
8902cecbdd39
net.dns: Add jitter to spread queries and reduce failures due to congestion
Matthew Wild <mwild1@gmail.com>
parents:
10956
diff
changeset
|
76 local default_jitter = 1; |
|
8902cecbdd39
net.dns: Add jitter to spread queries and reduce failures due to congestion
Matthew Wild <mwild1@gmail.com>
parents:
10956
diff
changeset
|
77 local default_retry_jitter = 2; |
| 337 | 78 |
| 79 -------------------------------------------------- module dns | |
|
6780
647adfd8f738
net.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents:
6753
diff
changeset
|
80 local _ENV = nil; |
|
8555
4f0f5b49bb03
vairious: Add annotation when an empty environment is set [luacheck]
Kim Alvefur <zash@zash.se>
parents:
8440
diff
changeset
|
81 -- luacheck: std none |
|
6780
647adfd8f738
net.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents:
6753
diff
changeset
|
82 local dns = {}; |
| 337 | 83 |
| 84 | |
| 85 -- dns type & class codes ------------------------------ dns type & class codes | |
| 86 | |
| 87 | |
| 88 local append = table.insert | |
| 89 | |
| 90 | |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
91 local function highbyte(i) -- - - - - - - - - - - - - - - - - - - highbyte |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
92 return (i-(i%0x100))/0x100; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
93 end |
| 337 | 94 |
| 95 | |
|
8908
144666d0ad2f
net.dns: Lazily generate unknown RR type names
Kim Alvefur <zash@zash.se>
parents:
8907
diff
changeset
|
96 local function augment (t, prefix) -- - - - - - - - - - - - - - - - - augment |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
97 local a = {}; |
|
8907
b7b960d30eef
Backed out changeset eae606b9266c: Used a lot of memory
Kim Alvefur <zash@zash.se>
parents:
8901
diff
changeset
|
98 for i,s in pairs(t) do |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
99 a[i] = s; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
100 a[s] = s; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
101 a[string.lower(s)] = s; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
102 end |
|
8908
144666d0ad2f
net.dns: Lazily generate unknown RR type names
Kim Alvefur <zash@zash.se>
parents:
8907
diff
changeset
|
103 setmetatable(a, { |
|
144666d0ad2f
net.dns: Lazily generate unknown RR type names
Kim Alvefur <zash@zash.se>
parents:
8907
diff
changeset
|
104 __index = function (_, i) |
|
144666d0ad2f
net.dns: Lazily generate unknown RR type names
Kim Alvefur <zash@zash.se>
parents:
8907
diff
changeset
|
105 if type(i) == "number" then |
|
144666d0ad2f
net.dns: Lazily generate unknown RR type names
Kim Alvefur <zash@zash.se>
parents:
8907
diff
changeset
|
106 return ("%s%d"):format(prefix, i); |
|
144666d0ad2f
net.dns: Lazily generate unknown RR type names
Kim Alvefur <zash@zash.se>
parents:
8907
diff
changeset
|
107 elseif type(i) == "string" then |
|
144666d0ad2f
net.dns: Lazily generate unknown RR type names
Kim Alvefur <zash@zash.se>
parents:
8907
diff
changeset
|
108 return i:upper(); |
|
144666d0ad2f
net.dns: Lazily generate unknown RR type names
Kim Alvefur <zash@zash.se>
parents:
8907
diff
changeset
|
109 end |
|
144666d0ad2f
net.dns: Lazily generate unknown RR type names
Kim Alvefur <zash@zash.se>
parents:
8907
diff
changeset
|
110 end; |
|
144666d0ad2f
net.dns: Lazily generate unknown RR type names
Kim Alvefur <zash@zash.se>
parents:
8907
diff
changeset
|
111 }) |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
112 return a; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
113 end |
| 337 | 114 |
| 115 | |
| 116 local function encode (t) -- - - - - - - - - - - - - - - - - - - - - encode | |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
117 local code = {}; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
118 for i,s in pairs(t) do |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
119 local word = string.char(highbyte(i), i%0x100); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
120 code[i] = word; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
121 code[s] = word; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
122 code[string.lower(s)] = word; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
123 end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
124 return code; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
125 end |
| 337 | 126 |
| 127 | |
| 128 dns.types = { | |
|
8903
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
129 [1] = "A", -- a host address,[RFC1035],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
130 [2] = "NS", -- an authoritative name server,[RFC1035],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
131 [3] = "MD", -- a mail destination (OBSOLETE - use MX),[RFC1035],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
132 [4] = "MF", -- a mail forwarder (OBSOLETE - use MX),[RFC1035],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
133 [5] = "CNAME", -- the canonical name for an alias,[RFC1035],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
134 [6] = "SOA", -- marks the start of a zone of authority,[RFC1035],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
135 [7] = "MB", -- a mailbox domain name (EXPERIMENTAL),[RFC1035],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
136 [8] = "MG", -- a mail group member (EXPERIMENTAL),[RFC1035],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
137 [9] = "MR", -- a mail rename domain name (EXPERIMENTAL),[RFC1035],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
138 [10] = "NULL", -- a null RR (EXPERIMENTAL),[RFC1035],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
139 [11] = "WKS", -- a well known service description,[RFC1035],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
140 [12] = "PTR", -- a domain name pointer,[RFC1035],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
141 [13] = "HINFO", -- host information,[RFC1035],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
142 [14] = "MINFO", -- mailbox or mail list information,[RFC1035],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
143 [15] = "MX", -- mail exchange,[RFC1035],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
144 [16] = "TXT", -- text strings,[RFC1035],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
145 [17] = "RP", -- for Responsible Person,[RFC1183],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
146 [18] = "AFSDB", -- for AFS Data Base location,[RFC1183][RFC5864],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
147 [19] = "X25", -- for X.25 PSDN address,[RFC1183],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
148 [20] = "ISDN", -- for ISDN address,[RFC1183],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
149 [21] = "RT", -- for Route Through,[RFC1183],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
150 [22] = "NSAP", -- "for NSAP address, NSAP style A record",[RFC1706],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
151 [23] = "NSAP-PTR", -- "for domain name pointer, NSAP style",[RFC1348][RFC1637][RFC1706],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
152 [24] = "SIG", -- for security signature,[RFC4034][RFC3755][RFC2535][RFC2536][RFC2537][RFC2931][RFC3110][RFC3008],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
153 [25] = "KEY", -- for security key,[RFC4034][RFC3755][RFC2535][RFC2536][RFC2537][RFC2539][RFC3008][RFC3110],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
154 [26] = "PX", -- X.400 mail mapping information,[RFC2163],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
155 [27] = "GPOS", -- Geographical Position,[RFC1712],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
156 [28] = "AAAA", -- IP6 Address,[RFC3596],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
157 [29] = "LOC", -- Location Information,[RFC1876],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
158 [30] = "NXT", -- Next Domain (OBSOLETE),[RFC3755][RFC2535],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
159 [31] = "EID", -- Endpoint Identifier,[Michael_Patton][http://ana-3.lcs.mit.edu/~jnc/nimrod/dns.txt],,1995-06 |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
160 [32] = "NIMLOC", -- Nimrod Locator,[1][Michael_Patton][http://ana-3.lcs.mit.edu/~jnc/nimrod/dns.txt],,1995-06 |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
161 [33] = "SRV", -- Server Selection,[1][RFC2782],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
162 [34] = "ATMA", -- ATM Address,"[ ATM Forum Technical Committee, ""ATM Name System, V2.0"", Doc ID: AF-DANS-0152.000, July 2000. Available from and held in escrow by IANA.]",, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
163 [35] = "NAPTR", -- Naming Authority Pointer,[RFC2915][RFC2168][RFC3403],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
164 [36] = "KX", -- Key Exchanger,[RFC2230],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
165 [37] = "CERT", -- CERT,[RFC4398],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
166 [38] = "A6", -- A6 (OBSOLETE - use AAAA),[RFC3226][RFC2874][RFC6563],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
167 [39] = "DNAME", -- DNAME,[RFC6672],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
168 [40] = "SINK", -- SINK,[Donald_E_Eastlake][http://tools.ietf.org/html/draft-eastlake-kitchen-sink],,1997-11 |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
169 [41] = "OPT", -- OPT,[RFC6891][RFC3225],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
170 [42] = "APL", -- APL,[RFC3123],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
171 [43] = "DS", -- Delegation Signer,[RFC4034][RFC3658],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
172 [44] = "SSHFP", -- SSH Key Fingerprint,[RFC4255],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
173 [45] = "IPSECKEY", -- IPSECKEY,[RFC4025],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
174 [46] = "RRSIG", -- RRSIG,[RFC4034][RFC3755],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
175 [47] = "NSEC", -- NSEC,[RFC4034][RFC3755],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
176 [48] = "DNSKEY", -- DNSKEY,[RFC4034][RFC3755],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
177 [49] = "DHCID", -- DHCID,[RFC4701],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
178 [50] = "NSEC3", -- NSEC3,[RFC5155],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
179 [51] = "NSEC3PARAM", -- NSEC3PARAM,[RFC5155],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
180 [52] = "TLSA", -- TLSA,[RFC6698],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
181 [53] = "SMIMEA", -- S/MIME cert association,[RFC8162],SMIMEA/smimea-completed-template,2015-12-01 |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
182 -- [54] = "Unassigned", -- ,,, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
183 [55] = "HIP", -- Host Identity Protocol,[RFC8005],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
184 [56] = "NINFO", -- NINFO,[Jim_Reid],NINFO/ninfo-completed-template,2008-01-21 |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
185 [57] = "RKEY", -- RKEY,[Jim_Reid],RKEY/rkey-completed-template,2008-01-21 |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
186 [58] = "TALINK", -- Trust Anchor LINK,[Wouter_Wijngaards],TALINK/talink-completed-template,2010-02-17 |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
187 [59] = "CDS", -- Child DS,[RFC7344],CDS/cds-completed-template,2011-06-06 |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
188 [60] = "CDNSKEY", -- DNSKEY(s) the Child wants reflected in DS,[RFC7344],,2014-06-16 |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
189 [61] = "OPENPGPKEY", -- OpenPGP Key,[RFC7929],OPENPGPKEY/openpgpkey-completed-template,2014-08-12 |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
190 [62] = "CSYNC", -- Child-To-Parent Synchronization,[RFC7477],,2015-01-27 |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
191 -- [63 .. 98] = "Unassigned", -- ,,, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
192 [99] = "SPF", -- ,[RFC7208],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
193 [100] = "UINFO", -- ,[IANA-Reserved],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
194 [101] = "UID", -- ,[IANA-Reserved],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
195 [102] = "GID", -- ,[IANA-Reserved],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
196 [103] = "UNSPEC", -- ,[IANA-Reserved],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
197 [104] = "NID", -- ,[RFC6742],ILNP/nid-completed-template, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
198 [105] = "L32", -- ,[RFC6742],ILNP/l32-completed-template, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
199 [106] = "L64", -- ,[RFC6742],ILNP/l64-completed-template, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
200 [107] = "LP", -- ,[RFC6742],ILNP/lp-completed-template, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
201 [108] = "EUI48", -- an EUI-48 address,[RFC7043],EUI48/eui48-completed-template,2013-03-27 |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
202 [109] = "EUI64", -- an EUI-64 address,[RFC7043],EUI64/eui64-completed-template,2013-03-27 |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
203 -- [110 .. 248] = "Unassigned", -- ,,, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
204 [249] = "TKEY", -- Transaction Key,[RFC2930],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
205 [250] = "TSIG", -- Transaction Signature,[RFC2845],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
206 [251] = "IXFR", -- incremental transfer,[RFC1995],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
207 [252] = "AXFR", -- transfer of an entire zone,[RFC1035][RFC5936],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
208 [253] = "MAILB", -- "mailbox-related RRs (MB, MG or MR)",[RFC1035],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
209 [254] = "MAILA", -- mail agent RRs (OBSOLETE - see MX),[RFC1035],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
210 [255] = "*", -- A request for all records the server/cache has available,[RFC1035][RFC6895],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
211 [256] = "URI", -- URI,[RFC7553],URI/uri-completed-template,2011-02-22 |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
212 [257] = "CAA", -- Certification Authority Restriction,[RFC6844],CAA/caa-completed-template,2011-04-07 |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
213 [258] = "AVC", -- Application Visibility and Control,[Wolfgang_Riedel],AVC/avc-completed-template,2016-02-26 |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
214 [259] = "DOA", -- Digital Object Architecture,[draft-durand-doa-over-dns],DOA/doa-completed-template,2017-08-30 |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
215 -- [260 .. 32767] = "Unassigned", -- ,,, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
216 [32768] = "TA", -- DNSSEC Trust Authorities,"[Sam_Weiler][http://cameo.library.cmu.edu/][ Deploying DNSSEC Without a Signed Root. Technical Report 1999-19, Information Networking Institute, Carnegie Mellon University, April 2004.]",,2005-12-13 |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
217 [32769] = "DLV", -- DNSSEC Lookaside Validation,[RFC4431],, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
218 -- [32770 .. 65279] = "Unassigned", -- ,,, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
219 -- [65280 .. 65534] = "Private use", -- ,,, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
220 -- [65535] = "Reserved", -- ,,, |
|
c5d5dfaa8d38
net.dns: Expand table of known RR types from IANA registry
Kim Alvefur <zash@zash.se>
parents:
8902
diff
changeset
|
221 } |
| 337 | 222 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
223 dns.classes = { 'IN', 'CS', 'CH', 'HS', [255] = '*' }; |
| 337 | 224 |
| 225 | |
|
8908
144666d0ad2f
net.dns: Lazily generate unknown RR type names
Kim Alvefur <zash@zash.se>
parents:
8907
diff
changeset
|
226 dns.type = augment (dns.types, "TYPE"); |
|
144666d0ad2f
net.dns: Lazily generate unknown RR type names
Kim Alvefur <zash@zash.se>
parents:
8907
diff
changeset
|
227 dns.class = augment (dns.classes, "CLASS"); |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
228 dns.typecode = encode (dns.types); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
229 dns.classcode = encode (dns.classes); |
| 337 | 230 |
| 231 | |
| 232 | |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
233 local function standardize(qname, qtype, qclass) -- - - - - - - standardize |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
234 if string.byte(qname, -1) ~= 0x2E then qname = qname..'.'; end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
235 qname = string.lower(qname); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
236 return qname, dns.type[qtype or 'A'], dns.class[qclass or 'IN']; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
237 end |
| 337 | 238 |
| 239 | |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
240 local function prune(rrs, time, soft) -- - - - - - - - - - - - - - - prune |
|
14078
d649d011df45
Use util.time.now() consistently instead of socket.gettime()
Link Mauve <linkmauve@linkmauve.fr>
parents:
13925
diff
changeset
|
241 time = time or time_now(); |
|
6463
460584257cc9
net.dns: Avoid duplicate cache entries
Florian Zeitz <florob@babelmonkeys.de>
parents:
6310
diff
changeset
|
242 for i,rr in ipairs(rrs) do |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
243 if rr.tod then |
|
8151
2c65f8be38aa
net.dns: Simplify expiry calculation (fixes #919)
Kim Alvefur <zash@zash.se>
parents:
7093
diff
changeset
|
244 if rr.tod < time then |
|
6463
460584257cc9
net.dns: Avoid duplicate cache entries
Florian Zeitz <florob@babelmonkeys.de>
parents:
6310
diff
changeset
|
245 rrs[rr[rr.type:lower()]] = nil; |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
246 table.remove(rrs, i); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
247 return prune(rrs, time, soft); -- Re-iterate |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
248 end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
249 elseif soft == 'soft' then -- What is this? I forget! |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
250 assert(rr.ttl == 0); |
|
6463
460584257cc9
net.dns: Avoid duplicate cache entries
Florian Zeitz <florob@babelmonkeys.de>
parents:
6310
diff
changeset
|
251 rrs[rr[rr.type:lower()]] = nil; |
|
460584257cc9
net.dns: Avoid duplicate cache entries
Florian Zeitz <florob@babelmonkeys.de>
parents:
6310
diff
changeset
|
252 table.remove(rrs, i); |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
253 end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
254 end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
255 end |
| 337 | 256 |
| 257 | |
| 258 -- metatables & co. ------------------------------------------ metatables & co. | |
| 259 | |
| 260 | |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
261 local resolver = {}; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
262 resolver.__index = resolver; |
| 337 | 263 |
|
3327
b447682f2a8d
net.dns: Make timeout configurable (default 15s)
Matthew Wild <mwild1@gmail.com>
parents:
3326
diff
changeset
|
264 resolver.timeout = default_timeout; |
| 337 | 265 |
|
3747
7d5b135bf268
net.dns: Clean up tostring() of returned records, as a result PTR records can now be tostring()'d
Matthew Wild <mwild1@gmail.com>
parents:
3746
diff
changeset
|
266 local function default_rr_tostring(rr) |
|
7d5b135bf268
net.dns: Clean up tostring() of returned records, as a result PTR records can now be tostring()'d
Matthew Wild <mwild1@gmail.com>
parents:
3746
diff
changeset
|
267 local rr_val = rr.type and rr[rr.type:lower()]; |
|
7d5b135bf268
net.dns: Clean up tostring() of returned records, as a result PTR records can now be tostring()'d
Matthew Wild <mwild1@gmail.com>
parents:
3746
diff
changeset
|
268 if type(rr_val) ~= "string" then |
|
7d5b135bf268
net.dns: Clean up tostring() of returned records, as a result PTR records can now be tostring()'d
Matthew Wild <mwild1@gmail.com>
parents:
3746
diff
changeset
|
269 return "<UNKNOWN RDATA TYPE>"; |
|
7d5b135bf268
net.dns: Clean up tostring() of returned records, as a result PTR records can now be tostring()'d
Matthew Wild <mwild1@gmail.com>
parents:
3746
diff
changeset
|
270 end |
|
7d5b135bf268
net.dns: Clean up tostring() of returned records, as a result PTR records can now be tostring()'d
Matthew Wild <mwild1@gmail.com>
parents:
3746
diff
changeset
|
271 return rr_val; |
|
7d5b135bf268
net.dns: Clean up tostring() of returned records, as a result PTR records can now be tostring()'d
Matthew Wild <mwild1@gmail.com>
parents:
3746
diff
changeset
|
272 end |
|
7d5b135bf268
net.dns: Clean up tostring() of returned records, as a result PTR records can now be tostring()'d
Matthew Wild <mwild1@gmail.com>
parents:
3746
diff
changeset
|
273 |
|
7d5b135bf268
net.dns: Clean up tostring() of returned records, as a result PTR records can now be tostring()'d
Matthew Wild <mwild1@gmail.com>
parents:
3746
diff
changeset
|
274 local special_tostrings = { |
|
7d5b135bf268
net.dns: Clean up tostring() of returned records, as a result PTR records can now be tostring()'d
Matthew Wild <mwild1@gmail.com>
parents:
3746
diff
changeset
|
275 LOC = resolver.LOC_tostring; |
|
4125
5cf13260edec
net.dns: Fix tostring() for SRV records
Matthew Wild <mwild1@gmail.com>
parents:
3955
diff
changeset
|
276 MX = function (rr) |
|
5cf13260edec
net.dns: Fix tostring() for SRV records
Matthew Wild <mwild1@gmail.com>
parents:
3955
diff
changeset
|
277 return string.format('%2i %s', rr.pref, rr.mx); |
|
5cf13260edec
net.dns: Fix tostring() for SRV records
Matthew Wild <mwild1@gmail.com>
parents:
3955
diff
changeset
|
278 end; |
|
5cf13260edec
net.dns: Fix tostring() for SRV records
Matthew Wild <mwild1@gmail.com>
parents:
3955
diff
changeset
|
279 SRV = function (rr) |
|
5cf13260edec
net.dns: Fix tostring() for SRV records
Matthew Wild <mwild1@gmail.com>
parents:
3955
diff
changeset
|
280 local s = rr.srv; |
|
5cf13260edec
net.dns: Fix tostring() for SRV records
Matthew Wild <mwild1@gmail.com>
parents:
3955
diff
changeset
|
281 return string.format('%5d %5d %5d %s', s.priority, s.weight, s.port, s.target); |
|
5cf13260edec
net.dns: Fix tostring() for SRV records
Matthew Wild <mwild1@gmail.com>
parents:
3955
diff
changeset
|
282 end; |
|
3747
7d5b135bf268
net.dns: Clean up tostring() of returned records, as a result PTR records can now be tostring()'d
Matthew Wild <mwild1@gmail.com>
parents:
3746
diff
changeset
|
283 }; |
| 337 | 284 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
285 local rr_metatable = {}; -- - - - - - - - - - - - - - - - - - - rr_metatable |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
286 function rr_metatable.__tostring(rr) |
|
3747
7d5b135bf268
net.dns: Clean up tostring() of returned records, as a result PTR records can now be tostring()'d
Matthew Wild <mwild1@gmail.com>
parents:
3746
diff
changeset
|
287 local rr_string = (special_tostrings[rr.type] or default_rr_tostring)(rr); |
|
7d5b135bf268
net.dns: Clean up tostring() of returned records, as a result PTR records can now be tostring()'d
Matthew Wild <mwild1@gmail.com>
parents:
3746
diff
changeset
|
288 return string.format('%2s %-5s %6i %-28s %s', rr.class, rr.type, rr.ttl, rr.name, rr_string); |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
289 end |
| 337 | 290 |
| 291 | |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
292 local rrs_metatable = {}; -- - - - - - - - - - - - - - - - - - rrs_metatable |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
293 function rrs_metatable.__tostring(rrs) |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
294 local t = {}; |
|
7469
363e4a5e9b0a
net.dns: remove unused one-letter loop variables [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents:
7322
diff
changeset
|
295 for _, rr in ipairs(rrs) do |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
296 append(t, tostring(rr)..'\n'); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
297 end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
298 return table.concat(t); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
299 end |
| 337 | 300 |
| 301 | |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
302 local cache_metatable = {}; -- - - - - - - - - - - - - - - - cache_metatable |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
303 function cache_metatable.__tostring(cache) |
|
14078
d649d011df45
Use util.time.now() consistently instead of socket.gettime()
Link Mauve <linkmauve@linkmauve.fr>
parents:
13925
diff
changeset
|
304 local time = time_now(); |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
305 local t = {}; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
306 for class,types in pairs(cache) do |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
307 for type,names in pairs(types) do |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
308 for name,rrs in pairs(names) do |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
309 prune(rrs, time); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
310 append(t, tostring(rrs)); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
311 end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
312 end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
313 end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
314 return table.concat(t); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
315 end |
| 337 | 316 |
| 317 | |
| 318 -- packet layer -------------------------------------------------- packet layer | |
| 319 | |
| 320 | |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
321 function dns.random(...) -- - - - - - - - - - - - - - - - - - - dns.random |
|
14078
d649d011df45
Use util.time.now() consistently instead of socket.gettime()
Link Mauve <linkmauve@linkmauve.fr>
parents:
13925
diff
changeset
|
322 math.randomseed(math.floor(10000 * time_now()) % 0x80000000); |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
323 dns.random = math.random; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
324 return dns.random(...); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
325 end |
| 337 | 326 |
| 327 | |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
328 local function encodeHeader(o) -- - - - - - - - - - - - - - - encodeHeader |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
329 o = o or {}; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
330 o.id = o.id or dns.random(0, 0xffff); -- 16b (random) id |
| 337 | 331 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
332 o.rd = o.rd or 1; -- 1b 1 recursion desired |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
333 o.tc = o.tc or 0; -- 1b 1 truncated response |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
334 o.aa = o.aa or 0; -- 1b 1 authoritative response |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
335 o.opcode = o.opcode or 0; -- 4b 0 query |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
336 -- 1 inverse query |
| 337 | 337 -- 2 server status request |
| 338 -- 3-15 reserved | |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
339 o.qr = o.qr or 0; -- 1b 0 query, 1 response |
| 337 | 340 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
341 o.rcode = o.rcode or 0; -- 4b 0 no error |
| 337 | 342 -- 1 format error |
| 343 -- 2 server failure | |
| 344 -- 3 name error | |
| 345 -- 4 not implemented | |
| 346 -- 5 refused | |
| 347 -- 6-15 reserved | |
|
12387
05c250fa335a
Spelling: Fix various spelling mistakes (thanks timeless)
Kim Alvefur <zash@zash.se>
parents:
10976
diff
changeset
|
348 o.z = o.z or 0; -- 3b 0 reserved |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
349 o.ra = o.ra or 0; -- 1b 1 recursion available |
| 337 | 350 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
351 o.qdcount = o.qdcount or 1; -- 16b number of question RRs |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
352 o.ancount = o.ancount or 0; -- 16b number of answers RRs |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
353 o.nscount = o.nscount or 0; -- 16b number of nameservers RRs |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
354 o.arcount = o.arcount or 0; -- 16b number of additional RRs |
| 337 | 355 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
356 -- string.char() rounds, so prevent roundup with -0.4999 |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
357 local header = string.char( |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
358 highbyte(o.id), o.id %0x100, |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
359 o.rd + 2*o.tc + 4*o.aa + 8*o.opcode + 128*o.qr, |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
360 o.rcode + 16*o.z + 128*o.ra, |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
361 highbyte(o.qdcount), o.qdcount %0x100, |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
362 highbyte(o.ancount), o.ancount %0x100, |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
363 highbyte(o.nscount), o.nscount %0x100, |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
364 highbyte(o.arcount), o.arcount %0x100 |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
365 ); |
| 337 | 366 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
367 return header, o.id; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
368 end |
| 337 | 369 |
| 370 | |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
371 local function encodeName(name) -- - - - - - - - - - - - - - - - encodeName |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
372 local t = {}; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
373 for part in string.gmatch(name, '[^.]+') do |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
374 append(t, string.char(string.len(part))); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
375 append(t, part); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
376 end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
377 append(t, string.char(0)); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
378 return table.concat(t); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
379 end |
| 337 | 380 |
| 381 | |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
382 local function encodeQuestion(qname, qtype, qclass) -- - - - encodeQuestion |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
383 qname = encodeName(qname); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
384 qtype = dns.typecode[qtype or 'a']; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
385 qclass = dns.classcode[qclass or 'in']; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
386 return qname..qtype..qclass; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
387 end |
| 337 | 388 |
| 389 | |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
390 function resolver:byte(len) -- - - - - - - - - - - - - - - - - - - - - byte |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
391 len = len or 1; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
392 local offset = self.offset; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
393 local last = offset + len - 1; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
394 if last > #self.packet then |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
395 error(string.format('out of bounds: %i>%i', last, #self.packet)); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
396 end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
397 self.offset = offset + len; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
398 return string.byte(self.packet, offset, last); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
399 end |
| 337 | 400 |
| 401 | |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
402 function resolver:word() -- - - - - - - - - - - - - - - - - - - - - - word |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
403 local b1, b2 = self:byte(2); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
404 return 0x100*b1 + b2; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
405 end |
| 337 | 406 |
| 407 | |
| 408 function resolver:dword () -- - - - - - - - - - - - - - - - - - - - - dword | |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
409 local b1, b2, b3, b4 = self:byte(4); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
410 --print('dword', b1, b2, b3, b4); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
411 return 0x1000000*b1 + 0x10000*b2 + 0x100*b3 + b4; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
412 end |
| 337 | 413 |
| 414 | |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
415 function resolver:sub(len) -- - - - - - - - - - - - - - - - - - - - - - sub |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
416 len = len or 1; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
417 local s = string.sub(self.packet, self.offset, self.offset + len - 1); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
418 self.offset = self.offset + len; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
419 return s; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
420 end |
| 337 | 421 |
| 422 | |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
423 function resolver:header(force) -- - - - - - - - - - - - - - - - - - header |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
424 local id = self:word(); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
425 --print(string.format(':header id %x', id)); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
426 if not self.active[id] and not force then return nil; end |
| 337 | 427 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
428 local h = { id = id }; |
| 337 | 429 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
430 local b1, b2 = self:byte(2); |
| 337 | 431 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
432 h.rd = b1 %2; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
433 h.tc = b1 /2%2; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
434 h.aa = b1 /4%2; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
435 h.opcode = b1 /8%16; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
436 h.qr = b1 /128; |
| 337 | 437 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
438 h.rcode = b2 %16; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
439 h.z = b2 /16%8; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
440 h.ra = b2 /128; |
| 337 | 441 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
442 h.qdcount = self:word(); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
443 h.ancount = self:word(); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
444 h.nscount = self:word(); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
445 h.arcount = self:word(); |
| 337 | 446 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
447 for k,v in pairs(h) do h[k] = v-v%1; end |
| 337 | 448 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
449 return h; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
450 end |
| 337 | 451 |
| 452 | |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
453 function resolver:name() -- - - - - - - - - - - - - - - - - - - - - - name |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
454 local remember, pointers = nil, 0; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
455 local len = self:byte(); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
456 local n = {}; |
|
4422
c25dee24623f
s2smanager, net.dns: Fix handling for NXNAME and SRV target of "."
Florian Zeitz <florob@babelmonkeys.de>
parents:
4400
diff
changeset
|
457 if len == 0 then return "." end -- Root label |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
458 while len > 0 do |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
459 if len >= 0xc0 then -- name is "compressed" |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
460 pointers = pointers + 1; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
461 if pointers >= 20 then error('dns error: 20 pointers'); end; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
462 local offset = ((len-0xc0)*0x100) + self:byte(); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
463 remember = remember or self.offset; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
464 self.offset = offset + 1; -- +1 for lua |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
465 else -- name is not compressed |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
466 append(n, self:sub(len)..'.'); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
467 end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
468 len = self:byte(); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
469 end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
470 self.offset = remember or self.offset; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
471 return table.concat(n); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
472 end |
| 337 | 473 |
| 474 | |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
475 function resolver:question() -- - - - - - - - - - - - - - - - - - question |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
476 local q = {}; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
477 q.name = self:name(); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
478 q.type = dns.type[self:word()]; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
479 q.class = dns.class[self:word()]; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
480 return q; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
481 end |
| 337 | 482 |
| 483 | |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
484 function resolver:A(rr) -- - - - - - - - - - - - - - - - - - - - - - - - A |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
485 local b1, b2, b3, b4 = self:byte(4); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
486 rr.a = string.format('%i.%i.%i.%i', b1, b2, b3, b4); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
487 end |
| 337 | 488 |
|
8427
1371518f70ff
net.dns: Use inet_ntop from util.net if available
Kim Alvefur <zash@zash.se>
parents:
8263
diff
changeset
|
489 if have_util_net and util_net.ntop then |
|
1371518f70ff
net.dns: Use inet_ntop from util.net if available
Kim Alvefur <zash@zash.se>
parents:
8263
diff
changeset
|
490 function resolver:A(rr) |
|
1371518f70ff
net.dns: Use inet_ntop from util.net if available
Kim Alvefur <zash@zash.se>
parents:
8263
diff
changeset
|
491 rr.a = util_net.ntop(self:sub(4)); |
|
1371518f70ff
net.dns: Use inet_ntop from util.net if available
Kim Alvefur <zash@zash.se>
parents:
8263
diff
changeset
|
492 end |
|
1371518f70ff
net.dns: Use inet_ntop from util.net if available
Kim Alvefur <zash@zash.se>
parents:
8263
diff
changeset
|
493 end |
|
1371518f70ff
net.dns: Use inet_ntop from util.net if available
Kim Alvefur <zash@zash.se>
parents:
8263
diff
changeset
|
494 |
|
4267
29d7eb6ff62c
net.dns: Support for resolving AAAA records
Matthew Wild <mwild1@gmail.com>
parents:
4251
diff
changeset
|
495 function resolver:AAAA(rr) |
|
29d7eb6ff62c
net.dns: Support for resolving AAAA records
Matthew Wild <mwild1@gmail.com>
parents:
4251
diff
changeset
|
496 local addr = {}; |
|
7500
4c519444d4a2
net.dns: remove unused one-letter loop variables [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents:
7480
diff
changeset
|
497 for _ = 1, rr.rdlength, 2 do |
|
4267
29d7eb6ff62c
net.dns: Support for resolving AAAA records
Matthew Wild <mwild1@gmail.com>
parents:
4251
diff
changeset
|
498 local b1, b2 = self:byte(2); |
|
29d7eb6ff62c
net.dns: Support for resolving AAAA records
Matthew Wild <mwild1@gmail.com>
parents:
4251
diff
changeset
|
499 table.insert(addr, ("%02x%02x"):format(b1, b2)); |
|
29d7eb6ff62c
net.dns: Support for resolving AAAA records
Matthew Wild <mwild1@gmail.com>
parents:
4251
diff
changeset
|
500 end |
| 4373 | 501 addr = table.concat(addr, ":"):gsub("%f[%x]0+(%x)","%1"); |
| 502 local zeros = {}; | |
|
8421
3d21c63ec03f
net.dns: Don't compress a single zero group in IPv6 addresses to match behaviour of inet_ntop
Kim Alvefur <zash@zash.se>
parents:
8263
diff
changeset
|
503 for item in addr:gmatch(":[0:]+:[0:]+:") do |
| 4373 | 504 table.insert(zeros, item) |
| 505 end | |
| 506 if #zeros == 0 then | |
| 507 rr.aaaa = addr; | |
| 508 return | |
| 509 elseif #zeros > 1 then | |
| 510 table.sort(zeros, function(a, b) return #a > #b end); | |
| 511 end | |
| 512 rr.aaaa = addr:gsub(zeros[1], "::", 1):gsub("^0::", "::"):gsub("::0$", "::"); | |
|
4267
29d7eb6ff62c
net.dns: Support for resolving AAAA records
Matthew Wild <mwild1@gmail.com>
parents:
4251
diff
changeset
|
513 end |
| 337 | 514 |
|
8427
1371518f70ff
net.dns: Use inet_ntop from util.net if available
Kim Alvefur <zash@zash.se>
parents:
8263
diff
changeset
|
515 if have_util_net and util_net.ntop then |
|
1371518f70ff
net.dns: Use inet_ntop from util.net if available
Kim Alvefur <zash@zash.se>
parents:
8263
diff
changeset
|
516 function resolver:AAAA(rr) |
|
1371518f70ff
net.dns: Use inet_ntop from util.net if available
Kim Alvefur <zash@zash.se>
parents:
8263
diff
changeset
|
517 rr.aaaa = util_net.ntop(self:sub(16)); |
|
1371518f70ff
net.dns: Use inet_ntop from util.net if available
Kim Alvefur <zash@zash.se>
parents:
8263
diff
changeset
|
518 end |
|
1371518f70ff
net.dns: Use inet_ntop from util.net if available
Kim Alvefur <zash@zash.se>
parents:
8263
diff
changeset
|
519 end |
|
1371518f70ff
net.dns: Use inet_ntop from util.net if available
Kim Alvefur <zash@zash.se>
parents:
8263
diff
changeset
|
520 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
521 function resolver:CNAME(rr) -- - - - - - - - - - - - - - - - - - - - CNAME |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
522 rr.cname = self:name(); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
523 end |
| 337 | 524 |
| 525 | |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
526 function resolver:MX(rr) -- - - - - - - - - - - - - - - - - - - - - - - MX |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
527 rr.pref = self:word(); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
528 rr.mx = self:name(); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
529 end |
| 337 | 530 |
| 531 | |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
532 function resolver:LOC_nibble_power() -- - - - - - - - - - LOC_nibble_power |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
533 local b = self:byte(); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
534 --print('nibbles', ((b-(b%0x10))/0x10), (b%0x10)); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
535 return ((b-(b%0x10))/0x10) * (10^(b%0x10)); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
536 end |
| 337 | 537 |
| 538 | |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
539 function resolver:LOC(rr) -- - - - - - - - - - - - - - - - - - - - - - LOC |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
540 rr.version = self:byte(); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
541 if rr.version == 0 then |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
542 rr.loc = rr.loc or {}; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
543 rr.loc.size = self:LOC_nibble_power(); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
544 rr.loc.horiz_pre = self:LOC_nibble_power(); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
545 rr.loc.vert_pre = self:LOC_nibble_power(); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
546 rr.loc.latitude = self:dword(); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
547 rr.loc.longitude = self:dword(); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
548 rr.loc.altitude = self:dword(); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
549 end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
550 end |
| 337 | 551 |
| 552 | |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
553 local function LOC_tostring_degrees(f, pos, neg) -- - - - - - - - - - - - - |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
554 f = f - 0x80000000; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
555 if f < 0 then pos = neg; f = -f; end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
556 local deg, min, msec; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
557 msec = f%60000; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
558 f = (f-msec)/60000; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
559 min = f%60; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
560 deg = (f-min)/60; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
561 return string.format('%3d %2d %2.3f %s', deg, min, msec/1000, pos); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
562 end |
| 337 | 563 |
| 564 | |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
565 function resolver.LOC_tostring(rr) -- - - - - - - - - - - - - LOC_tostring |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
566 local t = {}; |
| 337 | 567 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
568 --[[ |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
569 for k,name in pairs { 'size', 'horiz_pre', 'vert_pre', 'latitude', 'longitude', 'altitude' } do |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
570 append(t, string.format('%4s%-10s: %12.0f\n', '', name, rr.loc[name])); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
571 end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
572 --]] |
| 337 | 573 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
574 append(t, string.format( |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
575 '%s %s %.2fm %.2fm %.2fm %.2fm', |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
576 LOC_tostring_degrees (rr.loc.latitude, 'N', 'S'), |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
577 LOC_tostring_degrees (rr.loc.longitude, 'E', 'W'), |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
578 (rr.loc.altitude - 10000000) / 100, |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
579 rr.loc.size / 100, |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
580 rr.loc.horiz_pre / 100, |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
581 rr.loc.vert_pre / 100 |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
582 )); |
| 337 | 583 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
584 return table.concat(t); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
585 end |
| 337 | 586 |
| 587 | |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
588 function resolver:NS(rr) -- - - - - - - - - - - - - - - - - - - - - - - NS |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
589 rr.ns = self:name(); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
590 end |
| 337 | 591 |
| 592 | |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
593 function resolver:SOA(rr) -- - - - - - - - - - - - - - - - - - - - - - SOA |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
594 end |
| 337 | 595 |
| 596 | |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
597 function resolver:SRV(rr) -- - - - - - - - - - - - - - - - - - - - - - SRV |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
598 rr.srv = {}; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
599 rr.srv.priority = self:word(); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
600 rr.srv.weight = self:word(); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
601 rr.srv.port = self:word(); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
602 rr.srv.target = self:name(); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
603 end |
| 337 | 604 |
|
3513
4cf5962747fc
net.dns: Support for parsing PTR records
Matthew Wild <mwild1@gmail.com>
parents:
3512
diff
changeset
|
605 function resolver:PTR(rr) |
|
4cf5962747fc
net.dns: Support for parsing PTR records
Matthew Wild <mwild1@gmail.com>
parents:
3512
diff
changeset
|
606 rr.ptr = self:name(); |
|
4cf5962747fc
net.dns: Support for parsing PTR records
Matthew Wild <mwild1@gmail.com>
parents:
3512
diff
changeset
|
607 end |
| 337 | 608 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
609 function resolver:TXT(rr) -- - - - - - - - - - - - - - - - - - - - - - TXT |
| 4251 | 610 rr.txt = self:sub (self:byte()); |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
611 end |
| 337 | 612 |
| 613 | |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
614 function resolver:rr() -- - - - - - - - - - - - - - - - - - - - - - - - rr |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
615 local rr = {}; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
616 setmetatable(rr, rr_metatable); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
617 rr.name = self:name(self); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
618 rr.type = dns.type[self:word()] or rr.type; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
619 rr.class = dns.class[self:word()] or rr.class; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
620 rr.ttl = 0x10000*self:word() + self:word(); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
621 rr.rdlength = self:word(); |
| 337 | 622 |
|
8263
9b52b1f19b51
net.dns: Correctly apply lower bound of RTT (thanks Ge0rG)
Kim Alvefur <zash@zash.se>
parents:
8164
diff
changeset
|
623 rr.tod = self.time + math.max(rr.ttl, 1); |
| 337 | 624 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
625 local remember = self.offset; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
626 local rr_parser = self[dns.type[rr.type]]; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
627 if rr_parser then rr_parser(self, rr); end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
628 self.offset = remember; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
629 rr.rdata = self:sub(rr.rdlength); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
630 return rr; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
631 end |
| 337 | 632 |
| 633 | |
| 634 function resolver:rrs (count) -- - - - - - - - - - - - - - - - - - - - - rrs | |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
635 local rrs = {}; |
|
7500
4c519444d4a2
net.dns: remove unused one-letter loop variables [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents:
7480
diff
changeset
|
636 for _ = 1, count do append(rrs, self:rr()); end |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
637 return rrs; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
638 end |
| 337 | 639 |
| 640 | |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
641 function resolver:decode(packet, force) -- - - - - - - - - - - - - - decode |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
642 self.packet, self.offset = packet, 1; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
643 local header = self:header(force); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
644 if not header then return nil; end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
645 local response = { header = header }; |
| 337 | 646 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
647 response.question = {}; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
648 local offset = self.offset; |
|
7500
4c519444d4a2
net.dns: remove unused one-letter loop variables [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents:
7480
diff
changeset
|
649 for _ = 1, response.header.qdcount do |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
650 append(response.question, self:question()); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
651 end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
652 response.question.raw = string.sub(self.packet, offset, self.offset - 1); |
| 337 | 653 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
654 if not force then |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
655 if not self.active[response.header.id] or not self.active[response.header.id][response.question.raw] then |
|
5266
5c3a3ef6b769
net.dns: Clean up query list when a server is marked down
Matthew Wild <mwild1@gmail.com>
parents:
4422
diff
changeset
|
656 self.active[response.header.id] = nil; |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
657 return nil; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
658 end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
659 end |
| 337 | 660 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
661 response.answer = self:rrs(response.header.ancount); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
662 response.authority = self:rrs(response.header.nscount); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
663 response.additional = self:rrs(response.header.arcount); |
| 337 | 664 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
665 return response; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
666 end |
| 337 | 667 |
| 668 | |
| 669 -- socket layer -------------------------------------------------- socket layer | |
| 670 | |
| 671 | |
|
10958
25680ece29c2
net.dns: Increase backoff delays
Matthew Wild <mwild1@gmail.com>
parents:
10957
diff
changeset
|
672 resolver.delays = { 1, 2, 3, 5 }; |
| 337 | 673 |
|
10957
8902cecbdd39
net.dns: Add jitter to spread queries and reduce failures due to congestion
Matthew Wild <mwild1@gmail.com>
parents:
10956
diff
changeset
|
674 resolver.jitter = have_timer and default_jitter or nil; |
|
8902cecbdd39
net.dns: Add jitter to spread queries and reduce failures due to congestion
Matthew Wild <mwild1@gmail.com>
parents:
10956
diff
changeset
|
675 resolver.retry_jitter = have_timer and default_retry_jitter or nil; |
| 337 | 676 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
677 function resolver:addnameserver(address) -- - - - - - - - - - addnameserver |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
678 self.server = self.server or {}; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
679 append(self.server, address); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
680 end |
| 337 | 681 |
| 682 | |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
683 function resolver:setnameserver(address) -- - - - - - - - - - setnameserver |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
684 self.server = {}; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
685 self:addnameserver(address); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
686 end |
| 337 | 687 |
| 688 | |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
689 function resolver:adddefaultnameservers() -- - - - - adddefaultnameservers |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
690 if is_windows then |
|
3544
f2aca3e0fe3b
net.dns: Fixed a traceback when util/windows.dll is unavailable on windows.
Waqas Hussain <waqas20@gmail.com>
parents:
3540
diff
changeset
|
691 if windows and windows.get_nameservers then |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
692 for _, server in ipairs(windows.get_nameservers()) do |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
693 self:addnameserver(server); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
694 end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
695 end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
696 if not self.server or #self.server == 0 then |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
697 -- TODO log warning about no nameservers, adding opendns servers as fallback |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
698 self:addnameserver("208.67.222.222"); |
|
2742
6c0a081cd766
net.dns: Trailing whitespace
Matthew Wild <mwild1@gmail.com>
parents:
2741
diff
changeset
|
699 self:addnameserver("208.67.220.220"); |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
700 end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
701 else -- posix |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
702 local resolv_conf = io.open("/etc/resolv.conf"); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
703 if resolv_conf then |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
704 for line in resolv_conf:lines() do |
|
13925
a4c47203a9eb
various: Do not mutate loop variables as they are treated as const in Lua 5.5
Kim Alvefur <zash@zash.se>
parents:
12974
diff
changeset
|
705 local nameserver = line:gsub("#.*$", "") |
|
7056
7b0651e4534f
net.dns: Allow a zone id in resolv.conf (eg like %eth0)
Kim Alvefur <zash@zash.se>
parents:
7054
diff
changeset
|
706 :match('^%s*nameserver%s+([%x:%.]*%%?%S*)%s*$'); |
|
13925
a4c47203a9eb
various: Do not mutate loop variables as they are treated as const in Lua 5.5
Kim Alvefur <zash@zash.se>
parents:
12974
diff
changeset
|
707 if nameserver then |
|
a4c47203a9eb
various: Do not mutate loop variables as they are treated as const in Lua 5.5
Kim Alvefur <zash@zash.se>
parents:
12974
diff
changeset
|
708 local ip = new_ip(nameserver); |
|
7054
94d5e2f33a10
net.dns: Support IPv6 addresses in resolv.conf [Backported from 0.10]
Florian Zeitz <florob@babelmonkeys.de>
parents:
6863
diff
changeset
|
709 if ip then |
|
94d5e2f33a10
net.dns: Support IPv6 addresses in resolv.conf [Backported from 0.10]
Florian Zeitz <florob@babelmonkeys.de>
parents:
6863
diff
changeset
|
710 self:addnameserver(ip.addr); |
|
94d5e2f33a10
net.dns: Support IPv6 addresses in resolv.conf [Backported from 0.10]
Florian Zeitz <florob@babelmonkeys.de>
parents:
6863
diff
changeset
|
711 end |
|
2741
fcd30b72c50c
net.dns: More reliable parsing of resolv.conf - allow multiple nameserver IPs on one line (thanks dersd)
Matthew Wild <mwild1@gmail.com>
parents:
2620
diff
changeset
|
712 end |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
713 end |
|
9952
6402bc76f51a
net.dns: Close resolv.conf handle when done (fixes #1342)
Kim Alvefur <zash@zash.se>
parents:
8909
diff
changeset
|
714 resolv_conf:close(); |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
715 end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
716 if not self.server or #self.server == 0 then |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
717 -- TODO log warning about no nameservers, adding localhost as the default nameserver |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
718 self:addnameserver("127.0.0.1"); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
719 end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
720 end |
|
399
93b6587d9afb
Added temporary fix for srv on windows: using opendns nameservers
Waqas Hussain <waqas20@gmail.com>
parents:
379
diff
changeset
|
721 end |
| 337 | 722 |
| 723 | |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
724 function resolver:getsocket(servernum) -- - - - - - - - - - - - - getsocket |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
725 self.socket = self.socket or {}; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
726 self.socketset = self.socketset or {}; |
| 337 | 727 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
728 local sock = self.socket[servernum]; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
729 if sock then return sock; end |
| 337 | 730 |
|
6509
7cb69eba3e95
net.dns: Try next server if peer name can not be set (thanks wirehack7)
Kim Alvefur <zash@zash.se>
parents:
6508
diff
changeset
|
731 local ok, err; |
|
7054
94d5e2f33a10
net.dns: Support IPv6 addresses in resolv.conf [Backported from 0.10]
Florian Zeitz <florob@babelmonkeys.de>
parents:
6863
diff
changeset
|
732 local peer = self.server[servernum]; |
|
94d5e2f33a10
net.dns: Support IPv6 addresses in resolv.conf [Backported from 0.10]
Florian Zeitz <florob@babelmonkeys.de>
parents:
6863
diff
changeset
|
733 if peer:find(":") then |
|
94d5e2f33a10
net.dns: Support IPv6 addresses in resolv.conf [Backported from 0.10]
Florian Zeitz <florob@babelmonkeys.de>
parents:
6863
diff
changeset
|
734 sock, err = socket.udp6(); |
|
94d5e2f33a10
net.dns: Support IPv6 addresses in resolv.conf [Backported from 0.10]
Florian Zeitz <florob@babelmonkeys.de>
parents:
6863
diff
changeset
|
735 else |
|
6857
86fcc3fa1a97
net.dns: Use new IPv4-specific socket factory if available (fixes dns on libevent with latest development version of luasocket)
Kim Alvefur <zash@zash.se>
parents:
6780
diff
changeset
|
736 sock, err = (socket.udp4 or socket.udp)(); |
|
7054
94d5e2f33a10
net.dns: Support IPv6 addresses in resolv.conf [Backported from 0.10]
Florian Zeitz <florob@babelmonkeys.de>
parents:
6863
diff
changeset
|
737 end |
|
5730
411e9e7d8035
net.dns, net.adns: Make sure errors from net.server are propagated (thanks asterix)
Kim Alvefur <zash@zash.se>
parents:
5566
diff
changeset
|
738 if sock and self.socket_wrapper then sock, err = self.socket_wrapper(sock, self); end |
|
3954
6e22b0cf3d72
net.dns: resolver:getsocket(): Return nil, err on failure
Matthew Wild <mwild1@gmail.com>
parents:
3747
diff
changeset
|
739 if not sock then |
|
6e22b0cf3d72
net.dns: resolver:getsocket(): Return nil, err on failure
Matthew Wild <mwild1@gmail.com>
parents:
3747
diff
changeset
|
740 return nil, err; |
|
6e22b0cf3d72
net.dns: resolver:getsocket(): Return nil, err on failure
Matthew Wild <mwild1@gmail.com>
parents:
3747
diff
changeset
|
741 end |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
742 sock:settimeout(0); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
743 -- todo: attempt to use a random port, fallback to 0 |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
744 self.socket[servernum] = sock; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
745 self.socketset[sock] = servernum; |
|
6509
7cb69eba3e95
net.dns: Try next server if peer name can not be set (thanks wirehack7)
Kim Alvefur <zash@zash.se>
parents:
6508
diff
changeset
|
746 -- set{sock,peer}name can fail, eg because of local routing table |
|
7cb69eba3e95
net.dns: Try next server if peer name can not be set (thanks wirehack7)
Kim Alvefur <zash@zash.se>
parents:
6508
diff
changeset
|
747 -- if so, try the next server |
|
7cb69eba3e95
net.dns: Try next server if peer name can not be set (thanks wirehack7)
Kim Alvefur <zash@zash.se>
parents:
6508
diff
changeset
|
748 ok, err = sock:setsockname('*', 0); |
|
7cb69eba3e95
net.dns: Try next server if peer name can not be set (thanks wirehack7)
Kim Alvefur <zash@zash.se>
parents:
6508
diff
changeset
|
749 if not ok then return self:servfail(sock, err); end |
|
7054
94d5e2f33a10
net.dns: Support IPv6 addresses in resolv.conf [Backported from 0.10]
Florian Zeitz <florob@babelmonkeys.de>
parents:
6863
diff
changeset
|
750 ok, err = sock:setpeername(peer, 53); |
|
6509
7cb69eba3e95
net.dns: Try next server if peer name can not be set (thanks wirehack7)
Kim Alvefur <zash@zash.se>
parents:
6508
diff
changeset
|
751 if not ok then return self:servfail(sock, err); end |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
752 return sock; |
|
1786
4016d8bc30b8
net.dns: Multiple internal changes and API extensions to allow for more reliable DNS lookups
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
753 end |
| 337 | 754 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
755 function resolver:voidsocket(sock) |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
756 if self.socket[sock] then |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
757 self.socketset[self.socket[sock]] = nil; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
758 self.socket[sock] = nil; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
759 elseif self.socketset[sock] then |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
760 self.socket[self.socketset[sock]] = nil; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
761 self.socketset[sock] = nil; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
762 end |
|
5267
a2080e5c4eda
net.dns: Close voided sockets, so they don't stay in net.server
Kim Alvefur <zash@zash.se>
parents:
5266
diff
changeset
|
763 sock:close(); |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
764 end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
765 |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
766 function resolver:socket_wrapper_set(func) -- - - - - - - socket_wrapper_set |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
767 self.socket_wrapper = func; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
768 end |
| 337 | 769 |
| 770 | |
| 771 function resolver:closeall () -- - - - - - - - - - - - - - - - - - closeall | |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
772 for i,sock in ipairs(self.socket) do |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
773 self.socket[i] = nil; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
774 self.socketset[sock] = nil; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
775 sock:close(); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
776 end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
777 end |
| 337 | 778 |
| 779 | |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
780 function resolver:remember(rr, type) -- - - - - - - - - - - - - - remember |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
781 --print ('remember', type, rr.class, rr.type, rr.name) |
|
2620
481c6724818f
net.dns: Normalize records before placing them in the cache, fixes issues with CNAME targets in CAPS (fixes #161)
Matthew Wild <mwild1@gmail.com>
parents:
2619
diff
changeset
|
782 local qname, qtype, qclass = standardize(rr.name, rr.type, rr.class); |
| 337 | 783 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
784 if type ~= '*' then |
|
2620
481c6724818f
net.dns: Normalize records before placing them in the cache, fixes issues with CNAME targets in CAPS (fixes #161)
Matthew Wild <mwild1@gmail.com>
parents:
2619
diff
changeset
|
785 type = qtype; |
|
481c6724818f
net.dns: Normalize records before placing them in the cache, fixes issues with CNAME targets in CAPS (fixes #161)
Matthew Wild <mwild1@gmail.com>
parents:
2619
diff
changeset
|
786 local all = get(self.cache, qclass, '*', qname); |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
787 --print('remember all', all); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
788 if all then append(all, rr); end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
789 end |
| 337 | 790 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
791 self.cache = self.cache or setmetatable({}, cache_metatable); |
|
2620
481c6724818f
net.dns: Normalize records before placing them in the cache, fixes issues with CNAME targets in CAPS (fixes #161)
Matthew Wild <mwild1@gmail.com>
parents:
2619
diff
changeset
|
792 local rrs = get(self.cache, qclass, type, qname) or |
|
481c6724818f
net.dns: Normalize records before placing them in the cache, fixes issues with CNAME targets in CAPS (fixes #161)
Matthew Wild <mwild1@gmail.com>
parents:
2619
diff
changeset
|
793 set(self.cache, qclass, type, qname, setmetatable({}, rrs_metatable)); |
|
8900
fcf42bd7d067
net.dns: Don't attempt to cache unparsed data (fixes #1056)
Kim Alvefur <zash@zash.se>
parents:
8898
diff
changeset
|
794 if rr[qtype:lower()] and not rrs[rr[qtype:lower()]] then |
|
6463
460584257cc9
net.dns: Avoid duplicate cache entries
Florian Zeitz <florob@babelmonkeys.de>
parents:
6310
diff
changeset
|
795 rrs[rr[qtype:lower()]] = true; |
|
460584257cc9
net.dns: Avoid duplicate cache entries
Florian Zeitz <florob@babelmonkeys.de>
parents:
6310
diff
changeset
|
796 append(rrs, rr); |
|
460584257cc9
net.dns: Avoid duplicate cache entries
Florian Zeitz <florob@babelmonkeys.de>
parents:
6310
diff
changeset
|
797 end |
| 337 | 798 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
799 if type == 'MX' then self.unsorted[rrs] = true; end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
800 end |
| 337 | 801 |
| 802 | |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
803 local function comp_mx(a, b) -- - - - - - - - - - - - - - - - - - - comp_mx |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
804 return (a.pref == b.pref) and (a.mx < b.mx) or (a.pref < b.pref); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
805 end |
| 337 | 806 |
| 807 | |
|
6631
45222bfb206f
net.dns, mod_s2s: Add chasing of CNAMEs to net.dns and remove it from mod_s2s
Kim Alvefur <zash@zash.se>
parents:
6509
diff
changeset
|
808 function resolver:peek (qname, qtype, qclass, n) -- - - - - - - - - - - - peek |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
809 qname, qtype, qclass = standardize(qname, qtype, qclass); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
810 local rrs = get(self.cache, qclass, qtype, qname); |
|
6631
45222bfb206f
net.dns, mod_s2s: Add chasing of CNAMEs to net.dns and remove it from mod_s2s
Kim Alvefur <zash@zash.se>
parents:
6509
diff
changeset
|
811 if not rrs then |
|
45222bfb206f
net.dns, mod_s2s: Add chasing of CNAMEs to net.dns and remove it from mod_s2s
Kim Alvefur <zash@zash.se>
parents:
6509
diff
changeset
|
812 if n then if n <= 0 then return end else n = 3 end |
|
45222bfb206f
net.dns, mod_s2s: Add chasing of CNAMEs to net.dns and remove it from mod_s2s
Kim Alvefur <zash@zash.se>
parents:
6509
diff
changeset
|
813 rrs = get(self.cache, qclass, "CNAME", qname); |
|
45222bfb206f
net.dns, mod_s2s: Add chasing of CNAMEs to net.dns and remove it from mod_s2s
Kim Alvefur <zash@zash.se>
parents:
6509
diff
changeset
|
814 if not (rrs and rrs[1]) then return end |
|
45222bfb206f
net.dns, mod_s2s: Add chasing of CNAMEs to net.dns and remove it from mod_s2s
Kim Alvefur <zash@zash.se>
parents:
6509
diff
changeset
|
815 return self:peek(rrs[1].cname, qtype, qclass, n - 1); |
|
45222bfb206f
net.dns, mod_s2s: Add chasing of CNAMEs to net.dns and remove it from mod_s2s
Kim Alvefur <zash@zash.se>
parents:
6509
diff
changeset
|
816 end |
|
14078
d649d011df45
Use util.time.now() consistently instead of socket.gettime()
Link Mauve <linkmauve@linkmauve.fr>
parents:
13925
diff
changeset
|
817 if prune(rrs, time_now()) and qtype == '*' or not next(rrs) then |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
818 set(self.cache, qclass, qtype, qname, nil); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
819 return nil; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
820 end |
|
6631
45222bfb206f
net.dns, mod_s2s: Add chasing of CNAMEs to net.dns and remove it from mod_s2s
Kim Alvefur <zash@zash.se>
parents:
6509
diff
changeset
|
821 if self.unsorted[rrs] then table.sort (rrs, comp_mx); self.unsorted[rrs] = nil; end |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
822 return rrs; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
823 end |
| 337 | 824 |
| 825 | |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
826 function resolver:purge(soft) -- - - - - - - - - - - - - - - - - - - purge |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
827 if soft == 'soft' then |
|
14078
d649d011df45
Use util.time.now() consistently instead of socket.gettime()
Link Mauve <linkmauve@linkmauve.fr>
parents:
13925
diff
changeset
|
828 self.time = time_now(); |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
829 for class,types in pairs(self.cache or {}) do |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
830 for type,names in pairs(types) do |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
831 for name,rrs in pairs(names) do |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
832 prune(rrs, self.time, 'soft') |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
833 end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
834 end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
835 end |
|
4400
ac651265766c
net.dns: Preserve metatable on manual cache purge
Matthew Wild <mwild1@gmail.com>
parents:
4373
diff
changeset
|
836 else self.cache = setmetatable({}, cache_metatable); end |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
837 end |
| 337 | 838 |
| 839 | |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
840 function resolver:query(qname, qtype, qclass) -- - - - - - - - - - -- query |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
841 qname, qtype, qclass = standardize(qname, qtype, qclass) |
| 337 | 842 |
|
6288
d122420542fb
net.dns: Fix duplicated cache insertions by limiting outstanding queries per name to one
Kim Alvefur <zash@zash.se>
parents:
5730
diff
changeset
|
843 local co = coroutine.running(); |
|
d122420542fb
net.dns: Fix duplicated cache insertions by limiting outstanding queries per name to one
Kim Alvefur <zash@zash.se>
parents:
5730
diff
changeset
|
844 local q = get(self.wanted, qclass, qtype, qname); |
|
d122420542fb
net.dns: Fix duplicated cache insertions by limiting outstanding queries per name to one
Kim Alvefur <zash@zash.se>
parents:
5730
diff
changeset
|
845 if co and q then |
|
d122420542fb
net.dns: Fix duplicated cache insertions by limiting outstanding queries per name to one
Kim Alvefur <zash@zash.se>
parents:
5730
diff
changeset
|
846 -- We are already waiting for a reply to an identical query. |
|
d122420542fb
net.dns: Fix duplicated cache insertions by limiting outstanding queries per name to one
Kim Alvefur <zash@zash.se>
parents:
5730
diff
changeset
|
847 set(self.wanted, qclass, qtype, qname, co, true); |
|
d122420542fb
net.dns: Fix duplicated cache insertions by limiting outstanding queries per name to one
Kim Alvefur <zash@zash.se>
parents:
5730
diff
changeset
|
848 return true; |
|
d122420542fb
net.dns: Fix duplicated cache insertions by limiting outstanding queries per name to one
Kim Alvefur <zash@zash.se>
parents:
5730
diff
changeset
|
849 end |
|
d122420542fb
net.dns: Fix duplicated cache insertions by limiting outstanding queries per name to one
Kim Alvefur <zash@zash.se>
parents:
5730
diff
changeset
|
850 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
851 if not self.server then self:adddefaultnameservers(); end |
| 337 | 852 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
853 local question = encodeQuestion(qname, qtype, qclass); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
854 local peek = self:peek (qname, qtype, qclass); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
855 if peek then return peek; end |
| 337 | 856 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
857 local header, id = encodeHeader(); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
858 --print ('query id', id, qclass, qtype, qname) |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
859 local o = { |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
860 packet = header..question, |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
861 server = self.best_server, |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
862 delay = 1, |
|
14078
d649d011df45
Use util.time.now() consistently instead of socket.gettime()
Link Mauve <linkmauve@linkmauve.fr>
parents:
13925
diff
changeset
|
863 retry = time_now() + self.delays[1]; |
|
10956
03a09fa02e8e
net.dns: Fix timeout retry logic
Matthew Wild <mwild1@gmail.com>
parents:
10955
diff
changeset
|
864 qclass = qclass; |
|
03a09fa02e8e
net.dns: Fix timeout retry logic
Matthew Wild <mwild1@gmail.com>
parents:
10955
diff
changeset
|
865 qtype = qtype; |
|
03a09fa02e8e
net.dns: Fix timeout retry logic
Matthew Wild <mwild1@gmail.com>
parents:
10955
diff
changeset
|
866 qname = qname; |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
867 }; |
| 337 | 868 |
|
3540
bc139431830b
Monster whitespace commit (beware the whitespace monster).
Waqas Hussain <waqas20@gmail.com>
parents:
3513
diff
changeset
|
869 -- remember the query |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
870 self.active[id] = self.active[id] or {}; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
871 self.active[id][question] = o; |
| 337 | 872 |
|
3955
a096700d23d9
net.dns: resolver:query(): Handle getsocket() failures, and return true on success
Matthew Wild <mwild1@gmail.com>
parents:
3954
diff
changeset
|
873 local conn, err = self:getsocket(o.server) |
|
a096700d23d9
net.dns: resolver:query(): Handle getsocket() failures, and return true on success
Matthew Wild <mwild1@gmail.com>
parents:
3954
diff
changeset
|
874 if not conn then |
|
a096700d23d9
net.dns: resolver:query(): Handle getsocket() failures, and return true on success
Matthew Wild <mwild1@gmail.com>
parents:
3954
diff
changeset
|
875 return nil, err; |
|
a096700d23d9
net.dns: resolver:query(): Handle getsocket() failures, and return true on success
Matthew Wild <mwild1@gmail.com>
parents:
3954
diff
changeset
|
876 end |
|
10957
8902cecbdd39
net.dns: Add jitter to spread queries and reduce failures due to congestion
Matthew Wild <mwild1@gmail.com>
parents:
10956
diff
changeset
|
877 if self.jitter then |
|
8902cecbdd39
net.dns: Add jitter to spread queries and reduce failures due to congestion
Matthew Wild <mwild1@gmail.com>
parents:
10956
diff
changeset
|
878 timer.add_task(math.random()*self.jitter, function () |
|
8902cecbdd39
net.dns: Add jitter to spread queries and reduce failures due to congestion
Matthew Wild <mwild1@gmail.com>
parents:
10956
diff
changeset
|
879 conn:send(o.packet); |
|
8902cecbdd39
net.dns: Add jitter to spread queries and reduce failures due to congestion
Matthew Wild <mwild1@gmail.com>
parents:
10956
diff
changeset
|
880 end); |
|
8902cecbdd39
net.dns: Add jitter to spread queries and reduce failures due to congestion
Matthew Wild <mwild1@gmail.com>
parents:
10956
diff
changeset
|
881 else |
|
8902cecbdd39
net.dns: Add jitter to spread queries and reduce failures due to congestion
Matthew Wild <mwild1@gmail.com>
parents:
10956
diff
changeset
|
882 conn:send(o.packet); |
|
8902cecbdd39
net.dns: Add jitter to spread queries and reduce failures due to congestion
Matthew Wild <mwild1@gmail.com>
parents:
10956
diff
changeset
|
883 end |
|
7093
388281be2bc7
net.dns: Remember query only after it was sent, in case it was not (fixes #598)
Kim Alvefur <zash@zash.se>
parents:
7059
diff
changeset
|
884 |
|
388281be2bc7
net.dns: Remember query only after it was sent, in case it was not (fixes #598)
Kim Alvefur <zash@zash.se>
parents:
7059
diff
changeset
|
885 -- remember which coroutine wants the answer |
|
388281be2bc7
net.dns: Remember query only after it was sent, in case it was not (fixes #598)
Kim Alvefur <zash@zash.se>
parents:
7059
diff
changeset
|
886 if co then |
|
388281be2bc7
net.dns: Remember query only after it was sent, in case it was not (fixes #598)
Kim Alvefur <zash@zash.se>
parents:
7059
diff
changeset
|
887 set(self.wanted, qclass, qtype, qname, co, true); |
|
388281be2bc7
net.dns: Remember query only after it was sent, in case it was not (fixes #598)
Kim Alvefur <zash@zash.se>
parents:
7059
diff
changeset
|
888 end |
|
12387
05c250fa335a
Spelling: Fix various spelling mistakes (thanks timeless)
Kim Alvefur <zash@zash.se>
parents:
10976
diff
changeset
|
889 |
|
10664
c2b79b44ded7
net.dns: Handle being loaded outside of Prosody
Kim Alvefur <zash@zash.se>
parents:
9952
diff
changeset
|
890 if have_timer and self.timeout then |
|
3324
070c8ba71b76
net.dns: Handle our own timeouts, including falling onto other servers in resolv.conf if necessary
Matthew Wild <mwild1@gmail.com>
parents:
3057
diff
changeset
|
891 local num_servers = #self.server; |
|
070c8ba71b76
net.dns: Handle our own timeouts, including falling onto other servers in resolv.conf if necessary
Matthew Wild <mwild1@gmail.com>
parents:
3057
diff
changeset
|
892 local i = 1; |
|
3327
b447682f2a8d
net.dns: Make timeout configurable (default 15s)
Matthew Wild <mwild1@gmail.com>
parents:
3326
diff
changeset
|
893 timer.add_task(self.timeout, function () |
|
3324
070c8ba71b76
net.dns: Handle our own timeouts, including falling onto other servers in resolv.conf if necessary
Matthew Wild <mwild1@gmail.com>
parents:
3057
diff
changeset
|
894 if get(self.wanted, qclass, qtype, qname, co) then |
|
10955
7bcfac630b65
net.dns: Add some debug logging
Matthew Wild <mwild1@gmail.com>
parents:
10664
diff
changeset
|
895 log("debug", "DNS request timeout %d/%d", i, num_servers) |
|
3324
070c8ba71b76
net.dns: Handle our own timeouts, including falling onto other servers in resolv.conf if necessary
Matthew Wild <mwild1@gmail.com>
parents:
3057
diff
changeset
|
896 i = i + 1; |
|
10956
03a09fa02e8e
net.dns: Fix timeout retry logic
Matthew Wild <mwild1@gmail.com>
parents:
10955
diff
changeset
|
897 self:servfail(self.socket[o.server]); |
|
03a09fa02e8e
net.dns: Fix timeout retry logic
Matthew Wild <mwild1@gmail.com>
parents:
10955
diff
changeset
|
898 -- end |
|
03a09fa02e8e
net.dns: Fix timeout retry logic
Matthew Wild <mwild1@gmail.com>
parents:
10955
diff
changeset
|
899 end |
|
03a09fa02e8e
net.dns: Fix timeout retry logic
Matthew Wild <mwild1@gmail.com>
parents:
10955
diff
changeset
|
900 -- Still outstanding? (i.e. retried) |
|
03a09fa02e8e
net.dns: Fix timeout retry logic
Matthew Wild <mwild1@gmail.com>
parents:
10955
diff
changeset
|
901 if get(self.wanted, qclass, qtype, qname, co) then |
|
03a09fa02e8e
net.dns: Fix timeout retry logic
Matthew Wild <mwild1@gmail.com>
parents:
10955
diff
changeset
|
902 return self.timeout; -- Then wait |
|
3324
070c8ba71b76
net.dns: Handle our own timeouts, including falling onto other servers in resolv.conf if necessary
Matthew Wild <mwild1@gmail.com>
parents:
3057
diff
changeset
|
903 end |
|
070c8ba71b76
net.dns: Handle our own timeouts, including falling onto other servers in resolv.conf if necessary
Matthew Wild <mwild1@gmail.com>
parents:
3057
diff
changeset
|
904 end) |
|
070c8ba71b76
net.dns: Handle our own timeouts, including falling onto other servers in resolv.conf if necessary
Matthew Wild <mwild1@gmail.com>
parents:
3057
diff
changeset
|
905 end |
|
3955
a096700d23d9
net.dns: resolver:query(): Handle getsocket() failures, and return true on success
Matthew Wild <mwild1@gmail.com>
parents:
3954
diff
changeset
|
906 return true; |
|
869
09019c452709
net.dns: Add methods necessary for allowing non-blocking DNS lookups
Matthew Wild <mwild1@gmail.com>
parents:
759
diff
changeset
|
907 end |
|
09019c452709
net.dns: Add methods necessary for allowing non-blocking DNS lookups
Matthew Wild <mwild1@gmail.com>
parents:
759
diff
changeset
|
908 |
|
6509
7cb69eba3e95
net.dns: Try next server if peer name can not be set (thanks wirehack7)
Kim Alvefur <zash@zash.se>
parents:
6508
diff
changeset
|
909 function resolver:servfail(sock, err) |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
910 -- Resend all queries for this server |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
911 |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
912 local num = self.socketset[sock] |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
913 |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
914 -- Socket is dead now |
|
6508
4a28b8320d7f
net.dns: Return new socket from servfail
Kim Alvefur <zash@zash.se>
parents:
6463
diff
changeset
|
915 sock = self:voidsocket(sock); |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
916 |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
917 -- Find all requests to the down server, and retry on the next server |
|
14078
d649d011df45
Use util.time.now() consistently instead of socket.gettime()
Link Mauve <linkmauve@linkmauve.fr>
parents:
13925
diff
changeset
|
918 self.time = time_now(); |
|
10955
7bcfac630b65
net.dns: Add some debug logging
Matthew Wild <mwild1@gmail.com>
parents:
10664
diff
changeset
|
919 log("debug", "servfail %d (of %d)", num, #self.server); |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
920 for id,queries in pairs(self.active) do |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
921 for question,o in pairs(queries) do |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
922 if o.server == num then -- This request was to the broken server |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
923 o.server = o.server + 1 -- Use next server |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
924 if o.server > #self.server then |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
925 o.server = 1; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
926 end |
| 337 | 927 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
928 o.retries = (o.retries or 0) + 1; |
|
10956
03a09fa02e8e
net.dns: Fix timeout retry logic
Matthew Wild <mwild1@gmail.com>
parents:
10955
diff
changeset
|
929 local retried; |
|
03a09fa02e8e
net.dns: Fix timeout retry logic
Matthew Wild <mwild1@gmail.com>
parents:
10955
diff
changeset
|
930 if o.retries < #self.server then |
|
03a09fa02e8e
net.dns: Fix timeout retry logic
Matthew Wild <mwild1@gmail.com>
parents:
10955
diff
changeset
|
931 sock, err = self:getsocket(o.server); |
|
03a09fa02e8e
net.dns: Fix timeout retry logic
Matthew Wild <mwild1@gmail.com>
parents:
10955
diff
changeset
|
932 if sock then |
|
03a09fa02e8e
net.dns: Fix timeout retry logic
Matthew Wild <mwild1@gmail.com>
parents:
10955
diff
changeset
|
933 retried = true; |
|
10957
8902cecbdd39
net.dns: Add jitter to spread queries and reduce failures due to congestion
Matthew Wild <mwild1@gmail.com>
parents:
10956
diff
changeset
|
934 if self.retry_jitter then |
|
8902cecbdd39
net.dns: Add jitter to spread queries and reduce failures due to congestion
Matthew Wild <mwild1@gmail.com>
parents:
10956
diff
changeset
|
935 local delay = self.delays[((o.retries-1)%#self.delays)+1] + (math.random()*self.retry_jitter); |
|
8902cecbdd39
net.dns: Add jitter to spread queries and reduce failures due to congestion
Matthew Wild <mwild1@gmail.com>
parents:
10956
diff
changeset
|
936 log("debug", "retry %d in %0.2fs", o.retries, delay); |
|
8902cecbdd39
net.dns: Add jitter to spread queries and reduce failures due to congestion
Matthew Wild <mwild1@gmail.com>
parents:
10956
diff
changeset
|
937 timer.add_task(delay, function () |
|
8902cecbdd39
net.dns: Add jitter to spread queries and reduce failures due to congestion
Matthew Wild <mwild1@gmail.com>
parents:
10956
diff
changeset
|
938 sock:send(o.packet); |
|
8902cecbdd39
net.dns: Add jitter to spread queries and reduce failures due to congestion
Matthew Wild <mwild1@gmail.com>
parents:
10956
diff
changeset
|
939 end); |
|
8902cecbdd39
net.dns: Add jitter to spread queries and reduce failures due to congestion
Matthew Wild <mwild1@gmail.com>
parents:
10956
diff
changeset
|
940 else |
|
10956
03a09fa02e8e
net.dns: Fix timeout retry logic
Matthew Wild <mwild1@gmail.com>
parents:
10955
diff
changeset
|
941 log("debug", "retry %d (immediate)", o.retries); |
|
03a09fa02e8e
net.dns: Fix timeout retry logic
Matthew Wild <mwild1@gmail.com>
parents:
10955
diff
changeset
|
942 sock:send(o.packet); |
|
10957
8902cecbdd39
net.dns: Add jitter to spread queries and reduce failures due to congestion
Matthew Wild <mwild1@gmail.com>
parents:
10956
diff
changeset
|
943 end |
|
10956
03a09fa02e8e
net.dns: Fix timeout retry logic
Matthew Wild <mwild1@gmail.com>
parents:
10955
diff
changeset
|
944 end |
|
12387
05c250fa335a
Spelling: Fix various spelling mistakes (thanks timeless)
Kim Alvefur <zash@zash.se>
parents:
10976
diff
changeset
|
945 end |
|
10956
03a09fa02e8e
net.dns: Fix timeout retry logic
Matthew Wild <mwild1@gmail.com>
parents:
10955
diff
changeset
|
946 if not retried then |
|
03a09fa02e8e
net.dns: Fix timeout retry logic
Matthew Wild <mwild1@gmail.com>
parents:
10955
diff
changeset
|
947 log("debug", 'tried all servers, giving up'); |
|
03a09fa02e8e
net.dns: Fix timeout retry logic
Matthew Wild <mwild1@gmail.com>
parents:
10955
diff
changeset
|
948 self:cancel(o.qclass, o.qtype, o.qname); |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
949 queries[question] = nil; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
950 end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
951 end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
952 end |
|
5266
5c3a3ef6b769
net.dns: Clean up query list when a server is marked down
Matthew Wild <mwild1@gmail.com>
parents:
4422
diff
changeset
|
953 if next(queries) == nil then |
|
5c3a3ef6b769
net.dns: Clean up query list when a server is marked down
Matthew Wild <mwild1@gmail.com>
parents:
4422
diff
changeset
|
954 self.active[id] = nil; |
|
5c3a3ef6b769
net.dns: Clean up query list when a server is marked down
Matthew Wild <mwild1@gmail.com>
parents:
4422
diff
changeset
|
955 end |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
956 end |
|
3540
bc139431830b
Monster whitespace commit (beware the whitespace monster).
Waqas Hussain <waqas20@gmail.com>
parents:
3513
diff
changeset
|
957 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
958 if num == self.best_server then |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
959 self.best_server = self.best_server + 1; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
960 if self.best_server > #self.server then |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
961 -- Exhausted all servers, try first again |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
962 self.best_server = 1; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
963 end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
964 end |
|
6509
7cb69eba3e95
net.dns: Try next server if peer name can not be set (thanks wirehack7)
Kim Alvefur <zash@zash.se>
parents:
6508
diff
changeset
|
965 return sock, err; |
|
1786
4016d8bc30b8
net.dns: Multiple internal changes and API extensions to allow for more reliable DNS lookups
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
966 end |
| 337 | 967 |
|
3327
b447682f2a8d
net.dns: Make timeout configurable (default 15s)
Matthew Wild <mwild1@gmail.com>
parents:
3326
diff
changeset
|
968 function resolver:settimeout(seconds) |
|
b447682f2a8d
net.dns: Make timeout configurable (default 15s)
Matthew Wild <mwild1@gmail.com>
parents:
3326
diff
changeset
|
969 self.timeout = seconds; |
|
b447682f2a8d
net.dns: Make timeout configurable (default 15s)
Matthew Wild <mwild1@gmail.com>
parents:
3326
diff
changeset
|
970 end |
|
b447682f2a8d
net.dns: Make timeout configurable (default 15s)
Matthew Wild <mwild1@gmail.com>
parents:
3326
diff
changeset
|
971 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
972 function resolver:receive(rset) -- - - - - - - - - - - - - - - - - receive |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
973 --print('receive'); print(self.socket); |
|
14078
d649d011df45
Use util.time.now() consistently instead of socket.gettime()
Link Mauve <linkmauve@linkmauve.fr>
parents:
13925
diff
changeset
|
974 self.time = time_now(); |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
975 rset = rset or self.socket; |
| 337 | 976 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
977 local response; |
|
7469
363e4a5e9b0a
net.dns: remove unused one-letter loop variables [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents:
7322
diff
changeset
|
978 for _, sock in pairs(rset) do |
| 337 | 979 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
980 if self.socketset[sock] then |
|
2619
04158baefa34
net.dns: Update for new socket API
Matthew Wild <mwild1@gmail.com>
parents:
2578
diff
changeset
|
981 local packet = sock:receive(); |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
982 if packet then |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
983 response = self:decode(packet); |
|
2278
8c10f13c0c20
modulemanager, net.dns: Remove trailing whitespace
Matthew Wild <mwild1@gmail.com>
parents:
2082
diff
changeset
|
984 if response and self.active[response.header.id] |
|
2081
b9bbb709d62e
net.dns: Be more strict about checking the DNS replies we receive
Matthew Wild <mwild1@gmail.com>
parents:
2069
diff
changeset
|
985 and self.active[response.header.id][response.question.raw] then |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
986 --print('received response'); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
987 --self.print(response); |
| 337 | 988 |
|
7469
363e4a5e9b0a
net.dns: remove unused one-letter loop variables [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents:
7322
diff
changeset
|
989 for _, rr in pairs(response.answer) do |
|
7059
7ec52755622f
Backout 88d54bec26b7 prior to release, as it certainly requires more testing
Matthew Wild <mwild1@gmail.com>
parents:
7056
diff
changeset
|
990 if rr.name:sub(-#response.question[1].name, -1) == response.question[1].name then |
|
7ec52755622f
Backout 88d54bec26b7 prior to release, as it certainly requires more testing
Matthew Wild <mwild1@gmail.com>
parents:
7056
diff
changeset
|
991 self:remember(rr, response.question[1].type) |
|
7ec52755622f
Backout 88d54bec26b7 prior to release, as it certainly requires more testing
Matthew Wild <mwild1@gmail.com>
parents:
7056
diff
changeset
|
992 end |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
993 end |
| 337 | 994 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
995 -- retire the query |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
996 local queries = self.active[response.header.id]; |
|
2082
1381b2071c2e
net.dns: Be more strict about the records we cache
Matthew Wild <mwild1@gmail.com>
parents:
2081
diff
changeset
|
997 queries[response.question.raw] = nil; |
|
12387
05c250fa335a
Spelling: Fix various spelling mistakes (thanks timeless)
Kim Alvefur <zash@zash.se>
parents:
10976
diff
changeset
|
998 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
999 if not next(queries) then self.active[response.header.id] = nil; end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1000 if not next(self.active) then self:closeall(); end |
| 337 | 1001 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1002 -- was the query on the wanted list? |
|
2301
8a01b0898679
net.dns: Fix for blocking dns lookups to find waiting coroutines correctly (not that we use this in Prosody...)
Matthew Wild <mwild1@gmail.com>
parents:
2300
diff
changeset
|
1003 local q = response.question[1]; |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1004 local cos = get(self.wanted, q.class, q.type, q.name); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1005 if cos then |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1006 for co in pairs(cos) do |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1007 if coroutine.status(co) == "suspended" then coroutine.resume(co); end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1008 end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1009 set(self.wanted, q.class, q.type, q.name, nil); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1010 end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1011 end |
|
12387
05c250fa335a
Spelling: Fix various spelling mistakes (thanks timeless)
Kim Alvefur <zash@zash.se>
parents:
10976
diff
changeset
|
1012 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1013 end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1014 end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1015 end |
| 337 | 1016 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1017 return response; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1018 end |
| 337 | 1019 |
| 1020 | |
|
3512
e344b00f2cc9
net.dns: Add 'force' parameter to resolver:feed() to force decoding a packet even if it doesn't match an outstanding request
Matthew Wild <mwild1@gmail.com>
parents:
3360
diff
changeset
|
1021 function resolver:feed(sock, packet, force) |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1022 --print('receive'); print(self.socket); |
|
14078
d649d011df45
Use util.time.now() consistently instead of socket.gettime()
Link Mauve <linkmauve@linkmauve.fr>
parents:
13925
diff
changeset
|
1023 self.time = time_now(); |
|
869
09019c452709
net.dns: Add methods necessary for allowing non-blocking DNS lookups
Matthew Wild <mwild1@gmail.com>
parents:
759
diff
changeset
|
1024 |
|
3512
e344b00f2cc9
net.dns: Add 'force' parameter to resolver:feed() to force decoding a packet even if it doesn't match an outstanding request
Matthew Wild <mwild1@gmail.com>
parents:
3360
diff
changeset
|
1025 local response = self:decode(packet, force); |
|
2300
e182b5029ef2
net.dns: Port some DNS fixes to the resolver:feed() function for net.adns to use
Matthew Wild <mwild1@gmail.com>
parents:
2278
diff
changeset
|
1026 if response and self.active[response.header.id] |
|
e182b5029ef2
net.dns: Port some DNS fixes to the resolver:feed() function for net.adns to use
Matthew Wild <mwild1@gmail.com>
parents:
2278
diff
changeset
|
1027 and self.active[response.header.id][response.question.raw] then |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1028 --print('received response'); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1029 --self.print(response); |
|
869
09019c452709
net.dns: Add methods necessary for allowing non-blocking DNS lookups
Matthew Wild <mwild1@gmail.com>
parents:
759
diff
changeset
|
1030 |
|
7469
363e4a5e9b0a
net.dns: remove unused one-letter loop variables [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents:
7322
diff
changeset
|
1031 for _, rr in pairs(response.answer) do |
|
8897
102242a7ee60
net.dns: Cache all records from the 'answer' section (fixes #487)
Kim Alvefur <zash@zash.se>
parents:
8421
diff
changeset
|
1032 self:remember(rr, rr.type); |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1033 end |
|
869
09019c452709
net.dns: Add methods necessary for allowing non-blocking DNS lookups
Matthew Wild <mwild1@gmail.com>
parents:
759
diff
changeset
|
1034 |
|
8898
e6ba0e5260b4
net.dns: Also cache records from the 'additional' section
Kim Alvefur <zash@zash.se>
parents:
8897
diff
changeset
|
1035 for _, rr in pairs(response.additional) do |
|
e6ba0e5260b4
net.dns: Also cache records from the 'additional' section
Kim Alvefur <zash@zash.se>
parents:
8897
diff
changeset
|
1036 self:remember(rr, rr.type); |
|
e6ba0e5260b4
net.dns: Also cache records from the 'additional' section
Kim Alvefur <zash@zash.se>
parents:
8897
diff
changeset
|
1037 end |
|
e6ba0e5260b4
net.dns: Also cache records from the 'additional' section
Kim Alvefur <zash@zash.se>
parents:
8897
diff
changeset
|
1038 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1039 -- retire the query |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1040 local queries = self.active[response.header.id]; |
|
2300
e182b5029ef2
net.dns: Port some DNS fixes to the resolver:feed() function for net.adns to use
Matthew Wild <mwild1@gmail.com>
parents:
2278
diff
changeset
|
1041 queries[response.question.raw] = nil; |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1042 if not next(queries) then self.active[response.header.id] = nil; end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1043 if not next(self.active) then self:closeall(); end |
|
869
09019c452709
net.dns: Add methods necessary for allowing non-blocking DNS lookups
Matthew Wild <mwild1@gmail.com>
parents:
759
diff
changeset
|
1044 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1045 -- was the query on the wanted list? |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1046 local q = response.question[1]; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1047 if q then |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1048 local cos = get(self.wanted, q.class, q.type, q.name); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1049 if cos then |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1050 for co in pairs(cos) do |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1051 if coroutine.status(co) == "suspended" then coroutine.resume(co); end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1052 end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1053 set(self.wanted, q.class, q.type, q.name, nil); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1054 end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1055 end |
|
2742
6c0a081cd766
net.dns: Trailing whitespace
Matthew Wild <mwild1@gmail.com>
parents:
2741
diff
changeset
|
1056 end |
|
869
09019c452709
net.dns: Add methods necessary for allowing non-blocking DNS lookups
Matthew Wild <mwild1@gmail.com>
parents:
759
diff
changeset
|
1057 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1058 return response; |
|
869
09019c452709
net.dns: Add methods necessary for allowing non-blocking DNS lookups
Matthew Wild <mwild1@gmail.com>
parents:
759
diff
changeset
|
1059 end |
|
09019c452709
net.dns: Add methods necessary for allowing non-blocking DNS lookups
Matthew Wild <mwild1@gmail.com>
parents:
759
diff
changeset
|
1060 |
|
6309
b6f76a52eb36
net.dns: Ensure all pending requests get notified of a timeout when looking up a record (fix for d122420542fb)
Matthew Wild <mwild1@gmail.com>
parents:
6288
diff
changeset
|
1061 function resolver:cancel(qclass, qtype, qname) |
|
3326
fb95015bc646
net.dns, net.adns: Update resolver:cancel() API so that a table doesn't need to be created for each cancellation internal to net.dns
Matthew Wild <mwild1@gmail.com>
parents:
3325
diff
changeset
|
1062 local cos = get(self.wanted, qclass, qtype, qname); |
|
1202
e69fafc14491
net.dns: Add support for cancelling a coroutine-based request
Matthew Wild <mwild1@gmail.com>
parents:
896
diff
changeset
|
1063 if cos then |
|
6309
b6f76a52eb36
net.dns: Ensure all pending requests get notified of a timeout when looking up a record (fix for d122420542fb)
Matthew Wild <mwild1@gmail.com>
parents:
6288
diff
changeset
|
1064 for co in pairs(cos) do |
|
b6f76a52eb36
net.dns: Ensure all pending requests get notified of a timeout when looking up a record (fix for d122420542fb)
Matthew Wild <mwild1@gmail.com>
parents:
6288
diff
changeset
|
1065 if coroutine.status(co) == "suspended" then coroutine.resume(co); end |
|
3325
b3117a1da834
net.dns, net.adns: Move coroutine-calling logic into resolver:cancel()
Matthew Wild <mwild1@gmail.com>
parents:
3324
diff
changeset
|
1066 end |
|
6309
b6f76a52eb36
net.dns: Ensure all pending requests get notified of a timeout when looking up a record (fix for d122420542fb)
Matthew Wild <mwild1@gmail.com>
parents:
6288
diff
changeset
|
1067 set(self.wanted, qclass, qtype, qname, nil); |
|
1202
e69fafc14491
net.dns: Add support for cancelling a coroutine-based request
Matthew Wild <mwild1@gmail.com>
parents:
896
diff
changeset
|
1068 end |
|
e69fafc14491
net.dns: Add support for cancelling a coroutine-based request
Matthew Wild <mwild1@gmail.com>
parents:
896
diff
changeset
|
1069 end |
|
869
09019c452709
net.dns: Add methods necessary for allowing non-blocking DNS lookups
Matthew Wild <mwild1@gmail.com>
parents:
759
diff
changeset
|
1070 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1071 function resolver:pulse() -- - - - - - - - - - - - - - - - - - - - - pulse |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1072 --print(':pulse'); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1073 while self:receive() do end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1074 if not next(self.active) then return nil; end |
| 337 | 1075 |
|
14078
d649d011df45
Use util.time.now() consistently instead of socket.gettime()
Link Mauve <linkmauve@linkmauve.fr>
parents:
13925
diff
changeset
|
1076 self.time = time_now(); |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1077 for id,queries in pairs(self.active) do |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1078 for question,o in pairs(queries) do |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1079 if self.time >= o.retry then |
| 337 | 1080 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1081 o.server = o.server + 1; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1082 if o.server > #self.server then |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1083 o.server = 1; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1084 o.delay = o.delay + 1; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1085 end |
| 337 | 1086 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1087 if o.delay > #self.delays then |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1088 --print('timeout'); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1089 queries[question] = nil; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1090 if not next(queries) then self.active[id] = nil; end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1091 if not next(self.active) then return nil; end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1092 else |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1093 --print('retry', o.server, o.delay); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1094 local _a = self.socket[o.server]; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1095 if _a then _a:send(o.packet); end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1096 o.retry = self.time + self.delays[o.delay]; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1097 end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1098 end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1099 end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1100 end |
| 337 | 1101 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1102 if next(self.active) then return true; end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1103 return nil; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1104 end |
| 337 | 1105 |
| 1106 | |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1107 function resolver:lookup(qname, qtype, qclass) -- - - - - - - - - - lookup |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1108 self:query (qname, qtype, qclass) |
|
3049
e54774bd73a7
net/dns: Fix socket.select timeout.
Brian Cully <bjc@junctionnetworks.com>
parents:
2742
diff
changeset
|
1109 while self:pulse() do |
|
3540
bc139431830b
Monster whitespace commit (beware the whitespace monster).
Waqas Hussain <waqas20@gmail.com>
parents:
3513
diff
changeset
|
1110 local recvt = {} |
|
bc139431830b
Monster whitespace commit (beware the whitespace monster).
Waqas Hussain <waqas20@gmail.com>
parents:
3513
diff
changeset
|
1111 for i, s in ipairs(self.socket) do |
|
bc139431830b
Monster whitespace commit (beware the whitespace monster).
Waqas Hussain <waqas20@gmail.com>
parents:
3513
diff
changeset
|
1112 recvt[i] = s |
|
bc139431830b
Monster whitespace commit (beware the whitespace monster).
Waqas Hussain <waqas20@gmail.com>
parents:
3513
diff
changeset
|
1113 end |
|
bc139431830b
Monster whitespace commit (beware the whitespace monster).
Waqas Hussain <waqas20@gmail.com>
parents:
3513
diff
changeset
|
1114 socket.select(recvt, nil, 4) |
|
bc139431830b
Monster whitespace commit (beware the whitespace monster).
Waqas Hussain <waqas20@gmail.com>
parents:
3513
diff
changeset
|
1115 end |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1116 --print(self.cache); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1117 return self:peek(qname, qtype, qclass); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1118 end |
| 337 | 1119 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1120 function resolver:lookupex(handler, qname, qtype, qclass) -- - - - - - - - - - lookup |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1121 return self:peek(qname, qtype, qclass) or self:query(qname, qtype, qclass); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1122 end |
| 337 | 1123 |
|
3746
9719316c854e
net.dns: Add resolver:tohostname() and dns.tohostname()
Matthew Wild <mwild1@gmail.com>
parents:
3719
diff
changeset
|
1124 function resolver:tohostname(ip) |
|
9719316c854e
net.dns: Add resolver:tohostname() and dns.tohostname()
Matthew Wild <mwild1@gmail.com>
parents:
3719
diff
changeset
|
1125 return dns.lookup(ip:gsub("(%d+)%.(%d+)%.(%d+)%.(%d+)", "%4.%3.%2.%1.in-addr.arpa."), "PTR"); |
|
9719316c854e
net.dns: Add resolver:tohostname() and dns.tohostname()
Matthew Wild <mwild1@gmail.com>
parents:
3719
diff
changeset
|
1126 end |
|
869
09019c452709
net.dns: Add methods necessary for allowing non-blocking DNS lookups
Matthew Wild <mwild1@gmail.com>
parents:
759
diff
changeset
|
1127 |
|
09019c452709
net.dns: Add methods necessary for allowing non-blocking DNS lookups
Matthew Wild <mwild1@gmail.com>
parents:
759
diff
changeset
|
1128 --print ---------------------------------------------------------------- print |
| 337 | 1129 |
| 1130 | |
| 1131 local hints = { -- - - - - - - - - - - - - - - - - - - - - - - - - - - hints | |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1132 qr = { [0]='query', 'response' }, |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1133 opcode = { [0]='query', 'inverse query', 'server status request' }, |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1134 aa = { [0]='non-authoritative', 'authoritative' }, |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1135 tc = { [0]='complete', 'truncated' }, |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1136 rd = { [0]='recursion not desired', 'recursion desired' }, |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1137 ra = { [0]='recursion not available', 'recursion available' }, |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1138 z = { [0]='(reserved)' }, |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1139 rcode = { [0]='no error', 'format error', 'server failure', 'name error', 'not implemented' }, |
| 337 | 1140 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1141 type = dns.type, |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1142 class = dns.class |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1143 }; |
| 337 | 1144 |
| 1145 | |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1146 local function hint(p, s) -- - - - - - - - - - - - - - - - - - - - - - hint |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1147 return (hints[s] and hints[s][p[s]]) or ''; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1148 end |
| 337 | 1149 |
| 1150 | |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1151 function resolver.print(response) -- - - - - - - - - - - - - resolver.print |
|
7480
3dc7de31d3d1
net.dns: don't use "for s,s in pairs..." (unused loop variable s) [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents:
7469
diff
changeset
|
1152 for _, s in pairs { 'id', 'qr', 'opcode', 'aa', 'tc', 'rd', 'ra', 'z', |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1153 'rcode', 'qdcount', 'ancount', 'nscount', 'arcount' } do |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1154 print( string.format('%-30s', 'header.'..s), response.header[s], hint(response.header, s) ); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1155 end |
| 337 | 1156 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1157 for i,question in ipairs(response.question) do |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1158 print(string.format ('question[%i].name ', i), question.name); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1159 print(string.format ('question[%i].type ', i), question.type); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1160 print(string.format ('question[%i].class ', i), question.class); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1161 end |
| 337 | 1162 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1163 local common = { name=1, type=1, class=1, ttl=1, rdlength=1, rdata=1 }; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1164 local tmp; |
|
7480
3dc7de31d3d1
net.dns: don't use "for s,s in pairs..." (unused loop variable s) [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents:
7469
diff
changeset
|
1165 for _, s in pairs({'answer', 'authority', 'additional'}) do |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1166 for i,rr in pairs(response[s]) do |
|
7500
4c519444d4a2
net.dns: remove unused one-letter loop variables [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents:
7480
diff
changeset
|
1167 for _, t in pairs({ 'name', 'type', 'class', 'ttl', 'rdlength' }) do |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1168 tmp = string.format('%s[%i].%s', s, i, t); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1169 print(string.format('%-30s', tmp), rr[t], hint(rr, t)); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1170 end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1171 for j,t in pairs(rr) do |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1172 if not common[j] then |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1173 tmp = string.format('%s[%i].%s', s, i, j); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1174 print(string.format('%-30s %s', tostring(tmp), tostring(t))); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1175 end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1176 end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1177 end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1178 end |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1179 end |
| 337 | 1180 |
| 1181 | |
| 1182 -- module api ------------------------------------------------------ module api | |
| 1183 | |
| 1184 | |
| 1185 function dns.resolver () -- - - - - - - - - - - - - - - - - - - - - resolver | |
|
6310
d232bb1bbe1e
net.dns: Remove unused obsolete code
Matthew Wild <mwild1@gmail.com>
parents:
6309
diff
changeset
|
1186 local r = { active = {}, cache = {}, unsorted = {}, wanted = {}, best_server = 1 }; |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1187 setmetatable (r, resolver); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1188 setmetatable (r.cache, cache_metatable); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1189 setmetatable (r.unsorted, { __mode = 'kv' }); |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1190 return r; |
|
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1191 end |
| 337 | 1192 |
|
2573
60493186fef6
net.dns: Removed some useless indirection to improve readability.
Waqas Hussain <waqas20@gmail.com>
parents:
2425
diff
changeset
|
1193 local _resolver = dns.resolver(); |
|
60493186fef6
net.dns: Removed some useless indirection to improve readability.
Waqas Hussain <waqas20@gmail.com>
parents:
2425
diff
changeset
|
1194 dns._resolver = _resolver; |
|
10976
540f1bc5f082
net.dns: Disable jitter for default resolver (used by blocking dns.lookup() calls)
Matthew Wild <mwild1@gmail.com>
parents:
10959
diff
changeset
|
1195 _resolver.jitter, _resolver.retry_jitter = false, false; |
| 337 | 1196 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1197 function dns.lookup(...) -- - - - - - - - - - - - - - - - - - - - - lookup |
|
2573
60493186fef6
net.dns: Removed some useless indirection to improve readability.
Waqas Hussain <waqas20@gmail.com>
parents:
2425
diff
changeset
|
1198 return _resolver:lookup(...); |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1199 end |
| 337 | 1200 |
|
3746
9719316c854e
net.dns: Add resolver:tohostname() and dns.tohostname()
Matthew Wild <mwild1@gmail.com>
parents:
3719
diff
changeset
|
1201 function dns.tohostname(...) |
|
9719316c854e
net.dns: Add resolver:tohostname() and dns.tohostname()
Matthew Wild <mwild1@gmail.com>
parents:
3719
diff
changeset
|
1202 return _resolver:tohostname(...); |
|
9719316c854e
net.dns: Add resolver:tohostname() and dns.tohostname()
Matthew Wild <mwild1@gmail.com>
parents:
3719
diff
changeset
|
1203 end |
|
9719316c854e
net.dns: Add resolver:tohostname() and dns.tohostname()
Matthew Wild <mwild1@gmail.com>
parents:
3719
diff
changeset
|
1204 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1205 function dns.purge(...) -- - - - - - - - - - - - - - - - - - - - - - purge |
|
2573
60493186fef6
net.dns: Removed some useless indirection to improve readability.
Waqas Hussain <waqas20@gmail.com>
parents:
2425
diff
changeset
|
1206 return _resolver:purge(...); |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1207 end |
| 337 | 1208 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1209 function dns.peek(...) -- - - - - - - - - - - - - - - - - - - - - - - peek |
|
2573
60493186fef6
net.dns: Removed some useless indirection to improve readability.
Waqas Hussain <waqas20@gmail.com>
parents:
2425
diff
changeset
|
1210 return _resolver:peek(...); |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1211 end |
| 337 | 1212 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1213 function dns.query(...) -- - - - - - - - - - - - - - - - - - - - - - query |
|
2573
60493186fef6
net.dns: Removed some useless indirection to improve readability.
Waqas Hussain <waqas20@gmail.com>
parents:
2425
diff
changeset
|
1214 return _resolver:query(...); |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1215 end |
| 337 | 1216 |
|
2575
8f4d69940132
net.dns: Fixed whitespace/indentation.
Waqas Hussain <waqas20@gmail.com>
parents:
2574
diff
changeset
|
1217 function dns.feed(...) -- - - - - - - - - - - - - - - - - - - - - - - feed |
|
2573
60493186fef6
net.dns: Removed some useless indirection to improve readability.
Waqas Hussain <waqas20@gmail.com>
parents:
2425
diff
changeset
|
1218 return _resolver:feed(...); |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1219 end |
|
869
09019c452709
net.dns: Add methods necessary for allowing non-blocking DNS lookups
Matthew Wild <mwild1@gmail.com>
parents:
759
diff
changeset
|
1220 |
|
2575
8f4d69940132
net.dns: Fixed whitespace/indentation.
Waqas Hussain <waqas20@gmail.com>
parents:
2574
diff
changeset
|
1221 function dns.cancel(...) -- - - - - - - - - - - - - - - - - - - - - - cancel |
|
2573
60493186fef6
net.dns: Removed some useless indirection to improve readability.
Waqas Hussain <waqas20@gmail.com>
parents:
2425
diff
changeset
|
1222 return _resolver:cancel(...); |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1223 end |
| 337 | 1224 |
|
3328
5ac4fbbfb74d
net.dns: Add dns.settimeout() to set the timeout for the default resolver
Matthew Wild <mwild1@gmail.com>
parents:
3327
diff
changeset
|
1225 function dns.settimeout(...) |
|
5ac4fbbfb74d
net.dns: Add dns.settimeout() to set the timeout for the default resolver
Matthew Wild <mwild1@gmail.com>
parents:
3327
diff
changeset
|
1226 return _resolver:settimeout(...); |
|
5ac4fbbfb74d
net.dns: Add dns.settimeout() to set the timeout for the default resolver
Matthew Wild <mwild1@gmail.com>
parents:
3327
diff
changeset
|
1227 end |
|
5ac4fbbfb74d
net.dns: Add dns.settimeout() to set the timeout for the default resolver
Matthew Wild <mwild1@gmail.com>
parents:
3327
diff
changeset
|
1228 |
|
5566
74ae3e7e8779
net.dns: Add nicer API to cached records
Kim Alvefur <zash@zash.se>
parents:
5340
diff
changeset
|
1229 function dns.cache() |
|
74ae3e7e8779
net.dns: Add nicer API to cached records
Kim Alvefur <zash@zash.se>
parents:
5340
diff
changeset
|
1230 return _resolver.cache; |
|
74ae3e7e8779
net.dns: Add nicer API to cached records
Kim Alvefur <zash@zash.se>
parents:
5340
diff
changeset
|
1231 end |
|
74ae3e7e8779
net.dns: Add nicer API to cached records
Kim Alvefur <zash@zash.se>
parents:
5340
diff
changeset
|
1232 |
|
2578
61e5eff54415
net.dns, net.adns: Changed dns:socket_wrapper_set to dns.socket_wrapper_set for consistency.
Waqas Hussain <waqas20@gmail.com>
parents:
2575
diff
changeset
|
1233 function dns.socket_wrapper_set(...) -- - - - - - - - - socket_wrapper_set |
|
2573
60493186fef6
net.dns: Removed some useless indirection to improve readability.
Waqas Hussain <waqas20@gmail.com>
parents:
2425
diff
changeset
|
1234 return _resolver:socket_wrapper_set(...); |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1235 end |
| 337 | 1236 |
|
2069
72357b1c6d88
net.dns: Fixed indentation and coding style.
Waqas Hussain <waqas20@gmail.com>
parents:
2068
diff
changeset
|
1237 return dns; |
