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-route.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-route.c')
-rw-r--r-- | src/network/networkd-route.c | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c index bde26a42d4..81a065dd27 100644 --- a/src/network/networkd-route.c +++ b/src/network/networkd-route.c @@ -77,15 +77,20 @@ int route_new(Route **ret) { return 0; } -int route_new_static(Network *network, unsigned section, Route **ret) { +int route_new_static(Network *network, const char *filename, unsigned section_line, Route **ret) { + _cleanup_network_config_section_free_ NetworkConfigSection *n = NULL; _cleanup_route_free_ Route *route = NULL; int r; assert(network); assert(ret); - if (section) { - route = hashmap_get(network->routes_by_section, UINT_TO_PTR(section)); + if (section_line > 0) { + r = network_config_section_new(filename, section_line, &n); + if (r < 0) + return r; + + route = hashmap_get(network->routes_by_section, n); if (route) { *ret = route; route = NULL; @@ -103,10 +108,10 @@ int route_new_static(Network *network, unsigned section, Route **ret) { route->protocol = RTPROT_STATIC; - if (section) { - route->section = section; + if (section_line > 0) { + route->section = n; - r = hashmap_put(network->routes_by_section, UINT_TO_PTR(route->section), route); + r = hashmap_put(network->routes_by_section, n, route); if (r < 0) return r; } @@ -117,6 +122,7 @@ int route_new_static(Network *network, unsigned section, Route **ret) { *ret = route; route = NULL; + n = NULL; return 0; } @@ -131,8 +137,10 @@ void route_free(Route *route) { assert(route->network->n_static_routes > 0); route->network->n_static_routes--; - if (route->section) - hashmap_remove(route->network->routes_by_section, UINT_TO_PTR(route->section)); + if (route->section) { + hashmap_remove(route->network->routes_by_section, route->section); + network_config_section_free(route->section); + } } if (route->link) { @@ -673,10 +681,10 @@ int config_parse_gateway(const char *unit, if (streq(section, "Network")) { /* we are not in an Route section, so treat * this as the special '0' section */ - section_line = 0; - } + r = route_new_static(network, NULL, 0, &n); + } else + r = route_new_static(network, filename, section_line, &n); - r = route_new_static(network, section_line, &n); if (r < 0) return r; @@ -715,7 +723,7 @@ int config_parse_preferred_src(const char *unit, assert(rvalue); assert(data); - r = route_new_static(network, section_line, &n); + r = route_new_static(network, filename, section_line, &n); if (r < 0) return r; @@ -757,7 +765,7 @@ int config_parse_destination(const char *unit, assert(rvalue); assert(data); - r = route_new_static(network, section_line, &n); + r = route_new_static(network, filename, section_line, &n); if (r < 0) return r; @@ -835,7 +843,7 @@ int config_parse_route_priority(const char *unit, assert(rvalue); assert(data); - r = route_new_static(network, section_line, &n); + r = route_new_static(network, filename, section_line, &n); if (r < 0) return r; @@ -872,7 +880,7 @@ int config_parse_route_scope(const char *unit, assert(rvalue); assert(data); - r = route_new_static(network, section_line, &n); + r = route_new_static(network, filename, section_line, &n); if (r < 0) return r; @@ -913,7 +921,7 @@ int config_parse_route_table(const char *unit, assert(rvalue); assert(data); - r = route_new_static(network, section_line, &n); + r = route_new_static(network, filename, section_line, &n); if (r < 0) return r; |