netdevice通知程序

时间:2012-12-08 04:53:45

标签: linux-kernel linux-device-driver

我在我的模块中添加了一个netdevice通知程序:

int os_netdevice_notifier_cb (struct notifier_block *, unsigned long, void *);
...
static struct notifier_block os_netdevice_notifier =
  {
     os_netdevice_notifier_cb,
     NULL,
     0
  };
register_netdevice_notifier(&os_netdevice_notifier);

我希望能够看到的是已注册/未注册的设备,即我必须监视事件NETDEV_UNREGISTER。收到此事件后,是否保证设备已从系统中删除,或者仅表示已安排将其删除,实际工作将在以后完成?

查看net / core / dev.c中的代码,看起来事件是在设备清理后立即发送的,但可能是我遗漏了什么?

第二个问题 - 在系统未注册的情况下删除分配给接口的IP / hw地址的代码在哪里?

谢谢! 标记

1 个答案:

答案 0 :(得分:1)

在NETDEV_UNREGISTER点,设备没有完全从系统中移除,至少此时ref参数仍然不为零。设备至少已经关闭,所以可以在这里使用NETDEV_UNREGISTER,因为此时RTM_DELLINK也会被发送到用户空间。

删除IP地址由net / ipv4 / devinet.c中的inet_del_ifa()完成。取消注册网络接口时,在NETDEV_UNREGISTER事件时,会调用inetdev_destroy():

static void inetdev_destroy(struct in_device *in_dev)
{
        struct in_ifaddr *ifa;
        struct net_device *dev;

        ASSERT_RTNL();

        dev = in_dev->dev;

        in_dev->dead = 1;

        ip_mc_destroy_dev(in_dev);

        while ((ifa = in_dev->ifa_list) != NULL) {
                inet_del_ifa(in_dev, &in_dev->ifa_list, 0);
                inet_free_ifa(ifa);
        }

        RCU_INIT_POINTER(dev->ip_ptr, NULL);

        devinet_sysctl_unregister(in_dev);
        neigh_parms_release(&arp_tbl, in_dev->arp_parms);
        arp_ifdown(dev);

        call_rcu(&in_dev->rcu_head, in_dev_rcu_put);
}
相关问题