Skip to content

Commit ae62f21

Browse files
committed
Don't compile in IPv6 to the firewall when IPv6 is disabled.
1 parent 6101271 commit ae62f21

File tree

4 files changed

+40
-6
lines changed

4 files changed

+40
-6
lines changed

lib/firewall/firewall.cc

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ namespace
4848
enum class EtherType : uint16_t
4949
{
5050
IPv4 = 0x0008,
51+
#ifdef ENABLE_IPV6
5152
IPv6 = 0xDD86,
52-
ARP = 0x0608,
53+
#endif
54+
ARP = 0x0608,
5355
};
5456

5557
const char *ethertype_as_string(EtherType etherType)
@@ -58,8 +60,10 @@ namespace
5860
{
5961
case EtherType::IPv4:
6062
return "IPv4";
63+
#ifdef ENABLE_IPV6
6164
case EtherType::IPv6:
6265
return "IPv6";
66+
#endif
6367
case EtherType::ARP:
6468
return "ARP";
6569
default:
@@ -479,15 +483,18 @@ namespace
479483
}
480484
return ret;
481485
}
486+
#ifdef ENABLE_IPV6
482487
// For now, permit all outbound IPv6 packets.
488+
// FIXME: Check the firewall for IPv6!
483489
case EtherType::IPv6:
484490
{
485491
Debug::log("Permitting outbound IPv6 packet");
486492
return true;
487493
break;
488494
}
495+
#endif
489496
}
490-
return true;
497+
return false;
491498
}
492499

493500
bool packet_filter_ingress(const uint8_t *data, size_t length)
@@ -503,9 +510,12 @@ namespace
503510
reinterpret_cast<EthernetHeader *>(const_cast<uint8_t *>(data));
504511
switch (ethernetHeader->etherType)
505512
{
513+
#ifdef ENABLE_IPV6
506514
// For now, testing with v6 disabled.
515+
// FIXME: Check the firewall for IPv6!
507516
case EtherType::IPv6:
508517
return true;
518+
#endif
509519
case EtherType::ARP:
510520
Debug::log("Saw ARP frame");
511521
return true;
@@ -704,6 +714,7 @@ namespace
704714
}
705715
} // namespace
706716

717+
#ifdef ENABLE_IPV6
707718
void firewall_add_tcpipv6_endpoint(uint8_t *remoteAddress,
708719
uint16_t localPort,
709720
uint16_t remotePort)
@@ -748,3 +759,5 @@ void firewall_remove_udpipv6_remote_endpoint(uint8_t *remoteAddress,
748759
IPProtocolNumber::UDP, *copy, localPort, remotePort);
749760
}
750761
}
762+
763+
#endif

lib/firewall/xmake.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11

22
compartment("Firewall")
33
add_includedirs("../../include")
4+
on_load(function(target)
5+
target:add('options', "IPv6")
6+
local IPv6 = get_config("IPv6")
7+
target:add("defines", "CHERIOT_RTOS_OPTION_IPv6=" .. tostring(IPv6))
8+
end)
49
--FIXME: The FreeRTOS compat headers need to work with this mode!
510
--add_defines("CHERIOT_NO_AMBIENT_MALLOC", "CHERIOT_NO_NEW_DELETE")
611
add_files("firewall.cc")

lib/netapi/NetAPI.cc

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,15 @@ SObj network_socket_connect_tcp(Timeout *timeout,
6363
Debug::log("Failed to resolve host");
6464
return nullptr;
6565
}
66-
bool isIPv6 = address.kind == NetworkAddress::AddressKindIPv6;
66+
bool isIPv6 = address.kind == NetworkAddress::AddressKindIPv6;
67+
if constexpr (!UseIPv6)
68+
{
69+
if (isIPv6)
70+
{
71+
Debug::log("IPv6 is not supported");
72+
return nullptr;
73+
}
74+
}
6775
auto sealedSocket = network_socket_create_and_bind(
6876
timeout, mallocCapability, isIPv6, ConnectionTypeTCP);
6977
auto kind = network_socket_kind(sealedSocket);
@@ -148,8 +156,16 @@ NetworkAddress network_socket_udp_authorise_host(Timeout *timeout,
148156
}
149157
if (isIPv6)
150158
{
151-
firewall_add_udpipv6_endpoint(
152-
address.ipv6, kind.localPort, ntohs(host->port));
159+
if constexpr (!UseIPv6)
160+
{
161+
Debug::log("IPv6 is not supported");
162+
return {NetworkAddress::AddressKindInvalid};
163+
}
164+
else
165+
{
166+
firewall_add_udpipv6_endpoint(
167+
address.ipv6, kind.localPort, ntohs(host->port));
168+
}
153169
}
154170
else
155171
{

lib/tcpip/network_wrapper.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ int network_socket_close(Timeout *t, SObj mallocCapability, SObj sealedSocket)
580580
// happen in practice and has no impact for us.
581581
FreeRTOS_shutdown(socket->socket, FREERTOS_SHUT_RDWR);
582582
auto localPort = ntohs(socket->socket->usLocalPort);
583-
if (socket->socket->bits.bIsIPv6)
583+
if (UseIPv6 && socket->socket->bits.bIsIPv6)
584584
{
585585
if (isTCP)
586586
{

0 commit comments

Comments
 (0)