⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kernel_routes.c

📁 OLSR Implementation for XORP
💻 C
📖 第 1 页 / 共 2 页
字号:
			{				if(debug_level>5)				{					printf("+++++ added dst: %s\n",inet_ntop(AF_INET6,&destination_kernel->destination->rt_dst,str,46));					printf("      added router: %s\n",inet_ntop(AF_INET6,&destination_kernel->destination->rt_router,str,46));										fprintf(y_file,"+++++ added dst: %s\n",inet_ntop(AF_INET6,&destination_kernel->destination->rt_dst,str,46));					fprintf(y_file,"      added router: %s\n",inet_ntop(AF_INET6,&destination_kernel->destination->rt_router,str,46));				}				//finding one with metric equal to n				error=olsr_ioctl_add_route(destination_kernel->destination);								if(error<0) //print the error msg				{					printf("%s\n",strerror(errno));				}								//getting rid of this node and hooking up the broken point				if(destination_kernel == add_kernel_list) 				{					destination_kernel = add_kernel_list->next;					free(add_kernel_list);					add_kernel_list = destination_kernel;					previous_node=add_kernel_list;				}				else 				{					previous_node->next = destination_kernel->next;					free(destination_kernel);					destination_kernel = previous_node->next;				}			}			else 			{				previous_node = destination_kernel;				destination_kernel = destination_kernel->next;			}					}		++metric_counter;	}}/*------------------------------------------------------------------------*/#undef rt_flags#undef rt_ifp#undef rt_metric#undef rt_dst/*------------------------------------------------------------------------*///CRC v4->v6 modified/*------------------------------------------------------------------------*/intolsr_ioctl_add_route(struct rt_entry *destination){ 	int i;	struct in6_rtmsg kernel_route;	struct olsr_ip_addr default_gw=in6addr_any;	char str[46];	int iface_index; //added by Y.Ge  	iface_index = destination->rt_local_if; //added by Y.Ge	memset(&kernel_route,0,sizeof(struct in6_rtmsg));	memcpy(&kernel_route.rtmsg_dst,&(destination->rt_entry_infos.rtu_dst), sizeof(struct in6_addr));	memcpy(&kernel_route.rtmsg_src,&destination->rt_src, sizeof(struct in6_addr));	kernel_route.rtmsg_dst_len=destination->rt_dst_prefix;	kernel_route.rtmsg_ifindex=olsr_if_index[destination->rt_local_if]; //added by Y.Ge	//	printf ("++++++++++++++++ in ioclt add route +++++++++++\n");//	printf ("first, the ifindex is: %d\n",kernel_route.rtmsg_ifindex);  	if(memcmp(&destination->rt_entry_infos.rtu_dst, &destination->rt_entry_infos.rtu_router, sizeof(struct in6_addr)))	{		memcpy(&kernel_route.rtmsg_gateway,&(destination->rt_entry_infos.rtu_router), sizeof(struct in6_addr));		if(destination->rt_entry_infos.rtu_dst_prefix==128)		{			kernel_route.rtmsg_flags = RTF_UP|RTF_HOST|RTF_GATEWAY;		}		else			kernel_route.rtmsg_flags = RTF_UP|RTF_GATEWAY;	}	else if(destination->rt_entry_infos.rtu_dst_prefix==128)	{		kernel_route.rtmsg_flags = RTF_UP|RTF_HOST;	}	else		kernel_route.rtmsg_flags = RTF_UP;  	        	//CRC HNA add	kernel_route.rtmsg_dst_len = destination->rt_dst_prefix;	kernel_route.rtmsg_metric=destination->rt_entry_infos.rtu_metric;    	/* 	 * Y.Ge: should decide the rtmsg_ifindex 	 * based on the interface index of the routingg entry 	 */	/*if (ifnet)		kernel_route.rtmsg_ifindex = ifnet->int_ifindex;*/ //commented by Y.Ge			kernel_route.rtmsg_ifindex=olsr_if_index[iface_index]; //added by Y.Ge//added by L.Qin	short unsigned theIndex=kernel_route.rtmsg_ifindex;//	printf("The index is %d\n",theIndex);	struct interface *iftemp=ifnet;	while(theIndex!=iftemp->int_ifindex){		iftemp = iftemp->int_next;	}			char* interfaceName=iftemp->int_name;        printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");//        string theName=string(interfaceName);//	printf("in kernel routes Interface name:%s\n",interfaceName);//*****	if(debug_level>5)	{		printf("add kernel_route.rtmsg_dst: %s\n",inet_ntop(AF_INET6,&kernel_route.rtmsg_dst,str,46));		printf("add kernel_route.rtmsg_gateway: %s\n",inet_ntop(AF_INET6,&kernel_route.rtmsg_gateway,str,46));		printf("add kernel_route.rtmsg_dst_len:%d\n",kernel_route.rtmsg_dst_len);				fprintf(y_file,"add kernel_route.rtmsg_dst: %s\n",inet_ntop(AF_INET6,&kernel_route.rtmsg_dst,str,46));		fprintf(y_file,"add kernel_route.rtmsg_gateway: %s\n",inet_ntop(AF_INET6,&kernel_route.rtmsg_gateway,str,46));		fprintf(y_file,"add kernel_route.rtmsg_dst_len:%d\n",kernel_route.rtmsg_dst_len);	}     	//modified by L.Qin *****//the route will be sent to RIB int sent=0; //initialize the ribNotifier init_XrlRibNotifier(); sent=add_route_to_RIB(kernel_route, interfaceName); printf("we add one route to the RIB\n");// *****//	if(((i=ioctl(s6[iface_index],SIOCADDRT,&kernel_route))<0)&&(errno!=EEXIST))if(sent==0)	{		perror("SIOCADDRT 2");		printf("%08lx %08lx %08lx %08lx\n",default_gw.s6_addr32[0],default_gw.s6_addr32[1],default_gw.s6_addr32[1],default_gw.s6_addr32[0]);		fprintf(y_file,"%08lx %08lx %08lx %08lx\n",default_gw.s6_addr32[0],default_gw.s6_addr32[1],default_gw.s6_addr32[1],default_gw.s6_addr32[0]);		exit(1);	}	return i;}// CRC v4->v6 modify/*----------------------------------------------------------------------------------*/intolsr_ioctl_del_route(struct rt_entry *destination){	int i;	struct in6_rtmsg kernel_route;	char str[46];	int iface_index; //added by Y.Ge	iface_index = destination->rt_local_if; //addedd by Y.Ge  	memset(&kernel_route,0,sizeof(struct in6_rtmsg));	memcpy(&kernel_route.rtmsg_dst,&(destination->rt_entry_infos.rtu_dst), sizeof(struct in6_addr));	memcpy(&kernel_route.rtmsg_src,&destination->rt_src, sizeof(struct in6_addr));	kernel_route.rtmsg_dst_len=destination->rt_dst_prefix;		if(memcmp(&destination->rt_entry_infos.rtu_dst, &destination->rt_entry_infos.rtu_router, sizeof(struct in6_addr)))	{		memcpy(&kernel_route.rtmsg_gateway,&(destination->rt_entry_infos.rtu_router), sizeof(struct in6_addr));		if(destination->rt_entry_infos.rtu_dst_prefix==128)			kernel_route.rtmsg_flags = RTF_UP|RTF_HOST|RTF_GATEWAY;		else			kernel_route.rtmsg_flags = RTF_UP|RTF_GATEWAY;	}	else if(destination->rt_entry_infos.rtu_dst_prefix==128)	{		kernel_route.rtmsg_flags = RTF_UP|RTF_HOST;	}	else		kernel_route.rtmsg_flags = RTF_UP;  	    	//CRC add for HNA	kernel_route.rtmsg_dst_len = destination->rt_dst_prefix;	kernel_route.rtmsg_metric=destination->rt_entry_infos.rtu_metric;	/* 	 * Y.Ge: should decide the rtmsg_ifindex 	 * based on the interface index of the routingg entry 	 */	/*if (ifnet)		kernel_route.rtmsg_ifindex = ifnet->int_ifindex;*/ //commented by Y.Ge		kernel_route.rtmsg_ifindex=olsr_if_index[iface_index]; //added by Y.Ge   	if(debug_level>5)	{		printf("del kernel_route.rtmsg_dst: %s\n",inet_ntop(AF_INET6,&kernel_route.rtmsg_dst,str,46));		printf("del kernel_route.rtmsg_gateway: %s\n",inet_ntop(AF_INET6,&kernel_route.rtmsg_gateway,str,46));		printf("del kernel_route.rtmsg_dst_len:%d\n",kernel_route.rtmsg_dst_len);				fprintf(y_file,"del kernel_route.rtmsg_dst: %s\n",inet_ntop(AF_INET6,&kernel_route.rtmsg_dst,str,46));		fprintf(y_file,"del kernel_route.rtmsg_gateway: %s\n",inet_ntop(AF_INET6,&kernel_route.rtmsg_gateway,str,46));		fprintf(y_file,"del kernel_route.rtmsg_dst_len:%d\n",kernel_route.rtmsg_dst_len);	}    	//modified by L.Qin  *****//the route will be sent to RIB int sent=0; printf("ENter delete route section\n");// initialize the ribNotifier init_XrlRibNotifier(); printf("Initial the pointer again\n"); sent=delete_route_to_RIB(kernel_route);//*****//	if(((i=ioctl(s6[iface_index],SIOCDELRT,&kernel_route))<0)&&(errno!=ESRCH))if(sent==0)	{		perror("SIOCDELRT 2");				exit(1);	}	return i; }/*------------------------------------------------------------------------*/voidolsr_release_kernel_routing_table(struct rthash *table){	struct rt_entry *destination;	struct rthash   *routing_hash;	olsr_u8_t             index;  	for(index=0;index<HASHSIZE;index++)	{		routing_hash=&table[index];		for(destination=routing_hash->rt_forw;destination!=(struct rt_entry *)routing_hash;destination=destination->rt_forw)		{			olsr_ioctl_del_route(destination);		}	} }/*-----------------------------------------------------------------------*///CRC v4->v6 addint delete_subnet_default_entry(struct olsr_ip_addr* addrptr,olsr_u16_t addr_prefix, int iface_index) //"iface_index" added by Y.Ge{	int i;  	struct in6_rtmsg kernel_route;  	struct olsr_ip_addr default_gw=in6addr_any;	struct olsr_ip_addr subnet_addr;	char str[46];			memcpy(&subnet_addr,addrptr,sizeof(struct olsr_ip_addr));	olsr_prefix_setting(&subnet_addr,addr_prefix);		memset(&kernel_route,0,sizeof(struct in6_rtmsg));   	memcpy(&kernel_route.rtmsg_dst,&subnet_addr, sizeof(struct olsr_ip_addr));  	memcpy(&kernel_route.rtmsg_src,addrptr, sizeof(struct olsr_ip_addr));  	kernel_route.rtmsg_flags = RTF_UP; 	kernel_route.rtmsg_dst_len = addr_prefix;	//I don't know if the metrics of all default subnet entries are 256 	kernel_route.rtmsg_metric=256;			/* 	 * Y.Ge: should decide the rtmsg_ifindex 	 * based on the interface index of the routingg entry 	 */	/*if (ifnet)		kernel_route.rtmsg_ifindex = ifnet->int_ifindex;*/ //commented by Y.Ge		kernel_route.rtmsg_ifindex=olsr_if_index[iface_index]; //added by Y.Ge   		  	//if(((i=ioctl(s6,SIOCDELRT,&kernel_route))<0)&&(errno!=ESRCH)) //commented by Y.Ge		if(((i=ioctl(s6[iface_index],SIOCDELRT,&kernel_route))<0)&&(errno!=ESRCH)) //added by Y.Ge	{		perror("SIOCDELRT 1");  		exit(1);  	}  	return i;}//CRC v4->v6 addint add_subnet_default_entry(struct olsr_ip_addr* addrptr, olsr_u16_t addr_prefix, int iface_index) //"iface_index" added by Y.Ge{	int i;  	struct in6_rtmsg kernel_route;  	struct olsr_ip_addr default_gw=in6addr_any;	struct olsr_ip_addr subnet_addr;	char str[46];			memcpy(&subnet_addr,addrptr,sizeof(struct olsr_ip_addr));	olsr_prefix_setting(&subnet_addr,addr_prefix);			memset(&kernel_route,0,sizeof(struct in6_rtmsg));   	memcpy(&kernel_route.rtmsg_dst,&subnet_addr, sizeof(struct olsr_ip_addr));  	memcpy(&kernel_route.rtmsg_src,addrptr, sizeof(struct olsr_ip_addr));  	kernel_route.rtmsg_flags = RTF_UP; 	kernel_route.rtmsg_dst_len = addr_prefix;	//I don't know if the metrics of all default subnet entries are 256  	kernel_route.rtmsg_metric=256;   		/* 	 * Y.Ge: should decide the rtmsg_ifindex 	 * based on the interface index of the routingg entry 	 */	/*if (ifnet)		kernel_route.rtmsg_ifindex = ifnet->int_ifindex;*/ //commented by Y.Ge		kernel_route.rtmsg_ifindex=olsr_if_index[iface_index]; //added by Y.Ge  	  	if(debug_level>5)  	{  		printf("----------------------************************----------------------\n");  		printf("add_sub kernel_route.rtmsg_dst: %s\n",inet_ntop(AF_INET6,&kernel_route.rtmsg_dst,str,46));  		printf("add_sub kernel_route.rtmsg_gateway: %s\n",inet_ntop(AF_INET6,&kernel_route.rtmsg_gateway,str,46));				fprintf(y_file,"----------------------************************----------------------\n");  		fprintf(y_file,"add_sub kernel_route.rtmsg_dst: %s\n",inet_ntop(AF_INET6,&kernel_route.rtmsg_dst,str,46));  		fprintf(y_file,"add_sub kernel_route.rtmsg_gateway: %s\n",inet_ntop(AF_INET6,&kernel_route.rtmsg_gateway,str,46));  	}  	//if(((i=ioctl(s6,SIOCADDRT,&kernel_route))<0)&&(errno!=EEXIST)) //commented by  Y.Ge  	if(((i=ioctl(s6[iface_index],SIOCADDRT,&kernel_route))<0)&&(errno!=EEXIST)) //added by  Y.Ge	{  		perror("SIOCADDRT 1");  		exit(1);  	}  	return i;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -