]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
dpdk: update types to avoid type-warnings
authorLukas Sismis <lsismis@oisf.net>
Sat, 26 Apr 2025 13:00:58 +0000 (15:00 +0200)
committerVictor Julien <victor@inliniac.net>
Thu, 5 Jun 2025 17:14:30 +0000 (19:14 +0200)
13 files changed:
src/runmode-dpdk.c
src/source-dpdk.c
src/source-dpdk.h
src/util-dpdk-i40e.c
src/util-dpdk-i40e.h
src/util-dpdk-ice.c
src/util-dpdk-ice.h
src/util-dpdk-ixgbe.c
src/util-dpdk-ixgbe.h
src/util-dpdk-mlx5.c
src/util-dpdk-mlx5.h
src/util-memcmp.h
src/util-time.h

index 154e41b02dfb77e016d2a45afd0b53b36829aeb3..04eae0138cb6ac7fe939b2c7e8671b80b7072a45 100644 (file)
@@ -70,7 +70,7 @@ static char *AllocArgument(size_t arg_len);
 static char *AllocAndSetArgument(const char *arg);
 static char *AllocAndSetOption(const char *arg);
 
-static void ArgumentsInit(struct Arguments *args, unsigned capacity);
+static void ArgumentsInit(struct Arguments *args, uint16_t capacity);
 static void ArgumentsCleanup(struct Arguments *args);
 static void ArgumentsAdd(struct Arguments *args, char *value);
 static void ArgumentsAddOptionAndArgument(struct Arguments *args, const char *opt, const char *arg);
