FreeBSD kernel kern code
kern_hhook.c File Reference
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/hhook.h>
#include <sys/khelp.h>
#include <sys/malloc.h>
#include <sys/module.h>
#include <sys/module_khelp.h>
#include <sys/osd.h>
#include <sys/queue.h>
#include <sys/refcount.h>
#include <sys/systm.h>
#include <net/vnet.h>
Include dependency graph for kern_hhook.c:

Go to the source code of this file.

Data Structures

struct  hhook
 

Macros

#define V_hhook_vhead_list   VNET(hhook_vhead_list)
 
#define HHHLIST_LOCK()   mtx_lock(&hhook_head_list_lock)
 
#define HHHLIST_UNLOCK()   mtx_unlock(&hhook_head_list_lock)
 
#define HHHLIST_LOCK_ASSERT()   mtx_assert(&hhook_head_list_lock, MA_OWNED)
 
#define HHH_LOCK_INIT(hhh)   rm_init(&(hhh)->hhh_lock, "hhook_head rm lock")
 
#define HHH_LOCK_DESTROY(hhh)   rm_destroy(&(hhh)->hhh_lock)
 
#define HHH_WLOCK(hhh)   rm_wlock(&(hhh)->hhh_lock)
 
#define HHH_WUNLOCK(hhh)   rm_wunlock(&(hhh)->hhh_lock)
 
#define HHH_RLOCK(hhh, rmpt)   rm_rlock(&(hhh)->hhh_lock, (rmpt))
 
#define HHH_RUNLOCK(hhh, rmpt)   rm_runlock(&(hhh)->hhh_lock, (rmpt))
 

Functions

 __FBSDID ("$FreeBSD$")
 
static MALLOC_DEFINE (M_HHOOK, "hhook", "Helper hooks are linked off hhook_head lists")
 
 LIST_HEAD (hhookheadhead, hhook_head)
 
 VNET_DEFINE (struct hhookheadhead, hhook_vhead_list)
 
 MTX_SYSINIT (hhookheadlistlock, &hhook_head_list_lock, "hhook_head list lock", MTX_DEF)
 
static void hhook_head_destroy (struct hhook_head *hhh)
 
void khelp_new_hhook_registered (struct hhook_head *hhh, uint32_t flags)
 
void hhook_run_hooks (struct hhook_head *hhh, void *ctx_data, struct osd *hosd)
 
int hhook_add_hook (struct hhook_head *hhh, struct hookinfo *hki, uint32_t flags)
 
int hhook_add_hook_lookup (struct hookinfo *hki, uint32_t flags)
 
int hhook_remove_hook (struct hhook_head *hhh, struct hookinfo *hki)
 
int hhook_remove_hook_lookup (struct hookinfo *hki)
 
int hhook_head_register (int32_t hhook_type, int32_t hhook_id, struct hhook_head **hhh, uint32_t flags)
 
int hhook_head_deregister (struct hhook_head *hhh)
 
int hhook_head_deregister_lookup (int32_t hhook_type, int32_t hhook_id)
 
struct hhook_head * hhook_head_get (int32_t hhook_type, int32_t hhook_id)
 
void hhook_head_release (struct hhook_head *hhh)
 
uint32_t hhook_head_is_virtualised (struct hhook_head *hhh)
 
uint32_t hhook_head_is_virtualised_lookup (int32_t hook_type, int32_t hook_id)
 
static void hhook_vnet_init (const void *unused __unused)
 
static void hhook_vnet_uninit (const void *unused __unused)
 
 VNET_SYSINIT (hhook_vnet_init, SI_SUB_INIT_IF, SI_ORDER_FIRST, hhook_vnet_init, NULL)
 
 VNET_SYSUNINIT (hhook_vnet_uninit, SI_SUB_INIT_IF, SI_ORDER_FIRST, hhook_vnet_uninit, NULL)
 

Variables

struct hhookheadhead hhook_head_list
 
static struct mtx hhook_head_list_lock
 
static uint32_t n_hhookheads
 

Macro Definition Documentation

◆ HHH_LOCK_DESTROY

#define HHH_LOCK_DESTROY (   hhh)    rm_destroy(&(hhh)->hhh_lock)

Definition at line 86 of file kern_hhook.c.

◆ HHH_LOCK_INIT

#define HHH_LOCK_INIT (   hhh)    rm_init(&(hhh)->hhh_lock, "hhook_head rm lock")

Definition at line 85 of file kern_hhook.c.

