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

📄 packet.c

📁 OLSR Implementation for XORP
💻 C
字号:
/* * 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 packet_rcsid[] =   "$Id: packet.c,v 1.2 2000/12/06 10:36:12 prima Exp $";#include "defs.h"voidolsr_destroy_hello_message(struct hello_message *message){	struct hello_neighbor  *neighbors;	struct hello_neighbor  *neighbors_tmp;	neighbors=message->neighbors;	while(neighbors!=NULL)	{		neighbors_tmp=neighbors;		neighbors=neighbors->next;		free(neighbors_tmp);	}}/*---------------------------------------------------------------------------*/voidolsr_print_hello_message(struct hello_message *message){	struct hello_neighbor  *neighbors;	neighbors=message->neighbors;	printf("%s           \n ",convert_address_to_string(&message->source_addr)); 	while(neighbors!=NULL)	{     		neighbors=neighbors->next;		printf("%s           \n ",convert_address_to_string(&neighbors->address));     	}}/*---------------------------------------------------------------------------*/voidolsr_destroy_tc_message(struct tc_message *message){	struct tc_mpr_addr  *mpr_set;	struct tc_mpr_addr  *mpr_set_tmp;	mpr_set=message->multipoint_relay_selector_address;	while( mpr_set!=NULL)	{		mpr_set_tmp=mpr_set;		mpr_set=mpr_set->next;		free(mpr_set_tmp);	}}/*------------------------------------------------------------------------*//******************* added by Y.Ge *************/voidolsr_destroy_mid_message (struct mid_message *message){	struct mid_iface_addr *mid_iface_set;	struct mid_iface_addr *mid_iface_set_tmp;		mid_iface_set = message->mid_interface_address;		while (mid_iface_set != NULL)	{		mid_iface_set_tmp = mid_iface_set;		mid_iface_set = mid_iface_set->next;		free (mid_iface_set_tmp);	}}/*------------------------------------------------------------------------*/voidolsr_destroy_qos_tc_message(struct qos_tc_message *message){	struct tc_mpr_busy_time  *mpr_set;	struct tc_mpr_busy_time  *mpr_set_tmp;	mpr_set=message->multipoint_relay_selector_busy_time;	while( mpr_set!=NULL)	{		mpr_set_tmp=mpr_set;		mpr_set=mpr_set->next;		free(mpr_set_tmp);	}}/****************** end of revision ************//*------------------------------------------------------------------------*/olsr_u8_tolsr_lookup_link_status(struct hello_message *message, int index) //"index" is added by Y.Ge{  /*    Check whether the current address is in the received packet      */  	struct hello_neighbor  *neighbors;  	neighbors=message->neighbors;	while(neighbors!=NULL)	{		//CRC v4->v6 modify		//if(0==memcmp(&neighbors->address,&addr_ip,sizeof(struct olsr_ip_addr)))		if(0==memcmp(&neighbors->address,&addr_manet[index],sizeof(struct olsr_ip_addr)))			//return(neighbors->status);//commented by Y.Ge			return (neighbors->link_status); //added by Y.Ge       		neighbors=neighbors->next;    	}	return(NOT_DETECTED);}/*-----------------------------------------------------------------------*//******************* added by  Y.Ge ***************/olsr_u8_tolsr_lookup_neighbor_status(struct hello_message *message, int index){  /*    Check whether the current address is in the received packet      */  	struct hello_neighbor  *neighbors;  	neighbors=message->neighbors;	while(neighbors!=NULL)	{		//CRC v4->v6 modify		//if(0==memcmp(&neighbors->address,&addr_ip,sizeof(struct olsr_ip_addr)))		if(0==memcmp(&neighbors->address,&addr_manet[index],sizeof(struct olsr_ip_addr)))			return (neighbors->neigh_status); //added by Y.Ge       		neighbors=neighbors->next;    	}	return(NOT_DETECTED);}/**************** end of revision **************//*-----------------------------------------------------------------------*/voidolsr_destroy_hna_message(struct hna_message *message){	struct hna_net_addr  *net_addr_ptr;	struct hna_net_addr  *net_addr_ptr_tmp;	net_addr_ptr=message->hna_net_addrs;	while( net_addr_ptr!=NULL)	{		net_addr_ptr_tmp=net_addr_ptr;		net_addr_ptr=net_addr_ptr->next;		free(net_addr_ptr_tmp);	}	return;}/*------------------------------------------------------------------------*//************** added by Y.Ge ******************/voidolsr_copy_mid_packet(struct mid_message *inmid, struct mid_message *outmid){	struct olsr_ip_addr	*midaddr, *maddr;	struct mid_iface_addr	*midinterfaces, *addressptr;		outmid->mid_interface_address = (struct mid_iface_addr *)NULL;		if (!inmid)		return;			if (!inmid->mid_interface_address)		return;			memcpy(&outmid->source_addr, &inmid->source_addr, sizeof(struct olsr_ip_addr));	memcpy(&outmid->originator_addr, &inmid->originator_addr, sizeof(struct olsr_ip_addr));	outmid->hop_count = inmid->hop_count;	outmid->time_to_live = inmid->time_to_live;	outmid->packet_seq_number = inmid->packet_seq_number;	outmid->v_time = inmid->v_time;		for (addressptr = inmid->mid_interface_address; addressptr!=NULL; addressptr = addressptr->next)	{		midinterfaces = (struct mid_iface_addr *)malloc(sizeof (struct mid_iface_addr));		if (midinterfaces == 0)		{			printf ("olsrd: out of memery \n");			break;		}		memcpy(&midinterfaces->interface_address, &addressptr->interface_address,sizeof(struct olsr_ip_addr));		midinterfaces->next = outmid->mid_interface_address;		outmid->mid_interface_address=midinterfaces; 			}	}/*------------------------------------------------------------------------*/voidolsr_copy_tc_packet(struct tc_message  *intc, struct tc_message *outtc){	struct olsr_ip_addr	*mpraddr, *maddr;	struct tc_mpr_addr	*mprselector, *mprptr;		outtc->multipoint_relay_selector_address = (struct tc_mpr_addr *)NULL;		if(!intc)		return;			/*if(!intc->multipoint_relay_selector_address)		return;*/			memcpy(&outtc->source_addr, &intc->source_addr, sizeof(struct olsr_ip_addr));	memcpy(&outtc->originator, &intc->originator, sizeof(struct olsr_ip_addr));	outtc->hop_count = intc->hop_count;	outtc->time_to_live = intc->time_to_live;	outtc->packet_seq_number = intc->packet_seq_number;	outtc->mssn = intc->mssn;	outtc->v_time = intc->v_time;		/*printf ("********** in copy tc packet ! **********\n");	printf ("after copy, the out tc is:\n");	printf ("packet seq: %d, mssn: %d\n", outtc->packet_seq_number, outtc->mssn);		fprintf (y_file,"********** in copy tc packet ! **********\n");	fprintf (y_file,"after copy, the out tc is:\n");	fprintf (y_file,"packet seq: %d, mssn: %d\n", outtc->packet_seq_number, outtc->mssn);*/		for(mprptr= intc->multipoint_relay_selector_address; mprptr!=NULL; mprptr = mprptr->next)	{		mprselector = (struct tc_mpr_addr *)malloc(sizeof (struct tc_mpr_addr));		if(mprselector == 0)		{			printf ("olsrd: out of memery \n");			break;		}		memcpy(&mprselector->address, &mprptr->address, sizeof(struct olsr_ip_addr));		mprselector->next = outtc->multipoint_relay_selector_address;		outtc->multipoint_relay_selector_address=mprselector;	}}/*------------------------------------------------------------------------*/voidolsr_copy_qos_tc_packet(struct qos_tc_message  *inqostc, struct qos_tc_message *outqostc){	olsr_u32_t		*mprbusy, *mbusy;	struct tc_mpr_busy_time	*mprselectorbusy, *mprbusyptr;		outqostc->multipoint_relay_selector_busy_time = (struct tc_mpr_busy_time *)NULL;		if(!inqostc)		return;			/*if(!intc->multipoint_relay_selector_address)		return;*/			memcpy(&outqostc->source_addr, &inqostc->source_addr, sizeof(struct olsr_ip_addr));	memcpy(&outqostc->originator, &inqostc->originator, sizeof(struct olsr_ip_addr));	outqostc->hop_count = inqostc->hop_count;	outqostc->time_to_live = inqostc->time_to_live;	outqostc->packet_seq_number = inqostc->packet_seq_number;	outqostc->mssn = inqostc->mssn;	outqostc->my_busy_time = inqostc->my_busy_time;		/*printf ("********** in copy tc packet ! **********\n");	printf ("after copy, the out tc is:\n");	printf ("packet seq: %d, mssn: %d\n", outtc->packet_seq_number, outtc->mssn);		fprintf (y_file,"********** in copy tc packet ! **********\n");	fprintf (y_file,"after copy, the out tc is:\n");	fprintf (y_file,"packet seq: %d, mssn: %d\n", outtc->packet_seq_number, outtc->mssn);*/		for(mprbusyptr= inqostc->multipoint_relay_selector_busy_time; mprbusyptr!=NULL; mprbusyptr = mprbusyptr->next)	{		mprselectorbusy = (struct tc_mpr_busy_time *)malloc(sizeof (struct tc_mpr_busy_time));		if(mprselectorbusy == 0)		{			printf ("olsrd: out of memery \n");			break;		}		memcpy(&mprselectorbusy->busy_time, &mprbusyptr->busy_time, sizeof(olsr_u32_t));		mprselectorbusy->next = outqostc->multipoint_relay_selector_busy_time;		outqostc->multipoint_relay_selector_busy_time=mprselectorbusy;	}}/*------------------------------------------------------------------------*/voidolsr_copy_hna_packet(struct hna_message *inhna, struct hna_message *outhna){	struct hna_net_addr	*hnaaddrptr, *haddrptr;		outhna->hna_net_addrs = (struct hna_net_addr *)NULL;		if (!inhna)		return;			if (!inhna->hna_net_addrs)		return;		memcpy(&outhna->source_addr, &inhna->source_addr, sizeof(struct olsr_ip_addr));	memcpy(&outhna->originator, &inhna->originator, sizeof(struct olsr_ip_addr));	outhna->hop_count = inhna->hop_count;	outhna->time_to_live = inhna->time_to_live;	outhna->packet_seq_number = inhna->packet_seq_number;	outhna->v_time = inhna->v_time;			for (haddrptr = inhna->hna_net_addrs; haddrptr!=NULL; haddrptr = haddrptr->next)	{		hnaaddrptr = (struct hna_net_addr *)malloc(sizeof (struct hna_net_addr));		if (hnaaddrptr ==0)		{			printf ("olsrd: out of memery \n");			exit (1);		}		memcpy(&hnaaddrptr->net_addr, &haddrptr->net_addr, sizeof(struct olsr_ip_addr));		hnaaddrptr->prefix = haddrptr->prefix;		hnaaddrptr->next = outhna->hna_net_addrs;		outhna->hna_net_addrs = hnaaddrptr;	}	}/******************** end of revision *****************/

⌨️ 快捷键说明

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