git: bb2ab7a374b9 - main - ng_pipe: Remove node when all hooks are disconnected

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Wed, 24 Apr 2024 13:17:09 UTC
The branch main has been updated by markj:

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

commit bb2ab7a374b9d81f8368acc506c9700af20a22d6
Author:     Martin Vahlensieck <git@academicsolutions.ch>
AuthorDate: 2024-04-17 18:51:40 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2024-04-24 12:44:50 +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
---
 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);
 }