Adding upstream version 1.1.0+debian.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-09 08:30:48 +01:00
parent f890831723
commit 8d1b12293d
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
261 changed files with 31196 additions and 0 deletions

47
src/test/Makefile.am Normal file
View file

@ -0,0 +1,47 @@
# Copyright (c) 2018-2021, OARC, Inc.
# All rights reserved.
#
# This file is part of dnsjit.
#
# dnsjit is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dnsjit is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dnsjit. If not, see <http://www.gnu.org/licenses/>.
MAINTAINERCLEANFILES = $(srcdir)/Makefile.in
CLEANFILES = test*.log test*.trs test*.out \
*.pcap-dist
TESTS = test1.sh test2.sh test3.sh test4.sh test5.sh test6.sh test-ipsplit.sh \
test-trie.sh test-base64url.sh
test1.sh: dns.pcap-dist
test2.sh: dns.pcap-dist
test3.sh: dns.pcap-dist
test4.sh: dns.pcap-dist
test5.sh: dns.pcap-dist
test6.sh: dns.pcap-dist
test-ipsplit.sh: pellets.pcap-dist dns.pcap-dist
test-trie.sh: pellets.pcap-dist dns.pcap-dist
.pcap.pcap-dist:
cp "$<" "$@"
EXTRA_DIST = $(TESTS) \
dns.pcap pellets.pcap test_ipsplit.lua test_trie.lua test_base64url.lua \
test1.gold test2.gold test3.gold test4.gold

BIN
src/test/dns.pcap Normal file

Binary file not shown.

BIN
src/test/pellets.pcap Normal file

Binary file not shown.

20
src/test/test-base64url.sh Executable file
View file

@ -0,0 +1,20 @@
#!/bin/sh -e
# Copyright (c) 2020, CZ.NIC, z.s.p.o.
# All rights reserved.
#
# This file is part of dnsjit.
#
# dnsjit is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dnsjit is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dnsjit. If not, see <http://www.gnu.org/licenses/>.
../dnsjit "$srcdir/test_base64url.lua"

20
src/test/test-ipsplit.sh Executable file
View file

@ -0,0 +1,20 @@
#!/bin/sh -e
# Copyright (c) 2020, CZ.NIC, z.s.p.o.
# All rights reserved.
#
# This file is part of dnsjit.
#
# dnsjit is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dnsjit is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dnsjit. If not, see <http://www.gnu.org/licenses/>.
../dnsjit "$srcdir/test_ipsplit.lua"

20
src/test/test-trie.sh Executable file
View file

@ -0,0 +1,20 @@
#!/bin/sh -e
# Copyright (c) 2020, CZ.NIC, z.s.p.o.
# All rights reserved.
#
# This file is part of dnsjit.
#
# dnsjit is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dnsjit is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dnsjit. If not, see <http://www.gnu.org/licenses/>.
../dnsjit "$srcdir/test_trie.lua"

1493
src/test/test1.gold Normal file

File diff suppressed because it is too large Load diff

21
src/test/test1.sh Executable file
View file

@ -0,0 +1,21 @@
#!/bin/sh -e
# Copyright (c) 2018-2021, OARC, Inc.
# All rights reserved.
#
# This file is part of dnsjit.
#
# dnsjit is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dnsjit is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dnsjit. If not, see <http://www.gnu.org/licenses/>.
../dnsjit "$srcdir/../../examples/dumpdns.lua" dns.pcap-dist >test1.out
diff "$srcdir/test1.gold" test1.out

42
src/test/test2.gold Normal file
View file

