Example #1
0
int output_register(struct output_reg_info *reg_info) {

	pomlog(POMLOG_DEBUG "Registering output %s", reg_info->name);

	if (reg_info->api_ver != OUTPUT_API_VER) {
		pomlog(POMLOG_ERR "Cannot register output as API version differ : expected %u got %u", OUTPUT_API_VER, reg_info->api_ver);
		return POM_ERR;
	}

	pom_mutex_lock(&output_lock);
	struct output_reg *output = malloc(sizeof(struct output_reg));
	if (!output) {
		pom_mutex_unlock(&output_lock);
		pom_oom(sizeof(struct output_reg));
		return POM_ERR;
	}
	memset(output, 0, sizeof(struct output_reg));
	output->reg_info = reg_info;

	if (registry_add_instance_type(output_registry_class, reg_info->name) != POM_OK) {
		pom_mutex_unlock(&output_lock);
		free(output);
		return POM_ERR;
	}

	output->next = output_reg_head;
	if (output->next)
		output->next->prev = output;
	output_reg_head = output;
	pom_mutex_unlock(&output_lock);

	mod_refcount_inc(reg_info->mod);

	return POM_OK;
}
Example #2
0
int input_register(struct input_reg_info *reg_info) {

	pomlog(POMLOG_DEBUG "Registering input %s", reg_info->name);

	if (reg_info->api_ver != INPUT_API_VER) {
		pomlog(POMLOG_ERR "API version of input %s does not match : expected %s got %s", reg_info->name, INPUT_API_VER, reg_info->api_ver);
		return POM_ERR;
	}

	struct input_reg *tmp;
	for (tmp = input_reg_head; tmp && strcmp(tmp->info->name, reg_info->name); tmp = tmp->next);
	if (tmp) {
		pomlog(POMLOG_ERR "Input %s already registered", reg_info->name);
		return POM_ERR;
	}

	struct input_reg *reg = malloc(sizeof(struct input_reg));
	if(!reg) {
		pom_oom(sizeof(struct input_reg));
		return POM_ERR;
	}

	memset(reg, 0, sizeof(struct input_reg));
	reg->info = reg_info;

	if (registry_add_instance_type(input_registry_class, reg_info->name) != POM_OK) {
		free(reg);
		return POM_ERR;
	}

	mod_refcount_inc(reg_info->mod);

	reg->next = input_reg_head;
	input_reg_head = reg;
	if (reg->next)
		reg->next->prev = reg;

	return POM_OK;

}
Example #3
0
int decoder_register(char *name, struct decoder_reg_info *reg_info) {

	pomlog(POMLOG_DEBUG "Registering decoder %s", name);

	struct decoder_reg *decoder = malloc(sizeof(struct decoder_reg));
	if (!decoder) {
		pom_oom(sizeof(struct decoder_reg));
		return POM_ERR;
	}
	memset(decoder, 0, sizeof(struct decoder_reg));
	decoder->info = reg_info;
	decoder->name = name;

	decoder->next = decoder_reg_head;
	if (decoder->next)
		decoder->next->prev = decoder;
	decoder_reg_head = decoder;

	mod_refcount_inc(reg_info->mod);

	return POM_OK;
}
Example #4
0
File: ptype.c Project: k0a1a/pom-ng
int ptype_register(struct ptype_reg_info *reg_info, struct mod_reg *mod) {

	pomlog(POMLOG_DEBUG "Registering ptype %s", reg_info->name);

	if (reg_info->api_ver != PTYPE_API_VER) {
		pomlog(POMLOG_ERR "API version of ptype %s does not match : expected %u got %u", reg_info->name, PTYPE_API_VER, reg_info->api_ver);
		return POM_ERR;
	}

	struct ptype_reg *reg = malloc(sizeof(struct ptype_reg));
	if (!reg) {
		pom_oom(sizeof(struct ptype_reg));
		return POM_ERR;
	}
	memset(reg, 0, sizeof(struct ptype_reg));

	struct ptype_reg *tmp;
	for (tmp = ptype_reg_head; tmp && strcmp(tmp->info->name, reg_info->name); tmp = tmp->next);
	if (tmp) {
		pomlog(POMLOG_ERR "Ptype %s already registered", reg_info->name);
		free(reg);
		return POM_ERR;
	}

	reg->info = reg_info;
	reg->module = mod;

	mod_refcount_inc(mod);

	reg->next = ptype_reg_head;
	ptype_reg_head = reg;
	if (reg->next)
		reg->next->prev = reg;

	return POM_OK;
}
Example #5
0
int proto_register(struct proto_reg_info *reg_info) {

    if (reg_info->api_ver != PROTO_API_VER) {
        pomlog(POMLOG_ERR "Cannot register proto as API version differ : expected %u got %u", PROTO_API_VER, reg_info->api_ver);
        return POM_ERR;
    }


    // Check if the protocol already exists
    struct proto *proto;
    for (proto = proto_head; proto && strcmp(proto->info->name, reg_info->name); proto = proto->next);
    if (proto)
        return POM_ERR;

    // Allocate the protocol
    proto = malloc(sizeof(struct proto));
    if (!proto) {
        pom_oom(sizeof(struct proto));
        return POM_ERR;
    }

    memset(proto, 0, sizeof(struct proto));
    proto->info = reg_info;
    proto->id = proto_count;
    proto_count++;

    if (reg_info->number_class) {
        proto->number_class = proto_number_class_get(reg_info->number_class);
        if (!proto->number_class)
            goto err_proto;
    }

    int res = pthread_rwlock_init(&proto->expectation_lock, NULL);
    if (res) {
        pomlog(POMLOG_ERR "Error while initializing the proto_expectation rwlock : %s", pom_strerror(res));
        goto err_proto;
    }

    res = pthread_rwlock_init(&proto->listeners_lock, NULL);
    if (res) {
        pomlog(POMLOG_ERR "Error while initializing the proto_listeners rwlock : %s", pom_strerror(res));
        goto err_lock1;
    }

    proto->reg_instance = registry_add_instance(proto_registry_class, reg_info->name);
    if (!proto->reg_instance) {
        pomlog(POMLOG_ERR "Error while adding the registry instanc for protocol %s", reg_info->name);
        goto err_lock;
    }


    // Allocate the conntrack table
    if (reg_info->ct_info) {
        proto->ct = conntrack_table_alloc(reg_info->ct_info->default_table_size, (reg_info->ct_info->rev_pkt_field_id == -1 ? 0 : 1));
        if (!proto->ct) {
            pomlog(POMLOG_ERR "Error while allocating conntrack tables");
            goto err_registry;
        }

        proto->perf_conn_cur = registry_instance_add_perf(proto->reg_instance, "conn_cur", registry_perf_type_gauge, "Current number of monitored connection", "connections");
        proto->perf_conn_tot = registry_instance_add_perf(proto->reg_instance, "conn_tot", registry_perf_type_counter, "Total number of connections", "connections");
        proto->perf_conn_hash_col = registry_instance_add_perf(proto->reg_instance, "conn_hash_col", registry_perf_type_counter, "Total number of conntrack hash collisions", "collisions");

        if (!proto->perf_conn_cur || !proto->perf_conn_tot || !proto->perf_conn_hash_col)
            goto err_conntrack;

    }

    proto->perf_pkts = registry_instance_add_perf(proto->reg_instance, "pkts", registry_perf_type_counter, "Number of packets processed", "pkts");
    proto->perf_bytes = registry_instance_add_perf(proto->reg_instance, "bytes", registry_perf_type_counter, "Number of bytes processed", "bytes");
    proto->perf_expt_pending = registry_instance_add_perf(proto->reg_instance, "expectations_pending", registry_perf_type_gauge, "Number of expectations pending", "expectations");
    proto->perf_expt_matched = registry_instance_add_perf(proto->reg_instance, "expectations_matched", registry_perf_type_counter, "Number of expectations matched", "expectations");

    if (!proto->perf_pkts || !proto->perf_bytes || !proto->perf_expt_pending || !proto->perf_expt_matched)
        goto err_conntrack;

    if (reg_info->init) {
        if (reg_info->init(proto, proto->reg_instance) == POM_ERR) {
            pomlog(POMLOG_ERR "Error while registering proto %s", reg_info->name);
            goto err_conntrack;
        }
    }

    mod_refcount_inc(reg_info->mod);

    proto->next = proto_head;
    if (proto->next)
        proto->next->prev = proto;
    proto_head = proto;

    pomlog(POMLOG_DEBUG "Proto %s registered", reg_info->name);

    return POM_OK;

err_conntrack:
    // Remove proto number if any
    proto_number_unregister(proto);
    conntrack_table_cleanup(proto->ct);
err_registry:
    registry_remove_instance(proto->reg_instance);
err_lock:
    pthread_rwlock_destroy(&proto->listeners_lock);
err_lock1:
    pthread_rwlock_destroy(&proto->expectation_lock);
err_proto:
    free(proto);

    return POM_ERR;

}