Skip to content

Commit bb93ee8

Browse files
authored
Merge pull request #84 from jelu/timeout
Timeout
2 parents 2f560bc + 3280fbb commit bb93ee8

File tree

15 files changed

+422
-154
lines changed

15 files changed

+422
-154
lines changed

examples/dumpdns-qr.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ while true do
2929
local pl = obj:cast()
3030
if obj:type() == "payload" and pl.len > 0 then
3131
local transport = obj.obj_prev
32-
while transport do
32+
while transport ~= nil do
3333
if transport.obj_type == object.IP or transport.obj_type == object.IP6 then
3434
break
3535
end
3636
transport = transport.obj_prev
3737
end
3838
local protocol = obj.obj_prev
39-
while protocol do
39+
while protocol ~= nil do
4040
if protocol.obj_type == object.UDP or protocol.obj_type == object.TCP then
4141
break
4242
end

examples/dumpdns.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ while true do
2121
local pl = obj:cast()
2222
if obj:type() == "payload" and pl.len > 0 then
2323
local transport = obj.obj_prev
24-
while transport do
24+
while transport ~= nil do
2525
if transport.obj_type == object.IP or transport.obj_type == object.IP6 then
2626
break
2727
end
2828
transport = transport.obj_prev
2929
end
3030
local protocol = obj.obj_prev
31-
while protocol do
31+
while protocol ~= nil do
3232
if protocol.obj_type == object.UDP or protocol.obj_type == object.TCP then
3333
break
3434
end

examples/filter_rcode.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ while true do
2222
local pl = obj:cast()
2323
if obj:type() == "payload" and pl.len > 0 then
2424
local transport = obj.obj_prev
25-
while transport do
25+
while transport ~= nil do
2626
if transport.obj_type == object.IP or transport.obj_type == object.IP6 then
2727
break
2828
end

examples/replay.lua

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,17 @@ if printdns then
6767

6868
recv(rctx, obj)
6969

70-
local resp = nil
71-
while resp == nil do
72-
resp = oprod(opctx)
70+
local response = oprod(opctx)
71+
if response == nil then
72+
log.fatal("producer error")
7373
end
74-
while resp ~= nil do
74+
local payload = response:cast()
75+
if payload.len == 0 then
76+
print("timed out")
77+
else
7578
dns.obj_prev = resp
7679
print("response:")
7780
dns:print()
78-
resp = oprod(opctx)
7981
end
8082
end
8183
end

examples/respdiff.lua

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,14 @@ while true do
6666
dns.obj_prev = obj
6767
if dns:parse_header() == 0 then
6868
local transport = obj.obj_prev
69-
while transport do
69+
while transport ~= nil do
7070
if transport.obj_type == object.IP or transport.obj_type == object.IP6 then
7171
break
7272
end
7373
transport = transport.obj_prev
7474
end
7575
local protocol = obj.obj_prev
76-
while protocol do
76+
while protocol ~= nil do
7777
if protocol.obj_type == object.UDP or protocol.obj_type == object.TCP then
7878
break
7979
end
@@ -102,7 +102,8 @@ while true do
102102
clipayload.payload = q.payload
103103
clipayload.len = q.len
104104

105-
local responses, response = {}, nil
105+
local prod, pctx
106+
106107
if q.proto == "udp" then
107108
if not udpcli then
108109
udpcli = require("dnsjit.output.udpcli").new()
@@ -111,13 +112,8 @@ while true do
111112
udpprod, _ = udpcli:produce()
112113
end
113114
udprecv(udpctx, cliobject)
114-
while response == nil do
115-
response = udpprod(udpctx)
116-
end
117-
while response ~= nil do
118-
table.insert(responses, response)
119-
response = udpprod(udpctx)
120-
end
115+
prod = udpprod
116+
pctx = udpctx
121117
elseif q.proto == "tcp" then
122118
if not tcpcli then
123119
tcpcli = require("dnsjit.output.tcpcli").new()
@@ -126,27 +122,31 @@ while true do
126122
tcpprod, _ = tcpcli:produce()
127123
end
128124
tcprecv(tcpctx, cliobject)
129-
while response == nil do
130-
response = tcpprod(tcpctx)
131-
end
132-
while response ~= nil do
133-
table.insert(responses, response)
134-
response = tcpprod(tcpctx)
135-
end
125+
prod = tcpprod
126+
pctx = tcpctx
136127
end
137128

138-
for _, response in pairs(responses) do
139-
dns.obj_prev = response
140-
if dns:parse_header() == 0 and dns.id == q.id then
141-
query_payload.payload = q.payload
142-
query_payload.len = q.len
143-
original_payload.payload = payload.payload
144-
original_payload.len = payload.len
145-
response = response:cast()
146-
response_payload.payload = response.payload
147-
response_payload.len = response.len
129+
while true do
130+
local response = prod(pctx)
131+
if response == nil then
132+
log.fatal("producer error")
133+
end
134+
local rpl = response:cast()
135+
if rpl.len == 0 then
136+
log.info("timed out")
137+
else
138+
dns.obj_prev = response
139+
if dns:parse_header() == 0 and dns.id == q.id then
140+
query_payload.payload = q.payload
141+
query_payload.len = q.len
142+
original_payload.payload = payload.payload
143+
original_payload.len = payload.len
144+
response_payload.payload = rpl.payload
145+
response_payload.len = rpl.len
148146

