diff options
-rw-r--r-- | man/systemd.network.xml | 4 | ||||
-rw-r--r-- | network/80-container-host0.network | 2 | ||||
-rw-r--r-- | src/network/networkd-dhcp4.c | 2 | ||||
-rw-r--r-- | src/network/networkd-link.c | 6 | ||||
-rw-r--r-- | src/network/networkd-manager.c | 32 | ||||
-rw-r--r-- | src/network/networkd-network.c | 47 | ||||
-rw-r--r-- | src/network/networkd.h | 24 | ||||
-rw-r--r-- | src/network/test-network-tables.c | 2 |
8 files changed, 71 insertions, 48 deletions
diff --git a/man/systemd.network.xml b/man/systemd.network.xml index 9392089235..484d6f31c7 100644 --- a/man/systemd.network.xml +++ b/man/systemd.network.xml @@ -220,8 +220,8 @@ <term><varname>DHCP=</varname></term> <listitem> <para>Enables DHCPv4 and/or DHCPv6 support. Accepts - <literal>both</literal>, <literal>none</literal>, - <literal>v4</literal> or <literal>v6</literal>.</para> + <literal>yes</literal>, <literal>no</literal>, + <literal>ipv4</literal> or <literal>ipv6</literal>.</para> </listitem> </varlistentry> <varlistentry> diff --git a/network/80-container-host0.network b/network/80-container-host0.network index 6863ca9ce9..8d9293f239 100644 --- a/network/80-container-host0.network +++ b/network/80-container-host0.network @@ -10,5 +10,5 @@ Virtualization=container Name=host0 [Network] -DHCP=both +DHCP=yes IPv4LL=yes diff --git a/src/network/networkd-dhcp4.c b/src/network/networkd-dhcp4.c index 1c2edc5b87..c3d0e3d39d 100644 --- a/src/network/networkd-dhcp4.c +++ b/src/network/networkd-dhcp4.c @@ -586,7 +586,7 @@ int dhcp4_configure(Link *link) { assert(link); assert(link->network); - assert(IN_SET(link->network->dhcp, DHCP_SUPPORT_BOTH, DHCP_SUPPORT_V4)); + assert(IN_SET(link->network->dhcp, ADDRESS_FAMILY_YES, ADDRESS_FAMILY_IPV4)); r = sd_dhcp_client_new(&link->dhcp_client); if (r < 0) diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index 12944a03a3..1e2596749f 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -42,7 +42,7 @@ static bool link_dhcp6_enabled(Link *link) { if (!link->network) return false; - return IN_SET(link->network->dhcp, DHCP_SUPPORT_V6, DHCP_SUPPORT_BOTH); + return IN_SET(link->network->dhcp, ADDRESS_FAMILY_IPV6, ADDRESS_FAMILY_YES); } static bool link_dhcp4_enabled(Link *link) { @@ -52,7 +52,7 @@ static bool link_dhcp4_enabled(Link *link) { if (!link->network) return false; - return IN_SET(link->network->dhcp, DHCP_SUPPORT_V4, DHCP_SUPPORT_BOTH); + return IN_SET(link->network->dhcp, ADDRESS_FAMILY_IPV4, ADDRESS_FAMILY_YES); } static bool link_dhcp4_server_enabled(Link *link) { @@ -1331,7 +1331,7 @@ static int link_initialized_and_synced(sd_rtnl *rtnl, sd_rtnl_message *m, if (network->ipv4ll) log_link_debug(link, "ignoring IPv4LL for loopback link"); - if (network->dhcp != DHCP_SUPPORT_NONE) + if (network->dhcp != ADDRESS_FAMILY_NO) log_link_debug(link, "ignoring DHCP clients for loopback link"); if (network->dhcp_server) diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c index 6aab427564..42b51137ef 100644 --- a/src/network/networkd-manager.c +++ b/src/network/networkd-manager.c @@ -654,3 +654,35 @@ int manager_address_pool_acquire(Manager *m, int family, unsigned prefixlen, uni return 0; } + +const char *address_family_boolean_to_string(AddressFamilyBoolean b) { + if (b == ADDRESS_FAMILY_YES || + b == ADDRESS_FAMILY_NO) + return yes_no(b == ADDRESS_FAMILY_YES); + + if (b == ADDRESS_FAMILY_IPV4) + return "ipv4"; + if (b == ADDRESS_FAMILY_IPV6) + return "ipv6"; + + return NULL; +} + +AddressFamilyBoolean address_family_boolean_from_string(const char *s) { + int r; + + /* Make this a true superset of a boolean */ + + r = parse_boolean(s); + if (r > 0) + return ADDRESS_FAMILY_YES; + if (r == 0) + return ADDRESS_FAMILY_NO; + + if (streq(s, "ipv4")) + return ADDRESS_FAMILY_IPV4; + if (streq(s, "ipv6")) + return ADDRESS_FAMILY_IPV6; + + return _ADDRESS_FAMILY_BOOLEAN_INVALID; +} diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c index d6504cc178..98f199ad72 100644 --- a/src/network/networkd-network.c +++ b/src/network/networkd-network.c @@ -84,7 +84,7 @@ static int network_load_one(Manager *manager, const char *filename) { if (!network->filename) return log_oom(); - network->dhcp = DHCP_SUPPORT_NONE; + network->dhcp = ADDRESS_FAMILY_NO; network->dhcp_ntp = true; network->dhcp_dns = true; network->dhcp_hostname = true; @@ -470,15 +470,6 @@ int config_parse_tunnel(const char *unit, return 0; } -static const char* const dhcp_support_table[_DHCP_SUPPORT_MAX] = { - [DHCP_SUPPORT_NONE] = "none", - [DHCP_SUPPORT_BOTH] = "both", - [DHCP_SUPPORT_V4] = "v4", - [DHCP_SUPPORT_V6] = "v6", -}; - -DEFINE_STRING_TABLE_LOOKUP(dhcp_support, DHCPSupport); - int config_parse_dhcp( const char* unit, const char *filename, @@ -491,34 +482,34 @@ int config_parse_dhcp( void *data, void *userdata) { - DHCPSupport *dhcp = data; - int k; + AddressFamilyBoolean *dhcp = data, s; assert(filename); assert(lvalue); assert(rvalue); assert(data); - /* Our enum shall be a superset of booleans, hence first try - * to parse as boolean, and then as enum */ - - k = parse_boolean(rvalue); - if (k > 0) - *dhcp = DHCP_SUPPORT_BOTH; - else if (k == 0) - *dhcp = DHCP_SUPPORT_NONE; - else { - DHCPSupport s; - - s = dhcp_support_from_string(rvalue); - if (s < 0){ - log_syntax(unit, LOG_ERR, filename, line, -s, "Failed to parse DHCP option, ignoring: %s", rvalue); + s = address_family_boolean_from_string(rvalue); + if (s < 0) { + + /* Previously, we had a slightly different enum here, + * support its values for compatbility. */ + + 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_ERR, filename, line, s, "Failed to parse DHCP option, ignoring: %s", rvalue); return 0; } - - *dhcp = s; } + *dhcp = s; return 0; } diff --git a/src/network/networkd.h b/src/network/networkd.h index 39b2d2bec9..b36590e2d6 100644 --- a/src/network/networkd.h +++ b/src/network/networkd.h @@ -54,14 +54,14 @@ typedef struct Manager Manager; typedef struct AddressPool AddressPool; typedef struct FdbEntry FdbEntry; -typedef enum DHCPSupport { - DHCP_SUPPORT_NONE, - DHCP_SUPPORT_BOTH, - DHCP_SUPPORT_V4, - DHCP_SUPPORT_V6, - _DHCP_SUPPORT_MAX, - _DHCP_SUPPORT_INVALID = -1, -} DHCPSupport; +typedef enum AddressFamilyBoolean { + ADDRESS_FAMILY_NO, + ADDRESS_FAMILY_YES, + ADDRESS_FAMILY_IPV4, + ADDRESS_FAMILY_IPV6, + _ADDRESS_FAMILY_BOOLEAN_MAX, + _ADDRESS_FAMILY_BOOLEAN_INVALID = -1, +} AddressFamilyBoolean; typedef enum LLMNRSupport { LLMNR_SUPPORT_NO, @@ -102,7 +102,7 @@ struct Network { NetDev *bridge; NetDev *bond; Hashmap *stacked_netdevs; - DHCPSupport dhcp; + AddressFamilyBoolean dhcp; bool dhcp_dns; bool dhcp_ntp; bool dhcp_mtu; @@ -368,9 +368,6 @@ int config_parse_fdb_vlan_id(const char *unit, const char *filename, unsigned li /* DHCP support */ -const char* dhcp_support_to_string(DHCPSupport i) _const_; -DHCPSupport dhcp_support_from_string(const char *s) _pure_; - int config_parse_dhcp(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); @@ -391,3 +388,6 @@ int address_pool_new_from_string(Manager *m, AddressPool **ret, int family, cons void address_pool_free(AddressPool *p); int address_pool_acquire(AddressPool *p, unsigned prefixlen, union in_addr_union *found); + +const char *address_family_boolean_to_string(AddressFamilyBoolean b) _const_; +AddressFamilyBoolean address_family_boolean_from_string(const char *s) _const_; diff --git a/src/network/test-network-tables.c b/src/network/test-network-tables.c index 4d55434f03..d1e475a4c0 100644 --- a/src/network/test-network-tables.c +++ b/src/network/test-network-tables.c @@ -13,7 +13,7 @@ int main(int argc, char **argv) { test_table(bond_mode, NETDEV_BOND_MODE); /* test_table(link_state, LINK_STATE); -- not a reversible mapping */ test_table(link_operstate, LINK_OPERSTATE); - test_table(dhcp_support, DHCP_SUPPORT); + test_table(address_family_boolean, ADDRESS_FAMILY_BOOLEAN); test_table(netdev_kind, NETDEV_KIND); test_table(dhcp6_message_status, DHCP6_STATUS); test_table(duplex, DUP); |