]> git.ipfire.org Git - network.git/commitdiff
ports: bonding: Convert mode to string table
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 8 Jun 2023 15:12:00 +0000 (15:12 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 8 Jun 2023 15:12:00 +0000 (15:12 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/networkd/port-bonding.c
src/networkd/port-bonding.h

index a2e0fc3f84acb4e6001ea02058706f229308a6fb..e7657919844c66db3c01e93d400ab44622a285e2 100644 (file)
 #include "port-bonding.h"
 #include "string.h"
 
-const struct nw_port_bonding_mode {
-       const int mode;
-       const char* string;
-} nw_port_bonding_modes[] = {
-       { BOND_MODE_ROUNDROBIN,   "round-robin" },
-       { BOND_MODE_ACTIVEBACKUP, "active-backup" },
-       { BOND_MODE_XOR,          "xor" },
-       { BOND_MODE_BROADCAST,    "broadcast" },
-       { BOND_MODE_8023AD,       "802.3ad" },
-       { BOND_MODE_TLB,          "tlb" },
-       { BOND_MODE_ALB,          "alb" },
+const struct nw_string_table nw_port_bonding_mode[] = {
+       { NW_BONDING_MODE_ROUNDROBIN,   "round-robin" },
+       { NW_BONDING_MODE_ACTIVEBACKUP, "active-backup" },
+       { NW_BONDING_MODE_XOR,          "xor" },
+       { NW_BONDING_MODE_BROADCAST,    "broadcast" },
+       { NW_BONDING_MODE_8023AD,       "802.3ad" },
+       { NW_BONDING_MODE_TLB,          "tlb" },
+       { NW_BONDING_MODE_ALB,          "alb" },
        { -1, NULL },
 };
 
-static int nw_port_bonding_mode_from_string(const char* string) {
-       const struct nw_port_bonding_mode* m = NULL;
-
-       for (m = nw_port_bonding_modes; m->string; m++) {
-               if (strcmp(m->string, string) == 0)
-                       return m->mode;
-       }
-
-       return -1;
-}
-
-static const char* nw_port_bonding_mode_to_string(const int mode) {
-       const struct nw_port_bonding_mode* m = NULL;
-
-       for (m = nw_port_bonding_modes; m->string; m++) {
-               if (m->mode == mode)
-                       return m->string;
-       }
-
-       return NULL;
-}
+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;
index 5cd2c43365a88c97a45b9fc689fc5cee612ba44f..e21c251d131ee581ac0485855e12f7a472c32b06 100644 (file)
 
 #include "port.h"
 
+typedef enum nw_port_bonding_mode {
+       NW_BONDING_MODE_ROUNDROBIN   = BOND_MODE_ROUNDROBIN,
+       NW_BONDING_MODE_ACTIVEBACKUP = BOND_MODE_ACTIVEBACKUP,
+       NW_BONDING_MODE_XOR          = BOND_MODE_XOR,
+       NW_BONDING_MODE_BROADCAST    = BOND_MODE_BROADCAST,
+       NW_BONDING_MODE_8023AD       = BOND_MODE_8023AD,
+       NW_BONDING_MODE_TLB          = BOND_MODE_TLB,
+       NW_BONDING_MODE_ALB          = BOND_MODE_ALB,
+} nw_port_bonding_mode_t;
+
 struct nw_port_bonding {
-       int mode;
+       nw_port_bonding_mode_t mode;
 };
 
 extern const nw_port_info_t nw_port_info_bonding;