Commit dfcc868b authored by Arne Øslebø's avatar Arne Øslebø
Browse files

fixed possible race condition

git-svn-id: file:///home/svn/mapi/trunk@358 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent 676a646c
...@@ -10,30 +10,30 @@ LIB_DIR=-L/usr/local/lib ...@@ -10,30 +10,30 @@ LIB_DIR=-L/usr/local/lib
DEBUG=1 DEBUG=1
#DAG cards #DAG cards
WITH_DAG=0 WITH_DAG=1
#COMBO6 cards #COMBO6 cards
WITH_COMBO6=0 WITH_COMBO6=0
#Distributed MAPI functionality #Distributed MAPI functionality
WITH_DIMAPI=1 WITH_DIMAPI=0
#MAPI function statistics #MAPI function statistics
#With this pkt counters for each function is enabled #With this pkt counters for each function is enabled
WITH_FUNCT_STATS=1 WITH_FUNCT_STATS=1
#Support for flow priorities #Support for flow priorities
WITH_PRIORITIES=1 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
WITH_ANONYMIZATION=0 WITH_ANONYMIZATION=0
#Support for application-level filtering (mostly P2P traffic identification) #Support for application-level filtering (mostly P2P traffic identification)
WITH_TRACKING=1 WITH_TRACKING=0
#Ipfix flow record generation #Ipfix flow record generation
WITH_IPFIX=0 WITH_IPFIX=0
...@@ -52,7 +52,7 @@ WITH_ETHEREAL=0 ...@@ -52,7 +52,7 @@ WITH_ETHEREAL=0
WITH_OPTIMIZED_BPF_FILTER=0 WITH_OPTIMIZED_BPF_FILTER=0
# ADMISSION CONTROL # ADMISSION CONTROL
WITH_ADMISSION_CONTROL=1 WITH_ADMISSION_CONTROL=0
WITH_RESOURCE_CONTROL=0 WITH_RESOURCE_CONTROL=0
ifeq ($(WITH_DAG),1) ifeq ($(WITH_DAG),1)
......
...@@ -41,6 +41,7 @@ typedef struct dag_instance { ...@@ -41,6 +41,7 @@ typedef struct dag_instance {
mapi_offline_device_status_t *offline_status; mapi_offline_device_status_t *offline_status;
mapid_hw_info_t hwinfo; mapid_hw_info_t hwinfo;
mapidlib_instance_t mapidlib; mapidlib_instance_t mapidlib;
int active; //Workaround for possible race condition when deleting a driver
} dag_instance_t; } dag_instance_t;
flist_t *devlist; flist_t *devlist;
...@@ -72,6 +73,7 @@ int mapidrv_add_device(mapi_offline_device_status_t *olstatus,char *devname, int ...@@ -72,6 +73,7 @@ int mapidrv_add_device(mapi_offline_device_status_t *olstatus,char *devname, int
i->hwinfo.offline=0; i->hwinfo.offline=0;
i->hwinfo.gflist=gflist; i->hwinfo.gflist=gflist;
i->offline_status = olstatus; i->offline_status = olstatus;
i->active=1;
if(devid<0) if(devid<0)
i->hwinfo.offline = 1; i->hwinfo.offline = 1;
...@@ -88,6 +90,7 @@ int mapidrv_delete_device(int devid) ...@@ -88,6 +90,7 @@ int mapidrv_delete_device(int devid)
if (i!=NULL) { if (i!=NULL) {
int err=0; int err=0;
i->active=0;
if (i->th_proc && pthread_equal(i->th_proc, pthread_self())==0) { if (i->th_proc && pthread_equal(i->th_proc, pthread_self())==0) {
DEBUG_CMD(printf("Calling thread != th_proc (%lu != %lu), canceling [%s:%d]\n",i->th_proc,pthread_self(),__FILE__,__LINE__)); DEBUG_CMD(printf("Calling thread != th_proc (%lu != %lu), canceling [%s:%d]\n",i->th_proc,pthread_self(),__FILE__,__LINE__));
...@@ -100,7 +103,7 @@ int mapidrv_delete_device(int devid) ...@@ -100,7 +103,7 @@ int mapidrv_delete_device(int devid)
} }
} }
/* if ((err=pthread_join(i->th_proc,NULL))!=0) { /* if ((err=pthread_join(i->th_proc,NULL))!=0) {
if (!(i->hwinfo.offline==1 && err==ESRCH)) { if (!(i->hwinfo.offline==1 && err==ESRCH)) {
WARNING_CMD(printf("Could not join thread for devid %d (%s) [%s:%d]\n",devid,strerror(err),__FILE__,__LINE__)); WARNING_CMD(printf("Could not join thread for devid %d (%s) [%s:%d]\n",devid,strerror(err),__FILE__,__LINE__));
fflush(stdout); fflush(stdout);
...@@ -120,7 +123,7 @@ int mapidrv_delete_device(int devid) ...@@ -120,7 +123,7 @@ int mapidrv_delete_device(int devid)
DEBUG_CMD(printf("Closed file [%s:%d]\n",__FILE__,__LINE__)); DEBUG_CMD(printf("Closed file [%s:%d]\n",__FILE__,__LINE__));
} }
} }
mapid_destroy(&i->mapidlib); mapid_destroy(&i->mapidlib);
free(i->name); free(i->name);
if(i->offline_status != NULL) if(i->offline_status != NULL)
...@@ -143,8 +146,11 @@ process_pkts(void *buf,unsigned len, dag_instance_t *i) ...@@ -143,8 +146,11 @@ process_pkts(void *buf,unsigned len, dag_instance_t *i)
rec = (dag_record_t *) buf; rec = (dag_record_t *) buf;
rlen = ntohs (rec->rlen); rlen = ntohs (rec->rlen);
if(!i->active)
return len;
mapid_lock(&i->mapidlib); mapid_lock(&i->mapidlib);
while (c + rlen < len) while (c + rlen < len && i->active)
{ {
char *p = buf; char *p = buf;
buf = p + rlen; buf = p + rlen;
......
...@@ -142,7 +142,7 @@ mapid_init(mapidlib_instance_t *i) ...@@ -142,7 +142,7 @@ mapid_init(mapidlib_instance_t *i)
}; };
void mapid_lock(mapidlib_instance_t *i) { void mapid_lock(mapidlib_instance_t *i) {
// printf("Lock..\n"); // printf("Lock..\n");
pthread_spin_lock(i->shm_spinlock); pthread_spin_lock(i->shm_spinlock);
//printf("Locked\n"); //printf("Locked\n");
} }
...@@ -260,7 +260,8 @@ static void delete_flow(mapidlib_instance_t *i,struct mapidlibflow *flow) { ...@@ -260,7 +260,8 @@ static void delete_flow(mapidlib_instance_t *i,struct mapidlibflow *flow) {
} }
#ifdef WITH_MODIFY_PKTS #ifdef WITH_MODIFY_PKTS
free(flow->mod_pkt); if(flow->mod_pkt!=NULL)
free(flow->mod_pkt);
#endif #endif
lock=&flow->hwinfo->gflist->lock; lock=&flow->hwinfo->gflist->lock;
...@@ -456,6 +457,7 @@ mapid_add_flow(mapidlib_instance_t *i, ...@@ -456,6 +457,7 @@ mapid_add_flow(mapidlib_instance_t *i,
fl->shm_fname[0] = '\0'; fl->shm_fname[0] = '\0';
fl->adapterinfo=info; fl->adapterinfo=info;
fl->funct_info_list=NULL; fl->funct_info_list=NULL;
fl->mod_pkt=NULL;
//Add new flow to the global function list //Add new flow to the global function list
fl->functionlist=malloc(sizeof(flist_t)); fl->functionlist=malloc(sizeof(flist_t));
......
...@@ -15,19 +15,19 @@ if [ $# -lt 1 ]; then ...@@ -15,19 +15,19 @@ if [ $# -lt 1 ]; then
fi fi
#echo -n "testing bpf_filter: " #echo -n "testing bpf_filter: "
#./test_bpf_filter $1 > /dev/null #./test_bpf_filter $1
#test $? #test $?
echo -n "testing byte_counter : " echo -n "testing byte_counter : "
./test_byte_counter $1 > /dev/null ./test_byte_counter $1
test $? test $?
echo -n "testing close_flow : " echo -n "testing close_flow : "
./test_close_flow $1 > /dev/null ./test_close_flow $1
test $? test $?
echo -n "testing create_flow : " echo -n "testing create_flow : "
./test_create_flow $1 > /dev/null ./test_create_flow $1
test $? test $?
#echo #echo
...@@ -52,75 +52,75 @@ test $? ...@@ -52,75 +52,75 @@ test $?
#echo #echo
echo -n "testing mapi_apply_function : " echo -n "testing mapi_apply_function : "
./test_mapi_apply_function $1 > /dev/null ./test_mapi_apply_function $1
test $? test $?
echo -n "testing mapi_connect : " echo -n "testing mapi_connect : "
./test_mapi_connect $1 > /dev/null ./test_mapi_connect $1
test $? test $?
echo -n "testing mapi_read_results : " echo -n "testing mapi_read_results : "
./test_mapi_read_results $1 > /dev/null ./test_mapi_read_results $1
test $? test $?
echo -n "testing offline_bpf_filter : " echo -n "testing offline_bpf_filter : "
./test_off_bpf_filter tracefile > /dev/null ./test_off_bpf_filter tracefile
test $? test $?
echo -n "testing offline_pkt_counter : " echo -n "testing offline_pkt_counter : "
./test_off_pkt_counter tracefile > /dev/null ./test_off_pkt_counter tracefile
test $? test $?
echo -n "testing offline_str_search : " echo -n "testing offline_str_search : "
./test_off_str_search www.trace > /dev/null ./test_off_str_search www.trace
test $? test $?
echo -n "testing offline_to_buffer : " echo -n "testing offline_to_buffer : "
./test_off_to_buffer tracefile tracefile > /dev/null ./test_off_to_buffer tracefile tracefile
test $? test $?
echo -n "testing offline_res2file : " echo -n "testing offline_res2file : "
./test_off_res2file tracefile > /dev/null ./test_off_res2file tracefile
test $? test $?
echo -n "testing offline_stats : " echo -n "testing offline_stats : "
./test_off_stats tracefile > /dev/null ./test_off_stats tracefile
test $? test $?
echo -n "testing pkt_counter : " echo -n "testing pkt_counter : "
./test_pkt_counter $1 > /dev/null ./test_pkt_counter $1
test $? test $?
echo -n "testing sample_pkts : " echo -n "testing sample_pkts : "
./test_sample_pkts $1 > /dev/null ./test_sample_pkts $1
test $? test $?
echo -n "testing str_search : " echo -n "testing str_search : "
./test_str_search $1 > /dev/null ./test_str_search $1
test $? test $?
echo -n "testing tcp_offline_flow : " echo -n "testing tcp_offline_flow : "
./test_tcp_offline_flow tracefile > /dev/null ./test_tcp_offline_flow tracefile
test $? test $?
echo -n "testing to_buffer : " echo -n "testing to_buffer : "
./test_to_buffer $1 > /dev/null ./test_to_buffer $1
test $? test $?
echo -n "testing mapi_loop : " echo -n "testing mapi_loop : "
./test_loop > /dev/null ./test_loop
test $? test $?
echo -n "testing error cases : " echo -n "testing error cases : "
./test_for_error_cases $1 tracefile > /dev/null ./test_for_error_cases $1 tracefile
test $? test $?
echo -n "testing get_flow_info : " echo -n "testing get_flow_info : "
./test_get_flow_info $1 > /dev/null ./test_get_flow_info $1
test $? test $?
echo -n "testing get_function_info : " echo -n "testing get_function_info : "
./test_mapi_get_function_info $1 > /dev/null ./test_mapi_get_function_info $1
test $? test $?
#echo #echo
......
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