network interface card (NIC)

2022-04-17 ยท 2 min read


These are the phyiscal hardware devices responsible for actually, phyiscally sending bits over the proverbial wire. In OSI model terms, they usually bridge L1 (Phyiscal Layer) and L2 (Data-link Layer), though some fancy NICs can handle the whole TCP/IP stack.

Most consumer-grade hardware comes with a NIC integrated into the CPU or Motherboard. NICs can also be purchased separately and hooked up via the PCI bus.

These NICs are then typically connected via a physical Ethernet connection or provide wireless WiFi connection to a local router.

NICs are abstracted away by the kernel with network interfaces for userspace applications to configure and consume.

For a simplified mental model, I like to think of a NIC as a set of receive (rx) queues and transmit (tx) queues for sending and receiving link-layer frames.

The tx/rx queues are typically FIFO ring-buffers. If you don't pull off frames fast enough or push too many frames at once, you'll start overwriting old frames : ).

NICs typically provide a low-level interface or driver for the kernel (or more rarely, a userspace application) to pump outbound link-layer frames into the network and read inbound link-layer frames from the network.

NICs are addressed via MAC addresses on the local physical network. MAC addresses need to be unique per local network, but aren't globally unique.

Kernel Bypass #

Userspace applications can completely bypass the kernel and send/receive packets directly from a NIC. Doing this by hand would be quite tedious, as different NICs often have different APIs. People tend to use a library like DPDK (Data-Plane Development Kit) for this purpose. As for why you would want to do this, the answer is usually performance and control. Some exotic NICs or FPGA accelerators may also require bypassing the kernel to take full advantage.