FreeBSD kernel netgraph code
ng_bpf.c File Reference
#include "opt_bpf.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/errno.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/mbuf.h>
#include <net/bpf.h>
#include <netgraph/ng_message.h>
#include <netgraph/netgraph.h>
#include <netgraph/ng_parse.h>
#include <netgraph/ng_bpf.h>
Include dependency graph for ng_bpf.c:

Go to the source code of this file.

Data Structures

struct  ng_bpf_hookinfo
 

Macros

#define M_NETGRAPH_BPF   M_NETGRAPH
 
#define OFFSETOF(s, e)   ((char *)&((s *)0)->e - (char *)((s *)0))
 
#define ERROUT(x)   do { error = (x); goto done; } while (0)
 

Typedefs

typedef struct ng_bpf_hookinfohinfo_p
 

Functions

static int ng_bpf_setprog (hook_p hook, const struct ng_bpf_hookprog *hp)
 
static int ng_bpf_hookprogary_getLength (const struct ng_parse_type *type, const u_char *start, const u_char *buf)
 
 NETGRAPH_INIT (bpf, &typestruct)
 
static int ng_bpf_constructor (node_p node)
 
static int ng_bpf_addrefs (hook_p hook, void *arg)
 
static int ng_bpf_remrefs (hook_p hook, void *arg)
 
static int ng_bpf_newhook (node_p node, hook_p hook, const char *name)
 
static int ng_bpf_rcvmsg (node_p node, item_p item, hook_p lasthook)
 
static int ng_bpf_rcvdata (hook_p hook, item_p item)
 
static int ng_bpf_shutdown (node_p node)
 
static int ng_bpf_disconnect (hook_p hook)
 

Variables

static ng_constructor_t ng_bpf_constructor
 
static ng_rcvmsg_t ng_bpf_rcvmsg
 
static ng_shutdown_t ng_bpf_shutdown
 
static ng_newhook_t ng_bpf_newhook
 
static ng_rcvdata_t ng_bpf_rcvdata
 
static ng_disconnect_t ng_bpf_disconnect
 
int bpf_maxinsns
 
static const struct ng_parse_struct_field ng_bpf_insn_type_fields []
 
static const struct ng_parse_type ng_bpf_insn_type
 
static const struct ng_parse_array_info ng_bpf_hookprogary_info
 
static const struct ng_parse_type ng_bpf_hookprogary_type
 
static const struct ng_parse_struct_field ng_bpf_hookprog_type_fields [] = NG_BPF_HOOKPROG_TYPE_INFO(&ng_bpf_hookprogary_type)
 
static const struct ng_parse_type ng_bpf_hookprog_type
 
static const struct ng_parse_struct_field ng_bpf_hookstat_type_fields [] = NG_BPF_HOOKSTAT_TYPE_INFO
 
static const struct ng_parse_type ng_bpf_hookstat_type
 
static const struct ng_cmdlist ng_bpf_cmdlist []
 
static struct ng_type typestruct
 
static const struct ng_bpf_hookprog ng_bpf_default_prog
 

Macro Definition Documentation

◆ ERROUT

#define ERROUT (   x)    do { error = (x); goto done; } while (0)

Definition at line 84 of file ng_bpf.c.

◆ M_NETGRAPH_BPF

#define M_NETGRAPH_BPF   M_NETGRAPH

Definition at line 79 of file ng_bpf.c.

◆ OFFSETOF

#define OFFSETOF (   s,
 
)    ((char *)&((s *)0)->e - (char *)((s *)0))

Definition at line 82 of file ng_bpf.c.

Typedef Documentation

◆ hinfo_p

typedef struct ng_bpf_hookinfo* hinfo_p

Definition at line 97 of file ng_bpf.c.

Function Documentation

◆ NETGRAPH_INIT()

NETGRAPH_INIT ( bpf  ,
typestruct 
)

◆ ng_bpf_addrefs()

static int ng_bpf_addrefs ( hook_p  hook,
void *  arg 
)
static

Definition at line 244 of file ng_bpf.c.

