diff options
Diffstat (limited to 'src/nspawn/nspawn-network.c')
-rw-r--r-- | src/nspawn/nspawn-network.c | 49 |
1 files changed, 16 insertions, 33 deletions
diff --git a/src/nspawn/nspawn-network.c b/src/nspawn/nspawn-network.c index 01c57bef56..997609bb8e 100644 --- a/src/nspawn/nspawn-network.c +++ b/src/nspawn/nspawn-network.c @@ -4,7 +4,7 @@ #include <net/if.h> #include <sys/file.h> -#include "libudev.h" +#include "sd-device.h" #include "sd-id128.h" #include "sd-netlink.h" @@ -17,7 +17,7 @@ #include "socket-util.h" #include "stat-util.h" #include "string-util.h" -#include "udev-util.h" +#include "strv.h" #include "util.h" #define HOST_HASH_KEY SD_ID128_MAKE(1a,37,6f,c7,46,ec,45,0b,ad,a3,d5,31,06,60,5d,b1) @@ -392,21 +392,25 @@ int remove_bridge(const char *bridge_name) { return remove_one_link(rtnl, bridge_name); } -static int parse_interface(struct udev *udev, const char *name) { - _cleanup_(udev_device_unrefp) struct udev_device *d = NULL; +static int parse_interface(const char *name) { + _cleanup_(sd_device_unrefp) sd_device *d = NULL; char ifi_str[2 + DECIMAL_STR_MAX(int)]; - int ifi; + int ifi, initialized, r; ifi = (int) if_nametoindex(name); if (ifi <= 0) return log_error_errno(errno, "Failed to resolve interface %s: %m", name); sprintf(ifi_str, "n%i", ifi); - d = udev_device_new_from_device_id(udev, ifi_str); - if (!d) - return log_error_errno(errno, "Failed to get udev device for interface %s: %m", name); + r = sd_device_new_from_device_id(&d, ifi_str); + if (r < 0) + return log_error_errno(r, "Failed to get device for interface %s: %m", name); + + r = sd_device_get_is_initialized(d, &initialized); + if (r < 0) + return log_error_errno(r, "Failed to determine whether interface %s is initialized or not: %m", name); - if (udev_device_get_is_initialized(d) <= 0) { + if (!initialized) { log_error("Network interface %s is not initialized yet.", name); return -EBUSY; } @@ -415,7 +419,6 @@ static int parse_interface(struct udev *udev, const char *name) { } int move_network_interfaces(pid_t pid, char **ifaces) { - _cleanup_(udev_unrefp) struct udev *udev = NULL; _cleanup_(sd_netlink_unrefp) sd_netlink *rtnl = NULL; char **i; int r; @@ -427,17 +430,11 @@ int move_network_interfaces(pid_t pid, char **ifaces) { if (r < 0) return log_error_errno(r, "Failed to connect to netlink: %m"); - udev = udev_new(); - if (!udev) { - log_error("Failed to connect to udev."); - return -ENOMEM; - } - STRV_FOREACH(i, ifaces) { _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m = NULL; int ifi; - ifi = parse_interface(udev, *i); + ifi = parse_interface(*i); if (ifi < 0) return ifi; @@ -458,7 +455,6 @@ int move_network_interfaces(pid_t pid, char **ifaces) { } int setup_macvlan(const char *machine_name, pid_t pid, char **ifaces) { - _cleanup_(udev_unrefp) struct udev *udev = NULL; _cleanup_(sd_netlink_unrefp) sd_netlink *rtnl = NULL; unsigned idx = 0; char **i; @@ -471,19 +467,13 @@ int setup_macvlan(const char *machine_name, pid_t pid, char **ifaces) { if (r < 0) return log_error_errno(r, "Failed to connect to netlink: %m"); - udev = udev_new(); - if (!udev) { - log_error("Failed to connect to udev."); - return -ENOMEM; - } - STRV_FOREACH(i, ifaces) { _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m = NULL; _cleanup_free_ char *n = NULL; struct ether_addr mac; int ifi; - ifi = parse_interface(udev, *i); + ifi = parse_interface(*i); if (ifi < 0) return ifi; @@ -546,7 +536,6 @@ int setup_macvlan(const char *machine_name, pid_t pid, char **ifaces) { } int setup_ipvlan(const char *machine_name, pid_t pid, char **ifaces) { - _cleanup_(udev_unrefp) struct udev *udev = NULL; _cleanup_(sd_netlink_unrefp) sd_netlink *rtnl = NULL; char **i; int r; @@ -558,18 +547,12 @@ int setup_ipvlan(const char *machine_name, pid_t pid, char **ifaces) { if (r < 0) return log_error_errno(r, "Failed to connect to netlink: %m"); - udev = udev_new(); - if (!udev) { - log_error("Failed to connect to udev."); - return -ENOMEM; - } - STRV_FOREACH(i, ifaces) { _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m = NULL; _cleanup_free_ char *n = NULL; int ifi; - ifi = parse_interface(udev, *i); + ifi = parse_interface(*i); if (ifi < 0) return ifi; |