From fbf75f2e7dd1ab5a7da2ac9a071ee4db80df703c Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Wed, 24 Sep 2025 16:59:50 +0200 Subject: [PATCH] runmodes: let thread count callback return uint16_t It will be a long time before we need more than 64k threads. Update capture methods. --- src/runmode-af-packet.c | 10 +++++----- src/runmode-af-xdp.c | 9 ++------- src/runmode-dpdk.c | 2 +- src/runmode-erf-dag.c | 2 +- src/runmode-netmap.c | 4 ++-- src/runmode-nflog.c | 2 +- src/runmode-pcap.c | 4 ++-- src/source-af-packet.h | 2 +- src/source-af-xdp.h | 2 +- src/source-pcap.h | 2 +- src/util-runmodes.h | 2 +- 11 files changed, 18 insertions(+), 23 deletions(-) diff --git a/src/runmode-af-packet.c b/src/runmode-af-packet.c index 940eece3a0..c6652abd0e 100644 --- a/src/runmode-af-packet.c +++ b/src/runmode-af-packet.c @@ -253,7 +253,7 @@ static void *ParseAFPConfig(const char *iface) if (strcmp(threadsstr, "auto") == 0) { aconf->threads = 0; } else { - if (StringParseInt32(&aconf->threads, 10, 0, (const char *)threadsstr) < 0) { + if (StringParseUint16(&aconf->threads, 10, 0, (const char *)threadsstr) < 0) { SCLogWarning("%s: invalid number of " "threads, resetting to default", iface); @@ -668,15 +668,15 @@ finalize: if (aconf->threads == 0) { /* for cluster_flow use core count */ if (cluster_type == PACKET_FANOUT_HASH) { - aconf->threads = (int)UtilCpuGetNumProcessorsOnline(); + aconf->threads = UtilCpuGetNumProcessorsOnline(); SCLogPerf("%s: cluster_flow: %u cores, using %u threads", iface, aconf->threads, aconf->threads); /* for cluster_qm use RSS queue count */ } else if (cluster_type == PACKET_FANOUT_QM) { int rss_queues = GetIfaceRSSQueuesNum(iface); - if (rss_queues > 0) { - aconf->threads = rss_queues; + if (rss_queues > 0 && rss_queues <= UINT16_MAX) { + aconf->threads = (uint16_t)rss_queues; SCLogPerf("%s: cluster_qm: %d RSS queues, using %u threads", iface, rss_queues, aconf->threads); } @@ -771,7 +771,7 @@ finalize: return aconf; } -static int AFPConfigGeThreadsCount(void *conf) +static uint16_t AFPConfigGeThreadsCount(void *conf) { AFPIfaceConfig *afp = (AFPIfaceConfig *)conf; return afp->threads; diff --git a/src/runmode-af-xdp.c b/src/runmode-af-xdp.c index 03bcdbb71b..78aa3a3608 100644 --- a/src/runmode-af-xdp.c +++ b/src/runmode-af-xdp.c @@ -123,17 +123,12 @@ static TmEcode ConfigSetThreads(AFXDPIfaceConfig *aconf, const char *entry_str) SCReturnInt(TM_ECODE_OK); } - if (StringParseInt32(&aconf->threads, 10, 0, entry_str) < 0) { + if (StringParseUint16(&aconf->threads, 10, 0, entry_str) < 0) { SCLogError("Threads entry for interface %s contain non-numerical characters - \"%s\"", aconf->iface, entry_str); SCReturnInt(TM_ECODE_FAILED); } - if (aconf->threads < 0) { - SCLogError("Interface %s has a negative number of threads", aconf->iface); - SCReturnInt(TM_ECODE_FAILED); - } - if (aconf->threads > nr_queues) { SCLogWarning( "Selected threads greater than configured queues, using: %d thread(s)", nr_queues); @@ -306,7 +301,7 @@ finalize: return aconf; } -static int AFXDPConfigGetThreadsCount(void *conf) +static uint16_t AFXDPConfigGetThreadsCount(void *conf) { if (conf == NULL) FatalError("Configuration file is NULL"); diff --git a/src/runmode-dpdk.c b/src/runmode-dpdk.c index d031f51545..ef0c386798 100644 --- a/src/runmode-dpdk.c +++ b/src/runmode-dpdk.c @@ -1853,7 +1853,7 @@ static void *ParseDpdkConfigAndConfigureDevice(const char *iface) * \return a DPDKIfaceConfig corresponding to the interface name */ -static int DPDKConfigGetThreadsCount(void *conf) +static uint16_t DPDKConfigGetThreadsCount(void *conf) { if (conf == NULL) FatalError("Configuration file is NULL"); diff --git a/src/runmode-erf-dag.c b/src/runmode-erf-dag.c index de16011f1a..97cee3d241 100644 --- a/src/runmode-erf-dag.c +++ b/src/runmode-erf-dag.c @@ -30,7 +30,7 @@ #include "util-affinity.h" #include "util-runmodes.h" -static int DagConfigGetThreadCount(void *conf) +static uint16_t DagConfigGetThreadCount(void *conf) { return 1; } diff --git a/src/runmode-netmap.c b/src/runmode-netmap.c index 6b9d503b70..5ad2a55443 100644 --- a/src/runmode-netmap.c +++ b/src/runmode-netmap.c @@ -357,13 +357,13 @@ static void *ParseNetmapConfig(const char *iface_name) SC_ATOMIC_RESET(aconf->ref); (void) SC_ATOMIC_ADD(aconf->ref, aconf->in.threads); - SCLogPerf("%s: using %d threads", aconf->iface_name, aconf->in.threads); + SCLogPerf("%s: using %u threads", aconf->iface_name, aconf->in.threads); LiveDeviceHasNoStats(); return aconf; } -static int NetmapConfigGeThreadsCount(void *conf) +static uint16_t NetmapConfigGeThreadsCount(void *conf) { NetmapIfaceConfig *aconf = (NetmapIfaceConfig *)conf; return aconf->in.threads; diff --git a/src/runmode-nflog.c b/src/runmode-nflog.c index 07140822a2..19cd0cb203 100644 --- a/src/runmode-nflog.c +++ b/src/runmode-nflog.c @@ -139,7 +139,7 @@ static void *ParseNflogConfig(const char *group) return nflogconf; } -static int NflogConfigGeThreadsCount(void *conf) +static uint16_t NflogConfigGeThreadsCount(void *conf) { /* for each nflog group there is no reason to use more than 1 thread */ return 1; diff --git a/src/runmode-pcap.c b/src/runmode-pcap.c index 100485da02..80c01cc115 100644 --- a/src/runmode-pcap.c +++ b/src/runmode-pcap.c @@ -136,7 +136,7 @@ static void *ParsePcapConfig(const char *iface) aconf->threads = 1; } else { if (threadsstr != NULL) { - if (StringParseInt32(&aconf->threads, 10, 0, (const char *)threadsstr) < 0) { + if (StringParseUint16(&aconf->threads, 10, 0, (const char *)threadsstr) < 0) { SCLogWarning("Invalid value for " "pcap.threads: %s, resetting to 1", threadsstr); @@ -216,7 +216,7 @@ static void *ParsePcapConfig(const char *iface) return aconf; } -static int PcapConfigGeThreadsCount(void *conf) +static uint16_t PcapConfigGeThreadsCount(void *conf) { PcapIfaceConfig *pfp = (PcapIfaceConfig *)conf; return pfp->threads; diff --git a/src/source-af-packet.h b/src/source-af-packet.h index 29bedcb418..1e22c78352 100644 --- a/src/source-af-packet.h +++ b/src/source-af-packet.h @@ -89,7 +89,7 @@ typedef struct AFPIfaceConfig_ { char iface[AFP_IFACE_NAME_LENGTH]; /* number of threads */ - int threads; + uint16_t threads; /* socket buffer size */ int buffer_size; /* ring size in number of packets */ diff --git a/src/source-af-xdp.h b/src/source-af-xdp.h index e6ce0bc3e4..af841ee2f0 100644 --- a/src/source-af-xdp.h +++ b/src/source-af-xdp.h @@ -29,7 +29,7 @@ typedef struct AFXDPIfaceConfig { char iface[AFXDP_IFACE_NAME_LENGTH]; /* number of threads */ - int threads; + uint16_t threads; int promisc; /* misc use flags */ diff --git a/src/source-pcap.h b/src/source-pcap.h index 51f68aa6b8..f1d81c7982 100644 --- a/src/source-pcap.h +++ b/src/source-pcap.h @@ -45,7 +45,7 @@ typedef struct PcapIfaceConfig_ { char iface[PCAP_IFACE_NAME_LENGTH]; /* number of threads */ - int threads; + uint16_t threads; /* socket buffer size */ int buffer_size; /* snapshot length */ diff --git a/src/util-runmodes.h b/src/util-runmodes.h index d1e4c80208..dd6bf36392 100644 --- a/src/util-runmodes.h +++ b/src/util-runmodes.h @@ -25,7 +25,7 @@ typedef void *(*ConfigIfaceParserFunc) (const char *); typedef void *(*ConfigIPSParserFunc) (int); -typedef int (*ConfigIfaceThreadsCountFunc) (void *); +typedef uint16_t (*ConfigIfaceThreadsCountFunc)(void *); int RunModeSetLiveCaptureAuto(ConfigIfaceParserFunc configparser, ConfigIfaceThreadsCountFunc ModThreadsCount,