So guys, now let us start with understanding Netlink sockets, which is the subject of this course.
So Netlink sockets is a technique to do IPC between user space and kernel space.
We will going to understand that how netlink sockets provide a mechanism to carry out data exchange
from user space to kernel space and vice versa.
So we will start with the discussion on computer architecture at a higher level.
A typical computer architecture is actually a layered architecture which can be divided into three layers.
The first layer is an application layer, followed by a middle layer, which is called a kernel layer
or kernel space.
And the bottommost layer is the hardware layer.
Now, as the name of the layer suggests, the hardware layer is a layer where all the hardware is sit.
The hardware could be your CPU or memory which comes in built with any computer system and the rest
of the devices, which is attached to your computer system.
Right.
The topmost layer, on the other hand, is an application layer where it's all the softwares which you
use in your day to day life.
The operating system sits in the middle layer.
That is the layer between application layer and the hardware layer called the kernel layer or kernel
space.
So your operating system is actually logically sits between the application layer and the hardware layer.
Now when it comes to controlling these hardware devices, it is your kernel layer that is operating
system which actually directly interacts with the underlying hardware is the piece of software which
makes this interaction possible between the operating system and the underlying hardware.
Devices are called device drivers.
These device drivers are nothing, but these are Linux kernel module which after compilation are inserted
into the kernel.
These device drivers is a piece of code which is specific to the hardware.
For example, you will write a separate device driver code for a hardware which is camera.
You will write a separate device driver code for a mouse and et cetera.
ET cetera.
As many hardware devices are there as many device drivers you have to write?
So remember, at the end of the day, these device drivers are nothing, but these are Linux kernel
modules.
Now, when it comes to the communication between the application and the kernel, then there are several
mechanisms or facilities that is provided by our operating system to facilitate this communication.
The netlink socket is the one which we will going to discuss in this course.
The rest of the techniques are actually not specifically developed for carrying out IPC between application
and kernel layer, but these can also be used for communication.
However, each of these techniques have some limitations which we will explore later when we will going
to discuss each of these techniques in in the follow up courses on Linux kernel.
So Netlink sockets is the one which the kernel designer has specially developed to facilitate the data
exchange between application and the kernel layer.
Now, when it comes to the communication between the two applications running in the application layer,
we achieve this communication using our usual inter-process communication techniques, right?
So I have a separate course on IPC, which covers all the IPC techniques between the two applications
running in the application layer.
If you are interested, you can take a look.
So now the question arises that how is it possible to control or interact with the underlying hardware
device right from our application sitting in the application layer.
For example, suppose you have an application app one and you want to control the hardware device which
sits in the application layer.
What is the mode of communication that you will use?
The answer is simple The computer architecture do not allows the application sitting in the application
layer to interact with the hardware devices directly.
The application layer has to communicate with the kernel mode, specifically saying the application
has to interact with the device drivers.
And it is this device driver which will relay the communication to a particular device.
Right.
So device drivers actually sits as a middleman between the application and the underlying devices.
If the application has to place an order to the hardware device to perform some action, that particular
order has to go via device driver code, which was specifically written for that particular device,
which is present in the hardware layer.
So this diagram certainly makes a good picture in our mind about the overall computer architecture and
design and how the communication between the three layers of a typical computer architecture happens.
Now we understand the role of the device drivers clearly, right?
In this course, we will not going to write a device driver, but rather we will going to write a Linux
kernel module, right?
Remember, all device drivers could be Linux kernel module, but all Linux kernel modules are not device
drivers.