mirror of
https://github.com/systemd/systemd.git
synced 2025-09-01 13:59:26 +03:00
nspawn: check with udev before we take possession of an interface
This commit is contained in:
@ -1849,6 +1849,7 @@ systemd_nspawn_LDADD = \
|
|||||||
libsystemd-capability.la \
|
libsystemd-capability.la \
|
||||||
libsystemd-internal.la \
|
libsystemd-internal.la \
|
||||||
libsystemd-daemon-internal.la \
|
libsystemd-daemon-internal.la \
|
||||||
|
libudev-internal.la \
|
||||||
libsystemd-shared.la
|
libsystemd-shared.la
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
@ -73,6 +73,7 @@
|
|||||||
#include "env-util.h"
|
#include "env-util.h"
|
||||||
#include "def.h"
|
#include "def.h"
|
||||||
#include "rtnl-util.h"
|
#include "rtnl-util.h"
|
||||||
|
#include "udev-util.h"
|
||||||
|
|
||||||
typedef enum LinkJournal {
|
typedef enum LinkJournal {
|
||||||
LINK_NO,
|
LINK_NO,
|
||||||
@ -1256,6 +1257,7 @@ static int reset_audit_loginuid(void) {
|
|||||||
|
|
||||||
static int move_network_interfaces(pid_t pid) {
|
static int move_network_interfaces(pid_t pid) {
|
||||||
_cleanup_rtnl_unref_ sd_rtnl *rtnl = NULL;
|
_cleanup_rtnl_unref_ sd_rtnl *rtnl = NULL;
|
||||||
|
_cleanup_udev_unref_ struct udev *udev = NULL;
|
||||||
char **i;
|
char **i;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
@ -1271,8 +1273,16 @@ static int move_network_interfaces(pid_t pid) {
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
udev = udev_new();
|
||||||
|
if (!udev) {
|
||||||
|
log_error("Failed to connect to udev.");
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
STRV_FOREACH(i, arg_network_interfaces) {
|
STRV_FOREACH(i, arg_network_interfaces) {
|
||||||
_cleanup_rtnl_message_unref_ sd_rtnl_message *m = NULL;
|
_cleanup_rtnl_message_unref_ sd_rtnl_message *m = NULL;
|
||||||
|
_cleanup_udev_device_unref_ struct udev_device *d = NULL;
|
||||||
|
char ifi_str[2 + DECIMAL_STR_MAX(int)];
|
||||||
int ifi;
|
int ifi;
|
||||||
|
|
||||||
ifi = (int) if_nametoindex(*i);
|
ifi = (int) if_nametoindex(*i);
|
||||||
@ -1281,6 +1291,18 @@ static int move_network_interfaces(pid_t pid) {
|
|||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sprintf(ifi_str, "n%i", ifi);
|
||||||
|
d = udev_device_new_from_device_id(udev, ifi_str);
|
||||||
|
if (!d) {
|
||||||
|
log_error("Failed to get udev device for interface %s: %m", *i);
|
||||||
|
return -errno;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (udev_device_get_is_initialized(d) <= 0) {
|
||||||
|
log_error("Network interface %s is not initialized yet.", *i);
|
||||||
|
return -EBUSY;
|
||||||
|
}
|
||||||
|
|
||||||
r = sd_rtnl_message_new_link(RTM_NEWLINK, ifi, &m);
|
r = sd_rtnl_message_new_link(RTM_NEWLINK, ifi, &m);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
log_error("Failed to allocate netlink message: %s", strerror(-r));
|
log_error("Failed to allocate netlink message: %s", strerror(-r));
|
||||||
|
Reference in New Issue
Block a user