Ejemplo n.º 1
0
Archivo: gnet.c Proyecto: draringi/gini
void *GNETHandler(void *outq)
{
	char tmpbuf[MAX_NAME_LEN];
	interface_t *iface;
	uchar mac_addr[6];
	simplequeue_t *outputQ = (simplequeue_t *)outq;
	gpacket_t *in_pkt;
	int inbytes, cached;

	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);       // die as soon as cancelled
	while (1)
	{
		verbose(2, "[gnetHandler]:: Reading message from output Queue..");
		if (readQueue(outputQ, (void **)&in_pkt, &inbytes) == EXIT_FAILURE)
			return NULL;
		verbose(2, "[gnetHandler]:: Recvd message pkt ");
		pthread_testcancel();

		if ((iface = findInterface(in_pkt->frame.dst_interface)) == NULL)
		{
			error("[gnetHandler]:: Packet dropped, interface [%d] is invalid ", in_pkt->frame.dst_interface);
			continue;
		} else if (iface->state == INTERFACE_DOWN)
		{
			error("[gnetHandler]:: Packet dropped! Interface not up");
			continue;
		}

		if (!in_pkt->frame.openflow)
		{
			// we have a valid interface handle -- iface.
			COPY_MAC(in_pkt->data.header.src, iface->mac_addr);

			if (in_pkt->frame.arp_valid == TRUE)
				putARPCache(in_pkt->frame.nxth_ip_addr, in_pkt->data.header.dst);
			else if (in_pkt->frame.arp_bcast != TRUE)
			{
				if ((cached = lookupARPCache(in_pkt->frame.nxth_ip_addr,
							     mac_addr)) == TRUE)
					COPY_MAC(in_pkt->data.header.dst, mac_addr);
				else
				{
					ARPResolve(in_pkt);
					continue;
				}
			}
		}

		iface->devdriver->todev((void *)in_pkt);

	}
}
Ejemplo n.º 2
0
/*
 * ARPResolve: this routine is responsible for local ARP resolution.
 * It consults the local ARP cache to determine whether a valid ARP entry
 * is present. If a valid entry is not present, a remote request is sent out
 * and the packet that caused the request is buffered. The buffer is flushed
 * when the reply comes in.
 */
int ARPResolve(gpacket_t *in_pkt)
{
	printf("CONNORS DEBUG: ARPResolve\n");
	uchar mac_addr[6];
	char tmpbuf[MAX_TMPBUF_LEN];
	
	in_pkt->data.header.prot = htons(IP_PROTOCOL);
	// lookup the ARP table for the MAC for next hop
	if (ARPFindEntry(in_pkt->frame.nxth_ip_addr, mac_addr) == EXIT_FAILURE)
	{
		// no ARP match, buffer and send ARP request for next
		verbose(2, "[ARPResolve]:: buffering packet, sending ARP request");
		ARPAddBuffer(in_pkt);
		in_pkt->frame.arp_bcast = TRUE;                        // tell gnet this is bcast to prevent recursive ARP lookup!
		// create a new message for ARP request
		ARPSendRequest(in_pkt);
		return EXIT_SUCCESS;;
	}

	verbose(2, "[ARPResolve]:: sent packet to MAC %s", MAC2Colon(tmpbuf, mac_addr));
	COPY_MAC(in_pkt->data.header.dst, mac_addr);
	in_pkt->frame.arp_valid = TRUE;
	ARPSend2Output(in_pkt);

	return EXIT_SUCCESS;
}
Ejemplo n.º 3
0
Archivo: tap.c Proyecto: sciyoshi/gini
void *toTapDev(void *arg)
{
	gpacket_t *inpkt = (gpacket_t *)arg;
	interface_t *iface;
	arp_packet_t *apkt;
	char tmpbuf[MAX_TMPBUF_LEN];
	int pkt_size;

	verbose(2, "[toTapDev]:: entering the function.. ");
	// find the outgoing interface and device...
	if ((iface = findInterface(inpkt->frame.dst_interface)) != NULL)
	{
		/* send IP packet or ARP reply */
		if (inpkt->data.header.prot == htons(ARP_PROTOCOL))
		{
			apkt = (arp_packet_t *) inpkt->data.data;
			COPY_MAC(apkt->src_hw_addr, iface->mac_addr);
			COPY_IP(apkt->src_ip_addr, gHtonl(tmpbuf, iface->ip_addr));
		}
		pkt_size = findPacketSize(&(inpkt->data));

		verbose(2, "[toTapDev]:: tap_sendto called for interface %d.. ", iface->interface_id);
		tap_sendto(iface->vpl_data, &(inpkt->data), pkt_size);
		free(inpkt);          // finally destroy the memory allocated to the packet..
	} else
		error("[toTapDev]:: ERROR!! Could not find outgoing interface ...");

	// this is just a dummy return -- return value not used.
	return arg;
}
Ejemplo n.º 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)
	{
            //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));
	}
}
Ejemplo n.º 5
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));
    }
}
Ejemplo n.º 6
0
Archivo: gnet.c Proyecto: draringi/gini
void putARPCache(uchar *ip_addr, uchar *mac_addr)
{
	int key;

	key = getARPCacheKey(ip_addr);
	arp_cache[key].is_empty = FALSE;
	COPY_IP(arp_cache[key].ip_addr, ip_addr);
	COPY_MAC(arp_cache[key].mac_addr, mac_addr);
}
Ejemplo n.º 7
0
/*
 * add an entry to the ARP table
 * ARGUMENTS: uchar *ip_addr - the IP address (4 bytes)
 *            uchar *mac_addr - the MAC address (6 bytes)
 * RETURNS: Nothing
 */
