2

The netlink socket address structure is shown in the following

struct sockaddr_nl {
    sa_family_t     nl_family;  /* AF_NETLINK */
    unsigned short  nl_pad;     /* Zero. */
    pid_t           nl_pid;     /* Port ID. */
    __u32           nl_groups;  /* Multicast groups mask. */
};

man 7 netlink says, that each netlink family has a set of 32 multicast groups. Where do I find available multicast groups for each netlink family ? I am not able to find them on the man page.

Manos Nikolaidis
  • 21,608
  • 12
  • 74
  • 82
Zajcev
  • 21
  • 2
  • My impression is that it was intentional not to publish or gather any information regarding netlink. The "right" way is to use libnl. I was only able to find all information I need from reading kernel sources :( –  Mar 09 '16 at 13:30

2 Answers2

1

Well, this is not much of an answer, but I believe it's the closest it can practically be.

Netlink doesn't store any group metadata AFAIK. Users of the protocol define their groups and what they want to do with them by hacking the nl_groups bitfield. So you're not asking about Netlink; you're asking about Netlink's users. Furthermore, I've heard (though not actually bothered to implement) that even userspace can send multicast messages to arbitrary groups, even to other userspace clients, so the question is also not really kernel-scoped.

I'd be really surprised if there were a list lying around somewhere collecting this information for you. Netlink users are not meant to be static; One kernel will have a bunch of users, another kernel will have another bunch of users. Each user protocol will define its own multicast groups (if any). And that's not even counting protocols defined by stray out-of-tree kernel modules that don't have the common sense to use Generic Netlink instead of Netlink. :)

If you're hard pressed to find the fragment of this information which is readily available, you would have to notice from the Netlink socket API that kernel-side users of Netlink initialize nl_groups via a control buffer field named dst_group. So you'd have to find code that initializes this field. NETLINK_DNRTMSG, for example, seems to have two groups... one called DNRNG_NLGRP_L1, and another one called DNRNG_NLGRP_L2... good luck figuring out what they are. :)

On the other hand, and as you've seen, userspace code interacts with the groups via nl_groups. You'd have to find code that initializes this field. Since userspace code is even more scattered than the kernel's, you're facing a bit of an unreasonable task.

In other words, I feel your approach (for whatever it is that you're doing) is not exactly in line with Netlink's design. You don't list the multicast groups; your code already knows what they are for the specific protocol it's implementing and so it subscribes itself to it statically.

Community
  • 1
  • 1
Yd Ahhrk
  • 1,088
  • 12
  • 24
0

I can't give you all of them but will try to give you some.

NETLINK_ROUTE

All groups for this family are defined in linux/rtnetlink.h

#define RTMGRP_LINK     1
#define RTMGRP_NOTIFY       2
#define RTMGRP_NEIGH        4
#define RTMGRP_TC       8

#define RTMGRP_IPV4_IFADDR  0x10
#define RTMGRP_IPV4_MROUTE  0x20
#define RTMGRP_IPV4_ROUTE   0x40
#define RTMGRP_IPV4_RULE    0x80

#define RTMGRP_IPV6_IFADDR  0x100
#define RTMGRP_IPV6_MROUTE  0x200
#define RTMGRP_IPV6_ROUTE   0x400
#define RTMGRP_IPV6_IFINFO  0x800

#define RTMGRP_DECnet_IFADDR    0x1000
#define RTMGRP_DECnet_ROUTE     0x4000

#define RTMGRP_IPV6_PREFIX  0x20000

Will add to this answer as I get to know about others

PSKP
  • 1,178
  • 14
  • 28