if (!network->ipv4ll_route)
return 0;
- section_line = hashmap_find_free_section_line(network->routes_by_section);
+ r = hashmap_by_section_find_unused_line(network->routes_by_section, network->filename, §ion_line);
+ if (r < 0)
+ return r;
/* IPv4LLRoute= is in [Network] section. */
r = route_new_static(network, network->filename, section_line, &n);
if (!network->default_route_on_device)
return 0;
- section_line = hashmap_find_free_section_line(network->routes_by_section);
+ r = hashmap_by_section_find_unused_line(network->routes_by_section, network->filename, §ion_line);
+ if (r < 0)
+ return r;
/* DefaultRouteOnDevice= is in [Network] section. */
r = route_new_static(network, network->filename, section_line, &n);
return 0;
}
-unsigned hashmap_find_free_section_line(Hashmap *hashmap) {
+int hashmap_by_section_find_unused_line(
+ Hashmap *entries_by_section,
+ const char *filename,
+ unsigned *ret) {
+
ConfigSection *cs;
unsigned n = 0;
void *entry;
- HASHMAP_FOREACH_KEY(entry, cs, hashmap)
- if (n < cs->line)
- n = cs->line;
+ HASHMAP_FOREACH_KEY(entry, cs, entries_by_section) {
+ if (filename && !streq(cs->filename, filename))
+ continue;
+ n = MAX(n, cs->line);
+ }
+
+ /* overflow? */
+ if (n >= UINT_MAX)
+ return -EFBIG;
- return n + 1;
+ *ret = n + 1;
+ return 0;
}
#define DEFINE_PARSER(type, vartype, conv_func) \
int config_section_new(const char *filename, unsigned line, ConfigSection **ret);
extern const struct hash_ops config_section_hash_ops;
-unsigned hashmap_find_free_section_line(Hashmap *hashmap);
+int hashmap_by_section_find_unused_line(
+ Hashmap *entries_by_section,
+ const char *filename,
+ unsigned *ret);
static inline bool section_is_invalid(ConfigSection *section) {
/* If this returns false, then it does _not_ mean the section is valid. */