3 #include <types/types.h>
4 #include <talloc/talloc.h>
11 static struct config *config;
12 static struct config_storage *storage;
15 void config_set_defaults(struct config *config)
17 config->autoboot_enabled = true;
18 config->autoboot_timeout_sec = 10;
19 config->network.interfaces = NULL;
20 config->network.n_interfaces = 0;
21 config->network.dns_servers = NULL;
22 config->network.n_dns_servers = 0;
24 config->n_boot_priorities = 2;
25 config->boot_priorities = talloc_array(config, struct boot_priority,
26 config->n_boot_priorities);
27 config->boot_priorities[0].type = DEVICE_TYPE_NETWORK;
28 config->boot_priorities[1].type = DEVICE_TYPE_DISK;
32 void dump_config(struct config *config);
33 void dump_config(struct config *config)
37 pb_log("configuration:\n");
39 if (config->autoboot_enabled)
40 pb_log(" autoboot: enabled, %d sec\n",
41 config->autoboot_timeout_sec);
43 pb_log(" autoboot: disabled\n");
45 if (config->network.n_interfaces || config->network.n_dns_servers)
46 pb_log(" network configuration:\n");
48 for (i = 0; i < config->network.n_interfaces; i++) {
49 struct interface_config *ifconf =
50 config->network.interfaces[i];
52 pb_log(" interface %02x:%02x:%02x:%02x:%02x:%02x\n",
53 ifconf->hwaddr[0], ifconf->hwaddr[1],
54 ifconf->hwaddr[2], ifconf->hwaddr[3],
55 ifconf->hwaddr[4], ifconf->hwaddr[5]);
62 if (ifconf->method == CONFIG_METHOD_DHCP) {
65 } else if (ifconf->method == CONFIG_METHOD_STATIC) {
67 pb_log(" ip: %s\n", ifconf->static_config.address);
68 pb_log(" gw: %s\n", ifconf->static_config.gateway);
72 for (i = 0; i < config->network.n_dns_servers; i++)
73 pb_log(" dns server %s\n", config->network.dns_servers[i]);
76 int config_init(void *ctx)
78 config_ctx = talloc_new(ctx);
80 config = talloc(config_ctx, struct config);
81 config_set_defaults(config);
83 storage = create_powerpc_nvram_storage(config);
85 storage->load(storage, config);
92 int config_set(struct config *newconfig)
96 if (!storage || !storage->save)
99 if (newconfig == config)
102 pb_log("new configuration data received\n");
103 dump_config(newconfig);
105 rc = storage->save(storage, newconfig);
108 config = talloc_steal(config_ctx, newconfig);
110 pb_log("error saving new configuration; changes lost\n");
115 /* A non-exported function to allow the test infrastructure to initialise
116 * (and change) the configuration variables */
118 struct config __attribute__((unused)) *test_config_init(
119 struct parser_test *test);
120 struct config *test_config_init(struct parser_test *test)
122 config = talloc(test, struct config);
123 config_set_defaults(config);
127 const struct config *config_get(void)
132 void config_set_autoboot(bool autoboot_enabled)
134 config->autoboot_enabled = autoboot_enabled;
136 pb_log("set autoboot: %s\n",
137 config->autoboot_enabled ? "enabled" : "disabled");
140 int config_fini(void)
142 talloc_free(config_ctx);