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

📄 kernel_routes.c

📁 OLSR Implementation for XORP
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Department of Systems and Computer Engineering * Carleton University, CANADA * Copyright (c) 2004 Liang Qin, Department of Systems and Computer Engineering, * Carleton University * 1. Porting CRC's OLSR with QoS support to XORP 1.0, this release enable OLSR *    adds and deletes route entries to RIB in XORP, instead of to Linux kernel.  * * Copyright (c) 2004 Ying Ge, Communication Research Center Canada. * * Copyright (c) 2002, 2003 Maoyu Wang, Communication Research Center Canada. * * By Ying Ge: * 1. Change the OLSR packet format and message processing procedure based  *    on the OLSR RFC. * 2. Add support of multiple interfaces to OLSR, including MID message  *    creating and processing procedure as specified in the OLSR RFC. * 3. Add QoS Support to OLSR * * By Maoyu Wang: * 1. Ported OLSR from IPv4 to IPv6. * 2. Added the Host and Network Association (HNA) functionality into OLSR. * 3. Added the default gateway functionality into OLSR by extending the HNA  *    message usage. The default gateway functionality supported the mobility *	  by cooperating with Mobile IPv6 for a mobile node as well as supported  * 	  Internet access for MANET nodes.  * * DISTRIBUTED WITH NO WARRANTY, EXPRESS OR IMPLIED. * See the GNU Library General Public License (file COPYING in the distribution) * for conditions of use and redistribution *//* * This Copyright notice is in French. An English summary is given * but the referee text is the French one. * * Copyright (c) 2000, 2001 Adokoe.Plakoo@inria.fr, INRIA Rocquencourt, *                          Anis.Laouiti@inria.fr, INRIA Rocquencourt. * * Ce logiciel informatique est disponible aux conditions * usuelles dans la recherche, c'est-à-dire qu'il peut * être utilisé, copié, modifié, distribué à l'unique * condition que ce texte soit conservé afin que * l'origine de ce logiciel soit reconnue. * Le nom de l'Institut National de Recherche en Informatique * et en Automatique (INRIA), ou d'une personne morale * ou physique ayant participé à l'élaboration de ce logiciel ne peut * être utilisé sans son accord préalable explicite. *  * Ce logiciel est fourni tel quel sans aucune garantie, * support ou responsabilité d'aucune sorte. * Certaines parties de ce logiciel sont dérivées de sources developpees par * University of California, Berkeley et ses contributeurs couvertes  * par des copyrights. * This software is available with usual "research" terms * with the aim of retain credits of the software.  * Permission to use, copy, modify and distribute this software for any * purpose and without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies, * and the name of INRIA, or any contributor not be used in advertising * or publicity pertaining to this material without the prior explicit * permission. The software is provided "as is" without any * warranties, support or liabilities of any kind. * This product includes software developed by the University of * California, Berkeley and its contributors protected by copyrights. *//* * Routing table management daemon. */char kernel_routes_rcsid[] =   "$Id: kernel_routes.c,v 1.2 2000/12/06 10:36:11 prima Exp $";#include "defs.h"struct rthash       mirror_table[HASHSIZE];extern struct interf_name *interf_names;/*---------------------------------------------------------------------------------*/intolsr_find_up_route(struct rt_entry *dst,struct rthash *table){ 	struct rt_entry *destination;	struct rthash   *routing_hash;	olsr_u32_t      hash; 	olsr_hashing(&dst->rt_dst,&hash);	routing_hash=&table[hash & HASHMASK];	for(destination=routing_hash->rt_forw;destination!=(struct rt_entry *)routing_hash;destination=destination->rt_forw)	{		if(destination->rt_hash!=hash)			continue;      		if (0==memcmp(&destination->rt_dst,&dst->rt_dst,sizeof(struct olsr_ip_addr)))			if (0==memcmp(&destination->rt_router,&dst->rt_router,sizeof(struct olsr_ip_addr)))				//CRC hna add				if (0==memcmp(&destination->rt_src,&dst->rt_src,sizeof(struct olsr_ip_addr)))					if (destination->rt_metric==dst->rt_metric)	  					return 1;		else	  		return 0;	}	return 0;}/*------------------------------------------------------------------------*/struct destination_n *olsr_build_update_list(struct rthash *from_table,struct rthash *in_table){	struct destination_n *kernel_route_list=NULL;	struct destination_n *route_list=NULL;	struct rt_entry      *destination;	struct rthash        *routing_hash;	olsr_u8_t            index;  	for(index=0;index<HASHSIZE;index++)	{		routing_hash=&from_table[index];		for(destination=routing_hash->rt_forw;destination!=(struct rt_entry *)routing_hash;destination=destination->rt_forw)		{			if (!olsr_find_up_route(destination,in_table))			{				route_list=(struct destination_n *)malloc(sizeof(struct destination_n));				route_list->destination=destination;	      				route_list->next=kernel_route_list;				kernel_route_list=route_list;			}		}   	}	return (kernel_route_list);}/*------------------------------------------------------------------------*/voidolsr_delete_all_kernel_routes(int signal){ 	/*	This function will delete all entries from the kernel routing table	One should be careful to reconfigure the default entry.	*/	struct destination_n *delete_kernel_list=NULL;	struct interface *ifp; //added by Y.Ge  	delete_kernel_list=olsr_build_update_list(routingtable,mirror_table);	olsr_delete_routes_from_kernel(delete_kernel_list);  	if(role==MANETNODE)	{		//add_subnet_default_entry(&addr_ip,addr_ip_prefix); //commented by Y.Ge				/********************* added by Y.Ge ****************/		for (ifp = ifnet; ifp; ifp = ifp->int_next)		{			add_subnet_default_entry(&addr_manet[ifp->my_index],ifp->int6_site_prefix,ifp->my_index); 		}		/******************** end of revision *************/	}  	printf("\n ******************** Olsrd: Bye Bye !!!  ********************\n");	exit(signal);}/*CRC hna added------------------------------------------------------------------------*/voidolsr_del_all_kernel_routes( ){ 	/*	This function will delete all entries from the kernel routing table	One should be careful to reconfigure the default entry.	*/	struct destination_n *delete_kernel_list=NULL;  	if(debug_level>6)	{		printf("routingtable\n");		olsr_print_routing_table(routingtable);		printf("mirror_table\n");		olsr_print_routing_table(mirror_table);	} 	delete_kernel_list=olsr_build_update_list(routingtable,mirror_table);	olsr_delete_routes_from_kernel(delete_kernel_list);}/*------------------------------------------------------------------------*/voidolsr_update_kernel_routes(){	struct destination_n *delete_kernel_list=NULL;	struct destination_n *add_kernel_list=NULL; 	if(debug_level>6)	{		printf("******mirror_table********\n");		olsr_print_routing_table(mirror_table);		printf("******routingtable********\n");		olsr_print_routing_table(routingtable);		olsr_print_hna_host_table();		olsr_print_hna_subnet_table();	}  	delete_kernel_list=olsr_build_update_list(mirror_table,routingtable);  	add_kernel_list=olsr_build_update_list(routingtable,mirror_table);  	if(debug_level>5)	{		printf("\n\n***olsr_delete_routes_from_kernel***\n");		fprintf(y_file,"\n\n***olsr_delete_routes_from_kernel***\n");	}  	olsr_delete_routes_from_kernel(delete_kernel_list);    	if(debug_level>5)	{ 		printf("\n\n***olsr_add_routes_in_kernel***\n");		fprintf(y_file,"\n\n***olsr_add_routes_in_kernel***\n");	}  	olsr_add_routes_in_kernel(add_kernel_list);    }/*------------------------------------------------------------------------*/voidolsr_routing_mirror(){	/*	Cette procedure permet de copier la table de routage dans la mirror table	avant de recalculer la table de routage elle doit etre appele a la place de l'appel	de {olsr_release_routing_table();} qui doit etre remplacee par une autre procedure	acceptant une tabel comme argumant	*/	olsr_16_t            index;	for(index=0;index<HASHSIZE;index++)	{		if(routingtable[index].rt_forw==(struct rt_entry *)&routingtable[index])		{			mirror_table[index].rt_forw=(struct rt_entry *)&mirror_table[index];			mirror_table[index].rt_back=(struct rt_entry *)&mirror_table[index];		}		else		{			mirror_table[index].rt_forw=routingtable[index].rt_forw;			mirror_table[index].rt_forw->rt_back=(struct rt_entry *)&mirror_table[index];			mirror_table[index].rt_back=routingtable[index].rt_back;			mirror_table[index].rt_back->rt_forw=(struct rt_entry *)&mirror_table[index];	   			routingtable[index].rt_forw=(struct rt_entry *)&routingtable[index];			routingtable[index].rt_back=(struct rt_entry *)&routingtable[index];		}       	}}/*------------------------------------------------------------------------*/void olsr_delete_routes_from_kernel(struct destination_n *delete_kernel_list){	struct destination_n *destination_kernel;	olsr_16_t error;	char str[46];  	while(delete_kernel_list!=NULL)	{		if(debug_level>5)		{			printf("+++++ deleted dst: %s\n",inet_ntop(AF_INET6, &delete_kernel_list->destination->rt_dst,str,46));			printf("      deleted router: %s\n",inet_ntop(AF_INET6, &delete_kernel_list->destination->rt_router,str,46));						fprintf(y_file,"+++++ deleted dst: %s\n",inet_ntop(AF_INET6, &delete_kernel_list->destination->rt_dst,str,46));			fprintf(y_file,"      deleted router: %s\n",inet_ntop(AF_INET6, &delete_kernel_list->destination->rt_router,str,46));      		}		error=olsr_ioctl_del_route(delete_kernel_list->destination);      		if(error<0)		{			printf("%s\n",strerror(errno));		}		destination_kernel=delete_kernel_list;		delete_kernel_list=delete_kernel_list->next;      		free(destination_kernel);	}}/* previous version. see new version-----------------------------------------------------------*//*void olsr_add_routes_in_kernel(struct destination_n *add_kernel_list){  struct destination_n *destination_kernel;  olsr_16_t error;  while(add_kernel_list!=NULL)    {      error=olsr_ioctl_add_route(add_kernel_list->destination);      if((error<0)&&(debug_level > 0))			printf("%s\n",strerror(errno));      destination_kernel=add_kernel_list;      add_kernel_list=add_kernel_list->next;            free(destination_kernel);    }}*//*CRC v4->v6 modify------------------------------------------------------------------*//*new version with items in kernel_list sorted. There is a bug in previous version!!!*/void olsr_add_routes_in_kernel(struct destination_n *add_kernel_list){	struct destination_n *destination_kernel = NULL;	struct destination_n *previous_node = add_kernel_list;	olsr_16_t error;	int metric_counter = 0;	char str[46];	while(add_kernel_list!=NULL)	{		//searching for all the items with metric equal to n		for(destination_kernel = add_kernel_list; destination_kernel != NULL; )		{			//comparing the metric			if(destination_kernel->destination->rt_entry_infos.rtu_metric == metric_counter)

⌨️ 快捷键说明

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