Skip to content

Commit 6a1802e

Browse files
committed
added possibility to replay received opts
1 parent ff208a0 commit 6a1802e

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

lib/resty/dns/server.lua

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ function _M.decode_request(self, req)
285285
local rdata = nil
286286
if rdlen > 0 then
287287
-- get whole rdata
288-
rdata = byte(self.buf, self.pos - 1, self.pos + rdlen)
288+
rdata = strsub(self.buf, self.pos +1 , self.pos + rdlen)
289289

290290
-- parse OPTION-CODE
291291
self.pos = self.pos + 2
@@ -387,6 +387,12 @@ local function _encode_4byt(x)
387387
end
388388

389389

390+
local function _encode_1byt(x)
391+
local lo = band(x, 0xFF)
392+
393+
return char(lo)
394+
end
395+
390396
local function _encode_2byt(x)
391397
local hi = band(rshift(x, 8), 0x00FF)
392398
local lo = band(x, 0x00FF)
@@ -472,12 +478,14 @@ function _M.encode_response(self)
472478
end
473479

474480
for i = 1, self.response.header.arcount do
475-
buf = buf .. _encode_name(self.response.arsections[i].name)
481+
buf = buf .. _encode_name(self.response.arsections[i].name)
476482
buf = buf .. _encode_2byt(self.response.arsections[i].type)
477483
buf = buf .. _encode_2byt(self.response.arsections[i].class)
478484
buf = buf .. _encode_4byt(self.response.arsections[i].ttl or 0x258)
479485
buf = buf .. _encode_2byt(self.response.arsections[i].rdlength)
480-
buf = buf .. self.response.arsections[i].rdata
486+
if self.response.arsections[i].rdlength > 0 then
487+
buf = buf .. self.response.arsections[i].rdata
488+
i end
481489
end
482490

483491
return buf
@@ -531,7 +539,7 @@ function _M.create_a_answer(self, name, ttl, ipv4)
531539
return nil
532540
end
533541

534-
function _M.replay_additional_opt(self)
542+
function _M.replay_additional_opts(self)
535543

536544
for i = 1, #self.request.additionals do
537545
local additional = self.request.additionals[i]

0 commit comments

Comments
 (0)