#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/mbuf.h>
#include <sys/errno.h>
#include <sys/syslog.h>
#include <sys/socket.h>
#include <sys/ctype.h>
#include <net/if.h>
#include <net/if_var.h>
#include <net/ethernet.h>
#include <netinet/in.h>
#include <net/ipfw/ip_fw.h>
#include <netgraph7/ng_message.h>
#include <netgraph7/netgraph.h>
#include <netgraph7/ng_parse.h>
#include "ng_bridge.h"
#ifdef NG_SEPARATE_MALLOC
MALLOC_DEFINE(M_NETGRAPH_BRIDGE, "netgraph_bridge", "netgraph bridge node ");
#else
#define M_NETGRAPH_BRIDGE M_NETGRAPH
#endif
struct ng_bridge_link {
hook_p hook;
u_int16_t loopCount;
struct ng_bridge_link_stats stats;
};
struct ng_bridge_private {
struct ng_bridge_bucket *tab;
struct ng_bridge_link *links[NG_BRIDGE_MAX_LINKS];
struct ng_bridge_config conf;
node_p node;
u_int numHosts;
u_int numBuckets;
u_int hashMask;
int numLinks;
struct callout timer;
};
typedef struct ng_bridge_private *priv_p;
struct ng_bridge_hent {
struct ng_bridge_host host;
SLIST_ENTRY(ng_bridge_hent) next;
};
SLIST_HEAD(ng_bridge_bucket, ng_bridge_hent);
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 struct ng_bridge_host *ng_bridge_get(priv_p priv, const u_char *addr);
static int ng_bridge_put(priv_p priv, const u_char *addr, int linkNum);
static void ng_bridge_rehash(priv_p priv);
static void ng_bridge_remove_hosts(priv_p priv, int linkNum);
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 u_char ng_bridge_bcast_addr[ETHER_ADDR_LEN] =
{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
#define LINK_NUM(hook) (*(u_int16_t *)(&(hook)->private))
#define ETHER_EQUAL(a,b) (((const u_int32_t *)(a))[0] \
== ((const u_int32_t *)(b))[0] \
&& ((const u_int16_t *)(a))[2] \
== ((const u_int16_t *)(b))[2])
#define MIN_BUCKETS (1 << 5)
#define MAX_BUCKETS (1 << 14)
#define DEFAULT_LOOP_TIMEOUT 60
#define DEFAULT_MAX_STALENESS (15 * 60)
#define DEFAULT_MIN_STABLE_AGE 1
static int
ng_bridge_getTableLength(const struct ng_parse_type *type,
const u_char *start, const u_char *buf)
{
const struct ng_bridge_host_ary *const hary
= (const struct ng_bridge_host_ary *)(buf - sizeof(u_int32_t));
return hary->numHosts;
}
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 = {
&ng_parse_struct_type,
&ng_bridge_host_type_fields
};
static const struct ng_parse_array_info ng_bridge_hary_type_info = {
&ng_bridge_host_type,
ng_bridge_getTableLength
};
static const struct ng_parse_type ng_bridge_hary_type = {
&ng_parse_array_type,
&ng_bridge_hary_type_info
};
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 = {
&ng_parse_struct_type,
&ng_bridge_host_ary_type_fields
};
static const struct ng_parse_fixedarray_info ng_bridge_ipfwary_type_info = {
&ng_parse_uint8_type,
NG_BRIDGE_MAX_LINKS
};
static const struct ng_parse_type ng_bridge_ipfwary_type = {
&ng_parse_fixedarray_type,
&ng_bridge_ipfwary_type_info
};
static const struct ng_parse_struct_field ng_bridge_config_type_fields[]
= NG_BRIDGE_CONFIG_TYPE_INFO(&ng_bridge_ipfwary_type);
static const struct ng_parse_type ng_bridge_config_type = {
&ng_parse_struct_type,
&ng_bridge_config_type_fields
};
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 = {
&ng_parse_struct_type,
&ng_bridge_stats_type_fields
};
static const struct ng_cmdlist ng_bridge_cmdlist[] = {
{
NGM_BRIDGE_COOKIE,
NGM_BRIDGE_SET_CONFIG,
"setconfig",
&ng_bridge_config_type,
NULL
},
{
NGM_BRIDGE_COOKIE,
NGM_BRIDGE_GET_CONFIG,
"getconfig",
NULL,
&ng_bridge_config_type
},
{
NGM_BRIDGE_COOKIE,
NGM_BRIDGE_RESET,
"reset",
NULL,
NULL
},
{
NGM_BRIDGE_COOKIE,
NGM_BRIDGE_GET_STATS,
"getstats",
&ng_parse_uint32_type,
&ng_bridge_stats_type
},
{
NGM_BRIDGE_COOKIE,
NGM_BRIDGE_CLR_STATS,
"clrstats",
&ng_parse_uint32_type,
NULL
},
{
NGM_BRIDGE_COOKIE,
NGM_BRIDGE_GETCLR_STATS,
"getclrstats",
&ng_parse_uint32_type,
&ng_bridge_stats_type
},
{
NGM_BRIDGE_COOKIE,
NGM_BRIDGE_GET_TABLE,
"gettable",
NULL,
&ng_bridge_host_ary_type
},
{ 0 }
};
static struct ng_type ng_bridge_typestruct = {
.version = NG_ABI_VERSION,
.name = NG_BRIDGE_NODE_TYPE,
.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,
};
NETGRAPH_INIT(bridge, &ng_bridge_typestruct);
static int
ng_bridge_constructor(node_p node)
{
priv_p priv;
priv = kmalloc(sizeof(*priv), M_NETGRAPH_BRIDGE,
M_WAITOK | M_NULLOK | M_ZERO);
if (priv == NULL)
return (ENOMEM);
ng_callout_init(&priv->timer);
priv->tab = kmalloc(MIN_BUCKETS * sizeof(*priv->tab),
M_NETGRAPH_BRIDGE, M_WAITOK | M_NULLOK | M_ZERO);
if (priv->tab == NULL) {
kfree(priv, M_NETGRAPH_BRIDGE);
return (ENOMEM);
}
priv->numBuckets = MIN_BUCKETS;
priv->hashMask = MIN_BUCKETS - 1;
priv->conf.debugLevel = 1;
priv->conf.loopTimeout = DEFAULT_LOOP_TIMEOUT;
priv->conf.maxStaleness = DEFAULT_MAX_STALENESS;
priv->conf.minStableAge = DEFAULT_MIN_STABLE_AGE;
NG_NODE_FORCE_WRITER(node);
NG_NODE_SET_PRIVATE(node, priv);
priv->node = node;
ng_callout(&priv->timer, node, NULL, hz, ng_bridge_timeout, NULL, 0);
return (0);
}
static int
ng_bridge_newhook(node_p node, hook_p hook, const char *name)
{
const priv_p priv = NG_NODE_PRIVATE(node);
if (strncmp(name, NG_BRIDGE_HOOK_LINK_PREFIX,
strlen(NG_BRIDGE_HOOK_LINK_PREFIX)) == 0) {
const char *cp;
char *eptr;
u_long linkNum;
cp = name + strlen(NG_BRIDGE_HOOK_LINK_PREFIX);
if (!isdigit(*cp) || (cp[0] == '0' && cp[1] != '\0'))
return (EINVAL);
linkNum = strtoul(cp, &eptr, 10);
if (*eptr != '\0' || linkNum >= NG_BRIDGE_MAX_LINKS)
return (EINVAL);
if (priv->links[linkNum] != NULL)
return (EISCONN);
priv->links[linkNum] = kmalloc(sizeof(*priv->links[linkNum]),
M_NETGRAPH_BRIDGE,
M_WAITOK | M_NULLOK | M_ZERO);
if (priv->links[linkNum] == NULL)
return (ENOMEM);
priv->links[linkNum]->hook = hook;
NG_HOOK_SET_PRIVATE(hook, (void *)linkNum);
priv->numLinks++;
return (0);
}
return (EINVAL);
}
static int
ng_bridge_rcvmsg(node_p node, item_p item, hook_p lasthook)
{
const priv_p priv = NG_NODE_PRIVATE(node);
struct ng_mesg *resp = NULL;
int error = 0;
struct ng_mesg *msg;
NGI_GET_MSG(item, msg);
switch (msg->header.typecookie) {
case NGM_BRIDGE_COOKIE:
switch (msg->header.cmd) {
case NGM_BRIDGE_GET_CONFIG:
{
struct ng_bridge_config *conf;
NG_MKRESPONSE(resp, msg,
sizeof(struct ng_bridge_config), M_WAITOK | M_NULLOK);
if (resp == NULL) {
error = ENOMEM;
break;
}
conf = (struct ng_bridge_config *)resp->data;
*conf = priv->conf;
break;
}
case NGM_BRIDGE_SET_CONFIG:
{
struct ng_bridge_config *conf;
int i;
if (msg->header.arglen
!= sizeof(struct ng_bridge_config)) {
error = EINVAL;
break;
}
conf = (struct ng_bridge_config *)msg->data;
priv->conf = *conf;
for (i = 0; i < NG_BRIDGE_MAX_LINKS; i++)
priv->conf.ipfw[i] = !!priv->conf.ipfw[i];
break;
}
case NGM_BRIDGE_RESET:
{
int i;
ng_bridge_remove_hosts(priv, -1);
for (i = 0; i < NG_BRIDGE_MAX_LINKS; i++) {
if (priv->links[i] == NULL)
continue;
priv->links[i]->loopCount = 0;
bzero(&priv->links[i]->stats,
sizeof(priv->links[i]->stats));
}
break;
}
case NGM_BRIDGE_GET_STATS:
case NGM_BRIDGE_CLR_STATS:
case NGM_BRIDGE_GETCLR_STATS:
{
struct ng_bridge_link *link;
int linkNum;
if (msg->header.arglen != sizeof(u_int32_t)) {
error = EINVAL;
break;
}
linkNum = *((u_int32_t *)msg->data);
if (linkNum < 0 || linkNum >= NG_BRIDGE_MAX_LINKS) {
error = EINVAL;
break;
}
if ((link = priv->links[linkNum]) == NULL) {
error = ENOTCONN;
break;
}
if (msg->header.cmd != NGM_BRIDGE_CLR_STATS) {
NG_MKRESPONSE(resp, msg,
sizeof(link->stats), M_WAITOK | M_NULLOK);
if (resp == NULL) {
error = ENOMEM;
break;
}
bcopy(&link->stats,
resp->data, sizeof(link->stats));
}
if (msg->header.cmd != NGM_BRIDGE_GET_STATS)
bzero(&link->stats, sizeof(link->stats));
break;
}
case NGM_BRIDGE_GET_TABLE:
{
struct ng_bridge_host_ary *ary;
struct ng_bridge_hent *hent;
int i = 0, bucket;
NG_MKRESPONSE(resp, msg, sizeof(*ary)
+ (priv->numHosts * sizeof(*ary->hosts)), M_WAITOK | M_NULLOK);
if (resp == NULL) {
error = ENOMEM;
break;
}
ary = (struct ng_bridge_host_ary *)resp->data;
ary->numHosts = priv->numHosts;
for (bucket = 0; bucket < priv->numBuckets; bucket++) {
SLIST_FOREACH(hent, &priv->tab[bucket], next)
ary->hosts[i++] = hent->host;
}
break;
}
default:
error = EINVAL;
break;
}
break;
default:
error = EINVAL;
break;
}
NG_RESPOND_MSG(error, node, item, resp);
NG_FREE_MSG(msg);
return (error);
}
static int
ng_bridge_rcvdata(hook_p hook, item_p item)
{
const node_p node = NG_HOOK_NODE(hook);
const priv_p priv = NG_NODE_PRIVATE(node);
struct ng_bridge_host *host;
struct ng_bridge_link *link;
struct ether_header *eh;
int error = 0, linkNum, linksSeen;
int manycast;
struct mbuf *m;
struct ng_bridge_link *firstLink;
NGI_GET_M(item, m);
linkNum = (intptr_t)NG_HOOK_PRIVATE(hook);
KASSERT(linkNum >= 0 && linkNum < NG_BRIDGE_MAX_LINKS,
("%s: linkNum=%u", __func__, linkNum));
link = priv->links[linkNum];
KASSERT(link != NULL, ("%s: link%d null", __func__, linkNum));
if (m->m_pkthdr.len < ETHER_HDR_LEN) {
link->stats.recvRunts++;
NG_FREE_ITEM(item);
NG_FREE_M(m);
return (EINVAL);
}
if (m->m_len < ETHER_HDR_LEN && !(m = m_pullup(m, ETHER_HDR_LEN))) {
link->stats.memoryFailures++;
NG_FREE_ITEM(item);
return (ENOBUFS);
}
eh = mtod(m, struct ether_header *);
if ((eh->ether_shost[0] & 1) != 0) {
link->stats.recvInvalid++;
NG_FREE_ITEM(item);
NG_FREE_M(m);
return (EINVAL);
}
if (link->loopCount != 0) {
link->stats.loopDrops++;
NG_FREE_ITEM(item);
NG_FREE_M(m);
return (ELOOP);
}
link->stats.recvPackets++;
link->stats.recvOctets += m->m_pkthdr.len;
if ((manycast = (eh->ether_dhost[0] & 1)) != 0) {
if (ETHER_EQUAL(eh->ether_dhost, ng_bridge_bcast_addr)) {
link->stats.recvBroadcasts++;
manycast = 2;
} else
link->stats.recvMulticasts++;
}
if ((host = ng_bridge_get(priv, eh->ether_shost)) != NULL) {
host->staleness = 0;
if (host->linkNum != linkNum) {
if (host->age < priv->conf.minStableAge) {
if (priv->conf.debugLevel >= 2) {
struct ifnet *ifp = m->m_pkthdr.rcvif;
char suffix[32];
if (ifp != NULL)
ksnprintf(suffix, sizeof(suffix),
" (%s)", ifp->if_xname);
else
*suffix = '\0';
log(LOG_WARNING, "ng_bridge: %s:"
" loopback detected on %s%s\n",
ng_bridge_nodename(node),
NG_HOOK_NAME(hook), suffix);
}
link->loopCount = priv->conf.loopTimeout;
link->stats.loopDetects++;
ng_bridge_remove_hosts(priv, linkNum);
link->stats.loopDrops++;
NG_FREE_ITEM(item);
NG_FREE_M(m);
return (ELOOP);
}
host->linkNum = linkNum;
host->age = 0;
}
} else {
if (!ng_bridge_put(priv, eh->ether_shost, linkNum)) {
link->stats.memoryFailures++;
NG_FREE_ITEM(item);
NG_FREE_M(m);
return (ENOMEM);
}
}
#if 0
if (priv->conf.ipfw[linkNum] && fw_enable && ip_fw_chk_ptr != NULL) {
}
#endif
if (!manycast) {
if ((host = ng_bridge_get(priv, eh->ether_dhost)) != NULL) {
struct ng_bridge_link *const destLink
= priv->links[host->linkNum];
KASSERT(destLink != NULL,
("%s: link%d null", __func__, host->linkNum));
if (destLink == link) {
NG_FREE_ITEM(item);
NG_FREE_M(m);
return (0);
}
destLink->stats.xmitPackets++;
destLink->stats.xmitOctets += m->m_pkthdr.len;
NG_FWD_NEW_DATA(error, item, destLink->hook, m);
return (error);
}
link->stats.recvUnknown++;
}
firstLink = NULL;
for (linkNum = linksSeen = 0; linksSeen <= priv->numLinks; linkNum++) {
struct ng_bridge_link *destLink;
struct mbuf *m2 = NULL;
if (linksSeen == priv->numLinks) {
if (firstLink == NULL) {
NG_FREE_ITEM(item);
NG_FREE_M(m);
return (0);
}
destLink = firstLink;
} else {
destLink = priv->links[linkNum];
if (destLink != NULL)
linksSeen++;
if (destLink == NULL || destLink == link) {
continue;
}
if (firstLink == NULL) {
firstLink = destLink;
continue;
}
m2 = m_dup(m, M_NOWAIT);
if (m2 == NULL) {
link->stats.memoryFailures++;
NG_FREE_ITEM(item);
NG_FREE_M(m);
return (ENOBUFS);
}
}
destLink->stats.xmitPackets++;
destLink->stats.xmitOctets += m->m_pkthdr.len;
switch (manycast) {
case 0:
break;
case 1:
destLink->stats.xmitMulticasts++;
break;
case 2:
destLink->stats.xmitBroadcasts++;
break;
}
if (destLink == firstLink) {
NG_FWD_NEW_DATA(error, item, destLink->hook, m);
break;
} else {
NG_SEND_DATA_ONLY(error, destLink->hook, m2);
}
}
return (error);
}
static int
ng_bridge_shutdown(node_p node)
{
const priv_p priv = NG_NODE_PRIVATE(node);
KASSERT(priv->numLinks == 0 && priv->numHosts == 0,
("%s: numLinks=%d numHosts=%d",
__func__, priv->numLinks, priv->numHosts));
ng_uncallout(&priv->timer, node);
NG_NODE_SET_PRIVATE(node, NULL);
NG_NODE_UNREF(node);
kfree(priv->tab, M_NETGRAPH_BRIDGE);
kfree(priv, M_NETGRAPH_BRIDGE);
return (0);
}
static int
ng_bridge_disconnect(hook_p hook)
{
const priv_p priv = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
int linkNum;
linkNum = (intptr_t)NG_HOOK_PRIVATE(hook);
KASSERT(linkNum >= 0 && linkNum < NG_BRIDGE_MAX_LINKS,
("%s: linkNum=%u", __func__, linkNum));
ng_bridge_remove_hosts(priv, linkNum);
KASSERT(priv->links[linkNum] != NULL, ("%s: no link", __func__));
kfree(priv->links[linkNum], M_NETGRAPH_BRIDGE);
priv->links[linkNum] = NULL;
priv->numLinks--;
if ((NG_NODE_NUMHOOKS(NG_HOOK_NODE(hook)) == 0)
&& (NG_NODE_IS_VALID(NG_HOOK_NODE(hook)))) {
ng_rmnode_self(NG_HOOK_NODE(hook));
}
return (0);
}
#define HASH(addr,mask) ( (((const u_int16_t *)(addr))[0] \
^ ((const u_int16_t *)(addr))[1] \
^ ((const u_int16_t *)(addr))[2]) & (mask) )
static struct ng_bridge_host *
ng_bridge_get(priv_p priv, const u_char *addr)
{
const int bucket = HASH(addr, priv->hashMask);
struct ng_bridge_hent *hent;
SLIST_FOREACH(hent, &priv->tab[bucket], next) {
if (ETHER_EQUAL(hent->host.addr, addr))
return (&hent->host);
}
return (NULL);
}
static int
ng_bridge_put(priv_p priv, const u_char *addr, int linkNum)
{
const int bucket = HASH(addr, priv->hashMask);
struct ng_bridge_hent *hent;
char ethstr[ETHER_ADDRSTRLEN + 1] __debugvar;
#ifdef INVARIANTS
SLIST_FOREACH(hent, &priv->tab[bucket], next) {
KASSERT(!ETHER_EQUAL(hent->host.addr, addr),
("%s: entry %s exists in table", __func__, kether_ntoa(addr, ethstr)));
}
#endif
hent = kmalloc(sizeof(*hent), M_NETGRAPH_BRIDGE, M_WAITOK | M_NULLOK);
if (hent == NULL)
return (0);
bcopy(addr, hent->host.addr, ETHER_ADDR_LEN);
hent->host.linkNum = linkNum;
hent->host.staleness = 0;
hent->host.age = 0;
SLIST_INSERT_HEAD(&priv->tab[bucket], hent, next);
priv->numHosts++;
ng_bridge_rehash(priv);
return (1);
}
static void
ng_bridge_rehash(priv_p priv)
{
struct ng_bridge_bucket *newTab;
int oldBucket, newBucket;
int newNumBuckets;
u_int newMask;
if (priv->numHosts > priv->numBuckets
&& (priv->numBuckets << 1) <= MAX_BUCKETS)
newNumBuckets = priv->numBuckets << 1;
else if (priv->numHosts < (priv->numBuckets >> 2)
&& (priv->numBuckets >> 2) >= MIN_BUCKETS)
newNumBuckets = priv->numBuckets >> 2;
else
return;
newMask = newNumBuckets - 1;
newTab = kmalloc(newNumBuckets * sizeof(*newTab), M_NETGRAPH_BRIDGE,
M_NOWAIT | M_ZERO);
if (newTab == NULL)
return;
for (oldBucket = 0; oldBucket < priv->numBuckets; oldBucket++) {
struct ng_bridge_bucket *const oldList = &priv->tab[oldBucket];
while (!SLIST_EMPTY(oldList)) {
struct ng_bridge_hent *const hent
= SLIST_FIRST(oldList);
SLIST_REMOVE_HEAD(oldList, next);
newBucket = HASH(hent->host.addr, newMask);
SLIST_INSERT_HEAD(&newTab[newBucket], hent, next);
}
}
if (priv->conf.debugLevel >= 3) {
log(LOG_INFO, "ng_bridge: %s: table size %d -> %d\n",
ng_bridge_nodename(priv->node),
priv->numBuckets, newNumBuckets);
}
kfree(priv->tab, M_NETGRAPH_BRIDGE);
priv->numBuckets = newNumBuckets;
priv->hashMask = newMask;
priv->tab = newTab;
return;
}
static void
ng_bridge_remove_hosts(priv_p priv, int linkNum)
{
int bucket;
for (bucket = 0; bucket < priv->numBuckets; bucket++) {
struct ng_bridge_hent **hptr = &SLIST_FIRST(&priv->tab[bucket]);
while (*hptr != NULL) {
struct ng_bridge_hent *const hent = *hptr;
if (linkNum == -1 || hent->host.linkNum == linkNum) {
*hptr = SLIST_NEXT(hent, next);
kfree(hent, M_NETGRAPH_BRIDGE);
priv->numHosts--;
} else
hptr = &SLIST_NEXT(hent, next);
}
}
}
static void
ng_bridge_timeout(node_p node, hook_p hook, void *arg1, int arg2)
{
const priv_p priv = NG_NODE_PRIVATE(node);
int bucket;
int counter = 0;
int linkNum;
char ethstr[ETHER_ADDRSTRLEN + 1] __debugvar;
for (bucket = 0; bucket < priv->numBuckets; bucket++) {
struct ng_bridge_hent **hptr = &SLIST_FIRST(&priv->tab[bucket]);
while (*hptr != NULL) {
struct ng_bridge_hent *const hent = *hptr;
KASSERT(priv->links[hent->host.linkNum] != NULL,
("%s: host %s on nonexistent link %d",
__func__, kether_ntoa(hent->host.addr, ethstr),
hent->host.linkNum));
if (++hent->host.staleness >= priv->conf.maxStaleness) {
*hptr = SLIST_NEXT(hent, next);
kfree(hent, M_NETGRAPH_BRIDGE);
priv->numHosts--;
} else {
if (hent->host.age < 0xffff)
hent->host.age++;
hptr = &SLIST_NEXT(hent, next);
counter++;
}
}
}
KASSERT(priv->numHosts == counter,
("%s: hosts: %d != %d", __func__, priv->numHosts, counter));
ng_bridge_rehash(priv);
for (counter = linkNum = 0; linkNum < NG_BRIDGE_MAX_LINKS; linkNum++) {
struct ng_bridge_link *const link = priv->links[linkNum];
if (link != NULL) {
if (link->loopCount != 0) {
link->loopCount--;
if (link->loopCount == 0
&& priv->conf.debugLevel >= 2) {
log(LOG_INFO, "ng_bridge: %s:"
" restoring looped back link%d\n",
ng_bridge_nodename(node), linkNum);
}
}
counter++;
}
}
KASSERT(priv->numLinks == counter,
("%s: links: %d != %d", __func__, priv->numLinks, counter));
ng_callout(&priv->timer, node, NULL, hz, ng_bridge_timeout, NULL, 0);
}
static const char *
ng_bridge_nodename(node_p node)
{
static char name[NG_NODESIZ];
if (NG_NODE_NAME(node) != NULL)
ksnprintf(name, sizeof(name), "%s", NG_NODE_NAME(node));
else
ksnprintf(name, sizeof(name), "[%x]", ng_node2ID(node));
return name;
}