Live data from Hacker News

Let's code a TCP/IP stack (2016)

saminiir.com

21–30 of 55 posts

Re: Let's code a TCP/IP stack (2016)

#21

Coming from C/C++ and Having worked for 5 years within the java world now, i must admit that the naming "conventions" and variable abbreviation in c code or more specifically Linux kernel code form a high entry barrier for me. Why is it so hard to write things out? We all look up to the various Linux philosophies (keep it simple, do one thing, etc), but to me it feels that this kind of code style is not written with…

I think the name shortening is very common in practically every science - and when we are not restricted to ASCII it is even worse, you would see mostly single letter names, combined with subscripts, superscripts, fonts, extra alphabets like Greek and so on.

At least things like ifr_flags are easy to read, easy to type, and unique enough you ca search for them.

Re: Let's code a TCP/IP stack (2016)

#22
post #12

Notice these classic technologies. They’re SIMPLE. That got lost in later development up the stack.

I don't think I would describe TCP/IP as "simple". there are parts of the spec that contradict each other! it's impossible to implement fully.

Can you elaborate?

Re: Let's code a TCP/IP stack (2016)

#23

Earlier quoted context omitted.

I don't think I would describe TCP/IP as "simple". there are parts of the spec that contradict each other! it's impossible to implement fully.

The layer system used by TCP/IP (layer 2 -> 3 -> 4) makes it "simpler" because everything can be compartmentalized without worrying because it was designed to be that way. The real problem comes when you use TCP/UDP for higher level protocols and that's where the real difficulty is.

There's really no such system. In TCP/IP, we refer to "layer 3" and "layer 4" protocols, in reference to OSI, but TCP/IP isn't an OSI protocol, the lines between L2 and L3 are blurred by things like ARP and DHCP (or completely eliminated in overlay networks and multicast), and none of the rest of the layers are even informally specified for TCP/IP.

If all you're saying is that TCP/IP has, among its many goals, a separation of concerns, sure. But most major systems designs have separations of concerns.

Re: Let's code a TCP/IP stack (2016)

#24
post #23

Earlier quoted context omitted.

The layer system used by TCP/IP (layer 2 -> 3 -> 4) makes it "simpler" because everything can be compartmentalized without worrying because it was designed to be that way. The real problem comes when you use TCP/UDP for higher level protocols and that's where the real difficulty is.

There's really no such system. In TCP/IP, we refer to "layer 3" and "layer 4" protocols, in reference to OSI, but TCP/IP isn't an OSI protocol, the lines between L2 and L3 are blurred by things like ARP and DHCP (or completely eliminated in overlay networks and multicast), and none of the rest of the layers are even informally specified for TCP/IP. If all you're saying is that TCP/IP has, among its many goals, a sepa…

The fundamental problem is that once your break/compartmentalize into layers it's harder apply global optimizations at local layers. You are trading off ease of implementation and compositionality for performance. You have to bubble up optimizations up the stack.

This is partly why QUIC is based on UDP instead TCP. You don't have all the information needed at the TCP layer to do the kind of optimizations that QUIC does.

Re: Let's code a TCP/IP stack (2016)

#25
post #23

Earlier quoted context omitted.

There's really no such system. In TCP/IP, we refer to "layer 3" and "layer 4" protocols, in reference to OSI, but TCP/IP isn't an OSI protocol, the lines between L2 and L3 are blurred by things like ARP and DHCP (or completely eliminated in overlay networks and multicast), and none of the rest of the layers are even informally specified for TCP/IP. If all you're saying is that TCP/IP has, among its many goals, a sepa…

The fundamental problem is that once your break/compartmentalize into layers it's harder apply global optimizations at local layers. You are trading off ease of implementation and compositionality for performance. You have to bubble up optimizations up the stack. This is partly why QUIC is based on UDP instead TCP. You don't have all the information needed at the TCP layer to do the kind of optimizations that QUIC do…

This lack of "global optimization" I think is something that should be solved by a new protocol stack. (If it could be done without replacing the whole stack i'd be in favor of it, but I have no idea how)

Say you have a backend tcp http REST app that takes requests to modify a widget. To receive the request, the payload will pass over a series of networks and protocols, all with potentially different restrictions and modifications, until it gets to a load balancer, and then maybe a service mesh router, to a network service listening on the node of some container orchestrator, and finally read by the backend app.

All of the layers will have been replaced numerous times, and possibly the actual data payload modified. But the only thing your backend app knows is the final state. And then, somewhere along the way, there is an error. It could have happened anywhere along the chain, for who knows why. But you and the app server won't know when or where or why the error happened because none of the information about the changing layers (or network operations along the way) is carried along.

If the entire stack were not actually a stack, but instead a kind of commit log of transactions and instructions, we could see every single step in a transaction (ideally verified by cryptographic checksum). This would make it faster to diagnose problems and allow automation to work around known issues - in addition to making it harder for attackers to mess with traffic. In the simplest examples it would look like a stack, but for more complex paths it would look like a log. We could also potentially use this method to do away with service meshes.

Re: Let's code a TCP/IP stack (2016)

#26
post #14

Have a look at a TCP/IP stack written for ham radio, originally for CP/M: http://www.ka9q.net/code/ka9qnos/

Nostalgia anecdote: we used KA9Q as the routing software on a 286 PC with an ISDN uplink.

ISDN was super fast - I remember playing Warcraft 2 on an ISDN connect with a friend down the street :)

Re: Let's code a TCP/IP stack (2016)

#27
Past related threads:

Let's code a TCP/IP stack, 1: Ethernet & ARP (2016) - https://news.ycombinator.com/item?id=17316487 - June 2018 (47 comments)

Let's Code a TCP/IP Stack: TCP Retransmission - https://news.ycombinator.com/item?id=14701199 - July 2017 (30 comments)

Let's code a TCP/IP stack, 1: Ethernet and ARP - https://news.ycombinator.com/item?id=11234229 - March 2016 (49 comments)

Re: Let's code a TCP/IP stack (2016)

#29
ARP's fun but it's arguably the least fun bit of the TCP/IP stack. Here are the other articles from the series.

https://www.saminiir.com/lets-code-tcp-ip-stack-2-ipv4-icmpv...

https://www.saminiir.com/lets-code-tcp-ip-stack-3-tcp-handsh...

https://www.saminiir.com/lets-code-tcp-ip-stack-4-tcp-data-f...

https://www.saminiir.com/lets-code-tcp-ip-stack-5-tcp-retran...

Re: Let's code a TCP/IP stack (2016)

#30

This is an awesome reference but I wish the code was shown as part of the tutorials. The Github code today is somewhat more complicated to follow. If you know of any tutorials that walk through a TCP/IP stack with all relevant code I'd love to hear of it.

In addition to the Stevens books already mentioned, there's also volume 2 of Comer's Xinu OS book: Operating System Design, Vol. 2: Internetworking with Xinu, ISBN-13: 978-0136374145 ( https://www.amazon.com/Operating-System-Design-Vol-Internetw... ). Unfortunately, this book was written in 1987, so it's a bit dated (e.g. no IPv6). I think it's still useful to learn the basics of a TCP/IP implementation.

Interesting, thanks for the reference.
Post reply on HN