void ARPAddEntry(uchar *ip_addr, uchar *mac_addr)
{
	int i;
	int empty_slot = MAX_ARP;
	char tmpbuf[MAX_TMPBUF_LEN];

	for (i = 0; i < MAX_ARP; i++)
	{
		if ((ARPtable[i].is_empty == FALSE) &&
		    (COMPARE_IP(ARPtable[i].ip_addr, ip_addr) == 0))
		{
			// update entry
			COPY_IP(ARPtable[i].ip_addr, ip_addr);
			COPY_MAC(ARPtable[i].mac_addr, mac_addr);

			verbose(2, "[ARPAddEntry]:: updated ARP table entry #%d: IP %s = MAC %s", i,
			       IP2Dot(tmpbuf, ip_addr), MAC2Colon(tmpbuf+20, mac_addr));
			return;
		}
		if (ARPtable[i].is_empty == TRUE)
			empty_slot = i;
	}

	if (empty_slot == MAX_ARP)
	{
		// ARP table full.. do the replacement
		// use the FIFO strategy: table replace index is the FIFO pointer
		empty_slot = tbl_replace_indx;
		tbl_replace_indx = (tbl_replace_indx + 1) % MAX_ARP;
	}

	// add new entry or overwrite the replaced entry
	ARPtable[empty_slot].is_empty = FALSE;
	COPY_IP(ARPtable[empty_slot].ip_addr, ip_addr);
	COPY_MAC(ARPtable[empty_slot].mac_addr, mac_addr);

	verbose(2, "[ARPAddEntry]:: updated ARP table entry #%d: IP %s = MAC %s", empty_slot,
	       IP2Dot(tmpbuf, ip_addr), MAC2Colon(tmpbuf+20, mac_addr));

	return;
}
Ejemplo n.º 8
0
void *toRawDev(void *arg)
{
	gpacket_t *inpkt = (gpacket_t *)arg;
	interface_t *iface;
	arp_packet_t *apkt;
	char tmpbuf[MAX_TMPBUF_LEN];
	int pkt_size;

	verbose(1, "[toRawDev]:: entering the function.. ");
	// find the outgoing interface and device...
	if ((iface = findInterface(inpkt->frame.dst_interface)) != NULL)
	{
		char tmp[40];
		memset(tmp, 0, sizeof(tmp));
		IP2Dot(tmp, inpkt->frame.src_ip_addr);
		/* The Amazon network has the prefix 172, so if a packet is sent to the raw interface and it does
		not begin with that prefix, we know that the packet has come from the local gini network instead.
		In this case we want to apply a SNAT, to make the packet seem as if it has come from the cRouter 
		so that Amazon machines will be able to respond (recognize the address). Note that the reverse
		NAT operation is performed in ip.c*/
		/*if(inpkt->data.header.prot != htons(ARP_PROTOCOL) && !(tmp[0] == '1' && tmp[1] == '7' && tmp[2] == '2')) {
			//printf("\n\n TRYING TO PING AMAZON CLOUD\n");				
			//printGPacket(inpkt, 3, "CONNOR PACKET");
			ip_packet_t *ipkt = (ip_packet_t *)(inpkt->data.data);
			ipkt->ip_hdr_len = 5;                                  // no IP header options!!
			icmphdr_t *icmphdr = (icmphdr_t *)((uchar *)ipkt + ipkt->ip_hdr_len*4);
			printf("\n\nICMP ID: %d\n", icmphdr->un.echo.id); 
			The IP address given to the SNAT function is the private ip address of the 
			Amazon instance that is running the cRouter in reverse 
			applySNAT("62.44.31.172", (ip_packet_t*)inpkt->data.data, icmphdr->un.echo.id);
			printNAT();	
		}*/
		/* send IP packet or ARP reply */
		if (inpkt->data.header.prot == htons(ARP_PROTOCOL))
		{
			printf("CONNORS DEBUG arp in toRawDev\n");
			apkt = (arp_packet_t *) inpkt->data.data;
			COPY_MAC(apkt->src_hw_addr, iface->mac_addr);
			COPY_IP(apkt->src_ip_addr, gHtonl(tmpbuf, iface->ip_addr));
		}
		if(inpkt->data.header.prot == htons(ICMP_PROTOCOL)){
			printf("\nICMP Request over raw\n");
		}		
		pkt_size = findPacketSize(&(inpkt->data));
		verbose(2, "[toRawDev]:: raw_sendto called for interface %d.. ", iface->interface_id);
		raw_sendto(iface->vpl_data, &(inpkt->data), pkt_size);
		free(inpkt);          // finally destroy the memory allocated to the packet..
	} else
		error("[toRawDev]:: ERROR!! Could not find outgoing interface ...");

	// this is just a dummy return -- return value not used.
	return arg;
}
Ejemplo n.º 9
0
/*
 * send an ARP request to eventually process message,
 * a copy of which is now in the buffer
 */
