FreeBSD/share/examples/kld/khelp/h_example.c
/*
 * Very simple helper hook function. Here's a quick run through the arguments:
 *
 * - hhook_type and hhook_id are useful if you use a single function with many
 * hook points and want to know which hook point called the function.
 *
 * - udata will be NULL, because we didn't elect to pass a pointer in either of
 * the hookinfo structs we instantiated above in the example_hooks array.
 *
 * - ctx_data contains context specific data from the hook point call site. The
 * data type passed is subsystem dependent. In the case of TCP, the hook points
 * pass a pointer to a "struct tcp_hhook_data" (defined in <netinet/tcp_var.h>).
 *
 * - hdata is a pointer to the persistent per-object storage for our module. The
 * pointer is allocated automagically by the Khelp framework when the connection
 * is created, and comes from a dedicated UMA zone. It will never be NULL.
 *
 * - hosd can be used with the Khelp framework's khelp_get_osd() function to
 * access data belonging to a different Khelp module.
 */
Very simple helper hook function. Here's a quick run through the arguments:
- hhook_type and hhook_id are useful if you use a single function with many
hook points and want to know which hook point called the function.

- udata will be NULL, because we didn't elect to pass a pointer in either of
the hookinfo structs we instantiated above in the example_hooks array.

- ctx_data contains context specific data from the hook point call site. The
data type passed is subsystem dependent. In the case of TCP, the hook points
pass a pointer to a "struct tcp_hhook_data" (defined in ).

- hdata is a pointer to the persistent per-object storage for our module. The
pointer is allocated automagically by the Khelp framework when the connection
is created, and comes from a dedicated UMA zone. It will never be NULL.

- hosd can be used with the Khelp framework's khelp_get_osd() function to
access data belonging to a different Khelp module.
Very simple helper hook function . Here ' s a quick run through the arguments : - hhook_type and hhook_id are useful if you use a single function with many hook points and want to know which hook point called the function . - udata will be NULL because we didn ' t elect to pass a pointer in either of the hookinfo structs we instantiated above in the example_hooks array . - ctx_data contains context specific data from the hook point call site . The data type passed is subsystem dependent . In the case of TCP the hook points pass a pointer to a " struct tcp_hhook_data " ( defined in ) . - hdata is a pointer to the persistent per - object storage for our module . The pointer is allocated automagically by the Khelp framework when the connection is created and comes from a dedicated UMA zone . It will never be NULL . - hosd can be used with the Khelp framework ' s khelp_get_osd () function to access data belonging to a different Khelp module .
static int
example_hook(int hhook_type, int hhook_id, void *udata, void *ctx_data,
    void *hdata, struct osd *hosd)
{
	struct example *data;
	data = hdata;
	if (hhook_id == HHOOK_TCP_EST_IN)
		data->est_in_count++;
	else if (hhook_id == HHOOK_TCP_EST_OUT)
		data->est_out_count++;
	return (0);
}
static int example_hook ( int hhook_type , int hhook_id , void * udata , void * ctx_data , void * hdata , struct osd * hosd ) { struct example * data ; data = hdata ; if ( hhook_id == HHOOK_TCP_EST_IN ) data -> est_in_count ++ ; else if ( hhook_id == HHOOK_TCP_EST_OUT ) data -> est_out_count ++ ; return ( 0 ) ; }
Very simple helper hook function.
Very simple helper hook function .