mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-22 13:33:56 +03:00
networkd: introduce an AddressFamilyBoolean enum type
This introduces am AddressFamilyBoolean type that works more or less like a booleaan, but can optionally turn on/off things for ipv4 and ipv6 independently. THis also ports the DHCP field over to it.
This commit is contained in:
parent
66518acd40
commit
cb9fc36a12
@ -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>
|
||||
|
@ -10,5 +10,5 @@ Virtualization=container
|
||||
Name=host0
|
||||
|
||||
[Network]
|
||||
DHCP=both
|
||||
DHCP=yes
|
||||
IPv4LL=yes
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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 */
|
||||
s = address_family_boolean_from_string(rvalue);
|
||||
if (s < 0) {
|
||||
|
||||
k = parse_boolean(rvalue);
|
||||
if (k > 0)
|
||||
*dhcp = DHCP_SUPPORT_BOTH;
|
||||
else if (k == 0)
|
||||
*dhcp = DHCP_SUPPORT_NONE;
|
||||
else {
|
||||
DHCPSupport s;
|
||||
/* Previously, we had a slightly different enum here,
|
||||
* support its values for compatbility. */
|
||||
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -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_;
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user