Exemple #1
0
/*
 * TODO: Some form of conformance check so that only packets
 * destined to the particular Ethernet protocol are being captured
 * by the handler... right now.. this might capture other packets as well.
 */
void* fromEthernetDev(void *arg)
{
    
	interface_t *iface = (interface_t *) arg;
	interface_array_t *iarr = (interface_array_t *)iface->iarray;
	uchar bcast_mac[] = MAC_BCAST_ADDR;

	gpacket_t *in_pkt;

	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);		// die as soon as cancelled
	while (1)
	{
            //printf("In fromEthernet Dev\n");
            
		verbose(2, "[fromEthernetDev]:: Receiving a packet ...");
		if ((in_pkt = (gpacket_t *)malloc(sizeof(gpacket_t))) == NULL)
		{
			fatal("[fromEthernetDev]:: unable to allocate memory for packet.. ");
			return NULL;
		}

		bzero(in_pkt, sizeof(gpacket_t));
		vpl_recvfrom(iface->vpl_data, &(in_pkt->data), sizeof(pkt_data_t));
		pthread_testcancel();
		// check whether the incoming packet is a layer 2 broadcast or
		// meant for this node... otherwise should be thrown..
		// TODO: fix for promiscuous mode packet snooping.
		if ((COMPARE_MAC(in_pkt->data.header.dst, iface->mac_addr) != 0) &&
			(COMPARE_MAC(in_pkt->data.header.dst, bcast_mac) != 0))
		{
                    ip_packet_t *ip_pkt = (ip_packet_t *)in_pkt->data.data;
                    if( ip_pkt->ip_prot == OSPF_PROTOCOL ){
                        
                    }
                    else{
                        //stub verification
                        StubVerify( in_pkt, iface );
                        verbose(2, "[fromEthernetDev]:: SPacket dropped .. not for this router!? ");
                        free(in_pkt);
                        continue;
                    }
		}
                
                // copy fields into the message from the packet..
		in_pkt->frame.src_interface = iface->interface_id;
		COPY_MAC(in_pkt->frame.src_hw_addr, iface->mac_addr);
		COPY_IP(in_pkt->frame.src_ip_addr, iface->ip_addr);

		// check for filtering.. if the it should be filtered.. then drop
		if (filteredPacket(filter, in_pkt))
		{
			verbose(2, "[fromEthernetDev]:: Packet filtered..!");
			free(in_pkt);
			continue;   // skip the rest of the loop
		}

		verbose(2, "[fromEthernetDev]:: Packet is sent for enqueuing..");
                enqueuePacket(pcore, in_pkt, sizeof(gpacket_t));
	}
}
Exemple #2
0
void* fromRawDev(void *arg)
{
    interface_t *iface = (interface_t *) arg;
    uchar bcast_mac[] = MAC_BCAST_ADDR;
    gpacket_t *in_pkt;
    int pktsize;
    char tmpbuf[MAX_TMPBUF_LEN];
    
    pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);		// die as soon as cancelled
    while (1)
    {
        verbose(2, "[fromRawDev]:: Receiving a packet ...");
        if ((in_pkt = (gpacket_t *)malloc(sizeof(gpacket_t))) == NULL)
        {
            fatal("[fromRawDev]:: unable to allocate memory for packet.. ");
            return NULL;
        }

        bzero(in_pkt, sizeof(gpacket_t));
        pktsize = raw_recvfrom(iface->vpl_data, &(in_pkt->data), sizeof(pkt_data_t));
        pthread_testcancel();
        
        verbose(2, "[fromRawDev]:: Destination MAC is %s ", MAC2Colon(tmpbuf, in_pkt->data.header.dst));
        // check whether the incoming packet is a layer 2 broadcast or
        // meant for this node... otherwise should be thrown..
        // TODO: fix for promiscuous mode packet snooping.
        if ((COMPARE_MAC(in_pkt->data.header.dst, iface->mac_addr) != 0) &&
                (COMPARE_MAC(in_pkt->data.header.dst, bcast_mac) != 0))
        {
            verbose(2, "[fromRawDev]:: Packet[%d] dropped .. not for this router!? ", pktsize);
            free(in_pkt);
            continue;
        }
		
        // copy fields into the message from the packet..
        in_pkt->frame.src_interface = iface->interface_id;
        COPY_MAC(in_pkt->frame.src_hw_addr, iface->mac_addr);
        COPY_IP(in_pkt->frame.src_ip_addr, iface->ip_addr);
	
	
	char buf[20];
	memset(buf, 0, sizeof(buf));
	IP2Dot(buf, in_pkt->frame.src_ip_addr);
//	if(strcmp(buf, "172.31.32.1")==0)
//		printf("FROM RAW IP %s\n", buf);
        // check for filtering.. if the it should be filtered.. then drop
     
	if (filteredPacket(filter, in_pkt))
        {
            verbose(2, "[fromRawDev]:: Packet filtered..!");
            free(in_pkt);
            continue;   // skip the rest of the loop
        }

        verbose(2, "[fromRawDev]:: Packet is sent for enqueuing..");
        enqueuePacket(pcore, in_pkt, sizeof(gpacket_t));
    }
}
Exemple #3
0
void* fromTunDev(void *arg)
{
    interface_t *iface = (interface_t *) arg;
    interface_array_t *iarr = (interface_array_t *)iface->iarray;
    uchar bcast_mac[] = MAC_BCAST_ADDR;
    gpacket_t *in_pkt;
    int pktsize;
    char tmpbuf[MAX_TMPBUF_LEN];
    
    pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);		// die as soon as cancelled
    while (1)
    {
        verbose(2, "[fromTunDev]:: Receiving a packet ...");
        if ((in_pkt = (gpacket_t *)malloc(sizeof(gpacket_t))) == NULL)
        {
            fatal("[fromTunDev]:: unable to allocate memory for packet.. ");
            return NULL;
        }

        bzero(in_pkt, sizeof(gpacket_t));
        pktsize = tun_recvfrom(iface->vpl_data, &(in_pkt->data), sizeof(pkt_data_t));
        pthread_testcancel();
        
        verbose(2, "[fromTunDev]:: Destination MAC is %s ", MAC2Colon(tmpbuf, in_pkt->data.header.dst));
      
        if ((COMPARE_MAC(in_pkt->data.header.dst, iface->mac_addr) != 0) &&
                (COMPARE_MAC(in_pkt->data.header.dst, bcast_mac) != 0))
        {
            verbose(1, "[fromTunDev]:: Packet[%d] dropped .. not for this router!? ", pktsize);
            free(in_pkt);
            continue;
        }

        // copy fields into the message from the packet..
        in_pkt->frame.src_interface = iface->interface_id;
        COPY_MAC(in_pkt->frame.src_hw_addr, iface->mac_addr);
        COPY_IP(in_pkt->frame.src_ip_addr, iface->ip_addr);

        // check for filtering.. if the it should be filtered.. then drop
        if (filteredPacket(filter, in_pkt))
        {
            verbose(2, "[fromTunDev]:: Packet filtered..!");
            free(in_pkt);
            continue;   // skip the rest of the loop
        }

        verbose(2, "[fromTunDev]:: Packet is sent for enqueuing..");
        enqueuePacket(pcore, in_pkt, sizeof(gpacket_t));
    }
}
Exemple #4
0
/*
 * TODO: Some form of conformance check so that only packets
 * destined to the particular Ethernet protocol are being captured
 * by the handler... right now.. this might capture other packets as well.
 */