149-
resprecv(respctx, query_payload_obj)
147+
resprecv(respctx, query_payload_obj)
148+
break
149+
end
150150
end
151151
end
152152
end

examples/test_throughput.lua

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,96 @@ if getopt:val("s") then
232232

233233
print(run, "runtime", runtime, num/runtime, "/sec", o1:packets() + o2:packets() + o3:packets() + o4:packets(), o1:packets(), o2:packets(), o3:packets(), o4:packets())
234234
end
235+
236+
print("zero:receiver() -> lua split table -> null:receive() x4")
237+
local run
238+
for run = 1, runs do
239+
local i = require("dnsjit.input.zero").new()
240+
local o1 = require("dnsjit.output.null").new()
241+
local o2 = require("dnsjit.output.null").new()
242+
local o3 = require("dnsjit.output.null").new()
243+
local o4 = require("dnsjit.output.null").new()
244+
245+
local prod, pctx = i:produce()
246+
local recv, rctx = {}, {}
247+
248+
local f, c = o1:receive()
249+
table.insert(recv, f)
250+
table.insert(rctx, c)
251+
f, c = o2:receive()
252+
table.insert(recv, f)
253+
table.insert(rctx, c)
254+
f, c = o3:receive()
255+
table.insert(recv, f)
256+
table.insert(rctx, c)
257+
f, c = o4:receive()
258+
table.insert(recv, f)
259+
table.insert(rctx, c)
260+
261+
local start_sec, start_nsec = clock:monotonic()
262+
local idx = 1
263+
for n = 1, num do
264+
local f, c = recv[idx], rctx[idx]
265+
if not f then
266+
idx = 1
267+
f, c = recv[1], rctx[1]
268+
end
269+
f(c, prod(pctx))
270+
idx = idx + 1
271+
end
272+
local end_sec, end_nsec = clock:monotonic()
273+
274+
local runtime = 0
275+
if end_sec > start_sec then
276+
runtime = ((end_sec - start_sec) - 1) + ((1000000000 - start_nsec + end_nsec)/1000000000)
277+
elseif end_sec == start_sec and end_nsec > start_nsec then
278+
runtime = (end_nsec - start_nsec) / 1000000000
279+
end
280+
281+
print(run, "runtime", runtime, num/runtime, "/sec", o1:packets() + o2:packets() + o3:packets() + o4:packets(), o1:packets(), o2:packets(), o3:packets(), o4:packets())
282+
end
283+
284+
print("zero:receiver() -> lua split gen code -> null:receive() x4")
285+
local run
286+
for run = 1, runs do
287+
local i = require("dnsjit.input.zero").new()
288+
local o1 = require("dnsjit.output.null").new()
289+
local o2 = require("dnsjit.output.null").new()
290+
local o3 = require("dnsjit.output.null").new()
291+
local o4 = require("dnsjit.output.null").new()
292+
293+
local prod, pctx = i:produce()
294+
local f1, c1 = o1:receive()
295+
local f2, c2 = o2:receive()
296+
local f3, c3 = o3:receive()
297+
local f4, c4 = o4:receive()
298+
299+
local code = "return function (num, prod, pctx, f1, c1, f2, c2, f3, c3, f4, c4)\nlocal n = 0\nwhile n < num do\n"
300+
code = code .. "f1(c1,prod(pctx))\n"
301+
code = code .. "n = n + 1\n"
302+
code = code .. "f2(c2,prod(pctx))\n"
303+
code = code .. "n = n + 1\n"
304+
code = code .. "f3(c3,prod(pctx))\n"
305+
code = code .. "n = n + 1\n"
306+
code = code .. "f4(c4,prod(pctx))\n"
307+
code = code .. "n = n + 1\n"
308+
code = code .. "end\n"
309+
code = code .. "end"
310+
local f = assert(loadstring(code))()
311+
312+
local start_sec, start_nsec = clock:monotonic()
313+
f(num, prod, pctx, f1, c1, f2, c2, f3, c3, f4, c4)
314+
local end_sec, end_nsec = clock:monotonic()
315+
316+
local runtime = 0
317+
if end_sec > start_sec then
318+
runtime = ((end_sec - start_sec) - 1) + ((1000000000 - start_nsec + end_nsec)/1000000000)
319+
elseif end_sec == start_sec and end_nsec > start_nsec then
320+
runtime = (end_nsec - start_nsec) / 1000000000
321+
end
322+
323+
print(run, "runtime", runtime, num/runtime, "/sec", o1:packets() + o2:packets() + o3:packets() + o4:packets(), o1:packets(), o2:packets(), o3:packets(), o4:packets())
324+
end
235325
end
236326

237327
if getopt:val("t") then

src/core/object/dns.lua

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -671,44 +671,52 @@ function Dns:print(num_labels)
671671
print("", "nscount:", self.nscount)
672672
print("", "arcount:", self.arcount)
673673

