FreeBSD kernel netgraph code
ng_macfilter.c File Reference
#include <sys/param.h>
#include <sys/ctype.h>
#include <sys/systm.h>
#include <sys/lock.h>
#include <sys/mbuf.h>
#include <sys/mutex.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/socket.h>
#include <net/ethernet.h>
#include <netgraph/ng_message.h>
#include <netgraph/netgraph.h>
#include <netgraph/ng_parse.h>
#include "ng_macfilter.h"
Include dependency graph for ng_macfilter.c:

Go to the source code of this file.

Data Structures

struct  macfilter_p
 

Macros

#define M_NETGRAPH_MACFILTER   M_NETGRAPH
 
#define MACTABLE_BLOCKSIZE   128 /* block size for incrementing table */
 
#define MACFILTER_DEBUG(fmt, ...)
 
#define MAC_FMT   "%02x:%02x:%02x:%02x:%02x:%02x"
 
#define MAC_S_ARGS(v)   (v)[0], (v)[1], (v)[2], (v)[3], (v)[4], (v)[5]
 

Typedefs

typedef struct ngm_macfilter_macmf_mac_p
 

Functions

static int macfilter_get_macs_count (const struct ng_parse_type *type, const u_char *start, const u_char *buf)
 
static int macfilter_get_upper_hook_count (const struct ng_parse_type *type, const u_char *start, const u_char *buf)
 
 NETGRAPH_INIT (macfilter, &typestruct)
 
static int macfilter_mactable_resize (macfilter_p mfp)
 
static void macfilter_reset (macfilter_p mfp)
 
static void macfilter_reset_stats (macfilter_p mfp)
 
static int macfilter_mac_count (macfilter_p mfp, int hookid)
 
static u_int macfilter_find_mac (macfilter_p mfp, const u_char *ether, u_int *ri)
 
static int macfilter_mactable_change (macfilter_p mfp, u_char *ether, int hookid)
 
static int macfilter_mactable_remove_by_hookid (macfilter_p mfp, int hookid)
 
static int macfilter_find_hook (macfilter_p mfp, const char *hookname)
 
static int macfilter_direct (macfilter_p mfp, struct ngm_macfilter_direct *md)
 
static int macfilter_direct_hookid (macfilter_p mfp, struct ngm_macfilter_direct_hookid *mdi)
 
static int macfilter_ether_output (hook_p hook, macfilter_p mfp, struct mbuf *m, hook_p *next_hook)
 
static int macfilter_ether_input (hook_p hook, macfilter_p mfp, struct mbuf *m, hook_p *next_hook)
 
static int ng_macfilter_constructor (node_p node)
 
static int ng_macfilter_newhook (node_p node, hook_p hook, const char *hookname)
 
static int ng_macfilter_rcvmsg (node_p node, item_p item, hook_p lasthook)
 
static int ng_macfilter_rcvdata (hook_p hook, item_p item)
 
static int ng_macfilter_disconnect (hook_p hook)
 
static int ng_macfilter_shutdown (node_p node)
 

Variables

static const struct ng_parse_struct_field macfilter_direct_fields [] = NGM_MACFILTER_DIRECT_FIELDS
 
static const struct ng_parse_type ng_macfilter_direct_type
 
static const struct ng_parse_struct_field macfilter_direct_ndx_fields [] = NGM_MACFILTER_DIRECT_NDX_FIELDS
 
static const struct ng_parse_type ng_macfilter_direct_hookid_type
 
static const struct ng_parse_struct_field ng_macfilter_mac_fields [] = NGM_MACFILTER_MAC_FIELDS
 
static const struct ng_parse_type ng_macfilter_mac_type
 
static const struct ng_parse_array_info ng_macfilter_macs_array_info
 
static const struct ng_parse_type ng_macfilter_macs_array_type
 
static const struct ng_parse_struct_field ng_macfilter_macs_fields [] = NGM_MACFILTER_MACS_FIELDS
 
static const struct ng_parse_type ng_macfilter_macs_type
 
static const struct ng_parse_struct_field ng_macfilter_hook_fields [] = NGM_MACFILTER_HOOK_FIELDS
 
static const struct ng_parse_type ng_macfilter_hook_type
 
static const struct ng_parse_array_info ng_macfilter_hooks_array_info
 
static const struct ng_parse_type ng_macfilter_hooks_array_type
 
static const struct ng_parse_struct_field ng_macfilter_hooks_fields [] = NGM_MACFILTER_HOOKS_FIELDS
 
static const struct ng_parse_type ng_macfilter_hooks_type
 
static const struct ng_cmdlist ng_macfilter_cmdlist []
 
static ng_constructor_t ng_macfilter_constructor
 
