How do I implement a Network Stack?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
TheDragon
Member
Member
Posts: 43
Joined: Mon Aug 25, 2008 8:23 pm
Location: Middle of Nowhere

How do I implement a Network Stack?

Post by TheDragon »

I think I could manage if only I knew where to start. At what level of the OSI model do I need to start implementing protocols, and how do I interface with the hardware that takes care of the lower levels? And how standardized are the various NIC interfaces? Please help me!
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: How do I implement a Network Stack?

Post by Combuster »

Q1) see Q2,
Q2) google,
Q3) interfaces are different per generation of chip
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
TheDragon
Member
Member
Posts: 43
Joined: Mon Aug 25, 2008 8:23 pm
Location: Middle of Nowhere

Re: How do I implement a Network Stack?

Post by TheDragon »

When I posted, I had a very hard time getting anything that definitely answered my question on Google or anywhere, and had meant for some kind person who had already implemented a network stack to share that info. However, I recently found on Wikipedia, http://en.wikipedia.org/wiki/Network_In ... Controller. From this I gather that the NIC takes care of OSI levels 1&2, and I have to provide everything else, from Network level up. Am I right?

No response is necessary, but validation would be nice.

Thank you.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: How do I implement a Network Stack?

Post by Combuster »

Not quite, hardware implements anything between 1 and almost all layers, communicating with you on the second level and higher, all depending on the type of chip you use. To get a specific answer, you'd need to look at the manual for the chip/device in question and see for yourself how deep down the network stack you need or want to go.

At the other end this means that you need to be able to build everything from ethernet (if you use that medium) frames up to cover all cases, and hook up the driver at the level you want.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Warthog
Posts: 6
Joined: Fri Apr 23, 2010 11:33 pm

Re: How do I implement a Network Stack?

Post by Warthog »

Whenever you talk about OSI you're talking very abstractly.

If you're thinking specifically about IPv4 networking over Ethernet, it's very typical that the NIC implements OSI levels 1 and 2.

Or less abstractly, virtually all Ethernet cards will implement a set of 802.3 standards for "Physical" Ethernet, and they'll also implement the Ethernet data link layer (more or less, the framing of Ethernet packets).

More recently, maybe last 5 years or so, Ethernet NICs have begun to implement higher layer protocols (or parts of them) as well, for efficiency. For example, the card might do some IP checksum offloading (OSI level 3).

Or, a more extreme example, some of the 10Gigabit NICs used in data centers and high-performance computing environments offer TCP and RDMA offloading on the NIC as well, offloading the entire stack from OSI level 4 down in the NIC.
Post Reply