[PATCH 1/3] lib/types : Adds function to return struct config as string

Nayna Jain nayna at linux.vnet.ibm.com
Thu Jun 2 19:56:56 AEST 2016


Two new functions added to return ipmi boot configuration
and nvram boot configuration separately as string.

Signed-off-by: Nayna Jain <nayna at linux.vnet.ibm.com>
---
 lib/types/types.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/types/types.h |  3 +++
 2 files changed, 78 insertions(+)

diff --git a/lib/types/types.c b/lib/types/types.c
index 63045e1..2f924f1 100644
--- a/lib/types/types.c
+++ b/lib/types/types.c
@@ -1,4 +1,6 @@
 #include <string.h>
+#include <stdlib.h>
+#include <log/log.h>
 #include <types/types.h>
 #include <i18n/i18n.h>
 
@@ -75,3 +77,76 @@ enum device_type find_device_type(const char *str)
 
 	return DEVICE_TYPE_UNKNOWN;
 }
+
+unsigned char *get_ipmi_boot_policy_as_string(const struct config *config)
+{
+        unsigned char * input_data;
+
+        input_data = talloc_asprintf(config, "%04x%s", config->ipmi_bootdev,
+			config->ipmi_bootdev_persistent ? "1" : "0");
+        pb_log("Input data is %s, %d, %d\n", input_data, sizeof(input_data),
+			strlen(input_data));
+
+        return input_data;
+}
+
+unsigned char *get_nvram_boot_policy_as_string(const struct config* config)
+{
+
+        char * input_data = NULL;
+        char * autoboot_device = NULL;
+        unsigned int i = 0;
+
+        input_data = talloc_asprintf(config, "%s%d%s%s%s%s",
+			config->autoboot_enabled ? "1": "0",
+                	config->autoboot_timeout_sec,
+			config->safe_mode ? "1" : "0",
+			config->allow_writes ? "1" : "0",
+			config->disable_snapshots? "1" : "0",
+                	config->lang ? config->lang : "0");
+        for (i = 0; i < config->n_autoboot_opts; i++)
+        {
+                if (config->autoboot_opts[i].boot_type == BOOT_DEVICE_TYPE)
+                        autoboot_device = device_type_name(
+					config->autoboot_opts[i].type);
+                else
+                        autoboot_device = config->autoboot_opts[i].uuid;
+                input_data = talloc_asprintf_append(input_data, "%s",
+				autoboot_device);
+        }
+
+
+        for (i =0; i < config->network.n_interfaces; i++)
+        {
+                struct interface_config *iconf = config->network.interfaces[i];
+                input_data = talloc_asprintf_append(input_data,
+				"%02x:%02x:%02x:%02x:%02x:%02x",
+				iconf->hwaddr[0], iconf->hwaddr[1],
+				iconf->hwaddr[2], iconf->hwaddr[3],
+                                iconf->hwaddr[4], iconf->hwaddr[5]);
+
+                input_data = talloc_asprintf_append(input_data,"%s",
+				iconf->ignore ? "1" : "0");
+                if (iconf->method == CONFIG_METHOD_DHCP) {
+                        input_data = talloc_asprintf_append(input_data,
+					"%s", "dhcp");
+
+                } else if (iconf->method == CONFIG_METHOD_STATIC) {
+                        input_data = talloc_asprintf_append(input_data,
+					"%s%s%s%s", "static",
+					iconf->static_config.address,
+					iconf->static_config.gateway,
+                                        iconf->static_config.url);
+                }
+
+        }
+
+        for (i = 0; i < config->network.n_dns_servers; i++)
+                input_data = talloc_asprintf_append(input_data, "%s",
+				config->network.dns_servers[i]);
+
+        pb_log("input data is %s, %d, %d\n", input_data, sizeof(input_data),
+			strlen(input_data));
+        return input_data;
+
+}
diff --git a/lib/types/types.h b/lib/types/types.h
index 6ff4620..e6e1a78 100644
--- a/lib/types/types.h
+++ b/lib/types/types.h
@@ -167,4 +167,7 @@ struct config {
 	bool			debug;
 };
 
+unsigned char *get_ipmi_boot_policy_as_string(const struct config *conf);
+unsigned char *get_nvram_boot_policy_as_string(const struct config *conf);
+
 #endif /* _TYPES_H */
-- 
2.5.0



More information about the Petitboot mailing list