Commit a2c52531 authored by 's avatar
Browse files

fixes for cooking


git-svn-id: file:///home/svn/mapi/trunk@241 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent ead96908
...@@ -16,7 +16,7 @@ WITH_DAG=0 ...@@ -16,7 +16,7 @@ WITH_DAG=0
WITH_COMBO6=0 WITH_COMBO6=0
#Distributed MAPI functionality #Distributed MAPI functionality
WITH_DIMAPI=0 WITH_DIMAPI=1
#MAPI function statistics #MAPI function statistics
#With this pkt counters for each function is enabled #With this pkt counters for each function is enabled
...@@ -27,7 +27,7 @@ WITH_PRIORITIES=0 ...@@ -27,7 +27,7 @@ WITH_PRIORITIES=0
PRIORITIES=3 PRIORITIES=3
#Support for functions that modifies packets #Support for functions that modifies packets
WITH_MODIFY_PKTS=0 WITH_MODIFY_PKTS=1
#Support for anonymization #Support for anonymization
......
...@@ -774,6 +774,32 @@ mapid_get_lib_name(int libnumber) ...@@ -774,6 +774,32 @@ mapid_get_lib_name(int libnumber)
#ifdef WITH_MODIFY_PKTS #ifdef WITH_MODIFY_PKTS
#define NIC_PKTCAP_LEN 1514 #define NIC_PKTCAP_LEN 1514
unsigned char modified_packet_buf[NIC_PKTCAP_LEN]; unsigned char modified_packet_buf[NIC_PKTCAP_LEN];
struct headers_data {
unsigned char *header;
int header_len;
unsigned int caplen;
unsigned int wlen;
struct timeval ts;
void *decoded_pkt;
};
void free_header_list(flist_t *list,int method) {
flist_node_t *node=flist_head(list),*node2;
while(node) {
struct headers_data *data=flist_data(node);
node2=flist_next(node);
if(method==FLIST_FREE_DATA) {
free(data->header);
free(data);
}
free(node);
node=node2;
}
}
#endif #endif
void mapid_process_pkt(mapidlib_instance_t *i, void mapid_process_pkt(mapidlib_instance_t *i,
...@@ -813,24 +839,24 @@ void mapid_process_pkt(mapidlib_instance_t *i, ...@@ -813,24 +839,24 @@ void mapid_process_pkt(mapidlib_instance_t *i,
// n = flist_head(i->flowlist); // n = flist_head(i->flowlist);
#ifdef WITH_PRIORITIES #ifdef WITH_PRIORITIES
int j = 0; int j = 0;
printf("========================================================================================\n"); printf("========================================================================================\n");
for(j = 0; j < PRIORITIES; j++) for(j = 0; j < PRIORITIES; j++) {
{ n = flist_head(i->flowlist[j]);
n = flist_head(i->flowlist[j]);
#else #else
n = flist_head(i->flowlist); n = flist_head(i->flowlist);
#endif #endif
while (n) while (n) {
{
flow=flist_data(n); flow=flist_data(n);
#ifdef WITH_PRIORITIES #ifdef WITH_PRIORITIES
printf("Running on flow %d with priority %d\n", flow->fd, flow->priority); printf("Running on flow %d with priority %d\n", flow->fd, flow->priority);
#endif #endif
if(flow->status==FLOW_ACTIVE) { if(flow->status==FLOW_ACTIVE) {
#ifdef WITH_MODIFY_PKTS #ifdef WITH_MODIFY_PKTS
flow->decoded_packet=NULL; flow->decoded_packet=NULL;
flow->client_headers=NULL; flow->client_headers=NULL;
...@@ -851,54 +877,73 @@ printf("======================================================================== ...@@ -851,54 +877,73 @@ printf("========================================================================
} }
} }
#endif #endif
n2=flist_head(flow->procfunctionlist);
ret=1; n2=flist_head(flow->procfunctionlist);
while (n2 && ret && flow->status==FLOW_ACTIVE) { ret=1;
funct = flist_data(n2); while (n2 && ret && flow->status==FLOW_ACTIVE) {
funct = flist_data(n2);
#ifdef WITH_MODIFY_PKTS #ifdef WITH_MODIFY_PKTS
if(flow->modifies==1) if(flow->modifies==1)
ret=funct->def->process(funct,dev_pkt,flow->mod_pkt,&flow->mod_pkt_head); ret=funct->def->process(funct,dev_pkt,flow->mod_pkt,&flow->mod_pkt_head);
else else
ret=funct->def->process(funct,dev_pkt,link_pkt,pkt_head); ret=funct->def->process(funct,dev_pkt,link_pkt,pkt_head);
#else #else
ret=funct->def->process(funct,dev_pkt,link_pkt,pkt_head); ret=funct->def->process(funct,dev_pkt,link_pkt,pkt_head);
#endif #endif
#ifdef WITH_FUNCT_STATS #ifdef WITH_FUNCT_STATS
funct->pkts++; funct->pkts++;
if(ret) if(ret)
funct->processed_pkts++; funct->processed_pkts++;
#endif #endif
n2 = flist_next(n2); n2 = flist_next(n2);
} }
} else if(flow->delete==1) {
struct mapidlibflow *f;
// n = flist_next(n);
DEBUG_CMD(printf("Deleting flow %d [%s:%d]\n",flow->fd,__FILE__,__LINE__)); #ifdef WITH_MODIFY_PKTS
if(flow->client_headers) {
free_header_list(flow->client_headers,FLIST_FREE_DATA);
flist_init(flow->client_headers);
}
if(flow->server_headers) {
free_header_list(flow->server_headers,FLIST_FREE_DATA);
flist_init(flow->server_headers);
}
#endif
} //if(flow->status==FLOW_ACTIVE)
else if(flow->delete==1) {
struct mapidlibflow *f;
// n = flist_next(n);
DEBUG_CMD(printf("Deleting flow %d [%s:%d]\n",flow->fd,__FILE__,__LINE__));
pthread_spin_lock(&i->flowlist_lock); pthread_spin_lock(&i->flowlist_lock);
#ifdef WITH_PRIORITIES #ifdef WITH_PRIORITIES
f=flist_priorities_get(i->flowlist,flow->fd); f=flist_priorities_get(i->flowlist,flow->fd);
#else #else
f=flist_get(i->flowlist,flow->fd); f=flist_get(i->flowlist,flow->fd);
#endif #endif
// f=flist_get(i->flowlist,flow->fd); // f=flist_get(i->flowlist,flow->fd);
//TODO: Flow is still stored in flowlist for historical reference but //TODO: Flow is still stored in flowlist for historical reference but
//should be removed from the flowlist when number of closed flows reach //should be removed from the flowlist when number of closed flows reach
//a configurable limit. //a configurable limit.
free_functionlist(f); free_functionlist(f);
free_sharedmem(f); free_sharedmem(f);
f->delete=2; f->delete=2;
pthread_spin_unlock(&i->flowlist_lock); pthread_spin_unlock(&i->flowlist_lock);
} }
n = flist_next(n); n = flist_next(n);
} }
#ifdef WITH_PRIORITIES #ifdef WITH_PRIORITIES
} }
#endif #endif
} }
......
...@@ -710,7 +710,7 @@ ip_defrag_stub(struct ip *iph, struct ip **defrag,int id) ...@@ -710,7 +710,7 @@ ip_defrag_stub(struct ip *iph, struct ip **defrag,int id)
timenow = 0; timenow = 0;
while (timer_head[id] && timer_head[id]->expires < jiffies()) { while (timer_head[id] && timer_head[id]->expires < jiffies()) {
this_host[id] = ((struct ipq *) (timer_head[id]->data))->hf; this_host[id] = ((struct ipq *) (timer_head[id]->data))->hf;
timer_head[id]->function(timer_head[id]->data); timer_head[id]->function(timer_head[id]->data,id);
} }
offset = ntohs(iph->ip_off); offset = ntohs(iph->ip_off);
flags = offset & ~IP_OFFSET; flags = offset & ~IP_OFFSET;
......
No preview for this file type
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
int main(MAPI_UNUSED int argc, char *argv[]) int main(MAPI_UNUSED int argc, char *argv[])
{ {
int fd,fid,*cnt; int fd,fid,fid2,*cnt,*cnt2;
if(!argv[1]) if(!argv[1])
{ {
...@@ -20,10 +20,11 @@ int main(MAPI_UNUSED int argc, char *argv[]) ...@@ -20,10 +20,11 @@ int main(MAPI_UNUSED int argc, char *argv[])
return -1; return -1;
} }
fd=mapi_create_flow(argv[1]); fd=mapi_create_offline_flow(argv[1],MFF_PCAP);
mapi_apply_function(fd,"COOKING",100000,10);
fid=mapi_apply_function(fd,"PKT_COUNTER"); fid=mapi_apply_function(fd,"PKT_COUNTER");
mapi_apply_function(fd,"COOKING",100000,10);
fid2=mapi_apply_function(fd,"PKT_COUNTER");
mapi_connect(fd); mapi_connect(fd);
...@@ -31,7 +32,8 @@ int main(MAPI_UNUSED int argc, char *argv[]) ...@@ -31,7 +32,8 @@ int main(MAPI_UNUSED int argc, char *argv[])
{ {
sleep(1); sleep(1);
cnt = mapi_read_results(fd,fid,MAPI_REF); cnt = mapi_read_results(fd,fid,MAPI_REF);
printf("\nPacket read : %d",*cnt); cnt2 = mapi_read_results(fd,fid2,MAPI_REF);
printf("\nPackets:: Before COOKING: %d After COOKING: %d",*cnt,*cnt2);
} }
mapi_close_flow(fd); mapi_close_flow(fd);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment