Skip to content

Commit

Permalink
Allow compilation and unit testing with IPv4 turned off (#9989)
Browse files Browse the repository at this point in the history
* Swith enable ipv4 to default to false

* Disable some more IPv4: in linux/darwin/tizen

* Add some ifdefs in linux mdns for IPv4

* Fix ifdef to if in ipv4 conditional

* Make minmdns server compile with IPv4 disabled

* Fix DNSResolver compilation with IPv4 disabled

* More compilation fixes for android arm64 working

* Do not allow platformconfig to control ipv4 - this should be using build flags

* Make TestInetLayerDNS compile with IPv4 off

* Convert and conditional-change several tests for IPv6 compatiblity

* Also update chip_im_initiator to use ipv6

* Move echo apps to ipv6, make minmdns server compile with clang when ipv4 is disabled

* Restyle fixes

* Update darwin mdns to enforce IPv6 only if ipv4 is disabled

* Allow more time for happy tests CI, fix typo in integration test name

* Change happy to only test IPv6

* Update happy comment regarding tests being run

* Restyle fixes

* Undo the "interation" typo fix, since the github required runs seems to be name based

* Undo the disabling ipv4 by default. Also change infineon P6 to inherit ipv4 defaults (i.e. true for now, but potentially false in the future)

* Allow TestDevice.cpp to be compiled with ipv4 turned on

* Update listening for IM/Echo requester/responder to use IPv4 if enabled, to preserve cirque compatibility

* Use input address for deciding IP types for requester/initiator apps

* Fix typo for previous commit: use Type() instead of GetAddressType

* Fix typo

* Change error to detail for logging IPv4 skip

* Change PtrResponse to use IPv6 instead of IPv4

* Do not callback on IPv4 result from avahi when IPv4 not available

* Ensure mdns callback on unexpected ipv4 is reported as an INVALID_ADDRESS error
  • Loading branch information
andy31415 authored and pull[bot] committed Oct 21, 2021
1 parent 6e2a47d commit 1202659
Show file tree
Hide file tree
Showing 30 changed files with 160 additions and 108 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/unit_integration_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ jobs:
unit_tests:
name: Unit / Interation Tests
timeout-minutes: 60

if: github.actor != 'restyled-io[bot]'

strategy:
Expand Down Expand Up @@ -88,7 +87,7 @@ jobs:
timeout-minutes: 5
run: scripts/build/gn_build.sh
- name: Run Tests
timeout-minutes: 5
timeout-minutes: 10
run: RUN_HAPPY_TESTS=1 scripts/tests/gn_tests.sh
- name: Uploading Happy Test Log
uses: actions/upload-artifact@v2
Expand Down
9 changes: 7 additions & 2 deletions examples/minimal-mdns/AllInterfaceListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* limitations under the License.
*/

#include <inet/Inet.h>
#include <lib/mdns/minimal/Server.h>

namespace MdnsExample {
Expand All @@ -37,13 +38,17 @@ class AllInterfaces : public mdns::Minimal::ListenIterator
{
if (mState == State::kIpV4)
{
*id = INET_NULL_INTERFACEID;
*type = chip::Inet::kIPAddressType_IPv4;
#if INET_CONFIG_ENABLE_IPV4
*id = INET_NULL_INTERFACEID;
*type = chip::Inet::kIPAddressType_IPv4;
#endif
mState = State::kIpV6;

SkipToFirstValidInterface();

#if INET_CONFIG_ENABLE_IPV4
return true;
#endif
}

if (!mIterator.HasCurrent())
Expand Down
3 changes: 1 addition & 2 deletions examples/platform/linux/CommissioneeShellCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ static CHIP_ERROR PrintAllCommands()
streamer_t * sout = streamer_get();
streamer_printf(sout, " help Usage: commissionee <subcommand>\r\n");
#if CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY_CLIENT
streamer_printf(sout,
" sendudc <address> <port> Send UDC message to address. Usage: commissionee sendudc 127.0.0.1 5543\r\n");
streamer_printf(sout, " sendudc <address> <port> Send UDC message to address. Usage: commissionee sendudc ::1 5543\r\n");
#endif // CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY_CLIENT
streamer_printf(
sout, " setdiscoverytimeout <timeout> Set discovery timeout in seconds. Usage: commissionee setdiscoverytimeout 30\r\n");
Expand Down
2 changes: 1 addition & 1 deletion src/app/tests/integration/chip_im_initiator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ int main(int argc, char * argv[])
InitializeChip();

err = gTransportManager.Init(chip::Transport::UdpListenParameters(&chip::DeviceLayer::InetLayer)
.SetAddressType(chip::Inet::kIPAddressType_IPv4)
.SetAddressType(gDestAddr.Type())
.SetListenPort(IM_CLIENT_PORT));
SuccessOrExit(err);

Expand Down
9 changes: 7 additions & 2 deletions src/app/tests/integration/chip_im_responder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,13 @@ int main(int argc, char * argv[])

InitializeChip();

err = gTransportManager.Init(
chip::Transport::UdpListenParameters(&chip::DeviceLayer::InetLayer).SetAddressType(chip::Inet::kIPAddressType_IPv4));
err = gTransportManager.Init(chip::Transport::UdpListenParameters(&chip::DeviceLayer::InetLayer)
#if INET_CONFIG_ENABLE_IPV4
.SetAddressType(chip::Inet::kIPAddressType_IPv4)
#else
.SetAddressType(chip::Inet::kIPAddressType_IPv6)
#endif
);
SuccessOrExit(err);

err = gSessionManager.Init(&chip::DeviceLayer::SystemLayer(), &gTransportManager, &gMessageCounterManager);
Expand Down
7 changes: 2 additions & 5 deletions src/controller/tests/TestDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ using namespace chip::Transport;
using namespace chip::Controller;
using namespace chip::Messaging;

#if INET_CONFIG_ENABLE_IPV4
namespace {

using TestTransportMgr = TransportMgr<Transport::UDP>;
Expand All @@ -62,7 +61,7 @@ void TestDevice_EstablishSessionDirectly(nlTestSuite * inSuite, void * inContext
systemLayer.Init();
inetLayer.Init(systemLayer, nullptr);
transportMgr.Init(
UdpListenParameters(&inetLayer).SetAddressType(Inet::IPAddressType::kIPAddressType_IPv4).SetListenPort(CHIP_PORT)
UdpListenParameters(&inetLayer).SetAddressType(Inet::IPAddressType::kIPAddressType_IPv6).SetListenPort(CHIP_PORT)
#if INET_CONFIG_ENABLE_IPV4
,
UdpListenParameters(&inetLayer).SetAddressType(Inet::kIPAddressType_IPv4).SetListenPort(CHIP_PORT)
Expand All @@ -89,7 +88,7 @@ void TestDevice_EstablishSessionDirectly(nlTestSuite * inSuite, void * inContext
NodeId mockNodeId = 1;
FabricIndex mockFabricIndex = 1;
Inet::IPAddress mockAddr;
Inet::IPAddress::FromString("127.0.0.1", mockAddr);
Inet::IPAddress::FromString("::1", mockAddr);
PeerAddress addr = PeerAddress::UDP(mockAddr, CHIP_PORT);
device.Init(params, mockNodeId, addr, mockFabricIndex);

Expand Down Expand Up @@ -125,5 +124,3 @@ int TestDevice()
}

CHIP_REGISTER_TEST_SUITE(TestDevice)

#endif // INET_CONFIG_ENABLE_IPV4
13 changes: 8 additions & 5 deletions src/inet/DNSResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,11 @@ CHIP_ERROR DNSResolver::Resolve(const char * hostName, uint16_t hostNameLen, uin
uint8_t optionFlags = (options & kDNSOption_Flags_Mask);

// Check that the supplied options are valid.
if ((addrFamilyOption != kDNSOption_AddrFamily_Any && addrFamilyOption != kDNSOption_AddrFamily_IPv4Only &&
addrFamilyOption != kDNSOption_AddrFamily_IPv4Preferred && addrFamilyOption != kDNSOption_AddrFamily_IPv6Only &&
addrFamilyOption != kDNSOption_AddrFamily_IPv6Preferred) ||
if ((addrFamilyOption != kDNSOption_AddrFamily_Any
#if INET_CONFIG_ENABLE_IPV4
&& addrFamilyOption != kDNSOption_AddrFamily_IPv4Only && addrFamilyOption != kDNSOption_AddrFamily_IPv4Preferred
#endif
&& addrFamilyOption != kDNSOption_AddrFamily_IPv6Only && addrFamilyOption != kDNSOption_AddrFamily_IPv6Preferred) ||
(optionFlags & ~kDNSOption_ValidFlags) != 0)
{
Release();
Expand Down Expand Up @@ -347,10 +349,11 @@ void DNSResolver::LwIPHandleResolveComplete(const char * name, ip_addr_t * ipadd

void DNSResolver::InitAddrInfoHints(struct addrinfo & hints)
{
uint8_t addrFamilyOption = (DNSOptions & kDNSOption_AddrFamily_Mask);

memset(&hints, 0, sizeof(hints));

#if INET_CONFIG_ENABLE_IPV4
uint8_t addrFamilyOption = (DNSOptions & kDNSOption_AddrFamily_Mask);

if (addrFamilyOption == kDNSOption_AddrFamily_IPv4Only)
{
hints.ai_family = AF_INET;
Expand Down
14 changes: 12 additions & 2 deletions src/inet/tests/TestInetEndPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,10 +413,12 @@ static void TestInetEndPointLimit(nlTestSuite * inSuite, void * inContext)

CHIP_ERROR err = CHIP_NO_ERROR;

// TODO: err is not validated EXCEPT the last call
for (int i = 0; i < INET_CONFIG_NUM_UDP_ENDPOINTS + 1; i++)
err = gInet.NewUDPEndPoint(&testUDPEP[i]);
NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_ENDPOINT_POOL_FULL);

// TODO: err is not validated EXCEPT the last call
for (int i = 0; i < INET_CONFIG_NUM_TCP_ENDPOINTS + 1; i++)
err = gInet.NewTCPEndPoint(&testTCPEP[i]);
NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_ENDPOINT_POOL_FULL);
Expand All @@ -440,12 +442,20 @@ static void TestInetEndPointLimit(nlTestSuite * inSuite, void * inContext)

// Release UDP endpoints
for (int i = 0; i < INET_CONFIG_NUM_UDP_ENDPOINTS; i++)
testUDPEP[i]->Free();
{
if (testUDPEP[i] != nullptr)
{
testUDPEP[i]->Free();
}
}

// Release TCP endpoints
for (int i = 0; i < INET_CONFIG_NUM_TCP_ENDPOINTS; i++)
{
testTCPEP[i]->Free();
if (testTCPEP[i] != nullptr)
{
testTCPEP[i]->Free();
}
}
}
#endif
Expand Down
50 changes: 34 additions & 16 deletions src/inet/tests/TestInetLayerDNS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ static void TestDNSResolution_Basic(nlTestSuite * testSuite, void * testContext)
// clang-format off

#ifndef DISABLE_BROKEN_DNS_TESTS
#if INET_CONFIG_ENABLE_IPV4
// Test resolving a name with only IPv4 addresses.
RunTestCase(testSuite,
DNSResolutionTestCase
Expand All @@ -104,6 +105,7 @@ static void TestDNSResolution_Basic(nlTestSuite * testSuite, void * testContext)
false
}
);
#endif

// Test resolving a name with only IPv6 addresses.
RunTestCase(testSuite,
Expand All @@ -118,6 +120,7 @@ static void TestDNSResolution_Basic(nlTestSuite * testSuite, void * testContext)
}
);

#if INET_CONFIG_ENABLE_IPV4
// Test resolving a name with IPv4 and IPv6 addresses.
RunTestCase(testSuite,
DNSResolutionTestCase
Expand All @@ -130,6 +133,7 @@ static void TestDNSResolution_Basic(nlTestSuite * testSuite, void * testContext)
true
}
);
#endif
#endif
// clang-format on
}
Expand Down Expand Up @@ -183,7 +187,6 @@ static void TestDNSResolution_AddressTypeOption(nlTestSuite * testSuite, void *
true
}
);
#endif // INET_CONFIG_ENABLE_IPV4

// Test requesting IPv6 address preferentially.
RunTestCase(testSuite,
Expand All @@ -197,6 +200,7 @@ static void TestDNSResolution_AddressTypeOption(nlTestSuite * testSuite, void *
true
}
);
#endif // INET_CONFIG_ENABLE_IPV4

#endif
// clang-format on
Expand Down Expand Up @@ -251,7 +255,6 @@ static void TestDNSResolution_RestrictedResults(nlTestSuite * testSuite, void *
true
}
);
#endif // INET_CONFIG_ENABLE_IPV4

// Test requesting 2 addresses, preferring IPv6. This should result in 1 IPv6 address
// followed by 1 IPv4 address.
Expand All @@ -267,6 +270,7 @@ static void TestDNSResolution_RestrictedResults(nlTestSuite * testSuite, void *
}
);
// clang-format on
#endif // INET_CONFIG_ENABLE_IPV4
}

/**
Expand Down Expand Up @@ -350,6 +354,7 @@ static void TestDNSResolution_NoHostRecord(nlTestSuite * testSuite, void * testC
static void TestDNSResolution_TextForm(nlTestSuite * testSuite, void * testContext)
{
// clang-format off
#if INET_CONFIG_ENABLE_IPV4
RunTestCase(testSuite,
DNSResolutionTestCase
{
Expand All @@ -361,6 +366,7 @@ static void TestDNSResolution_TextForm(nlTestSuite * testSuite, void * testConte
false
}
);
#endif

RunTestCase(testSuite,
DNSResolutionTestCase
Expand All @@ -377,6 +383,7 @@ static void TestDNSResolution_TextForm(nlTestSuite * testSuite, void * testConte
// Test resolving text form IPv4 and IPv6 addresses while requesting an
// incompatible address type.

#if INET_CONFIG_ENABLE_IPV4
RunTestCase(testSuite,
DNSResolutionTestCase
{
Expand All @@ -400,13 +407,14 @@ static void TestDNSResolution_TextForm(nlTestSuite * testSuite, void * testConte
false
}
);
#endif
// clang-format on
}

static void TestDNSResolution_Cancel(nlTestSuite * testSuite, void * inContext)
{
DNSResolutionTestContext testContext{
testSuite, DNSResolutionTestCase{ "www.google.com", kDNSOption_Default, kMaxResults, CHIP_NO_ERROR, true, false }
testSuite, DNSResolutionTestCase{ "ipv6.google.com", kDNSOption_Default, kMaxResults, CHIP_NO_ERROR, false, true }
};

// Start DNS resolution.
Expand Down Expand Up @@ -440,48 +448,48 @@ static void TestDNSResolution_Simultaneous(nlTestSuite * testSuite, void * inCon
testSuite,
DNSResolutionTestCase
{
"www.nest.com",
kDNSOption_Default,
"example.net",
kDNSOption_AddrFamily_IPv6Only,
kMaxResults,
CHIP_NO_ERROR,
true,
false
false,
true
}
},
{
testSuite,
DNSResolutionTestCase
{
"10.0.0.1",
"2607:f8b0:4005:804::200e",
kDNSOption_Default,
kMaxResults,
CHIP_NO_ERROR,
true,
false
false,
true
}
},
{
testSuite,
DNSResolutionTestCase
{
"www.google.com",
"ipv6.google.com",
kDNSOption_Default,
kMaxResults,
CHIP_NO_ERROR,
true,
false,
true
}
},
{
testSuite,
DNSResolutionTestCase
{
"pool.ntp.org",
kDNSOption_Default,
"ibm.com",
kDNSOption_AddrFamily_IPv6Only,
kMaxResults,
CHIP_NO_ERROR,
true,
false
false,
true
}
}
};
Expand Down Expand Up @@ -587,7 +595,9 @@ static void HandleResolutionComplete(void * appState, CHIP_ERROR err, uint8_t ad

for (uint8_t i = 0; i < addrCount; i++)
{
#if INET_CONFIG_ENABLE_IPV4
respContainsIPv4Addrs = respContainsIPv4Addrs || (addrArray[i].Type() == kIPAddressType_IPv4);
#endif
respContainsIPv6Addrs = respContainsIPv6Addrs || (addrArray[i].Type() == kIPAddressType_IPv6);
}

Expand All @@ -604,8 +614,14 @@ static void HandleResolutionComplete(void * appState, CHIP_ERROR err, uint8_t ad
{
if (testCase.expectIPv4Addrs)
{
#if INET_CONFIG_ENABLE_IPV4
NL_TEST_ASSERT(testSuite, respContainsIPv4Addrs);
#else
// IP-v4 test ran without IPv4 support
NL_TEST_ASSERT(testSuite, false);
#endif
}

if (testCase.expectIPv6Addrs)
{
NL_TEST_ASSERT(testSuite, respContainsIPv6Addrs);
Expand All @@ -618,6 +634,7 @@ static void HandleResolutionComplete(void * appState, CHIP_ERROR err, uint8_t ad
{
case kDNSOption_AddrFamily_Any:
break;
#if INET_CONFIG_ENABLE_IPV4
case kDNSOption_AddrFamily_IPv4Only:
NL_TEST_ASSERT(testSuite, !respContainsIPv6Addrs);
break;
Expand All @@ -627,6 +644,7 @@ static void HandleResolutionComplete(void * appState, CHIP_ERROR err, uint8_t ad
NL_TEST_ASSERT(testSuite, addrArray[0].Type() == kIPAddressType_IPv4);
}
break;
#endif
case kDNSOption_AddrFamily_IPv6Only:
NL_TEST_ASSERT(testSuite, !respContainsIPv4Addrs);
break;
Expand Down
Loading

0 comments on commit 1202659

Please sign in to comment.