]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
unix-socket: add ebpf-bypassed-stats command
authorEric Leblond <eric@regit.org>
Wed, 17 Jan 2018 02:45:01 +0000 (03:45 +0100)
committerEric Leblond <eric@regit.org>
Tue, 6 Feb 2018 15:58:19 +0000 (16:58 +0100)
This command output the count of element in IPv4 and IPv6 flow
table of interfaces using eBPF/XDP bypass.

src/unix-manager.c
src/util-ebpf.c
src/util-ebpf.h

index 75ca92daba5227ce29eb298e4de78d7c4f31eaa7..b328227a76205c6f7c241276f99f13f1fbafb867 100644 (file)
@@ -34,6 +34,7 @@
 #include "util-privs.h"
 #include "util-debug.h"
 #include "util-device.h"
+#include "util-ebpf.h"
 #include "util-signal.h"
 #include "util-buffer.h"
 
@@ -1190,6 +1191,9 @@ void UnixManagerThreadSpawnNonRunmode(void)
                     UNIX_CMD_TAKE_ARGS);
             UnixManagerRegisterCommand("iface-list", LiveDeviceIfaceList, NULL, 0);
             UnixManagerThreadSpawn(0);
+#ifdef HAVE_PACKET_EBPF
+            UnixManagerRegisterCommand("ebpf-bypassed-stats", EBPFGetBypassedStats, NULL, 0);
+#endif
         }
     }
 }
index 341efea07cf38d0eb31354df426769f0d14ea662..39a662f3d443108bce4e680ba53c7c54b5de41b4 100644 (file)
@@ -551,6 +551,42 @@ int EBPFCheckBypassedFlowTimeout(struct flows_stats *bypassstats,
     return ret;
 }
 
+#ifdef BUILD_UNIX_SOCKET
+TmEcode EBPFGetBypassedStats(json_t *cmd, json_t *answer, void *data)
+{
+    LiveDevice *ldev = NULL, *ndev;
+
+    json_t *ifaces = NULL;
+    while(LiveDeviceForEach(&ldev, &ndev)) {
+        struct bpf_maps_info *bpfdata = LiveDevGetStorageById(ldev, g_livedev_storage_id);
+        if (bpfdata) {
+            uint64_t ipv4_hash_count = SC_ATOMIC_GET(bpfdata->ipv4_hash_count);
+            uint64_t ipv6_hash_count = SC_ATOMIC_GET(bpfdata->ipv6_hash_count);
+            json_t *iface = json_object();
+            if (ifaces == NULL) {
+                ifaces = json_object();
+                if (ifaces == NULL) {
+                    json_object_set_new(answer, "message",
+                            json_string("internal error at json object creation"));
+                    return TM_ECODE_FAILED;
+                }
+            }
+            json_object_set_new(iface, "ipv4_count", json_integer(ipv4_hash_count));
+            json_object_set_new(iface, "ipv6_count", json_integer(ipv6_hash_count));
+            json_object_set_new(ifaces, ldev->dev, iface);
+        }
+    }
+    if (ifaces) {
+        json_object_set_new(answer, "message", ifaces);
+        SCReturnInt(TM_ECODE_OK);
+    }
+
+    json_object_set_new(answer, "message",
+                        json_string("No interface using eBPF bypass"));
+    SCReturnInt(TM_ECODE_FAILED);
+}
+#endif
+
 void EBPFRegisterExtension(void)
 {
     g_livedev_storage_id = LiveDevStorageRegister("bpfmap", sizeof(void *), NULL, BpfMapsInfoFree);
index a4d167c3afbda7e6852a7ec4f8e44628ac7af861..1c01ad142093cc7205c2b48b9eb7183e4a974f53 100644 (file)
@@ -77,6 +77,10 @@ void EBPFBuildCPUSet(ConfNode *node, char *iface);
 int EBPFSetPeerIface(const char *iface, const char *out_iface);
 
 int EBPFUpdateFlow(Flow *f, Packet *p);
+  
+#ifdef BUILD_UNIX_SOCKET
+TmEcode EBPFGetBypassedStats(json_t *cmd, json_t *answer, void *data);
+#endif
 
 #endif