- 1. Why write a TCP/IP stack
- 2. The lab
- 3. Ethernet and ARP
- 4. IPv4 and ICMP
- 5. UDP and a socket API
- 6. Opening a connection
- 7. Sequence numbers
- 8. Reliable delivery
- 9. Flow control
- 10. Closing
- 11. Congestion control
- 12. SACK and timestamps
- 13. An executor and real applications
- 14. AF_XDP
- 15. Many cores
- 16. rginx
- 17. Defence
- 18. Testing a network stack
- 19. What it cost and what it is good for
A TCP/IP Stack from Scratch in Rust
Ethernet to TCP to an nginx-style server, in user space, tested against Linux
Build TCP/IP in Rust, from Ethernet frames to an nginx-style server, and test every packet against Linux.
Minimum price
$5.99
$11.99
You pay
Author earns
About
About the Book
This book builds a TCP/IP stack in Rust that runs in an ordinary process, and tests every step of it against the Linux kernel's own stack.
It starts by watching the kernel handle one HTTP request from curl to nginx, then builds rnet one layer at a time on a TAP device: Ethernet and ARP, IPv4 and ICMP, UDP with a small socket API, then TCP. The TCP part covers the handshake, sequence numbers, retransmission, flow control, closing, CUBIC congestion control, SACK and timestamps, and each chapter compares rnet's packets with what Linux sends in the same situation. Then the book makes it fast: an executor for real applications, AF_XDP to take frames straight from the NIC, and many cores. On top sits rginx, a small nginx-style server. The last part is about making it last: hostile packets and fuzzing, a seeded simulator that runs two stacks in virtual time, and an honest look at what a user-space stack costs and when it is worth it.
Some results: per small HTTP request, rnet over AF_XDP used 35 to 38% less CPU than the kernel's stack with the same HTTP code, and one rnet core served 94% of what nginx served on four. 40,000 simulator seeds pass.
It is for programmers who know some Rust and want to see how TCP really works. About 300 pages, 19 chapters in four parts, 60 figures. Every listing ran on real Google Cloud VMs, and every output and packet capture shown is copied from those runs. The code is at https://github.com/allthingssecurity/tcp-ip-stack-from-scratch-in-rust
Author
About the Author
Shashank Mohan Jain is a Senior Architect with 26 years in the IT industry. He is an Apache Camel committer, a Netty contributor and a Linux kernel contributor, and holds 45 software patents. He has written thirteen books, including Linux Containers and Virtualization (two editions), WebAssembly for Cloud, Introduction to Transformers for NLP for Apress, Hardware Sandboxes from Scratch, Confidential Computing from Scratch, eBPF from Scratch in Rust, io_uring from Scratch in Rust and Linux Kernel Modules in Rust. He writes at medium.com/@jain.sm, and the code for this book is at github.com/allthingssecurity/tcp-ip-stack-from-scratch-in-rust.
Contents
Table of Contents
Get the free sample chapters
Click the buttons to get the free sample in PDF or EPUB, or read the sample online here
The Leanpub 60 Day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms...
Earn $8 on a $10 Purchase, and $16 on a $20 Purchase
We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
Learn more about writing on Leanpub
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Learn more about Leanpub's ebook formats and where to read them
Write and Publish on Leanpub
You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!
Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.
Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.