FreeBSD kernel netgraph code
ng_bridge.c File Reference
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/mbuf.h>
#include <sys/errno.h>
#include <sys/rwlock.h>
#include <sys/syslog.h>
#include <sys/socket.h>
#include <sys/ctype.h>
#include <sys/types.h>
#include <sys/counter.h>
#include <net/if.h>
#include <net/if_var.h>
#include <net/ethernet.h>
#include <net/vnet.h>
#include <netinet/in.h>
#include <netgraph/ng_message.h>
#include <netgraph/netgraph.h>
#include <netgraph/ng_parse.h>
#include <netgraph/ng_bridge.h>
Include dependency graph for ng_bridge.c:

Go to the source code of this file.

Data Structures

struct  ng_bridge_link_kernel_stats
 
struct  ng_bridge_link
 
struct  ng_bridge_private
 
struct  ng_bridge_host
 
struct  ng_bridge_send_ctx
 

Macros

#define M_NETGRAPH_BRIDGE   M_NETGRAPH
 
#define ETHER_EQUAL(a, b)
 
#define MIN_BUCKETS   (1 << 5) /* 32 */
 
#define MAX_BUCKETS   (1 << 14) /* 16384 */
 
#define DEFAULT_LOOP_TIMEOUT   60
 
#define DEFAULT_MAX_STALENESS   (15 * 60) /* same as ARP timeout */
 
#define DEFAULT_MIN_STABLE_AGE   1
 
#define NG_BRIDGE_COUNTER_ALLOC(f)
 
#define FETCH(x)   rs->x = counter_u64_fetch(link->stats.x)
 
#define HASH(addr, mask)
 

Typedefs

typedef struct ng_bridge_link const * link_cp
 
typedef struct ng_bridge_privatepriv_p
 
typedef struct ng_bridge_private const * priv_cp
 

Functions

 SLIST_HEAD (ng_bridge_bucket, ng_bridge_host)
 
static void ng_bridge_free_link (link_p link)
 
static struct ng_bridge_hostng_bridge_get (priv_cp priv, const u_char *addr)
 
static int ng_bridge_put (priv_p priv, const u_char *addr, link_p link)
 
static void ng_bridge_rehash (priv_p priv)
 
static void ng_bridge_remove_hosts (priv_p priv, link_p link)
 
static void ng_bridge_timeout (node_p node, hook_p hook, void *arg1, int arg2)
 
static const char * ng_bridge_nodename (node_cp node)
 
static int ng_bridge_getTableLength (const struct ng_parse_type *type, const u_char *start, const u_char *buf)
 
 NETGRAPH_INIT (bridge, &ng_bridge_typestruct)
 
static int ng_bridge_constructor (node_p node)
 
static int ng_bridge_newhook (node_p node, hook_p hook, const char *name)
 
static void ng_bridge_clear_link_stats (struct ng_bridge_link_kernel_stats *p)
 
static int ng_bridge_reset_link (hook_p hook, void *arg __unused)
 
static int ng_bridge_rcvmsg (node_p node, item_p item, hook_p lasthook)
 
static int ng_bridge_send_data (link_cp dst, int manycast, struct mbuf *m, item_p item)
 
static int ng_bridge_send_ctx (hook_p dst, void *arg)
 
static int ng_bridge_rcvdata (hook_p hook, item_p item)
 
static int ng_bridge_shutdown (node_p node)
 
static int ng_bridge_disconnect (hook_p hook)
 
static int ng_bridge_unmute (hook_p hook, void *arg)
 

Variables

static ng_constructor_t ng_bridge_constructor
 
static ng_rcvmsg_t ng_bridge_rcvmsg
 
static ng_shutdown_t ng_bridge_shutdown
 
static ng_newhook_t ng_bridge_newhook
 
static ng_rcvdata_t ng_bridge_rcvdata
 
static ng_disconnect_t ng_bridge_disconnect
 
static const u_char ng_bridge_bcast_addr [ETHER_ADDR_LEN]
 
static const struct ng_parse_struct_field ng_bridge_host_type_fields [] = NG_BRIDGE_HOST_TYPE_INFO(&ng_parse_enaddr_type)
 
static const struct ng_parse_type ng_bridge_host_type
 
static const struct ng_parse_array_info ng_bridge_hary_type_info
 
static const struct ng_parse_type ng_bridge_hary_type
 
