7 #include <asm/byteorder.h>
9 #include <talloc/talloc.h>
10 #include <list/list.h>
13 #include "pb-protocol.h"
18 * 4-byte action, determines the remaining message content
19 * 4-byte total payload len
20 * - not including action and payload len header
22 * action = 0x1: device add message
27 * 4-byte len, description
28 * 4-byte len, icon_file
34 * 4-byte len, description
35 * 4-byte len, icon_file
36 * 4-byte len, boot_image_file
37 * 4-byte len, initrd_file
38 * 4-byte len, dtb_file
39 * 4-byte len, boot_args
40 * 4-byte len, args_sig_file
42 * action = 0x2: device remove message
48 * 4-byte len, boot option id
49 * 4-byte len, boot_image_file
50 * 4-byte len, initrd_file
51 * 4-byte len, dtb_file
52 * 4-byte len, boot_args
53 * 4-byte len, args_sig_file
57 void pb_protocol_dump_device(const struct device *dev, const char *text,
60 struct boot_option *opt;
62 fprintf(stream, "%snew dev:\n", text);
63 fprintf(stream, "%s\tid: %s\n", text, dev->id);
64 fprintf(stream, "%s\tname: %s\n", text, dev->name);
65 fprintf(stream, "%s\tdesc: %s\n", text, dev->description);
66 fprintf(stream, "%s\ticon: %s\n", text, dev->icon_file);
67 fprintf(stream, "%s\tboot options:\n", text);
68 list_for_each_entry(&dev->boot_options, opt, list) {
69 fprintf(stream, "%s\t\tid: %s\n", text, opt->id);
70 fprintf(stream, "%s\t\tname: %s\n", text, opt->name);
71 fprintf(stream, "%s\t\tdesc: %s\n", text, opt->description);
72 fprintf(stream, "%s\t\ticon: %s\n", text, opt->icon_file);
73 fprintf(stream, "%s\t\tboot: %s\n", text, opt->boot_image_file);
74 fprintf(stream, "%s\t\tinit: %s\n", text, opt->initrd_file);
75 fprintf(stream, "%s\t\tdtb: %s\n", text, opt->dtb_file);
76 fprintf(stream, "%s\t\targs: %s\n", text, opt->boot_args);
77 fprintf(stream, "%s\t\tasig: %s\n", text, opt->args_sig_file);
81 int pb_protocol_device_cmp(const struct device *a, const struct device *b)
83 return !strcmp(a->id, b->id);
86 int pb_protocol_boot_option_cmp(const struct boot_option *a,
87 const struct boot_option *b)
89 return !strcmp(a->id, b->id);
92 /* Write a string into the buffer, starting at pos.
94 * Returns the total length used for the write, including length header.
96 int pb_protocol_serialise_string(char *pos, const char *str)
103 *(uint32_t *)pos = __cpu_to_be32(len);
104 pos += sizeof(uint32_t);
106 memcpy(pos, str, len);
108 return len + sizeof(uint32_t);
111 /* Read a string from a buffer, allocating the new string as necessary.
113 * @param[in] ctx The talloc context to base the allocation on
114 * @param[in,out] pos Where to start reading
115 * @param[in,out] len The amount of data remaining in the buffer
116 * @param[out] str Pointer to resuling string
117 * @return zero on success, non-zero on failure
119 static int read_string(void *ctx, const char **pos, unsigned int *len,
122 uint32_t str_len, read_len;
124 if (*len < sizeof(uint32_t))
127 str_len = __be32_to_cpu(*(uint32_t *)(*pos));
128 read_len = sizeof(uint32_t);
130 if (read_len + str_len > *len)
136 *str = talloc_strndup(ctx, *pos + read_len, str_len);
140 /* all ok, update the caller's pointers */
147 static int read_u32(const char **pos, unsigned int *len, unsigned int *p)
149 if (*len < sizeof(uint32_t))
152 *p = (unsigned int)__be32_to_cpu(*(uint32_t *)(*pos));
153 *pos += sizeof(uint32_t);
154 *len -= sizeof(uint32_t);
159 char *pb_protocol_deserialise_string(void *ctx,
160 const struct pb_protocol_message *message)
166 len = message->payload_len;
167 buf = message->payload;
169 if (read_string(ctx, &buf, &len, &str))
175 static int optional_strlen(const char *str)
182 int pb_protocol_device_len(const struct device *dev)
184 return 4 + optional_strlen(dev->id) +
186 4 + optional_strlen(dev->name) +
187 4 + optional_strlen(dev->description) +
188 4 + optional_strlen(dev->icon_file);
191 int pb_protocol_boot_option_len(const struct boot_option *opt)
194 return 4 + optional_strlen(opt->device_id) +
195 4 + optional_strlen(opt->id) +
196 4 + optional_strlen(opt->name) +
197 4 + optional_strlen(opt->description) +
198 4 + optional_strlen(opt->icon_file) +
199 4 + optional_strlen(opt->boot_image_file) +
200 4 + optional_strlen(opt->initrd_file) +
201 4 + optional_strlen(opt->dtb_file) +
202 4 + optional_strlen(opt->boot_args) +
203 4 + optional_strlen(opt->args_sig_file) +
204 sizeof(opt->is_default);
207 int pb_protocol_boot_len(const struct boot_command *boot)
209 return 4 + optional_strlen(boot->option_id) +
210 4 + optional_strlen(boot->boot_image_file) +
211 4 + optional_strlen(boot->initrd_file) +
212 4 + optional_strlen(boot->dtb_file) +
213 4 + optional_strlen(boot->boot_args) +
214 4 + optional_strlen(boot->args_sig_file) +
215 4 + optional_strlen(boot->tty);
218 int pb_protocol_boot_status_len(const struct boot_status *status)
221 4 + optional_strlen(status->message) +
222 4 + optional_strlen(status->detail) +
226 int pb_protocol_system_info_len(const struct system_info *sysinfo)
230 len = 4 + optional_strlen(sysinfo->type) +
231 4 + optional_strlen(sysinfo->identifier) +
235 for (i = 0; i < sysinfo->n_primary; i++)
236 len += 4 + optional_strlen(sysinfo->platform_primary[i]);
238 for (i = 0; i < sysinfo->n_other; i++)
239 len += 4 + optional_strlen(sysinfo->platform_other[i]);
242 for (i = 0; i < sysinfo->n_bmc_current; i++)
243 len += 4 + optional_strlen(sysinfo->bmc_current[i]);
245 for (i = 0; i < sysinfo->n_bmc_golden; i++)
246 len += 4 + optional_strlen(sysinfo->bmc_golden[i]);
248 for (i = 0; i < sysinfo->n_interfaces; i++) {
249 struct interface_info *if_info = sysinfo->interfaces[i];
250 len += 4 + if_info->hwaddr_size +
251 4 + optional_strlen(if_info->name) +
252 sizeof(if_info->link);
255 for (i = 0; i < sysinfo->n_blockdevs; i++) {
256 struct blockdev_info *bd_info = sysinfo->blockdevs[i];
257 len += 4 + optional_strlen(bd_info->name) +
258 4 + optional_strlen(bd_info->uuid) +
259 4 + optional_strlen(bd_info->mountpoint);
268 static int pb_protocol_interface_config_len(struct interface_config *conf)
272 len = sizeof(conf->hwaddr) +
273 4 /* conf->ignore */;
278 len += 4 /* conf->method */;
280 if (conf->method == CONFIG_METHOD_STATIC) {
281 len += 4 + optional_strlen(conf->static_config.address);
282 len += 4 + optional_strlen(conf->static_config.gateway);
283 len += 4 + optional_strlen(conf->static_config.url);
289 int pb_protocol_config_len(const struct config *config)
293 len = 4 /* config->autoboot_enabled */ +
294 4 /* config->autoboot_timeout_sec */ +
295 4 /* config->safe_mode */;
298 for (i = 0; i < config->network.n_interfaces; i++)
299 len += pb_protocol_interface_config_len(
300 config->network.interfaces[i]);
303 for (i = 0; i < config->network.n_dns_servers; i++)
304 len += 4 + optional_strlen(config->network.dns_servers[i]);
307 for (i = 0; i < config->n_autoboot_opts; i++) {
308 if (config->autoboot_opts[i].boot_type == BOOT_DEVICE_TYPE)
312 optional_strlen(config->autoboot_opts[i].uuid);
315 len += 4 + 4; /* ipmi_bootdev, ipmi_bootdev_persistent */
317 len += 4; /* allow_writes */
319 len += 4; /* n_tty */
320 for (i = 0; i < config->n_tty; i++)
321 len += 4 + optional_strlen(config->tty_list[i]);
323 len += 4 + optional_strlen(config->boot_tty);
325 len += 4 + optional_strlen(config->lang);
330 int pb_protocol_url_len(const char *url)
332 /* url + length field */
333 return 4 + optional_strlen(url);
336 int pb_protocol_serialise_device(const struct device *dev,
337 char *buf, int buf_len)
341 pos += pb_protocol_serialise_string(pos, dev->id);
342 *(enum device_type *)pos = dev->type;
343 pos += sizeof(enum device_type);
344 pos += pb_protocol_serialise_string(pos, dev->name);
345 pos += pb_protocol_serialise_string(pos, dev->description);
346 pos += pb_protocol_serialise_string(pos, dev->icon_file);
348 assert(pos <= buf + buf_len);
354 int pb_protocol_serialise_boot_option(const struct boot_option *opt,
355 char *buf, int buf_len)
359 pos += pb_protocol_serialise_string(pos, opt->device_id);
360 pos += pb_protocol_serialise_string(pos, opt->id);
361 pos += pb_protocol_serialise_string(pos, opt->name);
362 pos += pb_protocol_serialise_string(pos, opt->description);
363 pos += pb_protocol_serialise_string(pos, opt->icon_file);
364 pos += pb_protocol_serialise_string(pos, opt->boot_image_file);
365 pos += pb_protocol_serialise_string(pos, opt->initrd_file);
366 pos += pb_protocol_serialise_string(pos, opt->dtb_file);
367 pos += pb_protocol_serialise_string(pos, opt->boot_args);
368 pos += pb_protocol_serialise_string(pos, opt->args_sig_file);
370 *(bool *)pos = opt->is_default;
373 assert(pos <= buf + buf_len);
379 int pb_protocol_serialise_boot_command(const struct boot_command *boot,
380 char *buf, int buf_len)
384 pos += pb_protocol_serialise_string(pos, boot->option_id);
385 pos += pb_protocol_serialise_string(pos, boot->boot_image_file);
386 pos += pb_protocol_serialise_string(pos, boot->initrd_file);
387 pos += pb_protocol_serialise_string(pos, boot->dtb_file);
388 pos += pb_protocol_serialise_string(pos, boot->boot_args);
389 pos += pb_protocol_serialise_string(pos, boot->args_sig_file);
390 pos += pb_protocol_serialise_string(pos, boot->tty);
392 assert(pos <= buf + buf_len);
398 int pb_protocol_serialise_boot_status(const struct boot_status *status,
399 char *buf, int buf_len)
403 *(uint32_t *)pos = __cpu_to_be32(status->type);
404 pos += sizeof(uint32_t);
406 pos += pb_protocol_serialise_string(pos, status->message);
407 pos += pb_protocol_serialise_string(pos, status->detail);
409 *(uint32_t *)pos = __cpu_to_be32(status->type);
410 pos += sizeof(uint32_t);
412 assert(pos <= buf + buf_len);
418 int pb_protocol_serialise_system_info(const struct system_info *sysinfo,
419 char *buf, int buf_len)
424 pos += pb_protocol_serialise_string(pos, sysinfo->type);
425 pos += pb_protocol_serialise_string(pos, sysinfo->identifier);
427 *(uint32_t *)pos = __cpu_to_be32(sysinfo->n_primary);
428 pos += sizeof(uint32_t);
429 for (i = 0; i < sysinfo->n_primary; i++)
430 pos += pb_protocol_serialise_string(pos, sysinfo->platform_primary[i]);
432 *(uint32_t *)pos = __cpu_to_be32(sysinfo->n_other);
433 pos += sizeof(uint32_t);
434 for (i = 0; i < sysinfo->n_other; i++)
435 pos += pb_protocol_serialise_string(pos, sysinfo->platform_other[i]);
437 *(uint32_t *)pos = __cpu_to_be32(sysinfo->n_bmc_current);
438 pos += sizeof(uint32_t);
439 for (i = 0; i < sysinfo->n_bmc_current; i++)
440 pos += pb_protocol_serialise_string(pos, sysinfo->bmc_current[i]);
442 *(uint32_t *)pos = __cpu_to_be32(sysinfo->n_bmc_golden);
443 pos += sizeof(uint32_t);
444 for (i = 0; i < sysinfo->n_bmc_golden; i++)
445 pos += pb_protocol_serialise_string(pos, sysinfo->bmc_golden[i]);
447 *(uint32_t *)pos = __cpu_to_be32(sysinfo->n_interfaces);
448 pos += sizeof(uint32_t);
450 for (i = 0; i < sysinfo->n_interfaces; i++) {
451 struct interface_info *if_info = sysinfo->interfaces[i];
453 *(uint32_t *)pos = __cpu_to_be32(if_info->hwaddr_size);
454 pos += sizeof(uint32_t);
456 memcpy(pos, if_info->hwaddr, if_info->hwaddr_size);
457 pos += if_info->hwaddr_size;
459 pos += pb_protocol_serialise_string(pos, if_info->name);
461 *(bool *)pos = if_info->link;
465 *(uint32_t *)pos = __cpu_to_be32(sysinfo->n_blockdevs);
466 pos += sizeof(uint32_t);
468 for (i = 0; i < sysinfo->n_blockdevs; i++) {
469 struct blockdev_info *bd_info = sysinfo->blockdevs[i];
471 pos += pb_protocol_serialise_string(pos, bd_info->name);
472 pos += pb_protocol_serialise_string(pos, bd_info->uuid);
473 pos += pb_protocol_serialise_string(pos, bd_info->mountpoint);
476 if (sysinfo->bmc_mac)
477 memcpy(pos, sysinfo->bmc_mac, HWADDR_SIZE);
479 memset(pos, 0, HWADDR_SIZE);
482 assert(pos <= buf + buf_len);
488 static int pb_protocol_serialise_config_interface(char *buf,
489 struct interface_config *conf)
493 memcpy(pos, conf->hwaddr, sizeof(conf->hwaddr));
494 pos += sizeof(conf->hwaddr);
496 *(uint32_t *)pos = conf->ignore;
502 *(uint32_t *)pos = __cpu_to_be32(conf->method);
505 if (conf->method == CONFIG_METHOD_STATIC) {
506 pos += pb_protocol_serialise_string(pos,
507 conf->static_config.address);
508 pos += pb_protocol_serialise_string(pos,
509 conf->static_config.gateway);
510 pos += pb_protocol_serialise_string(pos,
511 conf->static_config.url);
517 int pb_protocol_serialise_config(const struct config *config,
518 char *buf, int buf_len)
523 *(uint32_t *)pos = config->autoboot_enabled;
526 *(uint32_t *)pos = __cpu_to_be32(config->autoboot_timeout_sec);
529 *(uint32_t *)pos = config->safe_mode;
532 *(uint32_t *)pos = __cpu_to_be32(config->network.n_interfaces);
534 for (i = 0; i < config->network.n_interfaces; i++) {
535 struct interface_config *iface =
536 config->network.interfaces[i];
537 pos += pb_protocol_serialise_config_interface(pos, iface);
540 *(uint32_t *)pos = __cpu_to_be32(config->network.n_dns_servers);
542 for (i = 0; i < config->network.n_dns_servers; i++) {
543 pos += pb_protocol_serialise_string(pos,
544 config->network.dns_servers[i]);
547 *(uint32_t *)pos = __cpu_to_be32(config->n_autoboot_opts);
549 for (i = 0; i < config->n_autoboot_opts; i++) {
551 __cpu_to_be32(config->autoboot_opts[i].boot_type);
553 if (config->autoboot_opts[i].boot_type == BOOT_DEVICE_TYPE) {
555 __cpu_to_be32(config->autoboot_opts[i].type);
558 pos += pb_protocol_serialise_string(pos,
559 config->autoboot_opts[i].uuid);
563 *(uint32_t *)pos = __cpu_to_be32(config->ipmi_bootdev);
565 *(uint32_t *)pos = config->ipmi_bootdev_persistent;
568 *(uint32_t *)pos = config->allow_writes;
571 *(uint32_t *)pos = __cpu_to_be32(config->n_tty);
573 for (i = 0; i < config->n_tty; i++)
574 pos += pb_protocol_serialise_string(pos, config->tty_list[i]);
576 pos += pb_protocol_serialise_string(pos, config->boot_tty);
578 pos += pb_protocol_serialise_string(pos, config->lang);
580 assert(pos <= buf + buf_len);
586 int pb_protocol_serialise_url(const char *url, char *buf, int buf_len)
590 pos += pb_protocol_serialise_string(pos, url);
592 assert(pos <=buf+buf_len);
598 int pb_protocol_write_message(int fd, struct pb_protocol_message *message)
603 total_len = sizeof(*message) + message->payload_len;
605 message->payload_len = __cpu_to_be32(message->payload_len);
606 message->action = __cpu_to_be32(message->action);
608 for (pos = (void *)message; total_len;) {
609 rc = write(fd, pos, total_len);
618 talloc_free(message);
623 pb_log("%s: failed: %s\n", __func__, strerror(errno));
627 struct pb_protocol_message *pb_protocol_create_message(void *ctx,
628 enum pb_protocol_action action, int payload_len)
630 struct pb_protocol_message *message;
632 if (payload_len > PB_PROTOCOL_MAX_PAYLOAD_SIZE) {
633 pb_log("%s: payload too big %u/%u\n", __func__, payload_len,
634 PB_PROTOCOL_MAX_PAYLOAD_SIZE);
638 message = talloc_size(ctx, sizeof(*message) + payload_len);
640 /* we convert these to big-endian in write_message() */
641 message->action = action;
642 message->payload_len = payload_len;
648 struct pb_protocol_message *pb_protocol_read_message(void *ctx, int fd)
650 struct pb_protocol_message *message, m;
654 /* use the stack for the initial 8-byte read */
656 rc = read(fd, &m, sizeof(m));
660 m.payload_len = __be32_to_cpu(m.payload_len);
661 m.action = __be32_to_cpu(m.action);
663 if (m.payload_len > PB_PROTOCOL_MAX_PAYLOAD_SIZE) {
664 pb_log("%s: payload too big %u/%u\n", __func__, m.payload_len,
665 PB_PROTOCOL_MAX_PAYLOAD_SIZE);
669 message = talloc_size(ctx, sizeof(m) + m.payload_len);
670 memcpy(message, &m, sizeof(m));
672 for (len = 0; len < m.payload_len;) {
673 rc = read(fd, message->payload + len, m.payload_len - len);
676 talloc_free(message);
677 pb_log("%s: failed (%u): %s\n", __func__, len,
689 int pb_protocol_deserialise_device(struct device *dev,
690 const struct pb_protocol_message *message)
696 len = message->payload_len;
697 pos = message->payload;
699 if (read_string(dev, &pos, &len, &dev->id))
702 if (len < sizeof(enum device_type))
704 dev->type = *(enum device_type *)(pos);
705 pos += sizeof(enum device_type);
706 len -= sizeof(enum device_type);
708 if (read_string(dev, &pos, &len, &dev->name))
711 if (read_string(dev, &pos, &len, &dev->description))
714 if (read_string(dev, &pos, &len, &dev->icon_file))
723 int pb_protocol_deserialise_boot_option(struct boot_option *opt,
724 const struct pb_protocol_message *message)
730 len = message->payload_len;
731 pos = message->payload;
733 if (read_string(opt, &pos, &len, &opt->device_id))
736 if (read_string(opt, &pos, &len, &opt->id))
739 if (read_string(opt, &pos, &len, &opt->name))
742 if (read_string(opt, &pos, &len, &opt->description))
745 if (read_string(opt, &pos, &len, &opt->icon_file))
748 if (read_string(opt, &pos, &len, &opt->boot_image_file))
751 if (read_string(opt, &pos, &len, &opt->initrd_file))
754 if (read_string(opt, &pos, &len, &opt->dtb_file))
757 if (read_string(opt, &pos, &len, &opt->boot_args))
760 if (read_string(opt, &pos, &len, &opt->args_sig_file))
763 if (len < sizeof(bool))
765 opt->is_default = *(bool *)(pos);
773 int pb_protocol_deserialise_boot_command(struct boot_command *cmd,
774 const struct pb_protocol_message *message)
780 len = message->payload_len;
781 pos = message->payload;
783 if (read_string(cmd, &pos, &len, &cmd->option_id))
786 if (read_string(cmd, &pos, &len, &cmd->boot_image_file))
789 if (read_string(cmd, &pos, &len, &cmd->initrd_file))
792 if (read_string(cmd, &pos, &len, &cmd->dtb_file))
795 if (read_string(cmd, &pos, &len, &cmd->boot_args))
798 if (read_string(cmd, &pos, &len, &cmd->args_sig_file))
801 if (read_string(cmd, &pos, &len, &cmd->tty))
810 int pb_protocol_deserialise_boot_status(struct boot_status *status,
811 const struct pb_protocol_message *message)
817 len = message->payload_len;
818 pos = message->payload;
820 /* first up, the type enum... */
821 if (len < sizeof(uint32_t))
824 status->type = __be32_to_cpu(*(uint32_t *)(pos));
826 switch (status->type) {
827 case BOOT_STATUS_ERROR:
828 case BOOT_STATUS_INFO:
834 pos += sizeof(uint32_t);
835 len -= sizeof(uint32_t);
837 /* message and detail strings */
838 if (read_string(status, &pos, &len, &status->message))
841 if (read_string(status, &pos, &len, &status->detail))
844 /* and finally, progress */
845 if (len < sizeof(uint32_t))
848 status->progress = __be32_to_cpu(*(uint32_t *)(pos));
851 if (status->progress > 100)
852 status->progress = 100;
860 int pb_protocol_deserialise_system_info(struct system_info *sysinfo,
861 const struct pb_protocol_message *message)
868 len = message->payload_len;
869 pos = message->payload;
871 /* type and identifier strings */
872 if (read_string(sysinfo, &pos, &len, &sysinfo->type))
875 if (read_string(sysinfo, &pos, &len, &sysinfo->identifier))
878 /* Platform version strings for openpower platforms */
879 if (read_u32(&pos, &len, &sysinfo->n_primary))
881 sysinfo->platform_primary = talloc_array(sysinfo, char *,
883 for (i = 0; i < sysinfo->n_primary; i++) {
884 if (read_string(sysinfo, &pos, &len, &tmp))
886 sysinfo->platform_primary[i] = talloc_strdup(sysinfo, tmp);
889 if (read_u32(&pos, &len, &sysinfo->n_other))
891 sysinfo->platform_other = talloc_array(sysinfo, char *,
893 for (i = 0; i < sysinfo->n_other; i++) {
894 if (read_string(sysinfo, &pos, &len, &tmp))
896 sysinfo->platform_other[i] = talloc_strdup(sysinfo, tmp);
899 /* BMC version strings for openpower platforms */
900 if (read_u32(&pos, &len, &sysinfo->n_bmc_current))
902 sysinfo->bmc_current = talloc_array(sysinfo, char *,
903 sysinfo->n_bmc_current);
904 for (i = 0; i < sysinfo->n_bmc_current; i++) {
905 if (read_string(sysinfo, &pos, &len, &tmp))
907 sysinfo->bmc_current[i] = talloc_strdup(sysinfo, tmp);
910 if (read_u32(&pos, &len, &sysinfo->n_bmc_golden))
912 sysinfo->bmc_golden = talloc_array(sysinfo, char *,
913 sysinfo->n_bmc_golden);
914 for (i = 0; i < sysinfo->n_bmc_golden; i++) {
915 if (read_string(sysinfo, &pos, &len, &tmp))
917 sysinfo->bmc_golden[i] = talloc_strdup(sysinfo, tmp);
920 /* number of interfaces */
921 if (read_u32(&pos, &len, &sysinfo->n_interfaces))
924 sysinfo->interfaces = talloc_array(sysinfo, struct interface_info *,
925 sysinfo->n_interfaces);
927 for (i = 0; i < sysinfo->n_interfaces; i++) {
928 struct interface_info *if_info = talloc(sysinfo,
929 struct interface_info);
931 if (read_u32(&pos, &len, &if_info->hwaddr_size))
934 if (len < if_info->hwaddr_size)
937 if_info->hwaddr = talloc_memdup(if_info, pos,
938 if_info->hwaddr_size);
939 pos += if_info->hwaddr_size;
940 len -= if_info->hwaddr_size;
942 if (read_string(if_info, &pos, &len, &if_info->name))
945 if_info->link = *(bool *)pos;
946 pos += sizeof(if_info->link);
948 sysinfo->interfaces[i] = if_info;
951 /* number of interfaces */
952 if (read_u32(&pos, &len, &sysinfo->n_blockdevs))
955 sysinfo->blockdevs = talloc_array(sysinfo, struct blockdev_info *,
956 sysinfo->n_blockdevs);
958 for (i = 0; i < sysinfo->n_blockdevs; i++) {
959 struct blockdev_info *bd_info = talloc(sysinfo,
960 struct blockdev_info);
962 if (read_string(bd_info, &pos, &len, &bd_info->name))
965 if (read_string(bd_info, &pos, &len, &bd_info->uuid))
968 if (read_string(bd_info, &pos, &len, &bd_info->mountpoint))
971 sysinfo->blockdevs[i] = bd_info;
974 for (i = 0; i < HWADDR_SIZE; i++) {
976 sysinfo->bmc_mac = talloc_memdup(sysinfo, pos, HWADDR_SIZE);
989 static int pb_protocol_deserialise_config_interface(const char **buf,
990 unsigned int *len, struct interface_config *iface)
994 if (*len < sizeof(iface->hwaddr))
997 memcpy(iface->hwaddr, *buf, sizeof(iface->hwaddr));
998 *buf += sizeof(iface->hwaddr);
999 *len -= sizeof(iface->hwaddr);
1001 if (read_u32(buf, len, &tmp))
1003 iface->ignore = !!tmp;
1008 if (read_u32(buf, len, &iface->method))
1011 if (iface->method == CONFIG_METHOD_STATIC) {
1012 if (read_string(iface, buf, len, &iface->static_config.address))
1015 if (read_string(iface, buf, len, &iface->static_config.gateway))
1018 if (read_string(iface, buf, len, &iface->static_config.url))
1025 int pb_protocol_deserialise_config(struct config *config,
1026 const struct pb_protocol_message *message)
1028 unsigned int len, i, tmp;
1033 len = message->payload_len;
1034 pos = message->payload;
1036 if (read_u32(&pos, &len, &tmp))
1038 config->autoboot_enabled = !!tmp;
1040 if (read_u32(&pos, &len, &config->autoboot_timeout_sec))
1043 if (read_u32(&pos, &len, &tmp))
1045 config->safe_mode = !!tmp;
1047 if (read_u32(&pos, &len, &config->network.n_interfaces))
1050 config->network.interfaces = talloc_array(config,
1051 struct interface_config *, config->network.n_interfaces);
1053 for (i = 0; i < config->network.n_interfaces; i++) {
1054 struct interface_config *iface = talloc_zero(
1055 config->network.interfaces,
1056 struct interface_config);
1057 if (pb_protocol_deserialise_config_interface(&pos, &len, iface))
1059 config->network.interfaces[i] = iface;
1062 if (read_u32(&pos, &len, &config->network.n_dns_servers))
1064 config->network.dns_servers = talloc_array(config, const char *,
1065 config->network.n_dns_servers);
1067 for (i = 0; i < config->network.n_dns_servers; i++) {
1068 if (read_string(config->network.dns_servers, &pos, &len, &str))
1070 config->network.dns_servers[i] = str;
1073 if (read_u32(&pos, &len, &config->n_autoboot_opts))
1075 config->autoboot_opts = talloc_array(config, struct autoboot_option,
1076 config->n_autoboot_opts);
1078 for (i = 0; i < config->n_autoboot_opts; i++) {
1079 if (read_u32(&pos, &len, &tmp))
1081 config->autoboot_opts[i].boot_type = (int)tmp;
1082 if (config->autoboot_opts[i].boot_type == BOOT_DEVICE_TYPE) {
1083 if (read_u32(&pos, &len, &tmp))
1085 config->autoboot_opts[i].type = tmp;
1087 if (read_string(config, &pos, &len, &str))
1089 config->autoboot_opts[i].uuid = str;
1093 if (read_u32(&pos, &len, &config->ipmi_bootdev))
1095 if (read_u32(&pos, &len, &tmp))
1097 config->ipmi_bootdev_persistent = !!tmp;
1099 if (read_u32(&pos, &len, &tmp))
1101 config->allow_writes = !!tmp;
1103 if (read_u32(&pos, &len, &config->n_tty))
1106 config->tty_list = talloc_array(config, char *, config->n_tty);
1107 for (i = 0; i < config->n_tty; i++) {
1108 if (read_string(config->tty_list, &pos, &len, &str))
1110 config->tty_list[i] = str;
1113 if (read_string(config, &pos, &len, &str))
1116 config->boot_tty = str;
1118 if (read_string(config, &pos, &len, &str))