2 |
3 |
4 |
5 |
6 |
7 |
Blitzping
8 |
9 |
10 | A very high-speed, configurable, and portable packet-crafting utility optimized for embedded devices
11 |
12 |
13 |
14 |
15 |
16 | ***
17 |
18 | # Background
19 |
20 | I found [hping3](https://linux.die.net/man/8/hping3) and nmap's [nping](https://linux.die.net/man/1/nping) to be far too slow in terms of sending individual, bare-minimum (40-byte) TCP packets; other than inefficient socket I/O, they were also attempting to do far too much unnecessary processing in what should have otherwise been a tight execution loop. Furthermore, none of them were able to handle [CIDR notations](https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing) (i.e., a range of IP addresses) as their source IP parameter. Being intended for embedded devices (e.g., low-power MIPS/Arm-based routers), Blitzping only depends on standard POSIX headers and C11's libc (whether musl or gnu). To that end, even when supporting CIDR prefixes, Blitzping is significantly faster compared to hping3, nping, and whatever else that was hosted on GitHub (benchmarks below).
21 |
22 | Here are some of the performance optimizations specifically done on Blitzping:
23 | * **Pre-Generation:** All the static parts of the packet buffer get generated once, outside of the `sendto()` tightloop;
24 | * **Asynchronous:** Configuring raw sockets to be non-blocking by default;
25 | * **Socket Binding:** Using `connect()` to bind a raw socket to its destination only once, replacing `sendto()`/`sendmmsg()` with `write()`/`writev()`;
26 | * **Queueing:** Queues many packets to get processed *inside* the kernelspace (i.e., `writev()`), rather repeating userspace->kernelspace syscalls;
27 | * **Memory:** Locking memory pages and allocating the packet buffer in an *aligned* manner;
28 | * **Multithreading:** Polling the same socket in `sendto()` from multiple threads; and
29 | * **Compiler Flags:** Compiling with `-Ofast`, `-flto`, and `-march=native` (these actually had little effect; by this point, the entire bottleneck lays on the Kernel's own `sendto()` routine).
30 |
31 | ## License
32 |
33 | Blitzping's source code is licensed under the GNU General Public License v3.0 or later ("GPLv3+"), Copyright (C) 2024 Fereydoun Memarzanjany. Blitzping comes with ABSOLUTELY NO WARRANTY. Blitzping is free software, and you are welcome to redistribute it under certain conditions; see the GPLv3+. If you wish to report a bug or contribute to this project, visit this repository: https://github.com/Thraetaona/Blitzping
34 |
35 | Usage:
36 | `blitzping