Esempio n. 1
0
static npf_rproc_t *
npf_mk_singlerproc(prop_dictionary_t rpdict)
{
	prop_object_iterator_t it;
	prop_dictionary_t extdict;
	prop_array_t extlist;
	npf_rproc_t *rp;

	extlist = prop_dictionary_get(rpdict, "extcalls");
	if (prop_object_type(extlist) != PROP_TYPE_ARRAY) {
		return NULL;
	}

	rp = npf_rproc_create(rpdict);
	if (rp == NULL) {
		return NULL;
	}

	it = prop_array_iterator(extlist);
	while ((extdict = prop_object_iterator_next(it)) != NULL) {
		const char *name;

		if (!prop_dictionary_get_cstring_nocopy(extdict,
		    "name", &name) || npf_ext_construct(name, rp, extdict)) {
			npf_rproc_release(rp);
			rp = NULL;
			break;
		}
	}
	prop_object_iterator_release(it);
	return rp;
}
Esempio n. 2
0
static npf_rproc_t *
npf_mk_rproc(prop_array_t rprocs, const char *rpname)
{
	prop_object_iterator_t it;
	prop_dictionary_t rpdict;
	npf_rproc_t *rp;
	uint64_t rpval;

	it = prop_array_iterator(rprocs);
	while ((rpdict = prop_object_iterator_next(it)) != NULL) {
		const char *iname;
		prop_dictionary_get_cstring_nocopy(rpdict, "name", &iname);
		KASSERT(iname != NULL);
		if (strcmp(rpname, iname) == 0)
			break;
	}
	prop_object_iterator_release(it);
	if (rpdict == NULL) {
		return NULL;
	}
	CTASSERT(sizeof(uintptr_t) <= sizeof(uint64_t));
	if (!prop_dictionary_get_uint64(rpdict, "rproc-ptr", &rpval)) {
		rp = npf_rproc_create(rpdict);
		rpval = (uint64_t)(uintptr_t)rp;
		prop_dictionary_set_uint64(rpdict, "rproc-ptr", rpval);
	} else {
		rp = (npf_rproc_t *)(uintptr_t)rpval;
	}
	return rp;
}
Esempio n. 3
0
/*
 * npfctl_build_rproc: create and insert a rule procedure.
 */
void
npfctl_build_rproc(const char *name, npfvar_t *procs)
{
	nl_rproc_t *rp;
	size_t i;

	rp = npf_rproc_create(name);
	if (rp == NULL) {
		errx(EXIT_FAILURE, "npf_rproc_create failed");
	}
	npf_rproc_insert(npf_conf, rp);

	for (i = 0; i < npfvar_get_count(procs); i++) {
		proc_op_t *po = npfvar_get_data(procs, NPFVAR_PROC_OP, i);
		npfctl_build_rpcall(rp, po->po_name, po->po_opts);
	}
}