Browse Source

paper edits

cecylia 9 years ago
parent
commit
8882838534
4 changed files with 18 additions and 8 deletions
  1. 7 4
      server/flow.c
  2. 2 0
      server/flow.h
  3. 7 3
      server/slitheen-proxy.c
  4. 2 1
      server/slitheen.h

+ 7 - 4
server/flow.c

@@ -343,7 +343,9 @@ err:
  */
 int remove_flow(flow *f) {
 
-	EVP_MD_CTX_destroy(f->finish_md_ctx);
+	if(f->finish_md_ctx){
+		EVP_MD_CTX_destroy(f->finish_md_ctx);
+	}
 	//Clean up cipher ctxs
 	if(f->clnt_read_ctx != NULL){
 		EVP_CIPHER_CTX_free(f->clnt_read_ctx);
@@ -358,7 +360,6 @@ int remove_flow(flow *f) {
 		EVP_CIPHER_CTX_free(f->srvr_write_ctx);
 	}
 
-	sem_wait(&flow_table_lock);
 	flow_entry *entry = table->first_entry;
 	if(entry->f == f){
 		table->first_entry = entry->next;
@@ -390,7 +391,8 @@ int remove_flow(flow *f) {
 			entry = next;
 		}
 	}
-	sem_post(&flow_table_lock);
+
+	f = NULL;
 
 	return 1;
 }
@@ -413,6 +415,8 @@ int grow_table() {
  */
 flow *check_flow(flow observed){
 	/* Loop through flows in table and see if it exists */
+	
+	sem_wait(&flow_table_lock);
 	int i;
 	flow_entry *entry = table->first_entry;
 	flow *candidate;
@@ -420,7 +424,6 @@ flow *check_flow(flow observed){
 	if(entry == NULL)
 		return NULL;
 
-	sem_wait(&flow_table_lock);
 	/* Check first in this direction */
 	for(i=0; i<table->len; i++){
 		if(entry == NULL){

+ 2 - 0
server/flow.h

@@ -45,6 +45,8 @@ typedef struct data_queue_st {
 
 extern data_queue *downstream_queue;
 
+extern sem_t flow_table_lock;
+
 typedef struct packet_st packet;
 
 typedef struct session_st {

+ 7 - 3
server/slitheen-proxy.c

@@ -32,8 +32,8 @@ int main(int argc, char *argv[]){
 	dev1 = argv[1];
 	dev2 = argv[2];
 
-	snprintf(filter1, 33, "ether src host %s", macaddr);
-	snprintf(filter2, 33, "ether dst host %s", macaddr);
+	snprintf(filter1, 33, "ether src host %s", macaddr1);
+	snprintf(filter2, 33, "ether src host %s", macaddr2);
 
 	init_tables();
 	init_session_cache();
@@ -181,7 +181,11 @@ void process_packet(struct packet_info *info){
 		/* Update TCP state */
 		if(info->tcp_hdr->flags & (FIN | RST) ){
 			/* Remove flow from table, connection ended */
-			remove_flow(observed);
+			sem_wait(&flow_table_lock);
+			if(observed != NULL){
+				remove_flow(observed);
+			}
+			sem_post(&flow_table_lock);
 		}
 
 	}

+ 2 - 1
server/slitheen.h

@@ -4,7 +4,8 @@
 #include <netinet/in.h>
 #include <pcap.h>
 
-#define macaddr "08:00:27:0e:89:ea"
+#define macaddr1 "00:25:90:5a:26:99"
+#define macaddr2 "00:25:90:c9:5a:09"
 
 /* Ethernet addresses are 6 bytes */
 #define ETHER_ADDR_LEN	6