阅读957 返回首页    go 阿里云 go 技术社区[云栖]


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

//	路由表对网络设备事件的处理
//		在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;
}

最后更新:2017-04-03 14:53:48

  上一篇:go 网络子系统68_路由表处理设备ip配置事件
  下一篇:go 网络子系统66_策略路由初始化