Example #1
0
/*
 * Separate thread for handling packets asynchronously
 */ 
void *tMain(void *ptr)
{
	while(1) {
		npp_packet *npp = receiveNPPPacket(sock, (struct sockaddr*) &(args.sin));
		if(npp == NULL) {
			continue;
		}
		logFile("New Packet Received", npp);
		switch(npp->priority) {
		
		case 0x01:
			enqueuePacket(q1, m1, &q1_index, npp);
			break;
			
		case 0x02:
			enqueuePacket(q2, m2, &q2_index, npp);
			break;
			
		case 0x03:
			enqueuePacket(q3, m3, &q3_index, npp);
			break;
		}
	}
	exit(0);
}
Example #2
0
  void RtpPacketQueue::pushPacket(const char *data, int length)
  {

    const RTPHeader *header = reinterpret_cast<const RTPHeader*>(data);
    uint16_t nseq = header->getSeqNumber();
    uint32_t ts = header->getTimestamp();

    long long int ltsdiff = (long long int)ts - (long long int)lastTs_;
    int tsdiff = (int)ltsdiff;
    int nseqdiff = nseq - lastNseq_;
    /*
    // nseq sequence cicle test
    if ( abs(nseqdiff) > ( USHRT_MAX - MAX_DIFF ) )
    {
    NOTIFY("Vuelta del NSeq ns=%d last=%d\n", nseq, lastNseq_);
    if (nseqdiff > 0)
    nseqdiff-= (USHRT_MAX + 1);
    else
    nseqdiff+= (USHRT_MAX + 1);
    }
    */

    if (abs(tsdiff) > MAX_DIFF_TS || abs(nseqdiff) > MAX_DIFF )
    {
      // new flow, process and clean queue
      ELOG_DEBUG("Max diff reached, new Flow? nsqediff %d , tsdiff %d", nseqdiff, tsdiff);
      ELOG_DEBUG("PT %d", header->getPayloadType());
      lastNseq_ = nseq;
      lastTs_ = ts;
      cleanQueue();
      enqueuePacket(data, length, nseq);
    }
    else if (nseqdiff > 1)
    {
      // Jump in nseq, enqueue
      ELOG_DEBUG("Jump in nseq");
      enqueuePacket(data, length, nseq);
    }
    else if (nseqdiff == 1)
    {
      // next packet, process
      lastNseq_ = nseq;
      lastTs_ = ts;
      enqueuePacket(data, length, nseq);
    }
    else if (nseqdiff < 0)
    {
      ELOG_DEBUG("Old Packet Received");
      // old packet, discard?
      // stats?
    }
    else if (nseqdiff == 0)
    {
      ELOG_DEBUG("Duplicate Packet received");
      //duplicate packet, process (for stats)?
    }
  }
Example #3
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));
	}
}
Example #4
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));
    }
}
Example #5
0
// -----------------------------------------------------------------------------
// PacketQueue::packetReceived
//
// -----------------------------------------------------------------------------
//
void PacketQueue::packetReceived(const unsigned char *data, int length)
{
    //channel->packetReceived2(data, length);
    //return;

    const RTPHeader *header = reinterpret_cast<const RTPHeader*>(data);
    u16 nseq = header->GetSeqNumber();
    u32 ts = header->GetTimestamp();

    long long int ltsdiff = (long long int)ts - (long long int)lastTs;
    int tsdiff = (int)ltsdiff;
    int nseqdiff = nseq - lastNseq;
/*
    // nseq sequence cicle test
    if ( abs(nseqdiff) > ( USHRT_MAX - MAX_DIFF ) )
    {
        NOTIFY("Vuelta del NSeq ns=%d last=%d\n", nseq, lastNseq);
        if (nseqdiff > 0)
            nseqdiff-= (USHRT_MAX + 1);
        else
            nseqdiff+= (USHRT_MAX + 1);
    }
*/
    if (abs(tsdiff) > MAX_DIFF_TS || abs(nseqdiff) > MAX_DIFF )
    {
        // new flow, process and clean queue
        channel->packetReceived2(data, length);
        lastNseq = nseq;
        lastTs = ts;
        cleanQueue();
    }
    else if (nseqdiff > 1)
    {
        // Jump in nseq, enqueue
        enqueuePacket(data, length, nseq);
        checkQueue();
    }
    else if (nseqdiff == 1)
    {
        // next packet, process
        channel->packetReceived2(data, length);
        lastNseq = nseq;
        lastTs = ts;
        checkQueue();
    }
    else if (nseqdiff < 0)
    {
        // old packet, discard?
        // stats?
    }
    else if (nseqdiff == 0)
    {
        //duplicate packet, process (for stats)?
        //channel->packetReceived2(data, length);
    }
}
ExpandRequest::ExpandRequest( const RequestData& parentOrID,
                              const ExpandRequestData& data )
   
      : SearchResultRequest( parentOrID )
{
   enqueuePacket( updateIDs( new ExpandRequestPacket( data,
                                                      getUser() ) ),
                  MODULE_TYPE_MAP );
   
   m_status = StringTable::TIMEOUT_ERROR;
   m_replyData = new SearchReplyData();
   m_params = new SearchRequestParameters();
}
Example #7
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));
    }
}
void QueuedPacketReceiver::handleTimeout() 
{
   enqueuePacket();
   BufferReceiver::handleTimeout();
}
void QueuedPacketReceiver::handleIO( bool readyRead, bool readyWrite ) 
{
   enqueuePacket();
   BufferReceiver::handleIO( readyRead, readyWrite );
   enqueuePacket();
}
Example #10
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));
	}
}