So, guys, now let us understand the last field of the Netlink message header, which is the Netlink
message PID or also called port ID.
So this field is set by the userspace application while sending netlink messages to kernel space.
It must be unique to the userspace application, therefore it is always a good practice to use process
id as port 80 right.
Kernel space uses this information to reply back to the correct application in user space.
Right.
So for example, in this diagram you can see that there are three user space applications which are
running and all of these three user space applications are actually communicating with the Linux kernel
module.
Now suppose the user space application one issues the request R1 to your lkm, right?
Now the question is that when your Linux kernel module have to reply back to the user space application
one how your Linux kernel module will come to know that it has to reply to the user space application
one and not 2 or 3.
Right.
So there should be some identifier in the netlink message header which identifies the user space application
uniquely.
Right?
So when user space application one will send request R1 to the Linux kernel module, R1 will set some
signature in this PID field of the Netlink message header using which the kernel space can identify
that the request R1 is coming from the application one.
Right.
So the best practice is to use this PID as process ID of the application, sending the request to the
kernel space.
This PID field in the netlink message header is set to zero for netlink messages which are originating
from kernel space towards user space application.
Now note that these are the messages whose origin is the kernel space.
These messages are not the reply or feedback messages, but these are the individual messages which
are being originated from the kernel space towards the user space application.
In such a scenario, the PID is always set to zero because kernel is not a user space process and therefore
kernel as such do not have any process I.D..
So for example, in case of event based notification, all the messages which are being triggered from
kernel space towards user space application would have the PID value set to zero.
So now that we have discussed all the fields of a typical Netlink message header, now we are in a position
to start writing Netlink based communication between user space and kernel space.
So from now on in the rest of the course we shall be writing lots of lots of code.