@@ -148,9 +148,9 @@ DPDKIfaceConfigAttributes dpdk_yaml = {
  * \brief Input is a number of which we want to find the greatest divisor up to max_num (inclusive).
  * The divisor is returned.
  */
-static int GreatestDivisorUpTo(uint32_t num, uint32_t max_num)
+static uint32_t GreatestDivisorUpTo(uint32_t num, uint32_t max_num)
 {
-    for (int i = max_num; i >= 2; i--) {
+    for (uint32_t i = max_num; i >= 2; i--) {
         if (num % i == 0) {
             return i;
         }
@@ -225,12 +225,12 @@ static char *AllocAndSetOption(const char *arg)
     size_t full_len = arg_len + strlen(dash_prefix);
 
     ptr = AllocArgument(full_len);
-    strlcpy(ptr, dash_prefix, strlen(dash_prefix) + 1);
-    strlcat(ptr, arg, full_len + 1);
+    strlcpy(ptr, dash_prefix, full_len);
+    strlcat(ptr, arg, full_len);
     SCReturnPtr(ptr, "char *");
 }
 
-static void ArgumentsInit(struct Arguments *args, unsigned capacity)
+static void ArgumentsInit(struct Arguments *args, uint16_t capacity)
 {
     SCEnter();
     args->argv = SCCalloc(capacity, sizeof(*args->argv)); // alloc array of pointers
@@ -352,7 +352,7 @@ static void ConfigInit(DPDKIfaceConfig **iconf)
     if (ptr == NULL)
         FatalError("Could not allocate memory for DPDKIfaceConfig");
 
-    ptr->out_port_id = -1; // make sure no port is set
+    ptr->out_port_id = UINT16_MAX; // make sure no port is set
     SC_ATOMIC_INIT(ptr->ref);
     (void)SC_ATOMIC_ADD(ptr->ref, 1);
     ptr->DerefFunc = DPDKDerefConfig;
@@ -381,7 +381,7 @@ static void ConfigSetIface(DPDKIfaceConfig *iconf, const char *entry_str)
 static int ConfigSetThreads(DPDKIfaceConfig *iconf, const char *entry_str)
 {
     SCEnter();
-    static int32_t remaining_auto_cpus = -1;
+    static uint16_t remaining_auto_cpus = UINT16_MAX; // uninitialized
     if (!threading_set_cpu_affinity) {
         SCLogError("DPDK runmode requires configured thread affinity");
         SCReturnInt(-EINVAL);
@@ -397,7 +397,7 @@ static int ConfigSetThreads(DPDKIfaceConfig *iconf, const char *entry_str)
         SCLogError("Specify management-cpu-set list in the threading section");
         SCReturnInt(-EINVAL);
     }
-    uint32_t sched_cpus = UtilAffinityGetAffinedCPUNum(wtaf);
+    uint16_t sched_cpus = UtilAffinityGetAffinedCPUNum(wtaf);
     if (sched_cpus == UtilCpuGetNumProcessorsOnline()) {
         SCLogWarning(
                 "\"all\" specified in worker CPU cores affinity, excluding management threads");
@@ -425,7 +425,12 @@ static int ConfigSetThreads(DPDKIfaceConfig *iconf, const char *entry_str)
     }
 
     if (strcmp(entry_str, "auto") == 0) {
-        iconf->threads = (uint16_t)sched_cpus / LiveGetDeviceCount();
+        uint16_t live_dev_count = (uint16_t)LiveGetDeviceCount();
+        if (live_dev_count == 0) {
+            SCLogError("No live devices found, cannot auto-assign threads");
+            SCReturnInt(-EINVAL);
+        }
+        iconf->threads = sched_cpus / live_dev_count;
         if (iconf->threads == 0) {
             SCLogError("Not enough worker CPU cores with affinity were configured");
             SCReturnInt(-ERANGE);
@@ -434,8 +439,9 @@ static int ConfigSetThreads(DPDKIfaceConfig *iconf, const char *entry_str)
         if (remaining_auto_cpus > 0) {
             iconf->threads++;
             remaining_auto_cpus--;
-        } else if (remaining_auto_cpus == -1) {
-            remaining_auto_cpus = (int32_t)sched_cpus % LiveGetDeviceCount();
+        } else if (remaining_auto_cpus == UINT16_MAX) {
+            // first time auto-assignment
+            remaining_auto_cpus = sched_cpus % live_dev_count;
             if (remaining_auto_cpus > 0) {
                 iconf->threads++;
                 remaining_auto_cpus--;
@@ -582,7 +588,7 @@ static uint32_t MempoolCacheSizeCalculate(uint32_t mp_sz)
     // It is advised to have mempool cache size lower or equal to:
     //   RTE_MEMPOOL_CACHE_MAX_SIZE (by default 512) and "mempool-size / 1.5"
     // and at the same time "mempool-size modulo cache_size == 0".
-    uint32_t max_cache_size = MIN(RTE_MEMPOOL_CACHE_MAX_SIZE, mp_sz / 1.5);
+    uint32_t max_cache_size = MIN(RTE_MEMPOOL_CACHE_MAX_SIZE, (uint32_t)(mp_sz / 1.5));
     return GreatestDivisorUpTo(mp_sz, max_cache_size);
 }
 
@@ -626,7 +632,7 @@ static int ConfigSetRxDescriptors(DPDKIfaceConfig *iconf, const char *entry_str,
     }
 
     if (strcmp(entry_str, "auto") == 0) {
-        iconf->nb_rx_desc = GreatestPowOf2UpTo(max_desc);
+        iconf->nb_rx_desc = (uint16_t)GreatestPowOf2UpTo(max_desc);
         SCReturnInt(0);
     }
 
@@ -659,7 +665,7 @@ static int ConfigSetTxDescriptors(
 
     if (strcmp(entry_str, "auto") == 0) {
         if (iface_sends_pkts) {
-            iconf->nb_tx_desc = GreatestPowOf2UpTo(max_desc);
+            iconf->nb_tx_desc = (uint16_t)GreatestPowOf2UpTo(max_desc);
         } else {
             iconf->nb_tx_desc = 0;
         }
@@ -709,20 +715,21 @@ static int ConfigSetMtu(DPDKIfaceConfig *iconf, intmax_t entry_int)
         SCReturnInt(-ERANGE);
     }
 
-    iconf->mtu = entry_int;
+    iconf->mtu = (uint16_t)entry_int;
     SCReturnInt(0);
 }
 
 static int ConfigSetLinkupTimeout(DPDKIfaceConfig *iconf, intmax_t entry_int)
 {
     SCEnter();
-    if (entry_int < 0) {
-        SCLogError("%s: Link-up waiting timeout needs to be a positive number or 0 to disable",
-                iconf->iface);
+    if (entry_int < 0 || entry_int > UINT16_MAX) {
+        SCLogError("%s: Link-up waiting timeout needs to be a positive number (up to %u) or 0 to "
+                   "disable",
+                iconf->iface, UINT16_MAX);
         SCReturnInt(-ERANGE);
     }
 
-    iconf->linkup_timeout = entry_int;
+    iconf->linkup_timeout = (uint16_t)entry_int;
     SCReturnInt(0);
 }
 
@@ -913,7 +920,7 @@ static int ConfigLoad(DPDKIfaceConfig *iconf, const char *iface)
         SCReturnInt(retval);
 
     // currently only mapping "1 thread == 1 RX (and 1 TX queue in IPS mode)" is supported
-    retval = ConfigSetRxQueues(iconf, (uint16_t)iconf->threads, dev_info.max_rx_queues);
+    retval = ConfigSetRxQueues(iconf, iconf->threads, dev_info.max_rx_queues);
     if (retval < 0) {
         SCLogError("%s: too many threads configured - reduce thread count to: %" PRIu16,
                 iconf->iface, dev_info.max_rx_queues);
@@ -921,7 +928,7 @@ static int ConfigLoad(DPDKIfaceConfig *iconf, const char *iface)
     }
 
     // currently only mapping "1 thread == 1 RX (and 1 TX queue in IPS mode)" is supported
-    uint16_t tx_queues = iconf->nb_tx_desc > 0 ? (uint16_t)iconf->threads : 0;
+    uint16_t tx_queues = iconf->nb_tx_desc > 0 ? iconf->threads : 0;
     retval = ConfigSetTxQueues(iconf, tx_queues, dev_info.max_tx_queues, iface_sends_pkts);
     if (retval < 0) {
         SCLogError("%s: too many threads configured - reduce thread count to: %" PRIu16,
@@ -1062,9 +1069,9 @@ static void DeviceSetPMDSpecificRSS(struct rte_eth_rss_conf *rss_conf, const cha
 }
 
 // Returns -1 if no bit is set
-static int GetFirstSetBitPosition(uint64_t bits)
+static int32_t GetFirstSetBitPosition(uint64_t bits)
 {
-    for (uint64_t i = 0; i < 64; i++) {
+    for (int32_t i = 0; i < 64; i++) {
         if (bits & BIT_U64(i))
             return i;
     }
@@ -1467,7 +1474,7 @@ static int DeviceConfigureQueues(DPDKIfaceConfig *iconf, const struct rte_eth_de
                 rxq_conf.rx_free_thresh, rxq_conf.rx_drop_en);
 
         retval = rte_eth_rx_queue_setup(iconf->port_id, queue_id, iconf->nb_rx_desc,
-                iconf->socket_id, &rxq_conf, iconf->pkt_mempools->pkt_mp[queue_id]);
+                (unsigned int)iconf->socket_id, &rxq_conf, iconf->pkt_mempools->pkt_mp[queue_id]);
         if (retval < 0) {
             SCLogError("%s: failed to setup RX queue %u: %s", iconf->iface, queue_id,
                     rte_strerror(-retval));
@@ -1485,8 +1492,8 @@ static int DeviceConfigureQueues(DPDKIfaceConfig *iconf, const struct rte_eth_de
                 iconf->iface, queue_id, iconf->nb_tx_desc, txq_conf.offloads,
                 txq_conf.tx_thresh.hthresh, txq_conf.tx_thresh.pthresh, txq_conf.tx_thresh.wthresh,
                 txq_conf.tx_free_thresh, txq_conf.tx_rs_thresh, txq_conf.tx_deferred_start);
-        retval = rte_eth_tx_queue_setup(
-                iconf->port_id, queue_id, iconf->nb_tx_desc, iconf->socket_id, &txq_conf);
+        retval = rte_eth_tx_queue_setup(iconf->port_id, queue_id, iconf->nb_tx_desc,
+                (unsigned int)iconf->socket_id, &txq_conf);
         if (retval < 0) {
             SCLogError("%s: failed to setup TX queue %u: %s", iconf->iface, queue_id,
                     rte_strerror(-retval));
@@ -1815,7 +1822,7 @@ static void *ParseDpdkConfigAndConfigureDevice(const char *iface)
     if (ldev_instance == NULL) {
         FatalError("Device %s is not registered as a live device", iface);
     }
-    for (int32_t i = 0; i < iconf->threads; i++) {
+    for (uint16_t i = 0; i < iconf->threads; i++) {
         ldev_instance->dpdk_vars = iconf->pkt_mempools;
         iconf->pkt_mempools = NULL;
     }
index 62e3dccce56bfdef0dc71ec9c51ef34305d82195..69773003363a4093cb9915311879d608c5e42772 100644 (file)
@@ -151,7 +151,7 @@ static TmEcode DecodeDPDK(ThreadVars *, Packet *, void *);
 static void DPDKFreeMbufArray(struct rte_mbuf **mbuf_array, uint16_t mbuf_cnt, uint16_t offset);
 static bool InterruptsRXEnable(uint16_t port_id, uint16_t queue_id)
 {
-    uint32_t event_data = port_id << UINT16_WIDTH | queue_id;
+    uint32_t event_data = (uint32_t)port_id << UINT16_WIDTH | queue_id;
     int32_t ret = rte_eth_dev_rx_intr_ctl_q(port_id, queue_id, RTE_EPOLL_PER_THREAD,
             RTE_INTR_EVENT_ADD, (void *)((uintptr_t)event_data));
 
@@ -707,21 +707,23 @@ fail:
     SCReturnInt(TM_ECODE_FAILED);
 }
 
-static void PrintDPDKPortXstats(uint32_t port_id, const char *port_name)
+static void PrintDPDKPortXstats(uint16_t port_id, const char *port_name)
 {
     struct rte_eth_xstat *xstats;
     struct rte_eth_xstat_name *xstats_names;
 
-    int32_t len = rte_eth_xstats_get(port_id, NULL, 0);
-    if (len < 0)
+    int32_t ret = rte_eth_xstats_get(port_id, NULL, 0);
+    if (ret < 0) {
         FatalError("Error (%s) getting count of rte_eth_xstats failed on port %s",
-                rte_strerror(-len), port_name);
+                rte_strerror(-ret), port_name);
+    }
+    uint16_t len = (uint16_t)ret;
 
     xstats = SCCalloc(len, sizeof(*xstats));
     if (xstats == NULL)
         FatalError("Failed to allocate memory for the rte_eth_xstat structure");
 
-    int32_t ret = rte_eth_xstats_get(port_id, xstats, len);
+    ret = rte_eth_xstats_get(port_id, xstats, len);
     if (ret < 0 || ret > len) {
         SCFree(xstats);
         FatalError("Error (%s) getting rte_eth_xstats failed on port %s", rte_strerror(-ret),
index 350a5a164af5683a9aab5d98edecadfb37138849..7c2e9803439152d5263bf6e714b8033151b05997 100644 (file)
@@ -76,7 +76,7 @@ typedef struct DPDKIfaceConfig_ {
     uint32_t mempool_cache_size;
     DPDKDeviceResources *pkt_mempools;
     uint16_t linkup_timeout; // in seconds how long to wait for link to come up
-    SC_ATOMIC_DECLARE(unsigned int, ref);
+    SC_ATOMIC_DECLARE(uint16_t, ref);
     /* threads bind queue id one by one */
     SC_ATOMIC_DECLARE(uint16_t, queue_id);
     SC_ATOMIC_DECLARE(uint16_t, inconsistent_numa_cnt);
@@ -96,7 +96,7 @@ typedef struct DPDKPacketVars_ {
     struct rte_mbuf *mbuf;
     uint16_t out_port_id;
     uint16_t out_queue_id;
-    uint8_t copy_mode;
+    DpdkCopyModeEnum copy_mode;
 } DPDKPacketVars;
 
 void TmModuleReceiveDPDKRegister(void);
index 8879e27484a3fe18b0457a7047aed2c89bf40ef2..18aed1e030f613f3a06314022f64a094dbe560c5 100644 (file)
@@ -299,7 +299,7 @@ static int i40eDeviceSetRSSWithFlows(int port_id, const char *port_name, int nb_
 
 #endif /* RTE_VERSION < RTE_VERSION_NUM(20,0,0,0) */
 
-int i40eDeviceSetRSS(int port_id, int nb_rx_queues, char *port_name)
+int i40eDeviceSetRSS(int port_id, uint16_t nb_rx_queues, char *port_name)
 {
     (void)nb_rx_queues; // avoid unused variable warnings
 
index cbec290d8c76abafa7e50fa30b622dff760da13a..3a61d53d09d1ec77bd370f448b9de7304a1166d7 100644 (file)
@@ -30,7 +30,7 @@
 
 #include "util-dpdk.h"
 
-int i40eDeviceSetRSS(int port_id, int nb_rx_queues, char *port_name);
+int i40eDeviceSetRSS(int port_id, uint16_t nb_rx_queues, char *port_name);
 void i40eDeviceSetRSSConf(struct rte_eth_rss_conf *rss_conf);
 
 #endif /* HAVE_DPDK */
index 47e01c92dbdff252920e2987c27e0219eb22468b..f1b9e965d51821a0ebed62dcdece112ac56f2475 100644 (file)
@@ -90,7 +90,7 @@ static int iceDeviceSetRSSFlowIPv6(
     return DPDKCreateRSSFlow(port_id, port_name, rss_conf, RTE_ETH_RSS_IPV6, pattern);
 }
 
-int iceDeviceSetRSS(int port_id, int nb_rx_queues, char *port_name)
+int iceDeviceSetRSS(int port_id, uint16_t nb_rx_queues, char *port_name)
 {
     uint16_t queues[RTE_MAX_QUEUES_PER_PORT];
     struct rte_flow_error flush_error = { 0 };
index ca7c3cee18015302375fda1f1648ca1e5a1e688f..049f6a4d843a809dcf19446703c7f04862ea2ae0 100644 (file)
@@ -30,7 +30,7 @@
 
 #include "util-dpdk.h"
 
-int iceDeviceSetRSS(int port_id, int nb_rx_queues, char *port_name);
+int iceDeviceSetRSS(int port_id, uint16_t nb_rx_queues, char *port_name);
 void iceDeviceSetRSSConf(struct rte_eth_rss_conf *rss_conf);
 
 #endif /* HAVE_DPDK */
index 7fb43ec2bf27d2883091d962d38e107084b0f578..b2db54675c75f80ba1976c73325bbfbc576ca394 100644 (file)
@@ -45,7 +45,7 @@ void ixgbeDeviceSetRSSHashFunction(uint64_t *rss_hf)
     *rss_hf = RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_IPV6 | RTE_ETH_RSS_IPV6_EX;
 }
 
-int ixgbeDeviceSetRSS(int port_id, int nb_rx_queues, char *port_name)
+int ixgbeDeviceSetRSS(int port_id, uint16_t nb_rx_queues, char *port_name)
 {
     uint16_t queues[RTE_MAX_QUEUES_PER_PORT];
     struct rte_flow_error flush_error = { 0 };
index 79d3881397221dcd7b11b704559a84f8c9571868..14b46e8df9a53e9b460c48253677bfb32c6eb8ca 100644 (file)
@@ -28,7 +28,7 @@
 
 #ifdef HAVE_DPDK
 
-int ixgbeDeviceSetRSS(int port_id, int nb_rx_queues, char *port_name);
+int ixgbeDeviceSetRSS(int port_id, uint16_t nb_rx_queues, char *port_name);
 void ixgbeDeviceSetRSSHashFunction(uint64_t *rss_conf);
 
 #endif /* HAVE_DPDK */
index 2009af4f4f466464eb91de6d304a10f7ed762d4d..bc5061a5397d2400778af28613dde7c5bf28c365 100644 (file)
@@ -40,7 +40,7 @@
 
 #define MLX5_RSS_HKEY_LEN 40
 
-int mlx5DeviceSetRSS(int port_id, int nb_rx_queues, char *port_name)
+int mlx5DeviceSetRSS(int port_id, uint16_t nb_rx_queues, char *port_name)
 {
     uint16_t queues[RTE_MAX_QUEUES_PER_PORT];
     struct rte_flow_error flush_error = { 0 };
index e51593a22359f176604eb26e3abf3f7ab843da55..2ef2e5bf9eba800a23811ae3a728efc35d63be6c 100644 (file)
@@ -28,7 +28,7 @@
 
 #ifdef HAVE_DPDK
 
-int mlx5DeviceSetRSS(int port_id, int nb_rx_queues, char *port_name);
+int mlx5DeviceSetRSS(int port_id, uint16_t nb_rx_queues, char *port_name);
 
 #endif /* HAVE_DPDK */
 
index f9fc75357c17eefeb2cf20d49f03ef5376488d93..4356e2d2e4b0d40cb92d14b2aac05a6ac39a60aa 100644 (file)
@@ -71,7 +71,7 @@ static inline int SCMemcmp(const void *s1, const void *s2, size_t n)
         /* do the actual compare: _mm_cmpestri() returns the number of matching bytes */
         r = _mm_cmpestri(b1, SCMEMCMP_BYTES, b2, SCMEMCMP_BYTES,
                 _SIDD_CMP_EQUAL_EACH | _SIDD_MASKED_NEGATIVE_POLARITY);
-        m += r;
+        m += (size_t)r;
         s1 += SCMEMCMP_BYTES;
         s2 += SCMEMCMP_BYTES;
     } while (r == SCMEMCMP_BYTES);
@@ -116,7 +116,7 @@ static inline int SCMemcmpLowercase(const void *s1, const void *s2, size_t n)
         /* search using our converted buffer, return number of matching bytes */
         r = _mm_cmpestri(b1, SCMEMCMP_BYTES, b2, SCMEMCMP_BYTES,
                 _SIDD_CMP_EQUAL_EACH | _SIDD_MASKED_NEGATIVE_POLARITY);
-        m += r;
+        m += (size_t)r;
         s1 += SCMEMCMP_BYTES;
         s2 += SCMEMCMP_BYTES;
     } while (r == SCMEMCMP_BYTES);
index 1b428a9098327cb7a7fdadabb669596dd63cd86c..d978b5d5a763410a4a2bfbc9b0b7ac5162cb0bec 100644 (file)
@@ -79,7 +79,7 @@ typedef struct {
 #define SCTIME_FROM_TIMEVAL(tv)                                                                    \
     (SCTime_t)                                                                                     \
     {                                                                                              \
-        .secs = (tv)->tv_sec, .usecs = (tv)->tv_usec                                               \
+        .secs = (uint64_t)(tv)->tv_sec, .usecs = (uint32_t)(tv)->tv_usec                           \
     }
 /** \brief variant to deal with potentially bad timestamps, like from pcap files */
 #define SCTIME_FROM_TIMEVAL_UNTRUSTED(tv)                                                          \