◆ HHH_RLOCK

#define HHH_RLOCK (   hhh,
  rmpt 
)    rm_rlock(&(hhh)->hhh_lock, (rmpt))

Definition at line 89 of file kern_hhook.c.

◆ HHH_RUNLOCK

#define HHH_RUNLOCK (   hhh,
  rmpt 
)    rm_runlock(&(hhh)->hhh_lock, (rmpt))

Definition at line 90 of file kern_hhook.c.

◆ HHH_WLOCK

#define HHH_WLOCK (   hhh)    rm_wlock(&(hhh)->hhh_lock)

Definition at line 87 of file kern_hhook.c.

◆ HHH_WUNLOCK

#define HHH_WUNLOCK (   hhh)    rm_wunlock(&(hhh)->hhh_lock)

Definition at line 88 of file kern_hhook.c.

◆ HHHLIST_LOCK

#define HHHLIST_LOCK ( )    mtx_lock(&hhook_head_list_lock)

Definition at line 81 of file kern_hhook.c.

◆ HHHLIST_LOCK_ASSERT

#define HHHLIST_LOCK_ASSERT ( )    mtx_assert(&hhook_head_list_lock, MA_OWNED)

Definition at line 83 of file kern_hhook.c.

◆ HHHLIST_UNLOCK

#define HHHLIST_UNLOCK ( )    mtx_unlock(&hhook_head_list_lock)

Definition at line 82 of file kern_hhook.c.

◆ V_hhook_vhead_list

#define V_hhook_vhead_list   VNET(hhook_vhead_list)

Definition at line 68 of file kern_hhook.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ hhook_add_hook()

int hhook_add_hook ( struct hhook_head *  hhh,
struct hookinfo *  hki,
uint32_t  flags 
)

Definition at line 133 of file kern_hhook.c.

References flags, free(), HHH_WLOCK, HHH_WUNLOCK, hhook::hhk_func, hhook::hhk_helper, hhook::hhk_udata, and malloc().

Referenced by hhook_add_hook_lookup(), and khelp_new_hhook_registered().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hhook_add_hook_lookup()

int hhook_add_hook_lookup ( struct hookinfo *  hki,
uint32_t  flags 
)

Definition at line 190 of file kern_hhook.c.

References flags, free(), HHHLIST_LOCK, HHHLIST_UNLOCK, hhook_add_hook(), hhook_head_list, malloc(), and n_hhookheads.

Referenced by khelp_add_hhook().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hhook_head_deregister()

int hhook_head_deregister ( struct hhook_head *  hhh)

Definition at line 369 of file kern_hhook.c.

References HHHLIST_LOCK, HHHLIST_UNLOCK, and hhook_head_destroy().

Referenced by hhook_head_deregister_lookup(), and socket_hhook_deregister().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hhook_head_deregister_lookup()

int hhook_head_deregister_lookup ( int32_t  hhook_type,
int32_t  hhook_id 
)

Definition at line 391 of file kern_hhook.c.

References hhook_head_deregister(), hhook_head_get(), and hhook_head_release().

Here is the call graph for this function:

◆ hhook_head_destroy()

static void hhook_head_destroy ( struct hhook_head *  hhh)
static

Definition at line 344 of file kern_hhook.c.

References free(), HHH_LOCK_DESTROY, HHH_WLOCK, HHH_WUNLOCK, HHHLIST_LOCK_ASSERT, hhook_head_is_virtualised(), and n_hhookheads.

Referenced by hhook_head_deregister(), and hhook_vnet_uninit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hhook_head_get()

struct hhook_head * hhook_head_get ( int32_t  hhook_type,
int32_t  hhook_id 
)

Definition at line 410 of file kern_hhook.c.

References HHHLIST_LOCK, HHHLIST_UNLOCK, hhook_head_is_virtualised(), and hhook_head_list.

Referenced by hhook_head_deregister_lookup(), hhook_head_is_virtualised_lookup(), and hhook_head_register().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hhook_head_is_virtualised()

uint32_t hhook_head_is_virtualised ( struct hhook_head *  hhh)

Definition at line 448 of file kern_hhook.c.

Referenced by hhook_head_destroy(), hhook_head_get(), and hhook_head_is_virtualised_lookup().

Here is the caller graph for this function:

◆ hhook_head_is_virtualised_lookup()

uint32_t hhook_head_is_virtualised_lookup ( int32_t  hook_type,
int32_t  hook_id 
)

Definition at line 463 of file kern_hhook.c.

