- Python ≥ 3.6
- Packages in
requirements.txt
(pip install -r requirements.txt
) - Either
nftables
oriptables
ethtool
(for checksum tests)- Optional:
tcpdump
to record traces - Development:
pycodestyle
linter,mypy
type checker
- Choose an interface to run
tcpreq
on. Example:eth1
. - Set up the firewall rules preventing kernel interference.
- You will likely have to customize the user ID/name in the templates:
nftables
: Replaceskuid tcpreq
withskuid <username>
intcpreq-nft.conf
.iptables
: Replace--uid-owner 1001
with--uid-owner <user ID>
intcpreq-ipt.rules
.
- Optional: If you want to limit the firewall rules to
eth1
, insert:nftables
:meta oif != eth1 accept
on a new line beforemeta skuid ...
intcpreq-nft.conf
.iptables
:-o eth1
before-j tcpreq
intcpreq-ipt.rules
.
- Load the rules:
nftables
:nft -f tcpreq-nft.conf
iptables
:iptables-apply tcpreq-ipt.rules
(IPv4) orip6tables-apply tcpreq-ipt.rules
(IPv6)
- You will likely have to customize the user ID/name in the templates:
- Disable NIC offloads:
ethtool -K eth1 tx off rx off tso off gso off gro off lro off
tx off rx off
: Disables checksum offloads (necessary for checksum tests)tso off gso off gro off lro off
: Disables segmentation offloads intcpdump
traces (optional)
- Run
python -m tcpreq
and wait for it to finish. Seepython -m tcpreq -h
for details on its CLI.-B <eth1's IP address>
to set the IP address-r 100k
to limittcpreq
to 100 000 packets per second-b <path/to/blacklist>
to enforce a blacklist (in CIDR notation)-T *
to add all test cases,-T ZeroChecksumTest
to add just theZeroChecksumTest
,-T !ZeroChecksumTest
to remove theZeroChecksumTest
to/from the selection of tests-o <path/to/results.json>
to specify the output file name--json/--nmap/--zmap <path/to/input>
to specify the input file name(s)
- Re-enable the NIC offloads:
ethtool -K eth1 tx on rx on tso on gso on gro on lro on
- Remove the firewall rules added previously: see the comments in the respective rules file
tcpreq
can run as an unprivileged user, in which case the
Python executable requires the CAP_NET_RAW
and CAP_NET_ADMIN
capabilities.
These can be granted with setcap cap_net_admin,cap_net_raw+ep <path/to/python>
,
though this should probably only be done within a virtualenv.
Without these capabilities in place, tcpreq
must be run as root.
In this case, the user ID above is 0 and the username is root.