Beispiel #1
0
int ndpi_init_lru_cache(struct ndpi_LruCache *cache, u_int32_t max_size) {
  if(unlikely(traceLRU))
    printf("%s(max_size=%u)", __FUNCTION__, max_size);

  cache->max_cache_node_len = 4;
  cache->hash_size = max_size/cache->max_cache_node_len;

#ifdef FULL_STATS
  cache->mem_size += cache->hash_size*sizeof(struct ndpi_LruCacheEntry*);
#endif
  if((cache->hash = (struct ndpi_LruCacheEntry**)ndpi_calloc(cache->hash_size, sizeof(struct ndpi_LruCacheEntry*))) == NULL) {
    printf("ERROR: Not enough memory?");
    return(-1);
  }

#ifdef FULL_STATS
  cache->mem_size += cache->hash_size*sizeof(u_int32_t);
#endif
  if((cache->current_hash_size = (u_int32_t*)ndpi_calloc(cache->hash_size, sizeof(u_int32_t))) == NULL) {
    printf("ERROR: Not enough memory?");
    return(-1);
  }

  return(0);
}
Beispiel #2
0
struct pm_ndpi_workflow *pm_ndpi_workflow_init()
{
  struct ndpi_detection_module_struct *module = ndpi_init_detection_module();
  struct pm_ndpi_workflow *workflow = ndpi_calloc(1, sizeof(struct pm_ndpi_workflow));

  log_notification_init(&log_notifications.ndpi_cache_full);
  log_notification_init(&log_notifications.ndpi_tmp_frag_warn);

  workflow->prefs.decode_tunnels = FALSE;

  if (config.ndpi_num_roots) workflow->prefs.num_roots = config.ndpi_num_roots;
  else workflow->prefs.num_roots = NDPI_NUM_ROOTS;

  if (config.ndpi_max_flows) workflow->prefs.max_ndpi_flows = config.ndpi_max_flows;
  else workflow->prefs.max_ndpi_flows = NDPI_MAXFLOWS;

  if (config.ndpi_proto_guess) workflow->prefs.protocol_guess = config.ndpi_proto_guess;
  else workflow->prefs.protocol_guess = FALSE;

  if (config.ndpi_idle_scan_period) workflow->prefs.idle_scan_period = config.ndpi_idle_scan_period; 
  else workflow->prefs.idle_scan_period = NDPI_IDLE_SCAN_PERIOD;

  if (config.ndpi_idle_max_time) workflow->prefs.idle_max_time = config.ndpi_idle_max_time;
  else workflow->prefs.idle_max_time = NDPI_IDLE_MAX_TIME;

  if (config.ndpi_idle_scan_budget) workflow->prefs.idle_scan_budget = config.ndpi_idle_scan_budget;
  else workflow->prefs.idle_scan_budget = NDPI_IDLE_SCAN_BUDGET; 

  if (config.ndpi_giveup_proto_tcp) workflow->prefs.giveup_proto_tcp = config.ndpi_giveup_proto_tcp;
  else workflow->prefs.giveup_proto_tcp = NDPI_GIVEUP_PROTO_TCP;

  if (config.ndpi_giveup_proto_udp) workflow->prefs.giveup_proto_udp = config.ndpi_giveup_proto_udp;
  else workflow->prefs.giveup_proto_udp = NDPI_GIVEUP_PROTO_UDP;

  if (config.ndpi_giveup_proto_other) workflow->prefs.giveup_proto_other = config.ndpi_giveup_proto_other;
  else workflow->prefs.giveup_proto_other = NDPI_GIVEUP_PROTO_OTHER;

  workflow->ndpi_struct = module;

  if (workflow->ndpi_struct == NULL) {
    Log(LOG_ERR, "ERROR ( %s/core ): nDPI global structure initialization failed.\n", config.name);
    exit(1);
  }

  workflow->ndpi_flows_root = ndpi_calloc(workflow->prefs.num_roots, sizeof(void *));

  return workflow;
}
Beispiel #3
0
struct ndpi_LruCacheEntry* lru_allocCacheStringNode(struct ndpi_LruCache *cache, char *key, char *value, u_int32_t timeout) {
  struct ndpi_LruCacheEntry *node = (struct ndpi_LruCacheEntry*)ndpi_calloc(1, sizeof(struct ndpi_LruCacheEntry));

  if(unlikely(traceLRU))
    printf("%s(key=%s, value=%s)", __FUNCTION__, key, value);

  if(node == NULL)
    printf("ERROR: Not enough memory?");
  else {
    node->numeric_node = 0;
    node->u.str.key = ndpi_strdup(key), node->u.str.value = ndpi_strdup(value);
    node->u.str.expire_time = (timeout == 0) ? 0 : (compute_timeout(timeout) + get_now());

#ifdef FULL_STATS
    cache->mem_size += sizeof(struct ndpi_LruCacheEntry) + strlen(key) + strlen(value);
    //printf("%s(key=%s, value=%s) [memory: %u]", __FUNCTION__, key, value, cache->mem_size);
#endif
  }

  return(node);
}
Beispiel #4
0
struct ndpi_LruCacheEntry* lru_allocCacheNumericNode(struct ndpi_LruCache *cache, u_int64_t key, u_int64_t value) {
  struct ndpi_LruCacheEntry *node = (struct ndpi_LruCacheEntry*)ndpi_calloc(1, sizeof(struct ndpi_LruCacheEntry));

  if(unlikely(traceLRU))
    printf("%s(key=%lu, value=%u)", __FUNCTION__, 
	   (long unsigned int)key, (unsigned int)value);

  if(node == NULL)
    printf("ERROR: Not enough memory?");
  else {
    node->numeric_node = 1;
    node->u.num.key = key, node->u.num.value = value;
  }

#ifdef FULL_STATS
  cache->mem_size += sizeof(struct ndpi_LruCacheEntry);
  //printf("%s(key=%lu, value=%u) [memory: %u]", __FUNCTION__, key, value, cache->mem_size);
#endif

  return(node);
}