void ARPSendRequest(gpacket_t *pkt)
{
	arp_packet_t *apkt = (arp_packet_t *) pkt->data.data;
	uchar bcast_addr[6];
	char tmpbuf[MAX_TMPBUF_LEN];

	memset(bcast_addr, 0xFF, 6);

	/*
	 * Create ARP REQUEST packet
	 * ether header will be set in GNET_ADAPTER
	 * arp header
	 */
	apkt->hw_addr_type = htons(ETHERNET_PROTOCOL);      // set hw type
	apkt->arp_prot = htons(IP_PROTOCOL);                // set prtotocol address format

	apkt->hw_addr_len = 6;                              // address length
	apkt->arp_prot_len = 4;                             // protocol address length
	apkt->arp_opcode = htons(ARP_REQUEST);              // set ARP request opcode

	// source hw addr will be set in GNET_ADAPTER
	// source ip addr will be set in GNET_ADAPTER
	COPY_MAC(apkt->dst_hw_addr, bcast_addr);            // target hw addr

	COPY_IP(apkt->dst_ip_addr, gHtonl((uchar *)tmpbuf, pkt->frame.nxth_ip_addr));    // target ip addr

	// send the ARP request packet
	verbose(2, "[sendARPRequest]:: sending ARP request for %s",
		IP2Dot(tmpbuf, pkt->frame.nxth_ip_addr));

	// prepare sending.. to GNET adapter..

	COPY_MAC(pkt->data.header.dst, bcast_addr);
	pkt->data.header.prot = htons(ARP_PROTOCOL);
	// actually send the message to the other module..
	ARPSend2Output(pkt);

	return;
}
Ejemplo n.º 10
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));
    }
}
Ejemplo n.º 11
0
Archivo: gnet.c Proyecto: draringi/gini
/*
 * lookup the given ip_addr in the ARP cache.
 * copy the MAC address in mac_addr and return TRUE
 * otherwise return FALSE -- mac_addr is undefined in this case.
 */
