summaryrefslogtreecommitdiffhomepage
path: root/config.c
blob: a106db24bf36ba2c26afc5e70b4bc3462e954283 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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);
	}
}