@ -0,0 +1,42 @@
src dst id rcode qname qtype
172.17.0.10 8.8.8.8 59311 NOERROR <12>google.<19>com. A
172.17.0.10 8.8.8.8 35665 NOERROR <12>206.<16>218.<20>58.<23>216.<27>in-addr.<35>arpa. PTR
172.17.0.10 8.8.8.8 5337 NOERROR <12>google.<19>com. A
172.17.0.10 8.8.8.8 22982 NOERROR <12>google.<19>com. A
172.17.0.10 8.8.8.8 18718 NOERROR <12>206.<16>218.<20>58.<23>216.<27>in-addr.<35>arpa. PTR
172.17.0.10 8.8.8.8 22531 NOERROR <12>google.<19>com. A
172.17.0.10 8.8.8.8 58510 NOERROR <12>google.<19>com. A
172.17.0.10 8.8.8.8 45248 NOERROR <12>206.<16>218.<20>58.<23>216.<27>in-addr.<35>arpa. PTR
172.17.0.10 8.8.8.8 49483 NOERROR <12>google.<19>com. A
172.17.0.10 8.8.8.8 31669 NOERROR <12>google.<19>com. A
172.17.0.10 8.8.8.8 25433 NOERROR <12>206.<16>218.<20>58.<23>216.<27>in-addr.<35>arpa. PTR
172.17.0.10 8.8.8.8 63798 NOERROR <12>google.<19>com. A
172.17.0.10 8.8.8.8 8470 NOERROR <12>206.<16>218.<20>58.<23>216.<27>in-addr.<35>arpa. PTR
172.17.0.10 8.8.8.8 60258 NOERROR <12>google.<19>com. A
172.17.0.10 8.8.8.8 44985 NOERROR <12>206.<16>218.<20>58.<23>216.<27>in-addr.<35>arpa. PTR
172.17.0.10 8.8.8.8 45512 NOERROR <12>google.<19>com. A
172.17.0.10 8.8.8.8 22980 NOERROR <12>206.<16>218.<20>58.<23>216.<27>in-addr.<35>arpa. PTR
172.17.0.10 8.8.8.8 1834 NOERROR <12>google.<19>com. A
172.17.0.10 8.8.8.8 25431 NOERROR <12>206.<16>218.<20>58.<23>216.<27>in-addr.<35>arpa. PTR
172.17.0.10 8.8.8.8 48432 NOERROR <12>google.<19>com. A
172.17.0.10 8.8.8.8 47411 NOERROR <12>206.<16>218.<20>58.<23>216.<27>in-addr.<35>arpa. PTR
172.17.0.10 8.8.8.8 12038 NOERROR <12>google.<19>com. A
172.17.0.10 8.8.8.8 11614 NOERROR <12>google.<19>com. A
172.17.0.10 8.8.8.8 59173 NOERROR <12>google.<19>com. A
172.17.0.10 8.8.8.8 45535 NOERROR <12>google.<19>com. A
172.17.0.10 8.8.8.8 60808 NOERROR <12>206.<16>218.<20>58.<23>216.<27>in-addr.<35>arpa. PTR
172.17.0.10 8.8.8.8 64325 NOERROR <12>google.<19>com. A
172.17.0.10 8.8.8.8 25543 NOERROR <12>206.<16>218.<20>58.<23>216.<27>in-addr.<35>arpa. PTR
172.17.0.10 8.8.8.8 20736 NOERROR <12>google.<19>com. A
172.17.0.10 8.8.8.8 25911 NOERROR <12>206.<16>218.<20>58.<23>216.<27>in-addr.<35>arpa. PTR
172.17.0.10 8.8.8.8 64358 NOERROR <12>google.<19>com. A
172.17.0.10 8.8.8.8 37698 NOERROR <12>206.<16>218.<20>58.<23>216.<27>in-addr.<35>arpa. PTR
172.17.0.10 8.8.8.8 54706 NOERROR <12>google.<19>com. A
172.17.0.10 8.8.8.8 32142 NOERROR <12>206.<16>218.<20>58.<23>216.<27>in-addr.<35>arpa. PTR
172.17.0.10 8.8.8.8 41808 NOERROR <12>google.<19>com. A
172.17.0.10 8.8.8.8 18886 NOERROR <12>206.<16>218.<20>58.<23>216.<27>in-addr.<35>arpa. PTR
172.17.0.10 8.8.8.8 10624 NOERROR <12>google.<19>com. A
172.17.0.10 8.8.8.8 33139 NOERROR <12>206.<16>218.<20>58.<23>216.<27>in-addr.<35>arpa. PTR
172.17.0.10 8.8.8.8 61415 NOERROR <12>google.<19>com. A
172.17.0.10 8.8.8.8 59258 NOERROR <12>206.<16>218.<20>58.<23>216.<27>in-addr.<35>arpa. PTR
172.17.0.10 8.8.8.8 17700 NOERROR <12>google.<19>com. A

