Linux_Network_Device_Drivers_Overview_2020
Linux_Network_Device_Drivers_Overview_2020
Table of Contents
1 Device Drivers................................................................................................................1
2 Linux Network Stack......................................................................................................2
3 Network Device Drivers.................................................................................................3
3.1 Packet Transmission................................................................................................3
3.2 Packet Reception.....................................................................................................4
4 MACVLAN....................................................................................................................4
5 Traffic Classifier, tc........................................................................................................4
References.........................................................................................................................5
1 Device Drivers
A device driver is code in the
OS kernel that directly interacts
with hardware devices (Fig. 1).
Device drivers are an important
part of the kernel. They interact
directly with the hardware so
are complex, they are a poten-
tial security risk, and they must
be efficient. In Linux, device
drivers account for about 75-
80% of the kernel code (Ch. 2
in [1]).
Linux has 3 classes of devices
(Ch. 7 in [1], Ch. 1 in [2]):
1. Character devices:
these are devices that re-
ceive/send data serially
as a stream of bytes.
E.g. keyboard, display,
printer, mouse.
Figure 1: Structure of the Linux Kernel (Fig. 1-1 from [2]) 2. Block devices: these
deal with chunks of data
that can be accessed randomly. E.g. disks which consist of sectors, usually of size 512
bytes, that can be accessed in arbitrary order.
3. Network devices: these are similar to character devices as they deal with data serially.
However, they have different characteristics such as highly variable delay, variable er-
ror rate, complex network protocols, etc. Data is often read/written in units of one
variable-length packet. With most character and block devices, data in read only when
TCP UDP
IP sk_buff
Pool
send( ) recv( )
Ethernet
Driver
ISR
Task Queue
Interrupt
TX Buf
Ethernet
Adapter
(NIU)
LAN
RCV Buf cable
1 The Linux networking design accommodates assorted transport and network protocols. As TCP, UDP and IP
are the most widely used, we refer only to these here.
2 The functions mentioned in this document are only approximate. To thoroughly understand the network
stack or specific drivers, refer to the source code and developer documentation for the current kernel.
3 For ease of understanding, we present only a simplified view of the common case. Refer to [2] and the
source code for full details and optimisations.
4 MACVLAN
A MACVLAN is a pseudo-device [3]. The network driver for a MACVLAN is inserted
between the IP layer and a physical network driver, such as the Ethernet driver in Fig. 1. To
the IP layer, it looks like any other network driver. It does not directly control any hardware.
Instead, it treats the Ethernet driver as a virtual network adapter. Several MACVLAN drivers
can be inserted side-by-side above the same Ethernet driver, thus creating several pseudo-in-
terfaces. This is useful for creating several execution containers such as Dockers on a single
Linux system [4].
5 Traffic Classifier, tc
The Linux tc module makes use of the hook mechanisms in the Linux kernel. It registers it-
self as a hook for packets in each interface for which it ios configured. When a packet is
References
[1] M. Beck, et al., Linux Kernel Programming, 3rd ed., Pearson, 2002.
[2] J. Corbet, A. Rubini, and G. Kroah-Hartman, Linux Device Drivers, 3rd ed., O’Reilly,
2005.
[3] Hangbin Liu, “Introduction to Linux interfaces for virtual networking”, https://developer-
s.redhat.com/blog/2018/10/22/introduction-to-linux-interfaces- for-virtual-networking/
macvlan, Accessed: 7 April, 2020
[4] Anoushka Banerjee & Shaifu Gupta, “CS549: Quick Guide to Virtual Networking”,
Moodle, IIT Mandi, April 2020.