Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2ace2d4

Browse files
committedJul 3, 2018
Rewrite, v1.99.1
- Rewrote `drool` into command modules: `drool <command> ...` - Remove `drool.conf` - Remove functionality `backend`, both `input` and `output` - Remove functionality `log` and `nolog` (see Issue DNS-OARC#112) - Remove functionality `input` and `filter` (see Issue DNS-OARC#113) - Remove functionality `max_clients` and `max_reuse_clients` (`client_pool`) - Remove timing mode `best_effort` - Remove statistics: dropped, ignored, total - Add statistics: finish, sent, received, responses, timeouts, errors - Add `--csv` to output statistics as CSV - Add `--json` to output statistics as JSON - Add command module `replay` - Add timing mode `fixed=<nanoseconds>` - Up version to 1.99.1
1 parent 9048bec commit 2ace2d4

23 files changed

+1163
-1541
lines changed
 

‎.gitignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@ src/stamp-h1
2828
build
2929

3030
# Project specific files
31-
src/drool
3231
src/drool.1
33-
src/drool.conf.5
32+
src/drool-replay.1
3433
src/test/test-suite.log
3534
src/test/test*.sh.log
3635
src/test/test*.sh.trs

‎README.md

+8-22
Original file line numberDiff line numberDiff line change
@@ -25,38 +25,24 @@ efficacy of subsequent bug fixes.
2525
## Usage example
2626

2727
Send all DNS queries twice as fast as found in the PCAP file to localhost
28-
using UDP:
28+
using UDP.
2929

3030
```shell
31-
drool -vv \
32-
-c 'text:timing multiply 0.5; client_pool target "127.0.0.1" "53"; client_pool sendas udp;' \
33-
-r file.pcap
31+
drool replay --timing multiply=0.5 --no-tcp file.pcap 127.0.0.1 53
3432
```
3533

36-
Only look for DNS queries in TCP traffic and send it to localhost:
34+
Send all DNS queries over TCP to localhost as they were recorded.
3735

3836
```shell
39-
drool -vv \
40-
-c 'text:filter "tcp"; client_pool target "127.0.0.1" "53";' \
41-
-r file.pcap
37+
drool replay --timing keep --no-udp file.pcap 127.0.0.1 53
4238
```
4339

44-
Listen for DNS queries on eth0 and send them to an (assuming) internal server:
40+
Take all DNS queries found in the PCAP file and send them as fast as possible
41+
over UDP to localhost by ignoring both timings, replies and starting 3 threads
42+
that will simultaneously send queries.
4543

4644
```shell
47-
drool -vv \
48-
-c 'text:filter "port 53"; client_pool target "172.16.1.2" "53";' \
49-
-i eth0
50-
```
51-
52-
Take all UDP DNS queries found in the PCAP file and send them as fast as
53-
possible to localhost by ignoring both timings, replies and starting 5
54-
contexts (threads) that will simultaneously send queries:
55-
56-
```shell
57-
drool -vv \
58-
-c 'text:filter "udp"; timing ignore; context client_pools 5; client_pool target "127.0.0.1" "53"; client_pool skip_reply;' \
59-
-r file.pcap
45+
drool replay --no-tcp --no-responses --threads --udp-threads 3 file.pcap 127.0.0.1 53
6046
```
6147

6248
## Dependencies

‎configure.ac

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@
3434
# POSSIBILITY OF SUCH DAMAGE.
3535

3636
AC_PREREQ(2.61)
37-
AC_INIT([drool], [1.99.0], [admin@dns-oarc.net], [drool], [https://github.com/DNS-OARC/drool/issues])
37+
AC_INIT([drool], [1.99.1], [admin@dns-oarc.net], [drool], [https://github.com/DNS-OARC/drool/issues])
3838
AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects])
39-
AC_CONFIG_SRCDIR([src/main.lua])
39+
AC_CONFIG_SRCDIR([src/drool.in])
4040
AC_CONFIG_MACRO_DIR([m4])
4141

4242
# Checks for programs.

‎src/Makefile.am

+12-16
Original file line numberDiff line numberDiff line change
@@ -34,38 +34,34 @@
3434
# POSSIBILITY OF SUCH DAMAGE.
3535

3636
MAINTAINERCLEANFILES = $(srcdir)/Makefile.in
37-
CLEANFILES = drool drool.1 drool.conf.5
37+
CLEANFILES = drool \
38+
drool.1 \
39+
drool-replay.1
3840

3941
SUBDIRS = test
4042

4143
EXTRA_DIST = drool.in \
42-
drool.1.in \
43-
drool.conf.5.in \
44-
drool.conf.example
44+
drool.1in \
45+
drool-replay.1in
4546

4647
bin_SCRIPTS = drool
47-
dist_pkgdata_DATA = conf.lua log.lua run.lua main.lua
48+
droollibdir = $(pkglibdir)/drool
49+
dist_droollib_DATA = lib/drool/replay.lua
4850

49-
man1_MANS = drool.1
50-
man5_MANS = drool.conf.5
51+
man1_MANS = drool.1 \
52+
drool-replay.1
5153

5254
drool: drool.in Makefile
5355
sed -e 's,[@]PACKAGE_NAME[@],$(PACKAGE_NAME),g' \
5456
-e 's,[@]PACKAGE_VERSION[@],$(PACKAGE_VERSION),g' \
5557
-e 's,[@]PACKAGE_URL[@],$(PACKAGE_URL),g' \
5658
-e 's,[@]PACKAGE_BUGREPORT[@],$(PACKAGE_BUGREPORT),g' \
57-
-e 's,[@]pkgdatadir[@],$(pkgdatadir),g' \
59+
-e 's,[@]pkglibdir[@],$(pkglibdir),g' \
5860
< "$(srcdir)/drool.in" > drool
5961
chmod +x drool
6062

61-
drool.1: drool.1.in Makefile
63+
.1in.1:
6264
sed -e 's,[@]PACKAGE_VERSION[@],$(PACKAGE_VERSION),g' \
6365
-e 's,[@]PACKAGE_URL[@],$(PACKAGE_URL),g' \
6466
-e 's,[@]PACKAGE_BUGREPORT[@],$(PACKAGE_BUGREPORT),g' \
65-
< "$(srcdir)/drool.1.in" > drool.1
66-
67-
drool.conf.5: drool.conf.5.in Makefile
68-
sed -e 's,[@]PACKAGE_VERSION[@],$(PACKAGE_VERSION),g' \
69-
-e 's,[@]PACKAGE_URL[@],$(PACKAGE_URL),g' \
70-
-e 's,[@]PACKAGE_BUGREPORT[@],$(PACKAGE_BUGREPORT),g' \
71-
< "$(srcdir)/drool.conf.5.in" > drool.conf.5
67+
< "$<" > "$@"

‎src/conf.lua

-70
This file was deleted.

‎src/drool-replay.1in

+160
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
.\" DNS Reply Tool (drool)
2+
.\"
3+
.\" Copyright (c) 2017-2018, OARC, Inc.
4+
.\" Copyright (c) 2017, Comcast Corporation
5+
.\" All rights reserved.
6+
.\"
7+
.\" Redistribution and use in source and binary forms, with or without
8+
.\" modification, are permitted provided that the following conditions
9+
.\" are met:
10+
.\"
11+
.\" 1. Redistributions of source code must retain the above copyright
12+
.\" notice, this list of conditions and the following disclaimer.
13+
.\"
14+
.\" 2. Redistributions in binary form must reproduce the above copyright
15+
.\" notice, this list of conditions and the following disclaimer in
16+
.\" the documentation and/or other materials provided with the
17+
.\" distribution.
18+
.\"
19+
.\" 3. Neither the name of the copyright holder nor the names of its
20+
.\" contributors may be used to endorse or promote products derived
21+
.\" from this software without specific prior written permission.
22+
.\"
23+
.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24+
.\" "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25+
.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26+
.\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27+
.\" COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28+
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29+
.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30+
.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31+
.\" CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32+
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33+
.\" ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34+
.\" POSSIBILITY OF SUCH DAMAGE.
35+
.\"
36+
.TH drool 1 "@PACKAGE_VERSION@" "DNS Replay Tool"
37+
.SH NAME
38+
drool \- DNS Replay Tool
39+
.SH SYNOPSIS
40+
.B drool replay
41+
[
42+
.I options
43+
]
44+
.B file
45+
.B host
46+
.B port
47+
.SH DESCRIPTION
48+
\fBdrool\fR can replay DNS traffic from packet capture (PCAP) files and send
49+
it to a specified server, with options such as to manipulate the timing
50+
between packets, as well as loop packets infinitely or for a set number
51+
of iterations.
52+
This tool's goal is to be able to produce a high amount of UDP packets per
53+
second and TCP sessions per second on common hardware.
54+
55+
The purpose can be to simulate Distributed Denial of Service (DDoS) attacks
56+
on the DNS and measure normal DNS querying.
57+
For example, the tool could enable you to take a snapshot of a DDoS and be
58+
able to replay it later to test if new code or hardening techniques are
59+
useful, safe & effective.
60+
Another example is to be able to replay a packet stream for a bug that is
61+
sequence- and/or timing-related in order to validate the efficacy of
62+
subsequent bug fixes.
63+
.SH OPTIONS
64+
These options are specific for the
65+
.B replay
66+
command, see
67+
.IR drool (1)
68+
for generic options.
69+
.TP
70+
.B \-D
71+
Show DNS queries and responses as processing goes.
72+
.TP
73+
.B \-n \-\-no\-responses
74+
Do not wait for responses before sending next request.
75+
.TP
76+
.B \-\-no\-tcp
77+
Do not use TCP.
78+
.TP
79+
.B \-\-no\-udp
80+
Do not use UDP.
81+
.TP
82+
.B \-T \-\-threads
83+
Use threads.
84+
.TP
85+
.B \-\-tcp\-threads N
86+
Set the number of TCP threads to use, default 2.
87+
.TP
88+
.B \-\-udp\-threads N
89+
Set the number of UDP threads to use, default 4.
90+
.TP
91+
.B \-\-timeout N.N
92+
Set timeout for waiting on responses [seconds.nanoseconds], default 10.0.
93+
.TP
94+
.B \-t \-\-timing mode[=option]
95+
Set the timing mode, see TIMING MODES.
96+
.SH EXAMPLES
97+
.TP
98+
.B drool replay \-\-timing multiply=0.5 \-\-no\-tcp file.pcap 127.0.0.1 53
99+
100+
Send all DNS queries twice as fast as found in the PCAP file to localhost
101+
using UDP.
102+
.TP
103+
.B drool replay \-\-timing keep \-\-no\-udp file.pcap 127.0.0.1 53
104+
105+
Send all DNS queries over TCP to localhost as they were recorded.
106+
.TP
107+
.B drool replay \-\-no\-tcp \-\-no\-responses \-\-threads \-\-udp\-threads 3 file.pcap 127.0.0.1 53
108+
109+
Take all DNS queries found in the PCAP file and send them as fast as possible
110+
over UDP to localhost by ignoring both timings, replies and starting 3 threads
111+
that will simultaneously send queries.
112+
.SH TIMING MODES
113+
.TP
114+
.B ignore
115+
Set the timing mode to ignore all timings and try to send traffic as fast
116+
as possible (default).
117+
.TP
118+
.B keep
119+
Set the timing mode to try and keep up with interval between the traffic
120+
received.
121+
.TP
122+
.B add=<nanoseconds>
123+
Set the timing mode to add the given nanoseconds to the interval between
124+
the traffic received.
125+
.TP
126+
.B reduce=<nanoseconds>
127+
Set the timing mode to reduce the interval between the traffic received
128+
with the given nanoseconds.
129+
.TP
130+
.B multiply=<float>
131+
Set the timing mode to multiply the interval between the traffic received,
132+
this can be thought as percent with 1.00 being 100% of the interval, 2.00
133+
being 200%, 0.10 being 10% and so on.
134+
.TP
135+
.B fixed=<nanoseconds>
136+
Set the timing between packets to the given nanoseconds.
137+
.SH SEE ALSO
138+
drool(1)
139+
.SH AUTHORS
140+
Jerry Lundström, DNS-OARC
141+
.LP
142+
Maintained by DNS-OARC
143+
.LP
144+
.RS
145+
.I https://www.dns-oarc.net/
146+
.RE
147+
.LP
148+
.SH BUGS
149+
For issues and feature requests please use:
150+
.LP
151+
.RS
152+
\fI@PACKAGE_URL@\fP
153+
.RE
154+
.LP
155+
For question and help please use:
156+
.LP
157+
.RS
158+
\fI@PACKAGE_BUGREPORT@\fP
159+
.RE
160+
.LP

‎src/drool.1.in

-308
This file was deleted.

‎src/drool.1in

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
.\" DNS Reply Tool (drool)
2+
.\"
3+
.\" Copyright (c) 2017-2018, OARC, Inc.
4+
.\" Copyright (c) 2017, Comcast Corporation
5+
.\" All rights reserved.
6+
.\"
7+
.\" Redistribution and use in source and binary forms, with or without
8+
.\" modification, are permitted provided that the following conditions
9+
.\" are met:
10+
.\"
11+
.\" 1. Redistributions of source code must retain the above copyright
12+
.\" notice, this list of conditions and the following disclaimer.
13+
.\"
14+
.\" 2. Redistributions in binary form must reproduce the above copyright
15+
.\" notice, this list of conditions and the following disclaimer in
16+
.\" the documentation and/or other materials provided with the
17+
.\" distribution.
18+
.\"
19+
.\" 3. Neither the name of the copyright holder nor the names of its
20+
.\" contributors may be used to endorse or promote products derived
21+
.\" from this software without specific prior written permission.
22+
.\"
23+
.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24+
.\" "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25+
.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26+
.\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27+
.\" COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28+
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29+
.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30+
.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31+
.\" CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32+
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33+
.\" ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34+
.\" POSSIBILITY OF SUCH DAMAGE.
35+
.\"
36+
.TH drool 1 "@PACKAGE_VERSION@" "DNS Replay Tool"
37+
.SH NAME
38+
drool \- DNS Replay Tool
39+
.SH SYNOPSIS
40+
.B drool command
41+
[
42+
.I options
43+
] <
44+
.I arguments
45+
>
46+
.SH DESCRIPTION
47+
.B drool
48+
can replay DNS traffic from packet capture (PCAP) files and send
49+
it to a specified server, with options such as to manipulate the timing
50+
between packets, as well as loop packets infinitely or for a set number
51+
of iterations.
52+
This tool's goal is to be able to produce a high amount of UDP packets per
53+
second and TCP sessions per second on common hardware.
54+
55+
The purpose can be to simulate Distributed Denial of Service (DDoS) attacks
56+
on the DNS and measure normal DNS querying.
57+
For example, the tool could enable you to take a snapshot of a DDoS and be
58+
able to replay it later to test if new code or hardening techniques are
59+
useful, safe & effective.
60+
Another example is to be able to replay a packet stream for a bug that is
61+
sequence- and/or timing-related in order to validate the efficacy of
62+
subsequent bug fixes.
63+
.SH COMMANDS
64+
.B drool
65+
is divided into various commands for different scenarios.
66+
Each command has it's own man-page, may take different arguments and may
67+
have additional options.
68+
.TP
69+
.B replay
70+
Replay DNS from a PCAP file, see
71+
.IR drool-replay (1).
72+
.SH OPTIONS
73+
These options are generic for all
74+
.B drool
75+
commands.
76+
.TP
77+
.B \-\-csv
78+
Output statistics as CSV.
79+
.TP
80+
.B \-\-json
81+
Output statistics as JSON.
82+
.TP
83+
.B \-v
84+
Enable verbose logging, can be given multiple times to increase verbosity level.
85+
.TP
86+
.B \-h
87+
Print help and exit.
88+
.TP
89+
.B \-V
90+
Print version and exit.
91+
.SH EXIT VALUES
92+
0 \- no error
93+
.br
94+
1 \- generic error
95+
.SH SEE ALSO
96+
drool-replay(1)
97+
.SH AUTHORS
98+
Jerry Lundström, DNS-OARC
99+
.LP
100+
Maintained by DNS-OARC
101+
.LP
102+
.RS
103+
.I https://www.dns-oarc.net/
104+
.RE
105+
.LP
106+
.SH BUGS
107+
For issues and feature requests please use:
108+
.LP
109+
.RS
110+
.I @PACKAGE_URL@
111+
.RE
112+
.LP
113+
For question and help please use:
114+
.LP
115+
.RS
116+
.I @PACKAGE_BUGREPORT@
117+
.RE
118+
.LP

‎src/drool.conf.5.in

-296
This file was deleted.

‎src/drool.conf.example

-49
This file was deleted.

‎src/drool.in

+132-98
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,144 @@
11
#!/usr/bin/env dnsjit
2+
-- DNS Reply Tool (drool)
3+
--
4+
-- Copyright (c) 2017-2018, OARC, Inc.
5+
-- Copyright (c) 2017, Comcast Corporation
6+
-- All rights reserved.
7+
--
8+
-- Redistribution and use in source and binary forms, with or without
9+
-- modification, are permitted provided that the following conditions
10+
-- are met:
11+
--
12+
-- 1. Redistributions of source code must retain the above copyright
13+
-- notice, this list of conditions and the following disclaimer.
14+
--
15+
-- 2. Redistributions in binary form must reproduce the above copyright
16+
-- notice, this list of conditions and the following disclaimer in
17+
-- the documentation and/or other materials provided with the
18+
-- distribution.
19+
--
20+
-- 3. Neither the name of the copyright holder nor the names of its
21+
-- contributors may be used to endorse or promote products derived
22+
-- from this software without specific prior written permission.
23+
--
24+
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25+
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26+
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27+
-- FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28+
-- COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29+
-- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30+
-- BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31+
-- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32+
-- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33+
-- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34+
-- ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35+
-- POSSIBILITY OF SUCH DAMAGE.
36+
package.path = package.path .. ";@pkglibdir@/?.lua"
237

3-
log = require("dnsjit.core.log")
4-
clock = require("dnsjit.lib.clock")
5-
L = log.new("drool")
6-
conf = require("dnsjit.lib.parseconf").new()
7-
getopt = nil
38+
local clock = require("dnsjit.lib.clock")
39+
local log = require("dnsjit.core.log").new("drool")
40+
local getopt = require("dnsjit.lib.getopt").new({
41+
{ "v", "verbose", 0, "Enable and increase verbosity for each time given", "?+" },
42+
{ nil, "json", false, "Output statistics as JSON", "?" },
43+
{ nil, "csv", false, "Output statistics as CSV", "?" },
44+
})
45+
getopt.usage_desc = arg[1] .. " command [options...] <arguments...>"
846

9-
files = {}
10-
interfaces = {}
11-
bpf = nil
12-
client_pools = nil
13-
host = nil
14-
port = nil
15-
max_clients = nil
16-
client_ttl = nil
17-
skip_reply = nil
18-
max_reuse_clients = nil
19-
sendas = nil
20-
timing_mode = nil
21-
timing_arg = nil
22-
facility_log = {
23-
input = {},
24-
processing = {},
25-
network = {},
47+
local cmds = {
48+
replay = "drool.replay",
49+
mirror = "drool.mirror",
50+
respdiff = "drool.respdiff",
2651
}
27-
read_iter = 1
28-
read_mode = false
29-
program = "@PACKAGE_NAME@"
30-
version = "@PACKAGE_VERSION@"
31-
package_url = "@PACKAGE_URL@"
32-
pkgdatadir = "@pkgdatadir@"
33-
backend = {
34-
input = "pcapthread",
35-
output = "cpool",
36-
}
37-
38-
io.stderr:write("<< "..program.." v"..version.." "..package_url.." >>\n")
3952

40-
function args()
41-
getopt = require("dnsjit.lib.getopt").new({
42-
{ "c", nil, "", "", "?+" },
43-
{ "l", nil, "", "", "?+" },
44-
{ "L", nil, "", "", "?+" },
45-
{ "f", nil, "", "", "?" },
46-
{ "i", nil, "", "", "?+" },
47-
{ "r", nil, "", "", "?+" },
48-
{ "R", nil, "", "", "?" },
49-
{ "n", nil, "", "", "?" },
50-
{ "v", nil, 0, "", "?+" },
51-
{ "V", nil, false, "", "?" },
52-
{ nil, "pkgdatadir", pkgdatadir, "", "?" },
53-
})
54-
arg = getopt:parse()
53+
if not arg[2] or not cmds[arg[2]] then
54+
getopt:parse()
5555

56-
local v = getopt:val("v")
57-
if v > 0 then
58-
log.enable("warning")
59-
end
60-
if v > 1 then
61-
log.enable("notice")
62-
end
63-
if v > 2 then
64-
log.enable("info")
56+
if getopt:val("help") then
57+
getopt:usage()
58+
os.exit(0)
6559
end
66-
if v > 3 then
67-
log.enable("debug")
60+
if arg[2] then
61+
log:critical("Command "..arg[2].." not found")
6862
end
6963

70-
if getopt:val("help") then
71-
print("usage: "..program.." [options]")
72-
print[[
64+
getopt:usage()
65+
os.exit(-1)
66+
end
7367

74-
-c [type:]config
75-
Specify the configuration to use, if no type is given then
76-
config expects to be a file. Valid types are file and text.
77-
Can be given multiple times and will be processed in the
78-
given order. See drool.conf(5) for configuration syntax.
79-
-l facility[:level]
80-
Enable logging for facility, optional log level can be given
81-
to enable just that. Can be given multiple times and will be
82-
processed in the given order. See drool(1) for available
83-
facilities and log levels.
84-
-L facility[:level]
85-
Same as -l but to disable the given facility and log level.
86-
-f filter Set the Berkeley Packet Filter to use.
87-
-i interface Capture packets from interface, can be given multiple times.
88-
-r file.pcap Read packets from PCAP file, can be given multiple times.
89-
-R mode Specify the mode for reading PCAP files, see drool(1) for
90-
available modes.
91-
-n Dry run mode, do not allocate any outbound sockets or
92-
generate any network traffic.
93-
-v Enable verbose, a simple way to enable logging. Can be
94-
given multiple times to increase verbosity level.
95-
-h Print this help and exit
96-
-V Print version and exit
97-
]]
98-
os.exit(1)
99-
elseif getopt:val("V") then
100-
print("drool v"..version)
101-
os.exit(0)
102-
end
68+
local cmd = require(cmds[arg[2]]).new(getopt)
69+
getopt:parse()
70+
71+
if getopt:val("help") then
72+
getopt:usage()
73+
os.exit(0)
10374
end
10475

105-
args()
106-
assert(loadfile(getopt:val("pkgdatadir").."/conf.lua"))()
107-
assert(loadfile(getopt:val("pkgdatadir").."/log.lua"))()
108-
assert(loadfile(getopt:val("pkgdatadir").."/run.lua"))()
109-
assert(loadfile(getopt:val("pkgdatadir").."/main.lua"))()
110-
main()
76+
local v = getopt:val("v")
77+
if v > 0 then
78+
require("dnsjit.core.log").enable("warning")
79+
end
80+
if v > 1 then
81+
require("dnsjit.core.log").enable("notice")
82+
end
83+
if v > 2 then
84+
require("dnsjit.core.log").enable("info")
85+
end
86+
if v > 3 then
87+
require("dnsjit.core.log").enable("debug")
88+
end
89+
90+
cmd:setup(getopt)
91+
local start_sec, start_nsec = clock:monotonic()
92+
cmd:run()
93+
local end_sec, end_nsec = clock:monotonic()
94+
cmd:finish()
95+
local fin_sec, fin_nsec = clock:monotonic()
96+
97+
local runtime = 0
98+
if end_sec > start_sec then
99+
runtime = ((end_sec - start_sec) - 1) + ((1000000000 - start_nsec + end_nsec)/1000000000)
100+
elseif end_sec == start_sec and end_nsec > start_nsec then
101+
runtime = (end_nsec - start_nsec) / 1000000000
102+
end
103+
104+
local finish = 0
105+
if fin_sec > end_sec then
106+
finish = ((fin_sec - end_sec) - 1) + ((1000000000 - end_nsec + fin_nsec)/1000000000)
107+
elseif fin_sec == end_sec and fin_nsec > end_nsec then
108+
finish = (fin_nsec - end_nsec) / 1000000000
109+
end
110+
111+
if getopt:val("json") then
112+
print("{")
113+
print(" \"runtime\": " .. runtime .. ",")
114+
print(" \"finish\": " .. finish .. ",")
115+
print(" \"packets\": " .. cmd.packets .. ",")
116+
print(" \"queries\": " .. cmd.queries .. ",")
117+
print(" \"sent\": " .. cmd.sent .. ",")
118+
print(" \"received\": " .. cmd.received .. ",")
119+
print(" \"responses\": " .. cmd.responses .. ",")
120+
print(" \"timeouts\": " .. cmd.timeouts .. ",")
121+
print(" \"errors\": " .. cmd.errors)
122+
print("}")
123+
elseif getopt:val("csv") then
124+
print("runtime,finish,packets,queries,sent,received,responses,timeouts,errors")
125+
print(runtime ..","..
126+
finish ..","..
127+
cmd.packets ..","..
128+
cmd.queries ..","..
129+
cmd.sent ..","..
130+
cmd.received ..","..
131+
cmd.responses ..","..
132+
cmd.timeouts ..","..
133+
cmd.errors)
134+
else
135+
print("runtime", runtime+finish, "run", runtime, "finish", finish)
136+
print("", "total", "/sec")
137+
print("packets", cmd.packets, cmd.packets/runtime)
138+
print("queries", cmd.queries, cmd.queries/runtime)
139+
print("sent", cmd.sent, cmd.sent/runtime)
140+
print("received", cmd.received, cmd.received/runtime)
141+
print("responses", cmd.responses, cmd.responses/runtime)
142+
print("timeouts", cmd.timeouts)
143+
print("errors", cmd.errors)
144+
end

‎src/lib/drool/replay.lua

+680
Large diffs are not rendered by default.

‎src/log.lua

-197
This file was deleted.

‎src/main.lua

-81
This file was deleted.

‎src/run.lua

-230
This file was deleted.

‎src/test/Makefile.am

+4-7
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,15 @@ MAINTAINERCLEANFILES = $(srcdir)/Makefile.in
3737

3838
CLEANFILES = test*.log test*.trs \
3939
*.pcap-dist \
40-
test4.out test4.out2
40+
test2.out test2.out2
4141

42-
TESTS = test1.sh test2.sh test3.sh test4.sh
42+
TESTS = test1.sh test2.sh
4343

44-
test3.sh: dns.pcap-dist 1qtcp.pcap-dist
45-
46-
test4.sh: dns.pcap-dist 1qtcp.pcap-dist
44+
test2.sh: dns.pcap-dist 1qtcp.pcap-dist
4745

4846
.pcap.pcap-dist:
4947
cp "$<" "$@"
5048

5149
EXTRA_DIST = $(TESTS) \
52-
test2.conf \
5350
dns.pcap 1qtcp.pcap \
54-
test4.gold
51+
test2.gold

‎src/test/test1.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,6 @@
3535
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3636
# POSSIBILITY OF SUCH DAMAGE.
3737

38-
! ../drool --pkgdatadir "$srcdir/.." -h
38+
export LUA_PATH="$srcdir/../lib/?.lua"
39+
../drool -h
40+
../drool replay -h

‎src/test/test2.conf

-10
This file was deleted.

‎src/test/test2.gold

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
packets 133
2+
queries 41
3+
sent 41
4+
received 0
5+
responses 0
6+
timeouts 0
7+
errors 0
8+
packets 133
9+
queries 41
10+
sent 41
11+
received 0
12+
responses 0
13+
timeouts 0
14+
errors 0
15+
packets 10
16+
queries 2
17+
sent 2
18+
received 0
19+
responses 0
20+
timeouts 0
21+
errors 0
22+
packets 10
23+
queries 2
24+
sent 2
25+
received 0
26+
responses 0
27+
timeouts 0
28+
errors 0

‎src/test/test2.sh

+15-1
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,18 @@
3535
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3636
# POSSIBILITY OF SUCH DAMAGE.
3737

38-
! ../drool --pkgdatadir "$srcdir/.." -c "$srcdir/test2.conf"
38+
export LUA_PATH="$srcdir/../lib/?.lua"
39+
../drool -h
40+
../drool replay -h
41+
42+
if [ -n "$DROOL_TEST_NETWORK" ]; then
43+
rm -f test2.out test2.out2
44+
for pcap in ./dns.pcap-dist ./1qtcp.pcap-dist; do
45+
../drool replay -n --no-tcp "$pcap" 127.0.0.1 53 | tail -n 7 >>test2.out
46+
../drool replay -n --no-tcp "$pcap" ::1 53 | tail -n 7 >>test2.out
47+
done
48+
awk '{print $1 " " $2}' <test2.out >test2.out2
49+
diff test2.out2 "$srcdir/test2.gold"
50+
else
51+
echo "Not testing network (set DROOL_TEST_NETWORK to enable)"
52+
fi

‎src/test/test3.sh

-39
This file was deleted.

‎src/test/test4.gold

-60
This file was deleted.

‎src/test/test4.sh

-52
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.