Ejemplo n.º 1
0
char* ss_conf_path_get() {
    size_t path_size = PATH_MAX;
    char* program_directory = NULL;

    char* program_path = je_calloc(1, path_size);
    if (program_path == NULL) {
        goto error_out;
    }

    ssize_t rv = readlink(PROGRAM_PATH, program_path, path_size);
    if (rv < 0) {
        goto error_out;
    }

    char* directory = dirname(program_path);

    program_directory = je_calloc(1, path_size);
    if (program_directory == NULL) {
        goto error_out;
    }

    strlcpy(program_directory, directory, path_size);
    strlcat(program_directory, CONF_PATH, path_size);

error_out:
    if (program_path) je_free(program_path);

    return program_directory;
}
Ejemplo n.º 2
0
sflow_socket_t* sflow_socket_create(sflow_key_t* key, ss_frame_t* rx_buf) {
    int is_error = 0;

    sflow_key_dump("create socket for key", key);
    // XXX: should these be allocated from jemalloc or RTE alloc?
    sflow_socket_t* socket = je_calloc(1, sizeof(sflow_socket_t));
    if (socket == NULL) { is_error = 1; goto error_out; }

    sflow_socket_init(key, socket);

    rte_rwlock_write_lock(&sflow_hash_lock);
    int32_t socket_id = rte_hash_add_key(sflow_hash, key);
    socket->id = (uint64_t) socket_id;
    if (socket_id >= 0) {
        sflow_sockets[socket->id] = socket;
    }
    else {
        is_error = 1;
    }
    rte_rwlock_write_unlock(&sflow_hash_lock);

    // XXX: figure out what should be in this
    //RTE_LOG(INFO, L3L4, "new sflow socket: sport: %hu dport: %hu id: %lu is_error: %d\n",
    //    rte_bswap16(key->sport), rte_bswap16(key->dport), socket->id, is_error);

    error_out:
    if (unlikely(is_error)) {
        if (socket) { je_free(socket); socket = NULL; }
        RTE_LOG(ERR, L3L4, "failed to allocate sflow socket\n");
        return NULL;
    }

    return socket;
}
Ejemplo n.º 3
0
void* fs_calloc(size_t n, size_t size){
#ifdef JEMALLOC_HAVE_ATTR
    return je_calloc(n, size);
#else
    
    return calloc(n, size);
#endif
    
}
Ejemplo n.º 4
0
void*
calloc_impl(size_t num, size_t size)
{
  if (MOZ_UNLIKELY(!replace_malloc_initialized))
    init();
  if (MOZ_LIKELY(!replace_calloc))
    return je_calloc(num, size);
  return replace_calloc(num, size);
}
Ejemplo n.º 5
0
int main (void)
{
	size_t i;
	char * ptrs[num];
	MALLOC_INIT();
	for (i = 0; i < num; i++)
	{
		size_t size = (rand() % (max_size - min_size)) + min_size;
		ptrs[i] = je_calloc(size, 1);
		memset(ptrs[i], 1, size);
	}
	for (i = 0; i < num; i++)
		je_free(ptrs[i]);
	return 0;
}
Ejemplo n.º 6
0
static void *
zone_calloc(malloc_zone_t *zone, size_t num, size_t size)
{

	return (je_calloc(num, size));
}
Ejemplo n.º 7
0
ss_conf_t* ss_conf_file_parse(char* conf_path) {
    int is_ok = 1;
    int rv;
    char* conf_buffer            = NULL;
    json_object* json_underlying = NULL;
    json_object* items           = NULL;
    json_object* item            = NULL;
    json_error_t json_error      = json_tokener_success;

    conf_buffer                  = ss_conf_file_read(conf_path);
    if (conf_buffer == NULL) {
        fprintf(stderr, "conf file read error\n");
        is_ok = 0;
        goto error_out;
    }

    json_underlying = json_tokener_parse_verbose(conf_buffer, &json_error);
    if (json_underlying == NULL) {
        is_ok = 0;
        fprintf(stderr, "json parse error: %s\n", json_tokener_error_desc(json_error));
        is_ok = 0;
        goto error_out;
    }

    ss_conf = je_calloc(1, sizeof(ss_conf_t));
    if (ss_conf == NULL) {
        fprintf(stderr, "could not allocate sdn_sensor configuration\n");
        is_ok = 0;
        goto error_out;
    }

    ss_conf->json = json_object_get(json_underlying);
    is_ok         = json_object_is_type(ss_conf->json, json_type_object);
    if (!is_ok) {
        is_ok = 0;
        fprintf(stderr, "json configuration root is not object\n");
        is_ok = 0;
        goto error_out;
    }

    //const char* content = json_object_to_json_string_ext(ss_conf->json, JSON_C_TO_STRING_PRETTY);
    //fprintf(stderr, "json configuration:\n%s\n", content);

    TAILQ_INIT(&ss_conf->re_chain.re_list);
    TAILQ_INIT(&ss_conf->pcap_chain.pcap_list);
    TAILQ_INIT(&ss_conf->dns_chain.dns_list);
    TAILQ_INIT(&ss_conf->ioc_chain.ioc_list);

    items = ss_json_object_get(ss_conf->json, "network");
    if (items == NULL) {
        fprintf(stderr, "could not load network configuration\n");
        is_ok = 0;
        goto error_out;
    }
    if (!json_object_is_type(items, json_type_object)) {
        fprintf(stderr, "network configuration is not object\n");
        is_ok = 0;
        goto error_out;
    }

    rv = ss_conf_network_parse(items);
    if (rv) {
        fprintf(stderr, "could not parse network configuration\n");
        is_ok = 0;
        goto error_out;
    }

    items = ss_json_object_get(ss_conf->json, "dpdk");
    if (items == NULL) {
        fprintf(stderr, "could not load dpdk configuration\n");
        is_ok = 0;
        goto error_out;
    }
    if (!json_object_is_type(items, json_type_object)) {
        fprintf(stderr, "dpdk configuration is not object\n");
        is_ok = 0;
        goto error_out;
    }

    rv = ss_conf_dpdk_parse(items);
    if (rv) {
        fprintf(stderr, "could not parse dpdk configuration\n");
        is_ok = 0;
        goto error_out;
    }

    items = ss_json_object_get(ss_conf->json, "re_chain");
    if (items) {
        is_ok = json_object_is_type(items, json_type_array);
        if (!is_ok) {
            fprintf(stderr, "re_chain is not an array\n");
            goto error_out;
        }
        int length = json_object_array_length(items);
        for (int i = 0; i < length; ++i) {
            item = json_object_array_get_idx(items, i);
            ss_re_entry_t* entry = ss_re_entry_create(item);
            /*
            if (entry == NULL) {
                fprintf(stderr, "could not create re_chain entry\n");
                if (entry) je_free(entry);
                is_ok = 0; goto error_out;
            }
            */
            if (entry == NULL) {
                fprintf(stderr, "could not create re_chain entry %d\n", i);
                ss_re_entry_destroy(entry);
                is_ok = 0;
                goto error_out;
            }
            ss_re_chain_add(entry);
        }
    }

    items = ss_json_object_get(ss_conf->json, "pcap_chain");
    if (items) {
        is_ok = json_object_is_type(items, json_type_array);
        if (!is_ok) {
            fprintf(stderr, "pcap_chain is not an array\n");
            goto error_out;
        }
        int length = json_object_array_length(items);
        for (int i = 0; i < length; ++i) {
            item = json_object_array_get_idx(items, i);
            ss_pcap_entry_t* entry = ss_pcap_entry_create(item);
            if (entry == NULL) {
                fprintf(stderr, "could not create pcap_chain entry %d\n", i);
                ss_pcap_entry_destroy(entry);
                is_ok = 0;
                goto error_out;
            }
            ss_pcap_chain_add(entry);
        }
    }

    items = ss_json_object_get(ss_conf->json, "dns_chain");
    if (items) {
        is_ok = json_object_is_type(items, json_type_array);
        if (!is_ok) {
            fprintf(stderr, "dns_chain is not an array\n");
            goto error_out;
        }
        int length = json_object_array_length(items);
        for (int i = 0; i < length; ++i) {
            item = json_object_array_get_idx(items, i);
            ss_dns_entry_t* entry = ss_dns_entry_create(item);
            if (entry == NULL) {
                fprintf(stderr, "could not create dns_chain entry %d\n", i);
                ss_dns_entry_destroy(entry);
                is_ok = 0;
                goto error_out;
            }
            ss_dns_chain_add(entry);
        }
    }

    items = ss_json_object_get(ss_conf->json, "cidr_table");
    if (items) {
        is_ok = json_object_is_type(items, json_type_array);
        if (!is_ok) {
            fprintf(stderr, "cidr_table is not an array\n");
            goto error_out;
        }
        int length = json_object_array_length(items);
        for (int i = 0; i < length; ++i) {
            item = json_object_array_get_idx(items, i);
            ss_cidr_entry_t* entry = ss_cidr_entry_create(item);
            /*
            if (entry == NULL) {
                fprintf(stderr, "could not create cidr_table entry %d\n", i);
                ss_cidr_entry_destroy(entry);
                is_ok = 0; goto error_out;
            }
            */
            ss_cidr_table_add(&ss_conf->cidr_table, entry);
        }
    }

    // XXX: do more stuff
error_out:
    if (conf_buffer)        {
        je_free(conf_buffer);
        conf_buffer = NULL;
    }
    if (!is_ok && ss_conf)  {
        ss_conf_destroy();
        ss_conf     = NULL;
    }

    return ss_conf;
}
Ejemplo n.º 8
0
char* ss_conf_file_read(char* conf_path) {
    int is_ok = 1;
    int free_conf_path = 0;
    int rv;
    size_t srv;
    char* conf_content = NULL;

    if (conf_path == NULL) {
        conf_path = ss_conf_path_get();
        free_conf_path = 1;
    }

    FILE* conf_file = fopen(conf_path, "rb");
    if (conf_file == NULL) {
        is_ok = 0;
        fprintf(stderr, "error: could not open configuration file %s\n", conf_path);
        goto error_out;
    }

    rv = fseek(conf_file, 0L, SEEK_END);
    if (rv == -1) {
        is_ok = 0;
        fprintf(stderr, "error: could not seek to end of configuration file\n");
        goto error_out;
    }

    long size = ftell(conf_file);
    if (size == -1) {
        is_ok = 0;
        fprintf(stderr, "error: could not get size of configuration file\n");
        goto error_out;
    }

    rewind(conf_file);

    /* make room for terminating NUL */
    conf_content = je_calloc(1, (size_t) (size + 1));
    if (conf_content == NULL) {
        is_ok = 0;
        fprintf(stderr, "error: could not allocate configuration file buffer\n");
        goto error_out;
    }

    srv = fread(conf_content, 1, (size_t) size, conf_file);
    if (srv != (size_t) size) {
        is_ok = 0;
        fprintf(stderr, "error: could not load configuration file\n");
        goto error_out;
    }

    /* insert terminating NUL */
    conf_content[size - 1] = '\0';

error_out:
    if (free_conf_path)         {
        je_free(conf_path);
        conf_path    = NULL;
    }
    if (conf_file)              {
        fclose(conf_file);
        conf_file    = NULL;
    }
    if (!is_ok && conf_content) {
        je_free(conf_content);
        conf_content = NULL;
    }

    return conf_content;
}
Ejemplo n.º 9
0
void *
skynet_calloc(size_t nmemb,size_t size) {
	void* ptr = je_calloc(nmemb + ((PREFIX_SIZE+size-1)/size), size );
	if(!ptr) malloc_oom(size);
	return fill_prefix(ptr);
}
Ejemplo n.º 10
0
extern "C" void* wrap(calloc)(size_t num, size_t sz)
{
	return je_calloc(num, sz);
}
Ejemplo n.º 11
0
/* Allocate a new packet (XXX: make this use a pool of preallocated entries) */
struct flow_packet* flow_packet_alloc(void)
{
    return (je_calloc(1, sizeof(struct flow_packet)));
}