diff options
author | Felix Fietkau <nbd@openwrt.org> | 2011-02-19 15:21:52 +0100 |
---|---|---|
committer | Felix Fietkau <nbd@openwrt.org> | 2011-03-27 01:42:33 +0100 |
commit | 5d1fff7af6f77c9bf0d46572c7af563cd9fc55b3 (patch) | |
tree | 76d080e6b59f9235cd47b0e047f662c1f0a6ce00 /config.c |
Initial import
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); + } +} |