Networking Stack
Relevant source files
The following files were used as context for generating this wiki page:
The networking stack manages data transmission and reception across various network protocols and hardware devices. It acts as a protocol engine that translates standardized network protocols into Linux kernel API calls to facilitate communication between peer hosts. The stack encompasses core networking code, hardware-specific drivers, and specialized subsystems like wireless (mac80211) and network file systems (NFSD).
Sources: Documentation/process/maintainer-netdev.rst:17-21, Documentation/filesystems/nfs/nfsd-maintainer-entry-profile.rst:10-14, 451-454
Subsystem Architecture and Components
The networking stack resides primarily under the net/ directory for core code (e.g., IPv6) and drivers/net/ for hardware-specific drivers. It employs several mechanisms for data flow, including hardware interrupts, softirqs, and tasklets to handle high-volume traffic efficiently.
Primary Subsystems
- Netdev: The primary mailing list and development domain for all Linux network-related code.
- mac80211: A wireless networking stack that supports station and monitor modes.
- NFSD: The in-kernel NFS server implementation that provides access to local file systems over the network.
- Generic Netlink: A communication bus used for netlink-based protocols.
Sources: Documentation/process/maintainer-netdev.rst:17-21, Documentation/driver-api/80211/mac80211.rst:7-12, Documentation/filesystems/nfs/nfsd-maintainer-entry-profile.rst:16-19, Documentation/networking/generic_netlink.rst:7-8
Execution Contexts
The networking stack operates across different CPU states to manage data processing without blocking the system.
The diagram shows the hierarchy of execution where hardware interrupts preempt softirqs, which in turn preempt user context tasks.
Sources: Documentation/kernel-hacking/hacking.rst:24-38, 63-68
Data Path and Processing
Data processing follows a strict path from hardware arrival to user-space delivery. Interrupt handlers acknowledge hardware events, while softirqs perform the bulk of the packet processing.
Receive and Transmit Paths
In wireless subsystems like mac80211, the stack handles specific tasks:
- Receive (RX): Manages packet alignment and frame filtering.
- Transmit (TX): Handles transmit status and rate control.
Sources: Documentation/driver-api/80211/mac80211.rst:64-70, 93-98
Critical Functions and Macros
The following table lists key identifiers used in network driver development:
| Identifier | Description |
|---|---|
ieee80211_alloc_hw | Allocates a hardware structure for wireless devices. |
ieee80211_register_hw | Registers a hardware device with the mac80211 stack. |
ieee80211_rx | Passes a received frame into the mac80211 stack. |
netif_stop_queue | Stops the transmission queue for a network interface. |
in_interrupt() | Returns true if the CPU is currently serving an interrupt. |
Sources: Documentation/driver-api/80211/mac80211.rst:31-40, 93-118, Documentation/kernel-hacking/hacking.rst:49-50
Development and Maintenance Process
Network development follows a specific cadence with dedicated git trees and coding conventions.
Git Tree Management
Maintainers use two primary trees to manage the flow of code:
- net: Contains fixes for existing code already in the mainline kernel.
- net-next: Accumulates new features and content for future releases.
Sources: Documentation/process/maintainer-netdev.rst:55-66
Coding Conventions
The networking stack enforces specific style rules to maintain readability across its massive codebase:
- Reverse Christmas Tree (RCS): Local variable declarations must be ordered from longest line to shortest.
- Reverse Christmas Tree Order: In NFSD, new local variables are added to functions in this specific order.
/* Example of Reverse Christmas Tree ordering */
struct scatterlist *sg;
struct sk_buff *skb;
int err, i;
Sources: Documentation/process/maintainer-netdev.rst:246-252, Documentation/filesystems/nfs/nfsd-maintainer-entry-profile.rst:155-156
Patch Lifecycle
Patches submitted to the netdev list are tracked via Patchwork and assigned specific states.
The sequence shows how a patch moves from submission to acceptance or a request for changes.
Sources: Documentation/process/maintainer-netdev.rst:111-140
Observability and Debugging
The networking stack provides various tools for monitoring operations and diagnosing failures.
| Tool Type | Description |
|---|---|
| Static Trace Points | Favored for hot paths due to low overhead. |
| dprintk | Used for detailed info in pre-set groups; inappropriate for I/O paths. |
| netdevsim | A test driver that exercises configuration APIs without hardware. |
| lockdep | Tracks lock acquisition to find potential deadlocks in complex paths. |
Sources: Documentation/filesystems/nfs/nfsd-maintainer-entry-profile.rst:116-135, Documentation/process/maintainer-netdev.rst:306-310, Documentation/kernel-hacking/hacking.rst:307-315
Summary
The Linux Networking Stack provides a modular architecture for managing network data. It utilizes a hierarchical execution model to balance hardware responsiveness with complex protocol processing. Maintenance is strictly governed by dedicated git trees (net and net-next) and specific coding standards like the Reverse Christmas Tree variable ordering to ensure long-term stability and code quality.