您的位置:首页 > 理论基础 > 计算机网络

网络子系统67_路由表处理设备事件

2013-10-17 21:24 197 查看
//	路由表对网络设备事件的处理
//		在ip_rt_init->ip_fib_init中注册
1.1 static struct notifier_block fib_netdev_notifier = {
.notifier_call = fib_netdev_event,
};

// 路由表处理设备事件
//	函数主要功能:
//		1.设备开启
//			1.1 将设备配置的所有ip添加到路由表中
//			1.2 同步多路径缓存
//			1.3 刷新路由缓存

//		2.设备关闭,注销
//			2.1 关闭设备上的ip协议

//		3.设备mtu,载波改变:
//			3.1 同步路由缓存
1.2 static int fib_netdev_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 (event == NETDEV_UNREGISTER) {
fib_disable_ip(dev, 2);
return NOTIFY_DONE;
}
// 设备需要配置信息
if (!in_dev)
return NOTIFY_DONE;

switch (event) {
case NETDEV_UP:
//设备开启
for_ifa(in_dev) {
//将设备配置的ip地址均添加到路由表中
fib_add_ifaddr(ifa);
} endfor_ifa(in_dev);
//多路径同步
#ifdef CONFIG_IP_ROUTE_MULTIPATH
fib_sync_up(dev);
#endif
//刷新路由缓存
rt_cache_flush(-1);
break;
case NETDEV_DOWN:
//设备关闭,关闭设备上的ip协议
fib_disable_ip(dev, 0);
break;
//mtu,载波变化
case NETDEV_CHANGEMTU:
case NETDEV_CHANGE:
//立刻刷新路由缓存
rt_cache_flush(0);
break;
}
return NOTIFY_DONE;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息