chiark / gitweb /
machined: make sure GetMachineAddresses() is available for unprivileged processes
[elogind.git] / src / libsystemd-network / network-internal.c
index e7ba628fc71e8ef2030d0986c9f5d71a4b0cb5f1..f3dc42f6dd94660645c44a9ce2be84ae59a232cc 100644 (file)
@@ -327,16 +327,37 @@ int net_parse_inaddr(const char *address, unsigned char *family, void *dst) {
         return 0;
 }
 
-bool link_has_carrier(unsigned flags, uint8_t operstate) {
-        /* see Documentation/networking/operstates.txt in the kernel sources */
+int load_module(struct kmod_ctx *ctx, const char *mod_name) {
+        struct kmod_list *modlist = NULL, *l;
+        int r;
+
+        assert(ctx);
+        assert(mod_name);
+
+        r = kmod_module_new_from_lookup(ctx, mod_name, &modlist);
+        if (r < 0)
+                return r;
+
+        if (!modlist) {
+                log_error("Failed to find module '%s'", mod_name);
+                return -ENOENT;
+        }
+
+        kmod_list_foreach(l, modlist) {
+                struct kmod_module *mod = kmod_module_get_module(l);
 
-        if (operstate == IF_OPER_UP)
-                return true;
+                r = kmod_module_probe_insert_module(mod, 0, NULL, NULL, NULL, NULL);
+                if (r == 0)
+                        log_info("Inserted module '%s'", kmod_module_get_name(mod));
+                else {
+                        log_error("Failed to insert '%s': %s", kmod_module_get_name(mod),
+                                  strerror(-r));
+                }
+
+                kmod_module_unref(mod);
+        }
 
-        if (operstate == IF_OPER_UNKNOWN)
-                /* operstate may not be implemented, so fall back to flags */
-                if ((flags & IFF_LOWER_UP) && !(flags & IFF_DORMANT))
-                        return true;
+        kmod_module_unref_list(modlist);
 
-        return false;
+        return r;
 }