From patchwork Wed Dec 4 16:40:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 847696 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.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 0DE461B85EC; Wed, 4 Dec 2024 16:40:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733330460; cv=none; b=npKHh7GulsNgiGr1KWgQwY2lyiWGjhtWxYsrZniUS3qgHdOmsEz53fUmgiAVlVFXHIW4xsL5FPNWzf8n+IEKa6UEC1PiBK1z+AhxBL5G5E2u8Rhen/rll3urMOqHfNP2rjeRsWMwgJyhWbWKOSe3xcx5b8GdLRT7/7QSSWv5uyI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733330460; c=relaxed/simple; bh=ovxjdhKZTZJF3bNoyUUKDjDyDyhf1uuMTZmUa6QGS+4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gEIreUO5PUxX+7vjrln1MK0M5PNnAtteg3EacB0LQz7s7kTH19uqJB3JJb4xXLhsETzQTAw8IPzpeZER0jOaida6O66rJizPvhxOVRgxxaGzFD90LaodZoZHo8Pu+yJqO2mef4CzRABZ/xhlk8G9r3rvbNfADR8y6QFur8WbLVc= 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.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-ej1-f51.google.com with SMTP id a640c23a62f3a-aa55da18f89so1044156766b.0; Wed, 04 Dec 2024 08:40:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733330457; x=1733935257; 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=eGKhXWb7HtZIOVQHIFExLTvViIJYYv0F3Lwy/m15R3M=; b=wH/Fu6IDYtAyrWkG+ILgRtwer3VElxH7sW9jg2N+2stFXVdDL/aWrfZiUD5GCkPbW9 HZnmxXXZxpJSHTZ4NBeJ7bnpbcRBe+l7ONeK3L6QUk0Rn38u3wZ3o6k0HkA2FXDdnlHR D5UqjsXtWzE6LFrgCWIoDghPYn84PLOeWf7UkB5ysYOinwd8vXrKFMJEtnItFHchof+n ci3HOsJp2pfYZDN4sadwdHQgYuYL8+xZiqyQ7dB2UD63G62+097+3MiKvkFBD5TQ2imX hRqW8axvcVsDF0udUCPlolFlIZxYlklM+Wwlh7Q5FdWZe0hKKRs+bnHAYhpfmaShrQKG qPxA== X-Forwarded-Encrypted: i=1; AJvYcCUUiuoFXE41ud84AJCUmWPkE3I4MQKBG0Y7CGC5Z0oX0ALNesDyWHVYmsk9UU2gwlkGvYjxyam363m4FHlMK/JK@vger.kernel.org, AJvYcCV26EGSOPS5dl3WThzoQQNFYq/hYhY1imVsO76XawHQ86aLqDoijNyIwVTQ+7eosswLOQFJ7jalzQtiiPw=@vger.kernel.org X-Gm-Message-State: AOJu0YwqNhO/npUKkaljiTYAlzeUUN4mewYNAqJlegaUtMdetTj2Fx4R qo1lgPziXLkrDITVvLocZN2z6kAlmVXfmwkLTu4xFK9qLG7zb/PnVz3/cQ== X-Gm-Gg: ASbGnctUU+2FDlLnFM7ldrJ4RSmTBoh2WSSb5wCCSMhE/Vzwew2SkgfOFV/MVp/HJ4R m5zr65vUP1jEcMyC4Sip6zelGHXSKQYFgbOOHKYeuxWZYaLh5eMd1BrAmCsd088sZMofh89AGyS 1HZeNmilmBkPCOHKzvD13WaeZoqWufmmXbykI7T61YFQAXkDondNQ8BrOPWCYwmHp17v/JdfiPj fF7bgYaGmLafqK+42CqUMjxZfOmt95+lElSZahF/l8YwW7Giz0Gwhokr843HsQqx6PTEUiIyIvo CA== X-Google-Smtp-Source: AGHT+IGoMCilSf/5FCw7ftvtOv25fdXS12WGiCb7ddKIIZZQguO8hPB3cVK/S6ZqT15PetPGh7lhtA== X-Received: by 2002:a17:907:780d:b0:a9a:1585:dd3b with SMTP id a640c23a62f3a-aa5f7d4d219mr570414066b.21.1733330457195; Wed, 04 Dec 2024 08:40:57 -0800 (PST) Received: from localhost (fwdproxy-lla-009.fbsv.net. [2a03:2880:30ff:9::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa5996c2c44sm762955666b.29.2024.12.04.08.40.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Dec 2024 08:40:56 -0800 (PST) From: Breno Leitao Date: Wed, 04 Dec 2024 08:40:42 -0800 Subject: [PATCH net-next 1/4] netconsole: Warn if MAX_USERDATA_ITEMS limit is exceeded Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241204-netcons_overflow_test-v1-1-a85a8d0ace21@debian.org> References: <20241204-netcons_overflow_test-v1-0-a85a8d0ace21@debian.org> In-Reply-To: <20241204-netcons_overflow_test-v1-0-a85a8d0ace21@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 X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=987; i=leitao@debian.org; h=from:subject:message-id; bh=ovxjdhKZTZJF3bNoyUUKDjDyDyhf1uuMTZmUa6QGS+4=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBnUIYVs0kjByuqSoxAk0AiC4ZBu+mV7D9Kr2Y9q 7JqHzAbaQ2JAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCZ1CGFQAKCRA1o5Of/Hh3 bUkAEAClfKd1/z37QRE3JG+vQupkR9Vd1UrGnL9LaUSIA3qsKw3iFb5WWQelksTT62587/NQt0V N1am6K0jlfl0ux9Vs0nGk/sxsyfgiWZG359/87I6NLH+M2iccbCcE8s24M831Imkhb98jhtYvHH e4oeFgi1g6WXVdYtA4z0SsCb0+d28AI8jME0h3Cn2BwD/wzZLasFTTqd1ybQMexS5Nv9Ww58gCC ryMqs7bvoCecBheWtHro0qqwdwJ2m3562vufIGJGg1rD4yL7vBawlLfspfq7ulYRGzrYqcZH8D/ m4IgoJksgEMz4uLr/m0GE7/4Uzk+lsifvxJjdessPKC2SWtbJo01OsDrv+wWMvDtSJMZQ2wnvuk wTwUhvtVg8JutXgkAkzLRqSZ7mOP77YWNgXrj0vs5cdpmvwavDCziDiGiN1PvIVtVlG4Skzv65T iUH6V735PiKWe7NXi3VCDyx0PWRINTcg51GEXr3oNZ71Gngr9DdCWpeouy2x+TY7e6K2SOX0pZw mmwcM/B4cL/yHgzWACkUmRWdU5QPJ4bLG0yuvd4CFu5wdcPQFAT9HR6c1kx4OM5rT8hliH17UOP qSRh7InGo3Z4YGA3sUL/YORURv23GDMoh+zW/BrHLq7xTIqSwvzMKQhp8kfHVOSZGYOOInu99cQ mZYZpftASXUQJiA== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D 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 4ea44a2f48f7b1f9059d275f0f0edc40cc1997f0..8b9dd4842f3e516c7eaa08205a45092e64417440 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -705,7 +705,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 Dec 4 16:40:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 847472 Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com [209.85.208.43]) (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 0259120D4FC; Wed, 4 Dec 2024 16:41:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733330463; cv=none; b=QY8uxap9KJp+IOYvBOWAhG3JNKMuQFSni8t60OkqKJjlSrkF6snuXcj0llnMeOpiqfyo2ALcRnxKJMpFCR5o379C4GiLh56Kcwe2YiJ+fZXY8o1UtSNvDFN33yeKk2HIP1J5RH8V00IgipuHVA5BfcYztoFRyf1pPHqpzbtlXVQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733330463; c=relaxed/simple; bh=G+FEqjsvSdAMfldd5nI9dWrnpQcLblC/mjCfA25OZkQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Tw71bfbla89OU5oOjVTTP4CWQ1O7bxidxM+l7IZF1UB0Nle9/V5xKMuJ3lOJVe2OhYsSPdgjkaII8Vg0qO7YxXj1zlmRXs3ONdu8B3Wor9zGG4VqbRZUKw5QJHLlKRsaiW1ML7dJ/AH+VzDo0YVAwZq64uFzyoxmw7Nqp4H7YZM= 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.43 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-f43.google.com with SMTP id 4fb4d7f45d1cf-5cfddb70965so8728420a12.0; Wed, 04 Dec 2024 08:41:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733330459; x=1733935259; 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=EED6edYc58ZoUVFAXfO05i/aquvxfhSgMV2Jzs4zP+M=; b=eYu+yZVFUb2cZW5ht2wl0qIpatd4DAR0ZjgJ5Rif+Re8KWpgCPE80NpZblCrpPp+2f mKiMJkr0pUg8i+UtyXWQsAInYm0lOQAe9//agHrLLUQjT5tZgSsvWJ6Ys31WhkQW/pC8 CaVp2rgFISbYXk+noAe7Un3vnHNWul06AfHz70dByBY3t4+om1P7d6DeBCVHwOffD3I3 p8ziL3ZVqD12uQkgU2Iet6DcQQUModSNH0cxsS5xJZsvWpJCu0Oin4zgbMKnYHuQlQ5A 4wgG30AAvihq20Dq06/bAdkGgzJZdO6OYF7WBel/T0aVdAHp0iNjf/oc8UVXTJvjuEvK nkKQ== X-Forwarded-Encrypted: i=1; AJvYcCUMKWb9TmiOEg2BsPuYxEkt9E8kTg09uZwwfHkiT/7JCzwZusesQpI1eUHKkHBZUPFz6392mJbT+Jqna+lPHl71@vger.kernel.org, AJvYcCXeF0aX3wNT/tnLn1duLGinCamgC7yAFkGi/TmmNhc/7GrYHsfAKoVD6aSAs0G1ji+k0lFcc5KWxqN2egM=@vger.kernel.org X-Gm-Message-State: AOJu0YxtTHET5zFbjLs025C8JWeKa9Mwm3xKPV4rM5NUoBeJ08tqGQCZ eD1yjl9+lrkC6ZRWD5k9ozD9dyolrT6LaR+hnH14wgOuo/uqDy8AVjeTAg== X-Gm-Gg: ASbGncup8OvcE8sFqPPM6zl2URayW+lwfI4gsPjmN2Ofi9atKjXokk4jsyES+DOH2EB WcCFvIrl4o0H5Foqupft1oqInpxPtz7ix1+XHrHmsy171IEgvEwynxuRKSAzJUE5IRioCP6cTXH Rf7eA65tEDHAV4C29APFadNQSKQmJvohwxBQ3EhYe2yxthAmXyiMwy6uDb51xBL+vg386PvP/ma nOoUTLgNwpRVN8Tq9u+6Xy901OclkIjJHv66Lr0t45PYc4UwJdLce+eRXtQ2QsHfGeAVnUaqz1w h5g= X-Google-Smtp-Source: AGHT+IF1XvdKZE+Lf6LpH7ElP1PAKYpJv6ya+RmcbgwMyuj9BYlOc1/lAv3dkqRnu0MNk71XAgMsIQ== X-Received: by 2002:a05:6402:26c1:b0:5d0:e3fa:17dd with SMTP id 4fb4d7f45d1cf-5d10cb800e1mr7094272a12.22.1733330459081; Wed, 04 Dec 2024 08:40:59 -0800 (PST) Received: from localhost (fwdproxy-lla-126.fbsv.net. [2a03:2880:30ff:7e::face:b00c]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d0c7a2a0c6sm5411002a12.26.2024.12.04.08.40.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Dec 2024 08:40:58 -0800 (PST) From: Breno Leitao Date: Wed, 04 Dec 2024 08:40:43 -0800 Subject: [PATCH net-next 2/4] netconsole: selftest: Split the helpers from the selftest Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241204-netcons_overflow_test-v1-2-a85a8d0ace21@debian.org> References: <20241204-netcons_overflow_test-v1-0-a85a8d0ace21@debian.org> In-Reply-To: <20241204-netcons_overflow_test-v1-0-a85a8d0ace21@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 X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=15025; i=leitao@debian.org; h=from:subject:message-id; bh=G+FEqjsvSdAMfldd5nI9dWrnpQcLblC/mjCfA25OZkQ=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBnUIYVb7KdwjKK47u5OEDr6GHsJKdt9JdrHO/S+ c259S6rlRqJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCZ1CGFQAKCRA1o5Of/Hh3 bR64D/wMd4nODf3XQuYzhcS/zbYYtspIoXNfXh25aq7XpHCtMBtwsx44DMwmtFft7eJf9GnNfuE nOy9ruQ+0UFHK79n7xCcWhwHnFcCur+DktdeaqyYYn1rFIKRh7PWD+NnGicCV+fKFftl5OHuYOA YkBGYtnOVO6DNzzzDPvXpH3ZHNMg59uy2RrKEDoXxfFvXunN0MJDv5CCPJtzfrTdVY6Iy9gFVSa iD4Gj2WpidU5Euxon3djyGx8oPX3hP0zHKtAJdk0FMVFOAJMHcTjC8+Vrar8yYDIcXXtQ2uUO3i GBHg/8xLVsjtC/lSzdXofNbnXPN5BphX8S4d43vHIFoAcVxTh4Bs8jZ5RjuMvHfXF9KMQfOVGoO wpug67CJScOzDHSuSZMA7TxO+mrc53ueoLc5Y7VtbAEKroPaIgcGdZTNPUkv20ycKfgZvIh7TbZ fZf6Sv4Nu3SgMgVZf44DSLCyQN2o6iqaOpOFf/WpF1V63UvWmQYSUddXRQYCWfdPx6J1QEWmzUe 4pjX4nIZOUsoIxsGE2lQPsvOxEPNewslEwzTo6A2NBhEf+858RsZd/jcRt6NtlG1NSLOglxSF62 BnNN2K8086l35M5MWZGEYwxpKOGXuadgMZ3sa4Vs1QEn2B5eSL3XRhgizWX1KnWXO2dNC59VQ2J DYU30CKCwz5ulHg== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D 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 + .../selftests/drivers/net/lib/sh/lib_netcons.sh | 225 +++++++++++++++++++++ .../testing/selftests/drivers/net/netcons_basic.sh | 218 +------------------- 3 files changed, 227 insertions(+), 217 deletions(-) diff --git a/MAINTAINERS b/MAINTAINERS index 0456a33ef65792bacb5d305a6384d245844fb743..8af5c9a28e68c4b6a785e2e6b82db20b3cf59822 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -16091,6 +16091,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/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 Dec 4 16:40:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 847695 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.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 7F97A20DD66; Wed, 4 Dec 2024 16:41:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733330464; cv=none; b=RQv3ZvKW5jN6PgT8PZHSZTUIW2UKE6i76T+Wpv9un5H+3ZRzZFxTiSjQu7rzfVPodiAmp8IEQuZfAf4r7bxdbhZokmntD/92CqTmnR3LZj0TG9/r2B7Jhi0V1/FnqIbWQPcP9iZAUKHOsdsaQcGSQ/1OLtp+Njrrpei9nJuAngM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733330464; c=relaxed/simple; bh=jqv6quzS+t5dQGxDInZsb8SJ7DLV2oz6qpzinEOXBKY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=uRYcuyjYk3bnLpd0Qy3AARs1FU9eqaSidzeKa8toXGuVdIH1hNHsHyrnBCRi3sUG1/A00nlK5qQCea+4SSXvykcsh9TWjuTDqKumO5tasoZok/AZpcOCWJwOUOuI4URllna3jn97lvJ2RnXgmaUZCS5lzboe/ccrSAv6OBIv0Ps= 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.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-ej1-f51.google.com with SMTP id a640c23a62f3a-aa51b8c5f4dso985660366b.2; Wed, 04 Dec 2024 08:41:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733330461; x=1733935261; 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=QNlLMLrY7ZdfreOo5yiUeo8bDc7WwerZARy2ex9nAhs=; b=bkRbXrovMTnhDo/ugZG4ClIjmCRHm11WpB3GU6KSVsqq7SE+Zc8ZyQxorGpy6Bvy72 Ha8ahAMSc2+zCSBIt51U1hNxmsppVptx+Jctws1HKUVZhveRQPE+2v1cLFLWibwT7p13 zUAPHL6A+vdU1zp3gQvXrzeGMMFcFnr29pg7d3WnIT0pKkHJkHvbsq+KZuXuvHKC7m9s 1PaLNhAqkGCf9ZdbTcLONothutuRwKdn8YXX25XzreShjNChvGP1HIV86LwczKHkK+pg eaoDJLaHjognc1JNNZWuSQXTWRhn0MFjjlTBtr/D6fBzfev2q672K7GBnYfoN6zpJZiB WrLw== X-Forwarded-Encrypted: i=1; AJvYcCVAb3tdN6pWUFc2CPjhCigXErDVIlD+Hkzr6nLbgFFfnnKlw8+leBnsb4u2G3virk4EswbGNUD2WtCFeR4VNV2K@vger.kernel.org, AJvYcCWXJwYQWhtH+wAmMGK6sK5STVov9WgZ/V4HzbxBkuJ51rN/mW2n8pzJJAc+qdLXOxKBOuszZvGPHgcAwGQ=@vger.kernel.org X-Gm-Message-State: AOJu0Ywba8Z6/9sdeq2PF0AcLZbx7Wz3iljUNHgL80EA0PIxofOrGnGH 4t3MkGTF5OfwoSfjAOQ0I5QQ9TIBIOO72H4xdCsAmkRrwbH4ibd0 X-Gm-Gg: ASbGnctwoo5FkdU0dOzZwJJyesGSGwoWf7+YDxsl4PsfUj9lko1lhmmHI282Xu+GyUM T8IHc1689QAFJ5hlc6Tx61Cbfp9GSSjnByOo/T82bzlDgpS/mKHb3aEidiuUUUHNqMX7Q36YAj1 eQ2SsKpEELg6S2zRm2lEO3E9rBu/QRo1y1BextP9iuk30IyvVqQlnYVYVyxZAAudQxdFgSduukv R8EqeTPYY9LEW88P7CJcDMLxM+deqYysI7TWXXr8BqQ7pPWXy/DcxtXSBtSGxpiOzxnm8LF1hK/ fA== X-Google-Smtp-Source: AGHT+IEO+OSlAxFAqaLTZCaUND+HFxd0UiHFbMhHTVi6kYxV4hCnTX5VZ8sCvvsqwWXQwsacUtVsBw== X-Received: by 2002:a17:906:32c2:b0:aa5:4982:abca with SMTP id a640c23a62f3a-aa5f7dbd8dcmr588139666b.25.1733330460604; Wed, 04 Dec 2024 08:41:00 -0800 (PST) Received: from localhost (fwdproxy-lla-008.fbsv.net. [2a03:2880:30ff:8::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa5997d40e9sm747153866b.78.2024.12.04.08.40.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Dec 2024 08:41:00 -0800 (PST) From: Breno Leitao Date: Wed, 04 Dec 2024 08:40:44 -0800 Subject: [PATCH net-next 3/4] netconsole: selftest: Delete all userdata keys Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241204-netcons_overflow_test-v1-3-a85a8d0ace21@debian.org> References: <20241204-netcons_overflow_test-v1-0-a85a8d0ace21@debian.org> In-Reply-To: <20241204-netcons_overflow_test-v1-0-a85a8d0ace21@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 X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2024; i=leitao@debian.org; h=from:subject:message-id; bh=jqv6quzS+t5dQGxDInZsb8SJ7DLV2oz6qpzinEOXBKY=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBnUIYVQbbOwSTL+EokYvsUJewtdhNm5vfM+05aL juXhZhi2LyJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCZ1CGFQAKCRA1o5Of/Hh3 bXMHD/9i8eqprJvV+FyTNZH6qA5YEBuyMCrkciPrwsrYHPIrwNg3fXG/Rbses8i1Wf0ZZ1AR5s/ /M4M/rF8pGGpQti8DdoLujQKpr2W3fiv/jM/zz29AUZQUS7tv0O9rpq6R2yj5IwgCv9/j48Vgvx Z/JhZ8/1SZm2ZWVa2gEXV/qP1Bcf8Nbi1v2cnFwuoCdGKBSxQEcdBG/QznCYi6/Q7nZoxu6lXqV f1yHMoOKzTiodybFdTp82PQOEXeB6Ea84NeHhrvgcZTS86fjEUUQ4RvRaz2QXGXLCIvUelvFA13 p0gW88WDpFkuezWI4jxwIsFKpxthYfd8GePvpmFCTjCmPmW9/w8UQ541IvbEYX23TNAiV3SFXbK v4j76Y6i8uzwnBKVWY6u/O6cTa+rdDSd9Zb01MEnylGp3aQd1hVtUdgJXLbJkPUKpArw1IEXKuu 4bypGCh3Tsu9HuVVK0c/nfCQAeqRoRKqMXRcQAvAq3ZcUjjOVd2eMTz14+E4G8ZFp+CulJ64k4u n5qhtZFj9XiJo1Y8uu1GYKJ/1UARW7seHtrg8ZIBVjB3XJHawYU8w1T1/MbNJwISiXPnpeFVgrO 6B20I5ff0j7baVKWDmg8FNutF8Jpd5e0KxxiUJqdyufFXWxCjszsMSe+qLFiw+VnnuAgX+rMso4 0HjnAsH7jxkFvSA== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D 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 Dec 4 16:40:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 847471 Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) (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 ED91020D508; Wed, 4 Dec 2024 16:41:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733330466; cv=none; b=pBwZGrZl5aBhkuR4OXpEI0RdgQBYJTnOOG2fh6CYqNrDuy7IqR5Yj5IFAYVb95tUoPn+efocdYmlm7fiC7GERbB5yShDj0560pueDwiuc1rHKKKaGPzhpbw9VCnfhGglwiXPuK8o7Rt4Vo+CMxffvWQoQxUKvr1+XKV4AxNltmM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733330466; c=relaxed/simple; bh=YomcDZLsGkHJ93XYiHcO82QDo1w9Pr3neNOGqdenPeA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=aAC/qx6hqoA7pEAx/sCw4cosuyhadaUhZ7wz4GeBthlW2Y9BLx5iwh4f96iM0GTD4hTc/Fk97m1MSQYwUK4dLugS9cOVYi0Fu5qOvcZXH4xYtdsNGji5IY3MyJQN8Sa+BVEmXMWmCtd1v67rBzqNBF/tGtqEWc9aUDKR5ZeeUaE= 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.54 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-f54.google.com with SMTP id a640c23a62f3a-aa55da18f89so1044166566b.0; Wed, 04 Dec 2024 08:41:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733330462; x=1733935262; 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=cp5LZ1kxAlRspYk7ziqigDfPMTtHysD3G76P4O98mfc=; b=PCg2it7Dy+DB+dUV3p/njBpA4e/D3QDvI+2anX49f44whHDsrPGwNrzbo4gUhwZf9Q gvRltYJvX7zGEzpSRQsQ9r7cF7EvHHHcQJgqJng3q2/5OxP04hhEvznNg5maIpgP8qyK EpBwxPdTUBqZrZ1vtwm2/PXu5wj+0ZnE8fj6Ukij0Pan8KzVuTo+vE95rsLOBwsdZv6E 9ezBGbIB8bEDXS805oTLj89OtVtOR2mpFoYbyC+PYkXwi8YF7kzE2B6K8gWzH56QaFh/ 1SoWnNx7hLFbahT74tRivPlmdKiDO/dyzHVadoRQ6fHqMPPgeUvafxpC1Jacv9vFDNcV 6aTQ== X-Forwarded-Encrypted: i=1; AJvYcCUKtaGkjHvq1uEOi1X8kjCamcFd+ZS3SAKoh8bX83Fp1OvQDwSZqaxaZn8inWM7FTYn0Ta589nEW4wrcXmxRvEe@vger.kernel.org, AJvYcCViXz/fMTtCLi7q+MKOVMQBu32gPE2f50/Umya6LRkAGvsHESo8gCumwm5vzitDaFLqTYfdtcJrtlkJyEk=@vger.kernel.org X-Gm-Message-State: AOJu0Yz/CJJUkLgqqfnmx7BZ1sTgh3v64AZWLbK5v2UZlIEeKOkOmw+w 7U+TPvxjf1RbYAX38/D+8LiGkp0ThTHXmA2lgPoH0zQU0UYtS16j X-Gm-Gg: ASbGncv8Aqf1mY1UCxn4FjgzLq7HvcT49n4cdtle/BewoXMy4eEArst3mV893eZVilO jpmWsoStmWaMsQzbWhpVPSY9TbZRI3egW7VfOGiU34IkFddrpymuK9ZKBiIk5k15ByLeGXNYvCQ 76zRl9WGJl1JX/2IiUdiU7c4oExjd0V9txaKjCIUlxIjHPwpON6I71MBwTltl3LN+0GI3550v0n RD1dBUA39K3IIWAtS4uvHTrQ1hm2T2qzvjwUDYDU7C8V7DyLBxRvd+85J37LCSprw1yi5jnWQjh lQ== X-Google-Smtp-Source: AGHT+IHO0yNu3MoObM3YmZd7Bqm+/kY4WR82IcRqXNzewqckpka6AEx2/xT8dMOgvIORsma2yOwlbg== X-Received: by 2002:a17:906:cc9:b0:a99:e939:d69e with SMTP id a640c23a62f3a-aa5f7f35a67mr507569266b.51.1733330462155; Wed, 04 Dec 2024 08:41:02 -0800 (PST) Received: from localhost (fwdproxy-lla-001.fbsv.net. [2a03:2880:30ff:1::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa5998e6a1asm750102766b.98.2024.12.04.08.41.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Dec 2024 08:41:01 -0800 (PST) From: Breno Leitao Date: Wed, 04 Dec 2024 08:40:45 -0800 Subject: [PATCH net-next 4/4] netconsole: selftest: verify userdata entry limit Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241204-netcons_overflow_test-v1-4-a85a8d0ace21@debian.org> References: <20241204-netcons_overflow_test-v1-0-a85a8d0ace21@debian.org> In-Reply-To: <20241204-netcons_overflow_test-v1-0-a85a8d0ace21@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 X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3502; i=leitao@debian.org; h=from:subject:message-id; bh=YomcDZLsGkHJ93XYiHcO82QDo1w9Pr3neNOGqdenPeA=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBnUIYVHQTBNZj7dFIHe4XblV2VV/QByfF5NQGkt ioydQXukr6JAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCZ1CGFQAKCRA1o5Of/Hh3 bXPUEACn4DPPvEGE3XTGBPu/ibwdBM9YYUMy4lUVQ76eZv7QVfrRDLG7AbwUbLHhndQVsvqoPG8 bmykl0uRhspf0MNB+ugX9BfaQM8BvVnAxGhj/DbFvYdxs+gVAdJfujiXEG7axVPhsN4maoOsijw Vu51P9JfcO2jp84IO2Oj3noIqJQ9dzIXPQYHo9mBqZqzm+tRdUOF6yCVz7ZxRGerasSnpvMszML O6qCCQOXjlKd3ZxqtnuF1wbmvfMFizzAqX5ITp7/ZSMAuyua3AZ9GTjw3TLhEzlAzRhsdEH8Eni mIbqLz+aRCP5proEVnkc1AlHLZhr1ZLpEgLuguwEg67jdjpaq/U8ALZvpt+b1b5E9is6ck/YYI1 arL9sEeLn/xZdwOk8c9/NlZDbkjKJ7UCnvydjgOtQhvqtlq++ToEgfWkgRsQ01LhmKmX9NQTJEC 0eJ+zV1CU6tDSXTzJm8qtYnbbaW5UbsEnZYirIx6glEdGsECFP3PCU0fms0CsbHwecHFF4HzUU9 ceR05gJsUk0KFSiMuAPW2EyFxeM5ilQS2HBqguiAVR1C8Z9GiQIRUmjaL83gDIjukGWG4oPy8YB ZGv5ODoPSQj2qRxvhYVRu1k2/lpxvMk30b7pvin2nViDOE8yTPtsHSHendgFLDiykYQXSodG1TP aFbCj1R8O7Xpv5w== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D 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 +- .../selftests/drivers/net/netcons_overflow.sh | 67 ++++++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/MAINTAINERS b/MAINTAINERS index 8af5c9a28e68c4b6a785e2e6b82db20b3cf59822..62192db4641a4056d1eab911f5c141fb37eaed36 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -16092,7 +16092,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/netcons_overflow.sh b/tools/testing/selftests/drivers/net/netcons_overflow.sh new file mode 100755 index 0000000000000000000000000000000000000000..a19f613553578dc185b7332a827463d9b0c6685f --- /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}"