diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2016-06-06 22:43:27 +0200 |
---|---|---|
committer | Beniamino Galvani <bgalvani@redhat.com> | 2016-06-07 14:44:30 +0200 |
commit | 21bdb8255596ef9184300604e0e28aeb92792adc (patch) | |
tree | cbe8a4b779f75d78717cc22bcd529c95519d9840 | |
parent | ff3cd5aaf573324c7ff573cbd2a9c58d8a5d4f8c (diff) | |
download | NetworkManager-21bdb8255596ef9184300604e0e28aeb92792adc.tar.gz |
platform: tests: skip already used macvtap ifindexes
In old kernel versions the creation of a macvtap can fail if its
ifindex is already used by a macvtap in another namespace, because of
a conflict in sysfs entries generation [1].
Try to detect this situation in platform tests and skip an ifindex if
already in use.
[1] http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=17af2bce88d31e65ed73d638bb752d2e13c66ced
-rw-r--r-- | src/platform/tests/test-link.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/platform/tests/test-link.c b/src/platform/tests/test-link.c index bb09111eac..6eec946143 100644 --- a/src/platform/tests/test-link.c +++ b/src/platform/tests/test-link.c @@ -778,11 +778,32 @@ test_software_detect (gconstpointer user_data) } case NM_LINK_TYPE_MACVLAN: { NMPlatformLnkMacvlan lnk_macvlan = { }; + const NMPlatformLink *dummy; + char buf[256]; + int i; lnk_macvlan.mode = MACVLAN_MODE_BRIDGE; lnk_macvlan.no_promisc = FALSE; lnk_macvlan.tap = FALSE; + /* Since in old kernel versions sysfs files for macvtaps are not + * namespaced, the creation can fail if a macvtap in another namespace + * has the same index. Try to detect this situation and skip already + * used indexes. + * http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=17af2bce88d31e65ed73d638bb752d2e13c66ced + */ + for (i = ifindex_parent + 1; i < ifindex_parent + 100; i++) { + snprintf (buf, sizeof (buf), "/sys/class/macvtap/tap%d", i); + if (!g_file_test (buf, G_FILE_TEST_IS_SYMLINK)) + break; + + _LOGD ("skipping ifindex %d as already used by a macvtap", i); + + dummy = nmtstp_link_dummy_add (NM_PLATFORM_GET, FALSE, "dummy-tmp"); + g_assert_cmpint (dummy->ifindex, ==, i); + nmtstp_link_del (NM_PLATFORM_GET, FALSE, dummy->ifindex, NULL); + } + if (!nmtstp_link_macvlan_add (NULL, ext, DEVICE_NAME, ifindex_parent, &lnk_macvlan)) g_error ("Failed adding MACVLAN interface"); break; |