21
src/test/test2.sh Executable file
View file

@ -0,0 +1,21 @@
#!/bin/sh -e
# Copyright (c) 2018-2021, OARC, Inc.
# All rights reserved.
#
# This file is part of dnsjit.
#
# dnsjit is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dnsjit is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dnsjit. If not, see <http://www.gnu.org/licenses/>.
../dnsjit "$srcdir/../../examples/dumpdns-qr.lua" dns.pcap-dist >test2.out
diff "$srcdir/test2.gold" test2.out

82
src/test/test3.gold Normal file
View file

@ -0,0 +1,82 @@
59311 172.17.0.10 -> 8.8.8.8
59311 8.8.8.8 -> 172.17.0.10
35665 172.17.0.10 -> 8.8.8.8
35665 8.8.8.8 -> 172.17.0.10
5337 172.17.0.10 -> 8.8.8.8
5337 8.8.8.8 -> 172.17.0.10
22982 172.17.0.10 -> 8.8.8.8
22982 8.8.8.8 -> 172.17.0.10
18718 172.17.0.10 -> 8.8.8.8
18718 8.8.8.8 -> 172.17.0.10
22531 172.17.0.10 -> 8.8.8.8
22531 8.8.8.8 -> 172.17.0.10
58510 172.17.0.10 -> 8.8.8.8
58510 8.8.8.8 -> 172.17.0.10
45248 172.17.0.10 -> 8.8.8.8
45248 8.8.8.8 -> 172.17.0.10
49483 172.17.0.10 -> 8.8.8.8
49483 8.8.8.8 -> 172.17.0.10
31669 172.17.0.10 -> 8.8.8.8
31669 8.8.8.8 -> 172.17.0.10
25433 172.17.0.10 -> 8.8.8.8
25433 8.8.8.8 -> 172.17.0.10
63798 172.17.0.10 -> 8.8.8.8
63798 8.8.8.8 -> 172.17.0.10
8470 172.17.0.10 -> 8.8.8.8
8470 8.8.8.8 -> 172.17.0.10
60258 172.17.0.10 -> 8.8.8.8
60258 8.8.8.8 -> 172.17.0.10
44985 172.17.0.10 -> 8.8.8.8
44985 8.8.8.8 -> 172.17.0.10
45512 172.17.0.10 -> 8.8.8.8
45512 8.8.8.8 -> 172.17.0.10
22980 172.17.0.10 -> 8.8.8.8
22980 8.8.8.8 -> 172.17.0.10
1834 172.17.0.10 -> 8.8.8.8
1834 8.8.8.8 -> 172.17.0.10
25431 172.17.0.10 -> 8.8.8.8
25431 8.8.8.8 -> 172.17.0.10
48432 172.17.0.10 -> 8.8.8.8
48432 8.8.8.8 -> 172.17.0.10
47411 172.17.0.10 -> 8.8.8.8
47411 8.8.8.8 -> 172.17.0.10
12038 172.17.0.10 -> 8.8.8.8
12038 8.8.8.8 -> 172.17.0.10
11614 172.17.0.10 -> 8.8.8.8
11614 8.8.8.8 -> 172.17.0.10
59173 172.17.0.10 -> 8.8.8.8
59173 8.8.8.8 -> 172.17.0.10
45535 172.17.0.10 -> 8.8.8.8
45535 8.8.8.8 -> 172.17.0.10
60808 172.17.0.10 -> 8.8.8.8
60808 8.8.8.8 -> 172.17.0.10
64325 172.17.0.10 -> 8.8.8.8
64325 8.8.8.8 -> 172.17.0.10
25543 172.17.0.10 -> 8.8.8.8
25543 8.8.8.8 -> 172.17.0.10
20736 172.17.0.10 -> 8.8.8.8
20736 8.8.8.8 -> 172.17.0.10
25911 172.17.0.10 -> 8.8.8.8
25911 8.8.8.8 -> 172.17.0.10
64358 172.17.0.10 -> 8.8.8.8
64358 8.8.8.8 -> 172.17.0.10
37698 172.17.0.10 -> 8.8.8.8
37698 8.8.8.8 -> 172.17.0.10
54706 172.17.0.10 -> 8.8.8.8
54706 8.8.8.8 -> 172.17.0.10
32142 172.17.0.10 -> 8.8.8.8
32142 8.8.8.8 -> 172.17.0.10
41808 172.17.0.10 -> 8.8.8.8
41808 8.8.8.8 -> 172.17.0.10
18886 172.17.0.10 -> 8.8.8.8
18886 8.8.8.8 -> 172.17.0.10
10624 172.17.0.10 -> 8.8.8.8
10624 8.8.8.8 -> 172.17.0.10
33139 172.17.0.10 -> 8.8.8.8
33139 8.8.8.8 -> 172.17.0.10
61415 172.17.0.10 -> 8.8.8.8
61415 8.8.8.8 -> 172.17.0.10
59258 172.17.0.10 -> 8.8.8.8
59258 8.8.8.8 -> 172.17.0.10
17700 172.17.0.10 -> 8.8.8.8
17700 8.8.8.8 -> 172.17.0.10

