]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
netmap: output cleanups
authorVictor Julien <vjulien@oisf.net>
Tue, 20 Dec 2022 07:01:06 +0000 (08:01 +0100)
committerVictor Julien <vjulien@oisf.net>
Tue, 20 Dec 2022 07:51:33 +0000 (08:51 +0100)
src/runmode-netmap.c
src/source-netmap.c

index 010ffc9c83cbf91e6a0a0ba2fe742bf862e70f02..351000951f3368cb11231b9b4dbc966f418c74b8 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2014-2021 Open Information Security Foundation
+/* Copyright (C) 2014-2022 Open Information Security Foundation
  *
  * You can copy, redistribute or modify this Program under the terms of
  * the GNU General Public License version 2 as published by the Free
@@ -95,8 +95,7 @@ static int ParseNetmapSettings(NetmapIfaceSettings *ns, const char *iface,
     if (ns->iface[0]) {
         size_t len = strlen(ns->iface);
         if (ns->iface[len-1] == '+') {
-            SCLogWarning("netmap interface %s uses obsolete '+' notation. Using '^' instead.",
-                    ns->iface);
+            SCLogWarning("%s: interface uses obsolete '+' notation. Using '^' instead", ns->iface);
             ns->iface[len-1] = '^';
             ns->sw_ring = true;
         } else if (ns->iface[len-1] == '^') {
@@ -123,15 +122,14 @@ static int ParseNetmapSettings(NetmapIfaceSettings *ns, const char *iface,
     if (ConfGet("bpf-filter", &bpf_filter) == 1) {
         if (strlen(bpf_filter) > 0) {
             ns->bpf_filter = bpf_filter;
-            SCLogInfo("Going to use command-line provided bpf filter '%s'",
-                    ns->bpf_filter);
+            SCLogInfo("%s: using command-line provided bpf filter '%s'", iface, ns->bpf_filter);
         }
     }
 
     if (if_root == NULL && if_default == NULL) {
-        SCLogInfo("Unable to find netmap config for "
-                "interface \"%s\" or \"default\", using default values",
-                iface);
+        SCLogInfo("%s: unable to find netmap config for interface \"%s\" or \"default\", using "
+                  "default values",
+                iface, iface);
         goto finalize;
 
     /* If there is no setting for current interface use default one as main iface */
@@ -150,7 +148,8 @@ static int ParseNetmapSettings(NetmapIfaceSettings *ns, const char *iface,
             ns->threads_auto = true;
         } else {
             if (StringParseUint16(&ns->threads, 10, 0, threadsstr) < 0) {
-                SCLogWarning("Invalid config value for threads: %s, resetting to 0", threadsstr);
+                SCLogWarning("%s: invalid config value for threads: %s, resetting to 0", iface,
+                        threadsstr);
                 ns->threads = 0;
             }
         }
@@ -162,7 +161,7 @@ static int ParseNetmapSettings(NetmapIfaceSettings *ns, const char *iface,
         if (ConfGetChildValueWithDefault(if_root, if_default, "bpf-filter", &bpf_filter) == 1) {
             if (strlen(bpf_filter) > 0) {
                 ns->bpf_filter = bpf_filter;
-                SCLogInfo("Going to use bpf filter %s", ns->bpf_filter);
+                SCLogInfo("%s: using bpf filter %s", iface, ns->bpf_filter);
             }
         }
     }
@@ -170,7 +169,7 @@ static int ParseNetmapSettings(NetmapIfaceSettings *ns, const char *iface,
     int boolval = 0;
     (void)ConfGetChildValueBoolWithDefault(if_root, if_default, "disable-promisc", (int *)&boolval);
     if (boolval) {
-        SCLogInfo("Disabling promiscuous mode on iface %s", ns->iface);
+        SCLogInfo("%s: disabling promiscuous mode", ns->iface);
         ns->promisc = false;
     }
 
@@ -185,7 +184,7 @@ static int ParseNetmapSettings(NetmapIfaceSettings *ns, const char *iface,
         } else if (ConfValIsFalse(tmpctype)) {
             ns->checksum_mode = CHECKSUM_VALIDATION_DISABLE;
         } else {
-            SCLogWarning("Invalid value for checksum-checks for %s", iface);
+            SCLogWarning("%s: invalid value for checksum-checks '%s'", iface, tmpctype);
         }
     }
 
