Lines Matching +full:num +full:- +full:macs
1 /*-
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
42 * algorithm is included which disables a link for priv->conf.loopTimeout
44 * another within priv->conf.minStableAge seconds.
49 * expire after priv->conf.maxStaleness seconds.
105 /* Per-link private data */
109 unsigned int learnMac : 1, /* autolearn macs */
110 sendUnknown : 1;/* send unknown macs out */
115 /* Per-node private data */
120 u_int numHosts; /* num entries in table */
121 u_int numBuckets; /* num buckets in table */
122 u_int hashMask; /* numBuckets - 1 */
123 int numLinks; /* num connected links */
153 .len = sizeof(NG_BRIDGE_HOOK_LINK_PREFIX) - 1,
157 .len = sizeof(NG_BRIDGE_HOOK_UPLINK_PREFIX) - 1,
209 = (const struct ng_bridge_host_ary *)(buf - sizeof(u_int32_t)); in ng_bridge_getTableLength()
211 return hary->numHosts; in ng_bridge_getTableLength()
355 ng_callout_init(&priv->timer); in ng_bridge_constructor()
358 priv->tab = malloc(MIN_BUCKETS * sizeof(*priv->tab), in ng_bridge_constructor()
360 priv->numBuckets = MIN_BUCKETS; in ng_bridge_constructor()
361 priv->hashMask = MIN_BUCKETS - 1; in ng_bridge_constructor()
362 priv->conf.debugLevel = 1; in ng_bridge_constructor()
363 priv->conf.loopTimeout = DEFAULT_LOOP_TIMEOUT; in ng_bridge_constructor()
364 priv->conf.maxStaleness = DEFAULT_MAX_STALENESS; in ng_bridge_constructor()
365 priv->conf.minStableAge = DEFAULT_MIN_STABLE_AGE; in ng_bridge_constructor()
366 priv->sendUnknown = 1; /* classic bridge */ in ng_bridge_constructor()
369 priv->node = node; in ng_bridge_constructor()
372 priv->linkUnit = new_unrhdr(0, INT_MAX, NULL); in ng_bridge_constructor()
373 priv->uplinkUnit = new_unrhdr(1, INT_MAX, NULL); in ng_bridge_constructor()
376 ng_callout(&priv->timer, node, NULL, hz, ng_bridge_timeout, NULL, 0); in ng_bridge_constructor()
399 unit = isUplink ? priv->uplinkUnit : priv->linkUnit; in ng_bridge_newhook()
401 if (strlen(name) > pfx->len) { /* given number */ in ng_bridge_newhook()
405 linkNum = strtoul(name + pfx->len, NULL, 10); in ng_bridge_newhook()
407 snprintf(linkName, sizeof(linkName), "%s%u", pfx->prefix, in ng_bridge_newhook()
416 /* auto-assign and update hook name */ in ng_bridge_newhook()
418 MPASS(linkNum != -1); in ng_bridge_newhook()
419 snprintf(NG_HOOK_NAME(hook), NG_HOOKSIZ, "%s%u", pfx->prefix, in ng_bridge_newhook()
435 link->stats.f = counter_u64_alloc(M_NOWAIT); \ in ng_bridge_newhook()
436 if (link->stats.f == NULL) \ in ng_bridge_newhook()
454 link->hook = hook; in ng_bridge_newhook()
456 link->learnMac = 0; in ng_bridge_newhook()
457 link->sendUnknown = 1; in ng_bridge_newhook()
458 if (priv->numLinks == 0) /* if the first link is an uplink */ in ng_bridge_newhook()
459 priv->sendUnknown = 0; /* switch to restrictive mode */ in ng_bridge_newhook()
461 link->learnMac = 1; in ng_bridge_newhook()
462 link->sendUnknown = priv->sendUnknown; in ng_bridge_newhook()
466 priv->numLinks++; in ng_bridge_newhook()
481 counter_u64_zero(p->recvOctets); in ng_bridge_clear_link_stats()
482 counter_u64_zero(p->recvPackets); in ng_bridge_clear_link_stats()
483 counter_u64_zero(p->recvMulticasts); in ng_bridge_clear_link_stats()
484 counter_u64_zero(p->recvBroadcasts); in ng_bridge_clear_link_stats()
485 counter_u64_zero(p->recvUnknown); in ng_bridge_clear_link_stats()
486 counter_u64_zero(p->recvRunts); in ng_bridge_clear_link_stats()
487 counter_u64_zero(p->recvInvalid); in ng_bridge_clear_link_stats()
488 counter_u64_zero(p->xmitOctets); in ng_bridge_clear_link_stats()
489 counter_u64_zero(p->xmitPackets); in ng_bridge_clear_link_stats()
490 counter_u64_zero(p->xmitMulticasts); in ng_bridge_clear_link_stats()
491 counter_u64_zero(p->xmitBroadcasts); in ng_bridge_clear_link_stats()
492 counter_u64_zero(p->loopDrops); in ng_bridge_clear_link_stats()
493 p->loopDetects = 0; in ng_bridge_clear_link_stats()
494 counter_u64_zero(p->memoryFailures); in ng_bridge_clear_link_stats()
500 counter_u64_free(link->stats.recvOctets); in ng_bridge_free_link()
501 counter_u64_free(link->stats.recvPackets); in ng_bridge_free_link()
502 counter_u64_free(link->stats.recvMulticasts); in ng_bridge_free_link()
503 counter_u64_free(link->stats.recvBroadcasts); in ng_bridge_free_link()
504 counter_u64_free(link->stats.recvUnknown); in ng_bridge_free_link()
505 counter_u64_free(link->stats.recvRunts); in ng_bridge_free_link()
506 counter_u64_free(link->stats.recvInvalid); in ng_bridge_free_link()
507 counter_u64_free(link->stats.xmitOctets); in ng_bridge_free_link()
508 counter_u64_free(link->stats.xmitPackets); in ng_bridge_free_link()
509 counter_u64_free(link->stats.xmitMulticasts); in ng_bridge_free_link()
510 counter_u64_free(link->stats.xmitBroadcasts); in ng_bridge_free_link()
511 counter_u64_free(link->stats.loopDrops); in ng_bridge_free_link()
512 counter_u64_free(link->stats.memoryFailures); in ng_bridge_free_link()
521 priv->loopCount = 0; in ng_bridge_reset_link()
522 ng_bridge_clear_link_stats(&priv->stats); in ng_bridge_reset_link()
535 switch (msg->header.typecookie) { in ng_bridge_rcvmsg()
537 switch (msg->header.cmd) { in ng_bridge_rcvmsg()
548 conf = (struct ng_bridge_config *)resp->data; in ng_bridge_rcvmsg()
549 *conf = priv->conf; /* no sanity checking needed */ in ng_bridge_rcvmsg()
556 if (msg->header.arglen in ng_bridge_rcvmsg()
561 conf = (struct ng_bridge_config *)msg->data; in ng_bridge_rcvmsg()
562 priv->conf = *conf; in ng_bridge_rcvmsg()
584 if (msg->header.arglen != sizeof(u_int32_t)) { in ng_bridge_rcvmsg()
588 linkNum = *((int32_t *)msg->data); in ng_bridge_rcvmsg()
591 "%s%u", NG_BRIDGE_HOOK_UPLINK_PREFIX, -linkNum); in ng_bridge_rcvmsg()
603 if (msg->header.cmd != NGM_BRIDGE_CLR_STATS) { in ng_bridge_rcvmsg()
607 sizeof(link->stats), M_NOWAIT); in ng_bridge_rcvmsg()
612 rs = (struct ng_bridge_link_stats *)resp->data; in ng_bridge_rcvmsg()
613 #define FETCH(x) rs->x = counter_u64_fetch(link->stats.x) in ng_bridge_rcvmsg()
626 rs->loopDetects = link->stats.loopDetects; in ng_bridge_rcvmsg()
630 if (msg->header.cmd != NGM_BRIDGE_GET_STATS) in ng_bridge_rcvmsg()
631 ng_bridge_clear_link_stats(&link->stats); in ng_bridge_rcvmsg()
641 + (priv->numHosts * sizeof(*ary->hosts)), M_NOWAIT); in ng_bridge_rcvmsg()
646 ary = (struct ng_bridge_host_ary *)resp->data; in ng_bridge_rcvmsg()
647 ary->numHosts = priv->numHosts; in ng_bridge_rcvmsg()
648 for (bucket = 0; bucket < priv->numBuckets; bucket++) { in ng_bridge_rcvmsg()
649 SLIST_FOREACH(host, &priv->tab[bucket], next) { in ng_bridge_rcvmsg()
650 memcpy(ary->hosts[i].addr, in ng_bridge_rcvmsg()
651 host->addr, in ng_bridge_rcvmsg()
652 sizeof(ary->hosts[i].addr)); in ng_bridge_rcvmsg()
653 ary->hosts[i].age = host->age; in ng_bridge_rcvmsg()
654 ary->hosts[i].staleness = host->staleness; in ng_bridge_rcvmsg()
655 strncpy(ary->hosts[i].hook, in ng_bridge_rcvmsg()
656 NG_HOOK_NAME(host->link->hook), in ng_bridge_rcvmsg()
657 sizeof(ary->hosts[i].hook)); in ng_bridge_rcvmsg()
665 priv->persistent = 1; in ng_bridge_rcvmsg()
673 if (msg->header.arglen < sizeof(*mh)) { in ng_bridge_rcvmsg()
677 mh = (struct ng_bridge_move_host *)msg->data; in ng_bridge_rcvmsg()
678 hook = (mh->hook[0] == 0) in ng_bridge_rcvmsg()
680 : ng_findhook(node, mh->hook); in ng_bridge_rcvmsg()
685 error = ng_bridge_put(priv, mh->addr, NG_HOOK_PRIVATE(hook)); in ng_bridge_rcvmsg()
719 size_t len = m->m_pkthdr.len; in ng_bridge_send_data()
722 NG_FWD_NEW_DATA(error, item, dst->hook, m); in ng_bridge_send_data()
724 NG_SEND_DATA_ONLY(error, dst->hook, m); in ng_bridge_send_data()
728 counter_u64_add(dst->stats.memoryFailures, 1); in ng_bridge_send_data()
737 counter_u64_add(dst->stats.xmitPackets, 1); in ng_bridge_send_data()
738 counter_u64_add(dst->stats.xmitOctets, len); in ng_bridge_send_data()
743 counter_u64_add(dst->stats.xmitMulticasts, 1); in ng_bridge_send_data()
746 counter_u64_add(dst->stats.xmitBroadcasts, 1); in ng_bridge_send_data()
765 if (destLink == ctx->incoming) { in ng_bridge_send_ctx()
770 if (!ctx->manycast && !destLink->sendUnknown) in ng_bridge_send_ctx()
773 if (ctx->foundFirst == NULL) { in ng_bridge_send_ctx()
779 ctx->foundFirst = destLink; in ng_bridge_send_ctx()
787 m2 = m_dup(ctx->m, M_NOWAIT); in ng_bridge_send_ctx()
789 counter_u64_add(ctx->incoming->stats.memoryFailures, 1); in ng_bridge_send_ctx()
790 ctx->error = ENOBUFS; in ng_bridge_send_ctx()
795 error = ng_bridge_send_data(destLink, ctx->manycast, m2, NULL); in ng_bridge_send_ctx()
797 ctx->error = error; in ng_bridge_send_ctx()
814 if (ctx.m->m_pkthdr.len < ETHER_HDR_LEN) { in ng_bridge_rcvdata()
815 counter_u64_add(ctx.incoming->stats.recvRunts, 1); in ng_bridge_rcvdata()
820 if (ctx.m->m_len < ETHER_HDR_LEN && !(ctx.m = m_pullup(ctx.m, ETHER_HDR_LEN))) { in ng_bridge_rcvdata()
821 counter_u64_add(ctx.incoming->stats.memoryFailures, 1); in ng_bridge_rcvdata()
826 if ((eh->ether_shost[0] & 1) != 0) { in ng_bridge_rcvdata()
827 counter_u64_add(ctx.incoming->stats.recvInvalid, 1); in ng_bridge_rcvdata()
834 if (ctx.incoming->loopCount != 0) { in ng_bridge_rcvdata()
835 counter_u64_add(ctx.incoming->stats.loopDrops, 1); in ng_bridge_rcvdata()
842 counter_u64_add(ctx.incoming->stats.recvPackets, 1); in ng_bridge_rcvdata()
843 counter_u64_add(ctx.incoming->stats.recvOctets, ctx.m->m_pkthdr.len); in ng_bridge_rcvdata()
844 if ((ctx.manycast = (eh->ether_dhost[0] & 1)) != 0) { in ng_bridge_rcvdata()
845 if (ETHER_EQUAL(eh->ether_dhost, ng_bridge_bcast_addr)) { in ng_bridge_rcvdata()
846 counter_u64_add(ctx.incoming->stats.recvBroadcasts, 1); in ng_bridge_rcvdata()
849 counter_u64_add(ctx.incoming->stats.recvMulticasts, 1); in ng_bridge_rcvdata()
853 if ((host = ng_bridge_get(priv, eh->ether_shost)) != NULL) in ng_bridge_rcvdata()
858 if (__predict_false(host->staleness > 0)) in ng_bridge_rcvdata()
859 host->staleness = 0; in ng_bridge_rcvdata()
861 if ((host == NULL && ctx.incoming->learnMac) || in ng_bridge_rcvdata()
862 (host != NULL && host->link != ctx.incoming)) { in ng_bridge_rcvdata()
870 counter_u64_add(ctx.incoming->stats.memoryFailures, 1); in ng_bridge_rcvdata()
875 mh = (struct ng_bridge_move_host *)msg->data; in ng_bridge_rcvdata()
876 strncpy(mh->hook, NG_HOOK_NAME(ctx.incoming->hook), in ng_bridge_rcvdata()
877 sizeof(mh->hook)); in ng_bridge_rcvdata()
878 memcpy(mh->addr, eh->ether_shost, sizeof(mh->addr)); in ng_bridge_rcvdata()
882 counter_u64_add(ctx.incoming->stats.memoryFailures, 1); in ng_bridge_rcvdata()
885 if (host != NULL && host->link != ctx.incoming) { in ng_bridge_rcvdata()
886 if (host->age < priv->conf.minStableAge) { in ng_bridge_rcvdata()
888 counter_u64_add(ctx.incoming->stats.loopDrops, 1); in ng_bridge_rcvdata()
901 if ((host = ng_bridge_get(priv, eh->ether_dhost)) != NULL) { in ng_bridge_rcvdata()
902 link_p destLink = host->link; in ng_bridge_rcvdata()
916 counter_u64_add(ctx.incoming->stats.recvUnknown, 1); in ng_bridge_rcvdata()
950 KASSERT(priv->numLinks == 0 && priv->numHosts == 0, in ng_bridge_shutdown()
952 __func__, priv->numLinks, priv->numHosts)); in ng_bridge_shutdown()
953 ng_uncallout(&priv->timer, node); in ng_bridge_shutdown()
954 delete_unrhdr(priv->linkUnit); in ng_bridge_shutdown()
955 delete_unrhdr(priv->uplinkUnit); in ng_bridge_shutdown()
958 free(priv->tab, M_NETGRAPH_BRIDGE); in ng_bridge_shutdown()
980 priv->numLinks--; in ng_bridge_disconnect()
982 linkNum = strtoul(name + pfx->len, NULL, 10); in ng_bridge_disconnect()
983 free_unr(pfx == &link_pfx ? priv->linkUnit: priv->uplinkUnit, linkNum); in ng_bridge_disconnect()
988 && !priv->persistent) { in ng_bridge_disconnect()
1011 const int bucket = HASH(addr, priv->hashMask); in ng_bridge_get()
1014 SLIST_FOREACH(host, &priv->tab[bucket], next) { in ng_bridge_get()
1015 if (ETHER_EQUAL(host->addr, addr)) in ng_bridge_get()
1028 const int bucket = HASH(addr, priv->hashMask); in ng_bridge_put()
1033 if (host->link == link) in ng_bridge_put()
1037 if (host->age >= priv->conf.minStableAge) { in ng_bridge_put()
1038 host->link = link; in ng_bridge_put()
1039 host->age = 0; in ng_bridge_put()
1047 if (priv->conf.debugLevel >= 2) in ng_bridge_put()
1050 ng_bridge_nodename(priv->node), in ng_bridge_put()
1051 NG_HOOK_NAME(link->hook)); in ng_bridge_put()
1054 link->loopCount = priv->conf.loopTimeout; in ng_bridge_put()
1055 link->stats.loopDetects++; in ng_bridge_put()
1066 bcopy(addr, host->addr, ETHER_ADDR_LEN); in ng_bridge_put()
1067 host->link = link; in ng_bridge_put()
1068 host->staleness = 0; in ng_bridge_put()
1069 host->age = 0; in ng_bridge_put()
1072 SLIST_INSERT_HEAD(&priv->tab[bucket], host, next); in ng_bridge_put()
1073 priv->numHosts++; in ng_bridge_put()
1096 if (priv->numHosts > priv->numBuckets in ng_bridge_rehash()
1097 && (priv->numBuckets << 1) <= MAX_BUCKETS) in ng_bridge_rehash()
1098 newNumBuckets = priv->numBuckets << 1; in ng_bridge_rehash()
1099 else if (priv->numHosts < (priv->numBuckets >> 2) in ng_bridge_rehash()
1100 && (priv->numBuckets >> 2) >= MIN_BUCKETS) in ng_bridge_rehash()
1101 newNumBuckets = priv->numBuckets >> 2; in ng_bridge_rehash()
1104 newMask = newNumBuckets - 1; in ng_bridge_rehash()
1113 for (oldBucket = 0; oldBucket < priv->numBuckets; oldBucket++) { in ng_bridge_rehash()
1114 struct ng_bridge_bucket *const oldList = &priv->tab[oldBucket]; in ng_bridge_rehash()
1121 newBucket = HASH(host->addr, newMask); in ng_bridge_rehash()
1127 if (priv->conf.debugLevel >= 3) { in ng_bridge_rehash()
1128 log(LOG_INFO, "ng_bridge: %s: table size %d -> %d\n", in ng_bridge_rehash()
1129 ng_bridge_nodename(priv->node), in ng_bridge_rehash()
1130 priv->numBuckets, newNumBuckets); in ng_bridge_rehash()
1132 free(priv->tab, M_NETGRAPH_BRIDGE); in ng_bridge_rehash()
1133 priv->numBuckets = newNumBuckets; in ng_bridge_rehash()
1134 priv->hashMask = newMask; in ng_bridge_rehash()
1135 priv->tab = newTab; in ng_bridge_rehash()
1150 if (strncmp(pfxs[i]->prefix, name, pfxs[i]->len) == 0) in ng_get_link_prefix()
1158 * If linkNum == -1, then remove all hosts in the table.
1165 for (bucket = 0; bucket < priv->numBuckets; bucket++) { in ng_bridge_remove_hosts()
1166 struct ng_bridge_host **hptr = &SLIST_FIRST(&priv->tab[bucket]); in ng_bridge_remove_hosts()
1171 if (link == NULL || host->link == link) { in ng_bridge_remove_hosts()
1174 priv->numHosts--; in ng_bridge_remove_hosts()
1182 * Handle our once-per-second timeout event. We do two things:
1183 * we decrement link->loopCount for those links being muted due to
1195 if (link->loopCount != 0) { in ng_bridge_unmute()
1196 link->loopCount--; in ng_bridge_unmute()
1197 if (link->loopCount == 0 && priv->conf.debugLevel >= 2) { in ng_bridge_unmute()
1215 for (bucket = 0; bucket < priv->numBuckets; bucket++) { in ng_bridge_timeout()
1216 struct ng_bridge_host **hptr = &SLIST_FIRST(&priv->tab[bucket]); in ng_bridge_timeout()
1222 if (++host->staleness >= priv->conf.maxStaleness) { in ng_bridge_timeout()
1225 priv->numHosts--; in ng_bridge_timeout()
1227 if (host->age < 0xffff) in ng_bridge_timeout()
1228 host->age++; in ng_bridge_timeout()
1234 KASSERT(priv->numHosts == counter, in ng_bridge_timeout()
1235 ("%s: hosts: %d != %d", __func__, priv->numHosts, counter)); in ng_bridge_timeout()
1243 KASSERT(priv->numLinks == counter, in ng_bridge_timeout()
1244 ("%s: links: %d != %d", __func__, priv->numLinks, counter)); in ng_bridge_timeout()
1247 ng_callout(&priv->timer, node, NULL, hz, ng_bridge_timeout, NULL, 0); in ng_bridge_timeout()