summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamuel Mendoza-Jonas <sam@mendozajonas.com>2017-02-14 15:56:55 +1100
committerSamuel Mendoza-Jonas <sam@mendozajonas.com>2017-08-15 11:40:09 +1000
commit98b04aa42a4f1dc8e585f00d75c3b28d9e9aa2a9 (patch)
tree5d87ea583c6d8c5a8b92628c611ac417ddd272be
parent4974b691020cca86ce6c7f1f62c7c3fee4f52c61 (diff)
downloadtalos-petitboot-98b04aa42a4f1dc8e585f00d75c3b28d9e9aa2a9.tar.gz
talos-petitboot-98b04aa42a4f1dc8e585f00d75c3b28d9e9aa2a9.zip
lib: Add plugin_option type and protocol
Add a new struct 'plugin_option' to represent pb-plugins that are installed on the system. This consists of plugin metadata and an array of installed executables. This also adds two new pb-protocol actions to advertise the addition of a new plugin_option, and to remove known plugin_options. Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
-rw-r--r--lib/pb-protocol/pb-protocol.c104
-rw-r--r--lib/pb-protocol/pb-protocol.h8
-rw-r--r--lib/types/types.h15
3 files changed, 127 insertions, 0 deletions
diff --git a/lib/pb-protocol/pb-protocol.c b/lib/pb-protocol/pb-protocol.c
index 18edf57..ed61fe1 100644
--- a/lib/pb-protocol/pb-protocol.c
+++ b/lib/pb-protocol/pb-protocol.c
@@ -340,6 +340,26 @@ int pb_protocol_url_len(const char *url)
return 4 + optional_strlen(url);
}
+
+int pb_protocol_plugin_option_len(const struct plugin_option *opt)
+{
+ unsigned int i, len = 0;
+
+ len += 4 + optional_strlen(opt->id);
+ len += 4 + optional_strlen(opt->name);
+ len += 4 + optional_strlen(opt->vendor);
+ len += 4 + optional_strlen(opt->vendor_id);
+ len += 4 + optional_strlen(opt->version);
+ len += 4 + optional_strlen(opt->date);
+ len += 4 + optional_strlen(opt->plugin_file);
+
+ len += 4; /* n_executables */
+ for (i = 0; i < opt->n_executables; i++)
+ len += 4 + optional_strlen(opt->executables[i]);
+
+ return len;
+}
+
int pb_protocol_serialise_device(const struct device *dev,
char *buf, int buf_len)
{
@@ -611,6 +631,32 @@ int pb_protocol_serialise_url(const char *url, char *buf, int buf_len)
return 0;
}
+int pb_protocol_serialise_plugin_option(const struct plugin_option *opt,
+ char *buf, int buf_len)
+{
+ char *pos = buf;
+ unsigned int i;
+
+ pos += pb_protocol_serialise_string(pos, opt->id);
+ pos += pb_protocol_serialise_string(pos, opt->name);
+ pos += pb_protocol_serialise_string(pos, opt->vendor);
+ pos += pb_protocol_serialise_string(pos, opt->vendor_id);
+ pos += pb_protocol_serialise_string(pos, opt->version);
+ pos += pb_protocol_serialise_string(pos, opt->date);
+ pos += pb_protocol_serialise_string(pos, opt->plugin_file);
+
+ *(uint32_t *)pos = __cpu_to_be32(opt->n_executables);
+ pos += 4;
+
+ for (i = 0; i < opt->n_executables; i++)
+ pos += pb_protocol_serialise_string(pos, opt->executables[i]);
+
+ assert(pos <= buf + buf_len);
+ (void)buf_len;
+
+ return 0;
+}
+
int pb_protocol_write_message(int fd, struct pb_protocol_message *message)
{
int total_len, rc;
@@ -1150,3 +1196,61 @@ int pb_protocol_deserialise_config(struct config *config,
out:
return rc;
}
+
+int pb_protocol_deserialise_plugin_option(struct plugin_option *opt,
+ const struct pb_protocol_message *message)
+{
+ unsigned int len, i, tmp;
+ const char *pos;
+ int rc = -1;
+ char *str;
+
+ len = message->payload_len;
+ pos = message->payload;
+
+ if (read_string(opt, &pos, &len, &str))
+ goto out;
+ opt->id = str;
+
+ if (read_string(opt, &pos, &len, &str))
+ goto out;
+ opt->name = str;
+
+ if (read_string(opt, &pos, &len, &str))
+ goto out;
+ opt->vendor = str;
+
+ if (read_string(opt, &pos, &len, &str))
+ goto out;
+ opt->vendor_id = str;
+
+ if (read_string(opt, &pos, &len, &str))
+ goto out;
+ opt->version = str;
+
+ if (read_string(opt, &pos, &len, &str))
+ goto out;
+ opt->date = str;
+
+ if (read_string(opt, &pos, &len, &str))
+ goto out;
+ opt->plugin_file = str;
+
+ if (read_u32(&pos, &len, &tmp))
+ goto out;
+ opt->n_executables = tmp;
+
+ opt->executables = talloc_zero_array(opt, char *, opt->n_executables);
+ if (!opt->executables)
+ goto out;
+
+ for (i = 0; i < opt->n_executables; i++) {
+ if (read_string(opt, &pos, &len, &str))
+ goto out;
+ opt->executables[i] = talloc_strdup(opt, str);
+ }
+
+ rc = 0;
+out:
+ return rc;
+}
diff --git a/lib/pb-protocol/pb-protocol.h b/lib/pb-protocol/pb-protocol.h
index a8cd206..ce876d0 100644
--- a/lib/pb-protocol/pb-protocol.h
+++ b/lib/pb-protocol/pb-protocol.h
@@ -23,6 +23,8 @@ enum pb_protocol_action {
PB_PROTOCOL_ACTION_CONFIG = 0x9,
PB_PROTOCOL_ACTION_REINIT = 0xa,
PB_PROTOCOL_ACTION_ADD_URL = 0xb,
+ PB_PROTOCOL_ACTION_PLUGIN_OPTION_ADD = 0xc,
+ PB_PROTOCOL_ACTION_PLUGINS_REMOVE = 0xd,
};
struct pb_protocol_message {
@@ -40,6 +42,7 @@ int pb_protocol_boot_status_len(const struct status *status);
int pb_protocol_system_info_len(const struct system_info *sysinfo);
int pb_protocol_config_len(const struct config *config);
int pb_protocol_url_len(const char *url);
+int pb_protocol_plugin_option_len(const struct plugin_option *opt);
int pb_protocol_device_cmp(const struct device *a, const struct device *b);
int pb_protocol_boot_option_cmp(const struct boot_option *a,
@@ -62,6 +65,8 @@ int pb_protocol_serialise_system_info(const struct system_info *sysinfo,
int pb_protocol_serialise_config(const struct config *config,
char *buf, int buf_len);
int pb_protocol_serialise_url(const char *url, char *buf, int buf_len);
+int pb_protocol_serialise_plugin_option(const struct plugin_option *opt,
+ char *buf, int buf_len);
int pb_protocol_write_message(int fd, struct pb_protocol_message *message);
@@ -87,4 +92,7 @@ int pb_protocol_deserialise_system_info(struct system_info *sysinfo,
int pb_protocol_deserialise_config(struct config *config,
const struct pb_protocol_message *message);
+
+int pb_protocol_deserialise_plugin_option(struct plugin_option *opt,
+ const struct pb_protocol_message *message);
#endif /* _PB_PROTOCOL_H */
diff --git a/lib/types/types.h b/lib/types/types.h
index 7f4ae1f..36841cd 100644
--- a/lib/types/types.h
+++ b/lib/types/types.h
@@ -60,6 +60,21 @@ struct boot_option {
void *ui_info;
};
+struct plugin_option {
+ char *id;
+ char *name;
+ char *vendor;
+ char *vendor_id;
+ char *version;
+ char *date;
+ char *plugin_file;
+
+ unsigned int n_executables;
+ char **executables;
+
+ void *ui_info;
+};
+
struct boot_command {
char *option_id;
char *boot_image_file;
OpenPOWER on IntegriCloud