summaryrefslogtreecommitdiff
path: root/src/network/networkd-util.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2019-02-28 16:30:14 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2019-03-13 11:59:18 +0900
commit48315d3dcae9bb045ab7d16264904b976123018e (patch)
tree6d27ee01b0aaf3a1fa388d2868a325f3fbef1e08 /src/network/networkd-util.c
parent95dba435427f989717e02ead93fe0a3199efd2b0 (diff)
downloadsystemd-48315d3dcae9bb045ab7d16264904b976123018e.tar.gz
network: move NetworkConfigSection and related functions to networkd-util.[ch]
Diffstat (limited to 'src/network/networkd-util.c')
-rw-r--r--src/network/networkd-util.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/network/networkd-util.c b/src/network/networkd-util.c
index 9b6bc12858..a392aadd4c 100644
--- a/src/network/networkd-util.c
+++ b/src/network/networkd-util.c
@@ -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);
+}