Skip to main content
Be Bitwise

Networking Stacks Compared

Linux vs Windows Internals Compared · Operating Systems track

9 min read

In this module

How Packets Flow Through the OS

The networking stack is one of the gnarliest subsystems anywhere in an OS. It chews through everything from raw Ethernet frames to TLS handshakes, juggles firewalling and routing and QoS in parallel, and runs at line rate while doing it. Linux and Windows have grown very different architectures here for moving, inspecting, and shaping packets.

Linux Networking Stack

Packet Flow: Ingress

text
NIC Hardware
│ (DMA transfer to ring buffer)
▼
NAPI (New API) / Interrupt Handler
│ (sk_buff allocation)
▼
Network Device (net_device)
│
▼
netfilter/nftables: PREROUTING chain
│ (DNAT, connection tracking)
▼
Routing Decision
├── Local delivery ──→ netfilter: INPUT chain
│ │
│ ▼
│ Transport Layer (TCP/UDP)
│ │
│ ▼
│ Socket receive queue
│ │
│ ▼
│ Application (recv/read)
│
└── Forward ──→ netfilter: FORWARD chain
│
▼
netfilter: POSTROUTING chain
│ (SNAT, masquerade)
▼
Output NIC

The Socket Buffer (sk_buff)

sk_buff (the "socket buffer") is the workhorse struct that carries every packet through the Linux stack:

c
struct sk_buff {
struct sk_buff *next, *prev; // Linked list pointers
struct sock *sk; // Owning socket
struct net_device *dev; // Network device
unsigned char *head; // Start of allocated buffer
unsigned char *data; // Start of current data
unsigned char *tail; // End of current data
unsigned char *end; // End of allocated buffer
unsigned int len; // Data length
unsigned int data_len; // Fragmented data length
__u16 protocol; // Ethernet protocol
__u16 transport_header; // Transport header offset
__u16 network_header; // Network header offset
__u16 mac_header; // MAC header offset
// ... many more fields
};

As a packet climbs or descends the stack, the kernel just slides the data pointer over the next protocol header — no memcpy, no reallocation:

text
┌──────────┬─────────┬──────────┬──────────┬──────────┐
│ │ Ethernet│ IP │ TCP │ Payload │
│ headroom │ header │ header │ header │ │
└──────────┴─────────┴──────────┴──────────┴──────────┘
▲ head ▲ data moves as packet traverses layers ▲ tail
Zero-Copy Networking

Modern Linux supports several zero-copy techniques: sendfile() transfers file data to a socket without copying through user space, MSG_ZEROCOPY allows the kernel to send directly from user buffers, and XDP (eXpress Data Path) processes packets in the driver before sk_buff allocation. These techniques eliminate memory copies for high-performance networking.

netfilter / nftables

Linux's packet filtering rides on the netfilter framework. The modern user-facing tool is nftables, which is steadily replacing the venerable iptables:

text
nftables chains (simplified):
┌──────────────────────────────────────────┐
│ PREROUTING → Incoming packets │
│ INPUT → Packets destined locally │
│ FORWARD → Packets being routed │
│ OUTPUT → Locally generated packets │
│ POSTROUTING → All outgoing packets │
└──────────────────────────────────────────┘
bash
# nftables rule examples
nft add table ip filter
nft add chain ip filter input { type filter hook input priority 0 \; }
nft add rule ip filter input iif lo accept
nft add rule ip filter input tcp dport 22 accept
nft add rule ip filter input tcp dport 80 accept
nft add rule ip filter input ct state established,related accept
nft add rule ip filter input drop

nftables wraps connection tracking (conntrack), NAT, packet mangling, and logging into one coherent surface. For anything beyond that, you can hook eBPF programs directly into the networking path and write packet processing in C.

Windows Networking Stack

Architecture

The Windows stack: WFP's layers live inside tcpip.sys, not underneath it

Older diagrams show a TDI layer between AFD and tcpip.sys. TDI is deprecated: AFD talks to tcpip.sys directly, kernel-mode clients use Winsock Kernel (WSK), and packet inspection that used to need TDI filter drivers now goes through WFP callouts registered at the layers tcpip.sys hosts.

NDIS (Network Driver Interface Specification)

NDIS is Windows's answer to Linux's net_device. It pins down exactly how network drivers and the protocol stack are allowed to talk to each other:

text
┌────────────────────────────┐
│ Protocol Drivers │ (tcpip.sys)
│ (bind to adapters) │
├────────────────────────────┤
│ NDIS Library │ (ndis.sys)
│ (manages bindings, │
│ provides common services) │
├────────────────────────────┤
│ Miniport Drivers │ (hardware-specific)
│ (talk to NICs) │
├────────────────────────────┤
│ Filter Drivers │ (inspect/modify packets)
│ (inserted between layers) │
└────────────────────────────┘