22
src/test/test3.sh Executable file
View file

@ -0,0 +1,22 @@
#!/bin/sh -e
# Copyright (c) 2018-2021, OARC, Inc.
# All rights reserved.
#
# This file is part of dnsjit.
#
# dnsjit is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dnsjit is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dnsjit. If not, see <http://www.gnu.org/licenses/>.
../dnsjit "$srcdir/../../examples/filter_rcode.lua" dns.pcap-dist 0 >test3.out
../dnsjit "$srcdir/../../examples/filter_rcode.lua" dns.pcap-dist 1 >>test3.out
diff "$srcdir/test3.gold" test3.out

82
src/test/test4.gold Normal file
View file

@ -0,0 +1,82 @@
59311
59311
35665
35665
5337
5337
22982
22982
18718
18718
22531
22531
58510
58510
45248
45248
49483
49483
31669
31669
25433
25433
63798
63798
8470
8470
60258
60258
44985
44985
45512
45512
22980
22980
1834
1834
25431
25431
48432
48432
47411
47411
12038
12038
11614
11614
59173
59173
45535
45535
60808
60808
64325
64325
25543
25543
20736
20736
25911
25911
64358
64358
37698
37698
54706
54706
32142
32142
41808
41808
18886
18886
10624
10624
33139
33139
61415
61415
59258
59258
17700
17700

21
src/test/test4.sh Executable file
View file

@ -0,0 +1,21 @@
#!/bin/sh -e
# Copyright (c) 2018-2021, OARC, Inc.
# All rights reserved.
#
# This file is part of dnsjit.
#
# dnsjit is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dnsjit is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dnsjit. If not, see <http://www.gnu.org/licenses/>.
../dnsjit "$srcdir/../../examples/readme.lua" dns.pcap-dist >test4.out
diff "$srcdir/test4.gold" test4.out

24
src/test/test5.sh Executable file
View file

@ -0,0 +1,24 @@
#!/bin/sh -e
# Copyright (c) 2018-2021, OARC, Inc.
# All rights reserved.
#
# This file is part of dnsjit.
#
# dnsjit is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dnsjit is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dnsjit. If not, see <http://www.gnu.org/licenses/>.
../dnsjit "$srcdir/../../examples/test_throughput.lua" -vvvvv -t -s 1000000
../dnsjit "$srcdir/../../examples/test_pcap_read.lua" -vvvvv dns.pcap-dist
../dnsjit "$srcdir/../../examples/test_pcap_read.lua" -l -vvvvv dns.pcap-dist
../dnsjit "$srcdir/../../examples/test_pcap_read.lua" -p -vvvvv dns.pcap-dist
../dnsjit "$srcdir/../../examples/test_pcap_read.lua" -l -p -vvvvv dns.pcap-dist

23
src/test/test6.sh Executable file
View file

