From bb2ab7a374b9d81f8368acc506c9700af20a22d6 Mon Sep 17 00:00:00 2001 From: Martin Vahlensieck Date: Wed, 17 Apr 2024 20:51:40 +0200 Subject: [PATCH] ng_pipe: Remove node when all hooks are disconnected This is the behavior described in the man page. Signed-off-by: Martin Vahlensieck 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 c2424e3db48..7afaf24f591 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); } -- 2.45.0