So guys, continuing from the previous lecture video, we have written a Linux kernel module in which
we covered these four steps so far.
Now we will code how our Linux kernel module will going to receive a message from the userspace process,
the userspace message and then send reply back to the userspace.
But before going back into the code discussion, we need to cover some theory.
So you can see in the diagram that we have a typical user space and kernel space which are interacting
with each other.
So when kernel space receives the data from the user space application via netlink socket, the data
is received in a data structure called socket buffer, Right.
So the data type of this socket buffer is struct k underscore buff and it is defined in the file Linux
slash escoveitch.
So you can see that I'm opening the file Linux Cbuft-dt Edge.
And in this file you can see here is the definition of buff buff.
So this is actually called a socket buffer and it is a data structure which is provided and used within
inside the Linux kernel.
So if you look at the definition of this data structure, it is actually a pretty complex and long data
structure starting from the line 670 to the closing parenthesis of this data structure is at line 875.
Right?
So you can see that this data structure is pretty much complex and has lots of lots of members, right?
So what is this data structure used for?
So Kernel uses this data structure extensively for multiple purposes.
That is for transferring message from one kernel subsystem to another for receiving network packet from
the outside world.
Right.
So remember that there is a TCP IP stack running in the Linux kernel.
When I say TCP IP stack, it means the Linux implementation of OSI model.
So when your machine receives a network packet from the outside world that is from the internet, the
packet movement upwards and downwards in the layers of the TCP IP stack happens in the form of this
socket buffer.
The actual packet that is received is stored in a data structure called socket buffer.
And this socket buffer data structure is then moved upwards and downwards in the layers of the TCP IP
stack.
So struct buffer is actually a very large data structure.
We shall be discussing it only in the context of netlink socket communication.
Right.
So when your Linux kernel module receives a data from the userspace via netlink socket, we will going
to receive that data into the socket buffer.
So that socket buffer is represented by SKB underscore N.
Right.
Now from this data structure, if we want to actually access the data which is actually shipped from
the userspace to kernel space, we can access that data from the data member of this data structure.
So this data structure returns a pointer to the actual data which was transferred from the userspace
to kernel space.
And now the second question arises that how can we get the length of the data?
So the length of the data can be obtained using Len member of socket buffer data structure.
Right.
So as we discussed, this socket buffer is a pretty much complex data structure.
We will only need to know how to access the data which has been shipped from the user space and how
much data has been shipped.
Right?
So for that we only need to use the data and the length member of the socket buffer as you dive deep
into the Linux kernel and explore more and more kernel subsystems, you will get more familiar with
the socket buffers.
Socket buffers have been specially designed for handling network packets moving up and down through
the layers of the TCP IP stack running in the Linux kernel.
So now let us go back and resume our discussion of implementation of our first Netlink based Linux kernel
module.