Now, the next thing that we will going to discuss is the netlink message flags.
So you can see in this slide there are total of eight flags which we can set in the netlink message.
These flags are set in the netlink message to convey additional information to the recipient.
Right.
So note that these flags can be set by the kernel.
Sending Netlink message to the userspace or userspace can also set these flags in the netlink message
which it is sending to the kernel space.
But most of the time it is the user space which is actually requesting the kernel space for a resource.
Right?
So these flags are most commonly used in the netlink messages which are going from the user space to
the kernel space.
Of course, in one netlink message, multiple flags could be set using bitwise and or operators.
Right.
So now let us quickly understand what is the meaning of all these flags.
So, for example, suppose the user space application is issuing a request to the kernel space, telling
our Linux kernel module that hey, Linux kernel module, please create a new entry in the routing table.
So this is actually a kind of request which user space application is issuing to our Linux kernel module
sitting in the kernel space.
And therefore in this netlink message, this flag will be set right?
So whenever one party requests the other party to perform some action, then the request flag will be
set in the netlink message.
The create flag, on the other hand, is set by the userspace application.
When the userspace application asks our Linux kernel module to create a new resource altogether here,
new resource means creation of a new entry.
Right.
Exclude.
Flag, on the other hand, is set by the userspace application.
When the userspace application asks the Linux kernel module to create a new resource.
But setting this flag, the userspace application is also telling the Linux kernel module that if a
new resource which I am telling you to create already exist, then please return an error.
Right.
So setting the exclude flag is a way of telling to create a resource only if it doesn't exist already.
Similarly, replace Flag is a very straightforward user space application wants to replace an existing
resource which is sitting in the kernel space subsystem.
Right?
So this flag will be set if replacing an existing entry in the Linux kernel is a goal.
Similarly, we have an append flag in which the user space application requests the kernel space.
Here.
Kernel space means our Linux kernel module, which is a kernel routing table manager.
So user space application is requesting the kernel space to add more data to the existing configuration,
right?
For example, adding some more data to the existing link list.
So in this scenario, the user space application can actually use the flag append.
Right now there could be scenario where user space application requests the kernel space to actually.
Ship back all the data it has.
So in such a scenario, the userspace application will set such a flag, which is called dump flag in
the Netlink message issued by userspace application to request a dump from the kernel space.
When kernel space receives such a request from the userspace, the kernel space replies with the multipart
cascaded netlink message to such request.
Right.
So cascaded message will be formed when all the data which is requested by the userspace application
cannot fit in one netlink message.
Now our data may not be fit in one netlink message because probably the number of entries which the
kernel space is sending to the user space could be in millions.
The kernel would have to take a very long buffer and such a contiguous buffer may not be available to
the kernel space.
So this would be one scenario where the kernel space would choose to chunk the message and send the
message to the user space in multiple parts.
Right.
The same applies when the flow of data in bulk is from user space to kernel space.
Right.
Then the second last flag is the multi flag.
This flag is set to tell the recipient that there is next netlink message following to this one.
Right.
So remember the cascaded, multi-part netlink messages?
So if the cascaded multi-part netlink messages has three netlink messages appended one after the another,
the first and the second netlink message will have this flag set.
It would mean that the recipient would read this flag and the recipient would know that there is another
netlink message following this one.
Right.
Then the final flag is the acknowledgement flag.
If this flag is set, then the user space application is requesting the kernel space to reply back with
the confirmation message of the user space application request.
Right.
The kernel space replies with either the Netlink message, no operation Netlink message or the Netlink
message error type of Netlink message.
Right.
So setting this flag, the sender actually requests the feedback from the recipient.
So don't worry, we will going to exercise the application of all these flags in our Netlink project.
The recipient, whether it is a user space or it's a kernel space, will read these flags and will take
appropriate actions accordingly.
These flag values are specified in the same file that is in the following file.
Linux slash netlink dot h.
Right.
So you can see in line number from 54 to 78, you can see various flags.
We have just discussed the subset of flags which are most commonly used.
So you can see request multi ack eco and other flags are also there.
Then you have replace flag, exclude flag, create flag and append flag.
Right.
So wherever possible, we will discuss the Linux kernel code so that you get more familiar with the
Linux kernel code.
And over a period of time you develop the habit of browsing and navigating through the kernel source
code by yourself.