static const struct ng_parse_struct_field ng_bridge_host_ary_type_fields [] = NG_BRIDGE_HOST_ARY_TYPE_INFO(&ng_bridge_hary_type)
 
static const struct ng_parse_type ng_bridge_host_ary_type
 
static const struct ng_parse_struct_field ng_bridge_config_type_fields [] = NG_BRIDGE_CONFIG_TYPE_INFO
 
static const struct ng_parse_type ng_bridge_config_type
 
static const struct ng_parse_struct_field ng_bridge_stats_type_fields [] = NG_BRIDGE_STATS_TYPE_INFO
 
static const struct ng_parse_type ng_bridge_stats_type
 
static const struct ng_parse_struct_field ng_bridge_move_host_type_fields [] = NG_BRIDGE_MOVE_HOST_TYPE_INFO(&ng_parse_enaddr_type)
 
static const struct ng_parse_type ng_bridge_move_host_type
 
static const struct ng_cmdlist ng_bridge_cmdlist []
 
static struct ng_type ng_bridge_typestruct
 

Macro Definition Documentation

◆ DEFAULT_LOOP_TIMEOUT

#define DEFAULT_LOOP_TIMEOUT   60

Definition at line 180 of file ng_bridge.c.

◆ DEFAULT_MAX_STALENESS

#define DEFAULT_MAX_STALENESS   (15 * 60) /* same as ARP timeout */

Definition at line 181 of file ng_bridge.c.

◆ DEFAULT_MIN_STABLE_AGE

#define DEFAULT_MIN_STABLE_AGE   1

Definition at line 182 of file ng_bridge.c.

◆ ETHER_EQUAL

#define ETHER_EQUAL (   a,
 
)
Value:
(((const u_int32_t *)(a))[0] \
== ((const u_int32_t *)(b))[0] \
&& ((const u_int16_t *)(a))[2] \
== ((const u_int16_t *)(b))[2])

Definition at line 170 of file ng_bridge.c.

◆ FETCH

#define FETCH (   x)    rs->x = counter_u64_fetch(link->stats.x)

◆ HASH

#define HASH (   addr,
  mask 
)
Value:
( (((const u_int16_t *)(addr))[0] \
^ ((const u_int16_t *)(addr))[1] \
^ ((const u_int16_t *)(addr))[2]) & (mask) )

Definition at line 972 of file ng_bridge.c.

◆ M_NETGRAPH_BRIDGE

#define M_NETGRAPH_BRIDGE   M_NETGRAPH

Definition at line 89 of file ng_bridge.c.

◆ MAX_BUCKETS

#define MAX_BUCKETS   (1 << 14) /* 16384 */

Definition at line 177 of file ng_bridge.c.

◆ MIN_BUCKETS

#define MIN_BUCKETS   (1 << 5) /* 32 */

Definition at line 176 of file ng_bridge.c.

◆ NG_BRIDGE_COUNTER_ALLOC

#define NG_BRIDGE_COUNTER_ALLOC (   f)
Value:
do { \
link->stats.f = counter_u64_alloc(M_NOWAIT); \
if (link->stats.f == NULL) \
goto nomem; \
} while (0)

Typedef Documentation

◆ link_cp

typedef struct ng_bridge_link const* link_cp

Definition at line 118 of file ng_bridge.c.

◆ priv_cp

typedef struct ng_bridge_private const* priv_cp

Definition at line 134 of file ng_bridge.c.

◆ priv_p

typedef struct ng_bridge_private* priv_p

Definition at line 133 of file ng_bridge.c.

Function Documentation

◆ NETGRAPH_INIT()

NETGRAPH_INIT ( bridge  ,
ng_bridge_typestruct 
)

◆ ng_bridge_clear_link_stats()

◆ ng_bridge_constructor()

static int ng_bridge_constructor ( node_p  node)
static

◆ ng_bridge_disconnect()

static int ng_bridge_disconnect ( hook_p  hook)
static

◆ ng_bridge_free_link()

◆ ng_bridge_get()

static struct ng_bridge_host * ng_bridge_get ( priv_cp  priv,
const u_char *  addr 
)
static

Definition at line 980 of file ng_bridge.c.

References ng_bridge_host::addr, ETHER_EQUAL, and HASH.

Referenced by ng_bridge_put(), and ng_bridge_rcvdata().

