0

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.

Mark
  • 6,052
  • 8
  • 61
  • 129

2 Answers2

6

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

svinota
  • 779
  • 8
  • 10
-2
#define NETLINK_ROUTE       0   /* Routing/device hook          */
#define NETLINK_UNUSED      1   /* Unused number                */
#define NETLINK_USERSOCK    2   /* Reserved for user mode socket protocols  */
#define NETLINK_FIREWALL    3   /* Unused number, formerly ip_queue     */
#define NETLINK_SOCK_DIAG   4   /* socket monitoring                */
#define NETLINK_NFLOG       5   /* netfilter/iptables ULOG     */
#define NETLINK_XFRM        6   /* ipsec */
#define NETLINK_SELINUX     7   /* SELinux event notifications */
#define NETLINK_ISCSI       8   /* Open-iSCSI */
#define NETLINK_AUDIT       9   /* auditing   */
#define NETLINK_FIB_LOOKUP  10  
#define NETLINK_CONNECTOR   11
#define NETLINK_NETFILTER   12  /* netfilter subsystem */
#define NETLINK_IP6_FW      13
#define NETLINK_DNRTMSG     14  /* DECnet routing messages */
#define NETLINK_KOBJECT_UEVENT  15  /* Kernel messages to userspace */
#define NETLINK_GENERIC     16
#define NETLINK_SCSITRANSPORT   18  /* SCSI Transports */
#define NETLINK_ECRYPTFS    19
#define NETLINK_RDMA        20
#define NETLINK_CRYPTO      21  /* Crypto layer */

#define NETLINK_INET_DIAG   NETLINK_SOCK_DIAG

#define MAX_LINKS 32    

The fundamental reason is:

nl_table = kcalloc(MAX_LINKS, sizeof(*nl_table), GFP_KERNEL);

genl netlink is a wrapper for netlink

This is a new agreement I added: https://github.com/leesagacious/Netlink

Mika Sundland
  • 18,120
  • 16
  • 38
  • 50
leesagacious
  • 182
  • 1
  • 8