]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: move dhcp related conf parsers to networkd-dhcp-common.c
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 9 Apr 2021 11:11:33 +0000 (20:11 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 21 Apr 2021 11:56:58 +0000 (20:56 +0900)
src/network/networkd-conf.c
src/network/networkd-conf.h
src/network/networkd-dhcp-common.c
src/network/networkd-dhcp-common.h
src/network/networkd-gperf.gperf
src/network/networkd-network-gperf.gperf

index c413f167394e811da0c9f308434fefa897b2e0f3..7907fa81403125b6d649c4942c81d78cadfa2870 100644 (file)
@@ -3,20 +3,11 @@
   Copyright © 2014 Vinay Kulkarni <kulkarniv@vmware.com>
  ***/
 
-#include <ctype.h>
-#include <netinet/ip.h>
-
 #include "conf-parser.h"
 #include "def.h"
-#include "dhcp-identifier.h"
-#include "extract-word.h"
-#include "hexdecoct.h"
 #include "networkd-conf.h"
 #include "networkd-manager.h"
-#include "networkd-network.h"
 #include "networkd-speed-meter.h"
-#include "networkd-dhcp4.h"
-#include "string-table.h"
 
 int manager_parse_config_file(Manager *m) {
         int r;
@@ -45,147 +36,3 @@ int manager_parse_config_file(Manager *m) {
 
         return 0;
 }
-
-static const char* const duid_type_table[_DUID_TYPE_MAX] = {
-        [DUID_TYPE_LLT]  = "link-layer-time",
-        [DUID_TYPE_EN]   = "vendor",
-        [DUID_TYPE_LL]   = "link-layer",
-        [DUID_TYPE_UUID] = "uuid",
-};
-DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(duid_type, DUIDType);
-
-int config_parse_duid_type(
-                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) {
-
-        _cleanup_free_ char *type_string = NULL;
-        const char *p = rvalue;
-        DUID *duid = data;
-        DUIDType type;
-        int r;
-
-        assert(filename);
-        assert(lvalue);
-        assert(rvalue);
-        assert(duid);
-
-        r = extract_first_word(&p, &type_string, ":", 0);
-        if (r == -ENOMEM)
-                return log_oom();
-        if (r < 0) {
-                log_syntax(unit, LOG_WARNING, filename, line, r,
-                           "Invalid syntax, ignoring: %s", rvalue);
-                return 0;
-        }
-        if (r == 0) {
-                log_syntax(unit, LOG_WARNING, filename, line, 0,
-                           "Failed to extract DUID type from '%s', ignoring.", rvalue);
-                return 0;
-        }
-
-        type = duid_type_from_string(type_string);
-        if (type < 0) {
-                log_syntax(unit, LOG_WARNING, filename, line, type,
-                           "Failed to parse DUID type '%s', ignoring.", type_string);
-                return 0;
-        }
-
-        if (!isempty(p)) {
-                usec_t u;
-
-                if (type != DUID_TYPE_LLT) {
-                        log_syntax(unit, LOG_WARNING, filename, line, r,
-                                   "Invalid syntax, ignoring: %s", rvalue);
-                        return 0;
-                }
-
-                r = parse_timestamp(p, &u);
-                if (r < 0) {
-                        log_syntax(unit, LOG_WARNING, filename, line, r,
-                                   "Failed to parse timestamp, ignoring: %s", p);
-                        return 0;
-                }
-
-                duid->llt_time = u;
-        }
-
-        duid->type = type;
-
-        return 0;
-}
-
-int config_parse_duid_rawdata(
-                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) {
-
-        DUID *ret = data;
-        uint8_t raw_data[MAX_DUID_LEN];
-        unsigned count = 0;
-
-        assert(filename);
-        assert(lvalue);
-        assert(rvalue);
-        assert(ret);
-
-        /* RawData contains DUID in format "NN:NN:NN..." */
-        for (const char *p = rvalue;;) {
-                int n1, n2, len, r;
-                uint32_t byte;
-                _cleanup_free_ char *cbyte = NULL;
-
-                r = extract_first_word(&p, &cbyte, ":", 0);
-                if (r == -ENOMEM)
-                        return log_oom();
-                if (r < 0) {
-                        log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to read DUID, ignoring assignment: %s.", rvalue);
-                        return 0;
-                }
-                if (r == 0)
-                        break;
-
-                if (count >= MAX_DUID_LEN) {
-                        log_syntax(unit, LOG_WARNING, filename, line, 0, "Max DUID length exceeded, ignoring assignment: %s.", rvalue);
-                        return 0;
-                }
-
-                len = strlen(cbyte);
-                if (!IN_SET(len, 1, 2)) {
-                        log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid length - DUID byte: %s, ignoring assignment: %s.", cbyte, rvalue);
-                        return 0;
-                }
-                n1 = unhexchar(cbyte[0]);
-                if (len == 2)
-                        n2 = unhexchar(cbyte[1]);
-                else
-                        n2 = 0;
-
-                if (n1 < 0 || n2 < 0) {
-                        log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid DUID byte: %s. Ignoring assignment: %s.", cbyte, rvalue);
-                        return 0;
-                }
-
-                byte = ((uint8_t) n1 << (4 * (len-1))) | (uint8_t) n2;
-                raw_data[count++] = byte;
-        }
-
-        assert_cc(sizeof(raw_data) == sizeof(ret->raw_data));
-        memcpy(ret->raw_data, raw_data, count);
-        ret->raw_data_len = count;
-        return 0;
-}
index b485e9e5418c695a8ba70bbad14b0f7cac388fbf..6f8612ac9191f0c874d1c1e6afc087fe4d5ecd45 100644 (file)
@@ -12,6 +12,3 @@ typedef struct Manager Manager;
 int manager_parse_config_file(Manager *m);
 
 const struct ConfigPerfItem* networkd_gperf_lookup(const char *key, GPERF_LEN_TYPE length);
-
-CONFIG_PARSER_PROTOTYPE(config_parse_duid_type);
-CONFIG_PARSER_PROTOTYPE(config_parse_duid_rawdata);
index bb0b2044677d0ea8e4fcb482aabffded97fceb97..12bdda512941b0c55d175c0b58ea82ff0ec6339f 100644 (file)
@@ -4,9 +4,11 @@
 #include <linux/if_arp.h>
 
 #include "bus-error.h"
+#include "dhcp-identifier.h"
 #include "dhcp-internal.h"
 #include "dhcp6-internal.h"
 #include "escape.h"
+#include "hexdecoct.h"
 #include "in-addr-util.h"
 #include "networkd-dhcp-common.h"
 #include "networkd-link.h"
@@ -924,3 +926,147 @@ static const char * const dhcp_option_data_type_table[_DHCP_OPTION_DATA_MAX] = {
 };
 
 DEFINE_STRING_TABLE_LOOKUP(dhcp_option_data_type, DHCPOptionDataType);
+
+static const char* const duid_type_table[_DUID_TYPE_MAX] = {
+        [DUID_TYPE_LLT]  = "link-layer-time",
+        [DUID_TYPE_EN]   = "vendor",
+        [DUID_TYPE_LL]   = "link-layer",
+        [DUID_TYPE_UUID] = "uuid",
+};
+DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(duid_type, DUIDType);
+
+int config_parse_duid_type(
+                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) {
+
+        _cleanup_free_ char *type_string = NULL;
+        const char *p = rvalue;
+        DUID *duid = data;
+        DUIDType type;
+        int r;
+
+        assert(filename);
+        assert(lvalue);
+        assert(rvalue);
+        assert(duid);
+
+        r = extract_first_word(&p, &type_string, ":", 0);
+        if (r == -ENOMEM)
+                return log_oom();
+        if (r < 0) {
+                log_syntax(unit, LOG_WARNING, filename, line, r,
+                           "Invalid syntax, ignoring: %s", rvalue);
+                return 0;
+        }
+        if (r == 0) {
+                log_syntax(unit, LOG_WARNING, filename, line, 0,
+                           "Failed to extract DUID type from '%s', ignoring.", rvalue);
+                return 0;
+        }
+
+        type = duid_type_from_string(type_string);
+        if (type < 0) {
+                log_syntax(unit, LOG_WARNING, filename, line, type,
+                           "Failed to parse DUID type '%s', ignoring.", type_string);
+                return 0;
+        }
+
+        if (!isempty(p)) {
+                usec_t u;
+
+                if (type != DUID_TYPE_LLT) {
+                        log_syntax(unit, LOG_WARNING, filename, line, r,
+                                   "Invalid syntax, ignoring: %s", rvalue);
+                        return 0;
+                }
+
+                r = parse_timestamp(p, &u);
+                if (r < 0) {
+                        log_syntax(unit, LOG_WARNING, filename, line, r,
+                                   "Failed to parse timestamp, ignoring: %s", p);
+                        return 0;
+                }
+
+                duid->llt_time = u;
+        }
+
+        duid->type = type;
+
+        return 0;
+}
+
+int config_parse_duid_rawdata(
+                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) {
+
+        DUID *ret = data;
+        uint8_t raw_data[MAX_DUID_LEN];
+        unsigned count = 0;
+
+        assert(filename);
+        assert(lvalue);
+        assert(rvalue);
+        assert(ret);
+
+        /* RawData contains DUID in format "NN:NN:NN..." */
+        for (const char *p = rvalue;;) {
+                int n1, n2, len, r;
+                uint32_t byte;
+                _cleanup_free_ char *cbyte = NULL;
+
+                r = extract_first_word(&p, &cbyte, ":", 0);
+                if (r == -ENOMEM)
+                        return log_oom();
+                if (r < 0) {
+                        log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to read DUID, ignoring assignment: %s.", rvalue);
+                        return 0;
+                }
+                if (r == 0)
+                        break;
+
+                if (count >= MAX_DUID_LEN) {
+                        log_syntax(unit, LOG_WARNING, filename, line, 0, "Max DUID length exceeded, ignoring assignment: %s.", rvalue);
+                        return 0;
+                }
+
+                len = strlen(cbyte);
+                if (!IN_SET(len, 1, 2)) {
+                        log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid length - DUID byte: %s, ignoring assignment: %s.", cbyte, rvalue);
+                        return 0;
+                }
+                n1 = unhexchar(cbyte[0]);
+                if (len == 2)
+                        n2 = unhexchar(cbyte[1]);
+                else
+                        n2 = 0;
+
+                if (n1 < 0 || n2 < 0) {
+                        log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid DUID byte: %s. Ignoring assignment: %s.", cbyte, rvalue);
+                        return 0;
+                }
+
+                byte = ((uint8_t) n1 << (4 * (len-1))) | (uint8_t) n2;
+                raw_data[count++] = byte;
+        }
+
+        assert_cc(sizeof(raw_data) == sizeof(ret->raw_data));
+        memcpy(ret->raw_data, raw_data, count);
+        ret->raw_data_len = count;
+        return 0;
+}
index acf80e62555bc0826bd9146f1ba86f16de0f3aff..23baef924631b9f40f56fe699f87ff9c0e4c8ac9 100644 (file)
@@ -1,6 +1,8 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
+#include <netinet/in.h>
+
 #include "conf-parser.h"
 #include "dhcp-identifier.h"
 #include "time-util.h"
@@ -69,3 +71,5 @@ CONFIG_PARSER_PROTOTYPE(config_parse_section_route_table);
 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_user_or_vendor_class);
 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_send_option);
 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_request_options);
+CONFIG_PARSER_PROTOTYPE(config_parse_duid_type);
+CONFIG_PARSER_PROTOTYPE(config_parse_duid_rawdata);
index 74d509896a3d87120aa7f73f44941da93ad3f25f..8f02271278b4c3f9d57c0374241630d73d06db5e 100644 (file)
@@ -6,6 +6,7 @@ _Pragma("GCC diagnostic ignored \"-Wimplicit-fallthrough\"")
 #include <stddef.h>
 #include "conf-parser.h"
 #include "networkd-conf.h"
+#include "networkd-dhcp-common.h"
 #include "networkd-manager.h"
 #include "networkd-route.h"
 %}
index 568c34f51bd573c2be35eea6de952188eb960979..736988a4b810de96cd505c3d1e118b25ccf4a8a3 100644 (file)
@@ -10,7 +10,6 @@ _Pragma("GCC diagnostic ignored \"-Wimplicit-fallthrough\"")
 #include "networkd-address-label.h"
 #include "networkd-address.h"
 #include "networkd-can.h"
-#include "networkd-conf.h"
 #include "networkd-dhcp-common.h"
 #include "networkd-dhcp-server.h"
 #include "networkd-dhcp4.h"