static ng_rcvmsg_t ng_macfilter_rcvmsg
 
static ng_shutdown_t ng_macfilter_shutdown
 
static ng_newhook_t ng_macfilter_newhook
 
static ng_rcvdata_t ng_macfilter_rcvdata
 
static ng_disconnect_t ng_macfilter_disconnect
 
static struct ng_type typestruct
 

Macro Definition Documentation

◆ M_NETGRAPH_MACFILTER

#define M_NETGRAPH_MACFILTER   M_NETGRAPH

Definition at line 73 of file ng_macfilter.c.

◆ MAC_FMT

#define MAC_FMT   "%02x:%02x:%02x:%02x:%02x:%02x"

Definition at line 83 of file ng_macfilter.c.

◆ MAC_S_ARGS

#define MAC_S_ARGS (   v)    (v)[0], (v)[1], (v)[2], (v)[3], (v)[4], (v)[5]

Definition at line 84 of file ng_macfilter.c.

◆ MACFILTER_DEBUG

#define MACFILTER_DEBUG (   fmt,
  ... 
)

Definition at line 81 of file ng_macfilter.c.

◆ MACTABLE_BLOCKSIZE

#define MACTABLE_BLOCKSIZE   128 /* block size for incrementing table */

Definition at line 76 of file ng_macfilter.c.

Typedef Documentation

◆ mf_mac_p

typedef struct ngm_macfilter_mac* mf_mac_p

Definition at line 261 of file ng_macfilter.c.

Function Documentation

◆ macfilter_direct()

static int macfilter_direct ( macfilter_p  mfp,
struct ngm_macfilter_direct md 
)
static

Definition at line 494 of file ng_macfilter.c.

References ngm_macfilter_direct::ether, ngm_macfilter_direct::hookname, MAC_FMT, MAC_S_ARGS, MACFILTER_DEBUG, macfilter_find_hook(), and macfilter_mactable_change().

Referenced by ng_macfilter_rcvmsg().

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

◆ macfilter_direct_hookid()

static int macfilter_direct_hookid ( macfilter_p  mfp,
struct ngm_macfilter_direct_hookid mdi 
)
static

Definition at line 507 of file ng_macfilter.c.

References ngm_macfilter_direct_hookid::ether, ngm_macfilter_direct_hookid::hookid, MAC_FMT, MAC_S_ARGS, MACFILTER_DEBUG, macfilter_mactable_change(), macfilter_p::mf_upper, and macfilter_p::mf_upper_cnt.

Referenced by ng_macfilter_rcvmsg().

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

◆ macfilter_ether_input()

static int macfilter_ether_input ( hook_p  hook,
macfilter_p  mfp,
struct mbuf *  m,
hook_p next_hook 
)
static

◆ macfilter_ether_output()

static int macfilter_ether_output ( hook_p  hook,
macfilter_p  mfp,
struct mbuf *  m,
hook_p next_hook 
)
static

Definition at line 529 of file ng_macfilter.c.

References ngm_macfilter_mac::bytes_out, MAC_FMT, MAC_S_ARGS, MACFILTER_DEBUG, macfilter_find_mac(), macfilter_p::mf_ether_hook, macfilter_p::mf_macs, macfilter_p::mtx, NG_HOOK_NAME, and ngm_macfilter_mac::packets_out.

Referenced by ng_macfilter_rcvdata().

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

◆ macfilter_find_hook()

static int macfilter_find_hook ( macfilter_p  mfp,
const char *  hookname 
)
static

Definition at line 477 of file ng_macfilter.c.

References macfilter_p::mf_upper, macfilter_p::mf_upper_cnt, NG_HOOK_NAME, and NG_HOOKSIZ.

Referenced by macfilter_direct().

Here is the caller graph for this function:

◆ macfilter_find_mac()

static u_int macfilter_find_mac ( macfilter_p  mfp,
const u_char *  ether,
u_int *  ri 
)
static

Definition at line 373 of file ng_macfilter.c.

References macfilter_p::mf_mac_used, and macfilter_p::mf_macs.

Referenced by macfilter_ether_input(), macfilter_ether_output(), and macfilter_mactable_change().

Here is the caller graph for this function:

◆ macfilter_get_macs_count()

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

Definition at line 112 of file ng_macfilter.c.

References ngm_macfilter_macs::macs, ngm_macfilter_macs::n, and OFFSETOF.

◆ macfilter_get_upper_hook_count()

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

◆ macfilter_mac_count()

static int macfilter_mac_count ( macfilter_p  mfp,
int  hookid 
)
static

Definition at line 351 of file ng_macfilter.c.