Here is the caller graph for this function:

◆ ng_bridge_getTableLength()

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

Definition at line 192 of file ng_bridge.c.

References ng_bridge_host_ary::numHosts.

◆ ng_bridge_newhook()

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

◆ ng_bridge_nodename()

static const char * ng_bridge_nodename ( node_cp  node)
static

Definition at line 1213 of file ng_bridge.c.

References name, ng_node2ID(), NG_NODE_HAS_NAME, NG_NODE_NAME, and NG_NODESIZ.

Referenced by ng_bridge_put(), ng_bridge_rehash(), and ng_bridge_unmute().

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

◆ ng_bridge_put()

static int ng_bridge_put ( priv_p  priv,
const u_char *  addr,
link_p  link 
)
static

◆ ng_bridge_rcvdata()

◆ ng_bridge_rcvmsg()

static int ng_bridge_rcvmsg ( node_p  node,
item_p  item,
hook_p  lasthook 
)
static

Definition at line 495 of file ng_bridge.c.

References ng_bridge_host::addr, ng_bridge_hostent::addr, ng_bridge_move_host::addr, ng_bridge_host::age, ng_bridge_hostent::age, ng_mesg::ng_msghdr::arglen, ng_mesg::ng_msghdr::cmd, ng_mesg::data, FETCH, ng_mesg::header, ng_bridge_link::hook, ng_bridge_hostent::hook, ng_bridge_move_host::hook, ng_bridge_host_ary::hosts, ng_bridge_host::link, ng_bridge_link_kernel_stats::loopDetects, ng_bridge_link_stats::loopDetects, ng_bridge_link_stats::loopDrops, ng_bridge_link_stats::memoryFailures, ng_bridge_clear_link_stats(), NG_BRIDGE_HOOK_LINK_PREFIX, NG_BRIDGE_HOOK_UPLINK_PREFIX, ng_bridge_put(), ng_bridge_remove_hosts(), ng_bridge_reset_link(), ng_findhook(), NG_FREE_MSG, NG_HOOK_NAME, NG_HOOK_PRIVATE, NG_HOOKSIZ, NG_MKRESPONSE, NG_NODE_FOREACH_HOOK, NG_NODE_PRIVATE, NG_RESPOND_MSG, NGI_GET_MSG, NGM_BRIDGE_CLR_STATS, NGM_BRIDGE_COOKIE, NGM_BRIDGE_GET_CONFIG, NGM_BRIDGE_GET_STATS, NGM_BRIDGE_GET_TABLE, NGM_BRIDGE_GETCLR_STATS, NGM_BRIDGE_MOVE_HOST, NGM_BRIDGE_RESET, NGM_BRIDGE_SET_CONFIG, NGM_BRIDGE_SET_PERSISTENT, ng_bridge_host_ary::numHosts, ng_bridge_link_stats::recvBroadcasts, ng_bridge_link_stats::recvInvalid, ng_bridge_link_stats::recvMulticasts, ng_bridge_link_stats::recvOctets, ng_bridge_link_stats::recvPackets, ng_bridge_link_stats::recvRunts, ng_bridge_link_stats::recvUnknown, ng_bridge_host::staleness, ng_bridge_hostent::staleness, ng_bridge_link::stats, ng_mesg::ng_msghdr::typecookie, ng_bridge_link_stats::xmitBroadcasts, ng_bridge_link_stats::xmitMulticasts, ng_bridge_link_stats::xmitOctets, and ng_bridge_link_stats::xmitPackets.

Here is the call graph for this function:

◆ ng_bridge_rehash()

static void ng_bridge_rehash ( priv_p  priv)
static

Definition at line 1059 of file ng_bridge.c.

References ng_bridge_host::addr, HASH, M_NETGRAPH_BRIDGE, MAX_BUCKETS, MIN_BUCKETS, and ng_bridge_nodename().

Referenced by ng_bridge_put(), and ng_bridge_timeout().

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

◆ ng_bridge_remove_hosts()

static void ng_bridge_remove_hosts ( priv_p  priv,
link_p  link 
)
static

Definition at line 1119 of file ng_bridge.c.

References ng_bridge_host::link, and M_NETGRAPH_BRIDGE.

Referenced by ng_bridge_disconnect(), ng_bridge_put(), and ng_bridge_rcvmsg().

Here is the caller graph for this function:

◆ ng_bridge_reset_link()

