From bdd4ddd8fae7ba14548e1b6f01f7b9d143261db2 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 2 Dec 2015 11:08:56 -0800 Subject: QNetworkInterface: fix support for address labels on Linux interfaces Commit 64a1448d87727878d9789906b2f4f5b9e3d74e38 (Qt 5.2) caused QNetworkInterface to report address labels (a.k.a. interface aliases) as separate interfaces. This is caused by the fact that glibc, uClibc and MUSL copy the address label (netlink address attribute IFA_LABEL) to the ifa_name field, which made QNetworkInterfaceManager think that it was an interface it hadn't yet seen. Address labels are the old way to add more than one IP address to an interface on Linux, for example: ifconfig eth0:1 192.0.2.2 Those do not create a new interface, so the "eth0:1" label maps to the same interface index as the parent interface. This has been deprecated for 10 years, but there are still tools out there that add addresses in this manner. This commit restores behavior compatibility with Qt 4.2-5.1. The Qt 5.2-5.5 behavior is incorrect because it reports more than one interface with the same index. On systems configured like the above, the tst_QNetworkInterface::interfaceFromXXX test was failing. Change-Id: I8de47ed6c7be4847b99bffff141c2d9de8cf7329 Reviewed-by: Richard J. Moore --- .../qnetworkinterface/tst_qnetworkinterface.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'tests') diff --git a/tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp b/tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp index f7798bbb70..519ee0dc84 100644 --- a/tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp +++ b/tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp @@ -55,6 +55,7 @@ private slots: void initTestCase(); void cleanupTestCase(); void dump(); + void consistencyCheck(); void loopbackIPv4(); void loopbackIPv6(); void localAddress(); @@ -148,6 +149,24 @@ void tst_QNetworkInterface::dump() } } +void tst_QNetworkInterface::consistencyCheck() +{ + QList ifaces = QNetworkInterface::allInterfaces(); + QSet interfaceNames; + QVector interfaceIndexes; + + foreach (const QNetworkInterface &iface, ifaces) { + QVERIFY2(!interfaceNames.contains(iface.name()), + "duplicate name = " + iface.name().toLocal8Bit()); + interfaceNames << iface.name(); + + QVERIFY2(!interfaceIndexes.contains(iface.index()), + "duplicate index = " + QByteArray::number(iface.index())); + if (iface.index()) + interfaceIndexes << iface.index(); + } +} + void tst_QNetworkInterface::loopbackIPv4() { QList all = QNetworkInterface::allAddresses(); -- cgit v1.2.3