1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-12 09:17:44 +03:00

network: dhcp: use string table

This commit is contained in:
Yu Watanabe 2021-02-11 05:06:19 +09:00
parent 58f99ed8a8
commit bde8467a0d
3 changed files with 13 additions and 10 deletions

View File

@ -283,16 +283,9 @@ int config_parse_dhcp(
/* Previously, we had a slightly different enum here,
* support its values for compatibility. */
if (streq(rvalue, "none"))
s = ADDRESS_FAMILY_NO;
else if (streq(rvalue, "v4"))
s = ADDRESS_FAMILY_IPV4;
else if (streq(rvalue, "v6"))
s = ADDRESS_FAMILY_IPV6;
else if (streq(rvalue, "both"))
s = ADDRESS_FAMILY_YES;
else {
log_syntax(unit, LOG_WARNING, filename, line, 0,
s = dhcp_deprecated_address_family_from_string(rvalue);
if (s < 0) {
log_syntax(unit, LOG_WARNING, filename, line, s,
"Failed to parse DHCP option, ignoring: %s", rvalue);
return 0;
}

View File

@ -28,6 +28,13 @@ static const char* const duplicate_address_detection_address_family_table[_ADDRE
[ADDRESS_FAMILY_IPV6] = "ipv6",
};
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 dhcp_lease_server_type_table[_SD_DHCP_LEASE_SERVER_TYPE_MAX] = {
[SD_DHCP_LEASE_DNS] = "DNS servers",
[SD_DHCP_LEASE_NTP] = "NTP servers",
@ -51,6 +58,7 @@ DEFINE_STRING_TABLE_LOOKUP(routing_policy_rule_address_family, AddressFamily);
DEFINE_STRING_TABLE_LOOKUP(duplicate_address_detection_address_family, AddressFamily);
DEFINE_CONFIG_PARSE_ENUM(config_parse_link_local_address_family, link_local_address_family,
AddressFamily, "Failed to parse option");
DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(dhcp_deprecated_address_family, AddressFamily);
DEFINE_STRING_TABLE_LOOKUP(dhcp_lease_server_type, sd_dhcp_lease_server_type);
int config_parse_address_family_with_kernel(

View File

@ -40,6 +40,8 @@ AddressFamily routing_policy_rule_address_family_from_string(const char *s) _pur
const char *duplicate_address_detection_address_family_to_string(AddressFamily b) _const_;
AddressFamily duplicate_address_detection_address_family_from_string(const char *s) _pure_;
AddressFamily dhcp_deprecated_address_family_from_string(const char *s) _pure_;
const char *dhcp_lease_server_type_to_string(sd_dhcp_lease_server_type t) _const_;
sd_dhcp_lease_server_type dhcp_lease_server_type_from_string(const char *s) _pure_;