{"by":"VioletVillain","descendants":11,"id":40966262,"kids":[41092192,40968217,40991498,40991351,40992187,40994377],"score":44,"text":"I found hping3 and nmap&#x27;s nping to be far too slow in terms of sending individual, bare-minimum (40-byte) TCP SYN packets; other than inefficient socket I&#x2F;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 (i.e., a range of IP addresses) as their source IP parameter. Being intended for embedded devices (e.g., low-power MIPS&#x2F;Arm-based routers), Blitzping only depends on standard POSIX headers and C11&#x27;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.<p>Here are some of the performance optimizations specifically done on Blitzping:<p>* Pre-Generation : All the static parts of the packet buffer get generated once, outside of the sendto() tightloop;<p>* Asynchronous   : Configuring raw sockets to be non-blocking by default;<p>* Multithreading : Polling the same socket in sendto() from multiple threads; and<p>* Compiler Flags : Compiling with -Ofast, -flto, and -march=native (though these actually had little effect; by this point, the bottleneck is on the Kernel&#x27;s own sendto() routine).<p>Shown below are comparisons between the three software across two CPUs (more details at the GitHub repository):<p><pre><code>  #      Quad-Core &quot;Rockchip RK3328&quot; CPU @ 1.3 GHz. (ARMv8-A)        #\n  +--------------------+--------------+--------------+---------------+\n  | ARM (4 x 1.3 GHz)  | nping        | hping3       | Blitzping     |\n  +--------------------+ -------------+--------------+---------------+\n  | Num. Instances     | 4 (1 thread) | 4 (1 thread) | 1 (4 threads) |\n  | Pkts. per Second   | ~65,000      | ~80,000      | ~275,000      |\n  | Bandwidth (MiB&#x2F;s)  | ~2.50        | ~3.00        | ~10.50        |\n  +--------------------+--------------+--------------+---------------+\n\n  # Single-Core &quot;Qualcomm Atheros QCA9533&quot; SoC @ 650 MHz. (MIPS32r2) #\n  +--------------------+--------------+--------------+---------------+\n  | MIPS (1 x 650 MHz) | nping        | hping3       | Blitzping     |\n  +----------------------+------------+--------------+---------------+\n  | Num. Instances     | 1 (1 thread) | 1 (1 thread) | 1 (1 thread)  |\n  | Pkts. per Second   | ~5,000       | ~10,000      | ~25,000       |\n  | Bandwidth (MiB&#x2F;s)  | ~0.20        | ~0.40        | ~1.00         |\n  +--------------------+--------------+--------------+---------------+\n\n</code></pre>\nI tested Blitzping against both hpign3 and nping on two different routers, both running OpenWRT 23.05.03 (Linux Kernel v5.15.150) with the &quot;masquerading&quot; option (i.e., NAT) turned off in firewall; one device was a single-core 32-bit MIPS SoC, and another was a 64-bit quad-core ARMv8 CPU.  On the quad-core CPU, because both hping3 and nping were designed without multithreading capabilities (unlike Blitzping), I made the competition &quot;fairer&quot; by launching them as four individual processes, as opposed to Blitzping only using one.  Across all runs and on both devices, CPU usage remained at 100%, entirely dedicated to the currently running program.  Finally, the connection speed itself was not a bottleneck: both devices were connected to an otherwise-unused 200 Mb&#x2F;s (23.8419 MiB&#x2F;s) download&#x2F;upload line through a WAN ethernet interface.<p>It is important to note that Blitzping was not doing any less than hping3 and nping; in fact, it was doing more.  While hping3 and nping only randomized the source IP and port of each packet to a fixed address, Blitzping randomized not only the source port but also the IP within an CIDR range---a capability that is more computionally intensive and a feature that both hping3 and nping lacked in the first place.  Lastly, hping3 and nping were both launched with the &quot;best-case&quot; command-line parameters as to maximize their speed and disable runtime stdio logging.","time":1721033938,"title":"Show HN: Blitzping – A far faster nping/hping3 SYN-flood alternative with CIDR","type":"story","url":"https://github.com/Thraetaona/Blitzping"}