转:http://blog.csdn.net/nerdx/article/details/12843327
-
-
-
-
static struct fib_rule default_rule = {
-
.r_clntref = ATOMIC_INIT(2),
-
.r_preference = 0x7FFF,
-
.r_table = RT_TABLE_DEFAULT,
-
.r_action = RTN_UNICAST,
-
};
-
-
static struct fib_rule main_rule = {
-
.r_next = &default_rule,
-
.r_clntref = ATOMIC_INIT(2),
-
.r_preference = 0x7FFE,
-
.r_table = RT_TABLE_MAIN,
-
.r_action = RTN_UNICAST,
-
};
-
-
static struct fib_rule local_rule = {
-
.r_next = &main_rule,
-
.r_clntref = ATOMIC_INIT(2),
-
.r_table = RT_TABLE_LOCAL,
-
.r_action = RTN_UNICAST,
-
};
-
-
static struct fib_rule *fib_rules = &local_rule;
-
-
-
-
-
2.1 void __init fib_rules_init(void)
-
{
-
register_netdevice_notifier(&fib_rules_notifier);
-
}
-
-
2.1 static struct notifier_block fib_rules_notifier = {
-
.notifier_call =fib_rules_event,
-
};
-
-
-
-
static int fib_rules_event(struct notifier_block *this, unsigned long event, void *ptr)
-
{
-
struct net_device *dev = ptr;
-
-
if (event == NETDEV_UNREGISTER)
-
fib_rules_detach(dev);
-
else if (event == NETDEV_REGISTER)
-
fib_rules_attach(dev);
-
return NOTIFY_DONE;
-
}
-
-
-
-
2.2 static void fib_rules_detach(struct net_device *dev)
-
{
-
struct fib_rule *r;
-
-
for (r=fib_rules; r; r=r->r_next) {
-
if (r->r_ifindex == dev->ifindex) {
-
write_lock_bh(&fib_rules_lock);
-
r->r_ifindex = -1;
-
write_unlock_bh(&fib_rules_lock);
-
}
-
}
-
}
-
-
-
-
2.3 static void fib_rules_attach(struct net_device *dev)
-
{
-
struct fib_rule *r;
-
-
for (r=fib_rules; r; r=r->r_next) {
-
if (r->r_ifindex == -1 && strcmp(dev->name, r->r_ifname) == 0) {
-
write_lock_bh(&fib_rules_lock);
-
r->r_ifindex = dev->ifindex;
-
write_unlock_bh(&fib_rules_lock);
-
}
-
}
-
}
-
阅读(831) | 评论(0) | 转发(0) |