Esempio n. 1
0
static int output_inject_init(struct output *o) {


	struct output_inject_priv *priv = malloc(sizeof(struct output_inject_priv));
	if (!priv) {
		pom_oom(sizeof(struct output_inject_priv));
		return POM_ERR;
	}
	memset(priv, 0, sizeof(struct output_inject_priv));
	output_set_priv(o, priv);

	priv->p_interface = ptype_alloc("string");
	priv->p_filter = ptype_alloc("string");

	if (!priv->p_interface || !priv->p_filter)
		goto err;

	struct registry_instance *inst = output_get_reg_instance(o);
	priv->perf_pkts_out = registry_instance_add_perf(inst, "pkts_out", registry_perf_type_counter, "Number of packets injected", "pkts");
	priv->perf_bytes_out = registry_instance_add_perf(inst, "bytes_out", registry_perf_type_counter, "Number of packet bytes injected", "bytes");

	char err[PCAP_ERRBUF_SIZE] = { 0 };
	char *dev = pcap_lookupdev(err);
	if (!dev) {
		pomlog(POMLOG_WARN,  "Warning, could not find a suitable interface to inject packets to : %s", err);
		dev = "none";
	}

	struct registry_param *p = registry_new_param("interface", dev, priv->p_interface, "Output interface", 0);
	if (output_add_param(o, p) != POM_OK)
		goto err;
	
	p = registry_new_param("filter", "", priv->p_filter, "Filter", REGISTRY_PARAM_FLAG_NOT_LOCKED_WHILE_RUNNING);
	if (output_add_param(o, p) != POM_OK)
		goto err;

	registry_param_set_callbacks(p, priv, output_inject_filter_parse, output_inject_filter_update);

	return POM_OK;

err:
	output_inject_cleanup(priv);
	return POM_ERR;

}
Esempio n. 2
0
int output_tap_init(struct output *o) {

	struct output_tap_priv *priv = tap_init();

	if (!priv)
		return POM_ERR;

	output_set_priv(o, priv);

	struct registry_instance *inst = output_get_reg_instance(o);
	priv->perf_pkts_out = registry_instance_add_perf(inst, "pkts_out", registry_perf_type_counter, "Number of packets processed", "pkts");
	priv->perf_bytes_out = registry_instance_add_perf(inst, "bytes_out", registry_perf_type_counter, "Number of bytes processed", "bytes");

	if (!priv->perf_pkts_out || !priv->perf_bytes_out)
		goto err;

	struct registry_param *p = registry_new_param("ifname", "pom0", priv->p_ifname, "Name of the interface to create", 0);
	if (output_add_param(o, p) != POM_OK)
		goto err;

	p = registry_new_param("persistent", "no", priv->p_persistent, "Create a persistent interface", 0);
	if (output_add_param(o, p) != POM_OK)
		goto err;

	p = registry_new_param("filter", "", priv->p_filter, "Filter", REGISTRY_PARAM_FLAG_NOT_LOCKED_WHILE_RUNNING);
	if (output_add_param(o, p) != POM_OK)
		goto err;

	registry_param_set_callbacks(p, priv, output_tap_filter_parse, output_tap_filter_update);
	
	return POM_OK;
err:
	output_tap_cleanup(priv);
	return POM_ERR;

}
Esempio n. 3
0
int output_instance_add(char *type, char *name) {

	struct output_reg *reg;
	for (reg = output_reg_head; reg && strcmp(reg->reg_info->name, type); reg = reg->next);

	if (!reg) {
		pomlog(POMLOG_ERR "Output type %s does not exists", type);
		return POM_ERR;
	}

	struct output *res = malloc(sizeof(struct output));
	if (!res) {
		pom_oom(sizeof(struct output));
		return POM_ERR;
	}
	memset(res, 0, sizeof(struct output));
	res->info = reg;
	res->name = strdup(name);
	if (!res->name) {
		pom_oom(strlen(name) + 1);
		goto err;
	}

	res->reg_instance = registry_add_instance(output_registry_class, name);
	if (!res->reg_instance)
		goto err;

	res->reg_instance->priv = res;

	res->perf_runtime = registry_instance_add_perf(res->reg_instance, "runtime", registry_perf_type_timeticks, "Runtime", NULL);
	if (!res->perf_runtime)
		goto err;

	struct ptype *param_running_val = ptype_alloc("bool");
	if (!param_running_val)
		goto err;

	struct registry_param *param_running = registry_new_param("running", "no", param_running_val, "Running state of the output",  REGISTRY_PARAM_FLAG_CLEANUP_VAL);
	if (!param_running) {
		ptype_cleanup(param_running_val);
		goto err;
	}

	if (registry_param_set_callbacks(param_running, res, NULL, output_instance_start_stop_handler) != POM_OK) {
		registry_cleanup_param(param_running);
		ptype_cleanup(param_running_val);
		goto err;
	}
	
	if (registry_instance_add_param(res->reg_instance, param_running) != POM_OK) {
		registry_cleanup_param(param_running);
		ptype_cleanup(param_running_val);
		goto err;
	}


	struct ptype *output_type = ptype_alloc("string");
	if (!output_type)
		goto err;

	struct registry_param *type_param = registry_new_param("type", type, output_type, "Type of the output", REGISTRY_PARAM_FLAG_CLEANUP_VAL | REGISTRY_PARAM_FLAG_IMMUTABLE);
	if (!type_param) {
		ptype_cleanup(output_type);
		goto err;
	}

	if (registry_instance_add_param(res->reg_instance, type_param) != POM_OK) {
		registry_cleanup_param(type_param);
		ptype_cleanup(output_type);
		goto err;
	}

	if (registry_uid_create(res->reg_instance) != POM_OK)
		goto err;

	if (reg->reg_info->init) {
		if (reg->reg_info->init(res) != POM_OK) {
			pomlog(POMLOG_ERR "Error while initializing the output %s", name);
			goto err;
		}
	}

	res->next = output_head;
	if (res->next)
		res->next->prev = res;
	output_head = res;

	return POM_OK;

err:
	if (res->reg_instance) {
		registry_remove_instance(res->reg_instance);
	} else {
		if (res->name)
			free(res->name);
		free(res);
	}

	return POM_ERR;
}