git: ee069c0d5d49 - stable/15 - iflib: Add support for SIOCGIFDOWNREASON ioctl

From: Kevin Bowling <kbowling_at_FreeBSD.org>
Date: Thu, 29 Oct 2026 06:03:22 UTC
The branch stable/15 has been updated by kbowling:

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

commit ee069c0d5d49578b57bd700f6f5bb41c146dbc6c
Author:     Chandrakanth Patil <chandrakanth.patil@broadcom.com>
AuthorDate: 2026-01-30 07:15:55 +0000
Commit:     Kevin Bowling <kbowling@FreeBSD.org>
CommitDate: 2026-10-29 05:40:58 +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
    
    (cherry picked from commit c2f799d4193f135f4d36e9f622b10b825b9144eb)
---
 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 c9806a3c9b1d..3fa48f7a9e97 100644
--- a/sys/net/ifdi_if.m
+++ b/sys/net/ifdi_if.m
@@ -130,6 +130,12 @@ CODE {
 	{
 		return (false);
 	}
+
+	static int
+	null_get_downreason(if_ctx_t _ctx __unused, struct ifdownreason *_ifdr __unused)
+	{
+		return (ENOTSUP);
+	}
 };
 
 #
@@ -391,3 +397,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 51491cce928e..d9b4e770741b 100644
--- a/sys/net/iflib.c
+++ b/sys/net/iflib.c
@@ -4987,6 +4987,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;