static int ng_bridge_reset_link ( hook_p  hook,
void *arg  __unused 
)
static

Definition at line 485 of file ng_bridge.c.

References ng_bridge_clear_link_stats(), NG_HOOK_PRIVATE, and priv::stats.

Referenced by ng_bridge_rcvmsg().

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

◆ ng_bridge_send_ctx()

◆ ng_bridge_send_data()

static int ng_bridge_send_data ( link_cp  dst,
int  manycast,
struct mbuf *  m,
item_p  item 
)
inlinestatic

Definition at line 688 of file ng_bridge.c.

References NG_FREE_ITEM, NG_FREE_M, NG_FWD_NEW_DATA, and NG_SEND_DATA_ONLY.

Referenced by ng_bridge_rcvdata(), and ng_bridge_send_ctx().

Here is the caller graph for this function:

◆ ng_bridge_shutdown()

static int ng_bridge_shutdown ( node_p  node)
static

Definition at line 918 of file ng_bridge.c.

References M_NETGRAPH_BRIDGE, NG_NODE_PRIVATE, NG_NODE_SET_PRIVATE, NG_NODE_UNREF, and ng_uncallout().

Here is the call graph for this function:

◆ ng_bridge_timeout()

static void ng_bridge_timeout ( node_p  node,
hook_p  hook,
void *  arg1,
int  arg2 
)
static

Definition at line 1166 of file ng_bridge.c.

References ng_bridge_host::age, M_NETGRAPH_BRIDGE, ng_bridge_rehash(), ng_bridge_timeout(), ng_bridge_unmute(), ng_callout(), NG_NODE_FOREACH_HOOK, NG_NODE_PRIVATE, and ng_bridge_host::staleness.

Referenced by ng_bridge_constructor(), and ng_bridge_timeout().

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

◆ ng_bridge_unmute()

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

Definition at line 1146 of file ng_bridge.c.

References ng_bridge_host::link, ng_bridge_link::loopCount, ng_bridge_nodename(), NG_HOOK_NAME, NG_HOOK_NODE, NG_HOOK_PRIVATE, and NG_NODE_PRIVATE.

Referenced by ng_bridge_timeout().

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

◆ SLIST_HEAD()

SLIST_HEAD ( ng_bridge_bucket  ,
ng_bridge_host   
)

Variable Documentation

◆ ng_bridge_bcast_addr

const u_char ng_bridge_bcast_addr[ETHER_ADDR_LEN]
static
Initial value:
=
{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }

Definition at line 166 of file ng_bridge.c.

Referenced by ng_bridge_rcvdata().

◆ ng_bridge_cmdlist

const struct ng_cmdlist ng_bridge_cmdlist[]
static

Definition at line 247 of file ng_bridge.c.

◆ ng_bridge_config_type

const struct ng_parse_type ng_bridge_config_type
static
Initial value:
= {
}
static const struct ng_parse_struct_field ng_bridge_config_type_fields[]
Definition: ng_bridge.c:225
const struct ng_parse_type ng_parse_struct_type
Definition: ng_parse.c:222

Definition at line 226 of file ng_bridge.c.

◆ ng_bridge_config_type_fields

const struct ng_parse_struct_field ng_bridge_config_type_fields[] = NG_BRIDGE_CONFIG_TYPE_INFO
static

Definition at line 224 of file ng_bridge.c.

◆ ng_bridge_constructor

ng_constructor_t ng_bridge_constructor
static

Definition at line 149 of file ng_bridge.c.

◆ ng_bridge_disconnect

ng_disconnect_t ng_bridge_disconnect
static

Definition at line 154 of file ng_bridge.c.

◆ ng_bridge_hary_type

const struct ng_parse_type ng_bridge_hary_type
static
Initial value:
= {
}
static const struct ng_parse_array_info ng_bridge_hary_type_info
Definition: ng_bridge.c:208
const struct ng_parse_type ng_parse_array_type
Definition: ng_parse.c:318

Definition at line 212 of file ng_bridge.c.

◆ ng_bridge_hary_type_info

const struct ng_parse_array_info ng_bridge_hary_type_info
static
Initial value:
= {
}
static int ng_bridge_getTableLength(const struct ng_parse_type *type, const u_char *start, const u_char *buf)
Definition: ng_bridge.c:192
static const struct ng_parse_type ng_bridge_host_type
Definition: ng_bridge.c:204

