Show HN: I integrated my from-scratch TCP/IP stack into the xv6-riscv OS
github.comHi HN,
To truly understand how operating systems and network protocols work, I decided to combine two classic learning tools: the xv6 teaching OS and a from-scratch TCP/IP stack.
I'm excited to share the result: my own from-scratch TCP/IP networking stack running directly inside the xv6-riscv (https://github.com/pandax381/xv6-riscv-net) kernel.
The project uses a modern virtio-net driver, allowing it to run seamlessly in QEMU and communicate with the host machine.
Key features:
- From-Scratch Stack: The core is powered by microps (https://github.com/pandax381/microps), a TCP/IP stack I originally wrote to run in user-space as a personal project to learn the low-level details of networking.
- Kernel Integration: This project ports microps from user-space into the xv6-riscv kernel.
- Socket API: Implements standard system calls (socket, bind, accept, etc.) to enable network application development.
- User-level Tools: Comes with a simple ifconfig command, plus tcpecho and udpecho servers to demonstrate its capabilities.
This has been a fantastic learning experience. My goal was to demystify the magic behind network-aware operating systems by building the components myself.
I'd love to hear your feedback and answer any questions!
This is amazing work. Most people don’t realize how much effort and depth there is behind writing a TCP/IP stack and plugging it into xv6 with virtio-net and sockets. Huge respect for making it public. Projects like this are gold for those of us who love low-level systems.
Thank you so much for the kind words! It really means a lot, especially from someone who understands the effort involved. I'm thrilled that it's resonating with fellow low-level systems fans.
Awesome work! Thank you for showing it to the world!
I've considered writing a network stack myself. It's much more complex than most people can imagine. We have great tooling for TCP and that makes people believe it's simple technology. It's not.
Thank you! I completely agree, the complexity is definitely hidden by modern tools and abstractions. It's a challenging but rewarding project. You should give it a try, it's a fantastic way to learn!
Well done. I am actually solving the labs rn. I am on mmap, trying to get fork to work :)
Thank you! And good luck with the labs, they're a great learning experience.
Are you using any RISC-V extensions? If so, which? I couldn't find this information on the xv6 project page. It would be cool if you could run this project in bare metal.
Thanks for asking! It's compiled with -march=rv64g, so it uses the standard general-purpose extensions (IMAFD) and doesn't rely on anything exotic. Running it on bare metal is definitely a challenge I'd like to try someday! For now, the virtio-net driver is tightly coupled with QEMU, so a different network driver would be needed for specific hardware.
The readme implies that UDP is included. Is that true?
Yes, that's correct! Both TCP and UDP are implemented. There's a udpecho server included as a sample application you can use to test it out.
Well done! Thank you for sharing
Thank you for checking it out!