/*-
* Copyright (c) 2009-2013 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This material is based upon work partially supported by The
* NetBSD Foundation under a contract with Mindaugas Rasiukevicius.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* NPF extension and rule procedure interface.
*/
/*
* npf_rproc_create: construct a new rule procedure, lookup and associate
* the extension calls with it.
*/
npf_rproc_t *
npf_rproc_create(const nvlist_t *rproc)
{
const char *name;
npf_rproc_t *rp;
/*
* npf_rproc_acquire: acquire the reference on the rule procedure.
*/
void
npf_rproc_acquire(npf_rproc_t *rp)
{
atomic_inc_uint(&rp->rp_refcnt);
}
/*
* npf_rproc_getname: return the name of the given rproc
*/
const char *
npf_rproc_getname(const npf_rproc_t *rp)
{
return rp->rp_name;
}
/*
* npf_rproc_release: drop the reference count and destroy the rule
* procedure on the last reference.
*/
void
npf_rproc_release(npf_rproc_t *rp)
{
KASSERT(atomic_load_relaxed(&rp->rp_refcnt) > 0);
membar_release();
if (atomic_dec_uint_nv(&rp->rp_refcnt) != 0) {
return;
}
membar_acquire();
/* XXXintr */
for (unsigned i = 0; i < rp->rp_ext_count; i++) {
npf_ext_t *ext = rp->rp_ext[i];
const npf_ext_ops_t *extops = ext->ext_ops;
void
npf_rproc_assign(npf_rproc_t *rp, void *params)
{
unsigned i = rp->rp_ext_count;
/* Note: params may be NULL. */
KASSERT(i < RPROC_EXT_COUNT);
rp->rp_ext_meta[i] = params;
}
/*
* npf_rproc_run: run the rule procedure by executing each extension call.
*
* => Reference on the rule procedure must be held.
*/
bool
npf_rproc_run(npf_cache_t *npc, npf_rproc_t *rp, const npf_match_info_t *mi,
int *decision)
{
const unsigned extcount = rp->rp_ext_count;