From nobody Fri May 31 16:20:02 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4VrSyB5W6wz5N8LY; Fri, 31 May 2024 16:20:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VrSyB4pjgz42dj; Fri, 31 May 2024 16:20:02 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1717172402; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=z1W4xJmnv5JLNnuQI/8WZuOHy5l5/Cz26V6aax6oxdE=; b=e+PWPinywaK5+wDCC6ZcwzxdMDFlS2mUuCrkAeczgZB8nT4jA4LpBJFSVsViknx73FvdjO eOyOdTMqbHleQzipeimIjVQG5+KLrzJ4KYSGE8+bKrA63eKY28rzjo9HdWkpBS5N2oQPJT wukyT8INeVpli4zUhIRpkz4X6ADoL4x8Ck/uNWd2CyLes7Z1odspI13dhWPLpOlmkLlXit Xah4QTF+e3O4JvoCbZZ0Af8Gn0pNyMyJ/qPIsOQUwN85Jei/FIPzsajBB8/yIjFB04HoO6 iX9Hi45fXmzaiBCPzsQGToV1EyveOWLa5+qP+KwzQh6ebCcztxbsZ7YRNyxxIg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1717172402; a=rsa-sha256; cv=none; b=M+fSkfmmJTmf10VFOjaT2PuuVChwCY8V7M3Y4KfSXZcEPdIP+uf+9u37fPH8Dxzb0CX16/ 8+XgIlZhnQhiAmMyAJ4MAMYVNxrReHtyoznEZzb8TtqrJHqcrl64YZvK6cHgRTjbMtzO9K VyTtM0nPKYu9MITAsBrT5fMcVHrlP2G24X5eFBpCfFn4ZPPuVi6SZTBe+JxDdQd+ZO0Im/ 5NTXPSZTXOPSSy6CGpwXWIVYL7TQqQ3pF+hQgaXvuQnI8JZk0m0GSTACDd7kpqsRdePcjb 0Pv0lUwSQ4CN2l9jUj0BW0+fTns+xCvVEs1jzJLygH+fyxteAd0H430p7l1Y5w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1717172402; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=z1W4xJmnv5JLNnuQI/8WZuOHy5l5/Cz26V6aax6oxdE=; b=isi9s8Towj/uiMqHPRxPuFws6e3KxSEFpiW82vbf98j1RVLi+m8H+BYyzG9OOWr4cVwmX4 Zuc4wErKPdR+ouyguHYbl0zEhtl/SQAoyF1NVBkdP/GYSuSmw9wpvG6Hv7WClI5E7kAblM CPQvD/8ZQ9LXzFRLInvnkmGNmKRG7ZHhQbT4Nh3TGvIPaw4xCZ0YO9lp9RB64AJgMMds8g HSfJ6uekZbQD9F2jl72lXSpbz5NcpQ/pOEdjGRPvTNuxPbUcp2BSMp7UeOo/4p5ZNj+vvm GjRKCXg4mvSx9LFAjTRtdteK1l3v6Ktgd5bVcWE6odFU/SF5RZFman+dzPzdTA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4VrSyB4Q70zX7k; Fri, 31 May 2024 16:20:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 44VGK2ps033361; Fri, 31 May 2024 16:20:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 44VGK2xX033356; Fri, 31 May 2024 16:20:02 GMT (envelope-from git) Date: Fri, 31 May 2024 16:20:02 GMT Message-Id: <202405311620.44VGK2xX033356@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: 9b8db66402e9 - main - netgraph: provide separate malloc type for nodes that are missing it List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 9b8db66402e94919ab47fc2d69863968e49e305a Auto-Submitted: auto-generated The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=9b8db66402e94919ab47fc2d69863968e49e305a commit 9b8db66402e94919ab47fc2d69863968e49e305a Author: Dmitry Lukhtionov AuthorDate: 2024-05-31 16:19:54 +0000 Commit: Gleb Smirnoff CommitDate: 2024-05-31 16:19:54 +0000 netgraph: provide separate malloc type for nodes that are missing it The kernel option NG_SEPARATE_MALLOC helps to debug memory leaks in netgraph(4). Several nodes were missing the support. --- sys/netgraph/ng_car.c | 10 ++++++++-- sys/netgraph/ng_nat.c | 26 ++++++++++++++++---------- sys/netgraph/ng_pptpgre.c | 20 +++++++++++++------- sys/netgraph/ng_tcpmss.c | 10 ++++++++-- sys/netgraph/ng_tee.c | 10 ++++++++-- 5 files changed, 53 insertions(+), 23 deletions(-) diff --git a/sys/netgraph/ng_car.c b/sys/netgraph/ng_car.c index a4e8c0dd55d6..e828306bd7d5 100644 --- a/sys/netgraph/ng_car.c +++ b/sys/netgraph/ng_car.c @@ -51,6 +51,12 @@ #include "qos.h" +#ifdef NG_SEPARATE_MALLOC +static MALLOC_DEFINE(M_NETGRAPH_CAR, "netgraph_car", "netgraph car node"); +#else +#define M_NETGRAPH_CAR M_NETGRAPH +#endif + #define NG_CAR_QUEUE_SIZE 100 /* Maximum queue size for SHAPE mode */ #define NG_CAR_QUEUE_MIN_TH 8 /* Minimum RED threshold for SHAPE mode */ @@ -189,7 +195,7 @@ ng_car_constructor(node_p node) priv_p priv; /* Initialize private descriptor. */ - priv = malloc(sizeof(*priv), M_NETGRAPH, M_WAITOK | M_ZERO); + priv = malloc(sizeof(*priv), M_NETGRAPH_CAR, M_WAITOK | M_ZERO); NG_NODE_SET_PRIVATE(node, priv); priv->node = node; @@ -571,7 +577,7 @@ ng_car_shutdown(node_p node) mtx_destroy(&priv->upper.q_mtx); mtx_destroy(&priv->lower.q_mtx); NG_NODE_UNREF(priv->node); - free(priv, M_NETGRAPH); + free(priv, M_NETGRAPH_CAR); return (0); } diff --git a/sys/netgraph/ng_nat.c b/sys/netgraph/ng_nat.c index d7492b71e07c..e9de0e5b60c8 100644 --- a/sys/netgraph/ng_nat.c +++ b/sys/netgraph/ng_nat.c @@ -53,6 +53,12 @@ #include #include +#ifdef NG_SEPARATE_MALLOC +static MALLOC_DEFINE(M_NETGRAPH_NAT, "netgraph_nat", "netgraph nat node"); +#else +#define M_NETGRAPH_NAT M_NETGRAPH +#endif + static ng_constructor_t ng_nat_constructor; static ng_rcvmsg_t ng_nat_rcvmsg; static ng_shutdown_t ng_nat_shutdown; @@ -306,7 +312,7 @@ ng_nat_constructor(node_p node) priv_p priv; /* Initialize private descriptor. */ - priv = malloc(sizeof(*priv), M_NETGRAPH, M_WAITOK | M_ZERO); + priv = malloc(sizeof(*priv), M_NETGRAPH_NAT, M_WAITOK | M_ZERO); /* Init aliasing engine. */ priv->lib = LibAliasInit(NULL); @@ -422,7 +428,7 @@ ng_nat_rcvmsg(node_p node, item_p item, hook_p lasthook) } if ((entry = malloc(sizeof(struct ng_nat_rdr_lst), - M_NETGRAPH, M_NOWAIT | M_ZERO)) == NULL) { + M_NETGRAPH_NAT, M_NOWAIT | M_ZERO)) == NULL) { error = ENOMEM; break; } @@ -436,7 +442,7 @@ ng_nat_rcvmsg(node_p node, item_p item, hook_p lasthook) if (entry->lnk == NULL) { error = ENOMEM; - free(entry, M_NETGRAPH); + free(entry, M_NETGRAPH_NAT); break; } @@ -481,7 +487,7 @@ ng_nat_rcvmsg(node_p node, item_p item, hook_p lasthook) } if ((entry = malloc(sizeof(struct ng_nat_rdr_lst), - M_NETGRAPH, M_NOWAIT | M_ZERO)) == NULL) { + M_NETGRAPH_NAT, M_NOWAIT | M_ZERO)) == NULL) { error = ENOMEM; break; } @@ -492,7 +498,7 @@ ng_nat_rcvmsg(node_p node, item_p item, hook_p lasthook) if (entry->lnk == NULL) { error = ENOMEM; - free(entry, M_NETGRAPH); + free(entry, M_NETGRAPH_NAT); break; } @@ -533,7 +539,7 @@ ng_nat_rcvmsg(node_p node, item_p item, hook_p lasthook) } if ((entry = malloc(sizeof(struct ng_nat_rdr_lst), - M_NETGRAPH, M_NOWAIT | M_ZERO)) == NULL) { + M_NETGRAPH_NAT, M_NOWAIT | M_ZERO)) == NULL) { error = ENOMEM; break; } @@ -545,7 +551,7 @@ ng_nat_rcvmsg(node_p node, item_p item, hook_p lasthook) if (entry->lnk == NULL) { error = ENOMEM; - free(entry, M_NETGRAPH); + free(entry, M_NETGRAPH_NAT); break; } @@ -611,7 +617,7 @@ ng_nat_rcvmsg(node_p node, item_p item, hook_p lasthook) /* Delete entry from our internal list. */ priv->rdrcount--; STAILQ_REMOVE(&priv->redirhead, entry, ng_nat_rdr_lst, entries); - free(entry, M_NETGRAPH); + free(entry, M_NETGRAPH_NAT); } break; case NGM_NAT_ADD_SERVER: @@ -912,12 +918,12 @@ ng_nat_shutdown(node_p node) while (!STAILQ_EMPTY(&priv->redirhead)) { struct ng_nat_rdr_lst *entry = STAILQ_FIRST(&priv->redirhead); STAILQ_REMOVE_HEAD(&priv->redirhead, entries); - free(entry, M_NETGRAPH); + free(entry, M_NETGRAPH_NAT); } /* Final free. */ LibAliasUninit(priv->lib); - free(priv, M_NETGRAPH); + free(priv, M_NETGRAPH_NAT); return (0); } diff --git a/sys/netgraph/ng_pptpgre.c b/sys/netgraph/ng_pptpgre.c index 8bd866c2881a..ae55a8dae5fd 100644 --- a/sys/netgraph/ng_pptpgre.c +++ b/sys/netgraph/ng_pptpgre.c @@ -73,6 +73,12 @@ #include #include +#ifdef NG_SEPARATE_MALLOC +static MALLOC_DEFINE(M_NETGRAPH_PPTP, "netgraph_pptp", "netgraph pptpgre node"); +#else +#define M_NETGRAPH_PPTP M_NETGRAPH +#endif + /* GRE packet format, as used by PPTP */ struct greheader { #if BYTE_ORDER == LITTLE_ENDIAN @@ -320,7 +326,7 @@ ng_pptpgre_constructor(node_p node) int i; /* Allocate private structure */ - priv = malloc(sizeof(*priv), M_NETGRAPH, M_WAITOK | M_ZERO); + priv = malloc(sizeof(*priv), M_NETGRAPH_PPTP, M_WAITOK | M_ZERO); NG_NODE_SET_PRIVATE(node, priv); @@ -380,7 +386,7 @@ ng_pptpgre_newhook(node_p node, hook_p hook, const char *name) if (hex[i] != '\0') return (EINVAL); - hpriv = malloc(sizeof(*hpriv), M_NETGRAPH, M_NOWAIT | M_ZERO); + hpriv = malloc(sizeof(*hpriv), M_NETGRAPH_PPTP, M_NOWAIT | M_ZERO); if (hpriv == NULL) return (ENOMEM); @@ -542,7 +548,7 @@ ng_pptpgre_disconnect(hook_p hook) LIST_REMOVE(hpriv, sessions); mtx_destroy(&hpriv->mtx); - free(hpriv, M_NETGRAPH); + free(hpriv, M_NETGRAPH_PPTP); } /* Go away if no longer connected to anything */ @@ -566,7 +572,7 @@ ng_pptpgre_shutdown(node_p node) LIST_REMOVE(&priv->uppersess, sessions); mtx_destroy(&priv->uppersess.mtx); - free(priv, M_NETGRAPH); + free(priv, M_NETGRAPH_PPTP); /* Decrement ref count */ NG_NODE_UNREF(node); @@ -731,7 +737,7 @@ ng_pptpgre_sendq(const hpriv_p hpriv, roqh *q, const struct ng_pptpgre_roq *st) NGI_GET_M(np->item, m); NG_FWD_NEW_DATA(error, np->item, hpriv->hook, m); if (np != st) - free(np, M_NETGRAPH); + free(np, M_NETGRAPH_PPTP); } return (error); } @@ -967,7 +973,7 @@ badAck: hpriv->recvSeq = np->seq; enqueue: - np = malloc(sizeof(*np), M_NETGRAPH, M_NOWAIT | M_ZERO); + np = malloc(sizeof(*np), M_NETGRAPH_PPTP, M_NOWAIT | M_ZERO); if (np == NULL) { priv->stats.memoryFailures++; /* @@ -1263,7 +1269,7 @@ ng_pptpgre_reset(hpriv_p hpriv) np = SLIST_FIRST(&hpriv->roq); SLIST_REMOVE_HEAD(&hpriv->roq, next); NG_FREE_ITEM(np->item); - free(np, M_NETGRAPH); + free(np, M_NETGRAPH_PPTP); } hpriv->roq_len = 0; } diff --git a/sys/netgraph/ng_tcpmss.c b/sys/netgraph/ng_tcpmss.c index 3c5b4051ed92..02fa097369ad 100644 --- a/sys/netgraph/ng_tcpmss.c +++ b/sys/netgraph/ng_tcpmss.c @@ -63,6 +63,12 @@ #include #include +#ifdef NG_SEPARATE_MALLOC +static MALLOC_DEFINE(M_NETGRAPH_TCPMSS, "netgraph_tcpmss", "netgraph tcpmss node"); +#else +#define M_NETGRAPH_TCPMSS M_NETGRAPH +#endif + /* Per hook info. */ typedef struct { hook_p outHook; @@ -159,7 +165,7 @@ ng_tcpmss_newhook(node_p node, hook_p hook, const char *name) { hpriv_p priv; - priv = malloc(sizeof(*priv), M_NETGRAPH, M_NOWAIT | M_ZERO); + priv = malloc(sizeof(*priv), M_NETGRAPH_TCPMSS, M_NOWAIT | M_ZERO); if (priv == NULL) return (ENOMEM); @@ -371,7 +377,7 @@ ng_tcpmss_disconnect(hook_p hook) priv->outHook = NULL; } - free(NG_HOOK_PRIVATE(hook), M_NETGRAPH); + free(NG_HOOK_PRIVATE(hook), M_NETGRAPH_TCPMSS); if (NG_NODE_NUMHOOKS(NG_HOOK_NODE(hook)) == 0) ng_rmnode_self(NG_HOOK_NODE(hook)); diff --git a/sys/netgraph/ng_tee.c b/sys/netgraph/ng_tee.c index 391355cd756a..b2cceda29a40 100644 --- a/sys/netgraph/ng_tee.c +++ b/sys/netgraph/ng_tee.c @@ -60,6 +60,12 @@ #include #include +#ifdef NG_SEPARATE_MALLOC +static MALLOC_DEFINE(M_NETGRAPH_TEE, "netgraph_tee", "netgraph tee node"); +#else +#define M_NETGRAPH_TEE M_NETGRAPH +#endif + /* Per hook info */ struct hookinfo { hook_p hook; @@ -151,7 +157,7 @@ ng_tee_constructor(node_p node) { sc_p privdata; - privdata = malloc(sizeof(*privdata), M_NETGRAPH, M_WAITOK | M_ZERO); + privdata = malloc(sizeof(*privdata), M_NETGRAPH_TEE, M_WAITOK | M_ZERO); NG_NODE_SET_PRIVATE(node, privdata); return (0); @@ -352,7 +358,7 @@ ng_tee_shutdown(node_p node) const sc_p privdata = NG_NODE_PRIVATE(node); NG_NODE_SET_PRIVATE(node, NULL); - free(privdata, M_NETGRAPH); + free(privdata, M_NETGRAPH_TEE); NG_NODE_UNREF(node); return (0); }