Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 27 Jul 2026 21:55:27 +0000
From:      Bruce M Simpson <bms@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: d93d23529128 - main - netinet: Replace IFP_TO_IA() with in_ifprimaryaddr() completely.
Message-ID:  <6a67d3cf.21369.34fe6774@gitrepo.freebsd.org>

index | next in thread | raw e-mail

The branch main has been updated by bms:

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

commit d93d235291282b8eec90e49be95a1e78a295b34e
Author:     Bruce M Simpson <bms@FreeBSD.org>
AuthorDate: 2026-02-18 08:53:07 +0000
Commit:     Bruce M Simpson <bms@FreeBSD.org>
CommitDate: 2026-07-27 21:55:12 +0000

    netinet: Replace IFP_TO_IA() with in_ifprimaryaddr() completely.
    
    IPv4 multicast currently has the big caveat that it depends on the first
    assigned IPv4 address on an interface (the so-called "primary address").
    
    in_ifprimaryaddr() only needs to be used by the following:
     - the 0.0.0.0 booting node input workaround in IGMPv1;
     - filtering out the node's own reports in IGMPv2;
     - preserving the source IP where an IGMPv3 report has been looped back;
     - inferring the default upstream IPv4 interface address for the
       IP_MULTICAST_IF socket option;
     - and inferring the source address during ip_output() for a multicast
       datagram where an interface has been explicitly specified by that option.
    
    All of these uses mandate the use of IPv4 source address selection, but
    FreeBSD does not yet (fully) implement this functionality.
    
    Approved by:    glebius (2026-02-26)
    Reviewed by:    adrian, glebius, pouria
    Differential Revision:  D55345
---
 sys/netinet/igmp.c      | 10 +++++-----
 sys/netinet/in_mcast.c  |  2 +-
 sys/netinet/in_var.h    | 15 ---------------
 sys/netinet/ip_output.c |  2 +-
 4 files changed, 7 insertions(+), 22 deletions(-)

diff --git a/sys/netinet/igmp.c b/sys/netinet/igmp.c
index 226f38a035fb..5ca5a4575026 100644
--- a/sys/netinet/igmp.c
+++ b/sys/netinet/igmp.c
@@ -213,8 +213,8 @@ static MALLOC_DEFINE(M_IGMP, "igmp", "igmp state");
  * Obviously the IGMPv3 per-interface state has per-vimage granularity
  * also as a result.
  *
- * FUTURE: Stop using IFP_TO_IA/INADDR_ANY, and use source address selection
- * policy to control the address used by IGMP on the link.
+ * FUTURE: Use source address selection policy to control the address
+ * used by IGMP on the link.
  */
 VNET_DEFINE_STATIC(int, interface_timers_running);	/* IGMPv3 general
 							 * query response */
@@ -1283,7 +1283,7 @@ igmp_input_v1_report(struct ifnet *ifp, /*const*/ struct ip *ip,
 	 * Replace 0.0.0.0 with the subnet address if told to do so.
 	 */
 	if (V_igmp_recvifkludge && in_nullhost(ip->ip_src)) {
-		IFP_TO_IA(ifp, ia);
+		ia = in_ifprimaryaddr(ifp);
 		if (ia != NULL)
 			ip->ip_src.s_addr = htonl(ia->ia_subnet);
 	}
@@ -1377,7 +1377,7 @@ igmp_input_v2_report(struct ifnet *ifp, /*const*/ struct ip *ip,
 	 * leave requires knowing that we are the only member of a
 	 * group.
 	 */
-	IFP_TO_IA(ifp, ia);
+	ia = in_ifprimaryaddr(ifp);
 	if (ia != NULL && in_hosteq(ip->ip_src, IA_SIN(ia)->sin_addr)) {
 		return (0);
 	}
@@ -3600,7 +3600,7 @@ igmp_v3_encap_report(struct ifnet *ifp, struct mbuf *m)
 	if (m->m_flags & M_IGMP_LOOP) {
 		struct in_ifaddr *ia;
 
-		IFP_TO_IA(ifp, ia);
+		ia = in_ifprimaryaddr(ifp);
 		if (ia != NULL)
 			ip->ip_src = ia->ia_addr.sin_addr;
 	}
diff --git a/sys/netinet/in_mcast.c b/sys/netinet/in_mcast.c
index 340218cf5397..934cc71e745b 100644
--- a/sys/netinet/in_mcast.c
+++ b/sys/netinet/in_mcast.c
@@ -1768,7 +1768,7 @@ inp_getmoptions(struct inpcb *inp, struct sockopt *sopt)
 
 				mreqn.imr_ifindex = ifp->if_index;
 				NET_EPOCH_ENTER(et);
-				IFP_TO_IA(ifp, ia);
+				ia = in_ifprimaryaddr(ifp);
 				if (ia != NULL)
 					mreqn.imr_address =
 					    IA_SIN(ia)->sin_addr;
diff --git a/sys/netinet/in_var.h b/sys/netinet/in_var.h
index 191f3a54dbe5..99a628477155 100644
--- a/sys/netinet/in_var.h
+++ b/sys/netinet/in_var.h
@@ -151,21 +151,6 @@ do {									\
 	(ifp) = (ia == NULL) ? NULL : ia->ia_ifp; \
 }
 
-/*
- * Macro for finding the internet address structure (in_ifaddr) corresponding
- * to a given interface (ifnet structure). DEPRECATED.
- */
-#define IFP_TO_IA(ifp, ia)						\
-	/* struct ifnet *ifp; */					\
-	/* struct in_ifaddr *ia; */					\
-do {									\
-	NET_EPOCH_ASSERT();						\
-	for ((ia) = CK_STAILQ_FIRST(&V_in_ifaddrhead);			\
-	    (ia) != NULL && (ia)->ia_ifp != (ifp);			\
-	    (ia) = CK_STAILQ_NEXT((ia), ia_link))			\
-		continue;						\
-} while (0)
-
 /*
  * Legacy IPv4 IGMP per-link structure.
  */
diff --git a/sys/netinet/ip_output.c b/sys/netinet/ip_output.c
index 200f281f34a7..a7cb1234f97c 100644
--- a/sys/netinet/ip_output.c
+++ b/sys/netinet/ip_output.c
@@ -459,7 +459,7 @@ again:
 		 */
 		ifp = imo->imo_multicast_ifp;
 		mtu = ifp->if_mtu;
-		IFP_TO_IA(ifp, ia);
+		ia = in_ifprimaryaddr(ifp);
 		isbroadcast = false;
 		/* Interface may have no addresses. */
 		if (ia != NULL)


home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6a67d3cf.21369.34fe6774>