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->console);
218 int pb_protocol_boot_status_len(const struct status *status)
220 return 4 + /* type */
221 4 + optional_strlen(status->message) +
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) +
253 4 + optional_strlen(if_info->address);
256 for (i = 0; i < sysinfo->n_blockdevs; i++) {
257 struct blockdev_info *bd_info = sysinfo->blockdevs[i];
258 len += 4 + optional_strlen(bd_info->name) +
259 4 + optional_strlen(bd_info->uuid) +
260 4 + optional_strlen(bd_info->mountpoint);
269 static int pb_protocol_interface_config_len(struct interface_config *conf)
273 len = sizeof(conf->hwaddr) +
274 4 /* conf->ignore */;
279 len += 4 /* conf->method */;
281 if (conf->method == CONFIG_METHOD_STATIC) {
282 len += 4 + optional_strlen(conf->static_config.address);
283 len += 4 + optional_strlen(conf->static_config.gateway);
284 len += 4 + optional_strlen(conf->static_config.url);
287 len += 4 /* conf->override */;
292 int pb_protocol_config_len(const struct config *config)
296 len = 4 /* config->autoboot_enabled */ +
297 4 /* config->autoboot_timeout_sec */ +
298 4 /* config->safe_mode */;
301 for (i = 0; i < config->network.n_interfaces; i++)
302 len += pb_protocol_interface_config_len(
303 config->network.interfaces[i]);
306 for (i = 0; i < config->network.n_dns_servers; i++)
307 len += 4 + optional_strlen(config->network.dns_servers[i]);
309 len += 4 + optional_strlen(config->http_proxy);
310 len += 4 + optional_strlen(config->https_proxy);
313 for (i = 0; i < config->n_autoboot_opts; i++) {
314 if (config->autoboot_opts[i].boot_type == BOOT_DEVICE_TYPE)
318 optional_strlen(config->autoboot_opts[i].uuid);
321 len += 4 + 4; /* ipmi_bootdev, ipmi_bootdev_persistent */
323 len += 4; /* allow_writes */
325 len += 4; /* n_consoles */
326 for (i = 0; i < config->n_consoles; i++)
327 len += 4 + optional_strlen(config->consoles[i]);
329 len += 4 + optional_strlen(config->boot_console);
330 len += 4; /* manual_console */
332 len += 4 + optional_strlen(config->lang);
337 int pb_protocol_url_len(const char *url)
339 /* url + length field */
340 return 4 + optional_strlen(url);
344 int pb_protocol_plugin_option_len(const struct plugin_option *opt)
346 unsigned int i, len = 0;
348 len += 4 + optional_strlen(opt->id);
349 len += 4 + optional_strlen(opt->name);
350 len += 4 + optional_strlen(opt->vendor);
351 len += 4 + optional_strlen(opt->vendor_id);
352 len += 4 + optional_strlen(opt->version);
353 len += 4 + optional_strlen(opt->date);
354 len += 4 + optional_strlen(opt->plugin_file);
356 len += 4; /* n_executables */
357 for (i = 0; i < opt->n_executables; i++)
358 len += 4 + optional_strlen(opt->executables[i]);
363 int pb_protocol_serialise_device(const struct device *dev,
364 char *buf, int buf_len)
368 pos += pb_protocol_serialise_string(pos, dev->id);
369 *(enum device_type *)pos = dev->type;
370 pos += sizeof(enum device_type);
371 pos += pb_protocol_serialise_string(pos, dev->name);
372 pos += pb_protocol_serialise_string(pos, dev->description);
373 pos += pb_protocol_serialise_string(pos, dev->icon_file);
375 assert(pos <= buf + buf_len);
381 int pb_protocol_serialise_boot_option(const struct boot_option *opt,
382 char *buf, int buf_len)
386 pos += pb_protocol_serialise_string(pos, opt->device_id);
387 pos += pb_protocol_serialise_string(pos, opt->id);
388 pos += pb_protocol_serialise_string(pos, opt->name);
389 pos += pb_protocol_serialise_string(pos, opt->description);
390 pos += pb_protocol_serialise_string(pos, opt->icon_file);
391 pos += pb_protocol_serialise_string(pos, opt->boot_image_file);
392 pos += pb_protocol_serialise_string(pos, opt->initrd_file);
393 pos += pb_protocol_serialise_string(pos, opt->dtb_file);
394 pos += pb_protocol_serialise_string(pos, opt->boot_args);
395 pos += pb_protocol_serialise_string(pos, opt->args_sig_file);
397 *(bool *)pos = opt->is_default;
400 assert(pos <= buf + buf_len);
406 int pb_protocol_serialise_boot_command(const struct boot_command *boot,
407 char *buf, int buf_len)
411 pos += pb_protocol_serialise_string(pos, boot->option_id);
412 pos += pb_protocol_serialise_string(pos, boot->boot_image_file);
413 pos += pb_protocol_serialise_string(pos, boot->initrd_file);
414 pos += pb_protocol_serialise_string(pos, boot->dtb_file);
415 pos += pb_protocol_serialise_string(pos, boot->boot_args);
416 pos += pb_protocol_serialise_string(pos, boot->args_sig_file);
417 pos += pb_protocol_serialise_string(pos, boot->console);
419 assert(pos <= buf + buf_len);
425 int pb_protocol_serialise_boot_status(const struct status *status,
426 char *buf, int buf_len)
430 *(uint32_t *)pos = __cpu_to_be32(status->type);
431 pos += sizeof(uint32_t);
433 pos += pb_protocol_serialise_string(pos, status->message);
435 *(bool *)pos = __cpu_to_be32(status->backlog);
438 assert(pos <= buf + buf_len);
444 int pb_protocol_serialise_system_info(const struct system_info *sysinfo,
445 char *buf, int buf_len)
450 pos += pb_protocol_serialise_string(pos, sysinfo->type);
451 pos += pb_protocol_serialise_string(pos, sysinfo->identifier);
453 *(uint32_t *)pos = __cpu_to_be32(sysinfo->n_primary);
454 pos += sizeof(uint32_t);
455 for (i = 0; i < sysinfo->n_primary; i++)
456 pos += pb_protocol_serialise_string(pos, sysinfo->platform_primary[i]);
458 *(uint32_t *)pos = __cpu_to_be32(sysinfo->n_other);
459 pos += sizeof(uint32_t);
460 for (i = 0; i < sysinfo->n_other; i++)
461 pos += pb_protocol_serialise_string(pos, sysinfo->platform_other[i]);
463 *(uint32_t *)pos = __cpu_to_be32(sysinfo->n_bmc_current);
464 pos += sizeof(uint32_t);
465 for (i = 0; i < sysinfo->n_bmc_current; i++)
466 pos += pb_protocol_serialise_string(pos, sysinfo->bmc_current[i]);
468 *(uint32_t *)pos = __cpu_to_be32(sysinfo->n_bmc_golden);
469 pos += sizeof(uint32_t);
470 for (i = 0; i < sysinfo->n_bmc_golden; i++)
471 pos += pb_protocol_serialise_string(pos, sysinfo->bmc_golden[i]);
473 *(uint32_t *)pos = __cpu_to_be32(sysinfo->n_interfaces);
474 pos += sizeof(uint32_t);
476 for (i = 0; i < sysinfo->n_interfaces; i++) {
477 struct interface_info *if_info = sysinfo->interfaces[i];
479 *(uint32_t *)pos = __cpu_to_be32(if_info->hwaddr_size);
480 pos += sizeof(uint32_t);
482 memcpy(pos, if_info->hwaddr, if_info->hwaddr_size);
483 pos += if_info->hwaddr_size;
485 pos += pb_protocol_serialise_string(pos, if_info->name);
487 *(bool *)pos = if_info->link;
490 pos += pb_protocol_serialise_string(pos, if_info->address);
493 *(uint32_t *)pos = __cpu_to_be32(sysinfo->n_blockdevs);
494 pos += sizeof(uint32_t);
496 for (i = 0; i < sysinfo->n_blockdevs; i++) {
497 struct blockdev_info *bd_info = sysinfo->blockdevs[i];
499 pos += pb_protocol_serialise_string(pos, bd_info->name);
500 pos += pb_protocol_serialise_string(pos, bd_info->uuid);
501 pos += pb_protocol_serialise_string(pos, bd_info->mountpoint);
504 if (sysinfo->bmc_mac)
505 memcpy(pos, sysinfo->bmc_mac, HWADDR_SIZE);
507 memset(pos, 0, HWADDR_SIZE);
510 assert(pos <= buf + buf_len);
516 static int pb_protocol_serialise_config_interface(char *buf,
517 struct interface_config *conf)
521 memcpy(pos, conf->hwaddr, sizeof(conf->hwaddr));
522 pos += sizeof(conf->hwaddr);
524 *(uint32_t *)pos = conf->ignore;
530 *(uint32_t *)pos = __cpu_to_be32(conf->method);
533 if (conf->method == CONFIG_METHOD_STATIC) {
534 pos += pb_protocol_serialise_string(pos,
535 conf->static_config.address);
536 pos += pb_protocol_serialise_string(pos,
537 conf->static_config.gateway);
538 pos += pb_protocol_serialise_string(pos,
539 conf->static_config.url);
542 *(uint32_t *)pos = conf->override;
548 int pb_protocol_serialise_config(const struct config *config,
549 char *buf, int buf_len)
554 *(uint32_t *)pos = config->autoboot_enabled;
557 *(uint32_t *)pos = __cpu_to_be32(config->autoboot_timeout_sec);
560 *(uint32_t *)pos = config->safe_mode;
563 *(uint32_t *)pos = __cpu_to_be32(config->network.n_interfaces);
565 for (i = 0; i < config->network.n_interfaces; i++) {
566 struct interface_config *iface =
567 config->network.interfaces[i];
568 pos += pb_protocol_serialise_config_interface(pos, iface);
571 *(uint32_t *)pos = __cpu_to_be32(config->network.n_dns_servers);
573 for (i = 0; i < config->network.n_dns_servers; i++) {
574 pos += pb_protocol_serialise_string(pos,
575 config->network.dns_servers[i]);
578 pos += pb_protocol_serialise_string(pos, config->http_proxy);
579 pos += pb_protocol_serialise_string(pos, config->https_proxy);
581 *(uint32_t *)pos = __cpu_to_be32(config->n_autoboot_opts);
583 for (i = 0; i < config->n_autoboot_opts; i++) {
585 __cpu_to_be32(config->autoboot_opts[i].boot_type);
587 if (config->autoboot_opts[i].boot_type == BOOT_DEVICE_TYPE) {
589 __cpu_to_be32(config->autoboot_opts[i].type);
592 pos += pb_protocol_serialise_string(pos,
593 config->autoboot_opts[i].uuid);
597 *(uint32_t *)pos = __cpu_to_be32(config->ipmi_bootdev);
599 *(uint32_t *)pos = config->ipmi_bootdev_persistent;
602 *(uint32_t *)pos = config->allow_writes;
605 *(uint32_t *)pos = __cpu_to_be32(config->n_consoles);
607 for (i = 0; i < config->n_consoles; i++)
608 pos += pb_protocol_serialise_string(pos, config->consoles[i]);
610 pos += pb_protocol_serialise_string(pos, config->boot_console);
611 *(uint32_t *)pos = config->manual_console;
614 pos += pb_protocol_serialise_string(pos, config->lang);
616 assert(pos <= buf + buf_len);
622 int pb_protocol_serialise_url(const char *url, char *buf, int buf_len)
626 pos += pb_protocol_serialise_string(pos, url);
628 assert(pos <=buf+buf_len);
634 int pb_protocol_serialise_plugin_option(const struct plugin_option *opt,
635 char *buf, int buf_len)
640 pos += pb_protocol_serialise_string(pos, opt->id);
641 pos += pb_protocol_serialise_string(pos, opt->name);
642 pos += pb_protocol_serialise_string(pos, opt->vendor);
643 pos += pb_protocol_serialise_string(pos, opt->vendor_id);
644 pos += pb_protocol_serialise_string(pos, opt->version);
645 pos += pb_protocol_serialise_string(pos, opt->date);
646 pos += pb_protocol_serialise_string(pos, opt->plugin_file);
648 *(uint32_t *)pos = __cpu_to_be32(opt->n_executables);
651 for (i = 0; i < opt->n_executables; i++)
652 pos += pb_protocol_serialise_string(pos, opt->executables[i]);
654 assert(pos <= buf + buf_len);
660 int pb_protocol_write_message(int fd, struct pb_protocol_message *message)
665 total_len = sizeof(*message) + message->payload_len;
667 message->payload_len = __cpu_to_be32(message->payload_len);
668 message->action = __cpu_to_be32(message->action);
670 for (pos = (void *)message; total_len;) {
671 rc = write(fd, pos, total_len);
680 talloc_free(message);
685 pb_log("%s: failed: %s\n", __func__, strerror(errno));
689 struct pb_protocol_message *pb_protocol_create_message(void *ctx,
690 enum pb_protocol_action action, int payload_len)
692 struct pb_protocol_message *message;
694 if (payload_len > PB_PROTOCOL_MAX_PAYLOAD_SIZE) {
695 pb_log("%s: payload too big %u/%u\n", __func__, payload_len,
696 PB_PROTOCOL_MAX_PAYLOAD_SIZE);
700 message = talloc_size(ctx, sizeof(*message) + payload_len);
702 /* we convert these to big-endian in write_message() */
703 message->action = action;
704 message->payload_len = payload_len;
710 struct pb_protocol_message *pb_protocol_read_message(void *ctx, int fd)
712 struct pb_protocol_message *message, m;
716 /* use the stack for the initial 8-byte read */
718 rc = read(fd, &m, sizeof(m));
722 m.payload_len = __be32_to_cpu(m.payload_len);
723 m.action = __be32_to_cpu(m.action);
725 if (m.payload_len > PB_PROTOCOL_MAX_PAYLOAD_SIZE) {
726 pb_log("%s: payload too big %u/%u\n", __func__, m.payload_len,
727 PB_PROTOCOL_MAX_PAYLOAD_SIZE);
731 message = talloc_size(ctx, sizeof(m) + m.payload_len);
732 memcpy(message, &m, sizeof(m));
734 for (len = 0; len < m.payload_len;) {
735 rc = read(fd, message->payload + len, m.payload_len - len);
738 talloc_free(message);
739 pb_log("%s: failed (%u): %s\n", __func__, len,
751 int pb_protocol_deserialise_device(struct device *dev,
752 const struct pb_protocol_message *message)
758 len = message->payload_len;
759 pos = message->payload;
761 if (read_string(dev, &pos, &len, &dev->id))
764 if (len < sizeof(enum device_type))
766 dev->type = *(enum device_type *)(pos);
767 pos += sizeof(enum device_type);
768 len -= sizeof(enum device_type);
770 if (read_string(dev, &pos, &len, &dev->name))
773 if (read_string(dev, &pos, &len, &dev->description))
776 if (read_string(dev, &pos, &len, &dev->icon_file))
785 int pb_protocol_deserialise_boot_option(struct boot_option *opt,
786 const struct pb_protocol_message *message)
792 len = message->payload_len;
793 pos = message->payload;
795 if (read_string(opt, &pos, &len, &opt->device_id))
798 if (read_string(opt, &pos, &len, &opt->id))
801 if (read_string(opt, &pos, &len, &opt->name))
804 if (read_string(opt, &pos, &len, &opt->description))
807 if (read_string(opt, &pos, &len, &opt->icon_file))
810 if (read_string(opt, &pos, &len, &opt->boot_image_file))
813 if (read_string(opt, &pos, &len, &opt->initrd_file))
816 if (read_string(opt, &pos, &len, &opt->dtb_file))
819 if (read_string(opt, &pos, &len, &opt->boot_args))
822 if (read_string(opt, &pos, &len, &opt->args_sig_file))
825 if (len < sizeof(bool))
827 opt->is_default = *(bool *)(pos);
835 int pb_protocol_deserialise_boot_command(struct boot_command *cmd,
836 const struct pb_protocol_message *message)
842 len = message->payload_len;
843 pos = message->payload;
845 if (read_string(cmd, &pos, &len, &cmd->option_id))
848 if (read_string(cmd, &pos, &len, &cmd->boot_image_file))
851 if (read_string(cmd, &pos, &len, &cmd->initrd_file))
854 if (read_string(cmd, &pos, &len, &cmd->dtb_file))
857 if (read_string(cmd, &pos, &len, &cmd->boot_args))
860 if (read_string(cmd, &pos, &len, &cmd->args_sig_file))
863 if (read_string(cmd, &pos, &len, &cmd->console))
872 int pb_protocol_deserialise_boot_status(struct status *status,
873 const struct pb_protocol_message *message)
879 len = message->payload_len;
880 pos = message->payload;
882 /* first up, the type enum... */
883 if (len < sizeof(uint32_t))
886 status->type = __be32_to_cpu(*(uint32_t *)(pos));
888 switch (status->type) {
896 pos += sizeof(uint32_t);
897 len -= sizeof(uint32_t);
900 if (read_string(status, &pos, &len, &status->message))
904 status->backlog = *(bool *)pos;
905 pos += sizeof(status->backlog);
913 int pb_protocol_deserialise_system_info(struct system_info *sysinfo,
914 const struct pb_protocol_message *message)
921 len = message->payload_len;
922 pos = message->payload;
924 /* type and identifier strings */
925 if (read_string(sysinfo, &pos, &len, &sysinfo->type))
928 if (read_string(sysinfo, &pos, &len, &sysinfo->identifier))
931 /* Platform version strings for openpower platforms */
932 if (read_u32(&pos, &len, &sysinfo->n_primary))
934 sysinfo->platform_primary = talloc_array(sysinfo, char *,
936 for (i = 0; i < sysinfo->n_primary; i++) {
937 if (read_string(sysinfo, &pos, &len, &tmp))
939 sysinfo->platform_primary[i] = talloc_strdup(sysinfo, tmp);
942 if (read_u32(&pos, &len, &sysinfo->n_other))
944 sysinfo->platform_other = talloc_array(sysinfo, char *,
946 for (i = 0; i < sysinfo->n_other; i++) {
947 if (read_string(sysinfo, &pos, &len, &tmp))
949 sysinfo->platform_other[i] = talloc_strdup(sysinfo, tmp);
952 /* BMC version strings for openpower platforms */
953 if (read_u32(&pos, &len, &sysinfo->n_bmc_current))
955 sysinfo->bmc_current = talloc_array(sysinfo, char *,
956 sysinfo->n_bmc_current);
957 for (i = 0; i < sysinfo->n_bmc_current; i++) {
958 if (read_string(sysinfo, &pos, &len, &tmp))
960 sysinfo->bmc_current[i] = talloc_strdup(sysinfo, tmp);
963 if (read_u32(&pos, &len, &sysinfo->n_bmc_golden))
965 sysinfo->bmc_golden = talloc_array(sysinfo, char *,
966 sysinfo->n_bmc_golden);
967 for (i = 0; i < sysinfo->n_bmc_golden; i++) {
968 if (read_string(sysinfo, &pos, &len, &tmp))
970 sysinfo->bmc_golden[i] = talloc_strdup(sysinfo, tmp);
973 /* number of interfaces */
974 if (read_u32(&pos, &len, &sysinfo->n_interfaces))
977 sysinfo->interfaces = talloc_array(sysinfo, struct interface_info *,
978 sysinfo->n_interfaces);
980 for (i = 0; i < sysinfo->n_interfaces; i++) {
981 struct interface_info *if_info = talloc(sysinfo,
982 struct interface_info);
984 if (read_u32(&pos, &len, &if_info->hwaddr_size))
987 if (len < if_info->hwaddr_size)
990 if_info->hwaddr = talloc_memdup(if_info, pos,
991 if_info->hwaddr_size);
992 pos += if_info->hwaddr_size;
993 len -= if_info->hwaddr_size;
995 if (read_string(if_info, &pos, &len, &if_info->name))
998 if_info->link = *(bool *)pos;
999 pos += sizeof(if_info->link);
1001 if (read_string(if_info, &pos, &len, &if_info->address))
1004 sysinfo->interfaces[i] = if_info;
1007 /* number of interfaces */
1008 if (read_u32(&pos, &len, &sysinfo->n_blockdevs))
1011 sysinfo->blockdevs = talloc_array(sysinfo, struct blockdev_info *,
1012 sysinfo->n_blockdevs);
1014 for (i = 0; i < sysinfo->n_blockdevs; i++) {
1015 struct blockdev_info *bd_info = talloc(sysinfo,
1016 struct blockdev_info);
1018 if (read_string(bd_info, &pos, &len, &bd_info->name))
1021 if (read_string(bd_info, &pos, &len, &bd_info->uuid))
1024 if (read_string(bd_info, &pos, &len, &bd_info->mountpoint))
1027 sysinfo->blockdevs[i] = bd_info;
1030 for (i = 0; i < HWADDR_SIZE; i++) {
1032 sysinfo->bmc_mac = talloc_memdup(sysinfo, pos, HWADDR_SIZE);
1045 static int pb_protocol_deserialise_config_interface(const char **buf,
1046 unsigned int *len, struct interface_config *iface)
1050 if (*len < sizeof(iface->hwaddr))
1053 memcpy(iface->hwaddr, *buf, sizeof(iface->hwaddr));
1054 *buf += sizeof(iface->hwaddr);
1055 *len -= sizeof(iface->hwaddr);
1057 if (read_u32(buf, len, &tmp))
1059 iface->ignore = !!tmp;
1064 if (read_u32(buf, len, &iface->method))
1067 if (iface->method == CONFIG_METHOD_STATIC) {
1068 if (read_string(iface, buf, len, &iface->static_config.address))
1071 if (read_string(iface, buf, len, &iface->static_config.gateway))
1074 if (read_string(iface, buf, len, &iface->static_config.url))
1078 if (read_u32(buf, len, &tmp))
1080 iface->override = !!tmp;
1085 int pb_protocol_deserialise_config(struct config *config,
1086 const struct pb_protocol_message *message)
1088 unsigned int len, i, tmp;
1093 len = message->payload_len;
1094 pos = message->payload;
1096 if (read_u32(&pos, &len, &tmp))
1098 config->autoboot_enabled = !!tmp;
1100 if (read_u32(&pos, &len, &config->autoboot_timeout_sec))
1103 if (read_u32(&pos, &len, &tmp))
1105 config->safe_mode = !!tmp;
1107 if (read_u32(&pos, &len, &config->network.n_interfaces))
1110 config->network.interfaces = talloc_array(config,
1111 struct interface_config *, config->network.n_interfaces);
1113 for (i = 0; i < config->network.n_interfaces; i++) {
1114 struct interface_config *iface = talloc_zero(
1115 config->network.interfaces,
1116 struct interface_config);
1117 if (pb_protocol_deserialise_config_interface(&pos, &len, iface))
1119 config->network.interfaces[i] = iface;
1122 if (read_u32(&pos, &len, &config->network.n_dns_servers))
1124 config->network.dns_servers = talloc_array(config, const char *,
1125 config->network.n_dns_servers);
1127 for (i = 0; i < config->network.n_dns_servers; i++) {
1128 if (read_string(config->network.dns_servers, &pos, &len, &str))
1130 config->network.dns_servers[i] = str;
1133 if (read_string(config, &pos, &len, &str))
1135 config->http_proxy = str;
1136 if (read_string(config, &pos, &len, &str))
1138 config->https_proxy = str;
1140 if (read_u32(&pos, &len, &config->n_autoboot_opts))
1142 config->autoboot_opts = talloc_array(config, struct autoboot_option,
1143 config->n_autoboot_opts);
1145 for (i = 0; i < config->n_autoboot_opts; i++) {
1146 if (read_u32(&pos, &len, &tmp))
1148 config->autoboot_opts[i].boot_type = (int)tmp;
1149 if (config->autoboot_opts[i].boot_type == BOOT_DEVICE_TYPE) {
1150 if (read_u32(&pos, &len, &tmp))
1152 config->autoboot_opts[i].type = tmp;
1154 if (read_string(config, &pos, &len, &str))
1156 config->autoboot_opts[i].uuid = str;
1160 if (read_u32(&pos, &len, &config->ipmi_bootdev))
1162 if (read_u32(&pos, &len, &tmp))
1164 config->ipmi_bootdev_persistent = !!tmp;
1166 if (read_u32(&pos, &len, &tmp))
1168 config->allow_writes = !!tmp;
1170 if (read_u32(&pos, &len, &config->n_consoles))
1173 config->consoles = talloc_array(config, char *, config->n_consoles);
1174 for (i = 0; i < config->n_consoles; i++) {
1175 if (read_string(config->consoles, &pos, &len, &str))
1177 config->consoles[i] = str;
1180 if (read_string(config, &pos, &len, &str))
1183 config->boot_console = str;
1185 if (read_u32(&pos, &len, &tmp))
1187 config->manual_console = !!tmp;
1189 if (read_string(config, &pos, &len, &str))
1200 int pb_protocol_deserialise_plugin_option(struct plugin_option *opt,
1201 const struct pb_protocol_message *message)
1203 unsigned int len, i, tmp;
1208 len = message->payload_len;
1209 pos = message->payload;
1211 if (read_string(opt, &pos, &len, &str))
1215 if (read_string(opt, &pos, &len, &str))
1219 if (read_string(opt, &pos, &len, &str))
1223 if (read_string(opt, &pos, &len, &str))
1225 opt->vendor_id = str;
1227 if (read_string(opt, &pos, &len, &str))
1231 if (read_string(opt, &pos, &len, &str))
1235 if (read_string(opt, &pos, &len, &str))
1237 opt->plugin_file = str;
1239 if (read_u32(&pos, &len, &tmp))
1241 opt->n_executables = tmp;
1243 opt->executables = talloc_zero_array(opt, char *, opt->n_executables);
1244 if (!opt->executables)
1247 for (i = 0; i < opt->n_executables; i++) {
1248 if (read_string(opt, &pos, &len, &str))
1250 opt->executables[i] = talloc_strdup(opt, str);