Definition at line 208 of file ng_bridge.c.

◆ ng_bridge_host_ary_type

const struct ng_parse_type ng_bridge_host_ary_type
static
Initial value:
= {
}
static const struct ng_parse_struct_field ng_bridge_host_ary_type_fields[]
Definition: ng_bridge.c:217

Definition at line 218 of file ng_bridge.c.

◆ ng_bridge_host_ary_type_fields

const struct ng_parse_struct_field ng_bridge_host_ary_type_fields[] = NG_BRIDGE_HOST_ARY_TYPE_INFO(&ng_bridge_hary_type)
static

Definition at line 216 of file ng_bridge.c.

◆ ng_bridge_host_type

const struct ng_parse_type ng_bridge_host_type
static
Initial value:
= {
}
static const struct ng_parse_struct_field ng_bridge_host_type_fields[]
Definition: ng_bridge.c:203

Definition at line 204 of file ng_bridge.c.

◆ ng_bridge_host_type_fields

const struct ng_parse_struct_field ng_bridge_host_type_fields[] = NG_BRIDGE_HOST_TYPE_INFO(&ng_parse_enaddr_type)
static

Definition at line 202 of file ng_bridge.c.

◆ ng_bridge_move_host_type

const struct ng_parse_type ng_bridge_move_host_type
static
Initial value:
= {
}
static const struct ng_parse_struct_field ng_bridge_move_host_type_fields[]
Definition: ng_bridge.c:240

Definition at line 241 of file ng_bridge.c.

◆ ng_bridge_move_host_type_fields

const struct ng_parse_struct_field ng_bridge_move_host_type_fields[] = NG_BRIDGE_MOVE_HOST_TYPE_INFO(&ng_parse_enaddr_type)
static

Definition at line 239 of file ng_bridge.c.

◆ ng_bridge_newhook

ng_newhook_t ng_bridge_newhook
static

Definition at line 152 of file ng_bridge.c.

◆ ng_bridge_rcvdata

ng_rcvdata_t ng_bridge_rcvdata
static

Definition at line 153 of file ng_bridge.c.

◆ ng_bridge_rcvmsg

ng_rcvmsg_t ng_bridge_rcvmsg
static

Definition at line 150 of file ng_bridge.c.

◆ ng_bridge_shutdown

ng_shutdown_t ng_bridge_shutdown
static

Definition at line 151 of file ng_bridge.c.

◆ ng_bridge_stats_type

const struct ng_parse_type ng_bridge_stats_type
static
Initial value:
= {
}
static const struct ng_parse_struct_field ng_bridge_stats_type_fields[]
Definition: ng_bridge.c:233

Definition at line 234 of file ng_bridge.c.

◆ ng_bridge_stats_type_fields

const struct ng_parse_struct_field ng_bridge_stats_type_fields[] = NG_BRIDGE_STATS_TYPE_INFO
static

Definition at line 232 of file ng_bridge.c.

◆ ng_bridge_typestruct

struct ng_type ng_bridge_typestruct
static
Initial value:
= {
.version = NG_ABI_VERSION,
.constructor = ng_bridge_constructor,
.rcvmsg = ng_bridge_rcvmsg,
.shutdown = ng_bridge_shutdown,
.newhook = ng_bridge_newhook,
.rcvdata = ng_bridge_rcvdata,
.disconnect = ng_bridge_disconnect,
.cmdlist = ng_bridge_cmdlist,
}
#define NG_ABI_VERSION
Definition: netgraph.h:77
static ng_shutdown_t ng_bridge_shutdown
Definition: ng_bridge.c:151
static ng_constructor_t ng_bridge_constructor
Definition: ng_bridge.c:149
static ng_newhook_t ng_bridge_newhook
Definition: ng_bridge.c:152
static ng_disconnect_t ng_bridge_disconnect
Definition: ng_bridge.c:154
static ng_rcvdata_t ng_bridge_rcvdata
Definition: ng_bridge.c:153
static ng_rcvmsg_t ng_bridge_rcvmsg
Definition: ng_bridge.c:150
static const struct ng_cmdlist ng_bridge_cmdlist[]
Definition: ng_bridge.c:247
#define NG_BRIDGE_NODE_TYPE
Definition: ng_bridge.h:47

Definition at line 315 of file ng_bridge.c.