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

📄 neighbor_table.c

📁 OLSR Implementation for XORP
💻 C
📖 第 1 页 / 共 3 页
字号:
/* * 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 neighbor_table_rcsid[] =   "$Id: neighbor_table.c,v 1.2 2000/12/06 10:36:11 prima Exp $";#include "defs.h"struct neighbor_table		neighbortable; 		void olsr_delete_neighbor_2_pointer(struct neighbor_entry *neighbor,struct olsr_ip_addr *address){	struct neighbor_2_list_entry *neighbor_two_list;	struct neighbor_2_list_entry *neighbor_two_list_tmp;  	neighbor_two_list=neighbor->neighbor_2_list;	neighbor->neighbor_2_list=NULL;	while(neighbor_two_list!=NULL)	{		if(0==memcmp(&neighbor_two_list->neighbor_2->neighbor_2_addr,address,sizeof(struct olsr_ip_addr)))		{			neighbor_two_list_tmp= neighbor_two_list;			neighbor_two_list=neighbor_two_list->neighbor_2_next;			free(neighbor_two_list_tmp);	  		}		else		{			neighbor_two_list_tmp= neighbor_two_list;			neighbor_two_list=neighbor_two_list->neighbor_2_next;			neighbor_two_list_tmp->neighbor_2_next= neighbor->neighbor_2_list;			neighbor->neighbor_2_list=neighbor_two_list_tmp;		}      	}}/*------------------------------------------------------------------------*//***************** added by Y.Ge **************/void olsr_delete_main_neighbor_pointer(struct neighbor_entry *neighbor){	struct link_to_main_neighbor	*main_neighbor_link;	struct link_to_main_neighbor	*main_neighbor_link_tmp;  	main_neighbor_link=neighbor->neighbor_main_info;	neighbor->neighbor_main_info=NULL;	free(main_neighbor_link);	  }/**************** end of revision *************//*------------------------------------------------------------------------*/struct neighbor_2_list_entry*olsr_lookup_my_neighbors(struct neighbor_entry *neighbor,struct olsr_ip_addr *neighbor_address){  	struct neighbor_2_list_entry *neighbor_two_list;  	neighbor_two_list=neighbor->neighbor_2_list;  	while(neighbor_two_list!=NULL)	{      		if(0==memcmp(&neighbor_two_list->neighbor_2->neighbor_2_addr,neighbor_address,sizeof(struct olsr_ip_addr)))			return(neighbor_two_list);      		neighbor_two_list=neighbor_two_list->neighbor_2_next;      	}	return(NULL);}/*------------------------------------------------------------------------*/voidolsr_delete_neighbor_table(struct neighbor_entry *neighbor){  /*    Delete a neighbor entry results the deletion of its 2 hop neighbors list!!!   */  	struct  neighbor_2_list_entry *two_hop_list;	struct  neighbor_2_entry      *two_hop_entry;	struct  link_to_main_neighbor	*main_address_neighbor_entry; //added by Y.Ge	struct  main_addr_neigh_entry	*main_neigh; //added by Y.Ge	two_hop_list = neighbor->neighbor_2_list;	main_address_neighbor_entry = neighbor->neighbor_main_info; //added by Y.Ge	while(two_hop_list!=NULL)	{		two_hop_entry=two_hop_list->neighbor_2;		two_hop_entry->neighbor_2_pointer--;		olsr_delete_neighbor_pointer(two_hop_entry,&neighbor->neighbor_addr);      		if(two_hop_entry->neighbor_2_pointer<1)		/* means this two hop entry is no more pointed, not reachable */		{			olsr_remque((struct olsr_qelem *)two_hop_entry);			free((void *)two_hop_entry);		}		neighbor->neighbor_2_list=two_hop_list->neighbor_2_next;     		free(two_hop_list);		two_hop_list = neighbor->neighbor_2_list;	}	/***************added by Y.Ge *******************/	/*	 * also delete the link to the neighbor_main_addr table, update the neigh_status in neighbor_main_addr_table	 */	main_neigh = main_address_neighbor_entry->main_neighbor;	main_neigh->interface_pointer --;	//printf ("currently, main addr neighbor_info is: addr(%s), link(%d)\n", convert_address_to_string(&main_neigh->main_addr_neigh_addr), main_neigh->interface_pointer);	olsr_delete_iface_neighbor_pointer(main_neigh, &neighbor->neighbor_addr);	/*printf ("after deleting the neighbor pointer, the neighbor tables are: \n");	olsr_print_neighbor_table();	olsr_print_main_addr_neigh_table();*/	if (main_neigh->interface_pointer < 1)	{		//printf ("-------- should delete the main address neighbor !\n");		/* delete the neighbor from main_addr_neigh_table */		olsr_remque ((struct olsr_qelem *)main_neigh);		free((void *)main_neigh);	}	else	{		olsr_update_main_addr_neigh_status(main_neigh);	}	free (main_address_neighbor_entry); 	/*************** end of revision ****************/ 	if(neighbor->neighbor_ifp!=NULL)    		free(neighbor->neighbor_ifp);	TRACE_ACTION("DELETE NEIGHBOR", &neighbor->neighbor_addr,NULL,0);	olsr_remque((struct olsr_qelem *)neighbor);  	free((void *)neighbor);}/*------------------------------------------------------------------------*/voidolsr_insert_neighbor_table(struct neighbor_entry *neighbor){	olsr_u32_t             hash;	struct neighborhash    *hash_neighbor;	olsr_hashing(&neighbor->neighbor_addr,&hash);	neighbor->neighbor_hash=hash;	hash_neighbor=&neighbortable.neighborhash[hash & HASHMASK];	TRACE_ACTION("ADD NEIGHBOR", &neighbor->neighbor_addr,NULL,0);	olsr_insque((struct olsr_qelem *)neighbor, (struct olsr_qelem *)hash_neighbor);}/*------------------------------------------------------------------------*//*********** commented by Y.Ge *************//*struct neighbor_entry *olsr_lookup_neighbor_table(struct olsr_ip_addr *dst){	struct neighbor_entry  *neighbor;	struct neighborhash    *hash_neighbor;	olsr_u32_t             hash;	olsr_hashing(dst,&hash);	hash_neighbor=&neighbortable.neighborhash[hash & HASHMASK];	for(neighbor=hash_neighbor->neighbor_forw;neighbor!=(struct neighbor_entry *)hash_neighbor;neighbor=neighbor->neighbor_forw)	{		if(neighbor->neighbor_hash!=hash)			continue;		if (0==memcmp(&neighbor->neighbor_addr,dst,sizeof(struct olsr_ip_addr)))			return(neighbor);    	}	return (NULL);  }*//*------------------------------------------------------------------------*//************ added by Y.Ge ***********/struct neighbor_entry *olsr_lookup_neighbor_table(struct olsr_ip_addr *dst, struct olsr_ip_addr *my_addr){	struct neighbor_entry	*neighbor, *neighbor_tmp;	struct neighborhash   	*hash_neighbor;	olsr_u32_t           	hash;	int                  	i, mistake = 0;;	olsr_hashing(dst,&hash);	hash_neighbor=&neighbortable.neighborhash[hash & HASHMASK];	for(neighbor=hash_neighbor->neighbor_forw;neighbor!=(struct neighbor_entry *)hash_neighbor;neighbor=neighbor->neighbor_forw)	{		if(neighbor->neighbor_hash!=hash)			continue;		if (0==memcmp(&neighbor->neighbor_addr,dst,sizeof(struct olsr_ip_addr)))		{			if (0==memcmp(&neighbor->my_iface_addr, my_addr, sizeof (struct olsr_ip_addr)))				return (neighbor);    			else			{				printf ("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n");				printf ("XXXXXXXXXXXXXXXXXXXX ATTENTION: MAYBE there is ERROR in IFACE ADDR! XXXXXXXXXXXXXXXX\n");				printf ("XXXXXXXX the input addr is: neighbor(%s)\n",convert_address_to_string(dst));				printf ("          mine(%s)\n", convert_address_to_string(my_addr));				printf ("XXXXXXXX the found addr is: neighbor(%s)\n", convert_address_to_string(&neighbor->neighbor_addr));				printf ("          mine(%s)\n",  convert_address_to_string(&neighbor->my_iface_addr));				printf ("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n");				return (neighbor);							}		}	}	return (NULL);  }/*------------------------------------------------------------------------*/voidolsr_release_neighbor_table(){	olsr_u8_t              index;	struct neighbor_entry  *neighbor;	struct neighbor_entry  *neighbor_tmp;	struct neighborhash    *hash_neighbor;	int                    i;	for(index=0;index<HASHSIZE;index++)	{		hash_neighbor=&neighbortable.neighborhash[index];		//CRC modify: bugs in previous code:		//for(neighbor=hash_neighbor->neighbor_forw;has_neighbor!=(struct neighbor_entry *)hash_neighbor;neighbor=neighbor->neighbor_forw)			neighbor=hash_neighbor->neighbor_forw;		while(neighbor!=(struct neighbor_entry*)hash_neighbor)		{			neighbor_tmp=neighbor;			neighbor=neighbor->neighbor_forw;			olsr_delete_neighbor_table(neighbor_tmp);		}

⌨️ 快捷键说明

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