]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/core/dbus-unit.c
core: use string_table_lookup() at more places
[thirdparty/systemd.git] / src / core / dbus-unit.c
index 6f1a74d6b5605abf319deb55a9fc8fa14e0d0c37..d34833f4ffee5688d3b69c406abbd685301ac7b6 100644 (file)
@@ -19,6 +19,7 @@
 #include "selinux-access.h"
 #include "signal-util.h"
 #include "special.h"
+#include "string-table.h"
 #include "string-util.h"
 #include "strv.h"
 #include "user-util.h"
@@ -1029,26 +1030,23 @@ static int property_get_ip_counter(
                 void *userdata,
                 sd_bus_error *error) {
 
-        CGroupIPAccountingMetric metric;
-        uint64_t value = (uint64_t) -1;
+        static const char *const table[_CGROUP_IP_ACCOUNTING_METRIC_MAX] = {
+                [CGROUP_IP_INGRESS_BYTES]   = "IPIngressBytes",
+                [CGROUP_IP_EGRESS_BYTES]    = "IPEgressBytes",
+                [CGROUP_IP_INGRESS_PACKETS] = "IPIngressPackets",
+                [CGROUP_IP_EGRESS_PACKETS]  = "IPEgressPackets",
+        };
+
+        uint64_t value = UINT64_MAX;
         Unit *u = userdata;
+        ssize_t metric;
 
         assert(bus);
         assert(reply);
         assert(property);
         assert(u);
 
-        if (streq(property, "IPIngressBytes"))
-                metric = CGROUP_IP_INGRESS_BYTES;
-        else if (streq(property, "IPIngressPackets"))
-                metric = CGROUP_IP_INGRESS_PACKETS;
-        else if (streq(property, "IPEgressBytes"))
-                metric = CGROUP_IP_EGRESS_BYTES;
-        else {
-                assert(streq(property, "IPEgressPackets"));
-                metric = CGROUP_IP_EGRESS_PACKETS;
-        }
-
+        assert_se((metric = string_table_lookup(table, ELEMENTSOF(table), property)) >= 0);
         (void) unit_get_ip_accounting(u, metric, &value);
         return sd_bus_message_append(reply, "t", value);
 }