References hhook_head_get(), hhook_head_is_virtualised(), and hhook_head_release().

Here is the call graph for this function:

◆ hhook_head_register()

int hhook_head_register ( int32_t  hhook_type,
int32_t  hhook_id,
struct hhook_head **  hhh,
uint32_t  flags 
)

Definition at line 294 of file kern_hhook.c.

References flags, HHH_LOCK_INIT, HHHLIST_LOCK, HHHLIST_UNLOCK, hhook_head_get(), hhook_head_list, hhook_head_release(), khelp_new_hhook_registered(), malloc(), n_hhookheads, and V_hhook_vhead_list.

Referenced by socket_hhook_register().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hhook_head_release()

void hhook_head_release ( struct hhook_head *  hhh)

Definition at line 435 of file kern_hhook.c.

Referenced by hhook_head_deregister_lookup(), hhook_head_is_virtualised_lookup(), and hhook_head_register().

Here is the caller graph for this function:

◆ hhook_remove_hook()

int hhook_remove_hook ( struct hhook_head *  hhh,
struct hookinfo *  hki 
)

Definition at line 248 of file kern_hhook.c.

References free(), HHH_WLOCK, HHH_WUNLOCK, hhook::hhk_func, and hhook::hhk_udata.

Referenced by hhook_remove_hook_lookup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hhook_remove_hook_lookup()

int hhook_remove_hook_lookup ( struct hookinfo *  hki)

Definition at line 275 of file kern_hhook.c.

References HHHLIST_LOCK, HHHLIST_UNLOCK, hhook_head_list, and hhook_remove_hook().

Referenced by khelp_deregister_helper(), and khelp_remove_hhook().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hhook_run_hooks()

void hhook_run_hooks ( struct hhook_head *  hhh,
void *  ctx_data,
struct osd *  hosd 
)

Definition at line 96 of file kern_hhook.c.

References HHH_RLOCK, HHH_RUNLOCK, hhook::hhk_func, hhook::hhk_helper, hhook::hhk_udata, and osd_get().

Here is the call graph for this function:

◆ hhook_vnet_init()

static void hhook_vnet_init ( const void *unused  __unused)
static

Definition at line 483 of file kern_hhook.c.

References V_hhook_vhead_list.

◆ hhook_vnet_uninit()

static void hhook_vnet_uninit ( const void *unused  __unused)
static

Definition at line 493 of file kern_hhook.c.

References HHHLIST_LOCK, HHHLIST_UNLOCK, hhook_head_destroy(), printf(), and V_hhook_vhead_list.

Here is the call graph for this function:

◆ khelp_new_hhook_registered()

void khelp_new_hhook_registered ( struct hhook_head *  hhh,
uint32_t  flags 
)

Definition at line 291 of file kern_khelp.c.

References flags, hhook_add_hook(), KHELP_LIST_RLOCK, KHELP_LIST_RUNLOCK, and printf().

Referenced by hhook_head_register().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LIST_HEAD()

LIST_HEAD ( hhookheadhead  ,
hhook_head   
)

◆ MALLOC_DEFINE()

static MALLOC_DEFINE ( M_HHOOK  ,
"hhook"  ,
"Helper hooks are linked off hhook_head lists"   
)
static

◆ MTX_SYSINIT()

MTX_SYSINIT ( hhookheadlistlock  ,
hhook_head_list_lock,
"hhook_head list lock"  ,
MTX_DEF   
)

◆ VNET_DEFINE()

VNET_DEFINE ( struct hhookheadhead  ,
hhook_vhead_list   
)

◆ VNET_SYSINIT()

VNET_SYSINIT ( hhook_vnet_init  ,
SI_SUB_INIT_IF  ,
SI_ORDER_FIRST  ,
hhook_vnet_init  ,
NULL   
)

◆ VNET_SYSUNINIT()

VNET_SYSUNINIT ( hhook_vnet_uninit  ,
SI_SUB_INIT_IF  ,
SI_ORDER_FIRST  ,
hhook_vnet_uninit  ,
NULL   
)

Variable Documentation

◆ hhook_head_list

struct hhookheadhead hhook_head_list

◆ hhook_head_list_lock

struct mtx hhook_head_list_lock
static

Definition at line 70 of file kern_hhook.c.

◆ n_hhookheads

uint32_t n_hhookheads
static

Definition at line 75 of file kern_hhook.c.

Referenced by hhook_add_hook_lookup(), hhook_head_destroy(), and hhook_head_register().