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
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 NICThe Socket Buffer (sk_buff)
sk_buff (the "socket buffer") is the workhorse struct that carries every packet through the Linux stack:
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:
┌──────────┬─────────┬──────────┬──────────┬──────────┐│ │ Ethernet│ IP │ TCP │ Payload ││ headroom │ header │ header │ header │ │└──────────┴─────────┴──────────┴──────────┴──────────┘▲ head ▲ data moves as packet traverses layers ▲ tailModern 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:
nftables chains (simplified):┌──────────────────────────────────────────┐│ PREROUTING → Incoming packets ││ INPUT → Packets destined locally ││ FORWARD → Packets being routed ││ OUTPUT → Locally generated packets ││ POSTROUTING → All outgoing packets │└──────────────────────────────────────────┘# nftables rule examplesnft add table ip filternft add chain ip filter input { type filter hook input priority 0 \; }nft add rule ip filter input iif lo acceptnft add rule ip filter input tcp dport 22 acceptnft add rule ip filter input tcp dport 80 acceptnft add rule ip filter input ct state established,related acceptnft add rule ip filter input dropnftables 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
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:
┌────────────────────────────┐│ 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:
#include <winsock2.h>#pragma comment(lib, "ws2_32.lib")
// Initialise Winsock (required on Windows)WSADATA wsaData;WSAStartup(MAKEWORD(2, 2), &wsaData);
// Create socketSOCKET sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
// Connectstruct 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/Receivesend(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, notint - Closing is
closesocket(), not plainclose() - WSA-prefixed functions (WSARecv, WSASend, WSAIoctl) extend the basic API
WSARecvwith anOVERLAPPEDslots 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:
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.
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
| Feature | Linux | Windows |
|---|---|---|
| Socket API | BSD sockets (native) | Winsock (BSD-compatible wrapper) |
| Packet structure | sk_buff | NET_BUFFER / NET_BUFFER_LIST (NDIS) |
| Driver interface | net_device / NAPI | NDIS miniport |
| Firewall framework | netfilter/nftables | Windows Filtering Platform (WFP) |
| Firewall tool | nft / iptables | netsh / Windows Defender Firewall |
| Packet capture | AF_PACKET / libpcap | NDIS filter / WinPcap / Npcap |
| Programmable | eBPF/XDP | WFP callout drivers; eBPF for Windows (open-source project, hooks fewer points than Linux) |
| Connection tracking | conntrack (netfilter) | Built into WFP/tcpip.sys |
| Performance path | XDP, AF_XDP | RSS, 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.