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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <util/util.h>
#include "pb-config.h"
#include "storage.h"
struct interface_config net1 = {
.hwaddr = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 },
.method = CONFIG_METHOD_DHCP,
};
struct interface_config net2 = {
.hwaddr = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x56 },
.method = CONFIG_METHOD_STATIC,
.static_config = {
.address = "192.168.0.2/24",
.gateway = "192.168.0.1",
},
};
struct interface_config *interface_configs[] = { &net1, &net2 };
const char *dns_servers[] = { "192.168.1.1", "192.168.1.2" };
struct config test_config = {
.autoboot_enabled = true,
.network = {
.interfaces = interface_configs,
.n_interfaces = ARRAY_SIZE(interface_configs),
.dns_servers = dns_servers,
.n_dns_servers = ARRAY_SIZE(dns_servers),
}
};
struct test_storage {
struct config_storage storage;
struct param *params;
int n_params;
struct config *config;
};
#define to_test_storage(st) container_of(st, struct test_storage, storage)
static int load(struct config_storage *st, struct config *config)
{
struct test_storage *ts = to_test_storage(st);
memcpy(config, ts->config, sizeof(test_config));
return 0;
}
static int save(struct config_storage *st, struct config *newconfig)
{
struct test_storage *ts = to_test_storage(st);
ts->config = newconfig;
return 0;
}
static struct test_storage st = {
.storage = {
.load = load,
.save = save,
},
};
struct config_storage *create_test_storage(void *ctx __attribute__((unused)))
{
st.config = &test_config;
return &st.storage;
}
|