Miniport drivers do the actual hardware grunt work; protocol drivers (chiefly tcpip.sys) implement TCP/IP; filter drivers slot in between, sniffing or rewriting packets as they pass — exactly where firewalls and monitoring tools wedge themselves in.

Winsock

Winsock is Windows's sockets API. Mostly BSD-shaped, with a handful of Windows-only quirks bolted on top:

c
#include <winsock2.h>
#pragma comment(lib, "ws2_32.lib")
// Initialise Winsock (required on Windows)
WSADATA wsaData;
WSAStartup(MAKEWORD(2, 2), &wsaData);
// Create socket
SOCKET sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
// Connect
struct sockaddr_in addr = {
.sin_family = AF_INET,
.sin_port = htons(80),
};
inet_pton(AF_INET, "93.184.216.34", &addr.sin_addr);
connect(sock, (struct sockaddr *)&addr, sizeof(addr));
// Send/Receive
send(sock, "GET / HTTP/1.0\r\n\r\n", 18, 0);
char buf[4096];
int received = recv(sock, buf, sizeof(buf), 0);
closesocket(sock);
WSACleanup();

A few Winsock papercuts that catch BSD-trained programmers:

  • You have to bookend your code with WSAStartup and WSACleanup
  • The handle type is SOCKET, not int
  • Closing is closesocket(), not plain close()
  • WSA-prefixed functions (WSARecv, WSASend, WSAIoctl) extend the basic API
  • WSARecv with an OVERLAPPED slots straight into IOCP for async I/O

Windows Filtering Platform (WFP)

WFP is the current packet-filtering framework on Windows. It replaces the older TDI filters and NDIS intermediate filter drivers, both of which had their own special breed of misery:

text
WFP Filtering Layers:
┌──────────────────────────────────┐
│ Application Layer (ALE) │ - Per-connection filtering
│ - ALE Auth Connect │ (allow/block connections)
│ - ALE Auth Receive/Accept │
├──────────────────────────────────┤
│ Transport Layer │ - Per-packet filtering
│ - Inbound/Outbound Transport │ (TCP/UDP level)
├──────────────────────────────────┤
│ Network Layer │ - IP-level filtering
│ - Inbound/Outbound Network │ (source/dest IP, protocol)
├──────────────────────────────────┤
│ Forward Layer │ - Routed packet filtering
├──────────────────────────────────┤
│ NDIS Layer │ - Lowest level
│ - Inbound/Outbound MAC │ (Ethernet frame level)
└──────────────────────────────────┘

Windows Defender Firewall sits on top of WFP, and third-party security products plug in via their own callout drivers at the same layers.

Key Concept
WFP vs netfilter

Both WFP and netfilter provide layered packet filtering with connection tracking. WFP organises filters into layers (application, transport, network) with explicit classification APIs. netfilter uses a chain-based model (PREROUTING, INPUT, FORWARD, OUTPUT, POSTROUTING) with tables (filter, nat, mangle). WFP is more structured and API-driven; netfilter is more flexible and scriptable. Both support stateful inspection, NAT, and programmable callbacks.

Comparison Table

FeatureLinuxWindows
Socket APIBSD sockets (native)Winsock (BSD-compatible wrapper)
Packet structuresk_buffNET_BUFFER / NET_BUFFER_LIST (NDIS)
Driver interfacenet_device / NAPINDIS miniport
Firewall frameworknetfilter/nftablesWindows Filtering Platform (WFP)
Firewall toolnft / iptablesnetsh / Windows Defender Firewall
Packet captureAF_PACKET / libpcapNDIS filter / WinPcap / Npcap
ProgrammableeBPF/XDPWFP callout drivers; eBPF for Windows (open-source project, hooks fewer points than Linux)
Connection trackingconntrack (netfilter)Built into WFP/tcpip.sys
Performance pathXDP, AF_XDPRSS, RSC

Both stacks have soaked up enough production traffic to bend without breaking. Linux's lives in the open, documents itself reasonably well, and leans hard on eBPF for runtime programmability — write a verifier-checked C program and the kernel runs it inline on every packet, no recompile needed. Windows sells you structure: formal NDIS interfaces, tight integration with IPsec and Defender, a well-defined path through the layers if you're willing to write to them.

Pulling either stack apart pays dividends across network programming, security tool development, performance work, and forensics. The platform in front of you will vary; the fundamentals carry over every time.