Changeset View
Changeset View
Standalone View
Standalone View
sys/netgraph/ng_bridge.c
Show First 20 Lines • Show All 122 Lines • ▼ Show 20 Lines | |||||
static ng_constructor_t ng_bridge_constructor; | static ng_constructor_t ng_bridge_constructor; | ||||
static ng_rcvmsg_t ng_bridge_rcvmsg; | static ng_rcvmsg_t ng_bridge_rcvmsg; | ||||
static ng_shutdown_t ng_bridge_shutdown; | static ng_shutdown_t ng_bridge_shutdown; | ||||
static ng_newhook_t ng_bridge_newhook; | static ng_newhook_t ng_bridge_newhook; | ||||
static ng_rcvdata_t ng_bridge_rcvdata; | static ng_rcvdata_t ng_bridge_rcvdata; | ||||
static ng_disconnect_t ng_bridge_disconnect; | static ng_disconnect_t ng_bridge_disconnect; | ||||
/* Other internal functions */ | /* Other internal functions */ | ||||
static struct ng_bridge_host *ng_bridge_get(priv_p priv, const u_char *addr); | static struct ng_bridge_host *ng_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 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_rehash(priv_p priv); | ||||
static void ng_bridge_remove_hosts(priv_p priv, link_p link); | 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 void ng_bridge_timeout(node_p node, hook_p hook, void *arg1, int arg2); | ||||
static const char *ng_bridge_nodename(node_p node); | static const char *ng_bridge_nodename(const node_p node); | ||||
/* Ethernet broadcast */ | /* Ethernet broadcast */ | ||||
static const u_char ng_bridge_bcast_addr[ETHER_ADDR_LEN] = | static const u_char ng_bridge_bcast_addr[ETHER_ADDR_LEN] = | ||||
{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; | { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; | ||||
/* Compare Ethernet addresses using 32 and 16 bit words instead of bytewise */ | /* Compare Ethernet addresses using 32 and 16 bit words instead of bytewise */ | ||||
#define ETHER_EQUAL(a,b) (((const u_int32_t *)(a))[0] \ | #define ETHER_EQUAL(a,b) (((const u_int32_t *)(a))[0] \ | ||||
== ((const u_int32_t *)(b))[0] \ | == ((const u_int32_t *)(b))[0] \ | ||||
▲ Show 20 Lines • Show All 735 Lines • ▼ Show 20 Lines | |||||
#define HASH(addr,mask) ( (((const u_int16_t *)(addr))[0] \ | #define HASH(addr,mask) ( (((const u_int16_t *)(addr))[0] \ | ||||
^ ((const u_int16_t *)(addr))[1] \ | ^ ((const u_int16_t *)(addr))[1] \ | ||||
^ ((const u_int16_t *)(addr))[2]) & (mask) ) | ^ ((const u_int16_t *)(addr))[2]) & (mask) ) | ||||
/* | /* | ||||
* Find a host entry in the table. | * Find a host entry in the table. | ||||
*/ | */ | ||||
static struct ng_bridge_host * | static struct ng_bridge_host * | ||||
ng_bridge_get(priv_p priv, const u_char *addr) | ng_bridge_get(priv_cp priv, const u_char *addr) | ||||
{ | { | ||||
const int bucket = HASH(addr, priv->hashMask); | const int bucket = HASH(addr, priv->hashMask); | ||||
struct ng_bridge_hent *hent; | struct ng_bridge_hent *hent; | ||||
SLIST_FOREACH(hent, &priv->tab[bucket], next) { | SLIST_FOREACH(hent, &priv->tab[bucket], next) { | ||||
if (ETHER_EQUAL(hent->host.addr, addr)) | if (ETHER_EQUAL(hent->host.addr, addr)) | ||||
return (&hent->host); | return (&hent->host); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 194 Lines • ▼ Show 20 Lines | ng_bridge_timeout(node_p node, hook_p hook, void *arg1, int arg2) | ||||
/* Register a new timeout, keeping the existing node reference */ | /* Register a new timeout, keeping the existing node reference */ | ||||
ng_callout(&priv->timer, node, NULL, hz, ng_bridge_timeout, NULL, 0); | ng_callout(&priv->timer, node, NULL, hz, ng_bridge_timeout, NULL, 0); | ||||
} | } | ||||
/* | /* | ||||
* Return node's "name", even if it doesn't have one. | * Return node's "name", even if it doesn't have one. | ||||
*/ | */ | ||||
static const char * | static const char * | ||||
ng_bridge_nodename(node_p node) | ng_bridge_nodename(const node_p node) | ||||
{ | { | ||||
static char name[NG_NODESIZ]; | static char name[NG_NODESIZ]; | ||||
if (NG_NODE_HAS_NAME(node)) | if (NG_NODE_HAS_NAME(node)) | ||||
snprintf(name, sizeof(name), "%s", NG_NODE_NAME(node)); | snprintf(name, sizeof(name), "%s", NG_NODE_NAME(node)); | ||||
else | else | ||||
snprintf(name, sizeof(name), "[%x]", ng_node2ID(node)); | snprintf(name, sizeof(name), "[%x]", ng_node2ID(node)); | ||||
return name; | return name; | ||||
} | } |