@ -0,0 +1,23 @@
#!/bin/sh -e
# Copyright (c) 2018-2021, OARC, Inc.
# All rights reserved.
#
# This file is part of dnsjit.
#
# dnsjit is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# dnsjit is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dnsjit. If not, see <http://www.gnu.org/licenses/>.
../dnsjit "$srcdir/../../examples/dumpdns.lua" "$srcdir/dns.pcap" > test6-dns.out
../dnsjit "$srcdir/../../examples/dumpdns2pcap.lua" "$srcdir/dns.pcap" test6-pcap.out
../dnsjit "$srcdir/../../examples/dumpdns.lua" test6-pcap.out > test6-dns2.out
diff test6-dns.out test6-dns2.out

View file

@ -0,0 +1,24 @@
base64url = require("dnsjit.lib.base64url")
ffi = require("ffi")
-- empty string works
assert(base64url.decode(base64url.encode("")) == "")
-- regular string data
assert(base64url.encode("abcd") == "YWJjZA")
assert(base64url.decode(base64url.encode("abcd")) == "abcd")
-- invalid base64 data
base64url.decode("+")
-- check all symbols - arbitrary binary data
c_array = ffi.new("uint8_t[?]", 256)
bin_symbols = {}
for i = 0, 255 do
bin_symbols[i + 1] = string.char(i)
c_array[i] = i
end
bin_str = table.concat(bin_symbols)
assert(base64url.decode(base64url.encode(bin_str)) == bin_str)
assert(base64url.encode(c_array, 256) == base64url.encode(bin_str))

294
src/test/test_ipsplit.lua Executable file
View file

