#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;
#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;