void* fromEthernetDev(void *arg)
{

	interface_t *iface = (interface_t *) arg;
	interface_array_t *iarr = (interface_array_t *)iface->iarray;
	uchar bcast_mac[] = MAC_BCAST_ADDR;

	gpacket_t *in_pkt;

	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);		// die as soon as cancelled
	while (1)
	{
		verbose(2, "[fromEthernetDev]:: Receiving a packet ...");
		if ((in_pkt = (gpacket_t *)malloc(sizeof(gpacket_t))) == NULL)
		{
			fatal("[fromEthernetDev]:: unable to allocate memory for packet.. ");
			return NULL;
		}

		bzero(in_pkt, sizeof(gpacket_t));
		vpl_recvfrom(iface->vpl_data, &(in_pkt->data), sizeof(pkt_data_t));
		pthread_testcancel();
		// check whether the incoming packet is a layer 2 broadcast or
		// meant for this node... otherwise should be thrown..
		// TODO: fix for promiscuous mode packet snooping.
		if ((COMPARE_MAC(in_pkt->data.header.dst, iface->mac_addr) != 0) &&
			(COMPARE_MAC(in_pkt->data.header.dst, bcast_mac) != 0))
		{
			verbose(1, "[fromEthernetDev]:: Packet dropped .. not for this router!? ");
			free(in_pkt);
			continue;
		}


			// copy fields into the message from the packet..
		in_pkt->frame.src_interface = iface->interface_id;
		COPY_MAC(in_pkt->frame.src_hw_addr, iface->mac_addr);
		COPY_IP(in_pkt->frame.src_ip_addr, iface->ip_addr);

		//Printing packet values
		/*	printf("\n=========== INCOMING PACKET VALUES ================\n");
			printf("\n----------HEADER VALUES :");
			printf("\nSource MAC Address: %x : %x : %x : %x : %x : %x", in_pkt->data.header.src[0],
					in_pkt->data.header.src[1],in_pkt->data.header.src[2],
					in_pkt->data.header.src[3],in_pkt->data.header.src[4],in_pkt->data.header.src[5]);
			printf("\nDestination MAC Address: %x : %x : %x : %x : %x : %x", in_pkt->data.header.dst[0],
					in_pkt->data.header.dst[1],in_pkt->data.header.dst[2],
					in_pkt->data.header.dst[3],in_pkt->data.header.dst[4],in_pkt->data.header.dst[5]);

			printf("\nSource IP Address: %d.%d.%d.%d", in_pkt->frame.src_ip_addr[0],
					in_pkt->frame.src_ip_addr[1],in_pkt->frame.src_ip_addr[2],
					in_pkt->frame.src_ip_addr[3]);

			printf("\nProtocol is : %d",in_pkt->data.header.prot);
			printf("\nDestination Interface is : %d",in_pkt->frame.dst_interface);
			printf("\nIngress Port is : %d",in_pkt->frame.src_interface);
			printf("\nNXTH IP Destination: %d.%d.%d.%d", in_pkt->frame.nxth_ip_addr[0],in_pkt->frame.nxth_ip_addr[1],
					in_pkt->frame.nxth_ip_addr[2],in_pkt->frame.nxth_ip_addr[3]);

			printf("\n --- IP PACKET:");
			ip_packet_t *ip_pkt;
			ip_pkt = (ip_packet_t *) in_pkt->data.data;
			printf("\nIP Source: %d.%d.%d.%d", ip_pkt->ip_src[0],ip_pkt->ip_src[1],ip_pkt->ip_src[2],ip_pkt->ip_src[3]);
			printf("\nIP Destination: %d.%d.%d.%d", ip_pkt->ip_dst[0],ip_pkt->ip_dst[1],ip_pkt->ip_dst[2],ip_pkt->ip_dst[3]);
			printf("\nIP Protocol is : %d",ip_pkt->ip_prot);
			printf("\nIP TOS: %d\n",ip_pkt->ip_tos);*/

		// check for filtering.. if the it should be filtered.. then drop
		if (filteredPacket(filter, in_pkt))
		{
			verbose(2, "[fromEthernetDev]:: Packet filtered..!");
			free(in_pkt);
			continue;   // skip the rest of the loop
		}

		verbose(2, "[fromEthernetDev]:: Packet is sent for enqueuing..");
		//ENQUEUE PACKET TO QUEUE_1

		if (in_pkt->data.header.prot == htons(ARP_PROTOCOL))
		{

			ARPProcess(in_pkt);

		}
		else{
/*			if(in_pkt->frame.src_interface == 1){
				printf("\n RECEIVED PACKET FROM INTERFACE 1");

			in_pkt->frame.dst_interface = 2;			// HATA DO MUJHE

			in_pkt->data.header.src[0] = in_pkt->data.header.dst[0];
			in_pkt->data.header.src[1] = in_pkt->data.header.dst[1];
			in_pkt->data.header.src[2] = in_pkt->data.header.dst[2];
			in_pkt->data.header.src[3] = in_pkt->data.header.dst[3];
			in_pkt->data.header.src[4] = in_pkt->data.header.dst[4];
			in_pkt->data.header.src[5] = in_pkt->data.header.dst[5];

			in_pkt->data.header.dst[0] = 254;
			in_pkt->data.header.dst[1] = 253;
			in_pkt->data.header.dst[2] = 2;
			in_pkt->data.header.dst[3] = 0;
			in_pkt->data.header.dst[4] = 0;
			in_pkt->data.header.dst[5] = 1;

			in_pkt->data.header.src[0] = 254;
			in_pkt->data.header.src[1] = 253;
			in_pkt->data.header.src[2] = 3;
			in_pkt->data.header.src[3] = 01;
			in_pkt->data.header.src[4] = 0;
			in_pkt->data.header.src[5] = 2;
			}
			else if(in_pkt->frame.src_interface == 2){
				printf("\n RECEIVED PACKET FROM INTERFACE 2");

				in_pkt->frame.dst_interface = 1;
				in_pkt->data.header.src[0] = in_pkt->data.header.dst[0];
				in_pkt->data.header.src[1] = in_pkt->data.header.dst[1];
				in_pkt->data.header.src[2] = in_pkt->data.header.dst[2];
				in_pkt->data.header.src[3] = in_pkt->data.header.dst[3];
				in_pkt->data.header.src[4] = in_pkt->data.header.dst[4];
				in_pkt->data.header.src[5] = in_pkt->data.header.dst[5];

				in_pkt->data.header.dst[0] = 254;
				in_pkt->data.header.dst[1] = 253;
				in_pkt->data.header.dst[2] = 2;
				in_pkt->data.header.dst[3] = 0;
				in_pkt->data.header.dst[4] = 0;
				in_pkt->data.header.dst[5] = 2;

				in_pkt->data.header.src[0] = 254;
				in_pkt->data.header.src[1] = 253;
				in_pkt->data.header.src[2] = 03;
				in_pkt->data.header.src[3] = 01;
				in_pkt->data.header.src[4] = 0;
				in_pkt->data.header.src[5] = 1;
			}*/

			writeQueue(queue1, (void *)in_pkt, sizeof(gpacket_t));
		}
	}


}
Exemple #5
0
/*
 * TODO: Can we do these without super user permissions?
 */