@ -0,0 +1,294 @@
-- Test cases for dnsjit.filter.ipsplit
-- Some checks that use ip_pkt() assume little-endian machine and will fail otherwise
local ffi = require("ffi")
local object = require("dnsjit.core.objects")
local dns = require("dnsjit.core.object.dns").new()
local function dns_msgid(obj)
local obj = ffi.cast("core_object_t*", obj)
assert(obj, "obj is nil")
local pl = obj:cast()
assert(obj:type() == "payload" and pl.len > 0, "obj doesn't have payload")
dns.obj_prev = obj
dns:parse_header()
return dns.id
end
local function ip_pkt(obj)
local obj = ffi.cast("core_object_t*", obj)
assert(obj, "obj is nil")
local pl = obj:cast()
assert(obj:type() == "payload" and pl.len > 0, "obj doesn't have payload")
local pkt = obj.obj_prev
while pkt ~= nil do
if pkt.obj_type == object.IP or pkt.obj_type == object.IP6 then
return pkt:cast()
end
pkt = pkt.obj_prev
end
assert(pkt, "obj has no ip/ip6 layer")
end
-----------------------------------------------------
-- pellets.pcap: client detection
--
-- All packets have IPv6 layer and are expected to
-- be sucessfully processed by ipsplit filter.
-- Clients should be identified from source ip.
-----------------------------------------------------
local input = require("dnsjit.input.pcap").new()
local layer = require("dnsjit.filter.layer").new()
local copy = require("dnsjit.filter.copy").new()
local ipsplit = require("dnsjit.filter.ipsplit").new()
local out1 = require("dnsjit.core.channel").new(256)
local out2 = require("dnsjit.core.channel").new(256)
input:open_offline("pellets.pcap-dist")
layer:producer(input)
ipsplit:receiver(out1)
ipsplit:receiver(out2)
ipsplit:overwrite_dst()
copy:obj_type(object.IP)
copy:obj_type(object.IP6)
copy:obj_type(object.PAYLOAD)
copy:receiver(ipsplit)
local prod, pctx = layer:produce()
local recv, rctx = copy:receive()
-- Process entire PCAP first, channels are large enough to bufer all packets
while true do
local obj = prod(pctx)
if obj == nil then break end
recv(rctx, obj)
end
out1:close()
out2:close()
assert(ipsplit:discarded() == 0, "some valid packets have been discarded")
assert(out1:size() == 47, "out1: some IPv6 packets lost by filter")
assert(out2:size() == 44, "out2: some IPv6 packets lost by filter")
-- out1: test individual packets
local i = 0
while true do
local obj = out1:get()
if obj == nil then break end
i = i + 1
if i == 1 then
assert(dns_msgid(obj) == 0x0a31, "pkt 1: client 1, pkt 1 -> out1")
assert(ip_pkt(obj):source() == "2001:0db8:beef:feed:0000:0000:0000:0003")
assert(ip_pkt(obj):destination() == "0100:0000:0000:0000:0000:0000:0000:0001")
end
if i == 2 then
assert(dns_msgid(obj) == 0xb3e8, "pkt 3: client 3, pkt 1 -> out1")
assert(ip_pkt(obj):source() == "2001:0db8:beef:feed:0000:0000:0000:0005")
assert(ip_pkt(obj):destination() == "0200:0000:0000:0000:0000:0000:0000:0001")
end
if i == 3 then
assert(dns_msgid(obj) == 0xb3e9, "pkt 4: client 3, pkt 2 -> out1")
assert(ip_pkt(obj):source() == "2001:0db8:beef:feed:0000:0000:0000:0005")
assert(ip_pkt(obj):destination() == "0200:0000:0000:0000:0000:0000:0000:0001")
end
if i == 13 then assert(dns_msgid(obj) == 0x4a05, "pkt 16: client 7, pkt 1 -> out1") end
if i == 14 then assert(dns_msgid(obj) == 0x4a06, "pkt 17: client 7, pkt 2 -> out1") end
end
-- out2: test individual packets
local i = 0
while true do
local obj = out2:get()
if obj == nil then break end
i = i + 1
if i == 1 then
assert(dns_msgid(obj) == 0xe6bd, "pkt 2: client 2, pkt 1 -> out2")
assert(ip_pkt(obj):source() == "2001:0db8:beef:feed:0000:0000:0000:0004")
assert(ip_pkt(obj):destination() == "0100:0000:0000:0000:0000:0000:0000:0001")
end
if i == 4 then assert(dns_msgid(obj) == 0xabfe, "pkt 18: client 8, pkt 1 -> out2") end
if i == 5 then assert(dns_msgid(obj) == 0xabff, "pkt 21: client 8, pkt 2 -> out2") end
end
-----------------------------------------------------
-- pellets.pcap: weighted ipsplit:sequential()
--
-- Test sequential client assignment that respects
-- weight.
-----------------------------------------------------
local input = require("dnsjit.input.pcap").new()
local layer = require("dnsjit.filter.layer").new()
local copy = require("dnsjit.filter.copy").new()
local ipsplit = require("dnsjit.filter.ipsplit").new()
local out1 = require("dnsjit.core.channel").new(256)
local out2 = require("dnsjit.core.channel").new(256)
input:open_offline("pellets.pcap-dist")
layer:producer(input)
ipsplit:receiver(out1, 3)
ipsplit:receiver(out2, 2)
copy:obj_type(object.IP)
copy:obj_type(object.IP6)
copy:obj_type(object.PAYLOAD)
copy:receiver(ipsplit)
local prod, pctx = layer:produce()
local recv, rctx = copy:receive()
-- Process entire PCAP first, channels are large enough to bufer all packets
while true do
local obj = prod(pctx)
if obj == nil then break end
recv(rctx, obj)
end
out1:close()
out2:close()
assert(ipsplit:discarded() == 0, "some valid packets have been discarded")
assert(out1:size() + out2:size() == 91, "some IPv6 packets lost by filter")
-- out1: test individual packets
local i = 0
while true do
local obj = out1:get()
if obj == nil then break end
i = i + 1
if i == 1 then
assert(dns_msgid(obj) == 0x0a31, "pkt 1: client 1, pkt 1 -> out1")
assert(ip_pkt(obj):source() == "2001:0db8:beef:feed:0000:0000:0000:0003")
assert(ip_pkt(obj):destination() == "0000:0000:0000:0000:0000:0000:0000:0001")
end
if i == 2 then assert(dns_msgid(obj) == 0xe6bd, "pkt 2: client 2, pkt 1 -> out1") end
if i == 3 then assert(dns_msgid(obj) == 0xb3e8, "pkt 3: client 3, pkt 1 -> out1") end
if i == 4 then assert(dns_msgid(obj) == 0xb3e9, "pkt 4: client 3, pkt 2 -> out1") end
if i == 5 then assert(dns_msgid(obj) == 0x0a6f, "pkt 9: client 6, pkt 1 -> out1") end
end
-- out2: test individual packets
local i = 0
while true do
local obj = out2:get()
if obj == nil then break end
i = i + 1
if i == 1 then assert(dns_msgid(obj) == 0xaac6, "pkt 5: client 4, pkt 1 -> out2") end
if i == 2 then assert(dns_msgid(obj) == 0xaea6, "pkt 6: client 5, pkt 1 -> out2") end
if i == 3 then assert(dns_msgid(obj) == 0xaea7, "pkt 7: client 5, pkt 2 -> out2") end
end
-----------------------------------------------------
-- pellets.pcap: weighted ipsplit:random()
--
-- Test sequential client assignment that respects
-- weight.
-----------------------------------------------------
local input = require("dnsjit.input.pcap").new()
local layer = require("dnsjit.filter.layer").new()
local copy = require("dnsjit.filter.copy").new()
local ipsplit = require("dnsjit.filter.ipsplit").new()
local out1 = require("dnsjit.core.channel").new(256)
local out2 = require("dnsjit.core.channel").new(256)
input:open_offline("pellets.pcap-dist")
layer:producer(input)
ipsplit:receiver(out1, 85)
ipsplit:receiver(out2, 15)
ipsplit:random()
copy:obj_type(object.IP)
copy:obj_type(object.IP6)
copy:obj_type(object.PAYLOAD)
copy:receiver(ipsplit)
local prod, pctx = layer:produce()
local recv, rctx = copy:receive()
-- Process entire PCAP first, channels are large enough to bufer all packets
while true do
local obj = prod(pctx)
if obj == nil then break end
recv(rctx, obj)
end
out1:close()
out2:close()
assert(ipsplit:discarded() == 0, "some valid packets have been discarded")
assert(out1:size() == 81, "out1: some IPv6 packets lost by filter")
assert(out2:size() == 10, "out2: some IPv6 packets lost by filter")
-- out1: test individual packets
local i = 0
while true do
local obj = out1:get()
if obj == nil then break end
i = i + 1
if i == 1 then assert(dns_msgid(obj) == 0xe6bd, "pkt 1: client 2, pkt 1 -> out1") end
if i == 2 then assert(dns_msgid(obj) == 0xb3e8, "pkt 2: client 3, pkt 1 -> out1") end
if i == 3 then assert(dns_msgid(obj) == 0xb3e9, "pkt 3: client 3, pkt 2 -> out1") end
if i == 5 then assert(dns_msgid(obj) == 0xaea6, "pkt 4: client 5, pkt 1 -> out1") end
if i == 29 then assert(dns_msgid(obj) == 0xaeaf, "pkt 29: client 5, pkt 10 -> out1") end
end
-- out2: test individual packets
local i = 0
while true do
local obj = out2:get()
if obj == nil then break end
i = i + 1
if i == 1 then assert(dns_msgid(obj) == 0x0a31, "pkt 1: client 1, pkt 1 -> out2") end
if i == 2 then assert(dns_msgid(obj) == 0x0a6f, "pkt 2: client 6, pkt 1 -> out2") end
if i == 10 then assert(dns_msgid(obj) == 0x0a70, "pkt 10: client 6, pkt 2 -> out2") end
end
-----------------------------------------------------
-- Tests with dns.pcap
--
-- Packets use IPv4 and not all packets have IP layer
-----------------------------------------------------
local input = require("dnsjit.input.pcap").new()
local layer = require("dnsjit.filter.layer").new()
local copy = require("dnsjit.filter.copy").new()
local ipsplit = require("dnsjit.filter.ipsplit").new()
local out1 = require("dnsjit.core.channel").new(256)
local out2 = require("dnsjit.core.channel").new(256)
input:open_offline("dns.pcap-dist")
layer:producer(input)
ipsplit:receiver(out1)
ipsplit:receiver(out2)
ipsplit:overwrite_src()
copy:obj_type(object.IP)
copy:obj_type(object.IP6)
copy:obj_type(object.PAYLOAD)
copy:receiver(ipsplit)
local prod, pctx = layer:produce()
local recv, rctx = copy:receive()
-- Process entire PCAP first, channels are large enough to bufer all packets
while true do
local obj = prod(pctx)
if obj == nil then break end
recv(rctx, obj)
end
out1:close()
out2:close()
assert(out1:size() + out2:size() == 123, "some IPv4 packets lost by filter")
-- out1: test individual packets
local i = 0
while true do
local obj = out1:get()
if obj == nil then break end
i = i + 1
if i == 1 then
assert(dns_msgid(obj) == 0xe7af)
assert(ip_pkt(obj):source() == "1.0.0.0")
assert(ip_pkt(obj):destination() == "8.8.8.8")
end
end

