platform: don't wait for udev device initializaton if there's no udev
There's no udev running in containers, it only starts if /sys is writable. If a hardware device is added to the container's namespace NM would not announce it. This also removes the software link special case -- the software links will now wait for udev initialization (in case udev is there) as well. There's no reason to treat them differently anymore. This makes it possible to use udev properties of the software links. https://bugzilla.gnome.org/show_bug.cgi?id=740526
This commit is contained in:
@@ -49,6 +49,11 @@ typedef struct {
|
||||
int vlan_id;
|
||||
} NMFakePlatformLink;
|
||||
|
||||
typedef struct {
|
||||
int ifindex;
|
||||
NMPlatform *platform;
|
||||
} NMFakePlatformLinkData;
|
||||
|
||||
#define NM_FAKE_PLATFORM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_FAKE_PLATFORM, NMFakePlatformPrivate))
|
||||
|
||||
G_DEFINE_TYPE (NMFakePlatform, nm_fake_platform, NM_TYPE_PLATFORM)
|
||||
@@ -174,6 +179,23 @@ _nm_platform_link_get (NMPlatform *platform, int ifindex, NMPlatformLink *l)
|
||||
return !!device;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_link_announce (NMFakePlatformLinkData *data)
|
||||
{
|
||||
NMFakePlatformLink *device = link_get (data->platform, data->ifindex);
|
||||
|
||||
if (device)
|
||||
g_signal_emit_by_name (data->platform,
|
||||
NM_PLATFORM_SIGNAL_LINK_CHANGED,
|
||||
device->link.ifindex,
|
||||
device,
|
||||
NM_PLATFORM_SIGNAL_ADDED,
|
||||
NM_PLATFORM_REASON_INTERNAL);
|
||||
g_free (data);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
link_add (NMPlatform *platform, const char *name, NMLinkType type, const void *address, size_t address_len)
|
||||
{
|
||||
@@ -184,8 +206,12 @@ link_add (NMPlatform *platform, const char *name, NMLinkType type, const void *a
|
||||
|
||||
g_array_append_val (priv->links, device);
|
||||
|
||||
if (device.link.ifindex)
|
||||
g_signal_emit_by_name (platform, NM_PLATFORM_SIGNAL_LINK_CHANGED, device.link.ifindex, &device, NM_PLATFORM_SIGNAL_ADDED, NM_PLATFORM_REASON_INTERNAL);
|
||||
if (device.link.ifindex) {
|
||||
NMFakePlatformLinkData *data = g_new (NMFakePlatformLinkData, 1);
|
||||
data->ifindex = device.link.ifindex;
|
||||
data->platform = platform;
|
||||
g_idle_add ((GSourceFunc) _link_announce, data);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@@ -780,41 +780,6 @@ link_type_from_udev (NMPlatform *platform, int ifindex, const char *ifname, int
|
||||
return_type (NM_LINK_TYPE_UNKNOWN, "unknown");
|
||||
}
|
||||
|
||||
static gboolean
|
||||
link_is_software (struct rtnl_link *rtnllink)
|
||||
{
|
||||
const char *type;
|
||||
|
||||
/* FIXME: replace somehow with NMLinkType or nm_platform_is_software(), but
|
||||
* solve the infinite callstack problems that getting the type of a TUN/TAP
|
||||
* device causes.
|
||||
*/
|
||||
|
||||
if ( rtnl_link_get_arptype (rtnllink) == ARPHRD_INFINIBAND
|
||||
&& strchr (rtnl_link_get_name (rtnllink), '.'))
|
||||
return TRUE;
|
||||
|
||||
type = rtnl_link_get_type (rtnllink);
|
||||
if (type == NULL)
|
||||
return FALSE;
|
||||
|
||||
if (!strcmp (type, "dummy") ||
|
||||
!strcmp (type, "gre") ||
|
||||
!strcmp (type, "gretap") ||
|
||||
!strcmp (type, "macvlan") ||
|
||||
!strcmp (type, "macvtap") ||
|
||||
!strcmp (type, "tun") ||
|
||||
!strcmp (type, "veth") ||
|
||||
!strcmp (type, "vlan") ||
|
||||
!strcmp (type, "vxlan") ||
|
||||
!strcmp (type, "bridge") ||
|
||||
!strcmp (type, "bond") ||
|
||||
!strcmp (type, "team"))
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static const char *
|
||||
ethtool_get_driver (const char *ifname)
|
||||
{
|
||||
@@ -837,10 +802,6 @@ link_is_announceable (NMPlatform *platform, struct rtnl_link *rtnllink)
|
||||
{
|
||||
NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform);
|
||||
|
||||
/* Software devices are always visible outside the platform */
|
||||
if (link_is_software (rtnllink))
|
||||
return TRUE;
|
||||
|
||||
/* Hardware devices must be found by udev so rules get run and tags set */
|
||||
if (g_hash_table_lookup (priv->udev_devices,
|
||||
GINT_TO_POINTER (rtnl_link_get_ifindex (rtnllink))))
|
||||
@@ -1587,7 +1548,7 @@ announce_object (NMPlatform *platform, const struct nl_object *object, NMPlatfor
|
||||
if (!init_link (platform, &device, rtnl_link))
|
||||
return;
|
||||
|
||||
/* Skip hardware devices not yet discovered by udev. They will be
|
||||
/* Skip devices not yet discovered by udev. They will be
|
||||
* announced by udev_device_added(). This doesn't apply to removed
|
||||
* devices, as those come either from udev_device_removed(),
|
||||
* event_notification() or link_delete() which block the announcment
|
||||
@@ -1596,7 +1557,7 @@ announce_object (NMPlatform *platform, const struct nl_object *object, NMPlatfor
|
||||
switch (change_type) {
|
||||
case NM_PLATFORM_SIGNAL_ADDED:
|
||||
case NM_PLATFORM_SIGNAL_CHANGED:
|
||||
if (!link_is_software (rtnl_link) && !device.driver)
|
||||
if (!device.driver)
|
||||
return;
|
||||
break;
|
||||
default:
|
||||
@@ -4537,7 +4498,12 @@ setup (NMPlatform *platform)
|
||||
/* And read initial device list */
|
||||
enumerator = g_udev_enumerator_new (priv->udev_client);
|
||||
g_udev_enumerator_add_match_subsystem (enumerator, "net");
|
||||
g_udev_enumerator_add_match_is_initialized (enumerator);
|
||||
|
||||
/* Demand that the device is initialized (udev rules ran,
|
||||
* device has a stable name now) in case udev is running
|
||||
* (not in a container). */
|
||||
if (access ("/sys", W_OK) == 0)
|
||||
g_udev_enumerator_add_match_is_initialized (enumerator);
|
||||
|
||||
devices = g_udev_enumerator_execute (enumerator);
|
||||
for (iter = devices; iter; iter = g_list_next (iter)) {
|
||||
|
@@ -254,7 +254,7 @@ setup_tests (void)
|
||||
nm_platform_link_delete (nm_platform_link_get_ifindex (DEVICE_NAME));
|
||||
g_assert (!nm_platform_link_exists (DEVICE_NAME));
|
||||
g_assert (nm_platform_dummy_add (DEVICE_NAME));
|
||||
accept_signal (link_added);
|
||||
wait_signal (link_added);
|
||||
free_signal (link_added);
|
||||
|
||||
g_test_add_func ("/address/internal/ip4", test_ip4_address);
|
||||
|
@@ -36,7 +36,7 @@ test_cleanup_internal (void)
|
||||
|
||||
/* Create and set up device */
|
||||
g_assert (nm_platform_dummy_add (DEVICE_NAME));
|
||||
accept_signal (link_added);
|
||||
wait_signal (link_added);
|
||||
free_signal (link_added);
|
||||
g_assert (nm_platform_link_set_up (nm_platform_link_get_ifindex (DEVICE_NAME)));
|
||||
ifindex = nm_platform_link_get_ifindex (DEVICE_NAME);
|
||||
|
@@ -115,7 +115,7 @@ software_add (NMLinkType link_type, const char *name)
|
||||
/* Don't call link_callback for the bridge interface */
|
||||
parent_added = add_signal_ifname (NM_PLATFORM_SIGNAL_LINK_CHANGED, NM_PLATFORM_SIGNAL_ADDED, link_callback, PARENT_NAME);
|
||||
if (nm_platform_bridge_add (PARENT_NAME, NULL, 0))
|
||||
accept_signal (parent_added);
|
||||
wait_signal (parent_added);
|
||||
free_signal (parent_added);
|
||||
|
||||
{
|
||||
@@ -148,7 +148,7 @@ test_slave (int master, int type, SignalData *master_changed)
|
||||
g_assert (ifindex > 0);
|
||||
link_changed = add_signal_ifindex (NM_PLATFORM_SIGNAL_LINK_CHANGED, NM_PLATFORM_SIGNAL_CHANGED, link_callback, ifindex);
|
||||
link_removed = add_signal_ifindex (NM_PLATFORM_SIGNAL_LINK_CHANGED, NM_PLATFORM_SIGNAL_REMOVED, link_callback, ifindex);
|
||||
accept_signal (link_added);
|
||||
wait_signal (link_added);
|
||||
|
||||
/* Set the slave up to see whether master's IFF_LOWER_UP is set correctly.
|
||||
*
|
||||
@@ -263,7 +263,7 @@ test_software (NMLinkType link_type, const char *link_typename)
|
||||
link_added = add_signal_ifname (NM_PLATFORM_SIGNAL_LINK_CHANGED, NM_PLATFORM_SIGNAL_ADDED, link_callback, DEVICE_NAME);
|
||||
g_assert (software_add (link_type, DEVICE_NAME));
|
||||
no_error ();
|
||||
accept_signal (link_added);
|
||||
wait_signal (link_added);
|
||||
g_assert (nm_platform_link_exists (DEVICE_NAME));
|
||||
ifindex = nm_platform_link_get_ifindex (DEVICE_NAME);
|
||||
g_assert (ifindex >= 0);
|
||||
@@ -407,7 +407,7 @@ test_internal (void)
|
||||
/* Add device */
|
||||
g_assert (nm_platform_dummy_add (DEVICE_NAME));
|
||||
no_error ();
|
||||
accept_signal (link_added);
|
||||
wait_signal (link_added);
|
||||
|
||||
/* Try to add again */
|
||||
g_assert (!nm_platform_dummy_add (DEVICE_NAME));
|
||||
|
@@ -319,7 +319,7 @@ setup_tests (void)
|
||||
nm_platform_link_delete (nm_platform_link_get_ifindex (DEVICE_NAME));
|
||||
g_assert (!nm_platform_link_exists (DEVICE_NAME));
|
||||
g_assert (nm_platform_dummy_add (DEVICE_NAME));
|
||||
accept_signal (link_added);
|
||||
wait_signal (link_added);
|
||||
free_signal (link_added);
|
||||
|
||||
g_assert (nm_platform_link_set_up (nm_platform_link_get_ifindex (DEVICE_NAME)));
|
||||
|
@@ -648,7 +648,7 @@ fixture_setup (test_fixture *fixture, gconstpointer user_data)
|
||||
nm_platform_link_delete (nm_platform_link_get_ifindex ("nm-test-device0"));
|
||||
g_assert (!nm_platform_link_exists ("nm-test-device0"));
|
||||
g_assert (nm_platform_dummy_add ("nm-test-device0"));
|
||||
accept_signal (link_added);
|
||||
wait_signal (link_added);
|
||||
free_signal (link_added);
|
||||
fixture->ifindex0 = nm_platform_link_get_ifindex ("nm-test-device0");
|
||||
g_assert (nm_platform_link_set_up (fixture->ifindex0));
|
||||
@@ -660,7 +660,7 @@ fixture_setup (test_fixture *fixture, gconstpointer user_data)
|
||||
nm_platform_link_delete (nm_platform_link_get_ifindex ("nm-test-device1"));
|
||||
g_assert (!nm_platform_link_exists ("nm-test-device1"));
|
||||
g_assert (nm_platform_dummy_add ("nm-test-device1"));
|
||||
accept_signal (link_added);
|
||||
wait_signal (link_added);
|
||||
free_signal (link_added);
|
||||
fixture->ifindex1 = nm_platform_link_get_ifindex ("nm-test-device1");
|
||||
g_assert (nm_platform_link_set_up (fixture->ifindex1));
|
||||
|
Reference in New Issue
Block a user