void* fromTapDev(void *arg)
{
	interface_t *iface = (interface_t *) arg;
	interface_array_t *iarr = (interface_array_t *)iface->iarray;
	uchar bcast_mac[] = MAC_BCAST_ADDR;
	char *pkttag;
	gpacket_t *in_pkt;
	int pktsize;

	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);		// die as soon as cancelled
	while (1)
	{
		verbose(2, "[fromTapDev]:: Receiving a packet ...");
		if ((in_pkt = (gpacket_t *)malloc(sizeof(gpacket_t))) == NULL)
		{
			fatal("[fromTapDev]:: unable to allocate memory for packet.. ");
			return NULL;
		}

		bzero(in_pkt, sizeof(gpacket_t));
		pktsize = tap_recvfrom(iface->vpl_data, &(in_pkt->data), sizeof(pkt_data_t));
		pthread_testcancel();

		// check whether the incoming packet is a layer 2 broadcast or
		// meant for this node... otherwise should be thrown..
		// TODO: fix for promiscuous mode packet snooping.

		if ((COMPARE_MAC(in_pkt->data.header.dst, iface->mac_addr) != 0) &&
			(COMPARE_MAC(in_pkt->data.header.dst, bcast_mac) != 0))
		{
			verbose(1, "[fromTapDev]:: Packet[%d] dropped .. not for this router!? ", pktsize);
			free(in_pkt);
			continue;
		}

		// copy fields into the message from the packet..
		in_pkt->frame.src_interface = iface->interface_id;
		COPY_MAC(in_pkt->frame.src_hw_addr, iface->mac_addr);
		COPY_IP(in_pkt->frame.src_ip_addr, iface->ip_addr);

		// check for filtering.. if the it should be filtered.. then drop
		if (filteredPacket(filter, in_pkt))
		{
			verbose(2, "[fromTapDev]:: Packet filtered..!");
			free(in_pkt);
			continue;   // skip the rest of the loop
		}

		// invoke the packet core classifier to get the packet tag
		// at the very minimum, we get the "default" tag!
		verbose(2, "[fromTapDev]:: Calling the classifier..");
		pkttag = tagPacket(pcore, in_pkt);
		verbose(2, "[fromTapDev]:: Packet tagged as %s ", pkttag);
		if (!strcmp(rconfig.schedpolicy, "rr"))
			roundRobinQueuer(pcore, in_pkt, sizeof(gpacket_t), pkttag);
		else if (!strcmp(rconfig.schedpolicy, "wfq"))
			weightedFairQueuer(pcore, in_pkt, sizeof(gpacket_t), pkttag);
		else
			fatal("[fromTapDev]:: Unknown queuer specification! %s \n", rconfig.schedpolicy);

	}
}
Exemple #6
0
/*
 * TODO: Some form of conformance check so that only packets
 * destined to the particular Ethernet protocol are being captured
 * by the handler... right now.. this might capture other packets as well.
 */
