summaryrefslogtreecommitdiff
path: root/src/network/networkd-manager.c
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2014-02-12 16:40:24 +0100
committerTom Gundersen <teg@jklm.no>2014-02-12 17:04:35 +0100
commit60ad0c85e58ea8f546677c1d2e425551f7b96179 (patch)
treec2fc8b0739436729b70c8d2f170abfd434b88504 /src/network/networkd-manager.c
parent86d0d519429b85b0cad93c8c9fe8e68c5b9a4fe3 (diff)
networkd: work inside containers
Udev does not run in containers, so instead of relying on it to tell us when a network device is ready to be used by networkd, we simply assume that any device was fully initialized before being added to the container.
Diffstat (limited to 'src/network/networkd-manager.c')
-rw-r--r--src/network/networkd-manager.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c
index fb3360db0a..54e83e3dd5 100644
--- a/src/network/networkd-manager.c
+++ b/src/network/networkd-manager.c
@@ -27,6 +27,7 @@
#include "udev-util.h"
#include "rtnl-util.h"
#include "mkdir.h"
+#include "virt.h"
const char* const network_dirs[] = {
"/etc/systemd/network",
@@ -63,9 +64,18 @@ int manager_new(Manager **ret) {
if (!m->udev)
return -ENOMEM;
- m->udev_monitor = udev_monitor_new_from_netlink(m->udev, "udev");
- if (!m->udev_monitor)
- return -ENOMEM;
+ /* udev does not initialize devices inside containers,
+ * so we rely on them being already initialized before
+ * entering the container */
+ if (detect_container(NULL) > 0) {
+ m->udev_monitor = udev_monitor_new_from_netlink(m->udev, "kernel");
+ if (!m->udev_monitor)
+ return -ENOMEM;
+ } else {
+ m->udev_monitor = udev_monitor_new_from_netlink(m->udev, "udev");
+ if (!m->udev_monitor)
+ return -ENOMEM;
+ }
m->links = hashmap_new(uint64_hash_func, uint64_compare_func);
if (!m->links)
@@ -179,9 +189,14 @@ int manager_udev_enumerate_links(Manager *m) {
if (r < 0)
return r;
- r = udev_enumerate_add_match_is_initialized(e);
- if (r < 0)
- return r;
+ /* udev does not initialize devices inside containers,
+ * so we rely on them being already initialized before
+ * entering the container */
+ if (detect_container(NULL) <= 0) {
+ r = udev_enumerate_add_match_is_initialized(e);
+ if (r < 0)
+ return r;
+ }
r = udev_enumerate_scan_devices(e);
if (r < 0)