git: c2f799d4193f - main - iflib: Add support for SIOCGIFDOWNREASON ioctl

From: Sumit Saxena <ssaxena_at_FreeBSD.org>
Date: Tue, 10 Feb 2026 09:30:42 UTC
The branch main has been updated by ssaxena:

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

commit c2f799d4193f135f4d36e9f622b10b825b9144eb
Author:     Chandrakanth Patil <chandrakanth.patil@broadcom.com>
AuthorDate: 2026-01-30 07:15:55 +0000
Commit:     Sumit Saxena <ssaxena@FreeBSD.org>
CommitDate: 2026-02-10 09:30:06 +0000

    iflib: Add support for SIOCGIFDOWNREASON ioctl
    
    This change adds native support for the SIOCGIFDOWNREASON ioctl in iflib.
    
    When ifconfig issues SIOCGIFDOWNREASON, the request is now routed through a
    new driver callback (IFDI_GET_DOWNREASON). iflib allocates the ifdownreason
    structure, calls the driver to fill the down-reason message, and then
    returns the data back to ifconfig for display.
    
    Without this change, iflib-based drivers cannot implement link-down reason
    reporting even if the hardware provides the information.
    
    No functional change for existing drivers unless they implement the new
    IFDI_GET_DOWNREASON method. Existing drivers continue to behave as before.
    
    Reviewed by: gallatin, erj, kgalazka, ssaxena, #iflib
    Differential Revision: https://reviews.freebsd.org/D54045
    MFC After: 1 week
---
 sys/net/ifdi_if.m | 11 +++++++++++
 sys/net/iflib.c   |  5 +++++
 2 files changed, 16 insertions(+)

diff --git a/sys/net/ifdi_if.m b/sys/net/ifdi_if.m
index f4a3db5092ab..cb24ba36ee60 100644
--- a/sys/net/ifdi_if.m
+++ b/sys/net/ifdi_if.m
@@ -117,6 +117,12 @@ CODE {
 	{
 		return (false);
 	}
+
+	static int
+	null_get_downreason(if_ctx_t _ctx __unused, struct ifdownreason *_ifdr __unused)
+	{
+		return (ENOTSUP);
+	}
 };
 
 #
@@ -364,3 +370,8 @@ METHOD bool needs_restart {
 	if_ctx_t _ctx;
 	enum iflib_restart_event _event;
 } DEFAULT null_needs_restart;
+
+METHOD int get_downreason {
+	if_ctx_t _ctx;
+	struct ifdownreason *_ifdr;
+} DEFAULT null_get_downreason;
diff --git a/sys/net/iflib.c b/sys/net/iflib.c
index 8e2fd257ca74..08282d1799b8 100644
--- a/sys/net/iflib.c
+++ b/sys/net/iflib.c
@@ -4540,6 +4540,11 @@ iflib_if_ioctl(if_t ifp, u_long command, caddr_t data)
 		err = IFDI_PRIV_IOCTL(ctx, command, data);
 		CTX_UNLOCK(ctx);
 		break;
+	case SIOCGIFDOWNREASON:
+		CTX_LOCK(ctx);
+		err = IFDI_GET_DOWNREASON(ctx, (struct ifdownreason *)data);
+		CTX_UNLOCK(ctx);
+		break;
 	default:
 		err = ether_ioctl(ifp, command, data);
 		break;