References ng_bpf_hookprog::ifMatch, ng_bpf_hookprog::ifNotMatch, ng_bpf_hookinfo::match, NG_HOOK_NAME, NG_HOOK_PRIVATE, ng_bpf_hookinfo::nomatch, and ng_bpf_hookinfo::prog.

Referenced by ng_bpf_newhook().

Here is the caller graph for this function:

◆ ng_bpf_constructor()

static int ng_bpf_constructor ( node_p  node)
static

Definition at line 234 of file ng_bpf.c.

References NG_NODE_SET_PRIVATE.

◆ ng_bpf_disconnect()

static int ng_bpf_disconnect ( hook_p  hook)
static

Definition at line 523 of file ng_bpf.c.

References M_NETGRAPH_BPF, ng_bpf_remrefs(), NG_HOOK_NODE, NG_HOOK_PRIVATE, NG_NODE_FOREACH_HOOK, NG_NODE_IS_VALID, NG_NODE_NUMHOOKS, ng_rmnode_self(), and ng_bpf_hookinfo::prog.

Here is the call graph for this function:

◆ ng_bpf_hookprogary_getLength()

static int ng_bpf_hookprogary_getLength ( const struct ng_parse_type type,
const u_char *  start,
const u_char *  buf 
)
static

Definition at line 128 of file ng_bpf.c.

References ng_bpf_hookprog::bpf_prog, ng_bpf_hookprog::bpf_prog_len, and OFFSETOF.

◆ ng_bpf_newhook()

static int ng_bpf_newhook ( node_p  node,
hook_p  hook,
const char *  name 
)
static

◆ ng_bpf_rcvdata()

◆ ng_bpf_rcvmsg()

◆ ng_bpf_remrefs()

static int ng_bpf_remrefs ( hook_p  hook,
void *  arg 
)
static

Definition at line 257 of file ng_bpf.c.

References ng_bpf_hookinfo::match, NG_HOOK_PRIVATE, and ng_bpf_hookinfo::nomatch.

Referenced by ng_bpf_disconnect().

Here is the caller graph for this function:

◆ ng_bpf_setprog()

static int ng_bpf_setprog ( hook_p  hook,
const struct ng_bpf_hookprog hp 
)
static

◆ ng_bpf_shutdown()

static int ng_bpf_shutdown ( node_p  node)
static

Definition at line 513 of file ng_bpf.c.

References NG_NODE_UNREF.

Variable Documentation

◆ bpf_maxinsns

int bpf_maxinsns
extern

Referenced by ng_bpf_setprog().

◆ ng_bpf_cmdlist

const struct ng_cmdlist ng_bpf_cmdlist[]
static

Definition at line 165 of file ng_bpf.c.

◆ ng_bpf_constructor

ng_constructor_t ng_bpf_constructor
static

Definition at line 100 of file ng_bpf.c.

◆ ng_bpf_default_prog

const struct ng_bpf_hookprog ng_bpf_default_prog
static
Initial value:
= {
{ '\0' },
{ '\0' },
{ '\0' },
1,
{ BPF_STMT(BPF_RET+BPF_K, 0) }
}

Definition at line 219 of file ng_bpf.c.

Referenced by ng_bpf_newhook().

◆ ng_bpf_disconnect

ng_disconnect_t ng_bpf_disconnect
static

Definition at line 105 of file ng_bpf.c.

◆ ng_bpf_hookprog_type

const struct ng_parse_type ng_bpf_hookprog_type
static
Initial value:
= {
}
static const struct ng_parse_struct_field ng_bpf_hookprog_type_fields[]
Definition: ng_bpf.c:150
const struct ng_parse_type ng_parse_struct_type
Definition: ng_parse.c:222

Definition at line 151 of file ng_bpf.c.

◆ ng_bpf_hookprog_type_fields

const struct ng_parse_struct_field ng_bpf_hookprog_type_fields[] = NG_BPF_HOOKPROG_TYPE_INFO(&ng_bpf_hookprogary_type)
static

Definition at line 149 of file ng_bpf.c.

◆ ng_bpf_hookprogary_info

