prevent autostart of interfaces during config init
[project/netifd.git] / config.c
1 #include <string.h>
2 #include <stdlib.h>
3 #include <stdio.h>
4
5 #include "netifd.h"
6 #include "interface.h"
7
8 struct uci_context *uci_ctx;
9 bool config_init = false;
10
11 static void config_parse_interface(struct uci_section *s)
12 {
13 struct interface *iface;
14 const char *type;
15
16 DPRINTF("Create interface '%s'\n", s->e.name);
17
18 iface = alloc_interface(s->e.name);
19 type = uci_lookup_option_string(uci_ctx, s, "type");
20
21 if (!type)
22 type = "";
23
24 if (!strcmp(type, "bridge"))
25 interface_attach_bridge(iface, s);
26 }
27
28 void config_init_interfaces(const char *name)
29 {
30 struct uci_context *ctx;
31 struct uci_package *p = NULL;
32 struct uci_element *e;
33
34 ctx = uci_alloc_context();
35 uci_ctx = ctx;
36
37 uci_set_confdir(ctx, "./config");
38
39 if (uci_load(ctx, "network", &p)) {
40 fprintf(stderr, "Failed to load network config\n");
41 return;
42 }
43
44 config_init = true;
45 uci_foreach_element(&p->sections, e) {
46 struct uci_section *s = uci_to_section(e);
47
48 if (name && strcmp(s->e.name, name) != 0)
49 continue;
50
51 if (!strcmp(s->type, "interface"))
52 config_parse_interface(s);
53 }
54 config_init = false;
55
56 start_pending_interfaces();
57 }