summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDainis Jonitis <dainis.jonitis@ubnt.com>2019-04-29 14:47:13 +0300
committerHans Dedecker <dedeckeh@gmail.com>2019-05-03 14:51:52 +0200
commitb60c384a5ac698103f05bc102cbef92143f1f237 (patch)
tree14ac446c2d86102f05390f764ca5a4e47cd65b8b
parenta2dd8d6bd918fb211db491c7dcb1810032f3f8ca (diff)
config: use multi-stage parsing of uci sections
When loading uci sections from config file, in one pass do not mix sections from different types. First load odhcpd global settings, then all interface sections and finally static leases. It ensures that section order in file can't affect what information is already parsed. For example static lease section may need information about all interfaces, to decide whether ip address belongs to any of currently defined interfaces/address pools. Signed-off-by: Dainis Jonitis <dainis.jonitis@ubnt.com>
-rw-r--r--src/config.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/config.c b/src/config.c
index dfeadac..f1fe82b 100644
--- a/src/config.c
+++ b/src/config.c
@@ -965,19 +965,27 @@ void odhcpd_reload(void)
struct uci_package *dhcp = NULL;
if (!uci_load(uci, "dhcp", &dhcp)) {
struct uci_element *e;
+
+ /* 1. Global settings */
uci_foreach_element(&dhcp->sections, e) {
struct uci_section *s = uci_to_section(e);
- if (!strcmp(s->type, "host"))
- set_lease(s);
- else if (!strcmp(s->type, "odhcpd"))
+ if (!strcmp(s->type, "odhcpd"))
set_config(s);
}
+ /* 2. DHCP pools */
uci_foreach_element(&dhcp->sections, e) {
struct uci_section *s = uci_to_section(e);
if (!strcmp(s->type, "dhcp"))
set_interface(s);
}
+
+ /* 3. Static leases */
+ uci_foreach_element(&dhcp->sections, e) {
+ struct uci_section* s = uci_to_section(e);
+ if (!strcmp(s->type, "host"))
+ set_lease(s);
+ }
}
if (config.dhcp_statefile) {