git: a3ca254e6986 - stable/14 - ng_pipe: Remove node when all hooks are disconnected

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Wed, 08 May 2024 13:07:49 UTC
The branch stable/14 has been updated by markj:

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

commit a3ca254e698698cfa130770f3c5c12f7fd9b5685
Author:     Martin Vahlensieck <git@academicsolutions.ch>
AuthorDate: 2024-04-17 18:51:40 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2024-05-08 13:06:16 +0000

    ng_pipe: Remove node when all hooks are disconnected
    
    This is the behavior described in the man page.
    
    Signed-off-by: Martin Vahlensieck <git@academicsolutions.ch>
    
    Discussed with: glebius
    Reviewed by:    markj
    MFC after:      2 weeks
    Pull Request:   https://github.com/freebsd/freebsd-src/pull/1181
    
    (cherry picked from commit bb2ab7a374b9d81f8368acc506c9700af20a22d6)
---
 sys/netgraph/ng_pipe.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/sys/netgraph/ng_pipe.c b/sys/netgraph/ng_pipe.c
index c2424e3db48a..7afaf24f5914 100644
--- a/sys/netgraph/ng_pipe.c
+++ b/sys/netgraph/ng_pipe.c
@@ -936,6 +936,7 @@ ngp_disconnect(hook_p hook)
 	struct hookinfo *const hinfo = NG_HOOK_PRIVATE(hook);
 	struct ngp_fifo *ngp_f;
 	struct ngp_hdr *ngp_h;
+	priv_p priv;
 
 	KASSERT(hinfo != NULL, ("%s: null info", __FUNCTION__));
 	hinfo->hook = NULL;
@@ -962,6 +963,12 @@ ngp_disconnect(hook_p hook)
 	if (hinfo->ber_p)
 		free(hinfo->ber_p, M_NG_PIPE);
 
+	/* Destroy the node if all hooks are disconnected */
+	priv = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
+
+	if (priv->upper.hook == NULL && priv->lower.hook == NULL)
+		ng_rmnode_self(NG_HOOK_NODE(hook));
+
 	return (0);
 }