]> git.ozlabs.org Git - petitboot/blob - lib/pb-config/pb-config.c
discover/user-event: Use bootfile_url if available
[petitboot] / lib / pb-config / pb-config.c
1
2 #include <string.h>
3
4 #include <log/log.h>
5 #include <types/types.h>
6 #include <talloc/talloc.h>
7
8 #include "pb-config.h"
9
10 static struct interface_config *config_copy_interface(struct config *ctx,
11                 struct interface_config *src)
12 {
13         struct interface_config *dest = talloc_zero(ctx,
14                                                 struct interface_config);
15
16         memcpy(dest->hwaddr, src->hwaddr, sizeof(src->hwaddr));
17         dest->ignore = src->ignore;
18
19         if (dest->ignore)
20                 return dest;
21
22         dest->method = src->method;
23
24         switch (src->method) {
25         case CONFIG_METHOD_DHCP:
26                 break;
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);
34                 break;
35         }
36         dest->override = src->override;
37
38         return dest;
39 }
40
41 struct config *config_copy(void *ctx, const struct config *src)
42 {
43         struct config *dest;
44         unsigned int i;
45
46         dest = talloc_zero(ctx, struct config);
47         dest->autoboot_enabled = src->autoboot_enabled;
48         dest->autoboot_timeout_sec = src->autoboot_timeout_sec;
49         dest->safe_mode = src->safe_mode;
50
51         dest->network.n_interfaces = src->network.n_interfaces;
52         dest->network.interfaces = talloc_array(dest, struct interface_config *,
53                                         dest->network.n_interfaces);
54         dest->network.n_dns_servers = src->network.n_dns_servers;
55         dest->network.dns_servers = talloc_array(dest, const char *,
56                                         dest->network.n_dns_servers);
57
58         for (i = 0; i < src->network.n_interfaces; i++)
59                 dest->network.interfaces[i] = config_copy_interface(dest,
60                                 src->network.interfaces[i]);
61
62         for (i = 0; i < src->network.n_dns_servers; i++)
63                 dest->network.dns_servers[i] = talloc_strdup(dest,
64                                 src->network.dns_servers[i]);
65
66         dest->http_proxy = talloc_strdup(dest, src->http_proxy);
67         dest->https_proxy = talloc_strdup(dest, src->https_proxy);
68
69         dest->n_autoboot_opts = src->n_autoboot_opts;
70         dest->autoboot_opts = talloc_array(dest, struct autoboot_option,
71                                         dest->n_autoboot_opts);
72
73         for (i = 0; i < src->n_autoboot_opts; i++) {
74                 dest->autoboot_opts[i].boot_type =
75                         src->autoboot_opts[i].boot_type;
76                 if (src->autoboot_opts[i].boot_type == BOOT_DEVICE_TYPE)
77                         dest->autoboot_opts[i].type =
78                                 src->autoboot_opts[i].type;
79                 else
80                         dest->autoboot_opts[i].uuid =
81                                 talloc_strdup(dest, src->autoboot_opts[i].uuid);
82         }
83
84         dest->ipmi_bootdev = src->ipmi_bootdev;
85         dest->ipmi_bootdev_persistent = src->ipmi_bootdev_persistent;
86
87         dest->allow_writes = src->allow_writes;
88
89         dest->n_consoles = src->n_consoles;
90         if (src->consoles)
91                 dest->consoles = talloc_array(dest, char *, src->n_consoles);
92         for (i = 0; i < src->n_consoles && src->n_consoles; i++)
93                 dest->consoles[i] = talloc_strdup(dest->consoles,
94                                                 src->consoles[i]);
95
96         if (src->boot_console)
97                 dest->boot_console = talloc_strdup(dest, src->boot_console);
98         dest->manual_console = src->manual_console;
99
100         if (src->lang && strlen(src->lang))
101                 dest->lang = talloc_strdup(dest, src->lang);
102         else
103                 dest->lang = NULL;
104
105         return dest;
106 }