git: a84bf5eaa10c - main - debugnet: fix an errant assertion

From: Mitchell Horne <mhorne_at_FreeBSD.org>
Date: Sat, 14 May 2022 13:28:45 UTC
The branch main has been updated by mhorne:

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

commit a84bf5eaa10c2db8856c7497b63ae3caceac8c17
Author:     Mitchell Horne <mhorne@FreeBSD.org>
AuthorDate: 2022-05-14 13:23:08 +0000
Commit:     Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2022-05-14 13:27:53 +0000

    debugnet: fix an errant assertion
    
    We may call debugnet_free() before g_debugnet_pcb_inuse is true,
    specifically in the cases where the interface is down or does not
    support debugnet. pcb->dp_drv_input is used to hold the real driver
    if_input callback while debugnet is in use, so we can check the status
    of this field in the assertion.
    
    This can be triggered trivially by trying to configure netdump on an
    unsupported interface at the ddb prompt.
    
    Initializing the dp_drv_input field to NULL explicitly is not necessary
    but helps display the intent.
    
    PR:             263929
    Reported by:    Martin Filla <freebsd@sysctl.cz>
    Reviewed by:    cem, markj
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D35179
---
 sys/net/debugnet.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/sys/net/debugnet.c b/sys/net/debugnet.c
index 7a2c98ace65d..fa8d64ab86c8 100644
--- a/sys/net/debugnet.c
+++ b/sys/net/debugnet.c
@@ -605,8 +605,8 @@ debugnet_free(struct debugnet_pcb *pcb)
 {
 	struct ifnet *ifp;
 
-	MPASS(g_debugnet_pcb_inuse);
 	MPASS(pcb == &g_dnet_pcb);
+	MPASS(pcb->dp_drv_input == NULL || g_debugnet_pcb_inuse);
 
 	ifp = pcb->dp_ifp;
 	if (ifp != NULL) {
@@ -646,6 +646,7 @@ debugnet_connect(const struct debugnet_conn_params *dcp,
 		.dp_seqno = 1,
 		.dp_ifp = dcp->dc_ifp,
 		.dp_rx_handler = dcp->dc_rx_handler,
+		.dp_drv_input = NULL,
 	};
 
 	/* Switch to the debugnet mbuf zones. */