References ngm_macfilter_mac::hookid, macfilter_p::mf_mac_used, and macfilter_p::mf_macs.

Referenced by ng_macfilter_rcvmsg().

Here is the caller graph for this function:

◆ macfilter_mactable_change()

static int macfilter_mactable_change ( macfilter_p  mfp,
u_char *  ether,
int  hookid 
)
static

◆ macfilter_mactable_remove_by_hookid()

static int macfilter_mactable_remove_by_hookid ( macfilter_p  mfp,
int  hookid 
)
static

Definition at line 457 of file ng_macfilter.c.

References ngm_macfilter_mac::hookid, macfilter_mactable_resize(), macfilter_p::mf_mac_used, and macfilter_p::mf_macs.

Referenced by ng_macfilter_disconnect().

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

◆ macfilter_mactable_resize()

static int macfilter_mactable_resize ( macfilter_p  mfp)
static

◆ macfilter_reset()

static void macfilter_reset ( macfilter_p  mfp)
static

Definition at line 321 of file ng_macfilter.c.

References macfilter_mactable_resize(), and macfilter_p::mf_mac_used.

Referenced by ng_macfilter_rcvmsg().

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

◆ macfilter_reset_stats()

static void macfilter_reset_stats ( macfilter_p  mfp)
static

◆ NETGRAPH_INIT()

NETGRAPH_INIT ( macfilter  ,
typestruct 
)

◆ ng_macfilter_constructor()

static int ng_macfilter_constructor ( node_p  node)
static

Definition at line 623 of file ng_macfilter.c.

References macfilter_mactable_resize(), macfilter_p::mtx, and NG_NODE_SET_PRIVATE.

Here is the call graph for this function:

◆ ng_macfilter_disconnect()

◆ ng_macfilter_newhook()

static int ng_macfilter_newhook ( node_p  node,
hook_p  hook,
const char *  hookname 
)
static

◆ ng_macfilter_rcvdata()

static int ng_macfilter_rcvdata ( hook_p  hook,
item_p  item 
)
static

◆ ng_macfilter_rcvmsg()

◆ ng_macfilter_shutdown()

static int ng_macfilter_shutdown ( node_p  node)
static

Variable Documentation

◆ macfilter_direct_fields

const struct ng_parse_struct_field macfilter_direct_fields[] = NGM_MACFILTER_DIRECT_FIELDS
static

Definition at line 90 of file ng_macfilter.c.

◆ macfilter_direct_ndx_fields

const struct ng_parse_struct_field macfilter_direct_ndx_fields[] = NGM_MACFILTER_DIRECT_NDX_FIELDS
static

Definition at line 101 of file ng_macfilter.c.

◆ ng_macfilter_cmdlist

const struct ng_cmdlist ng_macfilter_cmdlist[]
static

Definition at line 180 of file ng_macfilter.c.

◆ ng_macfilter_constructor

ng_constructor_t ng_macfilter_constructor
static

Definition at line 236 of file ng_macfilter.c.

◆ ng_macfilter_direct_hookid_type

const struct ng_parse_type ng_macfilter_direct_hookid_type
static
Initial value:
= {
}
static const struct ng_parse_struct_field macfilter_direct_ndx_fields[]
Definition: ng_macfilter.c:102
const struct ng_parse_type ng_parse_struct_type
Definition: ng_parse.c:222

Definition at line 103 of file ng_macfilter.c.

◆ ng_macfilter_direct_type

const struct ng_parse_type ng_macfilter_direct_type
static
Initial value:
= {
}
static const struct ng_parse_struct_field macfilter_direct_fields[]
Definition: ng_macfilter.c:91

Definition at line 92 of file ng_macfilter.c.

◆ ng_macfilter_disconnect

ng_disconnect_t ng_macfilter_disconnect
static

Definition at line 241 of file ng_macfilter.c.

◆ ng_macfilter_hook_fields

const struct ng_parse_struct_field ng_macfilter_hook_fields[] = NGM_MACFILTER_HOOK_FIELDS
static

Definition at line 156 of file ng_macfilter.c.

◆ ng_macfilter_hook_type

const struct ng_parse_type ng_macfilter_hook_type
static
Initial value:
= {
}
static const struct ng_parse_struct_field ng_macfilter_hook_fields[]
Definition: ng_macfilter.c:157

Definition at line 158 of file ng_macfilter.c.

◆ ng_macfilter_hooks_array_info

const struct ng_parse_array_info ng_macfilter_hooks_array_info
static
Initial value:
= {
}
static int macfilter_get_upper_hook_count(const struct ng_parse_type *type, const u_char *start, const u_char *buf)
Definition: ng_macfilter.c:145
static const struct ng_parse_type ng_macfilter_hook_type
Definition: ng_macfilter.c:158

