summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2021-10-13 17:15:10 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2021-10-26 20:43:10 +0900
commit2cba2146ac70bf48b46d9e1a72c576ad94580085 (patch)
tree5b17681cd0b9001319dc49e6f5c1101730d6e872
parent47e9c655b4b79bb03e20648b53c227e62cdd6e74 (diff)
downloadsystemd-2cba2146ac70bf48b46d9e1a72c576ad94580085.tar.gz
network: move config_parse_uplink() to networkd-dhcp-common.[ch]
-rw-r--r--src/network/networkd-dhcp-common.c66
-rw-r--r--src/network/networkd-dhcp-common.h5
-rw-r--r--src/network/networkd-network.c67
-rw-r--r--src/network/networkd-network.h5
4 files changed, 71 insertions, 72 deletions
diff --git a/src/network/networkd-dhcp-common.c b/src/network/networkd-dhcp-common.c
index 7a769988ec..3a77a45780 100644
--- a/src/network/networkd-dhcp-common.c
+++ b/src/network/networkd-dhcp-common.c
@@ -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;
+}
diff --git a/src/network/networkd-dhcp-common.h b/src/network/networkd-dhcp-common.h
index 2573247db2..176f6c04fe 100644
--- a/src/network/networkd-dhcp-common.h
+++ b/src/network/networkd-dhcp-common.h
@@ -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);
diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c
index be3c087c8a..c3c792eb49 100644
--- a/src/network/networkd-network.c
+++ b/src/network/networkd-network.c
@@ -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");
diff --git a/src/network/networkd-network.h b/src/network/networkd-network.h
index dd9804ea2d..3972fc5c89 100644
--- a/src/network/networkd-network.h
+++ b/src/network/networkd-network.h
@@ -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);