]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: move config_parse_uplink() to networkd-dhcp-common.[ch]
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 13 Oct 2021 08:15:10 +0000 (17:15 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 26 Oct 2021 11:43:10 +0000 (20:43 +0900)
src/network/networkd-dhcp-common.c
src/network/networkd-dhcp-common.h
src/network/networkd-network.c
src/network/networkd-network.h

index 7a769988eccc80d60363bb7dbfa1a29dde0a407c..3a77a457802db174416162639aeb6a249c559041 100644 (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;
+}
index 2573247db2022e6bbcf5e1e52f2bb43380614471..176f6c04fe0c7eee687dbe5241e3fe3c60df34bd 100644 (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);
index be3c087c8a7abdccc2dc17a876b809a9ce3dc9a4..c3c792eb49862aa086fb7876bc28dbe6cf2e9f3b 100644 (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");
 
index dd9804ea2dbcc5b45f42dda40853efabef62dd2f..3972fc5c89265e27f02401573e2643b99d62759e 100644 (file)
 #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);