From patchwork Wed Jan 8 11:50:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13930679 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AE0561F9ABF; Wed, 8 Jan 2025 11:50:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736337041; cv=none; b=cbrZVmTgfSaKiaI3j+yV5cdywBqCOZw2ygHG+uFSLf7pWtTu4ETSe0VB9HTVe54g1Hg2a/uOUrB41MS0KubSHdHlliUBldkGyB9tlbZtKkSmceknRHlJ6YUz3KuA5LKoJ+h1YvVVnuOllgwvA98Y/Mdo/w5hwWoZVmhYZnlspMk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736337041; c=relaxed/simple; bh=b0dr5T0QwnIxuuEvkRyv8EVkHvyXW4ldpeHd7C+rkBU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HmsUK/Mrt9PNuKp8tKaq9nyWjAs7AOemGQ9EvJkC8q2PzygfDoosVEZUtJ8fTyFrC0dxw3Da3h1EknxwPFM65VbJyB+ZtXcNdiMj0nI7nbhMKnj2S7S6+j0lqOwKh/P8GQueoJv1Nsv3tYgnLRm4cAIlucilhUT81mYdaEm22x4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.208.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f53.google.com with SMTP id 4fb4d7f45d1cf-5d88c355e0dso11017563a12.0; Wed, 08 Jan 2025 03:50:39 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736337038; x=1736941838; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7Psq5v8QcPJKBmtJbh0DGeIRlVIPLBPUK0VHBQQ4Les=; b=T8iQyCFF7Do1XGhEpoSZLlB3dqLZowlqTWp/tEUQsmIsYEH6+p0JbDMdTdYb4F2k/K gkMvHvuYC2s4K5OBhXPvzJlyGu/UVlBJmXkXQJWTkjYiFerpoydeTerwm4YxWi340WDA djzy4Wp8AI7daPJSmDbMefL1kN3ZOrVBsMHDGTJePfjfMzwRrSkxaiZ8cHsPIWCVcUVP paqVexgiXW0uza8kZBtNRl6B+4GFYXqtwFBcHKCAVSYjda6YXIHpVwxyZENAryxIN57Q pfpeTZCV984hWQ5pRgUye3xWEGpv+JXMOEjc+iab/ckW51raezrq16j3RZXQ/wDwx0Ve iQRg== X-Forwarded-Encrypted: i=1; AJvYcCXKtUhkeZJj/8Yr6xdDVeCMNLMOjzct+DNvJ+JJpFZbeRM5VtPJG212eNSXipcacwurjXgDFx3i6xMJBCtAuKPC@vger.kernel.org, AJvYcCXVV7BLUUUF9zldzKijuZ/SRG6UVSWwj8S6tiQOIkPQc1YqG9wT7p3NVcPW4MYo3IfxwwLZ71LJPf8VhY4=@vger.kernel.org X-Gm-Message-State: AOJu0YzUBjfXepup7p5gamu4ejfUgfUC/8WJ9Hak+oR/5r8QYL+3A661 rnLaQcPR+s4OZTtUZfzUkaI5QMsubrdPwj5prbCy5m7/mc2OX32p X-Gm-Gg: ASbGncv6/dz9f5fwu2JhIkBRj5KRY4YRENKF67AWBGRwNZokZjGq7fxW7M2iSzjmCNr VDQ/cY0VkYqqzZETp5A+2cqYCeq/TgSYjDQ40ETSMKmbTJgCoGe1Q8bHrl+klkqR9dxznspCy5W KKhq+9O/Q7engtRq1yL2rY8I3tsyHQ4NtQCXnnm6f8qyqD0gnG4GVhPm6u86ft6Mp+wyLy9O3qA LHsklQ3xMIorw41wDaDsg2SXk4UoNfQoBBd/IZDZ47Klbo= X-Google-Smtp-Source: AGHT+IFopCOJu21oDNmoL8dIpNxFJc+Y2ey9HhB3yQ4O1yEV8uUW0MjU9SFgmk0F84MMiz2KIKMjMA== X-Received: by 2002:a05:6402:254d:b0:5d0:81dc:f20e with SMTP id 4fb4d7f45d1cf-5d972e1c5cfmr2010285a12.17.1736337037976; Wed, 08 Jan 2025 03:50:37 -0800 (PST) Received: from localhost ([2a03:2880:30ff:6::]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d806fed2a1sm26174988a12.67.2025.01.08.03.50.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jan 2025 03:50:37 -0800 (PST) From: Breno Leitao Date: Wed, 08 Jan 2025 03:50:25 -0800 Subject: [PATCH net-next v3 1/4] netconsole: Warn if MAX_USERDATA_ITEMS limit is exceeded Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250108-netcons_overflow_test-v3-1-3d85eb091bec@debian.org> References: <20250108-netcons_overflow_test-v3-0-3d85eb091bec@debian.org> In-Reply-To: <20250108-netcons_overflow_test-v3-0-3d85eb091bec@debian.org> To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Shuah Khan Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Breno Leitao , kernel-team@meta.com, Simon Horman X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1033; i=leitao@debian.org; h=from:subject:message-id; bh=b0dr5T0QwnIxuuEvkRyv8EVkHvyXW4ldpeHd7C+rkBU=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBnfmaKt0S/vMpwW6p6OgKnXBLS9xdtOqZpapuDk tQu/CcpzRGJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCZ35migAKCRA1o5Of/Hh3 bS4ID/wOOpk4VqlkC2/I80iu/4R1Nc9Usrx0LUlahssak1vjgUqxrAQf9spzw3atgjl4CuaYICF AD3/pGCV8+yig7qL3QX05W+Ct6I6drWk/eRNKzFT6KsVlQUhkFhnTOBALnJRTc4ijXn1GDxk/vW rHMkcBVu3jruzZHDrNmJwS8X66T8cAD8R9W0wD98IYUEnm3zwj6Zoq7CjPruN/nTcN5uV3n1pzt IFziB4/m0jAqjo5u3tOPmsFLZe1BBSiFUzASd3u7akO7jd/7WURBqy2RSl2luWu05J+Nv7bSumh 80i2wiElapymJ0zFdJRCORMmni4m5IlbtB6OMXNWLf1ZMclf7C/IHlNIPI3uFw0NxmYERYMau0n 4gEVlOuZDbHqXfbursa+q7kFpNMtbIkVFtFYf1Mo4bpP8dA/iKA6La/j/FF0+QTwKM2GnrEvUHh kCL19afZK/9rh8SVPpJ06MMRJGWP/8Wt7G/JKLGisLEAloUiR3jIk5lEE8C5E/9mU8QyiXWyueI fdP6ClxXoq0SB2PLLg2cTFyqiPj5VgPvaYIg/Tq0TbZ2zfTqIjUhI0DnmLMt8gdlnwDvCxg43Z2 pcdDTQn3aFuEK9QSS+9JYIXQ259JQwjEKRbXzkLTDhE/uMo0vnC2pb2kwZm0cc9Vyulq7czjj7L 2ijLk2cneqjcspQ== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Patchwork-Delegate: kuba@kernel.org netconsole configfs helpers doesn't allow the creation of more than MAX_USERDATA_ITEMS items. Add a warning when netconsole userdata update function attempts sees more than MAX_USERDATA_ITEMS entries. Replace silent ignore mechanism with WARN_ON_ONCE() to highlight potential misuse during development and debugging. Signed-off-by: Breno Leitao Reviewed-by: Simon Horman --- drivers/net/netconsole.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index f422a2f666ef2276cf5b10e1dbc6badbc8ef0038..86ab4a42769a49eebe5dd6f01dafafc6c86ec54f 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -730,7 +730,7 @@ static void update_userdata(struct netconsole_target *nt) struct userdatum *udm_item; struct config_item *item; - if (child_count >= MAX_USERDATA_ITEMS) + if (WARN_ON_ONCE(child_count >= MAX_USERDATA_ITEMS)) break; child_count++; From patchwork Wed Jan 8 11:50:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13930680 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D0DC71FA8F1; Wed, 8 Jan 2025 11:50:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736337044; cv=none; b=FSd+m6mLxNYiLljqzm09DCBcB7NY07OVgWvBKdsEepyWptQLNx7dyViZBRW9uNApTl7bYJx7SoDo5f6JZgF9wD60tJn1QC0A3RXIVZsKw/AD7ncQ/MK+Iuevc5v4ELD2K/a3V0nlkMWp+RpLWP/L5I2/zpJeGQT5OuSjd04uHPI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736337044; c=relaxed/simple; bh=jHwRkyhF+DGevPBPlLaE1J2ZEHxMKU4Wf9+VZbHGyZc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qf3qaKbL19TvHtbr7BE94FIHqDUdUXgfVpHvuYiUxMprAlPIyuqhx+7Yzjt+7VDSSlFumfDSow7qO5pPldjT6Y38CrRVenWnkny4DuMyCsZmllH9rPsdAQrCMqnrEkFB/UVSu+wS8ykJlur21dhzPfnIUK2LUM60BfnehpuX5po= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.208.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-5d7e527becaso28188487a12.3; Wed, 08 Jan 2025 03:50:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736337040; x=1736941840; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FIgG5bbCl3s6OJi/chMCEiXYTN20Hn4cEGL6NbROiN0=; b=u16yPUye+TBWfcY762sRyCoGF4uFY+FNSsVcb8fi58f1/8BQhME3Zy/nwd3wbZAFrc m68HwOv7NJ0GFXZptg+xWYk8WCwjmCZNg4knE81ccvof7KK4hf6IKXX+R4vv4mVWwKYQ mKrBKhkkgMso/VD4I6yxj2JfjOISkeSr3eqTx16cFSv2aJqAaUScFy4eXsnXM2/6NcVr zwrN3yfbr4EkxxKGY3hbf9xJonf5sMiNmgh0kMgPkrdKbySUUZbYBP0LIgdCvbHcFqOW gM/4UtjtAZIiETPQhMERx4yQ3NNgXigjNgcg8zim0jYfqyCRclPjFlbgiJtX2E/IPnBZ /euQ== X-Forwarded-Encrypted: i=1; AJvYcCUAZSppYALIJxgtDoZBNeVff5GXvTs/4CK73QfxHcOqIsWQgmNJs7lz5msNMIcj5X/6qocHeYCnThTAp2IUjPV/@vger.kernel.org, AJvYcCXHHlr1lsg9RCPrQwrYqkrAW0S5N0txf4TOdv+z3dxcMHUeXmeI0DK3WCjjS/ENWgLfu7ooQ3aWoaxh14E=@vger.kernel.org X-Gm-Message-State: AOJu0Yxj4tJO+pRpNqgCZBL4u8luFf2RjwqgR7AHyggXUogLPvIXpLwD P47c1LD4s2kRZKtAZFjyFQJOljdLcX3j/wpCa/gR9e3h5VLfJQcBNQudEA== X-Gm-Gg: ASbGncvj0QR3p52AkHDbt2HmrDofZvcudcBeuDAUpPzLzrEHcqh5fCAuTEZWARIfvNA yavrlh9pkOFawIEXpCULC4+i5Tkw3lJJ49Y1EkIz3UqUQgID5xC1rUU/abQyAGuQVNW/cBl7Rft LMH4aeMly0qNa4vi/YxEIy0jNhKuG5O2DaeT00gga2B8v12MYbdy8UnsG8Dgs0wv8MjoTR//U7y 0DnZD2CBk2bFn1xqS4wcJlfOG+IeAoN36SewSJRJax+SJ7U X-Google-Smtp-Source: AGHT+IFogEnMeqHh46Ja8fjUDUN0Eagv83BtI6z18mVNyNDI9drplgQ4GEvaodPv5yg1YqDOqCSO3g== X-Received: by 2002:a05:6402:40c1:b0:5d1:1064:326a with SMTP id 4fb4d7f45d1cf-5d972e1c39fmr5528971a12.15.1736337039785; Wed, 08 Jan 2025 03:50:39 -0800 (PST) Received: from localhost ([2a03:2880:30ff:70::]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aaf69b4540csm1070888266b.159.2025.01.08.03.50.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jan 2025 03:50:39 -0800 (PST) From: Breno Leitao Date: Wed, 08 Jan 2025 03:50:26 -0800 Subject: [PATCH net-next v3 2/4] netconsole: selftest: Split the helpers from the selftest Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250108-netcons_overflow_test-v3-2-3d85eb091bec@debian.org> References: <20250108-netcons_overflow_test-v3-0-3d85eb091bec@debian.org> In-Reply-To: <20250108-netcons_overflow_test-v3-0-3d85eb091bec@debian.org> To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Shuah Khan Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Breno Leitao , kernel-team@meta.com, Simon Horman X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=15674; i=leitao@debian.org; h=from:subject:message-id; bh=jHwRkyhF+DGevPBPlLaE1J2ZEHxMKU4Wf9+VZbHGyZc=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBnfmaK4vpwBJ4qECEb4RmQFjTcOzW5ESfNU4frH JKQSqb/qcqJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCZ35migAKCRA1o5Of/Hh3 bT6VEACASRQxOLY5jLBPxu6a4aqxS+VhreHfPX7bADnMk+WMqMKNLYSqpqICGNe/tR8XNHVSeUE 87mqDAgdaGuXBwLRJ+Jl9B4yqvWLH3vhjaIAK3rX51Bgf8SnUJdkoCE6ESot20I7nUOJfeSg55U jdxBC+xJDjnZgYgral/Sklm139zMw2m0UgV9JFlcOzqpms4+0smckl/5zuj4vfH5IJVf0Uj+gAG yFeW3Wq+dMUcCeutPNeh5g/dnpmB/FTLO2EGitwi3bRfOGndW3p+QQIu2kNKeV8lVl+YY4cvnGP pziRS5s1UkEnlOpyEHbN5rj5lwl1iqFuiRHMa+nIknZoF+PglM5NL3Rm58VgyA6VP1aShnmpWZ9 HP5t+CTLkFIFLKq4Hw80OYNDRw0YztZ6vnMix0vp5Ctq/XQjvUyVLymsjhP22nqiwWLNxDh8Ac4 xFvyn67cJK3MBtmXtghN8Diosy2EEgbWn2rxmJj1QrrhYLh8l/gESVDk1PNswbwlkNdaQjowWtH qwTvTIFywXMCtoAGwM976toVhA3jukm/lufvmLvL91ibVJyy8rn/7+gTwrEAsQI2vtm2OwFiFUg EvTS0gW9iaJ+7LT1FkF27/mkkbOAiVmH3jZ/nQ7fOAAakPuLkGQzxLjOIeWeRU6pxKE+xpiVS2P UUHnfDqU62H1v6w== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Patchwork-Delegate: kuba@kernel.org Split helper functions from the netconsole basic test into a separate library file to enable reuse across different netconsole tests. This change only moves the existing helper functions to lib/sh/lib_netcons.sh while preserving the same test functionality. The helpers provide common functions for: - Setting up network namespaces and interfaces - Managing netconsole dynamic targets - Setting user data - Handling test dependencies - Cleanup operations Do not make any change in the code, other than the mechanical separation. Signed-off-by: Breno Leitao Tested-by: Simon Horman Reviewed-by: Simon Horman --- MAINTAINERS | 1 + tools/testing/selftests/drivers/net/Makefile | 1 + .../selftests/drivers/net/lib/sh/lib_netcons.sh | 225 +++++++++++++++++++++ .../testing/selftests/drivers/net/netcons_basic.sh | 218 +------------------- 4 files changed, 228 insertions(+), 217 deletions(-) diff --git a/MAINTAINERS b/MAINTAINERS index a685c551faf089f862b5b8e96e3aeab05be97a40..d3cd4b7e48652b7a56873b840fd2ed6e12791008 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -16174,6 +16174,7 @@ M: Breno Leitao S: Maintained F: Documentation/networking/netconsole.rst F: drivers/net/netconsole.c +F: tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh F: tools/testing/selftests/drivers/net/netcons_basic.sh NETDEVSIM diff --git a/tools/testing/selftests/drivers/net/Makefile b/tools/testing/selftests/drivers/net/Makefile index 0fec8f9801ad4d94d99ab6d0acaea6e2e7b2894d..dafff5d7fe88c82a1d27aa49faca728b52435ebc 100644 --- a/tools/testing/selftests/drivers/net/Makefile +++ b/tools/testing/selftests/drivers/net/Makefile @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 TEST_INCLUDES := $(wildcard lib/py/*.py) \ + $(wildcard lib/sh/*.sh) \ ../../net/net_helper.sh \ ../../net/lib.sh \ diff --git a/tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh b/tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh new file mode 100644 index 0000000000000000000000000000000000000000..fdd45a3468f17449eeb66d9a808b7a3b2107e47c --- /dev/null +++ b/tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh @@ -0,0 +1,225 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: GPL-2.0 + +# This file contains functions and helpers to support the netconsole +# selftests +# +# Author: Breno Leitao + +set -euo pipefail + +LIBDIR=$(dirname "$(readlink -e "${BASH_SOURCE[0]}")") + +SRCIF="" # to be populated later +SRCIP=192.0.2.1 +DSTIF="" # to be populated later +DSTIP=192.0.2.2 + +PORT="6666" +MSG="netconsole selftest" +USERDATA_KEY="key" +USERDATA_VALUE="value" +TARGET=$(mktemp -u netcons_XXXXX) +DEFAULT_PRINTK_VALUES=$(cat /proc/sys/kernel/printk) +NETCONS_CONFIGFS="/sys/kernel/config/netconsole" +NETCONS_PATH="${NETCONS_CONFIGFS}"/"${TARGET}" +KEY_PATH="${NETCONS_PATH}/userdata/${USERDATA_KEY}" +# NAMESPACE will be populated by setup_ns with a random value +NAMESPACE="" + +# IDs for netdevsim +NSIM_DEV_1_ID=$((256 + RANDOM % 256)) +NSIM_DEV_2_ID=$((512 + RANDOM % 256)) +NSIM_DEV_SYS_NEW="/sys/bus/netdevsim/new_device" + +# Used to create and delete namespaces +source "${LIBDIR}"/../../../../net/lib.sh +source "${LIBDIR}"/../../../../net/net_helper.sh + +# Create netdevsim interfaces +create_ifaces() { + + echo "$NSIM_DEV_2_ID" > "$NSIM_DEV_SYS_NEW" + echo "$NSIM_DEV_1_ID" > "$NSIM_DEV_SYS_NEW" + udevadm settle 2> /dev/null || true + + local NSIM1=/sys/bus/netdevsim/devices/netdevsim"$NSIM_DEV_1_ID" + local NSIM2=/sys/bus/netdevsim/devices/netdevsim"$NSIM_DEV_2_ID" + + # These are global variables + SRCIF=$(find "$NSIM1"/net -maxdepth 1 -type d ! \ + -path "$NSIM1"/net -exec basename {} \;) + DSTIF=$(find "$NSIM2"/net -maxdepth 1 -type d ! \ + -path "$NSIM2"/net -exec basename {} \;) +} + +link_ifaces() { + local NSIM_DEV_SYS_LINK="/sys/bus/netdevsim/link_device" + local SRCIF_IFIDX=$(cat /sys/class/net/"$SRCIF"/ifindex) + local DSTIF_IFIDX=$(cat /sys/class/net/"$DSTIF"/ifindex) + + exec {NAMESPACE_FD} $NSIM_DEV_SYS_LINK + then + echo "linking netdevsim1 with netdevsim2 should succeed" + cleanup + exit "${ksft_skip}" + fi +} + +function configure_ip() { + # Configure the IPs for both interfaces + ip netns exec "${NAMESPACE}" ip addr add "${DSTIP}"/24 dev "${DSTIF}" + ip netns exec "${NAMESPACE}" ip link set "${DSTIF}" up + + ip addr add "${SRCIP}"/24 dev "${SRCIF}" + ip link set "${SRCIF}" up +} + +function set_network() { + # setup_ns function is coming from lib.sh + setup_ns NAMESPACE + + # Create both interfaces, and assign the destination to a different + # namespace + create_ifaces + + # Link both interfaces back to back + link_ifaces + + configure_ip +} + +function create_dynamic_target() { + DSTMAC=$(ip netns exec "${NAMESPACE}" \ + ip link show "${DSTIF}" | awk '/ether/ {print $2}') + + # Create a dynamic target + mkdir "${NETCONS_PATH}" + + echo "${DSTIP}" > "${NETCONS_PATH}"/remote_ip + echo "${SRCIP}" > "${NETCONS_PATH}"/local_ip + echo "${DSTMAC}" > "${NETCONS_PATH}"/remote_mac + echo "${SRCIF}" > "${NETCONS_PATH}"/dev_name + + echo 1 > "${NETCONS_PATH}"/enabled +} + +function cleanup() { + local NSIM_DEV_SYS_DEL="/sys/bus/netdevsim/del_device" + + # delete netconsole dynamic reconfiguration + echo 0 > "${NETCONS_PATH}"/enabled + # Remove key + rmdir "${KEY_PATH}" + # Remove the configfs entry + rmdir "${NETCONS_PATH}" + + # Delete netdevsim devices + echo "$NSIM_DEV_2_ID" > "$NSIM_DEV_SYS_DEL" + echo "$NSIM_DEV_1_ID" > "$NSIM_DEV_SYS_DEL" + + # this is coming from lib.sh + cleanup_all_ns + + # Restoring printk configurations + echo "${DEFAULT_PRINTK_VALUES}" > /proc/sys/kernel/printk +} + +function set_user_data() { + if [[ ! -d "${NETCONS_PATH}""/userdata" ]] + then + echo "Userdata path not available in ${NETCONS_PATH}/userdata" + exit "${ksft_skip}" + fi + + mkdir -p "${KEY_PATH}" + VALUE_PATH="${KEY_PATH}""/value" + echo "${USERDATA_VALUE}" > "${VALUE_PATH}" +} + +function listen_port_and_save_to() { + local OUTPUT=${1} + # Just wait for 2 seconds + timeout 2 ip netns exec "${NAMESPACE}" \ + socat UDP-LISTEN:"${PORT}",fork "${OUTPUT}" +} + +function validate_result() { + local TMPFILENAME="$1" + + # TMPFILENAME will contain something like: + # 6.11.1-0_fbk0_rc13_509_g30d75cea12f7,13,1822,115075213798,-;netconsole selftest: netcons_gtJHM + # key=value + + # Check if the file exists + if [ ! -f "$TMPFILENAME" ]; then + echo "FAIL: File was not generated." >&2 + exit "${ksft_fail}" + fi + + if ! grep -q "${MSG}" "${TMPFILENAME}"; then + echo "FAIL: ${MSG} not found in ${TMPFILENAME}" >&2 + cat "${TMPFILENAME}" >&2 + exit "${ksft_fail}" + fi + + if ! grep -q "${USERDATA_KEY}=${USERDATA_VALUE}" "${TMPFILENAME}"; then + echo "FAIL: ${USERDATA_KEY}=${USERDATA_VALUE} not found in ${TMPFILENAME}" >&2 + cat "${TMPFILENAME}" >&2 + exit "${ksft_fail}" + fi + + # Delete the file once it is validated, otherwise keep it + # for debugging purposes + rm "${TMPFILENAME}" + exit "${ksft_pass}" +} + +function check_for_dependencies() { + if [ "$(id -u)" -ne 0 ]; then + echo "This test must be run as root" >&2 + exit "${ksft_skip}" + fi + + if ! which socat > /dev/null ; then + echo "SKIP: socat(1) is not available" >&2 + exit "${ksft_skip}" + fi + + if ! which ip > /dev/null ; then + echo "SKIP: ip(1) is not available" >&2 + exit "${ksft_skip}" + fi + + if ! which udevadm > /dev/null ; then + echo "SKIP: udevadm(1) is not available" >&2 + exit "${ksft_skip}" + fi + + if [ ! -f "${NSIM_DEV_SYS_NEW}" ]; then + echo "SKIP: file ${NSIM_DEV_SYS_NEW} does not exist. Check if CONFIG_NETDEVSIM is enabled" >&2 + exit "${ksft_skip}" + fi + + if [ ! -d "${NETCONS_CONFIGFS}" ]; then + echo "SKIP: directory ${NETCONS_CONFIGFS} does not exist. Check if NETCONSOLE_DYNAMIC is enabled" >&2 + exit "${ksft_skip}" + fi + + if ip link show "${DSTIF}" 2> /dev/null; then + echo "SKIP: interface ${DSTIF} exists in the system. Not overwriting it." >&2 + exit "${ksft_skip}" + fi + + if ip addr list | grep -E "inet.*(${SRCIP}|${DSTIP})" 2> /dev/null; then + echo "SKIP: IPs already in use. Skipping it" >&2 + exit "${ksft_skip}" + fi +} diff --git a/tools/testing/selftests/drivers/net/netcons_basic.sh b/tools/testing/selftests/drivers/net/netcons_basic.sh index b175f4d966e5056ddb62e335f212c03e55f50fb0..fe765da498e845d7be1fd09551363224d40ded65 100755 --- a/tools/testing/selftests/drivers/net/netcons_basic.sh +++ b/tools/testing/selftests/drivers/net/netcons_basic.sh @@ -18,224 +18,8 @@ set -euo pipefail SCRIPTDIR=$(dirname "$(readlink -e "${BASH_SOURCE[0]}")") -# Simple script to test dynamic targets in netconsole -SRCIF="" # to be populated later -SRCIP=192.0.2.1 -DSTIF="" # to be populated later -DSTIP=192.0.2.2 +source "${SCRIPTDIR}"/lib/sh/lib_netcons.sh -PORT="6666" -MSG="netconsole selftest" -USERDATA_KEY="key" -USERDATA_VALUE="value" -TARGET=$(mktemp -u netcons_XXXXX) -DEFAULT_PRINTK_VALUES=$(cat /proc/sys/kernel/printk) -NETCONS_CONFIGFS="/sys/kernel/config/netconsole" -NETCONS_PATH="${NETCONS_CONFIGFS}"/"${TARGET}" -KEY_PATH="${NETCONS_PATH}/userdata/${USERDATA_KEY}" -# NAMESPACE will be populated by setup_ns with a random value -NAMESPACE="" - -# IDs for netdevsim -NSIM_DEV_1_ID=$((256 + RANDOM % 256)) -NSIM_DEV_2_ID=$((512 + RANDOM % 256)) -NSIM_DEV_SYS_NEW="/sys/bus/netdevsim/new_device" - -# Used to create and delete namespaces -source "${SCRIPTDIR}"/../../net/lib.sh -source "${SCRIPTDIR}"/../../net/net_helper.sh - -# Create netdevsim interfaces -create_ifaces() { - - echo "$NSIM_DEV_2_ID" > "$NSIM_DEV_SYS_NEW" - echo "$NSIM_DEV_1_ID" > "$NSIM_DEV_SYS_NEW" - udevadm settle 2> /dev/null || true - - local NSIM1=/sys/bus/netdevsim/devices/netdevsim"$NSIM_DEV_1_ID" - local NSIM2=/sys/bus/netdevsim/devices/netdevsim"$NSIM_DEV_2_ID" - - # These are global variables - SRCIF=$(find "$NSIM1"/net -maxdepth 1 -type d ! \ - -path "$NSIM1"/net -exec basename {} \;) - DSTIF=$(find "$NSIM2"/net -maxdepth 1 -type d ! \ - -path "$NSIM2"/net -exec basename {} \;) -} - -link_ifaces() { - local NSIM_DEV_SYS_LINK="/sys/bus/netdevsim/link_device" - local SRCIF_IFIDX=$(cat /sys/class/net/"$SRCIF"/ifindex) - local DSTIF_IFIDX=$(cat /sys/class/net/"$DSTIF"/ifindex) - - exec {NAMESPACE_FD} $NSIM_DEV_SYS_LINK - then - echo "linking netdevsim1 with netdevsim2 should succeed" - cleanup - exit "${ksft_skip}" - fi -} - -function configure_ip() { - # Configure the IPs for both interfaces - ip netns exec "${NAMESPACE}" ip addr add "${DSTIP}"/24 dev "${DSTIF}" - ip netns exec "${NAMESPACE}" ip link set "${DSTIF}" up - - ip addr add "${SRCIP}"/24 dev "${SRCIF}" - ip link set "${SRCIF}" up -} - -function set_network() { - # setup_ns function is coming from lib.sh - setup_ns NAMESPACE - - # Create both interfaces, and assign the destination to a different - # namespace - create_ifaces - - # Link both interfaces back to back - link_ifaces - - configure_ip -} - -function create_dynamic_target() { - DSTMAC=$(ip netns exec "${NAMESPACE}" \ - ip link show "${DSTIF}" | awk '/ether/ {print $2}') - - # Create a dynamic target - mkdir "${NETCONS_PATH}" - - echo "${DSTIP}" > "${NETCONS_PATH}"/remote_ip - echo "${SRCIP}" > "${NETCONS_PATH}"/local_ip - echo "${DSTMAC}" > "${NETCONS_PATH}"/remote_mac - echo "${SRCIF}" > "${NETCONS_PATH}"/dev_name - - echo 1 > "${NETCONS_PATH}"/enabled -} - -function cleanup() { - local NSIM_DEV_SYS_DEL="/sys/bus/netdevsim/del_device" - - # delete netconsole dynamic reconfiguration - echo 0 > "${NETCONS_PATH}"/enabled - # Remove key - rmdir "${KEY_PATH}" - # Remove the configfs entry - rmdir "${NETCONS_PATH}" - - # Delete netdevsim devices - echo "$NSIM_DEV_2_ID" > "$NSIM_DEV_SYS_DEL" - echo "$NSIM_DEV_1_ID" > "$NSIM_DEV_SYS_DEL" - - # this is coming from lib.sh - cleanup_all_ns - - # Restoring printk configurations - echo "${DEFAULT_PRINTK_VALUES}" > /proc/sys/kernel/printk -} - -function set_user_data() { - if [[ ! -d "${NETCONS_PATH}""/userdata" ]] - then - echo "Userdata path not available in ${NETCONS_PATH}/userdata" - exit "${ksft_skip}" - fi - - mkdir -p "${KEY_PATH}" - VALUE_PATH="${KEY_PATH}""/value" - echo "${USERDATA_VALUE}" > "${VALUE_PATH}" -} - -function listen_port_and_save_to() { - local OUTPUT=${1} - # Just wait for 2 seconds - timeout 2 ip netns exec "${NAMESPACE}" \ - socat UDP-LISTEN:"${PORT}",fork "${OUTPUT}" -} - -function validate_result() { - local TMPFILENAME="$1" - - # TMPFILENAME will contain something like: - # 6.11.1-0_fbk0_rc13_509_g30d75cea12f7,13,1822,115075213798,-;netconsole selftest: netcons_gtJHM - # key=value - - # Check if the file exists - if [ ! -f "$TMPFILENAME" ]; then - echo "FAIL: File was not generated." >&2 - exit "${ksft_fail}" - fi - - if ! grep -q "${MSG}" "${TMPFILENAME}"; then - echo "FAIL: ${MSG} not found in ${TMPFILENAME}" >&2 - cat "${TMPFILENAME}" >&2 - exit "${ksft_fail}" - fi - - if ! grep -q "${USERDATA_KEY}=${USERDATA_VALUE}" "${TMPFILENAME}"; then - echo "FAIL: ${USERDATA_KEY}=${USERDATA_VALUE} not found in ${TMPFILENAME}" >&2 - cat "${TMPFILENAME}" >&2 - exit "${ksft_fail}" - fi - - # Delete the file once it is validated, otherwise keep it - # for debugging purposes - rm "${TMPFILENAME}" - exit "${ksft_pass}" -} - -function check_for_dependencies() { - if [ "$(id -u)" -ne 0 ]; then - echo "This test must be run as root" >&2 - exit "${ksft_skip}" - fi - - if ! which socat > /dev/null ; then - echo "SKIP: socat(1) is not available" >&2 - exit "${ksft_skip}" - fi - - if ! which ip > /dev/null ; then - echo "SKIP: ip(1) is not available" >&2 - exit "${ksft_skip}" - fi - - if ! which udevadm > /dev/null ; then - echo "SKIP: udevadm(1) is not available" >&2 - exit "${ksft_skip}" - fi - - if [ ! -f "${NSIM_DEV_SYS_NEW}" ]; then - echo "SKIP: file ${NSIM_DEV_SYS_NEW} does not exist. Check if CONFIG_NETDEVSIM is enabled" >&2 - exit "${ksft_skip}" - fi - - if [ ! -d "${NETCONS_CONFIGFS}" ]; then - echo "SKIP: directory ${NETCONS_CONFIGFS} does not exist. Check if NETCONSOLE_DYNAMIC is enabled" >&2 - exit "${ksft_skip}" - fi - - if ip link show "${DSTIF}" 2> /dev/null; then - echo "SKIP: interface ${DSTIF} exists in the system. Not overwriting it." >&2 - exit "${ksft_skip}" - fi - - if ip addr list | grep -E "inet.*(${SRCIP}|${DSTIP})" 2> /dev/null; then - echo "SKIP: IPs already in use. Skipping it" >&2 - exit "${ksft_skip}" - fi -} - -# ========== # -# Start here # -# ========== # modprobe netdevsim 2> /dev/null || true modprobe netconsole 2> /dev/null || true From patchwork Wed Jan 8 11:50:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13930681 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 525711FBC91; Wed, 8 Jan 2025 11:50:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736337045; cv=none; b=o9EDziNWC7HRyk3N4SAEpy4tbHtbS5ld0eaIvXdUTgTqwpeNlNCwfDGzHIOKyPb8vL11x7L+QsNLAl3C+q/y/kR3lxZAap8KVSwLoOsMmdplv4Zrz5O9bAHtAaOAqmXZ1ym+CBoJ3XSCZfXZ6MVMo48jjMh7aYIIw3lWLhG+k9k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736337045; c=relaxed/simple; bh=5NsZyre7dhB8gjVJrgCTRYi8hSfLC+Af6awHSBnzZaA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iuYnOzTMhKDqhMB0svLZD64dJhJi4bCCT5vNY7FsqyekP9zBYMCdZGb9RqQmT8incoYzJ93JPBf+y3h5NQKhDCQsRjpvU1MXEtoBG+cu7MNiLKm+27KsJh5WRVuR5Rk+jC5IB6o8iZT2tXMkmsU4c/l01EUxh/4pBFiSgI1LqS0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.208.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-5d3f28881d6so24759579a12.1; Wed, 08 Jan 2025 03:50:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736337041; x=1736941841; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=10Sv9Y7ixrJh+da5K4zI/xAp2zqjv0+XI+pN38JTjZ8=; b=cKJ5eVE5pVWL21KQQGfiJsX/PptL4v4RKoh9tbFJ9CgzyXdypFcFu7iVoiaUpYsqaL C7d+wauGP5hgM3BDuMzHX9HVK3GYI3Rds8ux/epyzGKhvsJzzorokzQxxUIksN/HAcww MU07cmyznAXrkBZsbOcDqBF7ww5u7tNcGdl6w7ufCCNF4n/HxaYc+LzyyP5dEhoSLkzP gCfdSK4/OZVoBUa2e+wC5StiJzGp11Y5JZN9ioBE4GYsrpKvnw6pGGaPhbklu1+bDVOv y86jpD4MF35vsFxQEAAo0SML14YZc63mObP37BNTTYQSeFVSOBhcoJsnFtAYp8KrHSVy 1kfQ== X-Forwarded-Encrypted: i=1; AJvYcCWEmYFgCGpSv59kgqsj0b+PYKOzuAYlrq343QjJ5usOhcaUOX5+RDHrqIpsknztjMhP/82uqlpNG8dmJcz8skwN@vger.kernel.org, AJvYcCXsvq4LQ1RdWcE2UrdEWLtE6xofIRKA3nCQFLPCHzavD/2lzJjKF0FrsVo8r1KxboAO9HcHLRO4aARGlU0=@vger.kernel.org X-Gm-Message-State: AOJu0YwwBRT38jZc8YSTQ6Sp6nCIAhobeylSClMWqldEHKs1zMZ+cDrd kmryP/+TwmSIDE2PoIoLPZ6s42hoafvIiTctkthXoPerTB4rue01 X-Gm-Gg: ASbGncs8UhngJMMJ4ybMYEMNts8SWjncp48+7co7TaMoTZwFnBsiY31JSFbDA4VtPEv caW8vlnWrKj3g+yXXnmFE2KJr8GnZNmVGC59DXybMoFkqTBRDHzlRMhG1p4yvCihmbjWY4HYvQw OKiesGuixv5haxqMCryFT8q95O9fIRWLYneDrXuHdPp8gYVu5YuKEe7ZrRpimZNBZVWG6S72Au/ gD9y7xoG8WAPX3I6f3N+nYfRHs6Rlewr33r+k3gvcACpEGm X-Google-Smtp-Source: AGHT+IH7NRytDkgi57nzFn007chLWDtnMegqO5CoMn01qjqkiJcL0beA2O+M/nI74hZBU5K073h7fQ== X-Received: by 2002:a05:6402:2548:b0:5d4:2ef7:1c with SMTP id 4fb4d7f45d1cf-5d972e639e4mr5337731a12.24.1736337041391; Wed, 08 Jan 2025 03:50:41 -0800 (PST) Received: from localhost ([2a03:2880:30ff:74::]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aae8b7de1cesm2321862666b.23.2025.01.08.03.50.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jan 2025 03:50:40 -0800 (PST) From: Breno Leitao Date: Wed, 08 Jan 2025 03:50:27 -0800 Subject: [PATCH net-next v3 3/4] netconsole: selftest: Delete all userdata keys Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250108-netcons_overflow_test-v3-3-3d85eb091bec@debian.org> References: <20250108-netcons_overflow_test-v3-0-3d85eb091bec@debian.org> In-Reply-To: <20250108-netcons_overflow_test-v3-0-3d85eb091bec@debian.org> To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Shuah Khan Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Breno Leitao , kernel-team@meta.com, Simon Horman X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2070; i=leitao@debian.org; h=from:subject:message-id; bh=5NsZyre7dhB8gjVJrgCTRYi8hSfLC+Af6awHSBnzZaA=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBnfmaKFSsKWkOpGsBGb+V3+6JtTu/T/ABaU304s fNMMYay2/eJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCZ35migAKCRA1o5Of/Hh3 bZzXD/90cStCYZR/lkixASdyf3TlSbyXMF4991WY+3N0N2Kivj9DRwkBaG5s5TP7+76Lhx3Xdej /QG6rTZRrd3SiQ67wunmvXuEwtIjeR6YVLHNxXFIwK1nFbXwEeq/T9kXffs/PS1cgSMAn0BzbTj l4IxTehF8k6Lhzm4bEZrjsAkwtrwL+eeW8PhUljQ5BAonIVxHzm3ZLYd4AQwwdaurJNEqCgMsz1 aiKwywDOhQ7kOl5NiLU+c5cFpcrBjY054pu1hz5CZYHMD/sMmudRgiNNDokXT5CT8RACJ3AeZv0 nfFppHLgQWjk0ANJzbjPgMrd0r3lvvtnC4NPzI55rFNCG1goIvKuSEo6Mm26VXozLOwn9YWVTH9 TX5XH5Qc4+kYJV0xnDssxJ4tZa+n8+AgEC7oy2VSIxcu1Z4DuEUqMuVX+v8ydjUEg+PDOAKbKvF ZimAezn1GtQqSp+EA3/xGYzgklDPDZooF/dJbB74nItNhKam6vZiS/BPeSmj5TTMawZhsusrWJq 4ssbm6tff6hZQxt/jo7a9F4GEoKeTccwMdmop0QMNv5BTJYogceVtEDSNIaAs03pIhiRfrU1G8+ 62oBetljrc10Ya43KTcXsWUw9+5r5K4Df8gr4aGNlUBVT4rCxPtZc8oa8/ZABW/4sVkc56JRDaN LYuwkCrzMQgaIeg== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Patchwork-Delegate: kuba@kernel.org Modify the cleanup function to remove all userdata keys created during the test, instead of just deleting a single predefined key. This ensures a more thorough cleanup of temporary resources. Move the KEY_PATH variable definition inside the set_user_data function to reduce global variables and improve encapsulation. The KEY_PATH variable is now dynamically created when setting user data. This change has no effect on the current test, while improving an upcoming test that would create several userdata entries. Signed-off-by: Breno Leitao Reviewed-by: Simon Horman --- tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh b/tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh index fdd45a3468f17449eeb66d9a808b7a3b2107e47c..3acaba41ac7b21aa2fd8457ed640a5ac8a41bc12 100644 --- a/tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh +++ b/tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh @@ -23,7 +23,6 @@ TARGET=$(mktemp -u netcons_XXXXX) DEFAULT_PRINTK_VALUES=$(cat /proc/sys/kernel/printk) NETCONS_CONFIGFS="/sys/kernel/config/netconsole" NETCONS_PATH="${NETCONS_CONFIGFS}"/"${TARGET}" -KEY_PATH="${NETCONS_PATH}/userdata/${USERDATA_KEY}" # NAMESPACE will be populated by setup_ns with a random value NAMESPACE="" @@ -116,8 +115,8 @@ function cleanup() { # delete netconsole dynamic reconfiguration echo 0 > "${NETCONS_PATH}"/enabled - # Remove key - rmdir "${KEY_PATH}" + # Remove all the keys that got created during the selftest + find "${NETCONS_PATH}/userdata/" -mindepth 1 -type d -delete # Remove the configfs entry rmdir "${NETCONS_PATH}" @@ -139,6 +138,7 @@ function set_user_data() { exit "${ksft_skip}" fi + KEY_PATH="${NETCONS_PATH}/userdata/${USERDATA_KEY}" mkdir -p "${KEY_PATH}" VALUE_PATH="${KEY_PATH}""/value" echo "${USERDATA_VALUE}" > "${VALUE_PATH}" From patchwork Wed Jan 8 11:50:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13930682 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f49.google.com (mail-ej1-f49.google.com [209.85.218.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A318B1FC11C; Wed, 8 Jan 2025 11:50:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736337047; cv=none; b=EKoqjWtDwNbj1FvLtEyDf3N8QUDKVSsJ6DNVb/5243O2WUVu6vK7kWz0JmwNWmI08ujoJS0Awy/rtyzYU7W5NFT2u0scIz9JY9xixgmGlwsG8K9z7yuvmsTAuraC1i89akcH1BbJ8zvZPfMfT5AggcFqV9Xm+cKiakDDOjKvovo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736337047; c=relaxed/simple; bh=FxHCTrtEmHlr3dDtmtGQco4f9/wDAlZQfRPrG20bCrc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MxjJlu8LPPEsToZKKnAh0zqcE3aSlUz3J6BPXlJWklf8VQ1o8lB9Yr6KaNp0lg0hLUTkdgRzdKLsg7g4YdTt+QsgXvxABgskVebGAHsuPCtHxuBk4677TeRF+5868Tmv+hQkY1wXZxPpJ2eLDkf9lzEnaYncodjyJhKF1P7SCFA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f49.google.com with SMTP id a640c23a62f3a-aa689a37dd4so533854366b.3; Wed, 08 Jan 2025 03:50:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736337044; x=1736941844; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NJbpaWVafqwrrz+ZENkKDr5EG7mjxcdM072QuX4YMuo=; b=VY/TNxFC5NZlosi5ZJXgbSwG66Oy9AErQ6rK8hQs4wmQV+PI0r6RhRJZDuUhwe62+a QqVTAsfNWlpK+iQ0k3Xs9KgolvAuwqVb3Ve0O7jsDrv91MJ++amiDFK3g30LJ45+718a 9NuDYJ9uLq+ssqMaxDqGkFOjq82dJa6UdATSFPiDFSNbp+pEiVZOMKp9aEJO6MBFmNjK Y6fezCyIeUIt1SfHwGQl5bLQUmllhAt3kYEuqQobfLdT5bTJcK4/8k47b0GUSMtrF0fQ aQvYH+11WTH2b79h6eT3JE4LeGFAVSIpyRXZSKD5u1VcrNYq9TXcK/pXEV3mHoMX57E2 32rw== X-Forwarded-Encrypted: i=1; AJvYcCW6FUehK7QzL0l4qVzeHM/Q/4rOLTBAAylCIFAkvRYlaYi4q+sYTZMZPkuapap/Q+CVTae7zEciTt9ZErpNJbO9@vger.kernel.org, AJvYcCXG7VJkKN1SYl1NG/fHyXUYnFuDRvTYxToBJzugIWawGOYJF8UAsetgvREIDiUY0DoIIo8zq7QW5tvulAo=@vger.kernel.org X-Gm-Message-State: AOJu0YxvjhqbJf9QxfK/XFpdlDMC9quttPfdbVLwMDN/wWBVoPPf++v+ wiB4QtEyk7YhHTSuPQhIgQRxlvC/jp7etCj96Hw7r6F/tXLHhQeakNYwxw== X-Gm-Gg: ASbGnct9ukxvNLVBH25iFdLTxL4E8n6V8Un98lGWotYMgjlu5GPOiD87/Bw9PRHmUP3 RDq+6N7XtShfJlDJeBrl4UGS54YpAqqYYh0P8/yK6om3SNPS7jbRazTwx9P7Kchl4K+Ojpol7vT mCMh0MgrVDVBs+bToS8FW/idkzkmgIzORb4fKuTH6dQEtKZKcxeqJSxQcfGb2XdsUUpsEyEBltA 1C3lkplMqkQ2Pv1Z+vXZFaR7beG8q00iavXQODhvgbZ X-Google-Smtp-Source: AGHT+IGakNtI4bbSXZ+97iyWdDz31MdnmCsTICCsbc+mlfNjy7LWX8mBCDxPvF0ejv6v1zPchbYH/g== X-Received: by 2002:a17:906:f585:b0:aa6:7933:8b26 with SMTP id a640c23a62f3a-ab2ab6a8deamr162899666b.9.1736337043769; Wed, 08 Jan 2025 03:50:43 -0800 (PST) Received: from localhost ([2a03:2880:30ff::]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d80678c6dfsm25460691a12.37.2025.01.08.03.50.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jan 2025 03:50:43 -0800 (PST) From: Breno Leitao Date: Wed, 08 Jan 2025 03:50:28 -0800 Subject: [PATCH net-next v3 4/4] netconsole: selftest: verify userdata entry limit Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250108-netcons_overflow_test-v3-4-3d85eb091bec@debian.org> References: <20250108-netcons_overflow_test-v3-0-3d85eb091bec@debian.org> In-Reply-To: <20250108-netcons_overflow_test-v3-0-3d85eb091bec@debian.org> To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Shuah Khan Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Breno Leitao , kernel-team@meta.com, Simon Horman X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=4125; i=leitao@debian.org; h=from:subject:message-id; bh=FxHCTrtEmHlr3dDtmtGQco4f9/wDAlZQfRPrG20bCrc=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBnfmaK/oL+TEo0vdH3f7qL2qsiDS0LlxM+QiXYa a+AphiRc92JAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCZ35migAKCRA1o5Of/Hh3 bYb1D/9OiOlMTwUJSSQOGK0b8iQ2Cu4BW3XBxlDlKLkPgDZC+k+wc9NwdKfoh/DEUtHuaHMr7hM 51yWAP2VCFy3/WwexQS8c09K7ZeovJCYn34V7rOEt6+cUdS0L2bMb+5PhiBG5v+7wnAYWz6HYuc Du14l8jPNCCp3cilVRG1UZnIe3V1GYB62w1E/ctn4UoM19BjHIy9GbtAbUkXS9mBmzzH6FHwSSC +SCJSL7UTq+9to0jzR20CDercbl8eIfSOhPjiOJWRm1v0Xdt8lzeDN1d8V1g/q1EZZY0EwtEzkg U2ICUoRyu9JxP6Vw22PO+Qq9cSgYPZINTHN7OuIhIv6AbEJWxCcHo4cR/kaQLP+v7tw140VRw1m RP2fdMnf4CSsO9Aq405rCXL/Q6eBNM0PjflJXpiDL3Zl2HGm5J9s47fOmzdy5XHVM27+WLnDzYU zQgQPfWdod2Q7jAuKFYSTwEaqYmvnvyscK6Uky6rlqadL71y8A7M/jLtsZC812cOyIP483qc/hH Kb15Vv7a+DB47JZEWBflAjYeZU4CROn9/QhBWLlasu6ENfLHLjNMQfkbQ+TAmwchBYiWAFkkjye xdIaOVCWV1lba/UzxMLavhrOnbNSv0c3VKhQQpVKiiWDCcbsuZgf5JOrER9F8glxisy50jzICjO YBGiau5Q+GrHdLA== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Patchwork-Delegate: kuba@kernel.org Add a new selftest for netconsole that tests the userdata entry limit functionality. The test performs two key verifications: 1. Create MAX_USERDATA_ITEMS (16) userdata entries successfully 2. Confirm that attempting to create an additional userdata entry fails The selftest script uses the netcons library and checks the behavior by attempting to create entries beyond the maximum allowed limit. Signed-off-by: Breno Leitao Tested-by: Simon Horman Reviewed-by: Simon Horman --- MAINTAINERS | 2 +- tools/testing/selftests/drivers/net/Makefile | 1 + .../selftests/drivers/net/netcons_overflow.sh | 67 ++++++++++++++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) diff --git a/MAINTAINERS b/MAINTAINERS index d3cd4b7e48652b7a56873b840fd2ed6e12791008..44b560e3470ad612b60c7bf002152311bb419c72 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -16175,7 +16175,7 @@ S: Maintained F: Documentation/networking/netconsole.rst F: drivers/net/netconsole.c F: tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh -F: tools/testing/selftests/drivers/net/netcons_basic.sh +F: tools/testing/selftests/drivers/net/netcons\* NETDEVSIM M: Jakub Kicinski diff --git a/tools/testing/selftests/drivers/net/Makefile b/tools/testing/selftests/drivers/net/Makefile index dafff5d7fe88c82a1d27aa49faca728b52435ebc..469179c18935ffcc12b979ccdc9f84e9d4082b90 100644 --- a/tools/testing/selftests/drivers/net/Makefile +++ b/tools/testing/selftests/drivers/net/Makefile @@ -7,6 +7,7 @@ TEST_INCLUDES := $(wildcard lib/py/*.py) \ TEST_PROGS := \ netcons_basic.sh \ + netcons_overflow.sh \ ping.py \ queues.py \ stats.py \ diff --git a/tools/testing/selftests/drivers/net/netcons_overflow.sh b/tools/testing/selftests/drivers/net/netcons_overflow.sh new file mode 100755 index 0000000000000000000000000000000000000000..29bad56448a24a2d98c21bd53b74f3bc2ca7e64a --- /dev/null +++ b/tools/testing/selftests/drivers/net/netcons_overflow.sh @@ -0,0 +1,67 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: GPL-2.0 + +# This test verifies that users can successfully create up to +# MAX_USERDATA_ITEMS userdata entries without encountering any failures. +# +# Additionally, it tests for expected failure when attempting to exceed this +# maximum limit. +# +# Author: Breno Leitao + +set -euo pipefail + +SCRIPTDIR=$(dirname "$(readlink -e "${BASH_SOURCE[0]}")") + +source "${SCRIPTDIR}"/lib/sh/lib_netcons.sh +# This is coming from netconsole code. Check for it in drivers/net/netconsole.c +MAX_USERDATA_ITEMS=16 + +# Function to create userdata entries +function create_userdata_max_entries() { + # All these keys should be created without any error + for i in $(seq $MAX_USERDATA_ITEMS) + do + # USERDATA_KEY is used by set_user_data + USERDATA_KEY="key"${i} + set_user_data + done +} + +# Function to verify the entry limit +function verify_entry_limit() { + # Allowing the test to fail without exiting, since the next command + # will fail + set +e + mkdir "${NETCONS_PATH}/userdata/key_that_will_fail" 2> /dev/null + ret="$?" + set -e + if [ "$ret" -eq 0 ]; + then + echo "Adding more than ${MAX_USERDATA_ITEMS} entries in userdata should fail, but it didn't" >&2 + ls "${NETCONS_PATH}/userdata/" >&2 + exit "${ksft_fail}" + fi +} + +# ========== # +# Start here # +# ========== # + +modprobe netdevsim 2> /dev/null || true +modprobe netconsole 2> /dev/null || true + +# Check for basic system dependency and exit if not found +check_for_dependencies + +# Remove the namespace, interfaces and netconsole target on exit +trap cleanup EXIT +# Create one namespace and two interfaces +set_network +# Create a dynamic target for netconsole +create_dynamic_target +# populate the maximum number of supported keys in userdata +create_userdata_max_entries +# Verify an additional entry is not allowed +verify_entry_limit +exit "${ksft_pass}"