Member-only story

Uncovering the Path of a Network Packet: From Hardware to User-Space Programs

TJ. Podobnik, @dorkamotorka
6 min readDec 5, 2022

Have you ever wondered how an application receives a network packet? It’s a fascinating topic that delves into the intricacies of the Linux networking stack. But where do you start? Understanding packets and their formats are just the tip of the iceberg.

In this post, we’ll take a deep dive into the journey of a network packet, from the moment it’s received at the hardware level to its arrival in a user-space program. I’ll share my own experiences, research, and insights as a non-kernel developer, and explain how this knowledge can be used in projects like analyzing container primitives and BPF programs. Join me on a journey to uncover the inner workings of network packets.

Linux Networking Stack

This picture should already sum it up for you, but if you’re fairly new to the topic you might as well wanna know what’s the purpose of each component and what are the states through which the packet goes before it reaches your application.

Stack Breakdown

Virtually, we can disassemble the Linux networking stack in 3 stages:

  • Device Driver
  • Kernel Space
  • User Space

In the upcoming sections, we will look at each one in detail, although nowadays the distinction between each one of them is relatively blurry, due to so many interconnected features they share. As you’ve probably assumed it all starts with the Network Interface Card (NIC) receiving a network packet.

Device driver

NIC receives a packet either through twisted pair or wirelessly and checks if the packet is well-formed by validating FCS and if the packet is targeted for itself by checking the MAC address.

NIC then uses Direct Memory Access (DMA) to transfer the packet to a Ring Buffer. DMA is a system inside your PC that handles data transfer between the memory and various devices that need to access it in order to offload the CPU of data transfer tasks. Each NIC has its RX/TX Ring Buffer for receiving and transmitting network packets. Ring Buffer is basically a fixed-size circular FIFO queue for those of you that want a more abstract definition.

--

--

TJ. Podobnik, @dorkamotorka
TJ. Podobnik, @dorkamotorka

Responses (2)

Write a response