1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
#include <string.h>
#include <talloc/talloc.h>
#include <process/process.h>
#include <log/log.h>
#include "discover-server.h"
#include "platform.h"
#include "sysinfo.h"
static struct system_info *sysinfo;
static struct discover_server *server;
const struct system_info *system_info_get(void)
{
return sysinfo;
}
bool system_info_network_available(void)
{
unsigned int i;
for (i = 0; i < sysinfo->n_interfaces; i++)
if (sysinfo->interfaces[i]->address)
return true;
return false;
}
void system_info_set_interface_address(unsigned int hwaddr_size,
uint8_t *hwaddr, const char *address)
{
struct interface_info *if_info;
unsigned int i;
char mac[20];
for (i = 0; i < sysinfo->n_interfaces; i++) {
if_info = sysinfo->interfaces[i];
if (if_info->hwaddr_size != hwaddr_size)
continue;
if (memcmp(if_info->hwaddr, hwaddr, hwaddr_size))
continue;
/* Found an existing interface. Notify clients if a new address
* is set */
if (!if_info->address || strcmp(if_info->address, address)) {
talloc_free(if_info->address);
if_info->address = talloc_strdup(if_info, address);
discover_server_notify_system_info(server, sysinfo);
return;
}
}
mac_str(hwaddr, hwaddr_size, mac, sizeof(mac));
pb_log("Couldn't find interface matching %s\n", mac);
}
void system_info_register_interface(unsigned int hwaddr_size, uint8_t *hwaddr,
const char *name, bool link)
{
struct interface_info *if_info;
unsigned int i;
for (i = 0; i < sysinfo->n_interfaces; i++) {
bool changed = false;
if_info = sysinfo->interfaces[i];
if (if_info->hwaddr_size != hwaddr_size)
continue;
if (memcmp(if_info->hwaddr, hwaddr, hwaddr_size))
continue;
/* Found an existing interface. Notify clients on any name or
* link changes */
if (strcmp(if_info->name, name)) {
talloc_free(if_info->name);
if_info->name = talloc_strdup(if_info, name);
changed = true;
}
if (if_info->link != link) {
if_info->link = link;
changed = true;
}
if (changed)
discover_server_notify_system_info(server, sysinfo);
return;
}
if_info = talloc_zero(sysinfo, struct interface_info);
if_info->hwaddr_size = hwaddr_size;
if_info->hwaddr = talloc_memdup(if_info, hwaddr, hwaddr_size);
if_info->name = talloc_strdup(if_info, name);
if_info->link = link;
sysinfo->n_interfaces++;
sysinfo->interfaces = talloc_realloc(sysinfo, sysinfo->interfaces,
struct interface_info *,
sysinfo->n_interfaces);
sysinfo->interfaces[sysinfo->n_interfaces - 1] = if_info;
discover_server_notify_system_info(server, sysinfo);
}
void system_info_register_blockdev(const char *name, const char *uuid,
const char *mountpoint)
{
struct blockdev_info *bd_info;
unsigned int i;
for (i = 0; i < sysinfo->n_blockdevs; i++) {
bd_info = sysinfo->blockdevs[i];
if (strcmp(bd_info->name, name))
continue;
/* update the mountpoint and UUID, and we're done */
talloc_free(bd_info->mountpoint);
bd_info->uuid = talloc_strdup(bd_info, uuid);
bd_info->mountpoint = talloc_strdup(bd_info, mountpoint);
discover_server_notify_system_info(server, sysinfo);
return;
}
bd_info = talloc_zero(sysinfo, struct blockdev_info);
bd_info->name = talloc_strdup(bd_info, name);
bd_info->uuid = talloc_strdup(bd_info, uuid);
bd_info->mountpoint = talloc_strdup(bd_info, mountpoint);
sysinfo->n_blockdevs++;
sysinfo->blockdevs = talloc_realloc(sysinfo, sysinfo->blockdevs,
struct blockdev_info *,
sysinfo->n_blockdevs);
sysinfo->blockdevs[sysinfo->n_blockdevs - 1] = bd_info;
discover_server_notify_system_info(server, sysinfo);
}
void system_info_init(struct discover_server *s)
{
server = s;
sysinfo = talloc_zero(server, struct system_info);
platform_get_sysinfo(sysinfo);
}
/* Only reset device information. Platform information is static */
void system_info_reinit(void)
{
unsigned int i;
for (i = 0; i < sysinfo->n_blockdevs; i++)
talloc_free(sysinfo->blockdevs[i]);
talloc_free(sysinfo->blockdevs);
sysinfo->blockdevs = NULL;
sysinfo->n_blockdevs = 0;
for (i = 0; i < sysinfo->n_interfaces; i++)
talloc_free(sysinfo->interfaces[i]);
talloc_free(sysinfo->interfaces);
sysinfo->interfaces = NULL;
sysinfo->n_interfaces = 0;
}
|