]> git.ozlabs.org Git - petitboot/blob - lib/pb-config/pb-config.c
pb-config: Move config storage modules to "platform" modules in discover code
[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
46         dest->network.n_interfaces = src->network.n_interfaces;
47         dest->network.interfaces = talloc_array(dest, struct interface_config *,
48                                         dest->network.n_interfaces);
49         dest->network.n_dns_servers = src->network.n_dns_servers;
50         dest->network.dns_servers = talloc_array(dest, const char *,
51                                         dest->network.n_dns_servers);
52
53         for (i = 0; i < src->network.n_interfaces; i++)
54                 dest->network.interfaces[i] = config_copy_interface(dest,
55                                 src->network.interfaces[i]);
56
57         for (i = 0; i < src->network.n_dns_servers; i++)
58                 dest->network.dns_servers[i] = talloc_strdup(dest,
59                                 src->network.dns_servers[i]);
60
61         dest->n_boot_priorities = src->n_boot_priorities;
62         dest->boot_priorities = talloc_array(dest, struct boot_priority,
63                         src->n_boot_priorities);
64
65         for (i = 0; i < src->n_boot_priorities; i++)
66                 dest->boot_priorities[i].type = src->boot_priorities[i].type;
67
68         return dest;
69 }