int lookupARPCache(uchar *ip_addr, uchar *mac_addr)
{
	int key;

	key = getARPCacheKey(ip_addr);
	if ((arp_cache[key].is_empty == FALSE) &&
	    (COMPARE_IP(arp_cache[key].ip_addr, ip_addr) == 0))
	{
		COPY_MAC(mac_addr, arp_cache[key].mac_addr);
		return TRUE;
	}

	return FALSE;
}
Ejemplo n.º 12
0
/*
 * Find an ARP entry matching the supplied IP address in the ARP table
 * ARGUMENTS: uchar *ip_addr: IP address to look up
 *            uchar *mac_addr: returned MAC address corresponding to the IP
 * The MAC is only set when the return status is EXIT_SUCCESS. If error,
 * the MAC address (mac_addr) is undefined.
 */
int ARPFindEntry(uchar *ip_addr, uchar *mac_addr)
{
	int i;
	char tmpbuf[MAX_TMPBUF_LEN];

	for (i = 0; i < MAX_ARP; i++)
	{
		if(ARPtable[i].is_empty == FALSE &&
		   COMPARE_IP(ARPtable[i].ip_addr, ip_addr) == 0)
		{
			// found IP address - copy the MAC address
			COPY_MAC(mac_addr, ARPtable[i].mac_addr);
			verbose(2, "[ARPFindEntry]:: found ARP entry #%d for IP %s", i, IP2Dot(tmpbuf, ip_addr));
			return EXIT_SUCCESS;
		}
	}

	verbose(2, "[ARPFindEntry]:: failed to find ARP entry for IP %s", IP2Dot(tmpbuf, ip_addr));
	return EXIT_FAILURE;
}
Ejemplo n.º 13
0
/*
 * flush all packets from buffer matching the nexthop
 * for which we now have an ARP entry
 */
void ARPFlushBuffer(char *next_hop, char *mac_addr)
{
	gpacket_t *bfrd_msg;
	char tmpbuf[MAX_TMPBUF_LEN];

	verbose(2, "[ARPFlushBuffer]:: Entering the function.. ");
	while (ARPGetBuffer(&bfrd_msg, next_hop) == EXIT_SUCCESS)
	{
		// a message is already buffered.. send it out..
		// TODO: include QoS routines.. for now they are removed!

		// send to gnetAdapter
		// no need to set dst_int_num -- why?

		verbose(2, "[ARPFlushBuffer]:: flushing the entry with next_hop %s ", IP2Dot(tmpbuf, next_hop));
		COPY_MAC(bfrd_msg->data.header.dst, mac_addr);
		ARPSend2Output(bfrd_msg);
	}

	return;
}
Ejemplo n.º 14
0
void *toEthernetDev(void *arg)
{
        gpacket_t *inpkt = (gpacket_t *)arg;
	interface_t *iface;
	arp_packet_t *apkt;
        //ospf_packet_t *ospkt;
	char tmpbuf[MAX_TMPBUF_LEN];
	int pkt_size;

	verbose(2, "[toEthernetDev]:: entering the function.. ");
	// find the outgoing interface and device...
        if ((iface = findInterface(inpkt->frame.dst_interface)) != NULL)
	{
            /* send IP packet, ARP reply, or OSPF packet */
            if (inpkt->data.header.prot == htons(ARP_PROTOCOL)){
			apkt = (arp_packet_t *) inpkt->data.data;
			COPY_MAC(apkt->src_hw_addr, iface->mac_addr);
			COPY_IP(apkt->src_ip_addr, gHtonl(tmpbuf, iface->ip_addr));
            }
            else if (inpkt->data.header.prot == htons(IP_PROTOCOL))
	    {
                ip_packet_t *ip_pkt = (ip_packet_t *)inpkt->data.data;
                if(ip_pkt->ip_prot == OSPF_PROTOCOL){
                
                }
                //RECHECK determine if you're putting MAC address
                //into the right place
	    }
                pkt_size = findPacketSize(&(inpkt->data));
		verbose(2, "[toEthernetDev]:: vpl_sendto called for interface %d..%d bytes written ", iface->interface_id, pkt_size);
		int x = vpl_sendto(iface->vpl_data, &(inpkt->data), pkt_size);
                free(inpkt);          // finally destroy the memory allocated to the packet..
	} else{
            error("[toEthernetDev]:: ERROR!! Could not find outgoing interface ...");
        }
	// this is just a dummy return -- return value not used.
	return arg;
}
Ejemplo n.º 15
0
Archivo: gnet.c Proyecto: draringi/gini
/*
 * Create an interface data structure and fill it with relevant information.
 * This routine does not setup any external elements.. other than finding
 * the device driver and linking it. We need the correct device driver for
 * the interface.. because a particular device would provide its own I/O routines.
 */