Definition at line 162 of file ng_macfilter.c.

◆ ng_macfilter_hooks_array_type

const struct ng_parse_type ng_macfilter_hooks_array_type
static
Initial value:
= {
}
static const struct ng_parse_array_info ng_macfilter_hooks_array_info
Definition: ng_macfilter.c:162
const struct ng_parse_type ng_parse_array_type
Definition: ng_parse.c:318

Definition at line 166 of file ng_macfilter.c.

◆ ng_macfilter_hooks_fields

const struct ng_parse_struct_field ng_macfilter_hooks_fields[] = NGM_MACFILTER_HOOKS_FIELDS
static

Definition at line 170 of file ng_macfilter.c.

◆ ng_macfilter_hooks_type

const struct ng_parse_type ng_macfilter_hooks_type
static
Initial value:
= {
}
static const struct ng_parse_struct_field ng_macfilter_hooks_fields[]
Definition: ng_macfilter.c:171

Definition at line 172 of file ng_macfilter.c.

◆ ng_macfilter_mac_fields

const struct ng_parse_struct_field ng_macfilter_mac_fields[] = NGM_MACFILTER_MAC_FIELDS
static

Definition at line 120 of file ng_macfilter.c.

◆ ng_macfilter_mac_type

const struct ng_parse_type ng_macfilter_mac_type
static
Initial value:
= {
}
static const struct ng_parse_struct_field ng_macfilter_mac_fields[]
Definition: ng_macfilter.c:121

Definition at line 122 of file ng_macfilter.c.

◆ ng_macfilter_macs_array_info

const struct ng_parse_array_info ng_macfilter_macs_array_info
static
Initial value:
= {
}
static const struct ng_parse_type ng_macfilter_mac_type
Definition: ng_macfilter.c:122
static int macfilter_get_macs_count(const struct ng_parse_type *type, const u_char *start, const u_char *buf)
Definition: ng_macfilter.c:112

Definition at line 126 of file ng_macfilter.c.

◆ ng_macfilter_macs_array_type

const struct ng_parse_type ng_macfilter_macs_array_type
static
Initial value:
= {
}
static const struct ng_parse_array_info ng_macfilter_macs_array_info
Definition: ng_macfilter.c:126

Definition at line 130 of file ng_macfilter.c.

◆ ng_macfilter_macs_fields

const struct ng_parse_struct_field ng_macfilter_macs_fields[] = NGM_MACFILTER_MACS_FIELDS
static

Definition at line 134 of file ng_macfilter.c.

◆ ng_macfilter_macs_type

const struct ng_parse_type ng_macfilter_macs_type
static
Initial value:
= {
}
static const struct ng_parse_struct_field ng_macfilter_macs_fields[]
Definition: ng_macfilter.c:135

Definition at line 136 of file ng_macfilter.c.

◆ ng_macfilter_newhook

ng_newhook_t ng_macfilter_newhook
static

Definition at line 239 of file ng_macfilter.c.

◆ ng_macfilter_rcvdata

ng_rcvdata_t ng_macfilter_rcvdata
static

Definition at line 240 of file ng_macfilter.c.

◆ ng_macfilter_rcvmsg

ng_rcvmsg_t ng_macfilter_rcvmsg
static

Definition at line 237 of file ng_macfilter.c.

◆ ng_macfilter_shutdown

ng_shutdown_t ng_macfilter_shutdown
static

Definition at line 238 of file ng_macfilter.c.

◆ typestruct

struct ng_type typestruct
static
Initial value:
= {
.version = NG_ABI_VERSION,
.constructor = ng_macfilter_constructor,
.shutdown = ng_macfilter_shutdown,
.disconnect = ng_macfilter_disconnect,
}
#define NG_ABI_VERSION
Definition: netgraph.h:77
static const struct ng_cmdlist ng_macfilter_cmdlist[]
Definition: ng_macfilter.c:180
static ng_disconnect_t ng_macfilter_disconnect
Definition: ng_macfilter.c:241
static ng_rcvdata_t ng_macfilter_rcvdata
Definition: ng_macfilter.c:240
static ng_rcvmsg_t ng_macfilter_rcvmsg
Definition: ng_macfilter.c:237
static ng_newhook_t ng_macfilter_newhook
Definition: ng_macfilter.c:239
static ng_shutdown_t ng_macfilter_shutdown
Definition: ng_macfilter.c:238
static ng_constructor_t ng_macfilter_constructor
Definition: ng_macfilter.c:236
#define NG_MACFILTER_NODE_TYPE
Definition: ng_macfilter.h:36

Definition at line 243 of file ng_macfilter.c.