Download raw body.
replace macro IFP_TO_IA with function in_ifp2ia
Hi,
Can we replace macro IFP_TO_IA() with function in_ifp2ia() ?
Adding locks will be easier when you don't have to do it in a header
file.
ok?
bluhm
Index: netinet/igmp.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/igmp.c,v
diff -u -p -r1.92 igmp.c
--- netinet/igmp.c 17 Nov 2025 23:53:57 -0000 1.92
+++ netinet/igmp.c 2 Dec 2025 10:33:17 -0000
@@ -427,7 +427,7 @@ igmp_input_if(struct ifnet *ifp, struct
* determine the arrival interface of an incoming packet.
*/
if ((ip->ip_src.s_addr & IN_CLASSA_NET) == 0) {
- IFP_TO_IA(ifp, ia);
+ ia = in_ifp2ia(ifp);
if (ia)
ip->ip_src.s_addr = ia->ia_net;
}
@@ -466,7 +466,7 @@ igmp_input_if(struct ifnet *ifp, struct
* leave requires knowing that we are the only member of a
* group.
*/
- IFP_TO_IA(ifp, ia);
+ ia = in_ifp2ia(ifp);
if (ia && ip->ip_src.s_addr == ia->ia_addr.sin_addr.s_addr)
break;
#endif
@@ -494,7 +494,7 @@ igmp_input_if(struct ifnet *ifp, struct
*/
if ((ip->ip_src.s_addr & IN_CLASSA_NET) == 0) {
#ifndef MROUTING
- IFP_TO_IA(ifp, ia);
+ ia = in_ifp2ia(ifp);
#endif
if (ia)
ip->ip_src.s_addr = ia->ia_net;
Index: netinet/in.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/in.c,v
diff -u -p -r1.189 in.c
--- netinet/in.c 13 Nov 2025 23:30:01 -0000 1.189
+++ netinet/in.c 2 Dec 2025 10:29:18 -0000
@@ -193,6 +193,28 @@ in_sa2sin(struct sockaddr *sa, struct so
return 0;
}
+/*
+ * Finding the internet address structure (in_ifaddr) corresponding
+ * to a given interface (ifnet structure).
+ */
+struct in_ifaddr *
+in_ifp2ia(struct ifnet *ifp)
+{
+ struct in_ifaddr *ia = NULL;
+ struct ifaddr *ifa;
+
+ NET_ASSERT_LOCKED();
+
+ TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) {
+ if (ifa->ifa_addr->sa_family != AF_INET)
+ continue;
+ ia = ifatoia(ifa);
+ break;
+ }
+
+ return (ia);
+}
+
int
in_control(struct socket *so, u_long cmd, caddr_t data, struct ifnet *ifp)
{
Index: netinet/in_pcb.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/in_pcb.c,v
diff -u -p -r1.321 in_pcb.c
--- netinet/in_pcb.c 24 Oct 2025 15:09:56 -0000 1.321
+++ netinet/in_pcb.c 2 Dec 2025 10:33:59 -0000
@@ -1024,7 +1024,7 @@ in_pcbselsrc(struct in_addr *insrc, cons
ifp = if_get(mopts->imo_ifidx);
if (ifp != NULL) {
if (ifp->if_rdomain == rtable_l2(rtableid))
- IFP_TO_IA(ifp, ia);
+ ia = in_ifp2ia(ifp);
if (ia == NULL) {
if_put(ifp);
return (EADDRNOTAVAIL);
Index: netinet/in_var.h
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/in_var.h,v
diff -u -p -r1.43 in_var.h
--- netinet/in_var.h 12 Nov 2025 11:37:08 -0000 1.43
+++ netinet/in_var.h 2 Dec 2025 10:30:44 -0000
@@ -76,23 +76,6 @@ struct in_aliasreq {
};
#ifdef _KERNEL
-/*
- * Macro for finding the internet address structure (in_ifaddr) corresponding
- * to a given interface (ifnet structure).
- */
-#define IFP_TO_IA(ifp, ia) \
- /* struct ifnet *ifp; */ \
- /* struct in_ifaddr *ia; */ \
-do { \
- struct ifaddr *ifa; \
- NET_ASSERT_LOCKED(); \
- TAILQ_FOREACH(ifa, &(ifp)->if_addrlist, ifa_list) { \
- if (ifa->ifa_addr->sa_family == AF_INET) \
- break; \
- } \
- (ia) = ifatoia(ifa); \
-} while (/* CONSTCOND */ 0)
-
struct router_info;
/*
@@ -119,6 +102,7 @@ ifmatoinm(struct ifmaddr *ifma)
return ((struct in_multi *)(ifma));
}
+struct in_ifaddr *in_ifp2ia(struct ifnet *);
int in_ifinit(struct ifnet *,
struct in_ifaddr *, struct sockaddr_in *, int);
struct in_multi *in_lookupmulti(const struct in_addr *, struct ifnet *);
Index: netinet/ip_output.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/ip_output.c,v
diff -u -p -r1.414 ip_output.c
--- netinet/ip_output.c 11 Nov 2025 16:57:06 -0000 1.414
+++ netinet/ip_output.c 2 Dec 2025 10:34:36 -0000
@@ -175,7 +175,7 @@ reroute:
if (ip->ip_src.s_addr == INADDR_ANY) {
struct in_ifaddr *ia;
- IFP_TO_IA(ifp, ia);
+ ia = in_ifp2ia(ifp);
if (ia != NULL)
ip->ip_src = ia->ia_addr.sin_addr;
}
@@ -293,7 +293,7 @@ reroute:
if (ip->ip_src.s_addr == INADDR_ANY) {
struct in_ifaddr *ia;
- IFP_TO_IA(ifp, ia);
+ ia = in_ifp2ia(ifp);
if (ia != NULL)
ip->ip_src = ia->ia_addr.sin_addr;
}
@@ -1702,9 +1702,9 @@ ip_getmoptions(int optname, struct ip_mo
if (imo == NULL || (ifp = if_get(imo->imo_ifidx)) == NULL)
addr->s_addr = INADDR_ANY;
else {
- IFP_TO_IA(ifp, ia);
- addr->s_addr = (ia == NULL) ? INADDR_ANY
- : ia->ia_addr.sin_addr.s_addr;
+ ia = in_ifp2ia(ifp);
+ addr->s_addr = (ia == NULL) ? INADDR_ANY :
+ ia->ia_addr.sin_addr.s_addr;
if_put(ifp);
}
return (0);
replace macro IFP_TO_IA with function in_ifp2ia