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

📄 input.c

📁 OLSR Implementation for XORP
💻 C
📖 第 1 页 / 共 4 页
字号:
	struct hna_message hnapacket_in, *hnapacket_out; 	struct mid_message midpacket_in, *midpacket_out; //added by Y.Ge	struct qos_hello_message qoshellopacket;	//added by Y.Ge	struct qos_tc_message	qostcpacket_in, *qostcpacket_out;//added by Y.Ge	int   	qos_tc_rcvd_size = 0;	//added by Y.Ge	int	qos_tc_rcvd = 0;	//added by Y.Ge	int	tc_rcvd = 0;	//added by Y.Ge	int iface_index; //added by Y.Ge	int found = 0;  //added by Y.Ge		/********** added by Y.Ge *********/	/* deal with unknown packet */	int relay_unknown_pk = 0;	int i;	int unknown_pk_rcvd = 0;	int unknown_msg_size = 0;	/********* end of revision ********/    	/*CRC v4->v6 del	olsr_ip_addr src_addr = ((struct sockaddr_in *)from)->sin_addr.s_addr;*/	struct olsr_ip_addr src_addr; 	struct interface *ifp;	int minsize;      /* minimum size of olsr packet */	int count;	struct afswitch *afp;	char buf1[256];		//CRC v4->v6 add	memcpy(&src_addr,&(((struct sockaddr_in6 *)from)->sin6_addr),sizeof(struct olsr_ip_addr));	tcpacket_in.multipoint_relay_selector_address = (struct tc_mpr_addr *)NULL;	hellopacket.neighbors = (struct hello_neighbor *)NULL;	midpacket_in.mid_interface_address = (struct mid_iface_addr *)NULL; //added by Y.Ge    	//CRC HNA add	hnapacket_in.hna_net_addrs=(struct hna_net_addr*)NULL;	hnapacket_out=(struct hna_message*)NULL; 	//afp = &afswitch[from->sa_family];		//v4->v6	/*if (from->sa_family >= af_max || afp->af_hash == (void (*)(struct sockaddr *, struct afhash *))0)	{		syslog(LOG_INFO, "\"from\" address in unsupported address family (%d), msg %d\n",from->sa_family, m->olsr_msgtype);		return;	}*/	/* if (ntohs(olsr->olsr_packlen) != size) 	{		fprintf(stderr, "Size error detected in received packet.\n");		syslog(LOG_ERR, " packet length error in  packet received from %s!", *afswitch[from->sa_family].af_format)(from, buf1, sizeof(buf1)));		return;	}*/	/*	 * Process tools packets.	 */	//tools_input(from, afp, olsr, size);	/* verify message came from a privileged port */	/*if ((*afp->af_portmatch)(from) == 0)		return;*/	/*(*afp->af_canon)(from);*/       	/* are we talking to ourselves? */	ifp = if_ifwithaddr6(from);       	if (ifp) 	{		if (ifp->int_flags & IFF_PASSIVE) 		{			fprintf(stderr, " Data from passive interface\n");			syslog(LOG_ERR, "bogus input (from passive interface, %s)", (*afswitch[from->sa_family].af_format)(from, buf1, sizeof(buf1)));		}		return;	}      	if (filter)	{  	  	/********** commented by Y.Ge *************/		/*if (!is_neighbor(&addr, (struct sockaddr_in6 *)from))		{			return;		}*/		/********** end of revision**************/		/********** added by Y.Ge *************/			for (iface_index=0; iface_index<num_of_interface; iface_index++)		{			if (is_neighbor(&addr[iface_index], (struct sockaddr_in6 *)from))			{				found = 1;				break;			}		}		if (!found)		{			printf (" MESSAGE RECEIVED FROM A NON-NEIGHBOR\n");			return;		}		/********** end of revision**************/	}	     	ifp = 0;		/***************** added by Y.Ge ****************/	/***** debug *****/	if (debug_level >3)	{		printf ("\n\n\n************time (%02d:%02d:%02d.%06lu) message received from interface %d!************\n", nowtm->tm_hour, nowtm->tm_min,nowtm->tm_sec,now.tv_usec, index);		printf ("packet length: %d\n", ntohs(olsr->olsr_packlen));		printf ("packet sequence: %d\n", ntohs(olsr->olsr_seqnum));				fprintf (y_file,"\n\n\n************time (%02d:%02d:%02d.%06lu) message received from interface %d!************\n", nowtm->tm_hour, nowtm->tm_min,nowtm->tm_sec,now.tv_usec, index);		fprintf (y_file,"packet length: %d\n", ntohs(olsr->olsr_packlen));		fprintf (y_file,"packet sequence: %d\n", ntohs(olsr->olsr_seqnum));			}	/**************** end of revision ***************/	//TRACE_INPUT(ifp, from, (char *)olsr, size);	/*minsize = (int)sizeof(m->olsr_msgtype) + (int)sizeof(m->olsr_broad) + (int)sizeof(m->olsr_nextmsg);*/   /* commented by Y.Ge */		minsize = 4*(int)sizeof(olsr_u8_t) + (int)sizeof(olsr_u16_t) + (int)sizeof (struct olsr_ip_addr);  //added by Y.Ge	count = size - ((char *)m - (char *)olsr);	if (count < minsize)	{		printf ("XXXXXXXXXXXX PACKET to small! count is: %d, minsize is: %d XXXXXXXXXXXXXX\n", count, minsize);		exit(1);		//return;	}      	/* the following "for" is commented and re-writed by Y.Ge **/ 	/*for ( ; count > 0; m = (struct olsrmsg *)((char *)m + ntohs(m->olsr_nextmsg)))*/	for ( ; count > 0; m = (struct olsrmsg *)((char *)m + ntohs(m->olsr_msgsize)))	{		if (count < minsize)		{			printf ("XXXXXXXX MESSAGE too small! count is: %d, minsize is: %d XXXXXXXXXX\n", count, minsize);			printf ("break here!\n");			exit (1);			//break;	  	}		//count -= ntohs(m->olsr_nextmsg); //commented  by Y.Ge		count -= ntohs(m->olsr_msgsize); //added by Y.Ge	   		/************* added by Y.Ge ***************/		/*** debug ***/		if (debug_level >3)		{			printf ("\n\n\n.......................... the following is the olsr_msg info ...................\n");			printf ("      message type: %d\n", m->olsr_msgtype);			printf ("      vtime: %d\n", m->olsr_vtime);			printf ("      message size: %d\n", ntohs(m->olsr_msgsize));			printf ("      message source: %s\n", convert_address_to_string (&m->olsr_source));			printf ("      ttl: %d\n", m->olsr_ttl);			printf ("      hop count: %d\n", m->olsr_hopcount);			printf ("      message sequence number: %d\n", ntohs(m->olsr_msgseq));			printf ("\n\n");						fprintf (y_file, "\n\n\n.......................... the following is the olsr_msg info ...................\n");			fprintf (y_file, "      message type: %d\n", m->olsr_msgtype);			fprintf (y_file, "      vtime: %d\n", m->olsr_vtime);			fprintf (y_file, "      message size: %d\n", ntohs(m->olsr_msgsize));			fprintf (y_file, "      message source: %s\n", convert_address_to_string (&m->olsr_source));			fprintf (y_file, "      ttl: %d\n", m->olsr_ttl);			fprintf (y_file, "      hop count: %d\n", m->olsr_hopcount);			fprintf (y_file, "      message sequence number: %d\n", ntohs(m->olsr_msgseq));			fprintf (y_file, "\n\n");		}		/************* end of revision *************/		/************** added by Y.GE *********/		/* if I understand qos OLSR */		if (use_qos)		{			switch (m->olsr_msgtype)			{				case QOSHELLO_PACKET :					qoshello_chgestruct(&qoshellopacket, m, from, index);										olsr_process_received_qos_hello(index, &qoshellopacket);					break;				case QOSTC_PACKET :					qostc_chgestruct(&qostcpacket_in, m, from, index);					qos_tc_rcvd = 1;					qos_tc_rcvd_size = ntohs(m->olsr_msgsize); //remember the size of the qos TC					break;					}		}		/************* end of revision *******/				switch (m->olsr_msgtype) 		{			case HELLO_PACKET:				hello_chgestruct(&hellopacket, m, from, index); //"index" added by Y.Ge					//added by L.Qin	//					struct neighbor_entry *aNeighbor;//					aNeighbor=(struct neighbor_entry *)malloc(sizeof(struct neighbor_entry)); //			printf("input.c The hyst value of the neighbor in %d is //%f\n",index,aNeighbor->neighbor_hysavg); 					//***** 				olsr_process_received_hello(&hellopacket, index); //"index" added by Y.Ge				break;			case TC_PACKET:				tc_rcvd = 1;				tc_chgestruct(&tcpacket_in, m, from, index); //"index" added by Y.Ge												/******** added by Y.Ge *********/				/* qos OLSR */				if (qos_tc_rcvd) //I understand QoS OLSR					olsr_process_received_qos_tc(index, &tcpacket_in, &tcpacket_out, &qostcpacket_in, &qostcpacket_out);				else					olsr_process_received_tc(index, &tcpacket_in, &tcpacket_out); //"index" added by Y.Ge											if (tcpacket_out)				{					/*toall(tc_build, (struct hello_message *)NULL, tcpacket_out, (struct mid_message *)NULL, (struct hna_message *)NULL, (struct interface *)NULL);*/ //commented by Y.Ge										/************** added by Y.Ge **************/					/***** check if there is already another TC packet to be relayed *****/					if (tc_to_relay ==1)					{						/* send out that TC packet even the jitter time has not expired */						for (ifp = ifnet; ifp; ifp = ifp->int_next)						{							if (debug_level > 3)							{								printf ("XXXXXXXXXXXXXXXXXXXX send out the OLD RELAY TC! XXXXXXXXXXXXXXXXXXXXXXX\n"); 								printf ("XXXXXXXXXXXXXXXXXXXX time  (%02d:%02d:%02d.%06lu) TC sent from interface %d!XXXXXXXXXXXXXXXXXX\n", nowtm->tm_hour, nowtm->tm_min,nowtm->tm_sec,now.tv_usec, ifp->my_index);															fprintf (y_file,"XXXXXXXXXXXXXXXXXXXX send out the OLD RELAY TC! XXXXXXXXXXXXXXXXXXXXXXX\n"); 								fprintf (y_file,"XXXXXXXXXXXXXXXXXXXX time  (%02d:%02d:%02d.%06lu) TC sent from interface %d!XXXXXXXXXXXXXXXXXX\n", nowtm->tm_hour, nowtm->tm_min,nowtm->tm_sec,now.tv_usec, ifp->my_index);							}														/* added by Y.Ge */							/* check if there is a qos tc to be relayed */							if (qostc_to_relay ==1)								qostc_build((struct sockaddr *)NULL, &qostcpacket_relay, &tcpacket_relay, 0, ifp, 1);							else								tc_build((struct sockaddr *)NULL,(struct hello_message *)NULL, &tcpacket_relay, (struct mid_message *)NULL, (struct hna_message *)NULL,0,ifp, 1);							tointerface (sndmsg, (struct hello_message *)NULL, (struct tc_message *)NULL, (struct mid_message *)NULL,(struct hna_message *)NULL, (struct interface *)NULL, ifp->my_index);						}						/* free memory */						olsr_destroy_tc_message (&tcpacket_relay);						olsr_destroy_qos_tc_message (&qostcpacket_relay);						tcpacket_relay.multipoint_relay_selector_address = NULL;						qostcpacket_relay.multipoint_relay_selector_busy_time = NULL;												tc_to_relay = 0;						qostc_to_relay = 0;						tc_relay_interval = 0;						tc_relay_size = 0;						qostc_relay_size = 0;						}										/* added by Y.Ge */					/* qos OLSR */					if (use_qos)					{						if(qos_tc_rcvd)						{							olsr_copy_qos_tc_packet(qostcpacket_out, &qostcpacket_relay);								qostc_to_relay = 1;													}					}					olsr_copy_tc_packet(tcpacket_out, &tcpacket_relay);										/*printf ("********** copy tc packet finished ! **********\n");					printf ("after copy, the out tc is:\n");					printf ("packet seq: %d, mssn: %d\n", tcpacket_relay.packet_seq_number, tcpacket_relay.mssn);										fprintf (y_file,"********** copy tc packet finished ! **********\n");					fprintf (y_file,"after copy, the out tc is:\n");					fprintf (y_file,"packet seq: %d, mssn: %d\n", tcpacket_relay.packet_seq_number, tcpacket_relay.mssn);*/										/***** set the timer to relay the tc *****/					/* relay jitter is 1/4 of HELLO_INTERVAL */					tc_relay_jitter = (float) random()/(((double)RAND_MAX +1)/((double)HELLO_INTERVAL/4));										if(debug_level > 3)					{						printf (" ----- tc relay jetter is: %f\n", tc_relay_jitter);						fprintf (y_file," ----- tc relay jetter is: %f\n", tc_relay_jitter);					}										tc_to_relay = 1;					tc_relay_size =  qos_tc_rcvd_size + ntohs(m->olsr_msgsize); //remember the size of the TC															/*** free the memery ***/					olsr_destroy_tc_message (tcpacket_out);										if (qos_tc_rcvd)						olsr_destroy_qos_tc_message (qostcpacket_out);					/*************** end of rrevision **********/				}				break;			/******************* added by Y.Ge *************/			case MID_PACKET:				mid_chgestruct (&midpacket_in, m, from, index);				olsr_process_received_mid (index, &midpacket_in, &midpacket_out);				if (midpacket_out)				{					/***** check if there is already another MID packet to be relayed *****/

⌨️ 快捷键说明

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