@@ -198,7 +197,7 @@ static int ParseNetmapSettings(NetmapIfaceSettings *ns, const char *iface,
         } else if (strcmp(copymodestr, "tap") == 0) {
             ns->copy_mode = NETMAP_COPY_MODE_TAP;
         } else {
-            SCLogWarning("Invalid copy-mode (valid are tap, ips)");
+            SCLogWarning("%s: invalid copy-mode %s (valid are tap, ips)", iface, copymodestr);
         }
     }
 
@@ -255,7 +254,7 @@ static void *ParseNetmapConfig(const char *iface_name)
     /* Find initial node */
     ConfNode *netmap_node = ConfGetNode("netmap");
     if (netmap_node == NULL) {
-        SCLogInfo("Unable to find netmap config using default value");
+        SCLogInfo("%s: unable to find netmap config using default value", iface_name);
     } else {
         if_root = ConfFindDeviceConfig(netmap_node, aconf->iface_name);
         if_default = ConfFindDeviceConfig(netmap_node, "default");
@@ -309,8 +308,7 @@ static void *ParseNetmapConfig(const char *iface_name)
 
     SC_ATOMIC_RESET(aconf->ref);
     (void) SC_ATOMIC_ADD(aconf->ref, aconf->in.threads);
-    SCLogPerf("Using %d threads for interface %s", aconf->in.threads,
-            aconf->iface_name);
+    SCLogPerf("%s: using %d threads", aconf->iface_name, aconf->in.threads);
 
     LiveDeviceHasNoStats();
     return aconf;
index 3757b017d80573e83a84f324fb526c400c46836a..5dc4cc0065a844fe7b3f0009a11018e2e5e6bbae 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2011-2021 Open Information Security Foundation
+/* Copyright (C) 2011-2022 Open Information Security Foundation
  *
  * You can copy, redistribute or modify this Program under the terms of
  * the GNU General Public License version 2 as published by the Free
@@ -184,7 +184,7 @@ int NetmapGetRSSCount(const char *ifname)
     /* open netmap device */
     int fd = open("/dev/netmap", O_RDWR);
     if (fd == -1) {
-        SCLogError("Couldn't open netmap device, error %s", strerror(errno));
+        SCLogError("%s: open netmap device failed: %s", ifname, strerror(errno));
         goto error_open;
     }
 
@@ -197,7 +197,7 @@ int NetmapGetRSSCount(const char *ifname)
     strlcpy(hdr.nr_name, base_name, sizeof(hdr.nr_name));
 
     if (ioctl(fd, NIOCCTRL, &hdr) != 0) {
-        SCLogError("Couldn't query netmap for info about %s, error %s", ifname, strerror(errno));
+        SCLogError("%s: failed to query netmap for device info: %s", ifname, strerror(errno));
         goto error_fd;
     };
 
@@ -293,14 +293,14 @@ static int NetmapOpen(NetmapIfaceSettings *ns, NetmapDevice **pdevice, int verbo
         int if_flags = GetIfaceFlags(base_name);
         if (if_flags == -1) {
             if (verbose) {
-                SCLogError("Cannot access network interface '%s' (%s)", base_name, ns->iface);
+                SCLogError("%s: cannot access network interface: %s", base_name, ns->iface);
             }
             goto error;
         }
 
         /* bring iface up if it is down */
         if ((if_flags & IFF_UP) == 0) {
-            SCLogError("interface '%s' (%s) is down", base_name, ns->iface);
+            SCLogError("%s: interface is down", base_name);
             goto error;
         }
         /* if needed, try to set iface in promisc mode */
@@ -313,7 +313,7 @@ static int NetmapOpen(NetmapIfaceSettings *ns, NetmapDevice **pdevice, int verbo
     NetmapDevice *pdev = NULL, *spdev = NULL;
     pdev = SCCalloc(1, sizeof(*pdev));
     if (unlikely(pdev == NULL)) {
-        SCLogError("Memory allocation failed");
+        SCLogError("%s: memory allocation failed", base_name);
         goto error;
     }
     SC_ATOMIC_INIT(pdev->threads_run);
@@ -440,11 +440,13 @@ retry:
     if (pdev->nmd == NULL) {
         if (errno == EINVAL) {
             if (opt_z[0] == 'z') {
-                SCLogNotice("got '%s' EINVAL: going to retry without 'z'", devname);
+                SCLogNotice(
+                        "%s: dev '%s' got EINVAL: going to retry without 'z'", base_name, devname);
                 opt_z = "";
                 goto retry;
             } else if (opt_x[0] == 'x') {
-                SCLogNotice("dev '%s' got EINVAL: going to retry without 'x'", devname);
+                SCLogNotice(
+                        "%s: dev '%s' got EINVAL: going to retry without 'x'", base_name, devname);
                 opt_x = "";
                 goto retry;
             }
@@ -460,7 +462,7 @@ retry:
     pdev->nmd->cur_rx_ring = pdev->nmd->first_rx_ring;
     pdev->nmd->cur_tx_ring = pdev->nmd->first_tx_ring;
 
-    SCLogInfo("devname [fd: %d] %s %s opened", pdev->nmd->fd, devname, ns->iface);
+    SCLogInfo("%s: %s opened [fd: %d]", devname, ns->iface, pdev->nmd->fd);
 
     pdev->direction = direction;
     pdev->ring = ring;
@@ -551,8 +553,7 @@ static TmEcode ReceiveNetmapThreadInit(ThreadVars *tv, const void *initdata, voi
             ntv->tv);
 
     if (aconf->in.bpf_filter) {
-        SCLogConfig("Using BPF '%s' on iface '%s'",
-                  aconf->in.bpf_filter, ntv->ifsrc->ifname);
+        SCLogConfig("%s: using BPF '%s'", ntv->ifsrc->ifname, aconf->in.bpf_filter);
         char errbuf[PCAP_ERRBUF_SIZE];
         if (SCBPFCompile(default_packet_size,  /* snaplen_arg */
                     LINKTYPE_ETHERNET,    /* linktype_arg */
@@ -563,7 +564,8 @@ static TmEcode ReceiveNetmapThreadInit(ThreadVars *tv, const void *initdata, voi
                     errbuf,
                     sizeof(errbuf)) == -1)
         {
-            SCLogError("Failed to compile BPF \"%s\": %s", aconf->in.bpf_filter, errbuf);
+            SCLogError("%s: failed to compile BPF \"%s\": %s", ntv->ifsrc->ifname,
+                    aconf->in.bpf_filter, errbuf);
             goto error_dst;
         }
     }
@@ -797,12 +799,10 @@ static TmEcode ReceiveNetmapLoop(ThreadVars *tv, void *data, void *slot)
         PacketPoolWait();
 
         int r = poll(&fds, 1, POLL_TIMEOUT);
-
         if (r < 0) {
             /* error */
             if (errno != EINTR)
-                SCLogError("Error polling netmap from iface '%s': (%d" PRIu32 ") %s",
-                        ntv->ifsrc->ifname, errno, strerror(errno));
+                SCLogError("%s: error polling netmap: %s", ntv->ifsrc->ifname, strerror(errno));
             continue;
 
         } else if (r == 0) {
@@ -818,11 +818,10 @@ static TmEcode ReceiveNetmapLoop(ThreadVars *tv, void *data, void *slot)
 
         if (unlikely(fds.revents & POLL_EVENTS)) {
             if (fds.revents & POLLERR) {
-                SCLogError("Error reading netmap data via polling from iface '%s': (%d" PRIu32
-                           ") %s",
-                        ntv->ifsrc->ifname, errno, strerror(errno));
+                SCLogError("%s: error reading netmap data via polling: %s", ntv->ifsrc->ifname,
+                        strerror(errno));
             } else if (fds.revents & POLLNVAL) {
-                SCLogError("Invalid polling request");
+                SCLogError("%s: invalid polling request", ntv->ifsrc->ifname);
             }
             continue;
         }
@@ -852,11 +851,10 @@ static void ReceiveNetmapThreadExitStats(ThreadVars *tv, void *data)
     NetmapThreadVars *ntv = (NetmapThreadVars *)data;
 
     NetmapDumpCounters(ntv);
-    SCLogPerf("(%s) Kernel: Packets %" PRIu64 ", dropped %" PRIu64 ", bytes %" PRIu64 "",
-              tv->name,
-              StatsGetLocalCounterValue(tv, ntv->capture_kernel_packets),
-              StatsGetLocalCounterValue(tv, ntv->capture_kernel_drops),
-              ntv->bytes);
+    SCLogPerf("%s: (%s) packets %" PRIu64 ", dropped %" PRIu64 ", bytes %" PRIu64 "",
+            ntv->ifsrc->ifname, tv->name,
+            StatsGetLocalCounterValue(tv, ntv->capture_kernel_packets),
+            StatsGetLocalCounterValue(tv, ntv->capture_kernel_drops), ntv->bytes);
 }
 
 /**