]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: move NetworkConfigSection and related functions to networkd-util.[ch]
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 28 Feb 2019 07:30:14 +0000 (16:30 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 13 Mar 2019 02:59:18 +0000 (11:59 +0900)
src/network/networkd-network.c
src/network/networkd-network.h
src/network/networkd-util.c
src/network/networkd-util.h

index 1e5684144dcf1fdffcdc75edbd8fa5831c98d605..341b6335d6c098a5875f05b71db5405396ca2b40 100644 (file)
 /* Let's assume that anything above this number is a user misconfiguration. */
 #define MAX_NTP_SERVERS 128
 
-static void network_config_hash_func(const NetworkConfigSection *c, struct siphash *state) {
-        siphash24_compress(c->filename, strlen(c->filename), state);
-        siphash24_compress(&c->line, sizeof(c->line), state);
-}
-
-static int network_config_compare_func(const NetworkConfigSection *x, const NetworkConfigSection *y) {
-        int r;
-
-        r = strcmp(x->filename, y->filename);
-        if (r != 0)
-                return r;
-
-        return CMP(x->line, y->line);
-}
-
-DEFINE_HASH_OPS(network_config_hash_ops, NetworkConfigSection, network_config_hash_func, network_config_compare_func);
-
-int network_config_section_new(const char *filename, unsigned line, NetworkConfigSection **s) {
-        NetworkConfigSection *cs;
-
-        cs = malloc0(offsetof(NetworkConfigSection, filename) + strlen(filename) + 1);
-        if (!cs)
-                return -ENOMEM;
-
-        strcpy(cs->filename, filename);
-        cs->line = line;
-
-        *s = TAKE_PTR(cs);
-
-        return 0;
-}
-
-void network_config_section_free(NetworkConfigSection *cs) {
-        free(cs);
-}
-
 /* Set defaults following RFC7844 */
 void network_apply_anonymize_if_set(Network *network) {
         if (!network->dhcp_anonymize)
index 2f7b6133fd506a3ebdda3b0d6f8cbeb7b2adbb02..38f3b7decb338d5365cab28d27383a8d564f6f6e 100644 (file)
@@ -84,16 +84,6 @@ typedef enum RADVPrefixDelegation {
         _RADV_PREFIX_DELEGATION_INVALID = -1,
 } RADVPrefixDelegation;
 
-typedef struct NetworkConfigSection {
-        unsigned line;
-        char filename[];
-} NetworkConfigSection;
-
-int network_config_section_new(const char *filename, unsigned line, NetworkConfigSection **s);
-void network_config_section_free(NetworkConfigSection *network);
-DEFINE_TRIVIAL_CLEANUP_FUNC(NetworkConfigSection*, network_config_section_free);
-extern const struct hash_ops network_config_hash_ops;
-
 typedef struct Manager Manager;
 
 struct Network {
index 9b6bc128581d2fec8ce10179b5c3118f1fd23e4f..a392aadd4c4232a1f2555f4770afd146bed84338 100644 (file)
@@ -102,3 +102,39 @@ int kernel_route_expiration_supported(void) {
         }
         return cached;
 }
+
+static void network_config_hash_func(const NetworkConfigSection *c, struct siphash *state) {
+        siphash24_compress(c->filename, strlen(c->filename), state);
+        siphash24_compress(&c->line, sizeof(c->line), state);
+}
+
+static int network_config_compare_func(const NetworkConfigSection *x, const NetworkConfigSection *y) {
+        int r;
+
+        r = strcmp(x->filename, y->filename);
+        if (r != 0)
+                return r;
+
+        return CMP(x->line, y->line);
+}
+
+DEFINE_HASH_OPS(network_config_hash_ops, NetworkConfigSection, network_config_hash_func, network_config_compare_func);
+
+int network_config_section_new(const char *filename, unsigned line, NetworkConfigSection **s) {
+        NetworkConfigSection *cs;
+
+        cs = malloc0(offsetof(NetworkConfigSection, filename) + strlen(filename) + 1);
+        if (!cs)
+                return -ENOMEM;
+
+        strcpy(cs->filename, filename);
+        cs->line = line;
+
+        *s = TAKE_PTR(cs);
+
+        return 0;
+}
+
+void network_config_section_free(NetworkConfigSection *cs) {
+        free(cs);
+}
index 3c0c279b97b5d0c35062cee972be3c9445aa8964..d360035b147d325d08e8034dbe30b1459993fd92 100644 (file)
@@ -2,6 +2,7 @@
 #pragma once
 
 #include "conf-parser.h"
+#include "hash-funcs.h"
 #include "macro.h"
 
 typedef enum AddressFamilyBoolean {
@@ -14,6 +15,11 @@ typedef enum AddressFamilyBoolean {
         _ADDRESS_FAMILY_BOOLEAN_INVALID = -1,
 } AddressFamilyBoolean;
 
+typedef struct NetworkConfigSection {
+        unsigned line;
+        char filename[];
+} NetworkConfigSection;
+
 CONFIG_PARSER_PROTOTYPE(config_parse_address_family_boolean);
 CONFIG_PARSER_PROTOTYPE(config_parse_address_family_boolean_with_kernel);
 
@@ -21,3 +27,8 @@ const char *address_family_boolean_to_string(AddressFamilyBoolean b) _const_;
 AddressFamilyBoolean address_family_boolean_from_string(const char *s) _const_;
 
 int kernel_route_expiration_supported(void);
+
+int network_config_section_new(const char *filename, unsigned line, NetworkConfigSection **s);
+void network_config_section_free(NetworkConfigSection *network);
+DEFINE_TRIVIAL_CLEANUP_FUNC(NetworkConfigSection*, network_config_section_free);
+extern const struct hash_ops network_config_hash_ops;