674-
print("", "questions:")
675-
for n = 1, self.qdcount do
676-
if C.core_object_dns_parse_q(self, q, labels, num_labels) ~= 0 then
677-
return
674+
if self.qdcount > 0 then
675+
print("questions:", "class", "type", "labels")
676+
for n = 1, self.qdcount do
677+
if C.core_object_dns_parse_q(self, q, labels, num_labels) ~= 0 then
678+
return
679+
end
680+
print("", Dns.class_tostring(q.class), Dns.type_tostring(q.type), label.tooffstr(self, labels, num_labels))
678681
end
679-
print("", "", Dns.class_tostring(q.class), Dns.type_tostring(q.type), label.tooffstr(self, labels, num_labels))
680682
end
681-
print("", "answers:")
682-
for n = 1, self.ancount do
683-
if C.core_object_dns_parse_rr(self, rr, labels, num_labels) ~= 0 then
684-
return
685-
end
686-
if rr.rdata_labels == 0 then
687-
print("", "", Dns.class_tostring(rr.class), Dns.type_tostring(rr.type), rr.ttl, label.tooffstr(self, labels, rr.labels))
688-
else
689-
print("", "", Dns.class_tostring(rr.class), Dns.type_tostring(rr.type), rr.ttl, label.tooffstr(self, labels, rr.labels), label.tooffstr(self, labels, rr.rdata_labels, rr.labels))
683+
if self.ancount > 0 then
684+
print("answers:", "class", "type", "ttl", "labels", "RR labels")
685+
for n = 1, self.ancount do
686+
if C.core_object_dns_parse_rr(self, rr, labels, num_labels) ~= 0 then
687+
return
688+
end
689+
if rr.rdata_labels == 0 then
690+
print("", Dns.class_tostring(rr.class), Dns.type_tostring(rr.type), rr.ttl, label.tooffstr(self, labels, rr.labels))
691+
else
692+
print("", Dns.class_tostring(rr.class), Dns.type_tostring(rr.type), rr.ttl, label.tooffstr(self, labels, rr.labels), label.tooffstr(self, labels, rr.rdata_labels, rr.labels))
693+
end
690694
end
691695
end
692-
print("", "authorities:")
693-
for n = 1, self.nscount do
694-
if C.core_object_dns_parse_rr(self, rr, labels, num_labels) ~= 0 then
695-
return
696-
end
697-
if rr.rdata_labels == 0 then
698-
print("", "", Dns.class_tostring(rr.class), Dns.type_tostring(rr.type), rr.ttl, label.tooffstr(self, labels, rr.labels))
699-
else
700-
print("", "", Dns.class_tostring(rr.class), Dns.type_tostring(rr.type), rr.ttl, label.tooffstr(self, labels, rr.labels), label.tooffstr(self, labels, rr.rdata_labels, rr.labels))
696+
if self.nscount > 0 then
697+
print("authorities:", "class", "type", "ttl", "labels", "RR labels")
698+
for n = 1, self.nscount do
699+
if C.core_object_dns_parse_rr(self, rr, labels, num_labels) ~= 0 then
700+
return
701+
end
702+
if rr.rdata_labels == 0 then
703+
print("", Dns.class_tostring(rr.class), Dns.type_tostring(rr.type), rr.ttl, label.tooffstr(self, labels, rr.labels))
704+
else
705+
print("", Dns.class_tostring(rr.class), Dns.type_tostring(rr.type), rr.ttl, label.tooffstr(self, labels, rr.labels), label.tooffstr(self, labels, rr.rdata_labels, rr.labels))
706+
end
701707
end
702708
end
703-
print("", "additionals:")
704-
for n = 1, self.arcount do
705-
if C.core_object_dns_parse_rr(self, rr, labels, num_labels) ~= 0 then
706-
return
707-
end
708-
if rr.rdata_labels == 0 then
709-
print("", "", Dns.class_tostring(rr.class), Dns.type_tostring(rr.type), rr.ttl, label.tooffstr(self, labels, rr.labels))
710-
else
711-
print("", "", Dns.class_tostring(rr.class), Dns.type_tostring(rr.type), rr.ttl, label.tooffstr(self, labels, rr.labels), label.tooffstr(self, labels, rr.rdata_labels, rr.labels))
709+
if self.arcount > 0 then
710+
print("additionals:", "class", "type", "ttl", "labels", "RR labels")
711+
for n = 1, self.arcount do
712+
if C.core_object_dns_parse_rr(self, rr, labels, num_labels) ~= 0 then
713+
return
714+
end
715+
if rr.rdata_labels == 0 then
716+
print("", Dns.class_tostring(rr.class), Dns.type_tostring(rr.type), rr.ttl, label.tooffstr(self, labels, rr.labels))
717+
else
718+
print("", Dns.class_tostring(rr.class), Dns.type_tostring(rr.type), rr.ttl, label.tooffstr(self, labels, rr.labels), label.tooffstr(self, labels, rr.rdata_labels, rr.labels))
719+
end
712720
end
713721
end
714722
end

0 commit comments

Comments
 (0)