diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-07-14 09:50:26 +0200 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-09-15 09:50:23 +0200 |
commit | a093533c33e1d1e497765a505f12de8cee47171e (patch) | |
tree | 82285e7498cd586d249c143282537bf12010cbe7 /src/network/networkd-util.c | |
parent | Respect install_sysconfdir (diff) | |
download | systemd-a093533c33e1d1e497765a505f12de8cee47171e.tar.xz systemd-a093533c33e1d1e497765a505f12de8cee47171e.zip |
network: introduce NetworkConfigSource and NetworkConfigState
These will be used in later commits.
Diffstat (limited to 'src/network/networkd-util.c')
-rw-r--r-- | src/network/networkd-util.c | 52 |
1 files changed, 45 insertions, 7 deletions
diff --git a/src/network/networkd-util.c b/src/network/networkd-util.c index d7906e0cb5..7ac34c18f3 100644 --- a/src/network/networkd-util.c +++ b/src/network/networkd-util.c @@ -10,46 +10,84 @@ #include "string-util.h" #include "web-util.h" -static const char* const address_family_table[_ADDRESS_FAMILY_MAX] = { +/* This is used in log messages, and never used in parsing settings. So, upper cases are OK. */ +static const char * const network_config_source_table[_NETWORK_CONFIG_SOURCE_MAX] = { + [NETWORK_CONFIG_SOURCE_FOREIGN] = "foreign", + [NETWORK_CONFIG_SOURCE_STATIC] = "static", + [NETWORK_CONFIG_SOURCE_IPV4LL] = "IPv4LL", + [NETWORK_CONFIG_SOURCE_DHCP4] = "DHCPv4", + [NETWORK_CONFIG_SOURCE_DHCP6] = "DHCPv6", + [NETWORK_CONFIG_SOURCE_DHCP6PD] = "DHCPv6-PD", + [NETWORK_CONFIG_SOURCE_NDISC] = "NDisc", +}; + +DEFINE_STRING_TABLE_LOOKUP_TO_STRING(network_config_source, NetworkConfigSource); + +int network_config_state_to_string_alloc(NetworkConfigState s, char **ret) { + static const struct { + NetworkConfigState state; + const char *str; + } map[] = { + { .state = NETWORK_CONFIG_STATE_PROBING, .str = "probing", }, + { .state = NETWORK_CONFIG_STATE_REQUESTING, .str = "requesting", }, + { .state = NETWORK_CONFIG_STATE_CONFIGURING, .str = "configuring", }, + { .state = NETWORK_CONFIG_STATE_CONFIGURED, .str = "configured", }, + { .state = NETWORK_CONFIG_STATE_MARKED, .str = "marked", }, + { .state = NETWORK_CONFIG_STATE_REMOVING, .str = "removing", }, + }; + _cleanup_free_ char *buf = NULL; + + assert(ret); + + for (size_t i = 0; i < ELEMENTSOF(map); i++) + if (FLAGS_SET(s, map[i].state) && + !strextend_with_separator(&buf, ",", map[i].str)) + return -ENOMEM; + + *ret = TAKE_PTR(buf); + return 0; +} + +static const char * const address_family_table[_ADDRESS_FAMILY_MAX] = { [ADDRESS_FAMILY_NO] = "no", [ADDRESS_FAMILY_YES] = "yes", [ADDRESS_FAMILY_IPV4] = "ipv4", [ADDRESS_FAMILY_IPV6] = "ipv6", }; -static const char* const routing_policy_rule_address_family_table[_ADDRESS_FAMILY_MAX] = { +static const char * const routing_policy_rule_address_family_table[_ADDRESS_FAMILY_MAX] = { [ADDRESS_FAMILY_YES] = "both", [ADDRESS_FAMILY_IPV4] = "ipv4", [ADDRESS_FAMILY_IPV6] = "ipv6", }; -static const char* const nexthop_address_family_table[_ADDRESS_FAMILY_MAX] = { +static const char * const nexthop_address_family_table[_ADDRESS_FAMILY_MAX] = { [ADDRESS_FAMILY_IPV4] = "ipv4", [ADDRESS_FAMILY_IPV6] = "ipv6", }; -static const char* const duplicate_address_detection_address_family_table[_ADDRESS_FAMILY_MAX] = { +static const char * const duplicate_address_detection_address_family_table[_ADDRESS_FAMILY_MAX] = { [ADDRESS_FAMILY_NO] = "none", [ADDRESS_FAMILY_YES] = "both", [ADDRESS_FAMILY_IPV4] = "ipv4", [ADDRESS_FAMILY_IPV6] = "ipv6", }; -static const char* const dhcp_deprecated_address_family_table[_ADDRESS_FAMILY_MAX] = { +static const char * const dhcp_deprecated_address_family_table[_ADDRESS_FAMILY_MAX] = { [ADDRESS_FAMILY_NO] = "none", [ADDRESS_FAMILY_YES] = "both", [ADDRESS_FAMILY_IPV4] = "v4", [ADDRESS_FAMILY_IPV6] = "v6", }; -static const char* const ip_masquerade_address_family_table[_ADDRESS_FAMILY_MAX] = { +static const char * const ip_masquerade_address_family_table[_ADDRESS_FAMILY_MAX] = { [ADDRESS_FAMILY_NO] = "no", [ADDRESS_FAMILY_YES] = "both", [ADDRESS_FAMILY_IPV4] = "ipv4", [ADDRESS_FAMILY_IPV6] = "ipv6", }; -static const char* const dhcp_lease_server_type_table[_SD_DHCP_LEASE_SERVER_TYPE_MAX] = { +static const char * const dhcp_lease_server_type_table[_SD_DHCP_LEASE_SERVER_TYPE_MAX] = { [SD_DHCP_LEASE_DNS] = "DNS servers", [SD_DHCP_LEASE_NTP] = "NTP servers", [SD_DHCP_LEASE_SIP] = "SIP servers", |