]> git.ozlabs.org Git - petitboot/blob - lib/pb-config/pb-config.c
config/powerpc-nvram: Fix nvram line parsing
[petitboot] / lib / pb-config / pb-config.c
1
2 #include <log/log.h>
3 #include <talloc/talloc.h>
4
5 #include "pb-config.h"
6
7 #include "storage.h"
8
9 static struct config            *config;
10 static struct config_storage    *storage;
11
12
13 static void config_set_defaults(struct config *config)
14 {
15         config->autoboot_enabled = true;
16         config->network_configs = NULL;
17         config->n_network_configs = 0;
18 }
19
20 static void dump_config(struct config *config)
21 {
22         int i;
23
24         pb_log("configuration:\n");
25
26         pb_log(" autoboot enabled: %s\n",
27                         config->autoboot_enabled ? "yes" : "no");
28
29         if (config->n_network_configs > 0)
30                 pb_log(" network configuration:\n");
31
32         for (i = 0; i < config->n_network_configs; i++) {
33                 struct network_config *netconf = config->network_configs[i];
34
35                 pb_log("  interface %02x:%02x:%02x:%02x:%02x:%02x\n",
36                                 netconf->hwaddr[0], netconf->hwaddr[1],
37                                 netconf->hwaddr[2], netconf->hwaddr[3],
38                                 netconf->hwaddr[4], netconf->hwaddr[5]);
39
40                 if (netconf->ignore) {
41                         pb_log("   ignore\n");
42                         continue;
43                 }
44
45                 if (netconf->method == CONFIG_METHOD_DHCP) {
46                         pb_log("   dhcp\n");
47
48                 } else if (netconf->method == CONFIG_METHOD_STATIC) {
49                         pb_log("   static:\n");
50                         pb_log("    ip:  %s\n", netconf->static_config.address);
51                         pb_log("    gw:  %s\n", netconf->static_config.gateway);
52                         pb_log("    dns: %s\n", netconf->static_config.dns);
53
54                 }
55         }
56 }
57
58 int config_init(void *ctx)
59 {
60         config = talloc(ctx, struct config);
61         config_set_defaults(config);
62
63         storage = create_powerpc_nvram_storage(config);
64
65         storage->load(storage, config);
66
67         dump_config(config);
68
69         return 0;
70 }
71
72 const struct config *config_get(void)
73 {
74         return config;
75 }
76
77 int config_fini(void)
78 {
79         talloc_free(config);
80         return 0;
81 }