network: move config_parse_uplink() to networkd-dhcp-common.[ch]

This commit is contained in:
Yu Watanabe
2021-10-26 20:43:10 +09:00
parent 47e9c655b4
commit 2cba2146ac
4 changed files with 71 additions and 72 deletions
+66
View File
@@ -1267,3 +1267,69 @@ int config_parse_network_duid_rawdata(
/* For backward compatibility, also set DHCPv6 DUID if not specified explicitly. */
return config_parse_duid_rawdata(unit, filename, line, section, section_line, lvalue, false, rvalue, &network->dhcp6_duid, network);
}
int config_parse_uplink(
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) {
Network *network = userdata;
int *index, r;
char **name;
assert(filename);
assert(section);
assert(lvalue);
assert(rvalue);
if (streq(section, "DHCPServer")) {
index = &network->dhcp_server_uplink_index;
name = &network->dhcp_server_uplink_name;
} else if (streq(section, "IPv6SendRA")) {
index = &network->router_uplink_index;
name = &network->router_uplink_name;
} else
assert_not_reached();
if (isempty(rvalue) || streq(rvalue, ":auto")) {
*index = UPLINK_INDEX_AUTO;
*name = mfree(*name);
return 0;
}
if (streq(rvalue, ":none")) {
*index = UPLINK_INDEX_NONE;
*name = mfree(*name);
return 0;
}
r = parse_ifindex(rvalue);
if (r > 0) {
*index = r;
*name = mfree(*name);
return 0;
}
if (!ifname_valid_full(rvalue, IFNAME_VALID_ALTERNATIVE)) {
log_syntax(unit, LOG_WARNING, filename, line, 0,
"Invalid interface name in %s=, ignoring assignment: %s", lvalue, rvalue);
return 0;
}
/* The interface name will be resolved later. */
r = free_and_strdup_warn(name, rvalue);
if (r < 0)
return r;
/* Note, if uplink_name is set, then uplink_index will be ignored. So, the below does not mean
* an uplink interface will be selected automatically. */
*index = UPLINK_INDEX_AUTO;
return 0;
}
+5
View File
@@ -9,6 +9,10 @@
#include "set.h"
#include "time-util.h"
/* Special values for *_uplink_index. */
#define UPLINK_INDEX_AUTO 0 /* uplink will be selected automatically */
#define UPLINK_INDEX_NONE -1 /* uplink will not be selected automatically */
#define DHCP_ROUTE_METRIC 1024
#define DHCP6PD_ROUTE_METRIC 256
@@ -100,3 +104,4 @@ CONFIG_PARSER_PROTOTYPE(config_parse_network_duid_type);
CONFIG_PARSER_PROTOTYPE(config_parse_duid_rawdata);
CONFIG_PARSER_PROTOTYPE(config_parse_manager_duid_rawdata);
CONFIG_PARSER_PROTOTYPE(config_parse_network_duid_rawdata);
CONFIG_PARSER_PROTOTYPE(config_parse_uplink);
-67
View File
@@ -1245,73 +1245,6 @@ int config_parse_link_group(
return 0;
}
int config_parse_uplink(
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) {
Network *network = userdata;
int *index, r;
char **name;
assert(filename);
assert(section);
assert(lvalue);
assert(rvalue);
if (streq(section, "DHCPServer")) {
index = &network->dhcp_server_uplink_index;
name = &network->dhcp_server_uplink_name;
} else if (streq(section, "IPv6SendRA")) {
index = &network->router_uplink_index;
name = &network->router_uplink_name;
} else
assert_not_reached();
if (isempty(rvalue) || streq(rvalue, ":auto")) {
*index = UPLINK_INDEX_AUTO;
*name = mfree(*name);
return 0;
}
if (streq(rvalue, ":none")) {
*index = UPLINK_INDEX_NONE;
*name = mfree(*name);
return 0;
}
r = parse_ifindex(rvalue);
if (r > 0) {
*index = r;
*name = mfree(*name);
return 0;
}
if (!ifname_valid_full(rvalue, IFNAME_VALID_ALTERNATIVE)) {
log_syntax(unit, LOG_WARNING, filename, line, 0,
"Invalid interface name in %s=, ignoring assignment: %s", lvalue, rvalue);
return 0;
}
/* The interface name will be resolved later. */
r = free_and_strdup_warn(name, rvalue);
if (r < 0)
return r;
/* Note, if uplink_name is set, then uplink_index will be ignored. So, the below does not mean
* an uplink interface will be selected automatically. */
*index = UPLINK_INDEX_AUTO;
return 0;
}
DEFINE_CONFIG_PARSE_ENUM(config_parse_required_family_for_online, link_required_address_family, AddressFamily,
"Failed to parse RequiredFamilyForOnline= setting");
-5
View File
@@ -26,10 +26,6 @@
#include "resolve-util.h"
#include "socket-netlink.h"
/* Special values for *_uplink_index. */
#define UPLINK_INDEX_AUTO 0 /* uplink will be selected automatically */
#define UPLINK_INDEX_NONE -1 /* uplink will not be selected automatically */
typedef enum KeepConfiguration {
KEEP_CONFIGURATION_NO = 0,
KEEP_CONFIGURATION_DHCP_ON_START = 1 << 0,
@@ -385,7 +381,6 @@ CONFIG_PARSER_PROTOTYPE(config_parse_keep_configuration);
CONFIG_PARSER_PROTOTYPE(config_parse_ipv6_link_local_address_gen_mode);
CONFIG_PARSER_PROTOTYPE(config_parse_activation_policy);
CONFIG_PARSER_PROTOTYPE(config_parse_link_group);
CONFIG_PARSER_PROTOTYPE(config_parse_uplink);
const struct ConfigPerfItem* network_network_gperf_lookup(const char *key, GPERF_LEN_TYPE length);