2012-12-08 2 views
0

netdevice 통지 :내 모듈에 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

NETDEV_UNREGISTER 시점에서 장치가 시스템에서 완전히 제거되지는 않습니다. 적어도 그 시점에서 참조 카운트는 여전히 0이 아닙니다. 장치는 이미 최소한 종료되었으므로이 시점에서 RTM_DELLINK가 사용자 공간으로 보내 지므로 여기에서 NETDEV_UNREGISTER를 사용해도됩니다.

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); 
} 
관련 문제