5 #include <types/types.h>
6 #include <talloc/talloc.h>
10 static struct interface_config *config_copy_interface(struct config *ctx,
11 struct interface_config *src)
13 struct interface_config *dest = talloc_zero(ctx,
14 struct interface_config);
16 memcpy(dest->hwaddr, src->hwaddr, sizeof(src->hwaddr));
17 dest->ignore = src->ignore;
22 dest->method = src->method;
24 switch (src->method) {
25 case CONFIG_METHOD_DHCP:
27 case CONFIG_METHOD_STATIC:
28 dest->static_config.address =
29 talloc_strdup(dest, src->static_config.address);
30 dest->static_config.gateway =
31 talloc_strdup(dest, src->static_config.gateway);
32 dest->static_config.url =
33 talloc_strdup(dest, src->static_config.url);
40 struct config *config_copy(void *ctx, const struct config *src)
45 dest = talloc_zero(ctx, struct config);
46 dest->autoboot_enabled = src->autoboot_enabled;
47 dest->autoboot_timeout_sec = src->autoboot_timeout_sec;
48 dest->safe_mode = src->safe_mode;
50 dest->network.n_interfaces = src->network.n_interfaces;
51 dest->network.interfaces = talloc_array(dest, struct interface_config *,
52 dest->network.n_interfaces);
53 dest->network.n_dns_servers = src->network.n_dns_servers;
54 dest->network.dns_servers = talloc_array(dest, const char *,
55 dest->network.n_dns_servers);
57 for (i = 0; i < src->network.n_interfaces; i++)
58 dest->network.interfaces[i] = config_copy_interface(dest,
59 src->network.interfaces[i]);
61 for (i = 0; i < src->network.n_dns_servers; i++)
62 dest->network.dns_servers[i] = talloc_strdup(dest,
63 src->network.dns_servers[i]);
65 dest->n_autoboot_opts = src->n_autoboot_opts;
66 dest->autoboot_opts = talloc_array(dest, struct autoboot_option,
67 dest->n_autoboot_opts);
69 for (i = 0; i < src->n_autoboot_opts; i++) {
70 dest->autoboot_opts[i].boot_type =
71 src->autoboot_opts[i].boot_type;
72 if (src->autoboot_opts[i].boot_type == BOOT_DEVICE_TYPE)
73 dest->autoboot_opts[i].type =
74 src->autoboot_opts[i].type;
76 dest->autoboot_opts[i].uuid =
77 talloc_strdup(dest, src->autoboot_opts[i].uuid);
80 dest->ipmi_bootdev = src->ipmi_bootdev;
81 dest->ipmi_bootdev_persistent = src->ipmi_bootdev_persistent;
83 dest->allow_writes = src->allow_writes;
85 dest->n_tty = src->n_tty;
87 dest->tty_list = talloc_array(dest, char *, src->n_tty);
88 for (i = 0; i < src->n_tty && src->n_tty; i++)
89 dest->tty_list[i] = talloc_strdup(dest->tty_list,
93 dest->boot_tty = talloc_strdup(dest, src->boot_tty);
95 if (src->lang && strlen(src->lang))
96 dest->lang = talloc_strdup(dest, src->lang);