134
src/test/test_trie.lua Executable file
View file

@ -0,0 +1,134 @@
-- Test cases for dnsjit.lib.trie
local function key_compare(node1, node2)
local key1, keylen1 = node1:key()
local key2, keylen2 = node2:key()
if keylen1 ~= keylen2 then return false end
for i = 0, keylen1 - 1 do
if key1[i] ~= key2[i] then return false end
end
return true
end
-----------------------------------------------------
-- binary-key trie with which stores numbers
-----------------------------------------------------
local input = require("dnsjit.input.pcap").new()
local layer = require("dnsjit.filter.layer").new()
local object = require("dnsjit.core.objects")
local ip = require("dnsjit.lib.ip")
local trie = require("dnsjit.lib.trie").new("uint32_t", true, 16)
input:open_offline("pellets.pcap-dist")
layer:producer(input)
local prod, pctx = layer:produce()
-- fill trie with values
while true do
local obj = prod(pctx)
if obj == nil then break end
local pkt = obj:cast_to(object.IP6)
if pkt ~= nil then
-- count number of packets per IP
local node = trie:get_ins(pkt.src)
node:set(node:get() + 1)
end
end
assert(trie:weight() == 29)
-- test iterator and check values
local iter = trie:iter()
local node = iter:node()
local npkts = 0
local i = 0
while node ~= nil do
i = i + 1
local ip6str = ip.tostring(node:key())
local val = tonumber(node:get())
npkts = npkts + val
if i == 1 then assert(ip6str == "2001:0db8:beef:feed:0000:0000:0000:0003" and val == 1) end
if i == 1 then
local first = trie:get_first()
assert(key_compare(node, first))
assert(node:get() == first:get())
end
if i == 2 then assert(ip6str == "2001:0db8:beef:feed:0000:0000:0000:0004" and val == 1) end
if i == 2 then
local second = trie:get_try(node:key())
assert(key_compare(node, second))
assert(node:get() == second:get())
end
if i == 5 then assert(ip6str == "2001:0db8:beef:feed:0000:0000:0000:0008" and val == 10) end
if i == 29 then assert(ip6str == "2001:0db8:beef:feed:0000:0000:0000:0042" and val == 1) end
iter:next()
node = iter:node()
end
assert(npkts == 91)
trie:clear()
assert(trie:weight() == 0)
-----------------------------------------------------
-- string-key trie with which stores objects
-----------------------------------------------------
local input = require("dnsjit.input.pcap").new()
local layer = require("dnsjit.filter.layer").new()
local object = require("dnsjit.core.objects")
local trie = require("dnsjit.lib.trie").new("core_object_t*")
input:open_offline("dns.pcap-dist")
layer:producer(input)
local prod, pctx = layer:produce()
-- fill trie with values
while true do
local obj = prod(pctx)
if obj == nil then break end
local pkt = obj:cast_to(object.IP)
if pkt ~= nil then
local node = trie:get_ins(pkt:source())
local pkt2 = node:get()
if val ~= nil then
val:free()
end
node:set(pkt:copy():uncast())
end
end
assert(trie:weight() == 3)
local node
node = trie:get_first()
assert(node:key() == "172.17.0.10")
pkt = node:get():cast()
assert(pkt:source() == "172.17.0.10")
assert(pkt.id == 0x538b)
pkt:free()
node = trie:get_try("8.8.8.8")
assert(node:key() == "8.8.8.8")
pkt = node:get():cast()
assert(pkt:source() == "8.8.8.8")
pkt:free()
node = trie:get_try("216.58.218.206")
assert(node:key() == "216.58.218.206")
pkt = node:get():cast()
assert(pkt:source() == "216.58.218.206")
pkt:free()
node = trie:get_try("nonexistent")
assert(node == nil)
trie:clear()
assert(trie:weight() == 0)