summaryrefslogtreecommitdiffhomepage
path: root/config.c
diff options
context:
space:
mode:
Diffstat (limited to 'config.c')
-rw-r--r--config.c52
1 files changed, 43 insertions, 9 deletions
diff --git a/config.c b/config.c
index ff0410d..4f3a3cd 100644
--- a/config.c
+++ b/config.c
@@ -274,22 +274,56 @@ config_check_equal(struct blob_attr *c1, struct blob_attr *c2,
return true;
}
-void
-config_init_interfaces(const char *name)
+struct blob_attr *
+config_memdup(struct blob_attr *attr)
{
- struct uci_context *ctx;
+ struct blob_attr *ret;
+ int size = blob_pad_len(attr);
+
+ ret = malloc(size);
+ if (!ret)
+ return NULL;
+
+ memcpy(ret, attr, size);
+ return ret;
+}
+
+static struct uci_package *
+config_init_package(const char *config)
+{
+ struct uci_context *ctx = uci_ctx;
struct uci_package *p = NULL;
- struct uci_element *e;
- ctx = uci_alloc_context();
- uci_ctx = ctx;
+ if (!ctx) {
+ ctx = uci_alloc_context();
+ uci_ctx = ctx;
#ifdef DUMMY_MODE
- uci_set_confdir(ctx, "./config");
- uci_set_savedir(ctx, "./tmp");
+ uci_set_confdir(ctx, "./config");
+ uci_set_savedir(ctx, "./tmp");
#endif
+ } else {
+ p = uci_lookup_package(ctx, config);
+ if (p)
+ uci_unload(ctx, p);
+ }
+
+ if (uci_load(ctx, "network", &p))
+ return NULL;
+
+ return p;
+}
+
+void
+config_init_interfaces(const char *name)
+{
+ struct uci_context *ctx;
+ struct uci_package *p = NULL;
+ struct uci_element *e;
- if (uci_load(ctx, "network", &p)) {
+ p = config_init_package("network");
+ ctx = uci_ctx;
+ if (!p) {
fprintf(stderr, "Failed to load network config\n");
return;
}