aboutsummaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorLutz Donnerhacke <donner@FreeBSD.org>2021-02-10 10:47:38 +0000
committerLutz Donnerhacke <donner@FreeBSD.org>2021-02-10 18:05:37 +0000
commit3c958f5fdfc01b7579ea0fbfc3f15f8a85bebee9 (patch)
tree09049e72f145f7cc259129e85aabf6ba081e08f3 /sys
parente6f59be239aa17f80b44ded4779e29f5d5352b28 (diff)
downloadsrc-3c958f5fdfc01b7579ea0fbfc3f15f8a85bebee9.tar.gz
src-3c958f5fdfc01b7579ea0fbfc3f15f8a85bebee9.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 MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D28537
Diffstat (limited to 'sys')
-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 29ab2c715aa7..7b03b1a2599b 100644
--- a/sys/netgraph/ng_bridge.c
+++ b/sys/netgraph/ng_bridge.c
@@ -626,6 +626,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)
{
@@ -664,22 +699,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);
@@ -820,10 +841,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 */
@@ -844,8 +862,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));
}
/*