diff options
Diffstat (limited to 'config.c')
-rw-r--r-- | config.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/config.c b/config.c new file mode 100644 index 0000000..a106db2 --- /dev/null +++ b/config.c @@ -0,0 +1,51 @@ +#include <string.h> +#include <stdlib.h> +#include <stdio.h> + +#include "netifd.h" + +struct uci_context *uci_ctx; + +static void config_parse_interface(struct uci_section *s) +{ + struct interface *iface; + const char *type; + + DPRINTF("Create interface '%s'\n", s->e.name); + + iface = alloc_interface(s->e.name); + type = uci_lookup_option_string(uci_ctx, s, "type"); + + if (!type) + type = ""; + + if (!strcmp(type, "bridge")) + interface_attach_bridge(iface, s); +} + +void config_init_interfaces(const char *name) +{ + struct uci_context *ctx; + struct uci_package *p = NULL; + struct uci_element *e; + + ctx = uci_alloc_context(); + uci_ctx = ctx; + + uci_set_confdir(ctx, "./config"); + + if (uci_load(ctx, "network", &p)) { + fprintf(stderr, "Failed to load network config\n"); + return; + } + + uci_foreach_element(&p->sections, e) { + struct uci_section *s = uci_to_section(e); + + if (name && strcmp(s->e.name, name) != 0) + continue; + + if (!strcmp(s->type, "interface")) + config_parse_interface(s); + } +} |