]> git.ozlabs.org Git - petitboot/blob - lib/pb-config/pb-config.c
discover: Integrate ipmi bootdev settings into the priority system
[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(ctx, struct interface_config);
14
15         memcpy(dest->hwaddr, src->hwaddr, sizeof(src->hwaddr));
16         dest->ignore = src->ignore;
17
18         if (dest->ignore)
19                 return dest;
20
21         dest->method = src->method;
22
23         switch (src->method) {
24         case CONFIG_METHOD_DHCP:
25                 break;
26         case CONFIG_METHOD_STATIC:
27                 dest->static_config.address =
28                         talloc_strdup(dest, src->static_config.address);
29                 dest->static_config.gateway =
30                         talloc_strdup(dest, src->static_config.gateway);
31                 break;
32         }
33
34         return dest;
35 }
36
37 struct config *config_copy(void *ctx, const struct config *src)
38 {
39         struct config *dest;
40         unsigned int i;
41
42         dest = talloc(ctx, struct config);
43         dest->autoboot_enabled = src->autoboot_enabled;
44         dest->autoboot_timeout_sec = src->autoboot_timeout_sec;
45         dest->safe_mode = src->safe_mode;
46
47         dest->network.n_interfaces = src->network.n_interfaces;
48         dest->network.interfaces = talloc_array(dest, struct interface_config *,
49                                         dest->network.n_interfaces);
50         dest->network.n_dns_servers = src->network.n_dns_servers;
51         dest->network.dns_servers = talloc_array(dest, const char *,
52                                         dest->network.n_dns_servers);
53
54         for (i = 0; i < src->network.n_interfaces; i++)
55                 dest->network.interfaces[i] = config_copy_interface(dest,
56                                 src->network.interfaces[i]);
57
58         for (i = 0; i < src->network.n_dns_servers; i++)
59                 dest->network.dns_servers[i] = talloc_strdup(dest,
60                                 src->network.dns_servers[i]);
61
62         dest->n_boot_priorities = src->n_boot_priorities;
63         dest->boot_priorities = talloc_array(dest, struct boot_priority,
64                         src->n_boot_priorities);
65
66         for (i = 0; i < src->n_boot_priorities; i++) {
67                 dest->boot_priorities[i].priority =
68                                         src->boot_priorities[i].priority;
69                 dest->boot_priorities[i].type = src->boot_priorities[i].type;
70         }
71
72         if (src->boot_device && strlen(src->boot_device))
73                 dest->boot_device = talloc_strdup(dest, src->boot_device);
74         else
75                 dest->boot_device = NULL;
76
77         dest->ipmi_bootdev = src->ipmi_bootdev;
78         dest->ipmi_bootdev_persistent = src->ipmi_bootdev_persistent;
79
80         if (src->lang && strlen(src->lang))
81                 dest->lang = talloc_strdup(dest, src->lang);
82         else
83                 dest->lang = NULL;
84
85         return dest;
86 }