Where OS Kernel and Network protocol stack overlaps?

Viewed 104

I'm trying to learn network protocol stack(ie. Transport, IP, datalink layer library code implementation) along with linux. I'm confused where to start.

  1. First question is whether these codes come as in-built features of linux kernel/above library layers.
  2. If so why I can see 3rd party protocol stack in some applications (by blunk micro system - developer of protocol stack)
  3. If Linux doesn't have it as core feature, is linux give only placeholders for network part(like just Macros to enable the 3rd party stack ). But an article says it has Net4 networking codebase.
  4. If linux has in-built network features what are the linux modules I need to go through or where to start? Not only in the network perspective, if i'm guided to explore in linux in all aspects (process, memory, drivers) in the "code level", it would be helpful please.

Note: I'm greedy to write my own OS and protocol stack hence trying to understand an existing system.

Thanks in advance!

2 Answers

First question is whether these codes come as in-built features of linux kernel/above library layers.

Linux kernel has network stack up to including layer 4, i.e., TCP and UDP (well, kernel + a set of utilities needed to configure it). I think DNS is in kernel too, but I am not so sure. TLS used to be implemended as a library (OpenSSL and GnuTLS are I think the most common ones), but there seems to be kernel part too now (link.

Note, that some of the TCP functionality is offloaded to the network card (hardware). At high speeds (1Gb+) you won't get full performance without these features.

I am not familiar with all VoIP related protocols, but I think they are libraries, not kernel.

If so why I can see 3rd party protocol stack in some applications (by blunk micro system - developer of protocol stack)

I believe the reason is performance. If you implement a custom stack with a subset of features, it might work better for your applications. Also there are advanced features and protocols that might not be available in the kernel itself.

If Linux doesn't have it as core feature, is linux give only placeholders for network part(like just Macros to enable the 3rd party stack ). But an article says it has Net4 networking codebase.

there is a very large codebase

If linux has in-built network features what are the linux modules I need to go through or where to start? Not only in the network perspective, if i'm guided to explore in linux in all aspects (process, memory, drivers) in the "code level", it would be helpful please.

hmmm, this is a very good question, and I don't think there is an easy answer. In my experience reading the code is the only way to figure this out. However some people tried to fish LWN.net for information.

you could probably start somewhere here: include/net/

First question is whether these codes come as in-built features of linux kernel/above library layers. If linux has in-built network features what are the linux modules I need to go through or where to start?

You can think of a protocol stack as of a library. Linux kernel has one which runs inside the kernel address space and uses kernel APIs unavailable in user-space: https://github.com/torvalds/linux/tree/master/net/ipv4

There are multiple in-depth books about Linux kernel networking. Reading one is required for good understanding.

If so why I can see 3rd party protocol stack in some applications (by blunk micro system - developer of protocol stack)

Zero-copy, low-latency and streaming (processing an Ethernet packet in CPU-L1-cache-line-sized chunks while it hasn't been read off the wire in full) networking have been problematic with Linux kernel network stack. For these reasons makers of networking hardware offered their own user-space network stacks, aka kernel bypass.

Linux kernel network stack is getting better these days with MSG_ZEROCOPY and io_uring.

Related