@@ -27,6 +27,7 @@ local TYPE_MX = 15
27
27
local TYPE_TXT = 16
28
28
local TYPE_AAAA = 28
29
29
local TYPE_SRV = 33
30
+ local TYPE_OPT = 41
30
31
local TYPE_SPF = 99
31
32
local TYPE_ANY = 255
32
33
@@ -280,7 +281,12 @@ function _M.decode_request(self, req)
280
281
-- parse RDATA(OPTION)
281
282
-- rfc7871, 6. Option Format
282
283
284
+
285
+ local rdata = nil
283
286
if rdlen > 0 then
287
+ -- get whole rdata
288
+ rdata = strsub (self .buf , self .pos + 1 , self .pos + rdlen )
289
+
284
290
-- parse OPTION-CODE
285
291
self .pos = self .pos + 2
286
292
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)
329
335
mask = source_prefix_len ,
330
336
family = opt_family }
331
337
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 }
332
344
else
333
345
ngx .log (ngx .WARN , " parse EDNS0 error. qname_len: " ,
334
346
qname_len , " opt_type: " , opt_type )
@@ -374,7 +386,6 @@ local function _encode_4byt(x)
374
386
return char (hi_hi , hi_lo , lo_hi , lo_lo )
375
387
end
376
388
377
-
378
389
local function _encode_2byt (x )
379
390
local hi = band (rshift (x , 8 ), 0x00FF )
380
391
local lo = band (x , 0x00FF )
@@ -460,12 +471,14 @@ function _M.encode_response(self)
460
471
end
461
472
462
473
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 )
464
475
buf = buf .. _encode_2byt (self .response .arsections [i ].type )
465
476
buf = buf .. _encode_2byt (self .response .arsections [i ].class )
466
477
buf = buf .. _encode_4byt (self .response .arsections [i ].ttl or 0x258 )
467
478
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
469
482
end
470
483
471
484
return buf
@@ -519,6 +532,17 @@ function _M.create_a_answer(self, name, ttl, ipv4)
519
532
return nil
520
533
end
521
534
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
+
522
546
523
547
function _M .create_cname_answer (self , name , ttl , cname )
524
548
if not name or # name == 0 then
0 commit comments