Search code examples
linux-kernelnetlink

netlink and generic netlink protocol


I've already read generic netlink How-To, and the only major drawback of netlink, that I found, is that the number of protocol families is limited to MAX_LINKS (32), therefore they created generic netlink protocol. Is this the only reason? Does it mean, that it recommended to use genl rather then netlink, e.g. as a communication between user and kernel spaces? Is genl considered as a more scalable and manageble vs. traditional netlinks?

Thanks.


Solution

  • Netlink protocol number IDs are predefined, and these numbers are not supposed to be reused or overridden. At the same time, the generic netlink allows dynamic protocol resolution via string IDs.

    That's the main reason to use the generic netlink protocol for custom applications.

    Another difference is that in a plain netlink like RTNL one should pass command type in the type field of the message header, while in the case of the generic netlink the protocol id is passed there:

    # nlmsg header
    uint32 length;
    uint16 type;  # command for rtnl and protocol id for genl
    uint16 flags;
    uint32 sequence_number;
    uint32 pid;
    

    The generic netlink command id is passed in the message data:

    # genlmsg data
    uint8 cmd;
    uint8 version;
    uint16 reserved;
    

    Thus, all the data for genl should be passed in the NLA chain, while RTNL messages of different types can use the message data section as well.

    Some additional info you can find in the docs