From patchwork Fri Jan 3 12:57:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13925548 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) (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 D20771FA163; Fri, 3 Jan 2025 12:58:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735909098; cv=none; b=h7VZFD+Jn6p4qNqdyUfXuAiYmtS+YcQFU2lEIcl3msaixwRvbMSarWs+2HMkvXUCydNGcoRsWMiZTCET0F1d+Uny9jLCkHGROk0G7gz0t+g+oIf8ui8kD87Myxd2VIcgWFi5sbGsFzkHv4LhcHIRs1GI03u2BQojdbnSUDSoDR4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735909098; c=relaxed/simple; bh=b0dr5T0QwnIxuuEvkRyv8EVkHvyXW4ldpeHd7C+rkBU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=i5rosYV7ima81m9G9t4rb6AaUui7kE9nkRVdZl2UtBynyLpFC44hjYpp0CzMoNI4xYoG8Tz80bs2ENrY1W6IBSlfQ2jMGEQH9855fvai3DwweWSdPq/Xwr2jbzqHTUB96h6aiwsmmNu+ao/XOYLW3QbNZVO6FOGlZ5y8Vk0RCLA= 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.47 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-f47.google.com with SMTP id a640c23a62f3a-aa684b6d9c7so2019028666b.2; Fri, 03 Jan 2025 04:58:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735909095; x=1736513895; 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=dzmOjDO+rhB++nFsudhTqlNsWDXjmtQeAoTOpJoHSggBb3FMA3aAuZt0p4ejJZTatM 2Hb8yXaNIBiXln2KB31o6IDO1WjdAacg/J+j1jaTUvFGh7zgj9Hktlez129kzwJpW5lF kvxTYwp0jWHTDL2KE5FVYZqoX1egjQJG8h4v/4hZFxsiN8hcpHcUkgoeS1RiCAuuK86h SJDL9LTyxCPgdPCTYxuk5iZBqt935QWlxRRMdyC4By30LSs9wqxRmlLmLi0Gfh/RlXYC IMh+nCAuow1c24RIqUK2Fq6LkjwZJtLvVM1vSUd6zyXIhaUL2zfdwOMh1Opx3aiIoGNR Q8tQ== X-Forwarded-Encrypted: i=1; AJvYcCUbMKL/d7X7Yf+yX+W04OGyz1Bo5YKcsYXTm3l/0Z4p2m0LxhtAOYM6E3r7GwFvAfKja59e0VsQtr+qtRnqPcbH@vger.kernel.org, AJvYcCW8zmn1aDvLZaR2kK+CIa+LFiXw4/CMSBPolUxsR41CNoZFAocj2N3ydZ+FCjuJnEAisxbisOU5Gr5wA/o=@vger.kernel.org X-Gm-Message-State: AOJu0YyalVBqrkfNH4i3y9269XKMdEiNHk1kIRtxszfQS40mM7OTHmbf adEtoquBkV4kd2KJHnkloZvWmbU23H37rOBnWg2NqJizUhWKtudTgImhIw== X-Gm-Gg: ASbGnctZedr6tEZEKZC0doZN3mQHEo3qj0Mw9QKGOI1+Zfnvhd+MlY8S7THOtqh2Ary Ee8gU+MH62LRjwBwI8rhphYoQRBxZeB8UIUrpHLbP37xRxotiqD18qoxNaATtzzQJ4wihwgGcd2 mjJw6zq2hCE1kE0aqYAtAPvFzlsKEi26Z1gIYlisTiHXaDcqho6WvhizNbsAwyfVxb/G+rCy0k3 ZlakrhuJ/8I/T/vqvpyxSYrDHVuBCOsDgyYfaA1h/Fv5IQ= X-Google-Smtp-Source: AGHT+IH91eUxxXQCMUe9oLi8Kk8U0ragcVDdmvo3IT+p+2LBh3LFLA6cGHMLOlViOzICb41aV5TmQw== X-Received: by 2002:a17:907:78b:b0:aa6:af66:7c89 with SMTP id a640c23a62f3a-aac271333f8mr4365926666b.5.1735909094697; Fri, 03 Jan 2025 04:58:14 -0800 (PST) Received: from localhost ([2a03:2880:30ff:1::]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aac0e892bb7sm1877853866b.43.2025.01.03.04.58.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jan 2025 04:58:13 -0800 (PST) From: Breno Leitao Date: Fri, 03 Jan 2025 04:57:49 -0800 Subject: [PATCH net-next v2 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: <20250103-netcons_overflow_test-v2-1-a49f9be64c21@debian.org> References: <20250103-netcons_overflow_test-v2-0-a49f9be64c21@debian.org> In-Reply-To: <20250103-netcons_overflow_test-v2-0-a49f9be64c21@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/8eHdtAcsmYgBnd97h0oK6txn7150mY+xpPpjWtT/19xVuCeDf5 hPYTsWhr4SJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCZ3fe4QAKCRA1o5Of/Hh3 balwEACkqgwD3O98j2HBmmstJth3Kr5KTiJem1x69v4KRHVWgJ/7dPLIPxJxzeP50AmsO3maV1M kZyB0HVVvJm+6MfddFu+CwbqZ+Y+wPkam/bZs7HcJpWzlvv5hRp8Dpswg+QhxWyJfYY0ea1EgLf y0tT8wzyLsgd9Hi6EUcjhA7yyiiLSQcJ/AeJtdyiw466yrmrS22msMqi01ksOwhpT4oMaqHxF9q wIwkI6FDCdd+Tpvkxh9KAtKg2f0WWo3H9SQVN1juJvxE/nhmyDlydQmQtdYE8x3a81yWk5nsG+y JJ1bJFtTbbhcJn3LAu9dSpqSnYGFaSP0sYdXNxvDAf/ZEfIXNijPdpiGdXYrlfjdcIbHibR9wPu w58gHxI/vk7PDnUltTRelm/8lnKNRu8TSmf32vZFrJBO8PGHg1SoN6HLeTA0k0HC32JJkqReuwI ZZeWlZ1LxKzuT3KTSzhn7P/JuNhSJii+hhrbDeG4/f9pONHqwAa+kMOxjSm38wAELT+Sm1V+uVm OUMlsxH61QhCAl6jfAUVOXp3yTLPWqrW+Vmdq32z1pFSnvVtTmoXKqwudz7FPe43n/VsFYkmP+x uFS8pDNWLtt+g3nU714B4ISuenuj7Y20QeQitdDmOHZGDKsJvndBlh7iLXxKzoekYFWJliXp0nF BVsxbeqmIqqhaAw== 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 Fri Jan 3 12:57:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13925549 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.50]) (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 DB8691FA851; Fri, 3 Jan 2025 12:58:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735909101; cv=none; b=n6uZ3fFx7JUZ9Rlls/U6V2aVaQlDi1TSdk+4PQvCtTKzJKsEgrp+JMn5UDBk3nN0qbsFzv6aLItG6aZevtOU1uYqDJfWFJkADaGnooqOgtztYIU8Pj90U0gIWsSBaRN4P7Df5mAXveYx6/2ompxsOG6e7d0esQKvq49KRjPkS8Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735909101; c=relaxed/simple; bh=R5xlwxCKn/F7IvCMwgHk7EyMF3VZxWWE6+/IKLQCU+I=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RRCOcBU+sE4rDdxoaFSS/UJdAZ2QViTXypgJgOOcsoI5jv9tPySlvjHhAzbOmm9G7e9fyqVp06Sd7e5CU0HhUNUUOwzopD6LAXYcNdpPG+VrTqie6XZwzoBGgbF1kvZdIqwrxSU2wrlAyXwwPPrvpOeM6o2OtSuBvsZjmsIblPY= 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.50 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-f50.google.com with SMTP id 4fb4d7f45d1cf-5d3e829ff44so24470920a12.0; Fri, 03 Jan 2025 04:58:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735909097; x=1736513897; 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=PLR1sIMsxgbYbIJKRO+GpBe/DPp2Ji7L8BTReXkxRVw=; b=OqHZUYOQUVm6qIol9OwcOswMeUhdz4SRjkBh99SVHNWBtyRgzu4/BxVnCTqkcKNr65 Xj/2GbJwi4/3FqHfzsiVx7/K6HlI1NhLAKnre2FGwAn0cTJQ327HW5W9+AhPZzqgCQ30 6UEjsP49q1dySbbOWhdOOzJlzXfI8OCx+5AiO+XZJ37UeQOCIPY10IXMK3nhSh9tZBm8 /PdwGIw05cazY96uxtHB+VUor7k7swxyWOivpvoy5jC6rwTf7sSmve59hVMbsWw2+x1A OkIYpdt9ARsH/OUJUienxuU5z8hX4dMUeJlOKxN+4FuNcLVLhNad6C2e8WDEp2nC+BVM O2CA== X-Forwarded-Encrypted: i=1; AJvYcCURpMtxaVXBFSz+0BFQnuhQdqBTwWHXhw638cJ1GhO9AYrQ8UBVeEg5XTeMdb7tTZ/Zbwr9PtM7c+Mqsu7Lvgrj@vger.kernel.org, AJvYcCUlHEHXbWLwlCIav/cMjitlVxJ0tKdpH3f5bll6D6OgPgoT/jZcH6vafo/HovSQNVLENkEcIBjjSAL8XdA=@vger.kernel.org X-Gm-Message-State: AOJu0Ywcd6E5cK/3MM2DzPGfChxotBRm+A5LDvDR1RQY+uXrO7io021j uafNVRo9pvqhlx95H6rVXXUCKA+8PtcYoPcoKxjGggUBz/AVR970MAIHQw== X-Gm-Gg: ASbGnctZ3CRnadPbvETTSrp8YFNrPSzTE9o5eG6mkqRiDZVC3c8mzmkmIQtubMPob5Z Vi/18TH94fn04VjELWqTYEtff8dK0XokO1HjkwiT2e6FrjPcDK5wnG9Bv+JT5M1kMb05tHQNkT7 ylvFm1RC9KRSGecOpPJln+0jcAKEkaNs3mGI9xBb6OzUBESDc0FkeCvt8IQbmkRCG6wolPqel40 7kD34pTDpO9dn202XMMt8PdY+c6HdRm8/BfGs7DKiDUPsFe X-Google-Smtp-Source: AGHT+IGJU4zYDJQGt0B7+v5OT2o3D+Y2ur5Bw4LoaWM/yDOqjZLZDCe/Oyv2BQKwR06y+CCILXuaag== X-Received: by 2002:a17:907:1b83:b0:aae:cf50:5605 with SMTP id a640c23a62f3a-aaecf50562bmr2618581366b.19.1735909096474; Fri, 03 Jan 2025 04:58:16 -0800 (PST) Received: from localhost ([2a03:2880:30ff:71::]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aaf5d43429bsm558892966b.154.2025.01.03.04.58.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jan 2025 04:58:15 -0800 (PST) From: Breno Leitao Date: Fri, 03 Jan 2025 04:57:50 -0800 Subject: [PATCH net-next v2 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: <20250103-netcons_overflow_test-v2-2-a49f9be64c21@debian.org> References: <20250103-netcons_overflow_test-v2-0-a49f9be64c21@debian.org> In-Reply-To: <20250103-netcons_overflow_test-v2-0-a49f9be64c21@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=15115; i=leitao@debian.org; h=from:subject:message-id; bh=R5xlwxCKn/F7IvCMwgHk7EyMF3VZxWWE6+/IKLQCU+I=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBnd97hjJ5rpunrmtlVexvs69Tvrf1JS7L58TF3m oHm++vwtuOJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCZ3fe4QAKCRA1o5Of/Hh3 bT68EACMeU2MmijIoJindvROAW+UYlTIlG5KNp2uselXg9kMlx2TiCh9m3/Rv2t+bzT/THUYKSi p7m+EHRRVWZYSGeCpe/1epmerXExWVPH1sFOSwRMAWjIBJZsVIYKNFHNxv5lj6SpS6WL9CKGyAm 3VpquhT8jeaTg1z0xhgzHLUaPAPy28Zlita3teEjZVZU0JN8CFv8VmWJCohbj4UX1WtmgDpAqfQ VTKO6XCv/B27oKBQjQigf6t78a4AL+CSrlZECrqvJj2HMMhOjv2fGDNX21icZ6uIkEou6gI8Pc3 zgB+psK0hS/gQPziJzwsvb+BxNwViAV9zidwvam2045Wa3r752PL/F+sXLntCxWc5mUkeVNlc2c inTT7GckoxDZItnTGh/TJH/A/RpZCEx3FCYFs3pChJ2pSfZ2uVx8r5pl9QzmusV06pcDP8wxcNr G9g+eVsjL9ebiqzdaAPNR0ewcZQwRm3WTt+/8bUZ+w+stZuYsDquzQRn7vAeyl5OLntKo+qF0iy 6dqJnkedtD7zIAbHy4LFRtjKkvjqwja4aQ4n2B61wojqzN768n3LkoPPJUTriIceJxsek6m6uk2 xmKdhjWsoJpSTiGBTWdUVlmTaKI91205fzvJqpl7u8J4p3I0WWTeKzQLYx3wzrA/4uTOMX9WwtO a2xERpOQ1cPwgRQ== 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 + .../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 1579124ef426b8f2e066462e90e6c8e4d068f01e..d7af1c38dbab0c1ac253ced11a07ee7422c75c0a 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/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 Fri Jan 3 12:57:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13925550 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.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 26A671FA8D4; Fri, 3 Jan 2025 12:58:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735909101; cv=none; b=nExvKNLLRwqgf2ZVaQF1ofaV7D+Pci5jDNyRaA+oVEZ+PqPBN9uSzyxbuOi3EAi4/aVNJbLewyz3Z3TnAdyvv0t0343mL/o7+Ywh/VBqrnfNDnJK048MSwm7L8yQ5x8hj+BVqccGw7Vv1ZpOg12MKh9byINxlPWLDYqtIcA+Swo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735909101; c=relaxed/simple; bh=5NsZyre7dhB8gjVJrgCTRYi8hSfLC+Af6awHSBnzZaA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hKI1sNpUsStByrnVgCYvgwWxf27gFGrVp/KfMwoez2c2c2jq3plpKv57w92K7FYUSc1XpBDnU56RLDqqvTr016yCLqkuHRcNCLoKzE7DUlPMjbQOZjwJinlSgdN/BKfZ8eczi0PDWfi+HQczPR84h1HXYhrMY3Sh7ovsE5CW1yU= 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.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-ej1-f43.google.com with SMTP id a640c23a62f3a-aa692211331so2320720266b.1; Fri, 03 Jan 2025 04:58:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735909098; x=1736513898; 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=Nhp1xELfJh56Qcc2quI6Pter2a2oH5DvVngXlJRevE3VdnvsoEHF9RPk2Rgw1jPtOy uF2mx5d+YR+DcqyBd6CUGHAYGMF1KELCsjP0FZHX6zGL1mA2CYAp9W8j3GUIqkW9wlGQ 5zoN8sm+kpGVW21JdGIIOjqjtZnCqJ2H0WoR/seMFk+cK9Wa4Vz8ZKJcPLligeOKGinX a9xGIY6V/rmpjIy/EMRShMuvfNsPw5mkT86CkqipMjy7ESzDpxGsST7oVG5ImlQfMWY1 W4Jm184Ma32bsg2sp1qOvX+wa2qb7pkVVGThEv10k0M3Fh7f5tz4JbKdTniwyu4I9T8k XCXA== X-Forwarded-Encrypted: i=1; AJvYcCWvCpmX2G+VWhCdIncHUASQUnUBpMbpy2UVtj+Q0FjfYEPUUQZzWmUWhe3hdGaam2ndw5PREhQfO3X8HCjbclRt@vger.kernel.org, AJvYcCXIHacz/P9zet/29OgW8l2ySI17uDJO6L/X+uN5t6P121lIe+bqEnYeaxL5z0qnr/q8W8tQ/vbbRdofMbA=@vger.kernel.org X-Gm-Message-State: AOJu0YxZhxF1uT7Z1Rrqv/+LHDo3DRBmSfMWkMq1yO8K2JHKveMgX8dN l04SmGLeQYwiIkv3DkfWwFjHM66UTIskbzBRDpnZbg+NqNopBmiziCfgDw== X-Gm-Gg: ASbGncsSSiUqOfZ7BhDFtw2rl7viOOilVF8qYO58Rpu4IZccHP2cpOHtLE37+VVKpRp kB4iAOCIwYm9pbPxYukmrogIkBuv0zKWiTxE9cPeFoaOc6RXiUyOf20OKj7/bGy6Ae4NKwH1KdK tR0koPYKsZV76TDbEUgqOe6Zo2msNj6L8F176bkCSK0Ft0587RcvLOnF3Vfo+Ev3MKMN5jFpvpT 6y8eV58Zcr3E9pIZUZOdLTHjQt+y6EYNstTc2vJ36SfijQ= X-Google-Smtp-Source: AGHT+IFJ6D8KKTsgrukGXKDcZyE8XBTNBKUwAzN0zbi4EAAGVn3A9rYz94VL4XVi3YLoZqJJdFnOaQ== X-Received: by 2002:a17:907:704:b0:aa6:489e:5848 with SMTP id a640c23a62f3a-aac34695112mr4164882366b.25.1735909098064; Fri, 03 Jan 2025 04:58:18 -0800 (PST) Received: from localhost ([2a03:2880:30ff:2::]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aac0efe467esm1901792566b.104.2025.01.03.04.58.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jan 2025 04:58:17 -0800 (PST) From: Breno Leitao Date: Fri, 03 Jan 2025 04:57:51 -0800 Subject: [PATCH net-next v2 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: <20250103-netcons_overflow_test-v2-3-a49f9be64c21@debian.org> References: <20250103-netcons_overflow_test-v2-0-a49f9be64c21@debian.org> In-Reply-To: <20250103-netcons_overflow_test-v2-0-a49f9be64c21@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/8eHdtAcsmYgBnd97hSoHFpgMkhs2gqTnuIeSSZtPnMI6iWEr+j H5Ju1V/2A2JAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCZ3fe4QAKCRA1o5Of/Hh3 bSS4D/wJDpmGn8v61/rtYEhTniWGnI4IiuQcZpgIV4jM/OqbuUsaxjBHRtK6Wt/aDVkT6ab84dI encvdRyMFgDoKGv07nmz3Vts3gozj/f0q8SNk6kyn163zWYtAjFyRu2/3G1ec995FwE5D0I0Fin i7R4gNUGOszzjRfNE9Fdrc4ErL/L7FRglieuN7z6cJEHMxjLyzmLHJ6SxMdvXuCayJee4D4RWlE eQJxjpUfhtbMQSUq3J/uSfpzIzxiQFiUs/EjOVxlIyYPxGv6J47qclYA6DRqDtG+Jsr1Y0yLT6Y nVmfhEwJOwQfTVu8W/jNq/niVXimVrsOGjLH24cgS9rZb6ephygfnpdhhXEt0i7PgeqDPghClWi lP+n92n89jjEbuj8VIyNvhoGe5WUuVl5GNrVgKCvUbxbOIZlJxfzMh3qyox2XQkGhoeffN1IA2d A7k/4bu9LhS+vx3dopKI+B1NPnMS30iD8OpnnLfwQCCxOlyA0yVr0SD2RrrZlcTXW5y1mo6hREK l6b5NBQPKm4MWRjq7/Jr7xBLeqD3vf1lCFFDCkkSC4PcYO4jsQpfLVxomUNsEB42Gp6Y7NXutel IZwww++xbZFYo71am4o8QS8PqzZUekJE/3PArK2vsgP891/7VOn32IB9vxGcn7GDj3HkmUmQJHf pIeZnk3wpHTc/qw== 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 Fri Jan 3 12:57:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13925551 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) (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 BC65D1FAC31; Fri, 3 Jan 2025 12:58:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735909104; cv=none; b=ueqRNNmYp6OfujN+y0xXXFMKopkIVWuNffsW7f2XVMiW9+md/1jhhuvlHB1PZ0Zmb48HYlKXhZf1qV3ETIzLJQeT5qlVQwgaH390+LC0oeyHtk3MMiTtekgUnqlfrXtYeXankU8fSbCJs0xMsN0dUBgERS62yVKv7Z/vWvqcpVM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735909104; c=relaxed/simple; bh=j/d6IOIwcGaC9OHqLPuTe4vySvBHGxjJ9d3+kMRZ3vY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pU2lhsAtFqtn+FEeCb9MYco6uUpTayh9thdsQIu1Q4oT3oXl18JV2wiEuS5+zDPBCvkWJnVj1aKd6JBnNFwbTneeRG3FV8TOQe3AIgjHZxUdSSCsJif9Vrz0u6y74NEafuJ+i5nMMCmzzXfaj27QOuCWAV+jDejlgRnPETUbnCA= 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.42 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-f42.google.com with SMTP id 4fb4d7f45d1cf-5d3bbb0f09dso21117659a12.2; Fri, 03 Jan 2025 04:58:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735909101; x=1736513901; 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=ribTIMB9+dNnZKye+MGNDF+gCDhKrbL3cAGiX1697uw=; b=wfRywaTEYnFE4DwoFFDl2JcE2RCFk1zxKZNGBAypk2bUzniTnbyJHY7FPtWGDMB9uK Kv3QD7e3hhNvTHmsRab8CEbBaasYMxQWHbmVYElscP56PU5bnJXQGF/XKPrie/DdzKIB y/G8uPBJITPAQSTxx3/mjf5J5A7c+jxURiyAbg3Nv6WTuWL8QysfEMqxlW0KQi+q5A33 U7XO5jJV1cPbVxgTDBejvCE7j4rqaPRsWJuW1Im7Eh9spLY/sBOTEjX5n56oadYCcy98 QSHam3LzaE7yxtQEI2Ky7g3msOjrw8tqTB/9bcmCH/NW2UfQCfLnlfc8e1XeOhnvMSwb Yp5w== X-Forwarded-Encrypted: i=1; AJvYcCV9IN8IvJ7fTFeNkNGVXfMvKnnBAaW8CdThe3EEzcoTG3dUviQh26hlyf3/s/6hQFZEcvP3IcPttL3SQkk=@vger.kernel.org, AJvYcCXQ5OEMoq38FbNBSVroQ7kGdy1Wn1+5zK18KY7FN364TcSKf+8XAfH4DLuQgP48MXXsrbX1AwoaAq3wy8Y2ylWx@vger.kernel.org X-Gm-Message-State: AOJu0Yw3jVv3cSNpr+FmVKKkCwiqV9dCgOFLQNEUzlkffD6UXLOLJor+ JotgmpwqeNte4f9NdjT48kmwU3CEBDt8ZfC3EG2u4LU19MxYfX7+2sVmlA== X-Gm-Gg: ASbGnctvnjWQyEpYj1bojz0UvrPCvjwzPsAgeiHVSbt1nz5ixZu7Z41KMJOtaR27zQI CTcPO9tBFQn7PUFvaQQE/3R1GLbQjKLnc4T3W2a1urBkSwQsseFfQdNM2ODskSTveR+0RdKUZzh Kat47r7alN/LXo4+QVA3NcBMeR70v8eILZgneDezE5kOOpdrUwuj3tfemFUXdWamTz8b3r+RMSy CTGVtOL2nXXAgPIeNyHba2BeqvVuB3acVrurwp8j3pLcuR7 X-Google-Smtp-Source: AGHT+IGXoOLlnSCol77Ouy97fOE/3hjW4YIr1G6KR5jqHhGzU7NTiyOWkR7lZOs/rQXoz9UMQMB0uA== X-Received: by 2002:a05:6402:40c1:b0:5d0:e3fa:17ca with SMTP id 4fb4d7f45d1cf-5d81ddfdd7fmr41236836a12.15.1735909100493; Fri, 03 Jan 2025 04:58:20 -0800 (PST) Received: from localhost ([2a03:2880:30ff:70::]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d80675a71fsm19364962a12.18.2025.01.03.04.58.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jan 2025 04:58:19 -0800 (PST) From: Breno Leitao Date: Fri, 03 Jan 2025 04:57:52 -0800 Subject: [PATCH net-next v2 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: <20250103-netcons_overflow_test-v2-4-a49f9be64c21@debian.org> References: <20250103-netcons_overflow_test-v2-0-a49f9be64c21@debian.org> In-Reply-To: <20250103-netcons_overflow_test-v2-0-a49f9be64c21@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=j/d6IOIwcGaC9OHqLPuTe4vySvBHGxjJ9d3+kMRZ3vY=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBnd97i1fNFFHR5UlGtanDQc7lY/3RDoJje4pnAo S5mqo9eJzeJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCZ3fe4gAKCRA1o5Of/Hh3 bXKND/9XqnxRlCpX0HH/PJG2BEDc/qCdp6A9dZf258qWwHT8JiFEtM+6iu2pfMdP3i1gR8nhD6A nAhjEXaDEuXiwgmzho9cACEJKa66jx0TTWZMtx3LPULCL2BDPROY+SwH1ale9RM0RkbQD1YNXO3 fRKK+dOtPQ3e49OfoEeAAmrvK2vYpBgehevBC9j5fCv/0yiGIlbQ3z16t1kFONyCq6feVNtlr5n cnwR0nsC4j6enZUdVBJ6H7uR7EKiWCnbuouMqsHBg+gbpyN1m5YuZ6490Jn19Jp5h5jbUYW1uX6 mhHZJijjkhNDGOHjGX3L2uY14LKmQVngkjDRJOoshTiOCNL/GaWRfBmt3DsGDyscNp9V6UJBx4y odPJZgSnJ/v+6iEsdFGjrSFUzQeb9t6BoiU6oeoqmXqxntuG1KFzLeKq7EgllvLT7KNLm94d1ta ShB/51dopG5q9OsDepQNyEF9RjBgkMlAJht06W99x2Ez8cDvTomMncY1ztPwkievzdkjNkR/xrd qiPKdGyZoujb2dqtjb2RKKCGwD43YcpGM1Qnx433O4dj9UI0VojAz4m1TDsRaJIohLKJZdGpVx7 eGPM3I5UTb1JloSqfAlI2iYvQwMcoVBO6C0iMIVBEIngYSCo6vMb5m53EyiF+JHq8UCJFOP2CFh yh1oqtxH54xO4ug== 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 d7af1c38dbab0c1ac253ced11a07ee7422c75c0a..d14bfb5ab0122f0b6651e72add3b178dcf742f18 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 0fec8f9801ad4d94d99ab6d0acaea6e2e7b2894d..bcd630eb072eb9cf22bb11a647de751795de2408 100644 --- a/tools/testing/selftests/drivers/net/Makefile +++ b/tools/testing/selftests/drivers/net/Makefile @@ -6,6 +6,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}"