const struct ng_parse_array_info ng_bpf_hookprogary_info
static
Initial value:
= {
NULL
}
static int ng_bpf_hookprogary_getLength(const struct ng_parse_type *type, const u_char *start, const u_char *buf)
Definition: ng_bpf.c:128
static const struct ng_parse_type ng_bpf_insn_type
Definition: ng_bpf.c:121

Definition at line 138 of file ng_bpf.c.

◆ ng_bpf_hookprogary_type

const struct ng_parse_type ng_bpf_hookprogary_type
static
Initial value:
= {
}
static const struct ng_parse_array_info ng_bpf_hookprogary_info
Definition: ng_bpf.c:138
const struct ng_parse_type ng_parse_array_type
Definition: ng_parse.c:318

Definition at line 143 of file ng_bpf.c.

◆ ng_bpf_hookstat_type

const struct ng_parse_type ng_bpf_hookstat_type
static
Initial value:
= {
}
static const struct ng_parse_struct_field ng_bpf_hookstat_type_fields[]
Definition: ng_bpf.c:158

Definition at line 159 of file ng_bpf.c.

◆ ng_bpf_hookstat_type_fields

const struct ng_parse_struct_field ng_bpf_hookstat_type_fields[] = NG_BPF_HOOKSTAT_TYPE_INFO
static

Definition at line 157 of file ng_bpf.c.

◆ ng_bpf_insn_type

const struct ng_parse_type ng_bpf_insn_type
static
Initial value:
= {
}
static const struct ng_parse_struct_field ng_bpf_insn_type_fields[]
Definition: ng_bpf.c:114

Definition at line 121 of file ng_bpf.c.

◆ ng_bpf_insn_type_fields

const struct ng_parse_struct_field ng_bpf_insn_type_fields[]
static
Initial value:
= {
{ "code", &ng_parse_hint16_type },
{ "jt", &ng_parse_uint8_type },
{ "jf", &ng_parse_uint8_type },
{ NULL }
}
const struct ng_parse_type ng_parse_uint32_type
Definition: ng_parse.c:608
const struct ng_parse_type ng_parse_uint8_type
Definition: ng_parse.c:413
const struct ng_parse_type ng_parse_hint16_type
Definition: ng_parse.c:514

Definition at line 114 of file ng_bpf.c.

◆ ng_bpf_newhook

ng_newhook_t ng_bpf_newhook
static

Definition at line 103 of file ng_bpf.c.

◆ ng_bpf_rcvdata

ng_rcvdata_t ng_bpf_rcvdata
static

Definition at line 104 of file ng_bpf.c.

◆ ng_bpf_rcvmsg

ng_rcvmsg_t ng_bpf_rcvmsg
static

Definition at line 101 of file ng_bpf.c.

◆ ng_bpf_shutdown

ng_shutdown_t ng_bpf_shutdown
static

Definition at line 102 of file ng_bpf.c.

◆ typestruct

struct ng_type typestruct
static
Initial value:
= {
.version = NG_ABI_VERSION,
.constructor = ng_bpf_constructor,
.rcvmsg = ng_bpf_rcvmsg,
.shutdown = ng_bpf_shutdown,
.newhook = ng_bpf_newhook,
.rcvdata = ng_bpf_rcvdata,
.disconnect = ng_bpf_disconnect,
.cmdlist = ng_bpf_cmdlist,
}
#define NG_ABI_VERSION
Definition: netgraph.h:77
static ng_shutdown_t ng_bpf_shutdown
Definition: ng_bpf.c:102
static ng_newhook_t ng_bpf_newhook
Definition: ng_bpf.c:103
static ng_disconnect_t ng_bpf_disconnect
Definition: ng_bpf.c:105
static ng_constructor_t ng_bpf_constructor
Definition: ng_bpf.c:100
static const struct ng_cmdlist ng_bpf_cmdlist[]
Definition: ng_bpf.c:165
static ng_rcvmsg_t ng_bpf_rcvmsg
Definition: ng_bpf.c:101
static ng_rcvdata_t ng_bpf_rcvdata
Definition: ng_bpf.c:104
#define NG_BPF_NODE_TYPE
Definition: ng_bpf.h:48

Definition at line 205 of file ng_bpf.c.