From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (unknown [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id 3CEEF8017D for ; Mon, 28 Sep 2026 19:41:43 +0000 (UTC) Received: from mail.openvz.org (localhost [127.0.0.1]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 68SJeVCX014335; Mon, 28 Sep 2026 22:40:32 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 68SJeVCX014335 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="dWzTXUV1" Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 68SJeLfC014309 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Mon, 28 Sep 2026 22:40:21 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 68SJeLfC014309 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-488773be870so2485786f8f.2 for ; Mon, 28 Sep 2026 12:40:21 -0700 (PDT) X-Gm-Message-State: AFq9FYJ33v9He34Vv38YoVhfOwRUTnV6Tgk/QVv7XMXFPmuE8CbTQAa4 WXgc2Ne/y8cRE/Y97MmimSF7EQI0q296oPqrxWx9zFb+/lYY/V/LyRCkXr4/6ArmYjgYE8q3Sz1 zPeiObwqBTAH1iFes5VgQL5IZ5x6phajJj1x6hQfcTM01gjs3Cs5XjA== X-Gm-Gg: AYBFou3d5NU38mZ/bqTr6142N8YggPI1semqudDnGFp9CQaA/CZ2qdrJhnaTwYOpgkF P1/iUuE3iY1GDtp2bn+8LBYSDV/TX9UfUZa/10pzVMjZfDapJnKrcPSM47/oRqAU7oUrggVrtfA GpZTWKzS1YEEhC91nx6YVXakiXtD3vEX6RndtU7TBm1NJL9XdWzO1Ps9BhIp3DXin0nN+3khCSW Low3peNwsxVcjS0K63EWMmeH8UU9ub74qCqpJPAJRSnvr3Lz1fn7w8+FHTyFadWvl+BxPBZbrKz DlQznYcIadAZSs0CS2J8dHiLK1awG5fNaUYlO3D2LtUTYqeVE6BU7sjf2ak7xbxjS2MLoWLJyt3 5SN3mgi0bUP30f8/rAm2sdfxr X-Received: by 2002:a05:6000:490d:b0:488:845b:4bc with SMTP id ffacd0b85a97d-488845b065amr14839457f8f.11.1790624421487; Mon, 28 Sep 2026 12:40:21 -0700 (PDT) X-Received: by 2002:a05:6000:490d:b0:488:845b:4bc with SMTP id ffacd0b85a97d-488845b065amr14839422f8f.11.1790624420882; Mon, 28 Sep 2026 12:40:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1790624420; cv=none; d=google.com; s=arc-20260327; b=igFoDlCVmzi2Z9tbAEX/+3leVAqm3AUFxEllJGgIPdzWdO7E3pNkoJvCXc0roKO8kr ix59aYuFNnl/CDh/Xq6vk4PJiODPNXjyz7+hz9l7DQU1XgnSXjD0+/WedQ/SyUc1wYMf SdsSQ9jLrGGQXvtegjPGQppIztpfhkmfC0eb74pVN3puERl9+VUxN3K1UhxanLZjcXau HcOkekwFJTRdQpLD5nvpXaD8/SehQLHrV8YshKXiaGwgk1qAkPCPfVsvmLIsfB+GSzep YDM/rHsPrsqiPmyNp5uc4NlfK7haBr9svP+zp6cQdeFQQFb19YrHMgjoR0fO7RBYDdhB ngag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=+lYXl38TnnTWJyIWvni8YIzMuNBQjDQMVN2zEhwngK0=; fh=WpT6aB7RBAGHZeWZzqAr71yzRFbPTYkPWKsRagLn48Q=; b=cjSJ1K2+lKf9iHvcxOFVOL5ocJCYTaHB7KS1ooziMUrHhqEkM97cEtLW2TqW493w9L w4d0G7PTlaF+P6AyE1hLVfF00V5GnTlA5BPMvwNlwQbsw+YcscS7BcxDOrKlsQD3VPpQ +UPDjJlMk3APn7bf9pQuIRssHg8EAb/lj2lMMafMYbiZcj7OZe7vAyQeQoImZfSIbequ MTMvCzOMUilK+gkYMQxBV3xduAGzHzI/gkfIYeeFR9oFnM9w2Om8Ygl0tNQZA4qhYR5Z NUfPOal6SbRQBWTgUc9KHIyxLmKwPzRVJGdF2EdhaAOf/gFYdMZIMX5gY38kOR1AYwds Wk6A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=dWzTXUV1; spf=pass (google.com: domain of eva.kurchatova@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=eva.kurchatova@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: from relay.virtuozzo.com (relay.virtuozzo.com. [130.117.225.111]) by mx.google.com with ESMTPS id ffacd0b85a97d-4887a88264asi21173784f8f.456.2026.09.28.12.40.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Sep 2026 12:40:20 -0700 (PDT) Received-SPF: pass (google.com: domain of eva.kurchatova@virtuozzo.com designates 130.117.225.111 as permitted sender) client-ip=130.117.225.111; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=dWzTXUV1; spf=pass (google.com: domain of eva.kurchatova@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=eva.kurchatova@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=MIME-Version:Message-ID:Date:Subject:From: Content-Type; bh=+lYXl38TnnTWJyIWvni8YIzMuNBQjDQMVN2zEhwngK0=; b=dWzTXUV1yvOL JCSBdYvaoqs2P1m7c1ARxNepyY+JatK6CTIUuOUw3RVqsA2tP9W+52FL4YVJVjdP25kas2oiXT192 oKaCAfFSh220fIl/DR/4NZBPBq1ef1vP1+7jOIXmpRKcofZqiGukLt7sRfGQj9MfACXvzcl5/o8F3 CMdKCG7vq/8HT9TRiqbAldJng+S06N6WeViE+3zckgiVY1kbdMSeY61UMwb4x6QnsErGyJa95EKfK hF8iJ1FtuoLYHlrlGdhO81H7sVlxLp61j146qM2CbKkDOUwSgI4lrYB4UylwdOyv0YtW8QqdWXGPq AhhL8a9Nhg7HNx6HlO8L/g==; Received: from ch-vpn.virtuozzo.com ([130.117.225.6] helo=LekKit-T14) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1xBH9z-009xOK-1g; Mon, 28 Sep 2026 21:40:11 +0200 From: Eva Kurchatova To: khorenko@virtuozzo.com Date: Mon, 28 Sep 2026 22:37:16 +0300 Message-ID: <20260928194013.550250-3-eva.kurchatova@virtuozzo.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260928194013.550250-1-eva.kurchatova@virtuozzo.com> References: <20260928194013.550250-1-eva.kurchatova@virtuozzo.com> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.1 v2 2/3] selftests: drv-net: run ping in its own netns X-BeenThere: devel@openvz.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: OpenVZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: devel-bounces@openvz.org Errors-To: devel-bounces@openvz.org In netdevsim mode ping.py sends its traffic to itself through the host namespace, so a host firewall that drops it fails the test: ok 1 ping.test_v4 ok 2 ping.test_v6 not ok 3 ping.test_tcp # Stopping tests due to KsftTerminate. Re-exec the test in a namespace of its own, the way nft_audit.sh does since commit 2e2d9c7d4d37 ("selftests: netfilter: Run nft_audit.sh in its own netns"). A test given a real interface through NETIF stays where it is, that interface is not reachable from a new namespace. https://virtuozzo.atlassian.net/browse/VSTOR-139651 Feature: fix selftests Signed-off-by: Eva Kurchatova --- .../selftests/drivers/net/lib/py/__init__.py | 2 +- tools/testing/selftests/drivers/net/ping.py | 4 ++ tools/testing/selftests/net/lib/py/utils.py | 44 +++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/drivers/net/lib/py/__init__.py b/tools/testing/selftests/drivers/net/lib/py/__init__.py index fce5d9218f1d..2d3fdaa81550 100644 --- a/tools/testing/selftests/drivers/net/lib/py/__init__.py +++ b/tools/testing/selftests/drivers/net/lib/py/__init__.py @@ -15,7 +15,7 @@ try: NlError, RtnlFamily, DevlinkFamily from net.lib.py import CmdExitFailure from net.lib.py import bkg, cmd, defer, ethtool, fd_read_timeout, ip, \ - rand_port, tool, wait_port_listen + rand_port, rexec_in_netns, tool, wait_port_listen from net.lib.py import fd_read_timeout from net.lib.py import KsftSkipEx, KsftFailEx, KsftXfailEx from net.lib.py import ksft_disruptive, ksft_exit, ksft_pr, ksft_run, \ diff --git a/tools/testing/selftests/drivers/net/ping.py b/tools/testing/selftests/drivers/net/ping.py index eb83e7b48797..46da331158ba 100755 --- a/tools/testing/selftests/drivers/net/ping.py +++ b/tools/testing/selftests/drivers/net/ping.py @@ -5,6 +5,7 @@ from lib.py import ksft_run, ksft_exit from lib.py import ksft_eq from lib.py import NetDrvEpEnv from lib.py import bkg, cmd, wait_port_listen, rand_port +from lib.py import rexec_in_netns def test_v4(cfg) -> None: @@ -42,6 +43,9 @@ def test_tcp(cfg) -> None: def main() -> None: + # In netdevsim mode both ends would sit in the host's namespace + rexec_in_netns(__file__) + with NetDrvEpEnv(__file__) as cfg: ksft_run(globs=globals(), case_pfx={"test_"}, args=(cfg, )) ksft_exit() diff --git a/tools/testing/selftests/net/lib/py/utils.py b/tools/testing/selftests/net/lib/py/utils.py index afce547bcab0..ab91358cca9c 100644 --- a/tools/testing/selftests/net/lib/py/utils.py +++ b/tools/testing/selftests/net/lib/py/utils.py @@ -8,6 +8,7 @@ import re import select import socket import subprocess +import sys import time @@ -131,6 +132,49 @@ def ethtool(args, json=None, ns=None, host=None): return tool('ethtool', args, json=json, ns=ns, host=host) +def _netif_configured(path): + """ + Whether a real interface was named, in the environment or net.config. + """ + if os.environ.get("NETIF"): + return True + + cfg = os.path.join(os.path.dirname(os.path.abspath(path)), "net.config") + try: + with open(cfg, 'r') as fp: + for line in fp.readlines(): + pos = line.find("#") + if pos >= 0: + line = line[:pos] + pair = line.strip().split('=', maxsplit=1) + if len(pair) == 2 and pair[0] == "NETIF" and pair[1]: + return True + except OSError: + pass + return False + + +def rexec_in_netns(path): + """ + Re-exec the test in a network namespace of its own, with sysfs + mounted again. Does nothing where a real interface is named, or + where unshare is not there to move the test. + """ + if os.environ.get("KSFT_IN_NETNS") or _netif_configured(path): + return + + os.environ["KSFT_IN_NETNS"] = "1" + try: + os.execvp("unshare", + ["unshare", "-n", "-m", + "sh", "-c", + 'mount -t sysfs sysfs /sys && ip link set lo up && ' + 'exec "$@"', + "sh", sys.executable, os.path.abspath(path)] + sys.argv[1:]) + except OSError: + del os.environ["KSFT_IN_NETNS"] + + def rand_port(type=socket.SOCK_STREAM): """ Get a random unprivileged port. -- 2.55.0 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel