]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
networkd: lldp: use string table
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 10 Feb 2021 19:34:14 +0000 (04:34 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 11 Feb 2021 16:19:13 +0000 (01:19 +0900)
src/network/networkd-lldp-tx.c
src/network/networkd-lldp-tx.h

index de61e5119bfdaac1e48f5c2f56503ac83315d15b..1b97e6584e2235226bfce52314a9dd201d3ea7e4 100644 (file)
@@ -17,6 +17,7 @@
 #include "parse-util.h"
 #include "random-util.h"
 #include "socket-util.h"
+#include "string-table.h"
 #include "string-util.h"
 #include "strv.h"
 #include "unaligned.h"
@@ -415,46 +416,6 @@ void link_lldp_emit_stop(Link *link) {
         link->lldp_emit_event_source = sd_event_source_unref(link->lldp_emit_event_source);
 }
 
-int config_parse_lldp_emit(
-                const char *unit,
-                const char *filename,
-                unsigned line,
-                const char *section,
-                unsigned section_line,
-                const char *lvalue,
-                int ltype,
-                const char *rvalue,
-                void *data,
-                void *userdata) {
-
-        LLDPEmit *emit = data;
-        int r;
-
-        assert(filename);
-        assert(lvalue);
-        assert(rvalue);
-
-        if (isempty(rvalue))
-                *emit = LLDP_EMIT_NO;
-        else if (streq(rvalue, "nearest-bridge"))
-                *emit = LLDP_EMIT_NEAREST_BRIDGE;
-        else if (streq(rvalue, "non-tpmr-bridge"))
-                *emit = LLDP_EMIT_NON_TPMR_BRIDGE;
-        else if (streq(rvalue, "customer-bridge"))
-                *emit = LLDP_EMIT_CUSTOMER_BRIDGE;
-        else {
-                r = parse_boolean(rvalue);
-                if (r < 0) {
-                        log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse LLDP emission setting, ignoring: %s", rvalue);
-                        return 0;
-                }
-
-                *emit = r ? LLDP_EMIT_NEAREST_BRIDGE : LLDP_EMIT_NO;
-        }
-
-        return 0;
-}
-
 int config_parse_lldp_mud(
                 const char *unit,
                 const char *filename,
@@ -491,3 +452,13 @@ int config_parse_lldp_mud(
 
         return free_and_replace(n->lldp_mud, unescaped);
 }
+
+static const char * const lldp_emit_table[_LLDP_EMIT_MAX] = {
+        [LLDP_EMIT_NO]              = "no",
+        [LLDP_EMIT_NEAREST_BRIDGE]  = "nearest-bridge",
+        [LLDP_EMIT_NON_TPMR_BRIDGE] = "non-tpmr-bridge",
+        [LLDP_EMIT_CUSTOMER_BRIDGE] = "customer-bridge",
+};
+
+DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING_WITH_BOOLEAN(lldp_emit, LLDPEmit, LLDP_EMIT_NEAREST_BRIDGE);
+DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_lldp_emit, lldp_emit, LLDPEmit, LLDP_EMIT_NO, "Failed to parse LLDP emission setting");
index aae30cba0f97e2e38d00127aa30ab4cb32c4a01c..b8917f9de8cb9aca9c3e6b54a68608e10cdc7311 100644 (file)
@@ -13,6 +13,7 @@ typedef enum LLDPEmit {
         LLDP_EMIT_NON_TPMR_BRIDGE,
         LLDP_EMIT_CUSTOMER_BRIDGE,
         _LLDP_EMIT_MAX,
+        _LLDP_EMIT_INVALID = -EINVAL,
 } LLDPEmit;
 
 bool link_lldp_emit_enabled(Link *link);