void* fromEthernetDev(void *arg)
{
	interface_t *iface = (interface_t *) arg;
	interface_array_t *iarr = (interface_array_t *)iface->iarray;
	uchar bcast_mac[] = MAC_BCAST_ADDR;

	gpacket_t *in_pkt;

	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);		// die as soon as cancelled
	while (1)
	{
		verbose(2, "[fromEthernetDev]:: Receiving a packet ...");
		if ((in_pkt = (gpacket_t *)malloc(sizeof(gpacket_t))) == NULL)
		{
			fatal("[fromEthernetDev]:: unable to allocate memory for packet.. ");
			return NULL;
		}

		bzero(in_pkt, sizeof(gpacket_t));
		vpl_recvfrom(iface->vpl_data, &(in_pkt->data), sizeof(pkt_data_t));
		pthread_testcancel();


		//FOR OSPF
		/*
		char tmpbuf[MAX_TMPBUF_LEN];
		uchar valMac1[6];
		uchar valMac2[6];
		uchar valMac3[6];
		char *test1 = "33:33:00:00:00:16";
		char *test2 = "33:33:00:00:00:02";
		char *test3 = "33:33:ff:00:00:04";
		Colon2MAC(test1, valMac1);
		Colon2MAC(test2, valMac2);
		Colon2MAC(test3, valMac3);
		if(COMPARE_MAC(in_pkt->data.header.dst, valMac1) == 0 || 
			COMPARE_MAC(in_pkt->data.header.dst, valMac2) == 0|| 
			COMPARE_MAC(in_pkt->data.header.dst, valMac3) == 0){

			uchar link_ip[4];
			COPY_IP(link_ip,  iface->ip_addr);
			link_ip[0] = IP_ZERO_PREFIX;
			printf("Received IPV6 ICMP bcast from : %s \n", IP2Dot(tmpbuf, link_ip));
			//Then we know that this packet comes from a stub network
			//Set stub bit in neighbour table to true
			//printGPacket(in_pkt, 3, "IP_ROUTINE");
			int index = findNeighbourIndex(link_ip);

			if(index == -1)
			{
				// Add to neighbour table
				addNeighbourEntry(iface->ip_addr, link_ip, iface->interface_id);

				// Add to graph
				addStubToGraph(findNeighbourIndex(link_ip));

				updateRoutingTable();
				//printf("BCASTING my new stub neighbour\n");
				//bcast this change
				OSPFSendLSA();
			}

			setStubToTrueFlag(link_ip);
			
			
		}
		*/
		
		// check whether the incoming packet is a layer 2 broadcast or
		// meant for this node... otherwise should be thrown..
		// TODO: fix for promiscuous mode packet snooping.
		if ((COMPARE_MAC(in_pkt->data.header.dst, iface->mac_addr) != 0) &&
			(COMPARE_MAC(in_pkt->data.header.dst, bcast_mac) != 0))
		{
			verbose(1, "[fromEthernetDev]:: Packet dropped .. not for this router!? ");
			free(in_pkt);
			continue;
		}

		// copy fields into the message from the packet..
		in_pkt->frame.src_interface = iface->interface_id;
		COPY_MAC(in_pkt->frame.src_hw_addr, iface->mac_addr);
		COPY_IP(in_pkt->frame.src_ip_addr, iface->ip_addr);

		//calculate Input rate
		if(start == 1){
			counter_in = counter_in+sizeof(gpacket_t);
		}

		// check for filtering.. if the it should be filtered.. then drop
		if (filteredPacket(filter, in_pkt))
		{
			verbose(2, "[fromEthernetDev]:: Packet filtered..!");
			free(in_pkt);
			continue;   // skip the rest of the loop
		}

		verbose(2, "[fromEthernetDev]:: Packet is sent for enqueuing..");
		enqueuePacket(pcore, in_pkt, sizeof(gpacket_t));
	}
}