interface_t *newInterfaceStructure(char *vsock_name, char *device,
				   uchar *mac_addr, uchar *nw_addr, int iface_mtu)
{
	int iface_id;
	interface_t *iface;


	iface_id = gAtoi(device);

	// fill in the interface structure...
	iface = (interface_t *) malloc(sizeof(interface_t));
	if (iface == NULL)
	{
		fatal("[createInterfaceStructure]:: Memory allocation error ");
		return NULL;
	}

	verbose(2, "[createInterfaceStructure]:: Memory allocated for interface structure ");

	bzero((void *)iface, sizeof(interface_t));
	iface->interface_id = iface_id;
	iface->mode = IFACE_CLIENT_MODE;
	iface->state = INTERFACE_DOWN;                           // start in the DOWN state
	sscanf(device, "%[a-z]", iface->device_type);
	strcpy(iface->device_name, device);
	strcpy(iface->sock_name, vsock_name);
	COPY_MAC(iface->mac_addr, mac_addr);
	COPY_IP(iface->ip_addr, nw_addr);
	iface->device_mtu = iface_mtu;

	verbose(2, "[makeInterface]:: Searching the device driver for %s ", iface->device_type);
	iface->devdriver = findDeviceDriver(iface->device_type);
	iface->iarray = &netarray;

	return iface;
}
Ejemplo n.º 16
0
vpl_data_t *raw_connect(uchar* mac_addr)
{
    struct sockaddr_ll sll;
    struct ifreq* ifr;
    int sock_raw;
    char interface[10];
    vpl_data_t *pri;
    
    verbose(2, "[raw_connect]:: starting connection.. ");
    
    sock_raw = socket( AF_PACKET , SOCK_RAW , htons(ETH_P_ALL)) ;	
    if (sock_raw == -1) {
        verbose(2, "[raw_connect]:: Creating raw socket failed, error = %s", strerror(errno));
        free(ifr);
        return NULL;
    }
    
    //interface[0] = 't';
    //sprintf(&interface[1], "%d", rconfig.top_num); 
    //Above is from Ahmeds implementation
    //For the cloud we want to use the eth0
    //interface on the amazon machine for the raw socket
    strcpy(interface, "eth0");
    verbose(1, "[raw_connect]:: Binding to interface %s strlen = %d", interface, strlen(interface));
    ifr = calloc(1, sizeof(struct ifreq));
    strcpy((char*)ifr->ifr_name, interface);
            
    if((ioctl(sock_raw, SIOCGIFINDEX, ifr)) == -1)
    {
    	verbose(2, "[raw_connect]:: Unable to find interface index, error = %s", strerror(errno));
        free(ifr);
    	return NULL;
    }
    
    bzero(&sll, sizeof(sll));
    sll.sll_family = AF_PACKET;
    sll.sll_ifindex = ifr->ifr_ifindex;
    sll.sll_protocol = htons(ETH_P_ALL);
    
    verbose(2, "[raw_connect]:: ifr_index = %d", ifr->ifr_ifindex);
    if((bind(sock_raw, (struct sockaddr*) &sll, sizeof(sll))) == -1)
    {
        verbose(2, "[raw_connect]:: Binding raw Socket Failed, error = %s", strerror(errno));
        free(ifr);
        return NULL;
    }
    
    if((ioctl(sock_raw, SIOCGIFHWADDR, ifr)) == -1)
    {
    	verbose(2, "[raw_connect]:: Unable to find interface mac address, error = %s", strerror(errno));	
        free(ifr);
    	return NULL;
    }
    COPY_MAC(mac_addr, ifr->ifr_hwaddr.sa_data);
    
    pri = (vpl_data_t *)malloc(sizeof(vpl_data_t));
    bzero(pri, sizeof(sizeof(vpl_data_t))); 
    
    // initialize the vpl_data structure.. much of it is unused here.
    // we are reusing vpl_data_t to minimize the changes for other code.
    pri->sock_type = "raw";
    pri->ctl_sock = NULL;
    pri->ctl_addr = NULL;
    pri->data_addr = NULL;
    pri->control = -1;
    pri->data = sock_raw;
    pri->local_addr = (void*)ifr;

    return pri;
}
Ejemplo n.º 17
0
/*
 * ARPProcess: Process a received ARP packet... from remote nodes. If it is
 * a reply for a ARP request sent from the local node, use it
 * to update the local ARP cache. Flush (dequeue, process, and send) any packets
 * that are buffered for ARP processing that match the ARP reply.

 * If it a request, send a reply.. no need to record any state here.
 */
