discover/sysinfo: Add network availability helper
[petitboot] / discover / sysinfo.c
index 0ac29c1ead35adddd7f9a52acbe6c8fbd8f811c5..74d1eae573f230a53ea018aab36a713d34686d84 100644 (file)
@@ -17,6 +17,15 @@ 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)
@@ -139,3 +148,21 @@ void system_info_init(struct discover_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;
+}