0

My application should get netlink multicast route updates from kernel. I did some research and found mutlicast uses different family:RTNL_FAMILY_IPMR and group is RTMGRP_IPV4_MROUTE.

However if I use:

    sfd = socket (AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
    snl.nl_groups |= RTMGRP_IPV4_MROUTE

I dont get any updates.

But

    sfd = socket (AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
    snl.nl_family = RTNL_FAMILY_IPMR;
    snl.nl_groups |= RTMGRP_IPV4_MROUTE;

This give bind error", bind: Invalid argument

    sfd = socket (RTNL_FAMILY_IPMR, SOCK_RAW, NETLINK_ROUTE);

This give "Address family not supported by protocol" error

I'm not sure how to get updates from kernel for mutlicast routes.

Pramod
  • 371
  • 4
  • 13

1 Answers1

0

copy-paste from earlier project I have:

    struct sockaddr_nl naddr;

    netlinkfd = socket (AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
    naddr.nl_family = AF_NETLINK;
    naddr.nl_groups = (1 << (RTNLGRP_LINK - 1)) |
                      (1 << (RTNLGRP_IPV4_ROUTE - 1)) |
                      (1 << (RTNLGRP_IPV6_ROUTE - 1)) |
                      (1 << (RTNLGRP_IPV4_IFADDR - 1)) |
                      (1 << (RTNLGRP_IPV6_IFADDR -1 ));
    if (bind (netlinkfd, (struct sockaddr *)&naddr, sizeof (naddr)))
    {
        error_foo();
        return;
    }

This one works for me receiving link, ip and routing table in general. (pushing me all the changes from this point of - if I want to receive the current status, I need to request them aswell). Try to have both ROUTE and MROUTE since you want multicast routing tables, but they might be merged into the normal routing table

Stian Skjelstad
  • 2,277
  • 1
  • 9
  • 19