@@ -27,6 +27,7 @@ local TYPE_MX = 15
2727local TYPE_TXT = 16
2828local TYPE_AAAA = 28
2929local TYPE_SRV = 33
30+ local TYPE_OPT = 41
3031local TYPE_SPF = 99
3132local TYPE_ANY = 255
3233
@@ -280,7 +281,12 @@ function _M.decode_request(self, req)
280281 -- parse RDATA(OPTION)
281282 -- rfc7871, 6. Option Format
282283
284+
285+ local rdata = nil
283286 if rdlen > 0 then
287+ -- get whole rdata
288+ rdata = strsub (self .buf , self .pos + 1 , self .pos + rdlen )
289+
284290 -- parse OPTION-CODE
285291 self .pos = self .pos + 2
286292 local opt_code_hi , opt_code_lo = byte (self .buf , self .pos - 1 , self .pos )
@@ -329,6 +335,12 @@ function _M.decode_request(self, req)
329335 mask = source_prefix_len ,
330336 family = opt_family }
331337 end
338+ self .request .additionals [# self .request .additionals + 1 ] = { name = " " ,
339+ type = opt_type ,
340+ class = udp_size ,
341+ ttl = ext_rcode ,
342+ rdlength = rdlen ,
343+ rdata = rdata }
332344 else
333345 ngx .log (ngx .WARN , " parse EDNS0 error. qname_len: " ,
334346 qname_len , " opt_type: " , opt_type )
@@ -374,7 +386,6 @@ local function _encode_4byt(x)
374386 return char (hi_hi , hi_lo , lo_hi , lo_lo )
375387end
376388
377-
378389local function _encode_2byt (x )
379390 local hi = band (rshift (x , 8 ), 0x00FF )
380391 local lo = band (x , 0x00FF )
@@ -460,12 +471,14 @@ function _M.encode_response(self)
460471 end
461472
462473 for i = 1 , self .response .header .arcount do
463- buf = buf .. _encode_name (self .response .arsections [i ].name )
474+ buf = buf .. _encode_name (self .response .arsections [i ].name )
464475 buf = buf .. _encode_2byt (self .response .arsections [i ].type )
465476 buf = buf .. _encode_2byt (self .response .arsections [i ].class )
466477 buf = buf .. _encode_4byt (self .response .arsections [i ].ttl or 0x258 )
467478 buf = buf .. _encode_2byt (self .response .arsections [i ].rdlength )
468- buf = buf .. self .response .arsections [i ].rdata
479+ if self .response .arsections [i ].rdlength > 0 then
480+ buf = buf .. self .response .arsections [i ].rdata
481+ end
469482 end
470483
471484 return buf
@@ -519,6 +532,17 @@ function _M.create_a_answer(self, name, ttl, ipv4)
519532 return nil
520533end
521534
535+ function _M .replay_additional_opts (self )
536+
537+ for i = 1 , # self .request .additionals do
538+ local additional = self .request .additionals [i ]
539+ self .response .header .arcount = self .response .header .arcount + 1
540+ self .response .arsections [self .response .header .arcount ] = additional
541+ end
542+
543+ return nil
544+ end
545+
522546
523547function _M .create_cname_answer (self , name , ttl , cname )
524548 if not name or # name == 0 then
0 commit comments