rework includes
[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
10 static void config_parse_interface(struct uci_section *s)
11 {
12         struct interface *iface;
13         const char *type;
14
15         DPRINTF("Create interface '%s'\n", s->e.name);
16
17         iface = alloc_interface(s->e.name);
18         type = uci_lookup_option_string(uci_ctx, s, "type");
19
20         if (!type)
21                 type = "";
22
23         if (!strcmp(type, "bridge"))
24                 interface_attach_bridge(iface, s);
25 }
26
27 void config_init_interfaces(const char *name)
28 {
29         struct uci_context *ctx;
30         struct uci_package *p = NULL;
31         struct uci_element *e;
32
33         ctx = uci_alloc_context();
34         uci_ctx = ctx;
35
36         uci_set_confdir(ctx, "./config");
37
38         if (uci_load(ctx, "network", &p)) {
39                 fprintf(stderr, "Failed to load network config\n");
40                 return;
41         }
42
43         uci_foreach_element(&p->sections, e) {
44                 struct uci_section *s = uci_to_section(e);
45
46                 if (name && strcmp(s->e.name, name) != 0)
47                         continue;
48
49                 if (!strcmp(s->type, "interface"))
50                         config_parse_interface(s);
51         }
52 }