转:http://blog.csdn.net/nerdx/article/details/12842237
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
1.1 static int inet_insert_ifa(struct in_ifaddr *ifa)
-
{
-
struct in_device *in_dev = ifa->ifa_dev;
-
struct in_ifaddr *ifa1, **ifap, **last_primary;
-
-
-
ifa->ifa_flags &= ~IFA_F_SECONDARY;
-
-
last_primary = &in_dev->ifa_list;
-
-
for (ifap = &in_dev->ifa_list; (ifa1 = *ifap) != NULL;
-
ifap = &ifa1->ifa_next) {
-
-
if (!(ifa1->ifa_flags & IFA_F_SECONDARY) &&
-
ifa->ifa_scope <= ifa1->ifa_scope)
-
last_primary = &ifa1->ifa_next;
-
-
-
if (ifa1->ifa_mask == ifa->ifa_mask &&
-
inet_ifa_match(ifa1->ifa_address, ifa)) {
-
if (ifa1->ifa_local == ifa->ifa_local) {
-
inet_free_ifa(ifa);
-
return -EEXIST;
-
}
-
if (ifa1->ifa_scope != ifa->ifa_scope) {
-
inet_free_ifa(ifa);
-
return -EINVAL;
-
}
-
-
ifa->ifa_flags |= IFA_F_SECONDARY;
-
}
-
}
-
-
-
if (!(ifa->ifa_flags & IFA_F_SECONDARY)) {
-
net_srandom(ifa->ifa_local);
-
ifap = last_primary;
-
}
-
-
ifa->ifa_next = *ifap;
-
*ifap = ifa;
-
-
-
rtmsg_ifa(RTM_NEWADDR, ifa);
-
-
notifier_call_chain(&inetaddr_chain, NETDEV_UP, ifa);
-
-
return 0;
-
}
-
-
-
-
-
-
-
-
-
1.2 static void inet_del_ifa(struct in_device *in_dev, struct in_ifaddr **ifap,
-
int destroy)
-
{
-
struct in_ifaddr *ifa1 = *ifap;
-
-
-
if (!(ifa1->ifa_flags & IFA_F_SECONDARY)) {
-
struct in_ifaddr *ifa;
-
struct in_ifaddr **ifap1 = &ifa1->ifa_next;
-
-
while ((ifa = *ifap1) != NULL) {
-
if (!(ifa->ifa_flags & IFA_F_SECONDARY) ||
-
ifa1->ifa_mask != ifa->ifa_mask ||
-
!inet_ifa_match(ifa1->ifa_address, ifa)) {
-
ifap1 = &ifa->ifa_next;
-
continue;
-
}
-
-
*ifap1 = ifa->ifa_next;
-
-
rtmsg_ifa(RTM_DELADDR, ifa);
-
notifier_call_chain(&inetaddr_chain, NETDEV_DOWN, ifa);
-
-
inet_free_ifa(ifa);
-
}
-
}
-
-
-
*ifap = ifa1->ifa_next;
-
-
-
rtmsg_ifa(RTM_DELADDR, ifa1);
-
notifier_call_chain(&inetaddr_chain, NETDEV_DOWN, ifa1);
-
-
if (destroy) {
-
inet_free_ifa(ifa1);
-
-
if (!in_dev->ifa_list)
-
inetdev_destroy(in_dev);
-
}
-
}
-
阅读(1096) | 评论(0) | 转发(0) |