git: 7f1009d61c3e - stable/15 - net/if.c: Add fib-aware ifa_ifwithaddr()

Bojan Novković <[email protected]>
Newsgroups gmane.os.freebsd.devel.cvs.src,gmane.os.freebsd.devel.stable.scm
Message-ID <[email protected]>
The branch stable/15 has been updated by bnovkov:

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

commit 7f1009d61c3e70b34af749d4d7f21c5e152b3baf
Author:     Pouria Mousavizadeh Tehrani <[email protected]>
AuthorDate: 2026-07-17 16:11:42 +0000
Commit:     Bojan Novković <[email protected]>
CommitDate: 2026-08-06 16:18:25 +0000

    net/if.c: Add fib-aware ifa_ifwithaddr()
    
    Add FIB selection logic by introducing ifa_ifwithaddr_fib() to
    support FIB-specific lookups. Then have ifa_ifwithaddr() wrap it
    with RT_ALL_FIBS.
    Also, do the same for ifa_ifwithaddr_check().
    
    Reviewed by:    glebius, bnovkov
    Differential Revision: https://reviews.freebsd.org/D58305
    
    (cherry picked from commit b00d30950cde27eda8f51523a40f2c05a38daac1)
---
 sys/net/if.c     | 29 +++++++++++++++++++++++------
 sys/net/if_var.h |  2 ++
 2 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/sys/net/if.c b/sys/net/if.c
index ed22bbd8f8da..8ee7d3f3f924 100644
--- a/sys/net/if.c
+++ b/sys/net/if.c
@@ -1817,18 +1817,18 @@ sa_dl_equal(const struct sockaddr *a, const struct sockaddr *b)
 }
 
 /*
- * Locate an interface based on a complete address.
+ * Locate an interface on the specified fib based on a complete address.
  */
-/*ARGSUSED*/
 struct ifaddr *
-ifa_ifwithaddr(const struct sockaddr *addr)
+ifa_ifwithaddr_fib(const struct sockaddr *addr, int fibnum)
 {
 	struct ifnet *ifp;
 	struct ifaddr *ifa;
 
 	NET_EPOCH_ASSERT();
-
 	CK_STAILQ_FOREACH(ifp, &V_ifnet, if_link) {
+		if ((fibnum != RT_ALL_FIBS) && (ifp->if_fib != fibnum))
+			continue;
 		CK_STAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
 			if (ifa->ifa_addr->sa_family != addr->sa_family)
 				continue;
@@ -1849,18 +1849,35 @@ done:
 	return (ifa);
 }
 
+/*
+ * Locate an interface based on a complete address.
+ */
+struct ifaddr *
+ifa_ifwithaddr(const struct sockaddr *addr)
+{
+
+	return (ifa_ifwithaddr_fib(addr, RT_ALL_FIBS));
+}
+
 int
-ifa_ifwithaddr_check(const struct sockaddr *addr)
+ifa_ifwithaddr_fib_check(const struct sockaddr *addr, int fibnum)
 {
 	struct epoch_tracker et;
 	int rc;
 
 	NET_EPOCH_ENTER(et);
-	rc = (ifa_ifwithaddr(addr) != NULL);
+	rc = (ifa_ifwithaddr_fib(addr, fibnum) != NULL);
 	NET_EPOCH_EXIT(et);
 	return (rc);
 }
 
+int
+ifa_ifwithaddr_check(const struct sockaddr *addr)
+{
+
+	return (ifa_ifwithaddr_fib_check(addr, RT_ALL_FIBS));
+}
+
 /*
  * Locate an interface based on the broadcast address.
  */
diff --git a/sys/net/if_var.h b/sys/net/if_var.h
index 961259bb0ca1..3d0f0624aed2 100644
--- a/sys/net/if_var.h
+++ b/sys/net/if_var.h
@@ -547,7 +547,9 @@ int	ifa_add_loopback_route(struct ifaddr *, struct sockaddr *);
 int	ifa_del_loopback_route(struct ifaddr *, struct sockaddr *);
 int	ifa_switch_loopback_route(struct ifaddr *, struct sockaddr *);
 
+struct	ifaddr *ifa_ifwithaddr_fib(const struct sockaddr *, int);
 struct	ifaddr *ifa_ifwithaddr(const struct sockaddr *);
+int		ifa_ifwithaddr_fib_check(const struct sockaddr *, int);
 int		ifa_ifwithaddr_check(const struct sockaddr *);
 struct	ifaddr *ifa_ifwithbroadaddr(const struct sockaddr *, int);
 struct	ifaddr *ifa_ifwithdstaddr(const struct sockaddr *, int);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.