opnsense-src/sys/sys/module_khelp.h
Lawrence Stewart a8d61afdc2 - Introduce the Hhook (Helper Hook) KPI. The KPI is closely modelled on pfil(9),
and in many respects can be thought of as a more generic superset of pfil.
  Hhook provides a way for kernel subsystems to export hook points that Khelp
  modules can hook to provide enhanced or new functionality to the kernel. The
  KPI has been designed to ensure hook points pose no noticeable overhead when
  no hook functions are registered.

- Introduce the Khelp (Kernel Helpers) KPI. Khelp provides a framework for
  managing Khelp modules, which indirectly use the Hhook KPI to register their
  hook functions with hook points of interest within the kernel. Khelp modules
  aim to provide a structured way to dynamically extend the kernel at runtime in
  an ABI preserving manner. Depending on the subsystem providing hook points, a
  Khelp module may be able to associate per-object data for maintaining relevant
  state between hook calls.

- pjd's Object Specific Data (OSD) KPI is used to manage the per-object data
  allocated to Khelp modules. Create a new "OSD_KHELP" OSD type for use by the
  Khelp framework.

- Bump __FreeBSD_version to 900028 to mark the introduction of the new KPIs.

In collaboration with:	David Hayes <dahayes at swin edu au> and
			Grenville Armitage <garmitage at swin edu au>
Sponsored by:	FreeBSD Foundation
Reviewed by:	bz, others along the way
MFC after:	3 months
2010-12-21 13:45:29 +00:00

110 lines
3.8 KiB
C

/*-
* Copyright (c) 2010 Lawrence Stewart <lstewart@freebsd.org>
* Copyright (c) 2010 The FreeBSD Foundation
* All rights reserved.
*
* This software was developed by Lawrence Stewart while studying at the Centre
* for Advanced Internet Architectures, Swinburne University, made possible in
* part by grants from the FreeBSD Foundation and Cisco University Research
* Program Fund at Community Foundation Silicon Valley.
*
* Portions of this software were developed at the Centre for Advanced
* Internet Architectures, Swinburne University of Technology, Melbourne,
* Australia by Lawrence Stewart under sponsorship from the FreeBSD Foundation.
*
* 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 AUTHOR 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 AUTHOR 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.
*
* $FreeBSD$
*/
#ifndef _SYS_MODULE_KHELP_H_
#define _SYS_MODULE_KHELP_H_
/* XXXLAS: Needed for uma related typedefs. */
#include <vm/uma.h>
/* Helper flags. */
#define HELPER_NEEDS_OSD 0x0001
struct helper {
int (*mod_init) (void);
int (*mod_destroy) (void);
#define HELPER_NAME_MAXLEN 16
char h_name[HELPER_NAME_MAXLEN];
uma_zone_t h_zone;
struct hookinfo *h_hooks;
uint32_t h_nhooks;
uint32_t h_classes;
int32_t h_id;
volatile uint32_t h_refcount;
uint16_t h_flags;
TAILQ_ENTRY(helper) h_next;
};
struct khelp_modevent_data {
char name[HELPER_NAME_MAXLEN];
struct helper *helper;
struct hookinfo *hooks;
int nhooks;
int uma_zsize;
uma_ctor umactor;
uma_dtor umadtor;
};
#define KHELP_DECLARE_MOD(hname, hdata, hhooks, version) \
static struct khelp_modevent_data kmd_##hname = { \
.name = #hname, \
.helper = hdata \
.hooks = hhooks, \
.nhooks = sizeof(hhooks) / sizeof(hhooks[0]), \
}; \
static moduledata_t h_##hname = { \
.name = #hname, \
.evhand = khelp_modevent, \
.priv = &kmd_##hname \
}; \
DECLARE_MODULE(hname, h_##hname, SI_SUB_PROTO_IFATTACHDOMAIN, \
SI_ORDER_ANY); \
MODULE_VERSION(hname, version)
#define KHELP_DECLARE_MOD_UMA(hname, hdata, hhooks, version, size, ctor, dtor) \
static struct khelp_modevent_data kmd_##hname = { \
.name = #hname, \
.helper = hdata, \
.hooks = hhooks, \
.nhooks = sizeof(hhooks) / sizeof(hhooks[0]), \
.uma_zsize = size, \
.umactor = ctor, \
.umadtor = dtor \
}; \
static moduledata_t h_##hname = { \
.name = #hname, \
.evhand = khelp_modevent, \
.priv = &kmd_##hname \
}; \
DECLARE_MODULE(hname, h_##hname, SI_SUB_PROTO_IFATTACHDOMAIN, \
SI_ORDER_ANY); \
MODULE_VERSION(hname, version)
int khelp_modevent(module_t mod, int type, void *data);
#endif /* _SYS_MODULE_KHELP_H_ */