aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce M Simpson <bms@FreeBSD.org>2026-02-18 08:29:58 +0000
committerBruce M Simpson <bms@FreeBSD.org>2026-07-27 21:55:12 +0000
commite52655a939099402bab7e603ced58b17af106e23 (patch)
tree9be47b3f0bed6d2b120b1e9e7c56ebaf5ff96fc0
parent698402f4f97ce3bbe8130382c0bb16d48a87ff63 (diff)
netinet: Promote IFP_TO_IA() from macro to function in_ifprimaryaddr().
in_ifprimaryaddr() exists only to support IPv4 multicast usage. Since the adoption of epoch tracking, ifa_ref() is no longer required in its body; that was originally introduced by rwatson in 2009. We could not use __deprecated1() from <sys/cdefs.h> anyway, as IFP_TO_IA() is a macro, not a function. Approved by: glebius (2026-02-26) Reviewed by: adrian, glebius, pouria Differential Revision: D55344
-rw-r--r--sys/netinet/in.c22
-rw-r--r--sys/netinet/in.h1
-rw-r--r--sys/netinet/in_var.h2
3 files changed, 24 insertions, 1 deletions
diff --git a/sys/netinet/in.c b/sys/netinet/in.c
index 510cfa79d54b..508bc43bc63c 100644
--- a/sys/netinet/in.c
+++ b/sys/netinet/in.c
@@ -207,6 +207,28 @@ in_ifhasaddr(struct ifnet *ifp, struct in_addr in)
}
/*
+ * Return the first configured IPv4 address on the given ifnet.
+ * Replaces deprecated IFP_TO_IA() from 4.3BSD.
+ * Used only by IPv4 multicast, where source-address selection
+ * has not yet been introduced.
+ *
+ * Returns ifa or NULL.
+ */
+struct in_ifaddr *
+in_ifprimaryaddr(struct ifnet *ifp)
+{
+ struct ifaddr *ifa;
+
+ NET_EPOCH_ASSERT();
+
+ CK_STAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link)
+ if (ifa->ifa_addr->sa_family == AF_INET)
+ break;
+
+ return ((struct in_ifaddr *)ifa);
+}
+
+/*
* Return a reference to the interface address which is different to
* the supplied one but with same IP address value.
*/
diff --git a/sys/netinet/in.h b/sys/netinet/in.h
index 94f4bb682489..c4698b7056eb 100644
--- a/sys/netinet/in.h
+++ b/sys/netinet/in.h
@@ -677,6 +677,7 @@ bool in_localip(struct in_addr);
bool in_localip_fib(struct in_addr, uint16_t);
bool in_ifhasaddr(struct ifnet *, struct in_addr);
struct in_ifaddr *in_findlocal(uint32_t, bool);
+struct in_ifaddr *in_ifprimaryaddr(struct ifnet *);
int inet_aton(const char *, struct in_addr *); /* in libkern */
char *inet_ntoa_r(struct in_addr ina, char *buf); /* in libkern */
char *inet_ntop(int, const void *, char *, socklen_t); /* in libkern */
diff --git a/sys/netinet/in_var.h b/sys/netinet/in_var.h
index 6d843cf2f6ef..191f3a54dbe5 100644
--- a/sys/netinet/in_var.h
+++ b/sys/netinet/in_var.h
@@ -153,7 +153,7 @@ do { \
/*
* Macro for finding the internet address structure (in_ifaddr) corresponding
- * to a given interface (ifnet structure).
+ * to a given interface (ifnet structure). DEPRECATED.
*/
#define IFP_TO_IA(ifp, ia) \
/* struct ifnet *ifp; */ \