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

📄 input.c

📁 OLSR Implementation for XORP
💻 C
📖 第 1 页 / 共 4 页
字号:
/* * 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. * */char input_rcsid[] =   "$Id: input.c,v 1.2 2000/12/06 10:36:11 prima Exp $";/* * Routing Table Management Daemon */#include "defs.h"extern int filter;struct timeval now;		/* current idea of time */struct tm snowtm;struct tm *nowtm=&snowtm;	/* current idea of time (in tm) */int changes = 0;        /* is set if changes occur in MPRS set */ int tc_to_relay = 0;	/*added by Y.Ge, if the node should relay the tc */int qostc_to_relay = 0;	/*added by Y.Ge, if the node should relay the qos tc */int mid_to_relay = 0;	/*added by Y.Ge, if the node should relay the mid */int hna_to_relay = 0; 	/*added by Y.Ge, if the node should relay the hna */int tc_relay_size = 0;	/* added by Y.Ge. the size of the TC that should be relayed */int mid_relay_size = 0; /* added by Y.Ge. the size of the MID that should be relayed */int hna_relay_size = 0; /* added by Y.Ge. the size of the HNA that should be relayed */int qostc_relay_size = 0; /* added by Y.Ge, the size of QoS HNA that should be relayed */void tools_input(struct sockaddr *from, struct afswitch *afp, struct olsr *olsr, int size, int iface_index); //"iface_index" is added by Y.Ge /* * Build HELLO Message according to hello_message struct from olsrmsg struct. */void hello_chgestruct(struct hello_message *hmsg, struct olsrmsg *m, struct sockaddr *from, int index){ 	struct hellomsg *h;	struct hellinfo *hinfo, *hinf;	//v4->v6 chg	struct olsr_ip_addr *haddr, *hadr;	struct hello_neighbor *nb;	olsr_u8_t link; //added by Y.Ge        	hmsg->neighbors = (struct hello_neighbor *)NULL;	if (!m)		return;	if (m->olsr_msgtype != HELLO_PACKET && m->olsr_msgtype != UPDATE_NEIGHBOR)		return;	h = m->olsr_hello;	hinfo = h->hell_info;	/*CRC v4->v6 del	hmsg->source_addr = ((struct sockaddr_in *)from)->sin_addr.s_addr;*/	//CRC v4->v6 add	/*memcpy(&hmsg->source_addr,&(((struct sockaddr_in6 *)from)->sin6_addr),sizeof(struct olsr_ip_addr));*/	//CRC HNA add	//memcpy(&hmsg->source_addr,&(m->olsr_source),sizeof(struct olsr_ip_addr)); //commented by Y.Ge	memcpy (&hmsg->source_addr,&(((struct sockaddr_in6 *)from)->sin6_addr), sizeof(struct olsr_ip_addr)); //added by Y.Ge, set the interface addr	memcpy (&hmsg->originator_addr,&(m->olsr_source), sizeof(struct olsr_ip_addr)); //added by Y.Ge, set the originator main addr 	memcpy (&hmsg->my_addr, &addr_manet[index], sizeof(struct olsr_ip_addr)); //added by Y.Ge	/*---------------------------------------------------------------------*/		hmsg->v_time = m->olsr_vtime; //added by Y.Ge	hmsg->packet_seq_number = ntohs(m->olsr_msgseq); //added by Y.Ge	//hmsg->packet_seq_number = ntohs(h->hell_seqnum);  //commented by Y.Ge	//hmsg->mpr_seq_number = ntohs(h->hell_mprseqnum);  //commented by Y.Ge	hmsg->willingness = h->hell_willingness; //added by Y.Ge	hmsg->rcvd_h_time = h->hell_htime;	//added by Y.Ge	/********************** added by Y.Ge ******************/	/*** debug ***/	if (debug_level >3)	{		printf ("--------THE RECEIVED MESSAGE IS A HELLO with following information!\n");		printf ("        sender's interface address: %s\n", convert_address_to_string (&hmsg->source_addr));		printf ("        sender's originator address: %s\n", convert_address_to_string (&hmsg->originator_addr));		printf ("        received from my interface: %s\n", convert_address_to_string (&hmsg->my_addr));		printf ("        sender's willingness is: %d\n", hmsg->willingness);		printf ("        sender has the following neighbor information:\n");				fprintf (y_file,"--------THE RECEIVED MESSAGE IS A HELLO with following information!\n");		fprintf (y_file,"        sender's interface address: %s\n", convert_address_to_string (&hmsg->source_addr));		fprintf (y_file,"        sender's originator address: %s\n", convert_address_to_string (&hmsg->originator_addr));		fprintf (y_file,"        received from my interface: %s\n", convert_address_to_string (&hmsg->my_addr));		fprintf (y_file,"        sender's willingness is: %d\n", hmsg->willingness);		fprintf (y_file,"        sender has the following neighbor information:\n");	}	/********************* end of revision *****************/		/* the following "for" is commented and re-writed by Y.Ge **/		/*for (hinf = hinfo; (char *)hinf < (char *)m + ntohs(m->olsr_nextmsg);  hinf = (struct hellinfo *)((char *)hinf + ntohs(hinf->next_linktype)))*/		for (hinf = hinfo; (char *)hinf < (char *)m + ntohs(m->olsr_msgsize);  hinf = (struct hellinfo *)((char *)hinf + ntohs(hinf->link_msg_size)))	{		haddr = hinf->neigh_addr;		/* the following "for" is commented and re-writed by Y.Ge **/		//for (hadr = haddr; (char *)hadr < (char *)hinf + ntohs(hinf->next_linktype); hadr++)		for (hadr = haddr; (char *)hadr < (char *)hinf + ntohs(hinf->link_msg_size); hadr++)		{			nb = (struct hello_neighbor *)malloc(sizeof (struct hello_neighbor));			if (nb == 0)			{				printf("olsrd: out of memery \n");				break;			}			/*CRC v4->v6 del nb->address = *hadr;*/			//CRC v4->v6 add			memcpy(&(nb->address),hadr,sizeof(struct olsr_ip_addr));					//nb->status = hinf->link_type;  //commented by Y.Ge			/**************** added by  Y.Ge ************/			link = hinf->link_code;						if (debug_level > 3)			{				printf ("--link code: %d\n", link);				fprintf (y_file,"--link code: %d\n", link);			}						if (link>15)  //link code must less than 15			{				printf ("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n");				printf ("XX ATTENTION: the link code in the received HELLO is invalid! XX\n");				printf ("XXXXXXXXXXXXXXXXXXX     link code is: %d    XXXXXXXXXXXXXXXXXXXX\n", link);				printf ("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n");				exit (1);			}			nb->neigh_status = (int)link/4;			nb->link_status = link - (nb->neigh_status * 4);						if (nb->link_status == SYM_LINK && nb->neigh_status == NOT_NEIGH)			{				printf ("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n");				printf ("XX ATTENTION: the status in the received HELLO is invalid! XX\n");				printf ("XXXXXXXXXXXXX hello neighbor: %s XXXXXXXXXXX\n", convert_address_to_string(&nb->address));				printf ("XXXXXXXXXXX neighbor_status: %d, link_status: %d XXXXXXXXXX\n", nb->neigh_status, nb->link_status);				printf ("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n");				exit (1);			}			/**************** end of revision **********/			nb->next = hmsg->neighbors;			hmsg->neighbors = nb;			/************************** added by Y.Ge *********************/			/*** debug ***/			if (debug_level >3)			{				printf ("   hello neighboor: %s,  neighbor_status: %d, link_status: %d\n", convert_address_to_string(&nb->address), nb->neigh_status, nb->link_status);				//added by L.Qin//				printf ("   input.c the neighbor_hysavg is %f\n",nb->neighbor_hysavg);					fprintf (y_file,"   hello neighboor: %s,  neighbor_status: %d, link_status: %d\n", convert_address_to_string(&nb->address), nb->neigh_status, nb->link_status);			}			/************************** end of revision  ******************/		} 	    	}}/******************** added by Y.Ge ***********//* * Build QoS HELLO Message according to qos_hello_message struct from olsrmsg struct. */void qoshello_chgestruct(struct qos_hello_message *qoshmsg, struct olsrmsg *m, struct sockaddr *from, int index){ 	struct qoshellomsg *qosh;	olsr_u32_t	*in_busy, *out_busy;	int        	count = 0;        	if (!m)		return;	if (m->olsr_msgtype != QOSHELLO_PACKET && m->olsr_msgtype != UPDATE_NEIGHBOR)		return;	qosh = m->olsr_qos_hello;	in_busy = qosh->hell_busy;	memcpy (&qoshmsg->source_addr,&(((struct sockaddr_in6 *)from)->sin6_addr), sizeof(struct olsr_ip_addr)); //set the interface addr	memcpy (&qoshmsg->originator_addr,&(m->olsr_source), sizeof(struct olsr_ip_addr)); //set the originator main addr 	memcpy (&qoshmsg->my_addr, &addr_manet[index], sizeof(struct olsr_ip_addr)); //added by Y.Ge	qoshmsg->packet_seq_number = ntohs(m->olsr_msgseq);		/*** debug ***/	if (debug_level >3)	{		printf ("--------THE RECEIVED MESSAGE IS A QoS HELLO with following information!\n");		printf ("        sender's interface address: %s\n", convert_address_to_string (&qoshmsg->source_addr));		printf ("        sender's originator address: %s\n", convert_address_to_string (&qoshmsg->originator_addr));		printf ("        received from my interface: %s\n", convert_address_to_string (&qoshmsg->my_addr));				fprintf (y_file,"--------THE RECEIVED MESSAGE IS A QoS HELLO with following information!\n");		fprintf (y_file,"        sender's interface address: %s\n", convert_address_to_string (&qoshmsg->source_addr));		fprintf (y_file,"        sender's originator address: %s\n", convert_address_to_string (&qoshmsg->originator_addr));		fprintf (y_file,"        received from my interface: %s\n", convert_address_to_string (&qoshmsg->my_addr));	}		for(out_busy = in_busy; (char *)out_busy < (char *)m + ntohs(m->olsr_msgsize); out_busy ++)	{		qoshmsg->rcvd_busy_time = *out_busy;		count +=1;				if (debug_level > 3)		{			printf ("received busy time: %d\n", qoshmsg->rcvd_busy_time);			fprintf (y_file,"received busy time: %d\n", qoshmsg->rcvd_busy_time);					}	}		if (count > 1)	{		printf ("XXXXXXXXXXX error in reqding the QoS message ! XXXXXXXX\n");		exit (1);	}	}/* * Build QoS TC Message according to qos_tc_message struct from olsrmsg struct. */void qostc_chgestruct(struct qos_tc_message *qostmsg, struct olsrmsg *m, struct sockaddr *from, int index){	struct qostcmsg *qostc;	olsr_u32_t *mprsbusy, *mbusy;	struct tc_mpr_busy_time *mprs_busy_time;	qostmsg->multipoint_relay_selector_busy_time = (struct tc_mpr_busy_time *)NULL;	if (!m)		return;	if (m->olsr_msgtype != QOSTC_PACKET)		return;	qostc = m->olsr_qos_tc;	mprsbusy = qostc->tc_mpr_busy;		memcpy(&(qostmsg->source_addr),&(((struct sockaddr_in6 *)from)->sin6_addr),sizeof(struct olsr_ip_addr)); 	memcpy(&(qostmsg->originator),&(m->olsr_source),sizeof(struct olsr_ip_addr));	memcpy (&qostmsg->my_addr, &addr_manet[index], sizeof(struct olsr_ip_addr));		qostmsg->packet_seq_number = ntohs(m->olsr_msgseq);	qostmsg->hop_count = m->olsr_hopcount;	qostmsg->time_to_live = m->olsr_ttl;	qostmsg->my_busy_time = qostc->qostc_originator_busy; 	qostmsg->mssn =  ntohs(qostc->qostc_mprseqnum);		if (debug_level >3)	{		printf ("--------THE RECEIVED MESSAGE IS A QoS TC with following information!\n");		printf ("        sender's interface address: %s\n", convert_address_to_string (&qostmsg->source_addr));

⌨️ 快捷键说明

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