]> git.ipfire.org Git - network.git/blobdiff - src/networkd/port-bonding.c
config: Implement option that looks up string tables
[network.git] / src / networkd / port-bonding.c
index e7657919844c66db3c01e93d400ab44622a285e2..4e4c8a71786ba688afa637aceb843e32cfc16a8b 100644 (file)
@@ -27,7 +27,7 @@
 #include "port-bonding.h"
 #include "string.h"
 
-const struct nw_string_table nw_port_bonding_mode[] = {
+const nw_string_table_t nw_port_bonding_mode[] = {
        { NW_BONDING_MODE_ROUNDROBIN,   "round-robin" },
        { NW_BONDING_MODE_ACTIVEBACKUP, "active-backup" },
        { NW_BONDING_MODE_XOR,          "xor" },
@@ -40,31 +40,12 @@ const struct nw_string_table nw_port_bonding_mode[] = {
 
 NW_STRING_TABLE_LOOKUP(nw_port_bonding_mode_t, nw_port_bonding_mode)
 
-static int nw_port_bonding_read_mode(nw_config* config, const char* key, void* data) {
-       int* mode = (int*)data;
-
-       const char* value = nw_config_get(config, key);
-       if (value) {
-               *mode = nw_port_bonding_mode_from_string(value);
-               if (!*mode)
-                       return -errno;
-       }
-
-       return 0;
-}
-
-static int nw_port_bonding_write_mode(nw_config* config, const char* key, const void* data) {
-       const int* mode = (int*)data;
-
-       return nw_config_set(config, key, nw_port_bonding_mode_to_string(*mode));
-}
-
 static int nw_port_bonding_setup(nw_port* port) {
        int r;
 
        // Mode
-       r = NW_CONFIG_OPTION(port->config, "BONDING_MODE", &port->bonding.mode,
-                       nw_port_bonding_read_mode, nw_port_bonding_write_mode);
+       r = NW_CONFIG_OPTION_STRING_TABLE(port->config,
+                       "BONDING_MODE", &port->bonding.mode, nw_port_bonding_mode);
        if (r < 0)
                return r;