mirror of
https://github.com/freebsd/freebsd-src
synced 2024-09-06 17:18:32 +00:00
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
This commit is contained in:
parent
e6f59be239
commit
3c958f5fdf
|
@ -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));
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in a new issue