void ARPProcess(gpacket_t *pkt)
{
	char tmpbuf[MAX_TMPBUF_LEN];

	arp_packet_t *apkt = (arp_packet_t *) pkt->data.data;

	// check packet is ethernet and addresses of IP type.. otherwise throw away
	if ((ntohs(apkt->hw_addr_type) != ETHERNET_PROTOCOL) || (ntohs(apkt->arp_prot) != IP_PROTOCOL))
	{
		verbose(2, "[ARPProcess]:: unknown hwtype or protocol, dropping ARP packet");
		return;
	}


	verbose(2, "[ARPProcess]:: adding sender of received packet to ARP table");
	ARPAddEntry(gNtohl((uchar *)tmpbuf, apkt->src_ip_addr), apkt->src_hw_addr);

	// Check it's actually destined to us,if not throw packet
	if (COMPARE_IP(apkt->dst_ip_addr, gHtonl((uchar *)tmpbuf, pkt->frame.src_ip_addr)) != 0)
	{
		verbose(2, "[APRProcess]:: packet has a frame source (after ntohl) %s ...",
		       IP2Dot(tmpbuf, gNtohl((uchar *)tmpbuf, pkt->frame.src_ip_addr)));

		verbose(2, "[APRProcess]:: packet destined for %s, dropping",
		       IP2Dot(tmpbuf, gNtohl((uchar *)tmpbuf, apkt->dst_ip_addr)));
		return;
	}

	// We have a valid ARP packet, lets process it now.
	// If it's a REQUEST, send a reply back
	if (ntohs(apkt->arp_opcode) == ARP_REQUEST)
	{
		apkt->arp_opcode = htons(ARP_REPLY);
		COPY_MAC(apkt->src_hw_addr, pkt->frame.src_hw_addr);
		COPY_MAC(apkt->dst_hw_addr, pkt->data.header.src);
		COPY_IP(apkt->dst_ip_addr, apkt->src_ip_addr);
		COPY_IP(apkt->src_ip_addr, gHtonl((uchar *)tmpbuf, pkt->frame.src_ip_addr));

		verbose(2, "[ARPProcess]:: packet was ARP REQUEST, sending ARP REPLY packet");

		// prepare for sending. Set some parameters that is going to be used
		// by the GNET adapter...

		pkt->frame.dst_interface = pkt->frame.src_interface;

		COPY_MAC(pkt->data.header.dst, pkt->data.header.src);
		COPY_MAC(pkt->data.header.src,  pkt->frame.src_hw_addr);
		COPY_IP(pkt->frame.nxth_ip_addr, gNtohl((uchar *)tmpbuf, apkt->dst_ip_addr));
		pkt->frame.arp_valid = TRUE;

		pkt->data.header.prot = htons(ARP_PROTOCOL);

		ARPSend2Output(pkt);
	}
	else if (ntohs(apkt->arp_opcode) == ARP_REPLY)
	{
		// Flush buffer of any packets waiting for the incoming ARP..
		verbose(2, "[ARPProcess]:: packet was ARP REPLY... ");
		ARPFlushBuffer(gNtohl((uchar *)tmpbuf, apkt->src_ip_addr), apkt->src_hw_addr);
		verbose(2, "[ARPProcess]:: flushed the ARP buffer ... ");
	}
	else
		verbose(2, "[ARPProcess]:: unknown ARP type");

	return;
}
Ejemplo n.º 18
0
VOID GenerateRelatedMAC (MACADDR dest, const MACADDR src, const int delta)
{
  COPY_MAC (dest, src);
  dest[2] += (UCHAR) delta;
}
Ejemplo n.º 19
0
Archivo: tap.c Proyecto: sciyoshi/gini
/*
 * 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);

	}
}
Ejemplo n.º 20
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));
		}
	}


}
Ejemplo n.º 21
0
void *toEthernetDev(void *arg)
{

	gpacket_t *inpkt = (gpacket_t *)arg;
	interface_t *iface;
	arp_packet_t *apkt;
	char tmpbuf[MAX_TMPBUF_LEN];
	int pkt_size;

	verbose(2, "[toEthernetDev]:: entering the function.. ");
	// find the outgoing interface and device...
	if ((iface = findInterface(inpkt->frame.dst_interface)) != NULL)
	{
		/* send IP packet or ARP reply */
		if (inpkt->data.header.prot == htons(ARP_PROTOCOL))
		{
			apkt = (arp_packet_t *) inpkt->data.data;
			COPY_MAC(apkt->src_hw_addr, iface->mac_addr);
			COPY_IP(apkt->src_ip_addr, gHtonl(tmpbuf, iface->ip_addr));
		}


		pkt_size = findPacketSize(&(inpkt->data));



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

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


			printf("\nProtocol is : %d",inpkt->data.header.prot);
			printf("\nDestination Interface is : %d",inpkt->frame.dst_interface);
			printf("\nARP BDST : %d",inpkt->frame.arp_bcast);
			printf("\narp_valid : %d",inpkt->frame.arp_valid);
			printf("\nSource Hardware Address: %d.%d.%d.%d.%d.%d", inpkt->frame.src_hw_addr[0],
					inpkt->frame.src_hw_addr[1],inpkt->frame.src_hw_addr[2],
					inpkt->frame.src_hw_addr[3],inpkt->frame.src_hw_addr[4],inpkt->frame.src_hw_addr[5]);


			printf("\nIngress Port is : %d",inpkt->frame.src_interface);
			printf("\nNXTH IP Destination: %d.%d.%d.%d", inpkt->frame.nxth_ip_addr[0],inpkt->frame.nxth_ip_addr[1],
					inpkt->frame.nxth_ip_addr[2],inpkt->frame.nxth_ip_addr[3]);

			printf("\n --- IP PACKET:");
			ip_packet_t *ip_pkt;
			ip_pkt = (ip_packet_t *) inpkt->data.data;

			printf("\Destination MAC Address: %x : %x : %x : %x : %x : %x", inpkt->data.header.dst[0], inpkt->data.header.dst[1],
					inpkt->data.header.dst[2],
					inpkt->data.header.dst[3],inpkt->data.header.dst[4],inpkt->data.header.dst[5]);
			printf("\Source MAC Address: %x : %x : %x : %x : %x : %x", inpkt->data.header.src[0],
					inpkt->data.header.src[1],inpkt->data.header.src[2],
					inpkt->data.header.src[3],inpkt->data.header.src[4],inpkt->data.header.src[5]);
			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);
			printf("\nip_cksum: %d\n",ip_pkt->ip_cksum);
			printf("\nip_frag_off: %d\n",ip_pkt->ip_frag_off);
			printf("\nip_hdr_len: %d\n",ip_pkt->ip_hdr_len);
			printf("\nip_identifier: %d\n",ip_pkt->ip_identifier);
			printf("\nip_pkt_len: %d\n",ip_pkt->ip_pkt_len);
			printf("\nip_ttl: %d\n",ip_pkt->ip_ttl);
			printf("\nip_version: %d\n",ip_pkt->ip_version);*/



		verbose(2, "[toEthernetDev]:: vpl_sendto called for interface %d..%d bytes written ", iface->interface_id, pkt_size);
		vpl_sendto(iface->vpl_data, &(inpkt->data), pkt_size);

		free(inpkt);          // finally destroy the memory allocated to the packet..
	} else
		error("[toEthernetDev]:: ERROR!! Could not find outgoing interface ...");


	// this is just a dummy return -- return value not used.
	return arg;
}
Ejemplo n.º 22
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));
	}
}