Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 31 Mar 2026 15:58:54 +0000
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 58c649f857ed - stable/15 - ip_mroute: Use a local variable to store a VIF pointer
Message-ID:  <69cbef3e.3a83d.15fcc6c2@gitrepo.freebsd.org>

index | next in thread | raw e-mail

The branch stable/15 has been updated by markj:

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

commit 58c649f857ed20ae4a53ba13f5a8ca3991947d24
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2026-02-09 22:51:55 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2026-03-31 15:57:28 +0000

    ip_mroute: Use a local variable to store a VIF pointer
    
    This is cleaner and will make it a bit easier to add some more
    indirection to the VIF table, specifically, to add per-FIB tables.
    
    No functional change intended.
    
    Reviewed by:    glebius
    MFC after:      2 weeks
    Sponsored by:   Stormshield
    Sponsored by:   Klara, Inc.
    Differential Revision:  https://reviews.freebsd.org/D55057
    
    (cherry picked from commit 0a757ef9a79d101bb4b7429ab5802579888dce98)
---
 sys/netinet/ip_mroute.c | 51 ++++++++++++++++++++++++++++---------------------
 1 file changed, 29 insertions(+), 22 deletions(-)

diff --git a/sys/netinet/ip_mroute.c b/sys/netinet/ip_mroute.c
index c69f3cc8b41e..efd63f239d9a 100644
--- a/sys/netinet/ip_mroute.c
+++ b/sys/netinet/ip_mroute.c
@@ -594,7 +594,10 @@ get_sg_cnt(struct sioc_sg_req *req)
 static int
 get_vif_cnt(struct sioc_vif_req *req)
 {
-	vifi_t vifi = req->vifi;
+	struct vif *vif;
+	vifi_t vifi;
+
+	vifi = req->vifi;
 
 	MRW_RLOCK();
 	if (vifi >= V_numvifs) {
@@ -602,12 +605,13 @@ get_vif_cnt(struct sioc_vif_req *req)
 		return EINVAL;
 	}
 
-	mtx_lock(&V_viftable[vifi].v_mtx);
-	req->icount = V_viftable[vifi].v_pkt_in;
-	req->ocount = V_viftable[vifi].v_pkt_out;
-	req->ibytes = V_viftable[vifi].v_bytes_in;
-	req->obytes = V_viftable[vifi].v_bytes_out;
-	mtx_unlock(&V_viftable[vifi].v_mtx);
+	vif = &V_viftable[vifi];
+	mtx_lock(&vif->v_mtx);
+	req->icount = vif->v_pkt_in;
+	req->ocount = vif->v_pkt_out;
+	req->ibytes = vif->v_bytes_in;
+	req->obytes = vif->v_bytes_out;
+	mtx_unlock(&vif->v_mtx);
 	MRW_RUNLOCK();
 
 	return 0;
@@ -1574,6 +1578,7 @@ static int
 ip_mdq(struct mbuf *m, struct ifnet *ifp, struct mfc *rt, vifi_t xmt_vif)
 {
 	struct ip *ip = mtod(m, struct ip *);
+	struct vif *vif;
 	vifi_t vifi;
 	int plen = ntohs(ip->ip_len);
 
@@ -1598,9 +1603,10 @@ ip_mdq(struct mbuf *m, struct ifnet *ifp, struct mfc *rt, vifi_t xmt_vif)
 	 * Don't forward if it didn't arrive from the parent vif for its origin.
 	 */
 	vifi = rt->mfc_parent;
-	if ((vifi >= V_numvifs) || (V_viftable[vifi].v_ifp != ifp)) {
+	vif = &V_viftable[vifi];
+	if (vifi >= V_numvifs || vif->v_ifp != ifp) {
 		CTR4(KTR_IPMF, "%s: rx on wrong ifp %p (vifi %d, v_ifp %p)",
-				__func__, ifp, (int)vifi, V_viftable[vifi].v_ifp);
+				__func__, ifp, (int)vifi, vif->v_ifp);
 		MRTSTAT_INC(mrts_wrong_if);
 		++rt->mfc_wrong_if;
 		/*
@@ -1612,7 +1618,7 @@ ip_mdq(struct mbuf *m, struct ifnet *ifp, struct mfc *rt, vifi_t xmt_vif)
 		 * of the iif (broadcast media, GRE tunnel, etc).
 		 */
 		if (V_pim_assert_enabled && (vifi < V_numvifs) &&
-		    V_viftable[vifi].v_ifp) {
+		    vif->v_ifp != NULL) {
 			if (ifp == V_multicast_register_if)
 				PIMSTAT_INC(pims_rcv_registers_wrongiif);
 
@@ -1655,15 +1661,15 @@ ip_mdq(struct mbuf *m, struct ifnet *ifp, struct mfc *rt, vifi_t xmt_vif)
 	}
 
 	/* If I sourced this packet, it counts as output, else it was input. */
-	mtx_lock(&V_viftable[vifi].v_mtx);
-	if (in_hosteq(ip->ip_src, V_viftable[vifi].v_lcl_addr)) {
-		V_viftable[vifi].v_pkt_out++;
-		V_viftable[vifi].v_bytes_out += plen;
+	mtx_lock(&vif->v_mtx);
+	if (in_hosteq(ip->ip_src, vif->v_lcl_addr)) {
+		vif->v_pkt_out++;
+		vif->v_bytes_out += plen;
 	} else {
-		V_viftable[vifi].v_pkt_in++;
-		V_viftable[vifi].v_bytes_in += plen;
+		vif->v_pkt_in++;
+		vif->v_bytes_in += plen;
 	}
-	mtx_unlock(&V_viftable[vifi].v_mtx);
+	mtx_unlock(&vif->v_mtx);
 
 	rt->mfc_pkt_cnt++;
 	rt->mfc_byte_cnt += plen;
@@ -1676,12 +1682,13 @@ ip_mdq(struct mbuf *m, struct ifnet *ifp, struct mfc *rt, vifi_t xmt_vif)
 	 */
 	for (vifi = 0; vifi < V_numvifs; vifi++)
 		if ((rt->mfc_ttls[vifi] > 0) && (ip->ip_ttl > rt->mfc_ttls[vifi])) {
-			V_viftable[vifi].v_pkt_out++;
-			V_viftable[vifi].v_bytes_out += plen;
-			if (V_viftable[vifi].v_flags & VIFF_REGISTER)
-				pim_register_send(ip, V_viftable + vifi, m, rt);
+			vif = &V_viftable[vifi];
+			vif->v_pkt_out++;
+			vif->v_bytes_out += plen;
+			if (vif->v_flags & VIFF_REGISTER)
+				pim_register_send(ip, vif, m, rt);
 			else
-				phyint_send(ip, V_viftable + vifi, m);
+				phyint_send(ip, vif, m);
 		}
 
 	/*


home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69cbef3e.3a83d.15fcc6c2>