Netlink Message Macros

The interested reader can refer the netlink socket structures in the below two links

The Netlink Message construction uses a number of macros to create the complete netlink message. The below Netlink macros provide information on how the netlink message is constructed.

  • int NLMSG_ALIGN(size_t len) – The macro accepts a length parameter and rounds the length to the next highest NLMSG_ALIGNTO boundary
  • int NLMSG_LENGTH(size_t len) – this macro gives the length of the netlink packet which includes the data + header and any padding required to align it to the next NLMSG_ALIGNTO boundary
  • int NLMSG_SPACE(size t len) – returns the aligned size of the packet excluding the netlink message header
  • void *NLMSG_DATA(struct nlmsghdr *nlh) – given a netlink header, this macro provides a pointer to the netlink message it contains
  • struct nlmsghdr *NLMSG_NEXT(struct nlmsghdr *nlh) – provides the next netlink message pointer in a multi-netlink message
  • int NLMSG_OK(struct nlmsghdr *nlh, int len) – in a multi-netlink message, this macro checks if the message payload has not been truncated
  • int NLMSG_PAYLOAD(nlmsghdr *nlh, int len) – this macro accepts netlink message header and returns the length of the data associated with that header.

With the information that is shared in the previous two articles and the current article, we could try and look at the netlink message format again to refresh our understanding of the same. Depictions of the message and header are provided below

Fig Courtesy: https://people.redhat.com/nhorman/papers/netlink.pdf

Fig Courtesy: https://www.infradead.org/~tgr/libnl/doc/core.html

Netlink Protocol Families

Comments

  1. Pingback: The Netlink Socket Structures – Part 2 | Hitch Hiker's Guide to Learning

Leave a Reply

Your email address will not be published. Required fields are marked *