From nobody Mon Jan 23 22:12:31 2023 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 4P148v5vTKz2t17s; Mon, 23 Jan 2023 22:12:31 +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 4P148v4xpQz3N5q; Mon, 23 Jan 2023 22:12:31 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674511951; 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=grv9pWCRmVyHKsXvgyCdKNV9Cu8l/KT3oCVDHP/sSOw=; b=JQdWp/Zx6+s44VQuyk3d8C8RQIdfi/r2lfLmlvu67HkmvPMKXoTJsXpn7KvGSnx8zi7KMb G7eaaDUbb+ICV00PvoxLeE7zNfqe7st08uBC6fEJQxgzrGXSLm8Csp3EMdkYORewH7sOhs gtGn8HeUlTB84N6bTO5mD/nla/b4NRcW3W8MKiYDn1inbGqkQnTte1zAq9jMIgIznS9lh1 KhVRh/CX05yDubCxa9nvJHP52dSlOr9Qv7Z8pJ+AcAgkFqYfi75eXGOH1w0kXuRVZRiH8k 4YjrL5KFT3IR5F9DVk9pF0o0XLCCnzCCGiibC9FRu70OomfJbMC1v/gYxF8LNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674511951; 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=grv9pWCRmVyHKsXvgyCdKNV9Cu8l/KT3oCVDHP/sSOw=; b=CdEnBi28Z6aVhYd8EiBwdxsc1TyNw/vR+NS8RfS1YeWkh+d98nBA4xQdIYd32e//NQxG5p ETghOocdT6T/EurvnSCpLs3NxTBrH0bfdGOZrNIyl2spGx+Q5qKt3kT4SZhdrjfKN5dqlJ CughLCfOfmgdeBCLNlUGL9eM9joFtvx7VG02BXf2kCodMwTsLmTVYvruQ4TN1MUftItxx1 ZQLpZhxnB9qfTmmiA2WlCQNlSD3+a0Amgpw2fuYbp23ZYczvkbhgrs2iLTg7g01Rzr4g5J +1yr8nrXoLKrNV47VXTAEsRpLPlRPBk66lDY5hf/zeZZQUxB2QGOfN9SfsncZg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1674511951; a=rsa-sha256; cv=none; b=NlkeXvZAIIVKpCjI+60ZCClD4jLt/B95QWXcu1F8yfYU1zBpMXgODrvKnebXsKqUyjw5X8 SGyG5ffAk5oolSzWxHZyI5iqxpvu47AcCW09nD4rqQIbtuXw2Dw1Eq6J8k80yHw14MinvH hKKbjG5hGBYDqjd3KLYlv6GylLMUOnQlXQpDw36U+ZMz6LsFlIHVdOr3J87jcIsQuBKC6q kOqrp+rhzGXwQePeXDh7QV9IXh3wVz+z00yplDl3N5Wid1y/fwhDm/FHRvR/2ndTKU8T3Q To3yP2dvKffwIEBqyYbO/Z1U7pnfGSLXh26UnE/WzOchtnHD2fIBt1YDFGk9Jg== 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 4P148v3w5Wzm2d; Mon, 23 Jan 2023 22:12:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 30NMCVCN017574; Mon, 23 Jan 2023 22:12:31 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30NMCVcG017573; Mon, 23 Jan 2023 22:12:31 GMT (envelope-from git) Date: Mon, 23 Jan 2023 22:12:31 GMT Message-Id: <202301232212.30NMCVcG017573@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: "Alexander V. Chernikov" Subject: git: 16ae7b665c7e - stable/13 - nhop: hash ifnet pointer instead of if_index 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: melifaro X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 16ae7b665c7eac41fc717d9f09da2a2fb4ed1973 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=16ae7b665c7eac41fc717d9f09da2a2fb4ed1973 commit 16ae7b665c7eac41fc717d9f09da2a2fb4ed1973 Author: Gleb Smirnoff AuthorDate: 2021-12-04 18:05:46 +0000 Commit: Alexander V. Chernikov CommitDate: 2023-01-23 22:10:07 +0000 nhop: hash ifnet pointer instead of if_index Yet another problem created by VIMAGE/if_vmove/epair design that relocates ifnet between vnets and changes if_index. Since if_index changes, nhop hash values also changes, unlink_nhop() isn't able to find entry in hash and leaks the nhop. Since nhop references ifnet, the latter is also leaked. As result running network tests leaks memory on every single test that creates vnet jail. While here, rewrite whole hash_priv() to use static initializer, per Alexander's suggestion. Reviewed by: melifaro (cherry picked from commit ad2a0aec295478e750158b8985422f15deee0e54) --- sys/net/route/nhop.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/sys/net/route/nhop.c b/sys/net/route/nhop.c index 782bdd037d3e..07bced3e8b11 100644 --- a/sys/net/route/nhop.c +++ b/sys/net/route/nhop.c @@ -186,13 +186,13 @@ nhops_destroy_rib(struct rib_head *rh) * With that in mind, hash nexthops by the combination of the interface * and GW IP address. * - * To optimize hash calculation, ignore higher bytes of ifindex, as they - * give very little entropy. + * To optimize hash calculation, ignore lower bits of ifnet pointer, + * as they give very little entropy. * Similarly, use lower 4 bytes of IPv6 address to distinguish between the * neighbors. */ struct _hash_data { - uint16_t ifindex; + uint16_t ifentropy; uint8_t family; uint8_t nh_type; uint32_t gw_addr; @@ -213,21 +213,15 @@ djb_hash(const unsigned char *h, const int len) static uint32_t hash_priv(const struct nhop_priv *priv) { - struct nhop_object *nh; - uint16_t ifindex; - struct _hash_data key; - - nh = priv->nh; - ifindex = nh->nh_ifp->if_index & 0xFFFF; - memset(&key, 0, sizeof(key)); - - key.ifindex = ifindex; - key.family = nh->gw_sa.sa_family; - key.nh_type = priv->nh_type & 0xFF; - if (nh->gw_sa.sa_family == AF_INET6) - memcpy(&key.gw_addr, &nh->gw6_sa.sin6_addr.s6_addr32[3], 4); - else if (nh->gw_sa.sa_family == AF_INET) - memcpy(&key.gw_addr, &nh->gw4_sa.sin_addr, 4); + struct nhop_object *nh = priv->nh; + struct _hash_data key = { + .ifentropy = (uint16_t)((((uintptr_t)nh->nh_ifp) >> 6) & 0xFFFF), + .family = nh->gw_sa.sa_family, + .nh_type = priv->nh_type & 0xFF, + .gw_addr = (nh->gw_sa.sa_family == AF_INET6) ? + nh->gw6_sa.sin6_addr.s6_addr32[3] : + nh->gw4_sa.sin_addr.s_addr + }; return (uint32_t)(djb_hash((const unsigned char *)&key, sizeof(key))); }