diff options
author | Jeremy Kerr <jk@ozlabs.org> | 2013-05-29 17:24:42 +1000 |
---|---|---|
committer | Jeremy Kerr <jk@ozlabs.org> | 2013-06-24 13:07:22 +0800 |
commit | 32fe8024f5af5cd8de23c638ddad8ada67a46cd5 (patch) | |
tree | cd64dcd7c093f7d10fe9325e5b1c5479aadfe01a /lib/pb-config/pb-config.c | |
parent | 0f9597ab801ad4591e943bd7efcb8f1549997fdd (diff) | |
download | talos-petitboot-32fe8024f5af5cd8de23c638ddad8ada67a46cd5.tar.gz talos-petitboot-32fe8024f5af5cd8de23c638ddad8ada67a46cd5.zip |
lib: Add pb-config module
Add a library for (name, value) configuration.
Different storage backends are allowed (although currently hardcoded to
powerpc nvram), and config is read-only at present.
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'lib/pb-config/pb-config.c')
-rw-r--r-- | lib/pb-config/pb-config.c | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/lib/pb-config/pb-config.c b/lib/pb-config/pb-config.c new file mode 100644 index 0000000..9f7d240 --- /dev/null +++ b/lib/pb-config/pb-config.c @@ -0,0 +1,81 @@ + +#include <log/log.h> +#include <talloc/talloc.h> + +#include "pb-config.h" + +#include "storage.h" + +static struct config *config; +static struct config_storage *storage; + + +static void config_set_defaults(struct config *config) +{ + config->autoboot_enabled = true; + config->network_configs = NULL; + config->n_network_configs = 0; +} + +static void dump_config(struct config *config) +{ + int i; + + pb_log("configuration:\n"); + + pb_log(" autoboot enabled: %s\n", + config->autoboot_enabled ? "yes" : "no"); + + if (config->n_network_configs > 0) + pb_log(" network configuration:\n"); + + for (i = 0; i < config->n_network_configs; i++) { + struct network_config *netconf = config->network_configs[i]; + + pb_log(" interface %02x:%02x:%02x:%02x:%02x:%02x\n", + netconf->hwaddr[0], netconf->hwaddr[1], + netconf->hwaddr[2], netconf->hwaddr[3], + netconf->hwaddr[4], netconf->hwaddr[5]); + + if (netconf->ignore) { + pb_log(" ignore\n"); + continue; + } + + if (netconf->method == CONFIG_METHOD_DHCP) { + pb_log(" dhcp\n"); + + } else if (netconf->method == CONFIG_METHOD_STATIC) { + pb_log(" static:\n"); + pb_log(" ip: %s\n", netconf->static_config.address); + pb_log(" gw: %s\n", netconf->static_config.gateway); + pb_log(" dns: %s\n", netconf->static_config.dns); + + } + } +} + +int config_init(void *ctx) +{ + config = talloc(ctx, struct config); + config_set_defaults(config); + + storage = create_powerpc_nvram_storage(config); + + storage->load(storage, config); + + dump_config(config); + + return 0; +} + +const struct config *config_get(void) +{ + return config; +} + +int config_fini(void) +{ + talloc_free(config); + return 0; +} |