From: Denis Sergeev <denserg.edu@gmail.com>
To: dev@dpdk.org
Cc: shepard.siegel@atomicrules.com, ed.czeck@atomicrules.com,
john.miller@atomicrules.com, stephen@networkplumber.org,
Denis Sergeev <denserg.edu@gmail.com>,
stable@dpdk.org
Subject: [PATCH v2] net/ark: use standard IPv4 address parser
Date: Thu, 4 Jun 2026 06:48:37 +0300 [thread overview]
Message-ID: <20260604034837.250221-1-denserg.edu@gmail.com> (raw)
In-Reply-To: <20260603054742.120101-1-denserg.edu@gmail.com>
The IPv4 parsing helper used by pktgen and pktchkr read each octet with
"%u", which accepts values above 255 from the configuration file and
encodes them into unintended device register values.
Replace the hand-rolled parser in both modules with inet_pton(), which
validates the dotted-quad format and the octet range, and matches the
IPv4 parsing already used by other DPDK drivers. For valid input the
returned value is byte-order identical to the previous helper, so the
register contents are unchanged.
Fixes: 9c7188a68d7b ("net/ark: provide API for hardware modules pktchkr and pktgen")
Cc: stable@dpdk.org
Signed-off-by: Denis Sergeev <denserg.edu@gmail.com>
---
v2:
- Replace the hand-rolled parser with inet_pton() in both modules
instead of adding explicit octet range checks.
drivers/net/ark/ark_pktchkr.c | 9 +++++----
drivers/net/ark/ark_pktgen.c | 9 +++++----
2 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/drivers/net/ark/ark_pktchkr.c b/drivers/net/ark/ark_pktchkr.c
index e1f336c73c..67405ac18a 100644
--- a/drivers/net/ark/ark_pktchkr.c
+++ b/drivers/net/ark/ark_pktchkr.c
@@ -4,9 +4,11 @@
#include <stdlib.h>
#include <unistd.h>
+#include <arpa/inet.h>
#include <rte_string_fns.h>
#include <rte_malloc.h>
+#include <rte_byteorder.h>
#include "ark_pktchkr.h"
#include "ark_logs.h"
@@ -374,12 +376,11 @@ static int32_t parse_ipv4_string(char const *ip_address);
static int32_t
parse_ipv4_string(char const *ip_address)
{
- unsigned int ip[4];
+ struct in_addr addr;
- if (sscanf(ip_address, "%u.%u.%u.%u",
- &ip[0], &ip[1], &ip[2], &ip[3]) != 4)
+ if (inet_pton(AF_INET, ip_address, &addr) != 1)
return 0;
- return ip[3] + ip[2] * 0x100 + ip[1] * 0x10000ul + ip[0] * 0x1000000ul;
+ return rte_be_to_cpu_32(addr.s_addr);
}
void
diff --git a/drivers/net/ark/ark_pktgen.c b/drivers/net/ark/ark_pktgen.c
index 69ff7072b2..05d5773d44 100644
--- a/drivers/net/ark/ark_pktgen.c
+++ b/drivers/net/ark/ark_pktgen.c
@@ -4,9 +4,11 @@
#include <stdlib.h>
#include <unistd.h>
+#include <arpa/inet.h>
#include <rte_string_fns.h>
#include <rte_malloc.h>
+#include <rte_byteorder.h>
#include <rte_thread.h>
#include "ark_pktgen.h"
@@ -355,12 +357,11 @@ static int32_t parse_ipv4_string(char const *ip_address);
static int32_t
parse_ipv4_string(char const *ip_address)
{
- unsigned int ip[4];
+ struct in_addr addr;
- if (sscanf(ip_address, "%u.%u.%u.%u",
- &ip[0], &ip[1], &ip[2], &ip[3]) != 4)
+ if (inet_pton(AF_INET, ip_address, &addr) != 1)
return 0;
- return ip[3] + ip[2] * 0x100 + ip[1] * 0x10000ul + ip[0] * 0x1000000ul;
+ return rte_be_to_cpu_32(addr.s_addr);
}
static void
--
2.50.1
next prev parent reply other threads:[~2026-06-04 3:49 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-03 5:47 [PATCH] net/ark: validate IPv4 octets in address parser Denis Sergeev
2026-06-03 17:29 ` Stephen Hemminger
2026-06-04 3:48 ` Denis Sergeev [this message]
2026-06-04 16:55 ` [PATCH v2] net/ark: use standard IPv4 " Stephen Hemminger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260604034837.250221-1-denserg.edu@gmail.com \
--to=denserg.edu@gmail.com \
--cc=dev@dpdk.org \
--cc=ed.czeck@atomicrules.com \
--cc=john.miller@atomicrules.com \
--cc=shepard.siegel@atomicrules.com \
--cc=stable@dpdk.org \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox