]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
dpdk: minor refactoring in error handling and variable declaration
authorLukas Sismis <lsismis@oisf.net>
Thu, 25 May 2023 11:56:27 +0000 (13:56 +0200)
committerVictor Julien <vjulien@oisf.net>
Mon, 5 Jun 2023 09:07:02 +0000 (11:07 +0200)
src/runmode-dpdk.c

index 72e3ed2a51e8b291c3cb268dbdbcf1f040d47b2c..52364b3d765487d0baeb3abc2a6d378512a95606 100644 (file)
@@ -1200,14 +1200,9 @@ static int DeviceConfigureIPS(DPDKIfaceConfig *iconf)
 static int DeviceConfigure(DPDKIfaceConfig *iconf)
 {
     SCEnter();
-    // configure device
-    int retval;
-    struct rte_eth_dev_info dev_info;
-    struct rte_eth_conf port_conf;
-
-    retval = rte_eth_dev_get_port_by_name(iconf->iface, &(iconf->port_id));
+    int32_t retval = rte_eth_dev_get_port_by_name(iconf->iface, &(iconf->port_id));
     if (retval < 0) {
-        SCLogError("%s: getting port id failed (err=%d). Is device enabled?", iconf->iface, retval);
+        SCLogError("%s: getting port id failed (err: %s)", iconf->iface, rte_strerror(-retval));
         SCReturnInt(retval);
     }
 
@@ -1218,13 +1213,14 @@ static int DeviceConfigure(DPDKIfaceConfig *iconf)
 
     retval = DeviceSetSocketID(iconf->port_id, &iconf->socket_id);
     if (retval < 0) {
-        SCLogError("%s: invalid socket id (err=%d)", iconf->iface, retval);
+        SCLogError("%s: invalid socket id (err: %s)", iconf->iface, rte_strerror(-retval));
         SCReturnInt(retval);
     }
 
+    struct rte_eth_dev_info dev_info = { 0 };
     retval = rte_eth_dev_info_get(iconf->port_id, &dev_info);
-    if (retval != 0) {
-        SCLogError("%s: getting device info failed (err=%d)", iconf->iface, retval);
+    if (retval < 0) {
+        SCLogError("%s: getting device info failed (err: %s)", iconf->iface, rte_strerror(-retval));
         SCReturnInt(retval);
     }
 
@@ -1241,9 +1237,10 @@ static int DeviceConfigure(DPDKIfaceConfig *iconf)
     }
 
     retval = DeviceValidateMTU(iconf, &dev_info);
-    if (retval != 0)
+    if (retval < 0)
         return retval;
 
+    struct rte_eth_conf port_conf = { 0 };
     DeviceInitPortConf(iconf, &dev_info, &port_conf);
     if (port_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_CHECKSUM) {
         // Suricata does not need recalc checksums now
@@ -1252,9 +1249,9 @@ static int DeviceConfigure(DPDKIfaceConfig *iconf)
 
     retval = rte_eth_dev_configure(
             iconf->port_id, iconf->nb_rx_queues, iconf->nb_tx_queues, &port_conf);
-    if (retval != 0) {
-        SCLogError("%s: failed to configure the device (port %u, err %d)", iconf->iface,
-                iconf->port_id, retval);
+    if (retval < 0) {
+        SCLogError("%s: failed to configure the device (port %u, err %s)", iconf->iface,
+                iconf->port_id, rte_strerror(-retval));
         SCReturnInt(retval);
     }