So guys, next field that we need to discuss is the sequence number.
So we need to discuss two more fields.
That is the sequence number followed by PID.
After that, we will be in a position to write our first line of code, implementing the interaction
between user space and kernel space via netlink.
So now let us understand the usage of this field, which is called sequence number.
So when user space application sends a netlink request message to kernel space, it must set a unique
number to this request.
If user space application sets acknowledgment flag in the netlink message that it is sending.
So note that by setting the acknowledgement flag, the application will expect a feedback or reply from
the kernel space in response to the order the user space application had sent to the kernel space.
Right.
So when kernel space replies back with confirmation message to the user space application, it sets
the same sequence number which was specified in the request message sent from the user space application.
Right.
Now you must be wondering that what is the use of this?
So this helps the user space application to correlate which Netlink reply is for which Netlink request
in case user space application had issued multiple netlink request to kernel and awaiting reply for
all of these.
Right.
So, for example, in this diagram, you can see that suppose userspace application has issued the request,
R1, request R2 and request R3 to the Linux kernel module sitting in the kernel space.
Let the sequence number specified in the request.
R1 is six.
In the request, R2 is seven and in the request R3 is eight.
Now it so happens that our kernel space processed the request R2 first and therefore it sends back the
feedback or reply back to the kernel space.
For the request R2.
Right.
So this is the feedback.
Now the question is that that how user space would come to know that this particular reply is the reply
for the request R2 or R1 or R3, The user space application has no way to figure it out and therefore
sequence number comes to the rescue.
The kernel space, while replying back to the user space application will set the same sequence number
in the reply message which was specified in the request for which the kernel space is sending the reply.
Right.
So by doing this the user space application will be able to figure it out.
That the reply that it has received from the kernel space is the reply for the request number R2, which
has the sequence number seven.
Right.
So sequence number helps the user space application to correlate which Netlink reply message is for
which Netlink request.
Right.
Always remember that user space application must set the sequence number as always.
Ever increasing an integer number.