aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--example/Makefile.in5
-rw-r--r--example/ndpiReader.c5
-rw-r--r--example/ndpi_util.c2
-rw-r--r--src/include/Makefile.am2
-rw-r--r--src/include/ndpi_api.h6
-rw-r--r--src/include/ndpi_typedefs.h6
-rw-r--r--src/lib/Makefile.in2
-rw-r--r--src/lib/ndpi_main.c58
-rw-r--r--src/lib/protocols/coap.c2
-rw-r--r--src/lib/protocols/http.c19
-rw-r--r--src/lib/protocols/mdns_proto.c2
-rw-r--r--src/lib/protocols/ookla.c15
-rw-r--r--src/lib/protocols/ssl.c2
-rw-r--r--src/lib/third_party/include/lruc.h55
-rw-r--r--src/lib/third_party/src/lruc.c294
-rw-r--r--tests/result/pps.pcap.out7
-rw-r--r--tests/result/starcraft_battle.pcap.out5
-rw-r--r--tests/result/waze.pcap.out5
18 files changed, 93 insertions, 399 deletions
diff --git a/example/Makefile.in b/example/Makefile.in
index bf218f503..8960ed0a2 100644
--- a/example/Makefile.in
+++ b/example/Makefile.in
@@ -3,7 +3,7 @@ CFLAGS=-g -I../src/include @CFLAGS@
LIBNDPI=../src/lib/libndpi.a
LDFLAGS=$(LIBNDPI) @PCAP_LIB@ -lpthread @LDFLAGS@
OBJS=ndpiReader.o ndpi_util.o
-PREFIX?=/usr/local
+PREFIX?=@prefix@
all: ndpiReader @DPDK_TARGET@
@@ -22,6 +22,9 @@ install:
dpdk:
make -f Makefile.dpdk
+check:
+ cppcheck --template='{file}:{line}:{severity}:{message}' --quiet --enable=all --force -I../src/include -I/usr/local/include/json-c *.c
+
clean:
/bin/rm -f *.o ndpiReader ndpiReader.dpdk
/bin/rm -f .*.dpdk.cmd .*.o.cmd *.dpdk.map .*.o.d
diff --git a/example/ndpiReader.c b/example/ndpiReader.c
index 6c3dfeee8..3f030265c 100644
--- a/example/ndpiReader.c
+++ b/example/ndpiReader.c
@@ -913,7 +913,7 @@ static void node_proto_guess_walker(const void *node, ndpi_VISIT which, int dept
struct ndpi_flow_info *flow = *(struct ndpi_flow_info **) node;
u_int16_t thread_id = *((u_int16_t *) user_data);
- if((which == ndpi_preorder) || (which == ndpi_leaf)) { /* Avoid walking the same node multiple times */
+ if((which == ndpi_preorder) || (which == ndpi_leaf)) { /* Avoid walking the same node multiple times */
if((!flow->detection_completed) && flow->ndpi_flow)
flow->detected_protocol = ndpi_detection_giveup(ndpi_thread_info[0].workflow->ndpi_struct, flow->ndpi_flow, enable_protocol_guess);
@@ -1015,7 +1015,6 @@ void freeIpTree(addr_node *root) {
freeIpTree(root->left);
freeIpTree(root->right);
free(root);
- root = NULL;
}
/* *********************************************** */
@@ -2901,7 +2900,7 @@ float getAverage(struct json_object *jObj_stat, char *field){
float average;
float sum = 0;
int r;
- int j;
+ int j = 0;
if((r = strcmp(field, "top.scanner.stats")) == 0) {
for(j=0; j<json_object_array_length(jObj_stat); j++) {
diff --git a/example/ndpi_util.c b/example/ndpi_util.c
index 58dc896b1..3a2a66c97 100644
--- a/example/ndpi_util.c
+++ b/example/ndpi_util.c
@@ -1044,7 +1044,7 @@ iph_check:
static uint32_t crc32_for_byte(uint32_t r) {
int j;
for(j = 0; j < 8; ++j)
- r = (r & 1? 0: (uint32_t)0xEDB88320L) ^ r >> 1;
+ r = ((r & 1) ? 0 : (uint32_t)0xEDB88320L) ^ r >> 1;
return r ^ (uint32_t)0xFF000000L;
}
diff --git a/src/include/Makefile.am b/src/include/Makefile.am
index 6eeca93b4..47fcbd224 100644
--- a/src/include/Makefile.am
+++ b/src/include/Makefile.am
@@ -1,4 +1,4 @@
-library_includedir=$(includedir)/libndpi-@VERSION@/libndpi
+plibrary_includedir=$(includedir)/libndpi-@VERSION@/libndpi
library_include_HEADERS = ndpi_api.h \
ndpi_define.h \
diff --git a/src/include/ndpi_api.h b/src/include/ndpi_api.h
index e57f3a568..e09c91c8e 100644
--- a/src/include/ndpi_api.h
+++ b/src/include/ndpi_api.h
@@ -756,6 +756,12 @@ extern "C" {
u_int ndpi_get_ndpi_num_custom_protocols(struct ndpi_detection_module_struct *ndpi_mod);
u_int ndpi_get_ndpi_detection_module_size();
void ndpi_set_log_level(struct ndpi_detection_module_struct *ndpi_mod, u_int l);
+
+ /* LRU cache */
+ struct ndpi_lru_cache* ndpi_lru_cache_init(u_int32_t num_entries);
+ void ndpi_lru_free_cache(struct ndpi_lru_cache *c);
+ u_int8_t ndpi_lru_find_cache(struct ndpi_lru_cache *c, u_int32_t key, u_int8_t clean_key_when_found);
+ void ndpi_lru_add_to_cache(struct ndpi_lru_cache *c, u_int32_t key);
/**
* Add a string to match to an automata
diff --git a/src/include/ndpi_typedefs.h b/src/include/ndpi_typedefs.h
index 34d308e2e..cf1af8bc3 100644
--- a/src/include/ndpi_typedefs.h
+++ b/src/include/ndpi_typedefs.h
@@ -367,6 +367,10 @@ typedef enum {
HTTP_METHOD_CONNECT
} ndpi_http_method;
+struct ndpi_lru_cache {
+ u_int32_t num_entries, *entries;
+};
+
struct ndpi_id_struct {
/**
detected_protocol_bitmask:
@@ -997,7 +1001,7 @@ struct ndpi_detection_module_struct {
int bt_ann_len;
/* NDPI_PROTOCOL_OOKLA */
- void *ookla_cache;
+ struct ndpi_lru_cache *ookla_cache;
/* NDPI_PROTOCOL_TINC */
struct cache *tinc_cache;
diff --git a/src/lib/Makefile.in b/src/lib/Makefile.in
index 0ffeb9db5..8b0853dd4 100644
--- a/src/lib/Makefile.in
+++ b/src/lib/Makefile.in
@@ -10,7 +10,7 @@
#
# Installation directories
#
-prefix = /usr/local
+prefix = @prefix@
libdir = ${prefix}/lib
includedir = ${prefix}/include/ndpi
CC = @CC@
diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c
index ac8543648..fcf86449a 100644
--- a/src/lib/ndpi_main.c
+++ b/src/lib/ndpi_main.c
@@ -30,7 +30,6 @@
#include <sys/types.h>
#include "ahocorasick.h"
#include "libcache.h"
-#include "lruc.h"
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_UNKNOWN
@@ -842,21 +841,21 @@ static int init_hyperscan(struct ndpi_detection_module_struct *ndpi_mod) {
}
need_to_be_free = (unsigned char*)calloc(sizeof(unsigned char), num_patterns + 1);
- if (!need_to_be_free) {
+ if(!need_to_be_free) {
free(expressions);
free(ids);
return(-1);
}
- for (i = 0, j = 0; host_match[i].string_to_match != NULL || host_match[i].pattern_to_match != NULL; i++) {
- if (host_match[i].pattern_to_match) {
+ for(i = 0, j = 0; host_match[i].string_to_match != NULL || host_match[i].pattern_to_match != NULL; i++) {
+ if(host_match[i].pattern_to_match) {
expressions[j] = host_match[i].pattern_to_match;
ids[j] = host_match[i].protocol_id;
need_to_be_free[j] = 0;
++j;
} else {
expressions[j] = string2hex(host_match[i].string_to_match);
- if (expressions[j] != NULL) {
+ if(expressions[j] != NULL) {
ids[j] = host_match[i].protocol_id;
need_to_be_free[j] = 1;
++j;
@@ -871,11 +870,12 @@ static int init_hyperscan(struct ndpi_detection_module_struct *ndpi_mod) {
rc = hyperscan_load_patterns(hs, j, (const char**)expressions, ids);
- for (i = 0; i < j; ++i)
- if (need_to_be_free[i])
+ for(i = 0; i < j; ++i)
+ if(need_to_be_free[i])
free(expressions[i]);
free(expressions), free(ids);
+ free(need_to_be_free);
return(rc);
}
@@ -2433,7 +2433,7 @@ void ndpi_exit_detection_module(struct ndpi_detection_module_struct *ndpi_struct
cache_free((cache_t)(ndpi_struct->tinc_cache));
if(ndpi_struct->ookla_cache)
- lruc_free((lruc*)ndpi_struct->ookla_cache);
+ ndpi_lru_free_cache(ndpi_struct->ookla_cache);
if(ndpi_struct->protocols_ptree)
ndpi_Destroy_Patricia((patricia_tree_t*)ndpi_struct->protocols_ptree, free_ptree_data);
@@ -6171,6 +6171,48 @@ void ndpi_set_log_level(struct ndpi_detection_module_struct *ndpi_mod, u_int l)
/* ******************************************************************** */
+/* LRU cache */
+
+struct ndpi_lru_cache* ndpi_lru_cache_init(u_int32_t num_entries) {
+ struct ndpi_lru_cache *c = (struct ndpi_lru_cache*)malloc(sizeof(struct ndpi_lru_cache));
+
+ if(!c) return(NULL);
+
+ c->entries = (u_int32_t*)calloc(num_entries, sizeof(u_int32_t));
+
+ if(!c->entries) {
+ free(c);
+ return(NULL);
+ } else
+ c->num_entries = num_entries;
+
+ return(c);
+}
+
+void ndpi_lru_free_cache(struct ndpi_lru_cache *c) {
+ free(c->entries);
+ free(c);
+}
+
+
+u_int8_t ndpi_lru_find_cache(struct ndpi_lru_cache *c, u_int32_t key, u_int8_t clean_key_when_found) {
+ u_int32_t slot = key % c->num_entries;
+
+ if(c->entries[slot] == key) {
+ if(clean_key_when_found) c->entries[slot] = 0;
+ return(1);
+ } else
+ return(0);
+}
+
+void ndpi_lru_add_to_cache(struct ndpi_lru_cache *c, u_int32_t key) {
+ u_int32_t slot = key % c->num_entries;
+
+ c->entries[slot] = key;
+}
+
+/* ******************************************************************** */
+
/*
NOTE:
- Leave fields empty/zero when information is missing (e.g. with ICMP ports are zero)
diff --git a/src/lib/protocols/coap.c b/src/lib/protocols/coap.c
index 5ac8cb80e..cf5061bbe 100644
--- a/src/lib/protocols/coap.c
+++ b/src/lib/protocols/coap.c
@@ -129,7 +129,7 @@ void ndpi_search_coap (struct ndpi_detection_module_struct *ndpi_struct,
// check values in header
if(h->version == 1) {
if(h->type == CON || h->type == NO_CON || h->type == ACK || h->type == RST ) {
- if(h->tkl == 0 || h->tkl < 8) {
+ if(h->tkl < 8) {
if((h->code >= 0 && h->code <= 5) || (h->code >= 65 && h->code <= 69) ||
(h->code >= 128 && h->code <= 134) || (h->code >= 140 && h->code <= 143) ||
(h->code >= 160 && h->code <= 165)) {
diff --git a/src/lib/protocols/http.c b/src/lib/protocols/http.c
index 661e55732..16b122d06 100644
--- a/src/lib/protocols/http.c
+++ b/src/lib/protocols/http.c
@@ -26,7 +26,6 @@
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_HTTP
#include "ndpi_api.h"
-#include "lruc.h"
static void ndpi_int_http_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
@@ -642,19 +641,15 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_OOKLA, NDPI_PROTOCOL_UNKNOWN);
if(ndpi_struct->ookla_cache == NULL)
- ndpi_struct->ookla_cache = lruc_new(4*1024, 1024);
-
+ ndpi_struct->ookla_cache = ndpi_lru_cache_init(1024);
+
if(packet->iph != NULL && ndpi_struct->ookla_cache != NULL) {
- u_int8_t *dummy = (u_int8_t*)ndpi_malloc(sizeof(u_int8_t));
-
- if(dummy) {
- if(packet->tcp->source == htons(8080))
- lruc_set((lruc*)ndpi_struct->ookla_cache, (void*)&packet->iph->saddr, 4, dummy, 1);
- else
- lruc_set((lruc*)ndpi_struct->ookla_cache, (void*)&packet->iph->daddr, 4, dummy, 1);
- }
+ if(packet->tcp->source == htons(8080))
+ ndpi_lru_add_to_cache(ndpi_struct->ookla_cache, packet->iph->saddr);
+ else
+ ndpi_lru_add_to_cache(ndpi_struct->ookla_cache, packet->iph->daddr);
}
-
+
return;
}
diff --git a/src/lib/protocols/mdns_proto.c b/src/lib/protocols/mdns_proto.c
index 77bdf4208..00c7c8748 100644
--- a/src/lib/protocols/mdns_proto.c
+++ b/src/lib/protocols/mdns_proto.c
@@ -77,7 +77,7 @@ static int ndpi_int_check_mdns_payload(struct ndpi_detection_module_struct
char answer[256];
int i, j, len;
- for(i=13, j=0; (packet->payload[i] != 0) && (i < packet->payload_packet_len) && (i < (sizeof(answer)-1)); i++)
+ for(i=13, j=0; (i < packet->payload_packet_len) && (i < (sizeof(answer)-1)) && (packet->payload[i] != 0); i++)
answer[j++] = (packet->payload[i] < 13) ? '.' : packet->payload[i];
answer[j] = '\0';
diff --git a/src/lib/protocols/ookla.c b/src/lib/protocols/ookla.c
index b1eb295a7..06d97e216 100644
--- a/src/lib/protocols/ookla.c
+++ b/src/lib/protocols/ookla.c
@@ -22,34 +22,32 @@
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_OOKLA
#include "ndpi_api.h"
-#include "lruc.h"
void ndpi_search_ookla(struct ndpi_detection_module_struct* ndpi_struct, struct ndpi_flow_struct* flow) {
struct ndpi_packet_struct* packet = &flow->packet;
u_int32_t addr = 0;
void *value;
-
+
NDPI_LOG_DBG(ndpi_struct, "Ookla detection\n");
-
+
if(packet->tcp->source == htons(8080))
addr = packet->iph->saddr;
else if(packet->tcp->dest == htons(8080))
addr = packet->iph->daddr;
else
goto ookla_exclude;
-
+
if(ndpi_struct->ookla_cache != NULL) {
- if(lruc_get(ndpi_struct->ookla_cache, &addr, sizeof(addr), &value) == LRUC_NO_ERROR) {
- /* Don't remove it as it can be used for other connections */
+ if(ndpi_lru_find_cache(ndpi_struct->ookla_cache, addr, 0 /* Don't remove it as it can be used for other connections */)) {
NDPI_LOG_INFO(ndpi_struct, "found ookla tcp connection\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_OOKLA, NDPI_PROTOCOL_UNKNOWN);
return;
- }
+ }
}
ookla_exclude:
- NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
+ NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
}
void init_ookla_dissector(struct ndpi_detection_module_struct *ndpi_struct,
@@ -63,4 +61,3 @@ void init_ookla_dissector(struct ndpi_detection_module_struct *ndpi_struct,
*id += 1;
}
-
diff --git a/src/lib/protocols/ssl.c b/src/lib/protocols/ssl.c
index 25d535a57..4651b358f 100644
--- a/src/lib/protocols/ssl.c
+++ b/src/lib/protocols/ssl.c
@@ -559,7 +559,7 @@ static u_int8_t ndpi_search_sslv3_direction1(struct ndpi_detection_module_struct
}
}
- if((packet->payload_packet_len > temp && packet->payload_packet_len > 100) && packet->payload_packet_len > 9) {
+ if((packet->payload_packet_len > temp) && (packet->payload_packet_len > 100)) {
/* the server hello may be split into small packets and the certificate has its own SSL Record
* so temp contains only the length for the first ServerHello block */
u_int32_t cert_start;
diff --git a/src/lib/third_party/include/lruc.h b/src/lib/third_party/include/lruc.h
deleted file mode 100644
index 55fb271fe..000000000
--- a/src/lib/third_party/include/lruc.h
+++ /dev/null
@@ -1,55 +0,0 @@
-#include <pthread.h>
-#include <stdint.h>
-#include <time.h>
-
-#ifndef __lruc_header__
-#define __lruc_header__
-
-// ------------------------------------------
-// errors
-// ------------------------------------------
-typedef enum {
- LRUC_NO_ERROR = 0,
- LRUC_MISSING_CACHE,
- LRUC_MISSING_KEY,
- LRUC_MISSING_VALUE,
- LRUC_PTHREAD_ERROR,
- LRUC_VALUE_TOO_LARGE
-} lruc_error;
-
-
-// ------------------------------------------
-// types
-// ------------------------------------------
-typedef struct {
- void *value;
- void *key;
- uint32_t value_length;
- uint32_t key_length;
- uint64_t access_count;
- void *next;
-} lruc_item;
-
-typedef struct {
- lruc_item **items;
- uint64_t access_count;
- uint64_t free_memory;
- uint64_t total_memory;
- uint64_t average_item_length;
- uint32_t hash_table_size;
- time_t seed;
- lruc_item *free_items;
- pthread_mutex_t *mutex;
-} lruc;
-
-
-// ------------------------------------------
-// api
-// ------------------------------------------
-lruc *lruc_new(uint64_t cache_size, uint32_t average_length);
-lruc_error lruc_free(lruc *cache);
-lruc_error lruc_set(lruc *cache, void *key, uint32_t key_length, void *value, uint32_t value_length);
-lruc_error lruc_get(lruc *cache, void *key, uint32_t key_length, void **value);
-lruc_error lruc_delete(lruc *cache, void *key, uint32_t key_length);
-
-#endif
diff --git a/src/lib/third_party/src/lruc.c b/src/lib/third_party/src/lruc.c
deleted file mode 100644
index f08fb2ce1..000000000
--- a/src/lib/third_party/src/lruc.c
+++ /dev/null
@@ -1,294 +0,0 @@
-/* https://github.com/willcannings/C-LRU-Cache */
-
-#include "lruc.h"
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <err.h>
-
-// ------------------------------------------
-// private functions
-// ------------------------------------------
-// MurmurHash2, by Austin Appleby
-// http://sites.google.com/site/murmurhash/
-uint32_t lruc_hash(lruc *cache, void *key, uint32_t key_length) {
- uint32_t m = 0x5bd1e995;
- uint32_t r = 24;
- uint32_t h = cache->seed ^ key_length;
- char* data = (char *)key;
-
- while(key_length >= 4) {
- uint32_t k = *(uint32_t *)data;
- k *= m;
- k ^= k >> r;
- k *= m;
- h *= m;
- h ^= k;
- data += 4;
- key_length -= 4;
- }
-
- switch(key_length) {
- case 3: h ^= data[2] << 16;
- case 2: h ^= data[1] << 8;
- case 1: h ^= data[0];
- h *= m;
- };
-
- h ^= h >> 13;
- h *= m;
- h ^= h >> 15;
- return h % cache->hash_table_size;
-}
-
-// compare a key against an existing item's key
-int lruc_cmp_keys(lruc_item *item, void *key, uint32_t key_length) {
- if(key_length != item->key_length)
- return 1;
- else
- return memcmp(key, item->key, key_length);
-}
-
-// remove an item and push it to the free items queue
-void lruc_remove_item(lruc *cache, lruc_item *prev, lruc_item *item, uint32_t hash_index) {
- if(prev)
- prev->next = item->next;
- else
- cache->items[hash_index] = (lruc_item *) item->next;
-
- // free memory and update the free memory counter
- cache->free_memory += item->value_length;
- free(item->value);
- free(item->key);
-
- // push the item to the free items queue
- memset(item, 0, sizeof(lruc_item));
- item->next = cache->free_items;
- cache->free_items = item;
-}
-
-// remove the least recently used item
-// TODO: we can optimise this by finding the n lru items, where n = required_space / average_length
-void lruc_remove_lru_item(lruc *cache) {
- lruc_item *min_item = NULL, *min_prev = NULL;
- lruc_item *item = NULL, *prev = NULL;
- uint32_t i = 0, min_index = -1;
- uint64_t min_access_count = -1;
-
- for(; i < cache->hash_table_size; i++) {
- item = cache->items[i];
- prev = NULL;
-
- while(item) {
- if(item->access_count < min_access_count || min_access_count == -1) {
- min_access_count = item->access_count;
- min_item = item;
- min_prev = prev;
- min_index = i;
- }
- prev = item;
- item = item->next;
- }
- }
-
- if(min_item)
- lruc_remove_item(cache, min_prev, min_item, min_index);
-}
-
-// pop an existing item off the free queue, or create a new one
-lruc_item *lruc_pop_or_create_item(lruc *cache) {
- lruc_item *item = NULL;
-
- if(cache->free_items) {
- item = cache->free_items;
- cache->free_items = item->next;
- } else {
- item = (lruc_item *) calloc(sizeof(lruc_item), 1);
- }
-
- return item;
-}
-
-// error helpers
-#define error_for(conditions, error) if(conditions) {return error;}
-#define test_for_missing_cache() error_for(!cache, LRUC_MISSING_CACHE)
-#define test_for_missing_key() error_for(!key || key_length == 0, LRUC_MISSING_KEY)
-#define test_for_missing_value() error_for(!value || value_length == 0, LRUC_MISSING_VALUE)
-#define test_for_value_too_large() error_for(value_length > cache->total_memory, LRUC_VALUE_TOO_LARGE)
-
-// lock helpers
-#define lock_cache() if(pthread_mutex_lock(cache->mutex)) {\
- perror("LRU Cache unable to obtain mutex lock");\
- return LRUC_PTHREAD_ERROR;\
-}
-
-#define unlock_cache() if(pthread_mutex_unlock(cache->mutex)) {\
- perror("LRU Cache unable to release mutex lock");\
- return LRUC_PTHREAD_ERROR;\
-}
-
-
-// ------------------------------------------
-// public api
-// ------------------------------------------
-lruc *lruc_new(uint64_t cache_size, uint32_t average_length) {
- // create the cache
- lruc *cache = (lruc *) calloc(sizeof(lruc), 1);
- if(!cache) {
- perror("LRU Cache unable to create cache object");
- return NULL;
- }
- cache->hash_table_size = cache_size / average_length;
- cache->average_item_length = average_length;
- cache->free_memory = cache_size;
- cache->total_memory = cache_size;
- cache->seed = time(NULL);
-
- // size the hash table to a guestimate of the number of slots required (assuming a perfect hash)
- cache->items = (lruc_item **) calloc(sizeof(lruc_item *), cache->hash_table_size);
- if(!cache->items) {
- perror("LRU Cache unable to create cache hash table");
- free(cache);
- return NULL;
- }
-
- // all cache calls are guarded by a mutex
- cache->mutex = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t));
- if(pthread_mutex_init(cache->mutex, NULL)) {
- perror("LRU Cache unable to initialise mutex");
- free(cache->items);
- free(cache);
- return NULL;
- }
- return cache;
-}
-
-
-lruc_error lruc_free(lruc *cache) {
- test_for_missing_cache();
-
- // free each of the cached items, and the hash table
- lruc_item *item = NULL, *next = NULL;
- uint32_t i = 0;
- if(cache->items) {
- for(; i < cache->hash_table_size; i++) {
- item = cache->items[i];
- while(item) {
- next = (lruc_item *) item->next;
- free(item);
- item = next;
- }
- }
- free(cache->items);
- }
-
- // free the cache
- if(cache->mutex) {
- if(pthread_mutex_destroy(cache->mutex)) {
- perror("LRU Cache unable to destroy mutex");
- return LRUC_PTHREAD_ERROR;
- }
- }
- free(cache);
-
- return LRUC_NO_ERROR;
-}
-
-
-lruc_error lruc_set(lruc *cache, void *key, uint32_t key_length, void *value, uint32_t value_length) {
- test_for_missing_cache();
- test_for_missing_key();
- test_for_missing_value();
- test_for_value_too_large();
- lock_cache();
-
- // see if the key already exists
- uint32_t hash_index = lruc_hash(cache, key, key_length), required = 0;
- lruc_item *item = NULL, *prev = NULL;
- item = cache->items[hash_index];
-
- while(item && lruc_cmp_keys(item, key, key_length)) {
- prev = item;
- item = (lruc_item *) item->next;
- }
-
- if(item) {
- // update the value and value_lengths
- required = value_length - item->value_length;
- free(item->value);
- item->value = value;
- item->value_length = value_length;
-
- } else {
- // insert a new item
- item = lruc_pop_or_create_item(cache);
- item->value = value;
- item->key = key;
- item->value_length = value_length;
- item->key_length = key_length;
- required = value_length;
-
- if(prev)
- prev->next = item;
- else
- cache->items[hash_index] = item;
- }
- item->access_count = ++cache->access_count;
-
- // remove as many items as necessary to free enough space
- if(required > 0 && required > cache->free_memory) {
- while(cache->free_memory < required)
- lruc_remove_lru_item(cache);
- }
- cache->free_memory -= required;
- unlock_cache();
- return LRUC_NO_ERROR;
-}
-
-
-lruc_error lruc_get(lruc *cache, void *key, uint32_t key_length, void **value) {
- test_for_missing_cache();
- test_for_missing_key();
- lock_cache();
-
- // loop until we find the item, or hit the end of a chain
- uint32_t hash_index = lruc_hash(cache, key, key_length);
- lruc_item *item = cache->items[hash_index];
-
- while(item && lruc_cmp_keys(item, key, key_length))
- item = (lruc_item *) item->next;
-
- if(item) {
- *value = item->value;
- item->access_count = ++cache->access_count;
- } else {
- *value = NULL;
- }
-
- unlock_cache();
- return LRUC_NO_ERROR;
-}
-
-
-lruc_error lruc_delete(lruc *cache, void *key, uint32_t key_length) {
- test_for_missing_cache();
- test_for_missing_key();
- lock_cache();
-
- // loop until we find the item, or hit the end of a chain
- lruc_item *item = NULL, *prev = NULL;
- uint32_t hash_index = lruc_hash(cache, key, key_length);
- item = cache->items[hash_index];
-
- while(item && lruc_cmp_keys(item, key, key_length)) {
- prev = item;
- item = (lruc_item *) item->next;
- }
-
- if(item) {
- lruc_remove_item(cache, prev, item, hash_index);
- }
-
- unlock_cache();
- return LRUC_NO_ERROR;
-}
diff --git a/tests/result/pps.pcap.out b/tests/result/pps.pcap.out
index 778aa1197..f9e26850b 100644
--- a/tests/result/pps.pcap.out
+++ b/tests/result/pps.pcap.out
@@ -1,7 +1,6 @@
Unknown 990 378832 34
-HTTP 47 42014 11
+HTTP 73 69236 13
SSDP 63 17143 10
-HTTP_Download 26 27222 2
Google 2 1093 1
GenericProtocol 1429 1780307 49
@@ -9,7 +8,7 @@ GenericProtocol 1429 1780307 49
2 TCP 192.168.115.8:50778 <-> 223.26.106.20:80 [proto: 7.137/HTTP.GenericProtocol][cat: Streaming/17][1 pkts/303 bytes <-> 528 pkts/692658 bytes][Host: preimage1.qiyipic.com]
3 TCP 192.168.115.8:50505 <-> 223.26.106.19:80 [proto: 7.137/HTTP.GenericProtocol][cat: Streaming/17][2 pkts/400 bytes <-> 244 pkts/319633 bytes][Host: static.qiyi.com]
4 TCP 192.168.115.8:50491 <-> 223.26.106.66:80 [proto: 7/HTTP][cat: Web/5][1 pkts/426 bytes <-> 26 pkts/33872 bytes][Host: 223.26.106.66]
- 5 TCP 192.168.115.8:50486 <-> 77.234.40.96:80 [proto: 7.60/HTTP.HTTP_Download][cat: Download-FileTransfer-FileSharing/7][11 pkts/11023 bytes <-> 12 pkts/14869 bytes][Host: bcu.ff.avast.com]
+ 5 TCP 192.168.115.8:50486 <-> 77.234.40.96:80 [proto: 7/HTTP][cat: Web/5][11 pkts/11023 bytes <-> 12 pkts/14869 bytes][Host: bcu.ff.avast.com]
6 UDP 192.168.5.38:1900 -> 239.255.255.250:1900 [proto: 12/SSDP][cat: System/18][18 pkts/9327 bytes -> 0 pkts/0 bytes]
7 TCP 192.168.115.8:50476 <-> 101.227.32.39:80 [proto: 7.137/HTTP.GenericProtocol][cat: Streaming/17][1 pkts/656 bytes <-> 4 pkts/3897 bytes][Host: cache.video.iqiyi.com]
8 TCP 192.168.115.8:50495 <-> 202.108.14.236:80 [proto: 7.137/HTTP.GenericProtocol][cat: Streaming/17][3 pkts/2844 bytes <-> 3 pkts/597 bytes][Host: msg.71.am]
@@ -26,7 +25,7 @@ GenericProtocol 1429 1780307 49
19 TCP 192.168.115.8:50464 <-> 123.125.112.49:80 [proto: 7.137/HTTP.GenericProtocol][cat: Streaming/17][1 pkts/707 bytes <-> 1 pkts/744 bytes][Host: click.hm.baidu.com]
20 TCP 192.168.115.8:50492 <-> 111.206.13.3:80 [proto: 7.137/HTTP.GenericProtocol][cat: Streaming/17][1 pkts/389 bytes <-> 2 pkts/1034 bytes][Host: pdata.video.qiyi.com]
21 TCP 192.168.115.8:50777 <-> 111.206.22.77:80 [proto: 7.137/HTTP.GenericProtocol][cat: Streaming/17][1 pkts/1186 bytes <-> 1 pkts/194 bytes][Host: msg.iqiyi.com]
- 22 TCP 192.168.115.8:50494 <-> 223.26.106.66:80 [proto: 7.60/HTTP.HTTP_Download][cat: Download-FileTransfer-FileSharing/7][2 pkts/887 bytes <-> 1 pkts/443 bytes][Host: 223.26.106.66]
+ 22 TCP 192.168.115.8:50494 <-> 223.26.106.66:80 [proto: 7/HTTP][cat: Web/5][2 pkts/887 bytes <-> 1 pkts/443 bytes][Host: 223.26.106.66]
23 TCP 192.168.115.8:50497 <-> 123.125.112.49:80 [proto: 7.137/HTTP.GenericProtocol][cat: Streaming/17][1 pkts/1004 bytes <-> 2 pkts/301 bytes][Host: click.hm.baidu.com]
24 TCP 192.168.115.8:50499 <-> 111.206.22.76:80 [proto: 7.137/HTTP.GenericProtocol][cat: Streaming/17][1 pkts/1097 bytes <-> 1 pkts/199 bytes][Host: msg.iqiyi.com]
25 TCP 192.168.115.8:50474 <-> 202.108.14.221:80 [proto: 7.137/HTTP.GenericProtocol][cat: Streaming/17][1 pkts/1100 bytes <-> 1 pkts/194 bytes][Host: msg.iqiyi.com]
diff --git a/tests/result/starcraft_battle.pcap.out b/tests/result/starcraft_battle.pcap.out
index c63b86dc8..8d42d972d 100644
--- a/tests/result/starcraft_battle.pcap.out
+++ b/tests/result/starcraft_battle.pcap.out
@@ -1,7 +1,6 @@
DNS 26 2848 7
-HTTP 271 160676 18
+HTTP 450 294880 19
SSDP 11 4984 1
-HTTP_Download 179 134204 1
WorldOfWarcraft 9 880 1
IGMP 2 120 1
SSL 38 2548 11
@@ -9,7 +8,7 @@ Google 22 2184 5
Github 3 234 1
Starcraft 236 51494 6
- 1 TCP 192.168.1.100:3508 <-> 87.248.221.254:80 [proto: 7.60/HTTP.HTTP_Download][cat: Download-FileTransfer-FileSharing/7][90 pkts/5059 bytes <-> 89 pkts/129145 bytes][Host: llnw.blizzard.com]
+ 1 TCP 192.168.1.100:3508 <-> 87.248.221.254:80 [proto: 7/HTTP][cat: Web/5][90 pkts/5059 bytes <-> 89 pkts/129145 bytes][Host: llnw.blizzard.com]
2 TCP 192.168.1.100:3517 <-> 213.248.127.130:1119 [proto: 213/Starcraft][cat: Game/8][126 pkts/9157 bytes <-> 89 pkts/41021 bytes]
3 TCP 192.168.1.100:3527 <-> 2.228.46.112:80 [proto: 7/HTTP][cat: Web/5][15 pkts/971 bytes <-> 26 pkts/36462 bytes][Host: bnetcmsus-a.akamaihd.net]
4 TCP 192.168.1.100:3528 <-> 2.228.46.112:80 [proto: 7/HTTP][cat: Web/5][11 pkts/755 bytes <-> 18 pkts/24350 bytes][Host: bnetcmsus-a.akamaihd.net]
diff --git a/tests/result/waze.pcap.out b/tests/result/waze.pcap.out
index 5bdf0a3bb..c321981a5 100644
--- a/tests/result/waze.pcap.out
+++ b/tests/result/waze.pcap.out
@@ -1,14 +1,13 @@
Unknown 10 786 1
-HTTP 28 1572 7
+HTTP 65 64777 8
NTP 2 180 1
-HTTP_Download 37 63205 1
SSL 8 432 2
Google 13 2142 1
Waze 484 289335 19
WhatsApp 15 1341 1
1 TCP 10.8.0.1:36100 <-> 46.51.173.182:443 [proto: 91.135/SSL.Waze][cat: Web/5][52 pkts/10860 bytes <-> 55 pkts/74852 bytes][server: *.world.waze.com]
- 2 TCP 10.8.0.1:54915 <-> 65.39.128.135:80 [proto: 7.60/HTTP.HTTP_Download][cat: Download-FileTransfer-FileSharing/7][19 pkts/1309 bytes <-> 18 pkts/61896 bytes][Host: xtra1.gpsonextra.net]
+ 2 TCP 10.8.0.1:54915 <-> 65.39.128.135:80 [proto: 7/HTTP][cat: Web/5][19 pkts/1309 bytes <-> 18 pkts/61896 bytes][Host: xtra1.gpsonextra.net]
3 TCP 10.8.0.1:39021 <-> 52.17.114.219:443 [proto: 91.135/SSL.Waze][cat: Web/5][17 pkts/1962 bytes <-> 16 pkts/56934 bytes][server: *.world.waze.com]
4 TCP 10.8.0.1:36312 <-> 176.34.186.180:443 [proto: 91.135/SSL.Waze][cat: Web/5][17 pkts/2176 bytes <-> 15 pkts/42443 bytes][server: *.world.waze.com]
5 TCP 10.8.0.1:36316 <-> 176.34.186.180:443 [proto: 91.135/SSL.Waze][cat: Web/5][15 pkts/1540 bytes <-> 13 pkts/26346 bytes][server: *.world.waze.com]