4 #include <talloc/talloc.h>
5 #include <process/process.h>
8 #include "discover-server.h"
12 static struct system_info *sysinfo;
13 static struct discover_server *server;
15 const struct system_info *system_info_get(void)
21 void system_info_set_interface_address(unsigned int hwaddr_size,
22 uint8_t *hwaddr, const char *address)
24 struct interface_info *if_info;
27 for (i = 0; i < sysinfo->n_interfaces; i++) {
28 if_info = sysinfo->interfaces[i];
30 if (if_info->hwaddr_size != hwaddr_size)
33 if (memcmp(if_info->hwaddr, hwaddr, hwaddr_size))
36 /* Found an existing interface. Notify clients if a new address
38 if (!if_info->address || strcmp(if_info->address, address)) {
39 talloc_free(if_info->address);
40 if_info->address = talloc_strdup(if_info, address);
41 discover_server_notify_system_info(server, sysinfo);
46 pb_log("Couldn't find interface matching %s\n", "foo");
49 void system_info_register_interface(unsigned int hwaddr_size, uint8_t *hwaddr,
50 const char *name, bool link)
52 struct interface_info *if_info;
55 for (i = 0; i < sysinfo->n_interfaces; i++) {
58 if_info = sysinfo->interfaces[i];
60 if (if_info->hwaddr_size != hwaddr_size)
63 if (memcmp(if_info->hwaddr, hwaddr, hwaddr_size))
66 /* Found an existing interface. Notify clients on any name or
68 if (strcmp(if_info->name, name)) {
69 talloc_free(if_info->name);
70 if_info->name = talloc_strdup(if_info, name);
74 if (if_info->link != link) {
80 discover_server_notify_system_info(server, sysinfo);
85 if_info = talloc_zero(sysinfo, struct interface_info);
86 if_info->hwaddr_size = hwaddr_size;
87 if_info->hwaddr = talloc_memdup(if_info, hwaddr, hwaddr_size);
88 if_info->name = talloc_strdup(if_info, name);
91 sysinfo->n_interfaces++;
92 sysinfo->interfaces = talloc_realloc(sysinfo, sysinfo->interfaces,
93 struct interface_info *,
94 sysinfo->n_interfaces);
95 sysinfo->interfaces[sysinfo->n_interfaces - 1] = if_info;
97 discover_server_notify_system_info(server, sysinfo);
100 void system_info_register_blockdev(const char *name, const char *uuid,
101 const char *mountpoint)
103 struct blockdev_info *bd_info;
106 for (i = 0; i < sysinfo->n_blockdevs; i++) {
107 bd_info = sysinfo->blockdevs[i];
109 if (strcmp(bd_info->name, name))
112 /* update the mountpoint and UUID, and we're done */
113 talloc_free(bd_info->mountpoint);
114 bd_info->uuid = talloc_strdup(bd_info, uuid);
115 bd_info->mountpoint = talloc_strdup(bd_info, mountpoint);
116 discover_server_notify_system_info(server, sysinfo);
120 bd_info = talloc_zero(sysinfo, struct blockdev_info);
121 bd_info->name = talloc_strdup(bd_info, name);
122 bd_info->uuid = talloc_strdup(bd_info, uuid);
123 bd_info->mountpoint = talloc_strdup(bd_info, mountpoint);
125 sysinfo->n_blockdevs++;
126 sysinfo->blockdevs = talloc_realloc(sysinfo, sysinfo->blockdevs,
127 struct blockdev_info *,
128 sysinfo->n_blockdevs);
129 sysinfo->blockdevs[sysinfo->n_blockdevs - 1] = bd_info;
131 discover_server_notify_system_info(server, sysinfo);
134 void system_info_init(struct discover_server *s)
137 sysinfo = talloc_zero(server, struct system_info);
138 platform_get_sysinfo(sysinfo);