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