diff options
author | Susant Sahani <susant@redhat.com> | 2017-02-15 10:00:35 +0530 |
---|---|---|
committer | Susant Sahani <susant@redhat.com> | 2017-02-16 10:31:42 +0530 |
commit | f4859fc74c06bf5040e96ef68ddf7102f43cc7db (patch) | |
tree | e827c6ba57a292e1c77b3e4e07f585152e948dc6 /src/network/networkd-network.c | |
parent | 28b1a3eac252d471de4fbb6f317353af30d68878 (diff) |
networkd: fix drop-in conf directory configs overwriting each other
Now we track the sections for example [Address] via line number.
Which was fine till we din't had dropins dir. If we have multiple
sections which have the ideantical line number in diffrent files
we are overwriting these since line number is the key.
This patch fixes this by taking filename and line number as key.
This fixes [Address] and [Route] section overwriting.
fixes: #5141
Diffstat (limited to 'src/network/networkd-network.c')
-rw-r--r-- | src/network/networkd-network.c | 49 |
1 files changed, 46 insertions, 3 deletions
diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c index 92062ca00c..ab372568de 100644 --- a/src/network/networkd-network.c +++ b/src/network/networkd-network.c @@ -36,6 +36,49 @@ #include "string-util.h" #include "util.h" +static void network_config_hash_func(const void *p, struct siphash *state) { + const NetworkConfigSection *c = p; + + siphash24_compress(c->filename, strlen(c->filename), state); + siphash24_compress(&c->line, sizeof(c->line), state); +} + +static int network_config_compare_func(const void *a, const void *b) { + const NetworkConfigSection *x = a, *y = b; + int r; + + r = strcmp(x->filename, y->filename); + if (r != 0) + return r; + + return y->line - x->line; +} + +const struct hash_ops network_config_hash_ops = { + .hash = network_config_hash_func, + .compare = 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 = cs; + cs = NULL; + + return 0; +} + +void network_config_section_free(NetworkConfigSection *cs) { + free(cs); +} + static int network_load_one(Manager *manager, const char *filename) { _cleanup_network_free_ Network *network = NULL; _cleanup_fclose_ FILE *file = NULL; @@ -76,11 +119,11 @@ static int network_load_one(Manager *manager, const char *filename) { if (!network->stacked_netdevs) return log_oom(); - network->addresses_by_section = hashmap_new(NULL); + network->addresses_by_section = hashmap_new(&network_config_hash_ops); if (!network->addresses_by_section) return log_oom(); - network->routes_by_section = hashmap_new(NULL); + network->routes_by_section = hashmap_new(&network_config_hash_ops); if (!network->routes_by_section) return log_oom(); @@ -385,7 +428,7 @@ int network_apply(Network *network, Link *link) { if (network->ipv4ll_route) { Route *route; - r = route_new_static(network, 0, &route); + r = route_new_static(network, "Network", 0, &route); if (r < 0) return r; |