void *worker_thread(void *dummyPtr) { struct processor *me = NULL; struct packet *thispacket = NULL; struct session *thissession = NULL; struct iphdr *iph = NULL; struct tcphdr *tcph = NULL; __u32 largerIP, smallerIP; __u16 largerIPPort, smallerIPPort; char *remoteID = NULL; char message[LOGSZ]; qlz_state_compress *state_compress = (qlz_state_compress *) malloc( sizeof(qlz_state_compress)); qlz_state_decompress *state_decompress = (qlz_state_decompress *) malloc( sizeof(qlz_state_decompress)); me = (struct processor*) dummyPtr; me->lzbuffer = calloc(1, BUFSIZE + 400); /* Sharwan J: QuickLZ buffer needs (original data size + 400 bytes) buffer */ if (me->lzbuffer == NULL) { sprintf(message, "Worker: Couldn't allocate buffer"); logger(LOG_INFO, message); exit(1); } /* * Register the worker threads metrics so they get updated. */ register_counter(counter_updateworkermetrics, (t_counterdata) & me->metrics); if (me->lzbuffer != NULL) { while (me->state >= STOPPING) { thispacket = dequeue_packet(&me->queue, true); if (thispacket != NULL) { // If a packet was taken from the queue. iph = (struct iphdr *) thispacket->data; tcph = (struct tcphdr *) (((u_int32_t *) iph) + iph->ihl); if (DEBUG_WORKER == true) { sprintf(message, "Worker: IP Packet length is: %u\n", ntohs(iph->tot_len)); logger(LOG_INFO, message); } me->metrics.bytesin += ntohs(iph->tot_len); //remoteID = (__u32) __get_tcp_option((__u8 *)iph,30);/* Check what IP address is larger. */ remoteID = get_nod_header_data((__u8 *)iph, ONOP).data; sort_sockets(&largerIP, &largerIPPort, &smallerIP, &smallerIPPort, iph->saddr,tcph->source,iph->daddr,tcph->dest); if (DEBUG_WORKER == true) { sprintf(message, "Worker: Searching for session.\n"); logger(LOG_INFO, message); } thissession = getsession(largerIP, largerIPPort, smallerIP,smallerIPPort); if (thissession != NULL) { if (DEBUG_WORKER == true) { sprintf(message, "Worker: Found a session.\n"); logger(LOG_INFO, message); } if ((tcph->syn == 0) && (tcph->ack == 1) && (tcph->fin == 0)) { if ((remoteID == NULL) || verify_neighbor_in_domain(remoteID) == false) { /* * An accelerator ID was NOT found. * This is the first accelerator in the traffic path. * This will soon be tested against a list of opennop neighbors. * Traffic is sent through the optimize functions. */ saveacceleratorid(largerIP, (char*)get_opennop_id(), iph, thissession); //binary_dump("worker.c IP Packet: ", (char*)iph, ntohs(iph->tot_len)); //__set_tcp_option((__u8 *)iph,30,6,localID); // Add the Accelerator ID to this packet. set_nod_header_data((__u8 *)iph, ONOP, get_opennop_id(), OPENNOP_IPC_ID_LENGTH); //binary_dump("worker.c IP Packet: ", (char*)iph, ntohs(iph->tot_len)); if ((((iph->saddr == largerIP) && //(thissession->larger.accelerator == localID) && (compare_opennopid((char*)&thissession->larger.accelerator, (char*)get_opennop_id()) == 1) && //(thissession->smaller.accelerator != 0) && (check_opennopid((char*)&thissession->smaller.accelerator) == 1) && //(thissession->smaller.accelerator != localID)) || (compare_opennopid((char*)&thissession->smaller.accelerator, (char*)get_opennop_id()) != 1)) || ((iph->saddr == smallerIP) && //(thissession->smaller.accelerator == localID) && (compare_opennopid((char*)&thissession->smaller.accelerator, (char*)get_opennop_id()) == 1) && //(thissession->larger.accelerator != 0) && (check_opennopid((char*)&thissession->larger.accelerator) == 1) && //(thissession->larger.accelerator != localID))) && (compare_opennopid((char*)&thissession->larger.accelerator, (char*)get_opennop_id()) != 1))) && (thissession->state == TCP_ESTABLISHED)) { /* * Do some acceleration! */ if (DEBUG_WORKER == true) { sprintf(message, "Worker: Compressing packet.\n"); logger(LOG_INFO, message); } updateseq(largerIP, iph, tcph, thissession); tcp_compress((__u8 *)iph, me->lzbuffer,state_compress); } else { updateseq(largerIP, iph, tcph, thissession); if (DEBUG_WORKER == true) { sprintf(message, "Worker: Not compressing packet.\n"); logger(LOG_INFO, message); } } /* * End of what should be the optimize function. */ } else if(verify_neighbor_in_domain(remoteID) == true) { /* * An accelerator ID WAS found. * Traffic is sent through the de-optimize functions. */ saveacceleratorid(largerIP, remoteID, iph, thissession); if (__get_tcp_option((__u8 *)iph,31) != 0) { // Packet is flagged as compressed. if (DEBUG_WORKER == true) { sprintf(message, "Worker: Packet is compressed.\n"); logger(LOG_INFO, message); } if (((iph->saddr == largerIP) && //(thissession->smaller.accelerator == localID)) || (compare_opennopid((char*)&thissession->smaller.accelerator, (char*)get_opennop_id()) == 1))|| ((iph->saddr == smallerIP) && //(thissession->larger.accelerator == localID))) { (compare_opennopid((char*)&thissession->larger.accelerator, (char*)get_opennop_id()) == 1))) { /* * Decompress this packet! */ if (tcp_decompress((__u8 *)iph, me->lzbuffer, state_decompress) == 0) { // Decompression failed if 0. nfq_set_verdict(thispacket->hq, thispacket->id, NF_DROP, 0, NULL); // Decompression failed drop. put_freepacket_buffer(thispacket); thispacket = NULL; }else{ updateseq(largerIP, iph, tcph, thissession); // Only update the sequence after decompression. } } }else{ updateseq(largerIP, iph, tcph, thissession); // Also update sequences if packet is not optimized. } /* * End of what should be the deoptimize function. */ } } if (tcph->rst == 1) { // Session was reset. if (DEBUG_WORKER == true) { sprintf(message, "Worker: Session was reset.\n"); logger(LOG_INFO, message); } thissession = clearsession(thissession); } /* Normal session closing sequence. */ if (tcph->fin == 1) { thissession = closingsession(tcph, thissession); } if (thispacket != NULL) { /* * Changing anything requires the IP and TCP * checksum to need recalculated. */ checksum(thispacket->data); me->metrics.bytesout += ntohs(iph->tot_len); nfq_set_verdict(thispacket->hq, thispacket->id, NF_ACCEPT, ntohs(iph->tot_len), (unsigned char *)thispacket->data); put_freepacket_buffer(thispacket); thispacket = NULL; } } /* End NULL session check. */ else { /* Session was NULL. */ me->metrics.bytesout += ntohs(iph->tot_len); nfq_set_verdict(thispacket->hq, thispacket->id, NF_ACCEPT, 0, NULL); put_freepacket_buffer(thispacket); thispacket = NULL; } me->metrics.packets++; } /* End NULL packet check. */ } /* End working loop. */ free(me->lzbuffer); free(state_compress); free(state_decompress); me->lzbuffer = NULL; } return NULL; }
int counters_sys_init(void) { counter_jiffies_desc = register_counter(COUNTER_TYPE_64_BIT, "jiffies"); return counter_jiffies_desc; }