git: faa7d6c2f94a - stable/13 - if_vxlan(4): Correct the statistic for output bytes

From: Zhenlei Huang <zlei_at_FreeBSD.org>
Date: Wed, 11 Jan 2023 10:39:56 UTC
The branch stable/13 has been updated by zlei:

URL: https://cgit.FreeBSD.org/src/commit/?id=faa7d6c2f94aee09cdc92142d51a0b2eb12b3239

commit faa7d6c2f94aee09cdc92142d51a0b2eb12b3239
Author:     Zhenlei Huang <zlei.huang@gmail.com>
AuthorDate: 2022-10-07 11:37:12 +0000
Commit:     Zhenlei Huang <zlei@FreeBSD.org>
CommitDate: 2023-01-11 10:35:59 +0000

    if_vxlan(4): Correct the statistic for output bytes
    
    The vxlan interface encapsulates the Ethernet frame by prepending IP/UDP
    and vxlan headers. For statistics, only the payload, i.e. the
    encapsulated (inner) frame should be counted.
    
    Event:          Aberdeen Hackathon 2022
    Reviewed by:    kp
    Approved by:    kp (mentor)
    Differential Revision:  https://reviews.freebsd.org/D36855
    
    (cherry picked from commit de1ea2d5171ec53acd69f93821b9507267ee44b7)
---
 sys/net/if_vxlan.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/sys/net/if_vxlan.c b/sys/net/if_vxlan.c
index f8e8c413ea62..7ea480899d7d 100644
--- a/sys/net/if_vxlan.c
+++ b/sys/net/if_vxlan.c
@@ -2501,7 +2501,7 @@ vxlan_encap4(struct vxlan_softc *sc, const union vxlan_sockaddr *fvxlsa,
 	struct ip *ip;
 	struct in_addr srcaddr, dstaddr;
 	uint16_t srcport, dstport;
-	int len, mcast, error;
+	int plen, mcast, error;
 	struct route route, *ro;
 	struct sockaddr_in *sin;
 	uint32_t csum_flags;
@@ -2514,6 +2514,7 @@ vxlan_encap4(struct vxlan_softc *sc, const union vxlan_sockaddr *fvxlsa,
 	dstaddr = fvxlsa->in4.sin_addr;
 	dstport = fvxlsa->in4.sin_port;
 
+	plen = m->m_pkthdr.len;
 	M_PREPEND(m, sizeof(struct ip) + sizeof(struct vxlanudphdr),
 	    M_NOWAIT);
 	if (m == NULL) {
@@ -2521,11 +2522,9 @@ vxlan_encap4(struct vxlan_softc *sc, const union vxlan_sockaddr *fvxlsa,
 		return (ENOBUFS);
 	}
 
-	len = m->m_pkthdr.len;
-
 	ip = mtod(m, struct ip *);
 	ip->ip_tos = 0;
-	ip->ip_len = htons(len);
+	ip->ip_len = htons(m->m_pkthdr.len);
 	ip->ip_off = 0;
 	ip->ip_ttl = sc->vxl_ttl;
 	ip->ip_p = IPPROTO_UDP;
@@ -2591,7 +2590,7 @@ vxlan_encap4(struct vxlan_softc *sc, const union vxlan_sockaddr *fvxlsa,
 	error = ip_output(m, NULL, ro, 0, sc->vxl_im4o, NULL);
 	if (error == 0) {
 		if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1);
-		if_inc_counter(ifp, IFCOUNTER_OBYTES, len);
+		if_inc_counter(ifp, IFCOUNTER_OBYTES, plen);
 		if (mcast != 0)
 			if_inc_counter(ifp, IFCOUNTER_OMCASTS, 1);
 	} else
@@ -2613,7 +2612,7 @@ vxlan_encap6(struct vxlan_softc *sc, const union vxlan_sockaddr *fvxlsa,
 	struct ip6_hdr *ip6;
 	const struct in6_addr *srcaddr, *dstaddr;
 	uint16_t srcport, dstport;
-	int len, mcast, error;
+	int plen, mcast, error;
 	struct route_in6 route, *ro;
 	struct sockaddr_in6 *sin6;
 	uint32_t csum_flags;
@@ -2626,6 +2625,7 @@ vxlan_encap6(struct vxlan_softc *sc, const union vxlan_sockaddr *fvxlsa,
 	dstaddr = &fvxlsa->in6.sin6_addr;
 	dstport = fvxlsa->in6.sin6_port;
 
+	plen = m->m_pkthdr.len;
 	M_PREPEND(m, sizeof(struct ip6_hdr) + sizeof(struct vxlanudphdr),
 	    M_NOWAIT);
 	if (m == NULL) {
@@ -2633,8 +2633,6 @@ vxlan_encap6(struct vxlan_softc *sc, const union vxlan_sockaddr *fvxlsa,
 		return (ENOBUFS);
 	}
 
-	len = m->m_pkthdr.len;
-
 	ip6 = mtod(m, struct ip6_hdr *);
 	ip6->ip6_flow = 0;		/* BMV: Keep in forwarding entry? */
 	ip6->ip6_vfc = IPV6_VERSION;
@@ -2709,7 +2707,7 @@ vxlan_encap6(struct vxlan_softc *sc, const union vxlan_sockaddr *fvxlsa,
 	error = ip6_output(m, NULL, ro, 0, sc->vxl_im6o, NULL, NULL);
 	if (error == 0) {
 		if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1);
-		if_inc_counter(ifp, IFCOUNTER_OBYTES, len);
+		if_inc_counter(ifp, IFCOUNTER_OBYTES, plen);
 		if (mcast != 0)
 			if_inc_counter(ifp, IFCOUNTER_OMCASTS, 1);
 	} else