From 5d1fff7af6f77c9bf0d46572c7af563cd9fc55b3 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Sat, 19 Feb 2011 15:21:52 +0100 Subject: Initial import --- config.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 config.c (limited to 'config.c') 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 +#include +#include + +#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); + } +} -- cgit v1.2.3