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 4B6B6606A31F for ; Sat, 5 Dec 2026 20:55:26 +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=IHTnZ9Nw Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 149BF4111B; Sat, 5 Dec 2026 21:52:53 +0100 (CET) Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) by mails.dpdk.org (Postfix) with ESMTPS id EEF2441157 for ; Sat, 5 Dec 2026 21:52:49 +0100 (CET) Received: by mail-pj1-f52.google.com with SMTP id 98e67ed59e1d1-3b567ae3d54so1165602a91.0 for ; Sat, 05 Dec 2026 12:52:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20260707.gappssmtp.com; s=20260707; t=1796503968; x=1797108768; 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=CqAPMSgYqr+0a0IqrflyYXAid6FyYUU1vEtsBi5ICsQ=; b=IHTnZ9NwzSqabl30YFSw7UAFGB98DIMvlRUfWajsW7mAi0tXYVY1KQphNkVKRiRxbk v5UnNAysVclQfGpAa3jE5oL8WEpTIOBUXxgbe/ZzU7+eaUgPrFyBWDV816ZBg2ey1pfV PD3B3GwQKaIEWIYXzrIJbx6Rz8bSn7MI1C6aBj7y9hgS4uvv61uSbUdweEN3tGcTK01M kq+8Q+O/q+Z1DfIZDh5hWHKNnvzjkFqh1WddWEBI4JBqSG+VxkkRGfcjZS7RdXwXgeJe rUHKa3dCj1CnvLf8/jCmS49HWOuL/Gfai/jT3zRUAvtMbI1Ly01s4U9T3x4SAh2CNAt+ 5zIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796503968; x=1797108768; 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=CqAPMSgYqr+0a0IqrflyYXAid6FyYUU1vEtsBi5ICsQ=; b=MPA6Rfea8t1axMbWdIluq9pUye21FHXl6Q35/CdVslUHvcpKGnkJzUgcHDNxNPDgKO z1/naNtbxBnpdaoIYTMux+jILHqNo0Bc5js85+sddppoL+IeR3vsfjYxPVfXGvlEhTiH KH6WT2abI6RsNvCyI/M6CJC/hZ+uiXe33lANq1wG1/2GcaKk5VpUB/sqQNQfTarKGFus 4m3V9HyXnr1khr/wogoAcL99eeaRkmBNyiKXDw8Sf5eI3HN+2p6uD36hybQZWa0ep81y zFZg578Z1fQd/Wv2SfFa82u/zs2hj4kkk0pULrAaK4R4No4hhlvTXuJNwHBNZ8JyJMoC CeIQ== X-Gm-Message-State: AB4q+uENv8VwOrWzqdM9KFIopeXKk5oPjhpNa8hj2O1DzJIOYCur1kpU S1dMbP9VxJIKPbuYQxKg1ZIoiG/Pp5TXqs55LJF6pMX56tFIbdhn2FyvxddMnZEA2s1CXCEatr3 sb6PbqoM= X-Gm-Gg: AZFdTZcwYTVvebbOUL2jJ55N4KyD0DU0XjwM8T1FCSdkFAOP/28oekno417x8RS7mxo KaGuEUclUtKSJhJ9uIKMLKeZhNcFepKGQ0zIAbRJRQAFETGachMtLAPt1LGybiZOyfuv9JfmLqL 0X63CB4f0JYU18IPeycu6F+YlD06zBw24COuMTMvMZYo1NmFRMNaXDnCZoeBe32MvZutB5cIYtI C4lo2p5FSpC8FnGR8+rdUn5twX/vB2+ZHkwJLgqY1Lw1uD4mQ0D9RKNBsH7goC7jt92nxHFgvxi eRrndiKKxqe7/x82FTIYs0yKL+uvQmrPbcBvKLSagmSiDCq9meCT99cbZEpC2BJMdhrVVnaSCgv EdVA8F5JEnYTIW3muuxjmg7QObETOt+h8i78fOjYVyFzy6T1ixA0UaCcazl2k4Q4pkPj9YzQ7+q BhhRq8BiSyyuvB/9IELa60TIJ72jnmcfBShj1EzUB3AJBfhmr3VoVgr9HN11WD2upFRfWCPiOdS Act3tokvTeeQtVYp+KknmvrJNtvqjcIRQ8nan717u0pumg8zUsUNAF5fKfQssjMXy8Dr/Eh4ha8 d43ckUvFfaUqs4ELgz5DFFCAJg+IPA9n3T6bCVBi+nTxY5f4/3ef0EOFrSBq48r/i0DfMqViz3P qjeOj4qG/dsf5uQ== X-Received: by 2002:a17:90b:5287:b0:3b5:32db:11c with SMTP id 98e67ed59e1d1-3b5e0692b4fmr5464796a91.12.1796503968407; Sat, 05 Dec 2026 12:52:48 -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.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 12:52:48 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v5 21/68] net/af_packet: use kvargs numeric helpers Date: Sat, 5 Dec 2026 12:49:52 -0800 Message-ID: <20261205205221.1131118-22-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 open coded parse_uint() is correct, but the same checks are now available from kvargs. Use them, and express the lower bound as part of the range rather than as a separate test after each call. qdisc_bypass and ignore_outgoing are booleans, so parse them with rte_kvargs_handle_bool() into a bool. A bare "qdisc_bypass" with no value now enables it, which the manual pair loop here supports without any further change. Note that both parameters of rte_pmd_init_internals() stay an unsigned int: the address of each is passed to setsockopt(), which expects a four byte int. Signed-off-by: Stephen Hemminger --- drivers/net/af_packet/rte_eth_af_packet.c | 81 ++++++----------------- 1 file changed, 20 insertions(+), 61 deletions(-) diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c index fbaea57615..1c2da2d6da 100644 --- a/drivers/net/af_packet/rte_eth_af_packet.c +++ b/drivers/net/af_packet/rte_eth_af_packet.c @@ -15,7 +15,6 @@ #include #include -#include #include #include #include @@ -70,7 +69,7 @@ struct __rte_cache_aligned pkt_rx_queue { uint8_t vlan_strip; uint8_t timestamp_offloading; uint8_t scatter_enabled; - uint8_t ignore_outgoing; + bool ignore_outgoing; volatile unsigned long rx_pkts; volatile unsigned long rx_bytes; @@ -204,7 +203,7 @@ eth_af_packet_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) break; /* skip outgoing frames if ignore_outgoing is set */ - if (pkt_q->ignore_outgoing != 0) { + if (pkt_q->ignore_outgoing) { sll = (struct sockaddr_ll *)((uint8_t *)ppd + TPACKET_ALIGN(sizeof(*ppd))); if (sll->sll_pkttype == PACKET_OUTGOING) @@ -1209,36 +1208,17 @@ rte_pmd_init_internals(struct rte_vdev_device *dev, /* Parse an unsigned integer device argument. */ static int parse_uint(const char *key, const char *value, - unsigned int *out, unsigned long limit) + unsigned int *out, unsigned long min, unsigned long max) { - unsigned long val; - char *endptr; + uint64_t val; - if (value == NULL) { - PMD_LOG(ERR, "no value for argument \"%s\"", key); - return -1; - } - - /* Skip leading whitespace so a leading sign can be detected. */ - while (isspace((unsigned char)*value)) - value++; - - /* strtoul() silently accepts and negates a leading '-'. */ - if (*value == '\0' || *value == '-') { - PMD_LOG(ERR, "invalid value \"%s\" for argument \"%s\"", - value, key); - return -1; - } - - errno = 0; - val = strtoul(value, &endptr, 10); - if (errno != 0 || *endptr != '\0' || val > limit) { + if (rte_kvargs_to_uint(value, min, max, &val) < 0) { PMD_LOG(ERR, "invalid value \"%s\" for argument \"%s\"", - value, key); + value == NULL ? "" : value, key); return -1; } - *out = (unsigned int)val; + *out = val; return 0; } @@ -1257,9 +1237,9 @@ rte_eth_from_packet(struct rte_vdev_device *dev, unsigned int framesize = DFLT_FRAME_SIZE; unsigned int framecount = DFLT_FRAME_COUNT; unsigned int qpairs = 1; - unsigned int qdisc_bypass = 1; + bool qdisc_bypass = true; const char *fanout_mode = NULL; - unsigned int ignore_outgoing = 0; + bool ignore_outgoing = false; /* do some parameter checking */ if (*sockfd < 0) @@ -1273,52 +1253,31 @@ rte_eth_from_packet(struct rte_vdev_device *dev, for (k_idx = 0; k_idx < kvlist->count; k_idx++) { pair = &kvlist->pairs[k_idx]; if (strstr(pair->key, ETH_AF_PACKET_NUM_Q_ARG) != NULL) { - if (parse_uint(pair->key, pair->value, - &qpairs, RTE_MAX_QUEUES_PER_PORT) < 0) - return -1; - if (qpairs < 1) { - PMD_LOG(ERR, - "%s: invalid qpairs value", - name); + if (parse_uint(pair->key, pair->value, &qpairs, + 1, RTE_MAX_QUEUES_PER_PORT) < 0) return -1; - } continue; } if (strstr(pair->key, ETH_AF_PACKET_BLOCKSIZE_ARG) != NULL) { - if (parse_uint(pair->key, pair->value, &blocksize, UINT_MAX) < 0) - return -1; - if (!blocksize) { - PMD_LOG(ERR, - "%s: invalid blocksize value", - name); + if (parse_uint(pair->key, pair->value, &blocksize, + 1, UINT_MAX) < 0) return -1; - } continue; } if (strstr(pair->key, ETH_AF_PACKET_FRAMESIZE_ARG) != NULL) { - if (parse_uint(pair->key, pair->value, &framesize, UINT_MAX) < 0) - return -1; - if (!framesize) { - PMD_LOG(ERR, - "%s: invalid framesize value", - name); + if (parse_uint(pair->key, pair->value, &framesize, + 1, UINT_MAX) < 0) return -1; - } continue; } if (strstr(pair->key, ETH_AF_PACKET_FRAMECOUNT_ARG) != NULL) { - if (parse_uint(pair->key, pair->value, &framecount, UINT_MAX) < 0) + if (parse_uint(pair->key, pair->value, &framecount, + 1, UINT_MAX) < 0) return -1; - if (!framecount) { - PMD_LOG(ERR, - "%s: invalid framecount value", - name); - return -1; - } continue; } if (strstr(pair->key, ETH_AF_PACKET_QDISC_BYPASS_ARG) != NULL) { - if (parse_uint(pair->key, pair->value, &qdisc_bypass, 1) < 0) + if (rte_kvargs_handle_bool(pair->key, pair->value, &qdisc_bypass) < 0) return -1; continue; } @@ -1327,7 +1286,7 @@ rte_eth_from_packet(struct rte_vdev_device *dev, continue; } if (strstr(pair->key, ETH_AF_PACKET_IGNORE_OUTGOING_ARG) != NULL) { - if (parse_uint(pair->key, pair->value, &ignore_outgoing, 1) < 0) + if (rte_kvargs_handle_bool(pair->key, pair->value, &ignore_outgoing) < 0) return -1; continue; } @@ -1357,7 +1316,7 @@ rte_eth_from_packet(struct rte_vdev_device *dev, PMD_LOG(DEBUG, "%s:\tfanout mode %s", name, fanout_mode); else PMD_LOG(DEBUG, "%s:\tfanout mode %s", name, "default PACKET_FANOUT_HASH"); - PMD_LOG(DEBUG, "%s:\tignore outgoing %u", name, ignore_outgoing); + PMD_LOG(DEBUG, "%s:\tignore outgoing %d", name, ignore_outgoing); if (rte_pmd_init_internals(dev, *sockfd, qpairs, blocksize, blockcount, -- 2.53.0