转:http://blog.csdn.net/nerdx/article/details/12839651
-
-
-
1.1 static struct notifier_block ip_netdev_notifier = {
-
.notifier_call =inetdev_event,
-
};
-
-
-
-
-
-
-
-
-
-
-
-
1.2 static int inetdev_event(struct notifier_block *this, unsigned long event,
-
void *ptr)
-
{
-
struct net_device *dev = ptr;
-
struct in_device *in_dev = __in_dev_get(dev);
-
-
if (!in_dev)
-
goto out;
-
-
switch (event) {
-
-
case NETDEV_REGISTER:
-
dev->ip_ptr = NULL;
-
break;
-
-
case NETDEV_UP:
-
-
if (dev->mtu < 68)
-
break;
-
-
if (dev == &loopback_dev) {
-
struct in_ifaddr *ifa;
-
-
if ((ifa = inet_alloc_ifa()) != NULL) {
-
-
ifa->ifa_local =
-
ifa->ifa_address = htonl(INADDR_LOOPBACK);
-
ifa->ifa_prefixlen = 8;
-
ifa->ifa_mask = inet_make_mask(8);
-
in_dev_hold(in_dev);
-
ifa->ifa_dev = in_dev;
-
-
ifa->ifa_scope = RT_SCOPE_HOST;
-
memcpy(ifa->ifa_label, dev->name, IFNAMSIZ);
-
-
inet_insert_ifa(ifa);
-
}
-
in_dev->cnf.no_xfrm = 1;
-
in_dev->cnf.no_policy = 1;
-
}
-
-
ip_mc_up(in_dev);
-
break;
-
case NETDEV_DOWN:
-
-
ip_mc_down(in_dev);
-
break;
-
case NETDEV_CHANGEMTU:
-
if (dev->mtu >= 68)
-
break;
-
case NETDEV_UNREGISTER:
-
inetdev_destroy(in_dev);
-
break;
-
case NETDEV_CHANGENAME:
-
inetdev_changename(dev, in_dev);
-
break;
-
}
-
out:
-
return NOTIFY_DONE;
-
}
-
-
-
-
-
-
-
1.3 static void inetdev_destroy(struct in_device *in_dev)
-
{
-
struct in_ifaddr *ifa;
-
struct net_device *dev;
-
-
in_dev->dead = 1;
-
-
while ((ifa = in_dev->ifa_list) != NULL) {
-
-
inet_del_ifa(in_dev, &in_dev->ifa_list, 0);
-
inet_free_ifa(ifa);
-
}
-
-
dev = in_dev->dev;
-
dev->ip_ptr = NULL;
-
-
neigh_parms_release(&arp_tbl, in_dev->arp_parms);
-
-
arp_ifdown(dev);
-
call_rcu(&in_dev->rcu_head, in_dev_rcu_put);
-
}
-
阅读(746) | 评论(0) | 转发(0) |