From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EE074606A31F for ; Sat, 5 Dec 2026 20:54:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=networkplumber-org.20260707.gappssmtp.com header.i=@networkplumber-org.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=E1UHlu41 Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 86BD840DD2; Sat, 5 Dec 2026 21:52:45 +0100 (CET) Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) by mails.dpdk.org (Postfix) with ESMTPS id 1FE19410D0 for ; Sat, 5 Dec 2026 21:52:42 +0100 (CET) Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-cdadf7e248aso1023082a12.3 for ; Sat, 05 Dec 2026 12:52:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20260707.gappssmtp.com; s=20260707; t=1796503960; x=1797108760; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=xJq5GxqsghmXGTUte96o0KN1rFX3EcSI+PXElBWMvA4=; b=E1UHlu41q+68XkwaIEX8b3vOWPQbpQGOnXLMU4vCq/FPG+aaztO/q5pHWuFJVVOO++ PR6NxwygUQIosFTdI194rFFUHJi2+ieF//kEoOEcNxQ0jYL4WkfOcu8RuKoPaU11bOd4 crsASNHlNn/RrMFYRrMkFO6/+gyYT7LgUpHFqZVI0gKA1jUceur1cn/emai94wxJkL4I /dYDbjOlWS9UJlJxy3zbQJEgFIcGpo22FKCezRJB9fhgRUI2/i2SjucWl+JD1eIlqOZ7 0IeBSkSjfdyfZpOvdWSRq78ApKw65pUUA/bbBsXlHuZgdsJQWIXOc7gIFa9vSBaXjEea dBGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796503960; x=1797108760; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=xJq5GxqsghmXGTUte96o0KN1rFX3EcSI+PXElBWMvA4=; b=tMtfun06GhhvFcG1Z4M5CAw61X8YsI1f0Z9Us0Yc3r2DZ5lM2lNjrVl3VWuPK7x3Re uQRfLZu4MdSJmBYztmjYAN2rW3PDPet5uhYmgh+kW4z4M3GWIRkTGuFhGI4ykzvnUV9z OI9Lw6MyQXJoVNNyESVN97r6Roqpq6lFur5GFaABlPxsd0eF7oLgOLo/gS9w9+QKqV5C JmvjEvDsQj73RX0cAr48bYWV5VKeau6VOn+txVE3PPEytSBbY7QXxP+1HGPfoQp10t4l Gfw/yEzlP0vC121uHnd0KsI6SxU/P/WLCDssNMTIIqWCtR8QGaImJb0NsZGy+k3Ckck9 dKNw== X-Gm-Message-State: AB4q+uEM8agEqfvsArlvj+oSgvP5xsmrWo1JLEme7ZlArVRaifQD/cq9 0eR4EcH9cq4h9d73JjfDArUVaNj4nQWVuIYWLaIs5YIB79Y0ayxxUvRhtXVePViLNEtDhfWrDFf FYalRkcQ= X-Gm-Gg: AZFdTZfwgGkvs1aZdox4IkZT033ctmehCuvFwKw1SPi6vyyDk14aZL3FNg0krtU0WOx XcCppcYp7reQ4Wu9BWZuG95ws1lNUwhOdr9lNiIK54lqaEPK3QmbCGWqDAPcjNoAosZ8VEX9z/w Tcg7LzUUZ/xJGoAWnypIwkXMhFGaDIMNfYwYqvvpQsnttzMMi0Ibvnw4sZQw84oAoeNtPVjFewS uqfGfvLvP/6yzPFQFF+rOVqx/HcS289KkART4cOXckFs5xH8skgdgi3Ra+eIfqsai7f3BzaFOHz g5iHLuHk6OKR2E3Q8xWiqCaRxupOkjTuDVNqr/5+1mYcHc8I9Nq8lB675r6lC5CQreJQGVQc5dQ O9hYC2lOwCXoygYNidnHCxvcuv7FlZ8m8Tf2sQel3qTUkp+n3JLvpJ7Ut/EHmLfa5h9lie3ZIrr +Hy7vG+0ZHIIeh9hs8wmmYZI+ULTX3xpxB5P5jte+tb1F2PAhkMFLkCHLc7yac5BxyfprataUOz ayGQ+93026Q3/3A+nonOwTxT/SSt4oh/f+NzgD+mx5qYBKq3gkNojNUU1TsTha+1WfRqaHo6Uzt +yimDwSGFjXNumBh0/KVUPtv4s/T81WnY7nIuYM+LfPYVKgLfS2SET/tlT9+edZSwUHF X-Received: by 2002:a17:90b:5910:b0:3b5:32db:12d with SMTP id 98e67ed59e1d1-3b5e0658b8dmr5643877a91.16.1796503960490; Sat, 05 Dec 2026 12:52:40 -0800 (PST) Received: from phoenix.lan (204-195-112-43.wavecable.com. [204.195.112.43]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b6166c7c72sm2965998a91.3.2026.12.05.12.52.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 12:52:40 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tetsuya Mukawa Subject: [PATCH v5 13/68] net/null: use kvargs numeric helpers Date: Sat, 5 Dec 2026 12:49:44 -0800 Message-ID: <20261205205221.1131118-14-stephen@networkplumber.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261205205221.1131118-1-stephen@networkplumber.org> References: <20260914054912.755403-1-stephen@networkplumber.org> <20261205205221.1131118-1-stephen@networkplumber.org> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Archive: List-Post: List-Help: List-Subscribe: , X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 The three device argument handlers each convert with strtoul() and check neither errno nor the end pointer, so "size=foo" is silently taken as zero and "size=99999999999999999999" as ULONG_MAX truncated to unsigned int. The checks for UINT_MAX that follow only catch the truncated overflow case on a 32 bit build. A zero packet size was accepted, and the value is later cast to the 16 bit mbuf data length, so anything above 65535 was silently truncated. Convert with an explicit 1..UINT16_MAX range instead. The copy and no-rx arguments are booleans, so store them as bool and use rte_kvargs_handle_bool. This also means they now accept the word forms such as "copy=on", not only 0 and 1. While here, set an error code when copy and no-rx are both given. The error was logged but the zero return from the last successful rte_kvargs_process() was returned, so probe reported success without ever creating the device. The booleans use rte_kvargs_process_opt(), so that a bare key with no value enables the option. Signed-off-by: Stephen Hemminger --- doc/guides/nics/null.rst | 2 +- drivers/net/null/rte_eth_null.c | 78 ++++++++++----------------------- 2 files changed, 24 insertions(+), 56 deletions(-) diff --git a/doc/guides/nics/null.rst b/doc/guides/nics/null.rst index c0e3199102..fd8d685d83 100644 --- a/doc/guides/nics/null.rst +++ b/doc/guides/nics/null.rst @@ -30,7 +30,7 @@ Runtime Configuration - ``size`` [optional, default=64 bytes] - Custom packet length value to use.r + Custom packet length value to use, from 1 to 65535. If ``copy`` is enabled, this is the length of copy operation. .. code-block:: console diff --git a/drivers/net/null/rte_eth_null.c b/drivers/net/null/rte_eth_null.c index a2f70fee79..f99f062798 100644 --- a/drivers/net/null/rte_eth_null.c +++ b/drivers/net/null/rte_eth_null.c @@ -3,7 +3,8 @@ * All rights reserved. */ -#include +#include +#include #include #include @@ -19,8 +20,8 @@ #define ETH_NULL_PACKET_NO_RX_ARG "no-rx" static unsigned int default_packet_size = 64; -static unsigned int default_packet_copy; -static unsigned int default_no_rx; +static bool default_packet_copy; +static bool default_no_rx; static const char *valid_arguments[] = { ETH_NULL_PACKET_SIZE_ARG, @@ -45,15 +46,15 @@ struct null_queue { }; struct pmd_options { - unsigned int packet_copy; + bool packet_copy; unsigned int packet_size; - unsigned int no_rx; + bool no_rx; }; struct pmd_internals { unsigned int packet_size; - unsigned int packet_copy; - unsigned int no_rx; + bool packet_copy; + bool no_rx; uint16_t port_id; struct null_queue rx_null_queues[RTE_MAX_QUEUES_PER_PORT]; @@ -606,55 +607,22 @@ eth_dev_null_create(struct rte_vdev_device *dev, struct pmd_options *args) return 0; } -static inline int -get_packet_size_arg(const char *key __rte_unused, - const char *value, void *extra_args) -{ - const char *a = value; - unsigned int *packet_size = extra_args; - - if ((value == NULL) || (extra_args == NULL)) - return -EINVAL; - - *packet_size = (unsigned int)strtoul(a, NULL, 0); - if (*packet_size == UINT_MAX) - return -1; - - return 0; -} - -static inline int -get_packet_copy_arg(const char *key __rte_unused, - const char *value, void *extra_args) -{ - const char *a = value; - unsigned int *packet_copy = extra_args; - - if ((value == NULL) || (extra_args == NULL)) - return -EINVAL; - - *packet_copy = (unsigned int)strtoul(a, NULL, 0); - if (*packet_copy == UINT_MAX) - return -1; - - return 0; -} - +/* Packet size is stored in a 16 bit mbuf data length, and must not be zero. */ static int -get_packet_no_rx_arg(const char *key __rte_unused, +get_packet_size_arg(const char *key __rte_unused, const char *value, void *extra_args) { - const char *a = value; - unsigned int no_rx; + uint64_t packet_size; + int ret; - if (value == NULL || extra_args == NULL) + if (extra_args == NULL) return -EINVAL; - no_rx = (unsigned int)strtoul(a, NULL, 0); - if (no_rx != 0 && no_rx != 1) - return -1; + ret = rte_kvargs_to_uint(value, 1, UINT16_MAX, &packet_size); + if (ret < 0) + return ret; - *(unsigned int *)extra_args = no_rx; + *(unsigned int *)extra_args = packet_size; return 0; } @@ -714,16 +682,15 @@ rte_pmd_null_probe(struct rte_vdev_device *dev) if (ret < 0) goto free_kvlist; - - ret = rte_kvargs_process(kvlist, + ret = rte_kvargs_process_opt(kvlist, ETH_NULL_PACKET_COPY_ARG, - &get_packet_copy_arg, &args.packet_copy); + rte_kvargs_handle_bool, &args.packet_copy); if (ret < 0) goto free_kvlist; - ret = rte_kvargs_process(kvlist, + ret = rte_kvargs_process_opt(kvlist, ETH_NULL_PACKET_NO_RX_ARG, - &get_packet_no_rx_arg, &args.no_rx); + rte_kvargs_handle_bool, &args.no_rx); if (ret < 0) goto free_kvlist; @@ -732,11 +699,12 @@ rte_pmd_null_probe(struct rte_vdev_device *dev) "Both %s and %s arguments at the same time not supported", ETH_NULL_PACKET_COPY_ARG, ETH_NULL_PACKET_NO_RX_ARG); + ret = -EINVAL; goto free_kvlist; } } - PMD_LOG(INFO, "Configure pmd_null: packet size is %d, " + PMD_LOG(INFO, "Configure pmd_null: packet size is %u, " "packet copy is %s", args.packet_size, args.packet_copy ? "enabled" : "disabled"); -- 2.53.0