@@ -17,6 +17,16 @@ local openssl_ssl = require "openssl.ssl"
17
17
local openssl_ctx = require " openssl.ssl.context"
18
18
local openssl_verify_param = require " openssl.x509.verify_param"
19
19
20
+ local AF_UNSPEC = cs .AF_UNSPEC
21
+ local AF_UNIX = cs .AF_UNIX
22
+ local AF_INET = cs .AF_INET
23
+ local AF_INET6 = cs .AF_INET6
24
+
25
+ local DNS_CLASS_IN = cqueues_dns_record .IN
26
+ local DNS_TYPE_A = cqueues_dns_record .A
27
+ local DNS_TYPE_AAAA = cqueues_dns_record .AAAA
28
+ local DNS_TYPE_CNAME = cqueues_dns_record .CNAME
29
+
20
30
local EOF = lpeg .P (- 1 )
21
31
local IPv4address = IPv4_patts .IPv4address * EOF
22
32
local IPv6addrz = IPv6_patts .IPv6addrz * EOF
@@ -98,8 +108,8 @@ local function each_matching_record(pkt, name, type)
98
108
-- First need to do CNAME chasing
99
109
local params = {
100
110
section = " answer" ;
101
- class = cqueues_dns_record . IN ;
102
- type = cqueues_dns_record . CNAME ;
111
+ class = DNS_CLASS_IN ;
112
+ type = DNS_TYPE_CNAME ;
103
113
name = name .. " ." ;
104
114
}
105
115
for _ = 1 , 8 do -- avoid cname loops
@@ -123,9 +133,9 @@ local function dns_lookup(records, dns_resolver, host, port, query_type, filter_
123
133
end
124
134
for rec in each_matching_record (packet , host , filter_type ) do
125
135
local t = rec :type ()
126
- if t == cqueues_dns_record . AAAA then
136
+ if t == DNS_TYPE_AAAA then
127
137
records :add_v6 (rec :addr (), port )
128
- elseif t == cqueues_dns_record . A then
138
+ elseif t == DNS_TYPE_A then
129
139
records :add_v4 (rec :addr (), port )
130
140
end
131
141
end
@@ -149,7 +159,7 @@ function records_mt:__len()
149
159
end
150
160
151
161
local record_ipv4_methods = {
152
- family = cs . AF_INET ;
162
+ family = AF_INET ;
153
163
}
154
164
local record_ipv4_mt = {
155
165
__name = " http.client.record.ipv4" ;
@@ -162,7 +172,7 @@ function records_methods:add_v4(addr, port)
162
172
end
163
173
164
174
local record_ipv6_methods = {
165
- family = cs . AF_INET6 ;
175
+ family = AF_INET6 ;
166
176
}
167
177
local record_ipv6_mt = {
168
178
__name = " http.client.record.ipv6" ;
@@ -182,7 +192,7 @@ function records_methods:add_v6(addr, port)
182
192
end
183
193
184
194
local record_unix_methods = {
185
- family = cs . AF_UNIX ;
195
+ family = AF_UNIX ;
186
196
}
187
197
local record_unix_mt = {
188
198
__name = " http.client.record.unix" ;
@@ -210,14 +220,14 @@ end
210
220
local function lookup_records (options , timeout )
211
221
local family = options .family
212
222
if family == nil then
213
- family = cs . AF_UNSPEC
223
+ family = AF_UNSPEC
214
224
end
215
225
216
226
local records = new_records ()
217
227
218
228
local path = options .path
219
229
if path then
220
- if family ~= cs . AF_UNSPEC and family ~= cs . AF_UNIX then
230
+ if family ~= AF_UNSPEC and family ~= AF_UNIX then
221
231
error (" cannot use .path with non-unix address family" )
222
232
end
223
233
records :add_unix (path )
@@ -240,14 +250,14 @@ local function lookup_records(options, timeout)
240
250
end
241
251
242
252
local dns_resolver = options .dns_resolver or cqueues_dns .getpool ()
243
- if family == cs . AF_UNSPEC then
253
+ if family == AF_UNSPEC then
244
254
local deadline = timeout and monotime ()+ timeout
245
- dns_lookup (records , dns_resolver , host , port , cqueues_dns_record . AAAA , nil , timeout )
246
- dns_lookup (records , dns_resolver , host , port , cqueues_dns_record . A , nil , deadline and deadline - monotime ())
247
- elseif family == cs . AF_INET then
248
- dns_lookup (records , dns_resolver , host , port , cqueues_dns_record . A , cqueues_dns_record . A , timeout )
249
- elseif family == cs . AF_INET6 then
250
- dns_lookup (records , dns_resolver , host , port , cqueues_dns_record . AAAA , cqueues_dns_record . AAAA , timeout )
255
+ dns_lookup (records , dns_resolver , host , port , DNS_TYPE_AAAA , nil , timeout )
256
+ dns_lookup (records , dns_resolver , host , port , DNS_TYPE_A , nil , deadline and deadline - monotime ())
257
+ elseif family == AF_INET then
258
+ dns_lookup (records , dns_resolver , host , port , DNS_TYPE_A , DNS_TYPE_A , timeout )
259
+ elseif family == AF_INET6 then
260
+ dns_lookup (records , dns_resolver , host , port , DNS_TYPE_AAAA , DNS_TYPE_AAAA , timeout )
251
261
end
252
262
253
263
return records
0 commit comments