列出从网络驱动程序绑定到特定设备的多播 IP 地址

List multicast IP addresses bound to specific device from network driver

有没有办法从网络驱动程序中列出绑定到特定设备的所有多播 IP 地址?

我了解如何使用 netdev_for_each_mc_addr() 通过 net_device 结构遍历多播 MAC 地址列表。我也知道存在从多播 MAC 到 IP 的映射,但它不是一对一的映射,这就是我对获取 IP 多播组感兴趣的原因。

我是 运行 Centos 7,内核是 3.10.0

目标是在加入和删除多播组时在 set_rx_mode() 中访问此列表。

我看到包含在 net_device 结构中的是一个 struct in_device,进一步嵌套在其中的是一个 struct ip_mc_list。考虑到这一点,我尝试了以下方法来遍历 ip_mc_list.

static void set_rx_mode(struct net_device *netdev)
{
    struct ip_mc_list *ip_list = netdev->ip_ptr->mc_list;

    while(ip_list) {
        printk(KERN_DEBUG " IP MC Address: 0x%x\n", ip_list->multiaddr);
        ip_list = ip_list->next;

    }
}

不幸的是,当多播 IP 地址绑定到设备时,ip_list 仍然是 NULL。如果这与内核 IGMP 实现中使用的 struct in_device 不同,有没有办法访问正确的?

我能够通过使用 in_dev_get(struct *net_device) 访问 in_device 结构来获取 IP 多播地址。以下是工作代码:

static void set_rx_mode(struct net_device *netdev)
{
    struct in_device *in_dev = in_dev_get(netdev);
    struct ip_mc_list *ip_list = in_dev->mc_list;

    while(ip_list) {
        printk(KERN_DEBUG " IP MC Address: 0x%x\n", ip_list->multiaddr);
        ip_list = ip_list->next;

    }
}