aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLutz Donnerhacke <donner@FreeBSD.org>2021-02-10 10:47:38 +0000
committerLutz Donnerhacke <donner@FreeBSD.org>2021-02-22 08:22:03 +0000
commitdcb4190179bd5588b28286828d65d50b9ba182cc (patch)
treeb896d7f84cd4f4c2e1fc4e9971b0e5b8a7eed49e
parent88e916bff0357ffd0a4b8844cc03c79fcaa2022c (diff)
downloadsrc-dcb4190179bd5588b28286828d65d50b9ba182cc.tar.gz
src-dcb4190179bd5588b28286828d65d50b9ba182cc.zip
netgraph/ng_bridge: Add counters for the first link, too
For broadcast, multicast and unknown unicast, the replication loop sends a copy of the packet to each link, beside the first one. This special path is handled later, but the counters are not updated. Factor out the common send and count actions as a function. Reviewed by: kp Differential Revision: https://reviews.freebsd.org/D28537 (cherry picked from commit 3c958f5fdfc01b7579ea0fbfc3f15f8a85bebee9)
-rw-r--r--sys/netgraph/ng_bridge.c59
1 files changed, 38 insertions, 21 deletions
diff --git a/sys/netgraph/ng_bridge.c b/sys/netgraph/ng_bridge.c
index b6f763dcb631..3b00e4c03124 100644
--- a/sys/netgraph/ng_bridge.c
+++ b/sys/netgraph/ng_bridge.c
@@ -695,6 +695,41 @@ struct ng_bridge_send_ctx {
int manycast, error;
};
+/*
+ * Update stats and send out
+ */
+static inline int
+ng_bridge_send_data(link_cp dst, int manycast, struct mbuf *m, item_p item) {
+ int error = 0;
+ size_t len = m->m_pkthdr.len;
+
+ if(item != NULL)
+ NG_FWD_NEW_DATA(error, item, dst->hook, m);
+ else
+ NG_SEND_DATA_ONLY(error, dst->hook, m);
+
+ if (error == 0) {
+ counter_u64_add(dst->stats.xmitPackets, 1);
+ counter_u64_add(dst->stats.xmitOctets, len);
+ switch (manycast) {
+ default: /* unknown unicast */
+ break;
+ case 1: /* multicast */
+ counter_u64_add(dst->stats.xmitMulticasts, 1);
+ break;
+ case 2: /* broadcast */
+ counter_u64_add(dst->stats.xmitBroadcasts, 1);
+ break;
+ }
+ }
+
+ return (error);
+}
+
+/*
+ * Loop body for sending to multiple destinations
+ * return 0 to stop looping
+ */
static int
ng_bridge_send_ctx(hook_p dst, void *arg)
{
@@ -733,22 +768,8 @@ ng_bridge_send_ctx(hook_p dst, void *arg)
return (0); /* abort loop */
}
- /* Update stats */
- counter_u64_add(destLink->stats.xmitPackets, 1);
- counter_u64_add(destLink->stats.xmitOctets, m2->m_pkthdr.len);
- switch (ctx->manycast) {
- default: /* unknown unicast */
- break;
- case 1: /* multicast */
- counter_u64_add(destLink->stats.xmitMulticasts, 1);
- break;
- case 2: /* broadcast */
- counter_u64_add(destLink->stats.xmitBroadcasts, 1);
- break;
- }
-
/* Send packet */
- NG_SEND_DATA_ONLY(error, destLink->hook, m2);
+ error = ng_bridge_send_data(destLink, ctx->manycast, m2, NULL);
if(error)
ctx->error = error;
return (1);
@@ -889,10 +910,7 @@ ng_bridge_rcvdata(hook_p hook, item_p item)
}
/* Deliver packet out the destination link */
- counter_u64_add(destLink->stats.xmitPackets, 1);
- counter_u64_add(destLink->stats.xmitOctets, ctx.m->m_pkthdr.len);
- NG_FWD_NEW_DATA(ctx.error, item, destLink->hook, ctx.m);
- return (ctx.error);
+ return (ng_bridge_send_data(destLink, ctx.manycast, ctx.m, item));
}
/* Destination host is not known */
@@ -913,8 +931,7 @@ ng_bridge_rcvdata(hook_p hook, item_p item)
* If we've sent all the others, send the original
* on the first link we found.
*/
- NG_FWD_NEW_DATA(ctx.error, item, ctx.foundFirst->hook, ctx.m);
- return (ctx.error);
+ return (ng_bridge_send_data(ctx.foundFirst, ctx.manycast, ctx.m, item));
}
/*